From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4BA1EA034E; Wed, 19 Jan 2022 11:50:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E36FC410FC; Wed, 19 Jan 2022 11:50:58 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id 6DA564013F; Wed, 19 Jan 2022 11:50:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642589457; x=1674125457; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=TMufWfHpP7BBj6cr1yvkIu3bSo8Opv02q0+XLt6b3YA=; b=bw0PhBtvlK8Pg5kR6by9tT/MxcFGJTn/BaSafmf6DbFsa9aLABwY3ton XmCUKBasJhk4ehKdC0iMIlnZ4NfPbP8bCfsepeQaBHKFHUEQ/gUpudtiv frJTjD7yXthUOHhYbYCic+bTFkKqf+pcB6yF6yAcAki+sCAH/21ScB1iu 2bHU2XULxkhaWZcRhuj//qOQdYJ8SlORs9JlIPj0W7SFAruymAAX7Q3Zr 2RaKGfOTOyJzqRQdInPtZXHjfVglkpAygMZOkA/HBpytWxW9bBl62u770 SdPwn2i4tbp5cqibSBnAX8qD8vd9LPJKJoUlxDkEyQZM6aeo9oca2GZAU Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="243860673" X-IronPort-AV: E=Sophos;i="5.88,299,1635231600"; d="scan'208";a="243860673" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2022 02:50:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,299,1635231600"; d="scan'208";a="532231573" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga008.jf.intel.com with ESMTP; 19 Jan 2022 02:50:56 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 19 Jan 2022 02:50:55 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Wed, 19 Jan 2022 02:50:55 -0800 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.44) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Wed, 19 Jan 2022 02:50:54 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OLnR5vr901rUijH4eu6YLa4Ot7UIo2Ee570Q1xsLJmNTceaPoCz+2VI8/00aU1BoOiR46/oWJPOs6jp5adKomQiTsNl6pQ0KLKLkN/4h2LlZRh+pjC/6p3LI0SfuloSxyz+AcFsIJovxTCdWk/9uPApe2hZIvO9yCdNCgTB0zttg5Ndl/v6MJfRit5ty+WovVQihmn4zr9PkiYpuNr5W+ejQtaNYzq2eXRhZ2mMWxXurnXmHd6wehuGk/fvZTpwfYR/RRv5IkjQmOTQ+KOfGh9hDzpppvhXZC5P8z75c3clW6ATcan+ihI1wRLSLEIvGR6VEh+I0GrFyYFrWvB4WxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PzcTQ6yKnGYPBjeYRmFQAyfep7H0+QrQOz4BxsV0wPw=; b=a4h0N69Oz13p2nLe9DpibUEA1M8klgj0qqhrkpDkAs3Uc64nioD2e6Rpwqbz/Dja7PwELWL3pTcZErsww/IZzx5Yy5QFdIN8V7th3bPBIcsA7uV05AeXmNFPNBQeo3IP/Iap3/9/NUc3Gks1gRIe+JoVTvXXGjTOtBorGlAFeHUKPBLcgrZ13l9dnFvckbuGyeR6exufUsj1Pjgztju0ren3vnJirnDPzZNPbv8BSDUmx7clmFH4pJbkKloh+dy+gR+R6keRj+G3wudeBbmpTuPxQFqGmWbAFrD7O/j5CM7yFGsXj1UcfA7wxTJI0GY8qCpePDVDZ5iIYaZjWBtiwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DM6PR11MB4252.namprd11.prod.outlook.com (2603:10b6:5:201::26) by DM6PR11MB4089.namprd11.prod.outlook.com (2603:10b6:5:198::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 10:50:50 +0000 Received: from DM6PR11MB4252.namprd11.prod.outlook.com ([fe80::e0a3:bb14:9df1:70d4]) by DM6PR11MB4252.namprd11.prod.outlook.com ([fe80::e0a3:bb14:9df1:70d4%4]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 10:50:49 +0000 From: "Xu, Rosen" To: "Huang, Wei" , "dev@dpdk.org" , "Zhang, Qi Z" CC: "stable@dpdk.org" , "Zhang, Tianfei" , "Yigit, Ferruh" Subject: RE: [PATCH v1] raw/ifpga/base: fix SPI transaction Thread-Topic: [PATCH v1] raw/ifpga/base: fix SPI transaction Thread-Index: AQHYDNah1u+Bg7UVtkiB2nJGXr00GaxqKxew Date: Wed, 19 Jan 2022 10:50:49 +0000 Message-ID: References: <20220119014459.3904-1-wei.huang@intel.com> In-Reply-To: <20220119014459.3904-1-wei.huang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.200.16 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDAxMTg3NzktOTgxNC00NzNlLTk0ZTAtMGI3OTMyNTczNDE2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSXpzYWlXUjhleHYwZTdrY0w0RG16dmcrZ2pGQ2pscVZhUG1Vb0RnRWNwclwvOEpISVF4SENudEl2THdKMzIrRGwifQ== x-ctpclassification: CTP_NT authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 968c28d4-4dda-4527-82ac-08d9db398e7a x-ms-traffictypediagnostic: DM6PR11MB4089:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5516; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 27FqMfC/Vj1D1IrNhoNqvA7lVKOarcrfvNtGIKgGP/ePbDp9QZiYsa+A6c7fR1WKsaanT6wbzPa0XQpHsLlsqsuxqWer0F/P4cFiC5Zkph2UfuV+SL9xP+mZIcW4DOw03nkAwOBqdnWvzTGPyv9hxcuN/1339qAGE2URIQArCE9IYmiSstZQrU+S3UqsE7OclOr1vsaAclCH8sVyL8NwrGWeanO0mrSVdbXPDDL42DbwGEVA74tG9Ox97bqAT5SgDhHZh9+Q9ggms/7uij2h11r0qcNSqfgHDgoNgvMoUdC2dC/LUswDAugxbgXQrdjXlHz5basgTNBu3tB1RUMH4bMHr1hqOzkkYWcJTyNi4rrCvV7CJNAQyVR4Wn239Z0JZZZkHmxlyIalDb+OnxTUD3KvnNnZnaCl9soBXRR3oTq3fZ6EXDm1GmZY68f3xSp0BMFSEjBeHUC6dNOKpdzm43vNm5QyKi2OCUtZzdr4GnRBJaPRVgAc7VWCo+/wgbL5pRJeV/sZRv2bjgjzZtDXXNOhFzygvhIFRO0TKTPcWZBsgPKYrPpb75tKbxi1cIna7ZsjrPoryXRIzB22SaBuVH1AFz4Lg82QDVOnHk/867rx+iPTnIH73X73slAA146PNvX6gjNQsxR77JiuXRJEtM8zEmlr+lCycgoAth1918HmqD67x98mlw03imHuFMPlmX2nGtO0lIt91C+cuew+5g== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4252.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(83380400001)(508600001)(66946007)(52536014)(64756008)(66446008)(66556008)(2906002)(76116006)(66476007)(8936002)(55016003)(71200400001)(186003)(82960400001)(38070700005)(5660300002)(86362001)(26005)(7696005)(8676002)(54906003)(110136005)(38100700002)(9686003)(6636002)(450100002)(33656002)(107886003)(122000001)(6506007)(316002)(53546011)(4326008); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?jW2HvL6/zo9aBw66xn5Zupoiffg8EZULGZeQ7svr8YE7bpDdFyi99TeRd/sK?= =?us-ascii?Q?1ayFAiI+fCMSjSvqg0HCi+Ib/eM8muEtrcPX4HDLqtRqPJ/Ttoghf3phbjAN?= =?us-ascii?Q?WXDT+wQKTxmcxsfEZYmD3KPr4YVNSZR2i2smnOsZCb9BzEp2fMvFi1XfIDt7?= =?us-ascii?Q?wIuiJSJ980dDpieq8pKxKN9P/JDGijAnACjb6FcMq2NxOTOGsReH2RWQXQbd?= =?us-ascii?Q?ku3p0MBnIXbNTz/MNswsNTn+fwSxu180WrGhpBzS/iSj0ppC0X9ezAArUOnF?= =?us-ascii?Q?FzOLm9hf6ULEi8iGAyEy9v9WbYP6SLCfLKbRTYxGTpsS9ZAYRP5T87JmYl+P?= =?us-ascii?Q?b+t8SrKXORIUVefCtWMbQ2wfYv5+Aior9TV3R5xli79IDaFHQ6Y+4ifr7zTA?= =?us-ascii?Q?GaYSpMMG1F2QzWmdFnX1dWnbmeZ9FjczBcSGN7qJQ8aP60/prnBvbDiiO+x+?= =?us-ascii?Q?YbTihtZ/Y5V/fevk2SijDUYEAmdQsfP5+FN9LOO/PYOPnjDApVIzO1A3qx3Q?= =?us-ascii?Q?V0ESHWa6UlDAcKDncTQECaI8o55VaTWuA58bptgkQpTjZP6zIBwcjPtHlx4Z?= =?us-ascii?Q?lOGpoUQusOKnLBGOuWcta+MFXxfWSK5ohaM6iVqkZXr/ur7Xiw5JGS02Kxmi?= =?us-ascii?Q?tMv45bFgQM7VH/KjTYslucfa3oIZtbpPtxPvLSXg8NHvEyNJvjZxn7bRGls+?= =?us-ascii?Q?uekiggzjGs7DsZa5b5II3xe1OOH7m8kPMh+dKc+YpUByRg+HgzhYJdO9WGs0?= =?us-ascii?Q?2yLz+pZmk9gDnrmtWt4cckIxdapA+XaZE6WVp818X2Mf7c0IlPVD1LWyIYeE?= =?us-ascii?Q?/5OopbiZWj9mN6EHO1ylQ2xvq8vlrWBhahfdF14JRMXIatuKYldGXQAaJUXl?= =?us-ascii?Q?9rXi0SRXBrf5vtQu8rdBrkzCZf/QujjyDeHDZ1hia2No42ci4ULOOfmDne2D?= =?us-ascii?Q?KC3rFVow0IbvnEouIDE3xp+kDcCFJTATE4COqZ+Zk8MduDDyiKyhc0qE4D1q?= =?us-ascii?Q?aeAO+GucQl2daeUCL65VCmrMjSKkjPN5A1W3LNOTvLY1XtC267J0VKFmiNjJ?= =?us-ascii?Q?Ehx6nWyogVgjSlXrJRoMHAfRxyiMJIwUKBO3rSQvE6jO9E6c+6M/2WF57cOR?= =?us-ascii?Q?215LRfKk4XPJORgI+Q/4CnQsLHEhePVKkBsVAO7BndwjNzPzitGvYi9qzkYU?= =?us-ascii?Q?E+cLFJWWakt8ZD7gv7yxzMKgMNqHYFqUPUgbsdqe9y3voq2U4b0TNZ3+yz5a?= =?us-ascii?Q?MjYXQpDPj1ZtbyNqg10n1OcRoG45EW2MveDsj/ecYSarA0pc+wMVV+tSrSYT?= =?us-ascii?Q?d9rSs3jKloNH9xrEPsRQGR+tv3ED1z5pSsmXvmIbWw7agGRJ8EK1mZnHO5Iq?= =?us-ascii?Q?qynXF2sH8/EH1v6cgte+s//Ex0QvInh5tFiJ97epYTOgoNjwhg/OwypIQzqc?= =?us-ascii?Q?xJfMZ6X6+sQ3A4LpQAJYCRV0YnxKuKAbpSIDHAMXU/VToWJFWeqEfCCGXG2j?= =?us-ascii?Q?xcuMo2fe9M2CiC/EZENdr7aY8Iq2JXHmh1cgMUd4oNlzoKPMTISv9nBFNwxK?= =?us-ascii?Q?mTZJlSxi6SeEixPyHY96mD7hNXNIw8LJzCorOviQP0kcWiENrt/dREIPFWQl?= =?us-ascii?Q?3Q=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4252.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 968c28d4-4dda-4527-82ac-08d9db398e7a X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jan 2022 10:50:49.8554 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: mdlYRWrEoOiMNOGME3swXsdu84K10xa7tdBGT0YvEoso5ytf6XrnLaq6dbtWmMcqIk3RzW+KLTryIlCmgtCFEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4089 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Hi, > -----Original Message----- > From: Huang, Wei > Sent: Wednesday, January 19, 2022 9:45 > To: dev@dpdk.org; Xu, Rosen ; Zhang, Qi Z > > Cc: stable@dpdk.org; Zhang, Tianfei ; Yigit, Fer= ruh > > Subject: [PATCH v1] raw/ifpga/base: fix SPI transaction >=20 > From: Tianfei Zhang >=20 > When EOP is detected, 2 more bytes should be received (may be a > SPI_PACKET_ESC before last valid byte) then rx should be finished. >=20 > Fixes: 96ebfcf8 ("raw/ifpga/base: add SPI and MAX10 device driver") > Cc: stable@dpdk.org >=20 > Signed-off-by: Tianfei Zhang > --- > drivers/raw/ifpga/base/opae_spi.c | 12 ++ > drivers/raw/ifpga/base/opae_spi.h | 4 + > drivers/raw/ifpga/base/opae_spi_transaction.c | 215 +++++++++++++++-----= - > ----- > 3 files changed, 140 insertions(+), 91 deletions(-) >=20 > diff --git a/drivers/raw/ifpga/base/opae_spi.c > b/drivers/raw/ifpga/base/opae_spi.c > index 9efeecb..ca3d41f 100644 > --- a/drivers/raw/ifpga/base/opae_spi.c > +++ b/drivers/raw/ifpga/base/opae_spi.c > @@ -239,6 +239,18 @@ int spi_command(struct altera_spi_device *dev, > unsigned int chip_select, > return 0; > } >=20 > +int spi_write(struct altera_spi_device *dev, unsigned int chip_select, > + unsigned int wlen, void *wdata) > +{ > + return spi_command(dev, chip_select, wlen, wdata, 0, NULL); } > + > +int spi_read(struct altera_spi_device *dev, unsigned int chip_select, > + unsigned int rlen, void *rdata) > +{ > + return spi_command(dev, chip_select, 0, NULL, rlen, rdata); } > + > struct altera_spi_device *altera_spi_alloc(void *base, int type) { > struct altera_spi_device *spi_dev =3D > diff --git a/drivers/raw/ifpga/base/opae_spi.h > b/drivers/raw/ifpga/base/opae_spi.h > index af11656..bcff67d 100644 > --- a/drivers/raw/ifpga/base/opae_spi.h > +++ b/drivers/raw/ifpga/base/opae_spi.h > @@ -117,6 +117,10 @@ struct spi_tran_header { > u32 addr; > }; >=20 > +int spi_read(struct altera_spi_device *dev, unsigned int chip_select, > + unsigned int rlen, void *rdata); > +int spi_write(struct altera_spi_device *dev, unsigned int chip_select, > + unsigned int wlen, void *wdata); > int spi_command(struct altera_spi_device *dev, unsigned int chip_select, > unsigned int wlen, void *wdata, unsigned int rlen, void > *rdata); void spi_cs_deactivate(struct altera_spi_device *dev); diff --g= it > a/drivers/raw/ifpga/base/opae_spi_transaction.c > b/drivers/raw/ifpga/base/opae_spi_transaction.c > index 006cdb4..cd50d40 100644 > --- a/drivers/raw/ifpga/base/opae_spi_transaction.c > +++ b/drivers/raw/ifpga/base/opae_spi_transaction.c > @@ -40,7 +40,7 @@ static void print_buffer(const char *string, void *buff= er, > int len) > printf("%s print buffer, len=3D%d\n", string, len); >=20 > for (i =3D 0; i < len; i++) > - printf("%x ", *(p+i)); > + printf("%02x ", *(p+i)); > printf("\n"); > } > #else > @@ -72,43 +72,6 @@ static void reorder_phy_data(u8 bits_per_word, > } > } >=20 > -enum { > - SPI_FOUND_SOP, > - SPI_FOUND_EOP, > - SPI_NOT_FOUND, > -}; > - > -static int resp_find_sop_eop(unsigned char *resp, unsigned int len, > - int flags) > -{ > - int ret =3D SPI_NOT_FOUND; > - > - unsigned char *b =3D resp; > - > - /* find SOP */ > - if (flags !=3D SPI_FOUND_SOP) { > - while (b < resp + len && *b !=3D SPI_PACKET_SOP) > - b++; > - > - if (*b !=3D SPI_PACKET_SOP) > - goto done; > - > - ret =3D SPI_FOUND_SOP; > - } > - > - /* find EOP */ > - while (b < resp + len && *b !=3D SPI_PACKET_EOP) > - b++; > - > - if (*b !=3D SPI_PACKET_EOP) > - goto done; > - > - ret =3D SPI_FOUND_EOP; > - > -done: > - return ret; > -} > - > static void phy_tx_pad(unsigned char *phy_buf, unsigned int phy_buf_len, > unsigned int *aligned_len) > { > @@ -137,6 +100,104 @@ static void phy_tx_pad(unsigned char *phy_buf, > unsigned int phy_buf_len, > *p++ =3D SPI_BYTE_IDLE; > } >=20 > +#define RX_ALL_IDLE_DATA (SPI_BYTE_IDLE << 24 | SPI_BYTE_IDLE << 16 | > \ > + SPI_BYTE_IDLE << 8 | SPI_BYTE_IDLE) > + > +static bool all_idle_data(u8 *rxbuf) > +{ > + return *(u32 *)rxbuf =3D=3D RX_ALL_IDLE_DATA; } > + > +static unsigned char *find_eop(u8 *rxbuf, u32 BPW) { > + return memchr(rxbuf, SPI_PACKET_EOP, BPW); } > + > +static int do_spi_txrx(struct spi_transaction_dev *dev, > + unsigned char *tx_buffer, > + unsigned int tx_len, unsigned char *rx_buffer, > + unsigned int rx_len, > + unsigned int *actual_rx) > +{ > + unsigned int rx_cnt =3D 0; > + int ret =3D 0; > + unsigned int BPW =3D 4; > + bool eop_found =3D false; > + unsigned char *eop; > + unsigned char *ptr; > + unsigned char *rxbuf =3D rx_buffer; > + int add_byte =3D 0; > + unsigned long ticks; > + unsigned long timeout; > + > + /* send command */ > + ret =3D spi_write(dev->dev, dev->chipselect, tx_len, tx_buffer); > + if (ret) > + return -EBUSY; > + > + timeout =3D rte_get_timer_cycles() + > + msecs_to_timer_cycles(2000); > + > + /* read out data */ > + while (rx_cnt < rx_len) { > + ret =3D spi_read(dev->dev, dev->chipselect, BPW, rxbuf); > + if (ret) > + return -EBUSY; > + > + /* skip all of invalid data */ > + if (!eop_found && all_idle_data(rxbuf)) { > + ticks =3D rte_get_timer_cycles(); > + if (!time_after(ticks, timeout)) { > + continue; > + } else { > + dev_err(dev, "read spi data timeout\n"); > + return -ETIMEDOUT; > + } > + } > + > + rx_cnt +=3D BPW; > + if (!eop_found) { > + /* EOP is found, we read 2 more bytes and exit. */ > + eop =3D find_eop(rxbuf, BPW); > + if (eop) { > + if ((BPW + rxbuf - eop) > 2) { > + /* > + * check if the last 2 bytes are already > + * received in current word. > + */ > + break; > + } else if ((BPW + rxbuf - eop) =3D=3D 2) { > + /* > + * skip if last byte is not SPI_BYTE_ESC > + * or SPI_PACKET_ESC. this is the valid > + * end of a response too. > + */ > + ptr =3D eop + 1; > + > + if (*ptr !=3D SPI_BYTE_ESC && > + *ptr !=3D > SPI_PACKET_ESC) > + break; > + > + add_byte =3D 1; > + } else { > + add_byte =3D 2; > + } > + > + rx_len =3D min(rx_len, > + IFPGA_ALIGN(rx_cnt + > + add_byte, BPW)); > + eop_found =3D true; > + } > + } > + rxbuf +=3D BPW; > + } > + > + *actual_rx =3D rx_cnt; > + print_buffer("found valid data:", rx_buffer, rx_cnt); > + > + return ret; > +} > + > static int byte_to_core_convert(struct spi_transaction_dev *dev, > unsigned int send_len, unsigned char *send_data, > unsigned int resp_len, unsigned char *resp_data, @@ - > 148,15 +209,9 @@ static int byte_to_core_convert(struct > spi_transaction_dev *dev, > unsigned char *resp_packet =3D dev->buffer->bytes_resp; > unsigned char *p; > unsigned char current_byte; > - unsigned char *tx_buffer; > unsigned int tx_len =3D 0; > - unsigned char *rx_buffer; > - unsigned int rx_len =3D 0; > - int retry =3D 0; > - int spi_flags; > - unsigned long timeout =3D msecs_to_timer_cycles(1000); > - unsigned long ticks; > unsigned int resp_max_len =3D 2 * resp_len; > + unsigned int actual_rx; >=20 > print_buffer("before bytes:", send_data, send_len); >=20 > @@ -190,48 +245,15 @@ static int byte_to_core_convert(struct > spi_transaction_dev *dev, >=20 > print_buffer("after order to spi:", send_packet, tx_len); >=20 > - /* call spi */ > - tx_buffer =3D send_packet; > - rx_buffer =3D resp_packet; > - rx_len =3D resp_max_len; > - spi_flags =3D SPI_NOT_FOUND; > - > -read_again: > - ret =3D spi_command(dev->dev, dev->chipselect, tx_len, tx_buffer, > - rx_len, rx_buffer); > + ret =3D do_spi_txrx(dev, send_packet, tx_len, resp_packet, > + resp_max_len, &actual_rx); > if (ret) > - return -EBUSY; > - > - print_buffer("read from spi:", rx_buffer, rx_len); > - > - /* look for SOP firstly*/ > - ret =3D resp_find_sop_eop(rx_buffer, rx_len - 1, spi_flags); > - if (ret !=3D SPI_FOUND_EOP) { > - tx_buffer =3D NULL; > - tx_len =3D 0; > - ticks =3D rte_get_timer_cycles(); > - if (time_after(ticks, timeout) && > - retry++ > SPI_MAX_RETRY) { > - dev_err(NULL, "Have retry %d, found invalid packet > data\n", > - retry); > - return -EBUSY; > - } > - > - if (ret =3D=3D SPI_FOUND_SOP) { > - rx_buffer +=3D rx_len; > - resp_max_len +=3D rx_len; > - } > - > - spi_flags =3D ret; > - goto read_again; > - } > - > - print_buffer("found valid data:", resp_packet, resp_max_len); > + return ret; >=20 > /* analyze response packet */ > i =3D 0; > p =3D resp_data; > - while (i < resp_max_len) { > + while (i < actual_rx) { > current_byte =3D resp_packet[i]; > switch (current_byte) { > case SPI_BYTE_IDLE: > @@ -337,9 +359,13 @@ static int packet_to_byte_conver(struct > spi_transaction_dev *dev, > current_byte =3D resp_packet[i]; >=20 > switch (current_byte) { > - case SPI_PACKET_ESC: > - case SPI_PACKET_CHANNEL: > case SPI_PACKET_SOP: > + dev_err(dev, "error on get SOP after SOP\n"); > + return -EINVAL; > + case SPI_PACKET_CHANNEL: > + i +=3D 2; > + break; > + case SPI_PACKET_ESC: > i++; > current_byte =3D resp_packet[i]; > *p++ =3D xor_20(current_byte); > @@ -348,23 +374,30 @@ static int packet_to_byte_conver(struct > spi_transaction_dev *dev, > case SPI_PACKET_EOP: > i++; > current_byte =3D resp_packet[i]; > - if (current_byte =3D=3D SPI_PACKET_ESC || > - current_byte =3D=3D > SPI_PACKET_CHANNEL || > - current_byte =3D=3D SPI_PACKET_SOP) { > + switch (current_byte) { > + case SPI_PACKET_ESC: > i++; > current_byte =3D resp_packet[i]; > *p++ =3D xor_20(current_byte); > - } else > + break; > + case SPI_PACKET_CHANNEL: > + case SPI_PACKET_SOP: > + case SPI_PACKET_EOP: > + dev_err(dev, "error get SOP/EOP after > EOP\n"); > + return -EINVAL; > + default: > *p++ =3D current_byte; > - i =3D valid_resp_len; > - break; > + break; > + } > + goto done; > + > default: > *p++ =3D current_byte; > i++; > } > - > } >=20 > +done: > *valid =3D p - resp_buf; >=20 > print_buffer("after packet:", resp_buf, *valid); > -- > 1.8.3.1 Acked-by: Rosen Xu