From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 644DCA04B3;
	Fri,  8 Nov 2019 11:22:12 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id C0EFA1C0C2;
	Fri,  8 Nov 2019 11:21:34 +0100 (CET)
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id 3263A1C0B7
 for <dev@dpdk.org>; Fri,  8 Nov 2019 11:21:33 +0100 (CET)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from fmsmga004.fm.intel.com ([10.253.24.48])
 by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 08 Nov 2019 02:21:32 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.68,281,1569308400"; d="scan'208";a="228141922"
Received: from dpdk-rosen-02.sh.intel.com ([10.67.110.156])
 by fmsmga004.fm.intel.com with ESMTP; 08 Nov 2019 02:21:31 -0800
From: Rosen Xu <rosen.xu@intel.com>
To: dev@dpdk.org
Cc: rosen.xu@intel.com, tianfei.zhang@intel.com, andy.pei@intel.com,
 xiaolong.ye@intel.com, ferruh.yigit@intel.com
Date: Fri,  8 Nov 2019 18:19:36 +0800
Message-Id: <1573208389-112471-7-git-send-email-rosen.xu@intel.com>
X-Mailer: git-send-email 1.8.3.1
In-Reply-To: <1573208389-112471-1-git-send-email-rosen.xu@intel.com>
References: <1571917119-149534-2-git-send-email-andy.pei@intel.com>
 <1573208389-112471-1-git-send-email-rosen.xu@intel.com>
Subject: [dpdk-dev] [PATCH v15 06/19] raw/ifpga/base: align the send buffer
	for SPI
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

From: Tianfei zhang <tianfei.zhang@intel.com>

The length of send buffer of SPI bus should be 4bytes align.

Signed-off-by: Tianfei Zhang <tianfei.zhang@intel.com>
Signed-off-by: Andy Pei <andy.pei@intel.com>
---
 drivers/raw/ifpga/base/opae_spi_transaction.c | 40 ++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/drivers/raw/ifpga/base/opae_spi_transaction.c b/drivers/raw/ifpga/base/opae_spi_transaction.c
index 17ec3c1..06ca625 100644
--- a/drivers/raw/ifpga/base/opae_spi_transaction.c
+++ b/drivers/raw/ifpga/base/opae_spi_transaction.c
@@ -109,6 +109,34 @@ static int resp_find_sop_eop(unsigned char *resp, unsigned int len,
 	return ret;
 }
 
+static void phy_tx_pad(unsigned char *phy_buf, unsigned int phy_buf_len,
+		unsigned int *aligned_len)
+{
+	unsigned char *p = &phy_buf[phy_buf_len - 1], *dst_p;
+
+	*aligned_len = IFPGA_ALIGN(phy_buf_len, 4);
+
+	if (*aligned_len == phy_buf_len)
+		return;
+
+	dst_p = &phy_buf[*aligned_len - 1];
+
+	/* move EOP and bytes after EOP to the end of aligned size */
+	while (p > phy_buf) {
+		*dst_p = *p;
+
+		if (*p == SPI_PACKET_EOP)
+			break;
+
+		p--;
+		dst_p--;
+	}
+
+	/* fill the hole with PHY_IDLE */
+	while (p < dst_p)
+		*p++ = SPI_BYTE_IDLE;
+}
+
 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,
@@ -149,15 +177,19 @@ static int byte_to_core_convert(struct spi_transaction_dev *dev,
 		}
 	}
 
-	print_buffer("before spi:", send_packet, p-send_packet);
+	tx_len = p - send_packet;
+
+	print_buffer("before spi:", send_packet, tx_len);
 
-	reorder_phy_data(32, send_packet, p - send_packet);
+	phy_tx_pad(send_packet, tx_len, &tx_len);
+	print_buffer("after pad:", send_packet, tx_len);
 
-	print_buffer("after order to spi:", send_packet, p-send_packet);
+	reorder_phy_data(32, send_packet, tx_len);
+
+	print_buffer("after order to spi:", send_packet, tx_len);
 
 	/* call spi */
 	tx_buffer = send_packet;
-	tx_len = p - send_packet;
 	rx_buffer = resp_packet;
 	rx_len = resp_max_len;
 	spi_flags = SPI_NOT_FOUND;
-- 
1.8.3.1