From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-eopbgr680050.outbound.protection.outlook.com [40.107.68.50]) by dpdk.org (Postfix) with ESMTP id 537895958 for ; Mon, 13 Jun 2016 15:57:33 +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=Bcp3HsGcSktajT9l1rZu09QDyJYum0u4m5EAb/62mBo=; b=BVQveXHgsePrwYsjDVIWQ/xOdpki8owd9/vMsPqJ/t2uXyZOQnvRCCI2Up9WPmJWW1cMA2gPpt92vnRHCtigPCr7jhHATq3WERWalcZEo2dNTlA8wgu3ZjVhMbna3vhr1RYVGjuikwD31haIxZc6lc8BryMgwSmoNL3LIWDyCC8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@cavium.com; Received: from localhost.localdomain.localdomain (171.48.21.3) by BN3PR0701MB1717.namprd07.prod.outlook.com (10.163.39.16) with Microsoft SMTP Server (TLS) id 15.1.517.8; Mon, 13 Jun 2016 13:57:27 +0000 From: Jerin Jacob To: CC: , , , Jerin Jacob , Maciej Czekaj , Kamil Rytarowski , Zyta Szpak , Slawomir Rosek , Radoslaw Biernacki Date: Mon, 13 Jun 2016 19:25:36 +0530 Message-ID: <1465826143-22159-13-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465826143-22159-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1465317632-11471-2-git-send-email-jerin.jacob@caviumnetworks.com> <1465826143-22159-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [171.48.21.3] X-ClientProxiedBy: BM1PR01CA0031.INDPRD01.PROD.OUTLOOK.COM (10.163.198.166) To BN3PR0701MB1717.namprd07.prod.outlook.com (10.163.39.16) X-MS-Office365-Filtering-Correlation-Id: 6e0c9c1e-fb19-4a44-7ae4-08d39392a999 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 2:x/irNgH6dEva1MFOINSDFEYMii7KU7/RlNeXboDBfOTek2WPpOlU/3YrHzI4FANIyIcwj7ywHNE5VHBw5COY+z3bLvAYH7V4jAYIZsjSXQ3yZUT7vQvpKsJn20V0kaqEI+uZLKW45RWtI2wemGnqF+eZcb54yKjDKYiwzuUMsDNEwmhyP1xmM136/lpe4Glv; 3:yNk7s1eqZaeHzpHnR4ybHgFJpY9MbrQc+/1gJLVtnklnk2PshiGkkJDX9iVyiEwoo9EEqHxG1j6kKMp3m/RWw8KpfxhFp9jajR/wHVFReCYX6EhOyLomTu0OfzM1F1bf; 25:KxSsf6+4vtw3azfuM+qbCYApKnqqQgcwHAFZkttKUSxC7Sq2Y9CDxRv3I+E1VahSazoGeuabp/NXp4iT3ohz9V4vIX6nPXDFh4qDxNbACBL8dSZm8KUdWl8TxmxtjTrv8FYrlinasMeeqxwzUrnIqwP9l4bvfKJT41wMC5a0xsh+oC4uPt/wljUVNyuvNRPb9h1wRtvFQrzXBVe7KjVEu8KxFMmZInP4hJkg1T2dV1FR+GnerrXBOhdTT81dW5/d5spua8qnvNE318PrsvxIFQXDHmC0DGsZNTOaKcAVTMe3OcQR33K8DXaRzCsTVIF/vI6ydBeqQ41FPoNYIPS3sKdYJ9gJhFt7BRB7euXUiyLrPq/xfkYFpPE8JcOP1/QqFtYbGWv4XqOO/QtVVBmmn+0O3j1KGDqZ+ssTlgLFinw= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0701MB1717; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 20:tydWpFD4QyexBoz/PdqCNN/FAF8EKIYWtnEvvTH86kMkwEL+kNC0sZ4bYH3os7O/BaEHtBzasjmXKXKeTtq++ZphrR0E+nqBppYEVD8GHpZc1H6yD4/JLst/pSS/HauXbRhbP2ih8UX779sIlAA2luPhc45YHGf/Z1XXPr9QjjiZxTXRKHwqnxQBBsOQWJRGWicLy81SS4rj2Y9eEWvjFSBXPZX2n9/cb5B7CnMJHmqVwIMcKq8hHTyX/T1bUFbXe9XIKfPPn5BrZq5GH7H4HzlmFw1mJDz6IeZLZVN7oOHMvxs/MShN3iCEwrTtwqMTTr+ex8FDsW5Yb9YxC5pHgv1cathyB4MfQJO1i6HpZSbj39l1fmrgo5QRGln93QIUhY6ve9Tfxl/utHIzcWmX4GlHSna2FL+hOJmadrwrXhljOXXIBAFcqERmirCCVtr8MZhSOBtX+YAOVsZTBtTz9+odtpuwZuAK+CGOwJCtiJsg7X6vWYmrODAriE5WovYNgSXD99sJs3Z92hIqwp8imFrqUA/3Cop2zHiGt/qonYoAHcgkrbW0yxdAUuxV/JEDJ3OnrRMvP1pJ+5z2kxHnAyaEsgcu4fXHkkPReqcchmE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BN3PR0701MB1717; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1717; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 4:fy6nvmnYYv8Edx7eg6VbJx4PNQsZ0CJjfkCP7jCGlRmZW8IXy3sYIS98jDxRXfJPRN+qdsx0Y1J5pNL9O8XxqObf4oj1GeD+WKsHBCrX4RmHIXawQgZP5snkF/PsGIbr44hqAGAOIqloLnEGXQc8rTurgrUv2X22lx9yF37hb3nC352UfN84Lqao3teC0bjCSUBdGg1jnXKsghLnevYtJLi872SpCWgshWmMBKdR4CIHcvBZ3J57EjCPSWPMrGBP3vRvzqlweKkXVnjValjroeuuwR4oQ401kAcxh1NgZqXwr79o+cDuWCnTuKDNeycvYqFQtZLkWB3NS4tSac4+AuzJI9BTynSS0kDAxILrBVt92i12mFWU+6LfQ5Wkr7u/ X-Forefront-PRVS: 0972DEC1D9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(50466002)(48376002)(101416001)(42186005)(50986999)(92566002)(76176999)(105586002)(106356001)(33646002)(2351001)(5004730100002)(47776003)(66066001)(36756003)(586003)(3846002)(6116002)(19580405001)(19580395003)(77096005)(8676002)(2906002)(81156014)(81166006)(4326007)(189998001)(97736004)(2950100001)(110136002)(5008740100001)(229853001)(5003940100001)(50226002)(68736007); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1717; H:localhost.localdomain.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0701MB1717; 23:vkEXuyuXnufSPA4S3AWh71+5NX3ljvLe4B80hlN?= =?us-ascii?Q?fbXGGY5ghNf1E1NtOfb7pVPOmhMfuR5mn1elYFpNTssdMGY5Kkm2meAJWQS6?= =?us-ascii?Q?6tJTObQVp9dNRed3mqxKwZ2BDN2E13Bks97Db5guSFhD/RVzpCaCzIQjyp60?= =?us-ascii?Q?gswbYBD3Ck2QXg70Eeca2GDlY5/7iQWhkkGgrjnXcMQBoa6e9MU6qMLtnz5x?= =?us-ascii?Q?tAmaE9aEHwVdz3yJed57SGPayVBUJXN3QPM2TK82ddhA9ov1NE0QmnCwggoF?= =?us-ascii?Q?lEGFUJaBwm6YegqN5GRC2fEfMvAMQzsyGxtG0StWC1xmaz1enrxDE6xd5Snm?= =?us-ascii?Q?ZDWQK4GuCXE+OAMSEHGyb+2XlCDAWwqDM2dzDU+QAX9u6wu7eTjEhM/0+b3X?= =?us-ascii?Q?ZrYJof62ylcXk/2YzFDTQP43DcApSJIlyEKbHzqLz9qSkPO0jt0FdHMo3FyS?= =?us-ascii?Q?ndhz3XUZLa7dUY2F+SuOimLz27E7dba0l2Q7Fdp4z0bByivH1v2Fjqp/b2pG?= =?us-ascii?Q?Wr0QZTwdw599aY1FHJVkbn0L3mEpba0BFvBEFq5AcKCamVx8GEUrgHnVpXca?= =?us-ascii?Q?pWM9Q0sTzEjiDxoOYCv/zVrE8j45UXi89dTSObHfgtp3HLo9zEMShuNfJoOE?= =?us-ascii?Q?C+Qea60wlsFNEJUcjcPePLkJbwdMp4xr72l22yu3rA5dlgdu9zHSPKPPCxFI?= =?us-ascii?Q?zSZo+1xKGYbfGSMGSYPmfvPgSKNm2fXwZmjRfjjlbefoOhnwRrosmTaygIj7?= =?us-ascii?Q?Y+McsYDqD3IiK2qP5cX2ULDIBwNRidXKelC6EO3ZRgydKJnUE8h6b57NdSZr?= =?us-ascii?Q?IE8/5Gcqkv8BYlDn2xDDMmEgK1MuHn/Yt+3QxA8Aa8k3L0lKA2l6Ww8SC5Xz?= =?us-ascii?Q?Uc4wHckmP24PqeUvGMqxOdl1i5WRqSZ1hMvWt6F0sgyBQccKxatt7sw89KBV?= =?us-ascii?Q?lS0UDArfnye5Jof53EPQSUdn4E6+9Rf6NMlKvL/yqOGye+XIceUoC1ucRIIy?= =?us-ascii?Q?7G3Av7zh7rgJGJCESUMvlsGTWv0/qdjORicRehEalCq1emNf7B2tMvxcDF30?= =?us-ascii?Q?o363hHcCreJKpVuRbXOzBZzTeZjwb?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 6:8m/LuEig7A2TshEgAucIxDjWW9ik6rx1rXKEfQFbGQI/PUd3C2RhVwj43mlRJ4jR1EApImIJ8BtckJBJ1brB/YUz5UhqRUYy9QsZ0wYC6vu8gPI5WrUuKwOOI31Hk7fvx880L9KqIb3e4VmYtqtKpo0loca1PasCdtM0SwaycRDI+3MQt1TLXNxsEo0Njh1CGe/LUO5vs1SWf73PFtjIQYyugCI+HqjYPINjar+rOAm97ZfwIYyWDqpjRLveqi8wlQnya5OQlOGsTlfjKqRjQH8PuyErxcfYBtTgApzIn2E=; 5:N1z9jKSBdpXDlDzDHfJpG0Wog2S+eGMQlCAiVoQ840n1wKLXMid1i9WcI0jF8v9wMNTaAT8+XQXaAdcODt3fW8eqwsnJihKPdglaZyJFfJB7Tqfate0ApD8q3smFIX/Rd0X/KsFJiVhLwvH2mSIHwA==; 24:jKKVcA7/Y2QKBajc0B9DcLiTDgxq4lYzffxMI9Yvcu/ArOWUc6Md+nNZ2YwzO5l1hImpsVylzt/f09mAHc78iOoW7p2YO/KjXMQNFYxauFg=; 7:yd/4U/7aankBMIJG4p2IUjuWz1V9x6k5smrfpSFGpaV5M6+K1PDNPFvXyKVDyrZADm1A7WE5buBLxh0y4d6u+Y5kdrO7whhMfh2pXRMaay5VMesZLHGfPiw8a2sKOYL9lPWvtOGSWRkKySDDE0YxusRQmLB3aXFJMmnjNtQhFzauR6QKXxwk1yREu2TBIsAXuORnwifKZp8TS/jB0FtjNjWEsCULC7R3bXJOtcI16JE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2016 13:57:27.1217 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1717 Subject: [dpdk-dev] [PATCH v4 12/19] net/thunderx: 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: Mon, 13 Jun 2016 13:57:34 -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 | 255 ++++++++++++++++++++++++++++++++++++ drivers/net/thunderx/nicvf_rxtx.h | 93 +++++++++++++ 4 files changed, 354 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 19ad85a..15f5cfc 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 inline int @@ -617,6 +617,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..88a5152 --- /dev/null +++ b/drivers/net/thunderx/nicvf_rxtx.c @@ -0,0 +1,255 @@ +/* + * 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_xmitted_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_xmitted_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_xmitted_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..b1fdc69 --- /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