All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matej Vido <matejvido@gmail.com>
To: dev@dpdk.org
Subject: [PATCH v3 3/6] szedata2: add TX function
Date: Tue, 10 Nov 2015 15:18:15 +0100	[thread overview]
Message-ID: <1447165098-6412-4-git-send-email-matejvido@gmail.com> (raw)
In-Reply-To: <1447165098-6412-1-git-send-email-matejvido@gmail.com>
In-Reply-To: <1442565172-5338-1-git-send-email-matejvido@gmail.com>

TX function handles scattered and non-scattered packets.

Signed-off-by: Matej Vido <matejvido@gmail.com>
---
 drivers/net/szedata2/rte_eth_szedata2.c | 216 +++++++++++++++++++++++++++++++-
 1 file changed, 215 insertions(+), 1 deletion(-)

diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index 785ac88..3213a20 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -358,6 +358,220 @@ eth_szedata2_rx(void *queue,
 	return num_rx;
 }
 
+static uint16_t
+eth_szedata2_tx(void *queue,
+		struct rte_mbuf **bufs,
+		uint16_t nb_pkts)
+{
+	struct rte_mbuf *mbuf;
+	struct szedata2_tx_queue *sze_q = queue;
+	uint16_t num_tx = 0;
+	uint64_t num_bytes = 0;
+
+	const struct szedata_lock *lck;
+	uint32_t lock_size;
+	uint32_t lock_size2;
+	void *dst;
+	uint32_t pkt_len;
+	uint32_t hwpkt_len;
+	uint32_t unlock_size;
+	uint32_t rem_len;
+	uint8_t mbuf_segs;
+	uint16_t pkt_left = nb_pkts;
+
+	if (sze_q->sze == NULL || nb_pkts == 0)
+		return 0;
+
+	while (pkt_left > 0) {
+		unlock_size = 0;
+		lck = szedata_tx_lock_data(sze_q->sze,
+			RTE_ETH_SZEDATA2_TX_LOCK_SIZE,
+			sze_q->tx_channel);
+		if (lck == NULL)
+			continue;
+
+		dst = lck->start;
+		lock_size = lck->len;
+		lock_size2 = lck->next ? lck->next->len : 0;
+
+next_packet:
+		mbuf = bufs[nb_pkts - pkt_left];
+
+		pkt_len = mbuf->pkt_len;
+		mbuf_segs = mbuf->nb_segs;
+
+		hwpkt_len = RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
+			RTE_SZE2_ALIGN8(pkt_len);
+
+		if (lock_size + lock_size2 < hwpkt_len) {
+			szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
+			continue;
+		}
+
+		num_bytes += pkt_len;
+
+		if (lock_size > hwpkt_len) {
+			void *tmp_dst;
+
+			rem_len = 0;
+
+			/* write packet length at first 2 bytes in 8B header */
+			*((uint16_t *)dst) = htole16(
+					RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
+					pkt_len);
+			*(((uint16_t *)dst) + 1) = htole16(0);
+
+			/* copy packet from mbuf */
+			tmp_dst = ((uint8_t *)(dst)) +
+				RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
+			if (mbuf_segs == 1) {
+				/*
+				 * non-scattered packet,
+				 * transmit from one mbuf
+				 */
+				rte_memcpy(tmp_dst,
+					rte_pktmbuf_mtod(mbuf, const void *),
+					pkt_len);
+			} else {
+				/* scattered packet, transmit from more mbufs */
+				struct rte_mbuf *m = mbuf;
+				while (m) {
+					rte_memcpy(tmp_dst,
+						rte_pktmbuf_mtod(m,
+						const void *),
+						m->data_len);
+					tmp_dst = ((uint8_t *)(tmp_dst)) +
+						m->data_len;
+					m = m->next;
+				}
+			}
+
+
+			dst = ((uint8_t *)dst) + hwpkt_len;
+			unlock_size += hwpkt_len;
+			lock_size -= hwpkt_len;
+
+			rte_pktmbuf_free(mbuf);
+			num_tx++;
+			pkt_left--;
+			if (pkt_left == 0) {
+				szedata_tx_unlock_data(sze_q->sze, lck,
+					unlock_size);
+				break;
+			}
+			goto next_packet;
+		} else if (lock_size + lock_size2 >= hwpkt_len) {
+			void *tmp_dst;
+			uint16_t write_len;
+
+			/* write packet length at first 2 bytes in 8B header */
+			*((uint16_t *)dst) =
+				htole16(RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
+					pkt_len);
+			*(((uint16_t *)dst) + 1) = htole16(0);
+
+			/*
+			 * If the raw packet (pkt_len) is smaller than lock_size
+			 * get the correct length for memcpy
+			 */
+			write_len =
+				pkt_len < lock_size -
+				RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED ?
+				pkt_len :
+				lock_size - RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
+
+			rem_len = hwpkt_len - lock_size;
+
+			tmp_dst = ((uint8_t *)(dst)) +
+				RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
+			if (mbuf_segs == 1) {
+				/*
+				 * non-scattered packet,
+				 * transmit from one mbuf
+				 */
+				/* copy part of packet to first area */
+				rte_memcpy(tmp_dst,
+					rte_pktmbuf_mtod(mbuf, const void *),
+					write_len);
+
+				if (lck->next)
+					dst = lck->next->start;
+
+				/* copy part of packet to second area */
+				rte_memcpy(dst,
+					(const void *)(rte_pktmbuf_mtod(mbuf,
+							const uint8_t *) +
+					write_len), pkt_len - write_len);
+			} else {
+				/* scattered packet, transmit from more mbufs */
+				struct rte_mbuf *m = mbuf;
+				uint16_t written = 0;
+				uint16_t to_write = 0;
+				bool new_mbuf = true;
+				uint16_t write_off = 0;
+
+				/* copy part of packet to first area */
+				while (m && written < write_len) {
+					to_write = RTE_MIN(m->data_len,
+							write_len - written);
+					rte_memcpy(tmp_dst,
+						rte_pktmbuf_mtod(m,
+							const void *),
+						to_write);
+
+					tmp_dst = ((uint8_t *)(tmp_dst)) +
+						to_write;
+					if (m->data_len <= write_len -
+							written) {
+						m = m->next;
+						new_mbuf = true;
+					} else {
+						new_mbuf = false;
+					}
+					written += to_write;
+				}
+
+				if (lck->next)
+					dst = lck->next->start;
+
+				tmp_dst = dst;
+				written = 0;
+				write_off = new_mbuf ? 0 : to_write;
+
+				/* copy part of packet to second area */
+				while (m && written < pkt_len - write_len) {
+					rte_memcpy(tmp_dst, (const void *)
+						(rte_pktmbuf_mtod(m,
+						uint8_t *) + write_off),
+						m->data_len - write_off);
+
+					tmp_dst = ((uint8_t *)(tmp_dst)) +
+						(m->data_len - write_off);
+					written += m->data_len - write_off;
+					m = m->next;
+					write_off = 0;
+				}
+			}
+
+			dst = ((uint8_t *)dst) + rem_len;
+			unlock_size += hwpkt_len;
+			lock_size = lock_size2 - rem_len;
+			lock_size2 = 0;
+
+			rte_pktmbuf_free(mbuf);
+			num_tx++;
+		}
+
+		szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
+		pkt_left--;
+	}
+
+	sze_q->tx_pkts += num_tx;
+	sze_q->err_pkts += nb_pkts - num_tx;
+	sze_q->tx_bytes += num_bytes;
+	return num_tx;
+}
+
 static int
 init_rx_channels(struct rte_eth_dev *dev, int v)
 {
@@ -961,7 +1175,7 @@ rte_eth_from_szedata2(const char *name,
 	}
 
 	eth_dev->rx_pkt_burst = eth_szedata2_rx;
-	eth_dev->tx_pkt_burst = NULL;
+	eth_dev->tx_pkt_burst = eth_szedata2_tx;
 
 	return 0;
 }
-- 
1.9.1

  parent reply	other threads:[~2015-11-10 14:19 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-19  8:24 [PATCH 0/2] Virtual PMD using sze2 layer for COMBO cards Matej Vido
2015-06-19  8:25 ` [PATCH 1/2] szedata2: new poll mode driver Matej Vido
2016-03-21 17:45   ` Stephen Hemminger
2016-03-24 17:52     ` Matej Vido
2015-06-19  8:25 ` [PATCH 2/2] doc: added documentation for szedata2 PMD Matej Vido
2015-09-18  8:32 ` [PATCH v2 0/5] Virtual PMD using sze2 layer for COMBO cards Matej Vido
2015-09-18  8:32   ` [PATCH v2 1/5] szedata2: add new poll mode driver Matej Vido
2015-10-26 15:10     ` Thomas Monjalon
2015-09-18  8:32   ` [PATCH v2 2/5] szedata2: add handling of scattered packets in RX Matej Vido
2015-09-18  8:32   ` [PATCH v2 3/5] szedata2: add handling of scattered packets in TX Matej Vido
2015-10-26 14:55     ` Thomas Monjalon
2015-10-27 17:40       ` Matej Vido
2015-09-18  8:32   ` [PATCH v2 4/5] doc: add documentation for szedata2 PMD Matej Vido
2015-10-26 15:00     ` Thomas Monjalon
2015-10-26 15:09     ` Thomas Monjalon
2015-10-27 17:33       ` Matej Vido
2015-10-27 18:00         ` Thomas Monjalon
2015-11-02 14:26           ` Matej Vido
2015-10-30 12:16     ` Mcnamara, John
2015-11-06 14:34       ` Matej Vido
2015-09-18  8:32   ` [PATCH v2 5/5] doc: update 2.2 release notes Matej Vido
2015-09-24 16:23     ` [PATCH v2] doc: update the dpdk " John McNamara
2015-09-24 21:14       ` Thomas Monjalon
2015-11-10 14:18   ` [PATCH v3 0/6] Virtual PMD using sze2 layer for COMBO cards Matej Vido
2015-11-10 14:18     ` [PATCH v3 1/6] szedata2: add new poll mode driver Matej Vido
2015-11-20 15:04       ` Thomas Monjalon
2015-11-20 19:25         ` Matej Vido
2015-11-21 10:27           ` Thomas Monjalon
2015-11-10 14:18     ` [PATCH v3 2/6] szedata2: add non-scattered RX function Matej Vido
2015-11-10 14:18     ` Matej Vido [this message]
2015-11-10 14:18     ` [PATCH v3 4/6] szedata2: add support for scattered packets in RX Matej Vido
2015-11-10 14:18     ` [PATCH v3 5/6] doc: add documentation for szedata2 PMD Matej Vido
2015-11-10 14:55       ` Mcnamara, John
2015-11-10 14:18     ` [PATCH v3 6/6] doc: update 2.2 release notes Matej Vido
2015-11-16 14:22       ` Mcnamara, John
2015-11-20 16:19     ` [PATCH v3 0/6] Virtual PMD using sze2 layer for COMBO cards Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447165098-6412-4-git-send-email-matejvido@gmail.com \
    --to=matejvido@gmail.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.