From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0093.outbound.protection.outlook.com [157.56.111.93]) by dpdk.org (Postfix) with ESMTP id 1C4F3AB03 for ; Tue, 7 Jun 2016 18:42:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cbg+Jfs0YnC8LBNmjBTDf2jX/rkOOontd+CMz0h3UQw=; b=buLpvbmo8z3tbJMGKPRBG9Ac5WtGLmp1dCVdL/XlbqSdyuJSrWQyyQAzm4vM6UEiE9O+Ngd0NCLh+O4G6snVZGWfkIfLKsiPJdegU6N+v7kEZ5NpN8/YuEXjCqPPE8mwIe+0brpbocQcc/lU0k3rxJnLQOot/2v6111kI5A7hL0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@cavium.com; Received: from localhost.caveonetworks.com (111.93.218.67) by BN3PR0701MB1719.namprd07.prod.outlook.com (10.163.39.18) with Microsoft SMTP Server (TLS) id 15.1.511.8; Tue, 7 Jun 2016 16:42:05 +0000 From: Jerin Jacob To: CC: , , Jerin Jacob , Maciej Czekaj , Kamil Rytarowski , Zyta Szpak , Slawomir Rosek , Radoslaw Biernacki Date: Tue, 7 Jun 2016 22:10:24 +0530 Message-ID: <1465317632-11471-13-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465317632-11471-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1464540424-12631-1-git-send-email-jerin.jacob@caviumnetworks.com> <1465317632-11471-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: MAXPR01CA0054.INDPRD01.PROD.OUTLOOK.COM (10.164.146.154) To BN3PR0701MB1719.namprd07.prod.outlook.com (10.163.39.18) X-MS-Office365-Filtering-Correlation-Id: 2a74a205-a311-42c9-2dcc-08d38ef2aa91 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 2:gsuvQ8jA2sc04wrHTbZU8f8o3q0Jv+7SS1ei5n5m91g31Jnd9Se74ZVUuYHCcRFIzI8wbJpEvj5vPmLcBLb+LrHE043z+M8b4ri73I2MRnaxI/j20nXN0yS1pgODN2MMPvkkjikUL2eupjQ7+jimasiClQZEIzpLkHHD/T7HFuBic35SngV7+uMWXCYDcbBJ; 3:gp+RE3lcRq3jT0rxQApkCjX1QlaSmaNb4bllPGn3U6D3fXmSauxeQkN/JKcaplu0T62ZYtHoFb/P9314Wl7J6dv0HwsDAhSaXIte9t6wmrzx/VaJXsmrZQioKQu+0IUw; 25:44gkqXh3IyIoKTMHnZs/dR4jivqnu8YmdGHCK1vqcZWCWAhQHc2m/9lIxlIRg7CN5B0ZQOXknx+todw7IVuTsM4uC8NSjcx8NenDJuyLzBwDMOLOXRyUMxrSKQNIuP1fcW4f6l8a4NCXRlEYzp/vuxyZnlhsFKsQy4PCsznD5mHpYoQtJKv/sGZqNkSUNTFYRQ8rzn/X8A9+n8xb/of55r01gKjYkIxmcM3PB8ei9G4joOwE0rwCNidATxG5qROy6FdszwennQjG7obrJosyJBW1uXI2p/OsQsU/0U4xBGfQ2KFbk951lGacDCcbjh95UeBoQU8aWWpUOuSH01YzAmeo7RFR6FuQNy4uf0KbarNj7NLQlxOlmOjxZt1f0ePss7iarbbua/N9RA37rkM8YAA9Ijd3Eu9+U2klxZtWW+s= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0701MB1719; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 20:fYWtJ1gj3cyF9DLGMv0LwPCXbfgq0aHPjPgV1OjrsxIIKevj/h5muhtjMQQGqe0gdHyAniDzZxTMXfkWYjAyOyCh+zQ6bMphuViCO9zgXi1USmDNAPYiM7WqMikNGklNkzR95r6p3EBoXTcLGAozstDgPCSMne8x2xtTJ/5t3eZ+HTsaWhMr3tX5ydoD0+GY9knttjLWi2CMEzdL0SYg9OVU7iKrczI3+RH57yugUpwUFm1wAd/9jvkvbOK431Mg0YGtPmt72O4+rs0DZ+zfFdz4rCsCadybuCGqvijoJ8BuVDt4T9Gq36Hw/0om4S2FjZg4W+Wos80yt73zpi7ojlQGNPqBFlk59ZqhFqlRLihtWw0Y5JteAjPkCbdjUaX1bIpYXY8DMo4YO4NDm45LxDwDLbehUCLvH62nDgyC39sxu3G8fz4MgCwjKZPbJJwktW1f5jRm/XOBYi9OLbH0/7KETiHN5f63+yybAZOlN3k9mTLYaTzkCciA6zwGfgfcjKEtW6u4nHJndUqQplj4tpIouL1uHuK8JwTbpd7RYSCqvNKZRMrZehK7qU6IBLwf10tE7tiHW+3cd+QpRObt87l6AN9zruGPQVH9f3wHV6A= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:BN3PR0701MB1719; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1719; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 4:xIy2WDNZyrKgLyseXSzNV4+qyJCjmYWbGkjG76WwEgJjkIvPYGBtIncLCw135RKQ/IFUyb6oo4/2ggzvyvCRpRIFQ6mMaHINr74ZUxKUB0wMHPmz5h68jpwJNc5PCDWLGFdkMgOmD2O7uHfd7+oRtGRrtls6mrWXuodBnxCJznydlRXFJ8+YOwBUNN7bEGPwoFvnvMpYSAZ8oi3nG3v7sP5VpITxIzQ3rWhThlurNyrZ7cbjCuNHG3StgLaki9AnL2XI6gXGpDqfne4r5tiuRlJAYU/AE2iPGrRUd113MnSlNIbB3sILU/3Y3KZO5vIH44aZqC6cWb90GMyvcegkbTS8DnS1VegBaJ+iT9FwbqciYp38T84e+ftx3yarxISL X-Forefront-PRVS: 09669DB681 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(199003)(189002)(81166006)(8676002)(81156014)(47776003)(66066001)(36756003)(92566002)(2950100001)(586003)(2351001)(48376002)(76506005)(42186005)(50466002)(4326007)(77096005)(3846002)(6116002)(5003940100001)(53416004)(5004730100002)(105586002)(97736004)(2906002)(5008740100001)(106356001)(189998001)(19580395003)(69596002)(101416001)(110136002)(19580405001)(68736007)(33646002)(76176999)(50986999)(229853001)(50226002)(5009440100003)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1719; H:localhost.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0701MB1719; 23:+VfvYXwAoZIvmI9TxEYhp/dDVBAjRmsOdaYUra3?= =?us-ascii?Q?aayda0fnTuThhs5Oull8SomQJbt75E1WklnVvlAoegiJthpEh+btli2dVo5+?= =?us-ascii?Q?zD+MxgBdNftRhRYWBAJ2dCEiFmESl5uTIHy75h7hnIgAUdc/KgWTzYwatNIv?= =?us-ascii?Q?390UAxBaOMV0x8xsUprJWMOnzTKNJmAN3V0A/Lbz7h6IfpAXj75N/E4sP0l0?= =?us-ascii?Q?8cNhItpGrDjN+o+x//Ld3RwS6oibvqvoDV1MU8zbnT1oUvbS8KvN0UPSVaMK?= =?us-ascii?Q?jz+7iYlqGzApMXhZukGQn/mpSz0SX5KD3JHz2FdAwWdJ/1xK4GmUTpDwvorV?= =?us-ascii?Q?f9UN3ujviKzlv6rQcHdjPmYvXAKyCGfy9q1J8oiCrZAuUvUARXLeSbi/KCHo?= =?us-ascii?Q?s9nbKNtZKFUn68RsigUbQZsEgQ/vmCaJHLchNOQixb1b17P3rWZZQMPszYN4?= =?us-ascii?Q?fDKe0bZJAay90p2BY2eo/5TwnruI8kWYKiHCQ0SPRSaEIwDYt0xNe3vfJLnZ?= =?us-ascii?Q?/0ffBFwIbbKgi93mnnMb9aFaz0+WEYiFPwRVNScTu4zMta6UvnYZGq59A2dt?= =?us-ascii?Q?S3C7yiVN3PUmd33Jj9yTBvw4msXyu/zvyhP2UFeBa5kvgZRKEF4lKOVHzzlD?= =?us-ascii?Q?r2uhk0N3sqvC7Dk7ywAFHlN/J5PzqXdvLCrgrSeRlASh6ji1bJZziG2/h3M6?= =?us-ascii?Q?A/3F8lR/TI0dxrMyQBtgHIBviqCR8qJRn1x7Isty7fbjPlYVN3WSMJakJYcV?= =?us-ascii?Q?S5Wb9LpnvRlnjkKk+9oLf7bsuR2nNHP//ShuhQ+4HAPDOTZQxhcZlVY+CO8e?= =?us-ascii?Q?MjlGODGRYesMy7MmeKjFqVbKIrfYD0Fm5z4A/147EcQSgv7u08EDPA5682kd?= =?us-ascii?Q?h34uU4lohv6sTSNZQh/hTaJ4bQDs1DQ9w/NriodRJqm+AaOVa8UrDxbJoF7w?= =?us-ascii?Q?MLn6qj5DBmda1Ue5X/qtqCeRLF3p1BmkS1kTuNbcBp/SIORke922wjCdLMKn?= =?us-ascii?Q?ln5e7lUXByxYKRNvSvkvWJFbQx+WXCy3KOA+MVluLxo6gIxII63VDr8I2J1R?= =?us-ascii?Q?CejVoKjHIMaGRnHbHaOQ+PTTtIEAN+SpqpIUFXMEgYMk4hG3V+mNC77VfAve?= =?us-ascii?Q?aAKIWKj0JFjl8/MqDR6o44ayp28iU/2RVZ1JRslYsIvi/3DTKV1UVSg=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 5:RvfibDrBBqeQHIdGRhy1sptnc7VIG7gdfznjgHnpaf0Yf0Lje68uhSNS9S3UT70Jz+c4plBZZU8yfE3HCT3XNpciEjzh4pyPj6PYLCdH2QybrtjfYBA2tHDvR/PcGjDus8QPIHjMvcONtDECxNasxA==; 24:sCrAWQrX58vIzFbxUYkAp8dSj9Cs7NaoSceevb7A2VMp50d49o19slvvstKMjUIEbZzrOkWzcqV9sMJ/zuxfPmvq+iBxJrynNmx2cXWsWnQ=; 7:gt5IsPz2kfTvzZZIppEKH7t/Tzg28UcaHwXtaW0b/K4n5inV5Q6DA2X2ROvMBOKxvKWeBiVFWMaqwkVIJ+ZLLiXnUvXL7b66L4iNFyOYmTfrFW9RrM8BDMC5EueSCQV0x7Uhen9AwhSXNiCLeW17NTHBUqvi1WsPKim9EnGGgt5Mm7Ur4g3El21S55dhwq3DwTMpCshdqPuVQ2VtPjG6BSdYxI+JKZLMmSCug/WArN8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2016 16:42:05.5475 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1719 Subject: [dpdk-dev] [PATCH v3 12/20] thunderx/nicvf: add single and multi segment tx functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2016 16:42:11 -0000 Signed-off-by: Jerin Jacob Signed-off-by: Maciej Czekaj Signed-off-by: Kamil Rytarowski Signed-off-by: Zyta Szpak Signed-off-by: Slawomir Rosek Signed-off-by: Radoslaw Biernacki --- drivers/net/thunderx/Makefile | 2 + drivers/net/thunderx/nicvf_ethdev.c | 5 +- drivers/net/thunderx/nicvf_rxtx.c | 256 ++++++++++++++++++++++++++++++++++++ drivers/net/thunderx/nicvf_rxtx.h | 93 +++++++++++++ 4 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 drivers/net/thunderx/nicvf_rxtx.c create mode 100644 drivers/net/thunderx/nicvf_rxtx.h diff --git a/drivers/net/thunderx/Makefile b/drivers/net/thunderx/Makefile index eb9f100..9079b5b 100644 --- a/drivers/net/thunderx/Makefile +++ b/drivers/net/thunderx/Makefile @@ -51,10 +51,12 @@ VPATH += $(SRCDIR)/base # # all source are stored in SRCS-y # +SRCS-$(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD) += nicvf_rxtx.c SRCS-$(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD) += nicvf_hw.c SRCS-$(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD) += nicvf_mbox.c SRCS-$(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD) += nicvf_ethdev.c +CFLAGS_nicvf_rxtx.o += -fno-prefetch-loop-arrays -Ofast # this lib depends upon: DEPDIRS-$(CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD) += lib/librte_eal lib/librte_ether diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c index 35fad4c..b273149 100644 --- a/drivers/net/thunderx/nicvf_ethdev.c +++ b/drivers/net/thunderx/nicvf_ethdev.c @@ -66,7 +66,7 @@ #include "base/nicvf_plat.h" #include "nicvf_ethdev.h" - +#include "nicvf_rxtx.h" #include "nicvf_logs.h" static int nicvf_dev_configure(struct rte_eth_dev *dev); @@ -649,6 +649,9 @@ nicvf_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, (tx_conf->tx_free_thresh == NICVF_DEFAULT_TX_FREE_THRESH ? NICVF_TX_FREE_MPOOL_THRESH : tx_conf->tx_free_thresh); + txq->pool_free = nicvf_multi_pool_free_xmited_buffers; + } else { + txq->pool_free = nicvf_single_pool_free_xmited_buffers; } /* Allocate software ring */ diff --git a/drivers/net/thunderx/nicvf_rxtx.c b/drivers/net/thunderx/nicvf_rxtx.c new file mode 100644 index 0000000..3cf7193 --- /dev/null +++ b/drivers/net/thunderx/nicvf_rxtx.c @@ -0,0 +1,256 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium networks Ltd. 2016. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Cavium networks nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "base/nicvf_plat.h" + +#include "nicvf_ethdev.h" +#include "nicvf_rxtx.h" +#include "nicvf_logs.h" + +static inline void __hot +fill_sq_desc_header(union sq_entry_t *entry, struct rte_mbuf *pkt) +{ + /* Local variable sqe to avoid read from sq desc memory*/ + union sq_entry_t sqe; + uint64_t ol_flags; + + /* Fill SQ header descriptor */ + sqe.buff[0] = 0; + sqe.hdr.subdesc_type = SQ_DESC_TYPE_HEADER; + /* Number of sub-descriptors following this one */ + sqe.hdr.subdesc_cnt = pkt->nb_segs; + sqe.hdr.tot_len = pkt->pkt_len; + + ol_flags = pkt->ol_flags & NICVF_TX_OFFLOAD_MASK; + if (unlikely(ol_flags)) { + /* L4 cksum */ + if (ol_flags & PKT_TX_TCP_CKSUM) + sqe.hdr.csum_l4 = SEND_L4_CSUM_TCP; + else if (ol_flags & PKT_TX_UDP_CKSUM) + sqe.hdr.csum_l4 = SEND_L4_CSUM_UDP; + else + sqe.hdr.csum_l4 = SEND_L4_CSUM_DISABLE; + sqe.hdr.l4_offset = pkt->l3_len + pkt->l2_len; + + /* L3 cksum */ + if (ol_flags & PKT_TX_IP_CKSUM) { + sqe.hdr.csum_l3 = 1; + sqe.hdr.l3_offset = pkt->l2_len; + } + } + + entry->buff[0] = sqe.buff[0]; +} + +void __hot +nicvf_single_pool_free_xmited_buffers(struct nicvf_txq *sq) +{ + int j = 0; + uint32_t curr_head; + uint32_t head = sq->head; + struct rte_mbuf **txbuffs = sq->txbuffs; + void *obj_p[NICVF_MAX_TX_FREE_THRESH] __rte_cache_aligned; + + curr_head = nicvf_addr_read(sq->sq_head) >> 4; + while (head != curr_head) { + if (txbuffs[head]) + obj_p[j++] = txbuffs[head]; + + head = (head + 1) & sq->qlen_mask; + } + + rte_mempool_put_bulk(sq->pool, obj_p, j); + sq->head = curr_head; + sq->xmit_bufs -= j; + NICVF_TX_ASSERT(sq->xmit_bufs >= 0); +} + +void __hot +nicvf_multi_pool_free_xmited_buffers(struct nicvf_txq *sq) +{ + uint32_t n = 0; + uint32_t curr_head; + uint32_t head = sq->head; + struct rte_mbuf **txbuffs = sq->txbuffs; + + curr_head = nicvf_addr_read(sq->sq_head) >> 4; + while (head != curr_head) { + if (txbuffs[head]) { + rte_pktmbuf_free_seg(txbuffs[head]); + n++; + } + + head = (head + 1) & sq->qlen_mask; + } + + sq->head = curr_head; + sq->xmit_bufs -= n; + NICVF_TX_ASSERT(sq->xmit_bufs >= 0); +} + +static inline uint32_t __hot +nicvf_free_tx_desc(struct nicvf_txq *sq) +{ + return ((sq->head - sq->tail - 1) & sq->qlen_mask); +} + +/* Send Header + Packet */ +#define TX_DESC_PER_PKT 2 + +static inline uint32_t __hot +nicvf_free_xmittted_buffers(struct nicvf_txq *sq, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) +{ + uint32_t free_desc = nicvf_free_tx_desc(sq); + + if (free_desc < nb_pkts * TX_DESC_PER_PKT || + sq->xmit_bufs > sq->tx_free_thresh) { + + if (unlikely(sq->pool == NULL)) + sq->pool = tx_pkts[0]->pool; + + sq->pool_free(sq); + /* Freed now, let see the number of free descs again */ + free_desc = nicvf_free_tx_desc(sq); + } + return free_desc; +} + +uint16_t __hot +nicvf_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) +{ + int i; + uint32_t free_desc; + uint32_t tail; + struct nicvf_txq *sq = tx_queue; + union sq_entry_t *desc_ptr = sq->desc; + struct rte_mbuf **txbuffs = sq->txbuffs; + struct rte_mbuf *pkt; + uint32_t qlen_mask = sq->qlen_mask; + + tail = sq->tail; + free_desc = nicvf_free_xmittted_buffers(sq, tx_pkts, nb_pkts); + + for (i = 0; i < nb_pkts && (int)free_desc >= TX_DESC_PER_PKT; i++) { + pkt = tx_pkts[i]; + + txbuffs[tail] = NULL; + fill_sq_desc_header(desc_ptr + tail, pkt); + tail = (tail + 1) & qlen_mask; + + txbuffs[tail] = pkt; + fill_sq_desc_gather(desc_ptr + tail, pkt); + tail = (tail + 1) & qlen_mask; + free_desc -= TX_DESC_PER_PKT; + } + + sq->tail = tail; + sq->xmit_bufs += i; + rte_wmb(); + + /* Inform HW to xmit the packets */ + nicvf_addr_write(sq->sq_door, i * TX_DESC_PER_PKT); + return i; +} + +uint16_t __hot +nicvf_xmit_pkts_multiseg(void *tx_queue, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) +{ + int i, k; + uint32_t used_desc, next_used_desc, used_bufs, free_desc, tail; + struct nicvf_txq *sq = tx_queue; + union sq_entry_t *desc_ptr = sq->desc; + struct rte_mbuf **txbuffs = sq->txbuffs; + struct rte_mbuf *pkt, *seg; + uint32_t qlen_mask = sq->qlen_mask; + uint16_t nb_segs; + + tail = sq->tail; + used_desc = 0; + used_bufs = 0; + + free_desc = nicvf_free_xmittted_buffers(sq, tx_pkts, nb_pkts); + + for (i = 0; i < nb_pkts; i++) { + pkt = tx_pkts[i]; + + nb_segs = pkt->nb_segs; + + next_used_desc = used_desc + nb_segs + 1; + if (next_used_desc > free_desc) + break; + used_desc = next_used_desc; + used_bufs += nb_segs; + + txbuffs[tail] = NULL; + fill_sq_desc_header(desc_ptr + tail, pkt); + tail = (tail + 1) & qlen_mask; + + txbuffs[tail] = pkt; + fill_sq_desc_gather(desc_ptr + tail, pkt); + tail = (tail + 1) & qlen_mask; + + seg = pkt->next; + for (k = 1; k < nb_segs; k++) { + txbuffs[tail] = seg; + fill_sq_desc_gather(desc_ptr + tail, seg); + tail = (tail + 1) & qlen_mask; + seg = seg->next; + } + } + + sq->tail = tail; + sq->xmit_bufs += used_bufs; + rte_wmb(); + + /* Inform HW to xmit the packets */ + nicvf_addr_write(sq->sq_door, used_desc); + return nb_pkts; +} diff --git a/drivers/net/thunderx/nicvf_rxtx.h b/drivers/net/thunderx/nicvf_rxtx.h new file mode 100644 index 0000000..3c51432 --- /dev/null +++ b/drivers/net/thunderx/nicvf_rxtx.h @@ -0,0 +1,93 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium networks Ltd. 2016. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Cavium networks nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __THUNDERX_NICVF_RXTX_H__ +#define __THUNDERX_NICVF_RXTX_H__ + +#include + +#define NICVF_TX_OFFLOAD_MASK (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK) + +#ifndef __hot +#define __hot __attribute__((hot)) +#endif + +#if RTE_BYTE_ORDER == RTE_BIG_ENDIAN +static inline uint16_t __attribute__((const)) +nicvf_frag_num(uint16_t i) +{ + return (i & ~3) + 3 - (i & 3); +} + +static inline void __hot +fill_sq_desc_gather(union sq_entry_t *entry, struct rte_mbuf *pkt) +{ + /* Local variable sqe to avoid read from sq desc memory*/ + union sq_entry_t sqe; + + /* Fill the SQ gather entry */ + sqe.buff[0] = 0; sqe.buff[1] = 0; + sqe.gather.subdesc_type = SQ_DESC_TYPE_GATHER; + sqe.gather.ld_type = NIC_SEND_LD_TYPE_E_LDT; + sqe.gather.size = pkt->data_len; + sqe.gather.addr = rte_mbuf_data_dma_addr(pkt); + + entry->buff[0] = sqe.buff[0]; + entry->buff[1] = sqe.buff[1]; +} + +#else + +static inline uint16_t __attribute__((const)) +nicvf_frag_num(uint16_t i) +{ + return i; +} + +static inline void __hot +fill_sq_desc_gather(union sq_entry_t *entry, struct rte_mbuf *pkt) +{ + entry->buff[0] = (uint64_t)SQ_DESC_TYPE_GATHER << 60 | + (uint64_t)NIC_SEND_LD_TYPE_E_LDT << 58 | + pkt->data_len; + entry->buff[1] = rte_mbuf_data_dma_addr(pkt); +} +#endif + +uint16_t nicvf_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts, uint16_t pkts); +uint16_t nicvf_xmit_pkts_multiseg(void *txq, struct rte_mbuf **tx_pkts, + uint16_t pkts); + +void nicvf_single_pool_free_xmited_buffers(struct nicvf_txq *sq); +void nicvf_multi_pool_free_xmited_buffers(struct nicvf_txq *sq); + +#endif /* __THUNDERX_NICVF_RXTX_H__ */ -- 2.5.5