From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03hn0234.outbound.protection.outlook.com [104.47.9.234]) by dpdk.org (Postfix) with ESMTP id 833E22B86 for ; Sun, 22 Apr 2018 13:30:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=UkSoGGpfl1D/r9PhZPPNjcupjZGZdSObUMMnp0Zquek=; b=bZDRbKZeUvo9HCBBOfL6XR3iqNew/DPHmcAypCVY1dLb2rd90TinmU6cNWWLQdhu1J46Vnq2Oh3CP/Q2j+i93xoVAyZwo0pqkhxc28GrzzviU54Ciw9s+RxINL5h2DPZEVGIknODUg/f3e9SaxpMvH7KZsg4rqLvPcgnFdOTPg4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by DB6PR0501MB2311.eurprd05.prod.outlook.com (2603:10a6:4:4c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Sun, 22 Apr 2018 11:30:29 +0000 From: Ophir Munk To: dev@dpdk.org, Pascal Mazon Cc: Thomas Monjalon , Olga Shern , Ophir Munk Date: Sun, 22 Apr 2018 11:30:11 +0000 Message-Id: <1524396611-22391-3-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1524396611-22391-1-git-send-email-ophirmu@mellanox.com> References: <1523313192-18048-3-git-send-email-ophirmu@mellanox.com> <1524396611-22391-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1PR07CA0022.eurprd07.prod.outlook.com (2603:10a6:7:67::32) To DB6PR0501MB2311.eurprd05.prod.outlook.com (2603:10a6:4:4c::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DB6PR0501MB2311; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2311; 3:VkeM6dpeCY3Loz2FvZJL3f/q0GZjkP+O0AtxypPDq4VkDNHioeE6wiegrL2gr4zRUV8SPZpjhJJ/sXgNjwW4/D4SGJTrQM1SVYYX/myx4+IMGjKq7M5Z0JLp5lCl8W18J16u3tJ+CsaFsF4BepNucUTKNW9z7s/orWQLIKOf2DoYPVwHdbV+tIDNUjQcmrAozAIPhSwZc6mKp6ZY4F2v31QrDR1+Xf/23gn/nDZg5bsHViBOTciz8WVJiXl/AzlV; 25:HYz2IeFpXFaAq9jCommVNzAoqp9hj/b6sCQsXPJ04P/Z7dEpOiW5L8f27EPlUNRvBz43RzyAlQVVgJL7WxUYr1HMnFjxEIRRuThw1xFVOEu9XcmOf1VYt9g1MczbWnQEqucmY2VXktGxdOGjavEWMP22grxGn0VB+DSHJu7smc9RR1MShw4F6JGZIKqQuX3yl1794DPqSbFB18j/0sKpLgw8jJiwp9NFnAZnP6DKFnY6qnEkj+grrbNkFXvcENpiPrIC2SfCaUQ0SAl3kG8LdwgTYY1FW8FLR1Br5uZT8UFKi38zyCBAvZ0rY8AEDRe/qqvgftF7fGccIHAvsnKGEg==; 31:lBD5uHM12rxxSaqwAcGx6k7NrHeBaiqFs6mHbEISg6BaS4GixzgSvH03HzBNP1umeWXtzSF1OC8HKB69JEvft9sbsbxtHsmyLKddGB4+RvAsES5O0ZWPePTiY+Gx/JTE5/VPO755zMsqVa/9YWr2Pgo07GeXfBqlOPkoP4RY4kGOYZStAsK8ovPSXTjA6f3cnolkYUW095qzCpC2GUJjAOa0HJAvwC3dSXItBra/7oU= X-MS-TrafficTypeDiagnostic: DB6PR0501MB2311:|DB6PR0501MB2311: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2311; 20:gfGhc8xXpAVZ2KK/r3U7xMyjd95fY4el/SCxIhJZ4FwOTRhOnNucy+Tm4SdbD9zXhcce5HQVBAmz+MM2rJbFs9NEbvHmmJvtHKigyIaM7l+k9w8UOhgYiAY6BQq/DS7HVBasiXA9moZOSPOmM/sQYZpaUNqXpdzoyA/pE5gWWRxIECTbpmhVVsQeukOyJw07/2NnnTsxbKHHuMDUESItXK+j5De2ZcpFs1xSFpHjl+ew4pvyuaP1jyWpV5ILwUf6o66XArmzstRDevXa8r5VcJp1+uXeptVMdMTE9SXeR6VZSK6VTmpXfbYk4A0VdeVuQviBOgtR1vfLq+QePQ1wlU0NsrD2vm4VXvUNjZ6iJWnx1cjKrbFXyAV4yKt/mB6S7Qd/JjeTkcoP/AL8+seaulq+XRgSoWXByVlBEYlcOX4HxA/JCyDdp7gBzpMEkU+EQNN65wuieVzALaNDB25Ass8bo3IPOiepNjf/uoo4EaKhMyE22lKLOz9GWvcofvSo; 4:b30VU1Df635QhlSgsSIay2glj/Axi2htET8MC6Kuh2v6TPRUDFUSbLej4wq+MyXlHCy+ACI2ctXmjE7jAaGtZG0vda811HjGP0FKpGH4lm4p28R/AUH21SWq21fuT0eRUN9ZhjYAFoiycsyQlPtag0qXdMacFQzauud3xys7BFbeNUBzClXb8mJk+hch7qZEnNj2L/jj8+JAXCYhpuynNYoXfLyEXFZpyZukUBjGYhj20QEKu3xWhUA+kFvyi4pM2nFy3JhZOhhQqp++80LUFneRaZvo7Kp+3sLUtXojAE7Gd9C9H5dTU+d7vTtKheTv X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(66839620246622); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231232)(2232076)(944501410)(52105095)(93006095)(93001095)(6055026)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(6072148)(201708071742011); SRVR:DB6PR0501MB2311; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0501MB2311; X-Forefront-PRVS: 0650714AAA X-Forefront-Antispam-Report: SFV:SPM; SFS:(10009020)(39380400002)(39860400002)(366004)(396003)(376002)(346002)(305945005)(446003)(50226002)(16586007)(48376002)(54906003)(316002)(66066001)(47776003)(5660300001)(50466002)(26005)(478600001)(86362001)(186003)(36756003)(6916009)(8676002)(16526019)(6666003)(81166006)(4720700003)(575784001)(25786009)(11346002)(55016002)(53936002)(7696005)(2906002)(21086003)(3846002)(8936002)(7736002)(2616005)(4326008)(76176011)(52116002)(107886003)(59450400001)(33026002)(6116002)(386003)(956004)(51416003)(476003)(59010400001); DIR:OUT; SFP:1501; SCL:5; SRVR:DB6PR0501MB2311; H:mellanox.com; FPR:; SPF:None; LANG:en; MLV:ovr; PTR:InfoNoRecords; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0501MB2311; 23:zZNiA17L4RJHXyp6BcdMOrEjGL0WfqWOll74/2c?= =?us-ascii?Q?3ANYbOVcKaeqXWixyNJFC5rYPTuqmGEty1iLnlDBOkKNmbWTiAXZ7nsE3qj+?= =?us-ascii?Q?gtm/En6KVCCc3q5lqSYPdt7wNuwaLjd55BuJm2L3H2bPQnSA4Ez3DdQc0WT3?= =?us-ascii?Q?Hl3crRkQLrCUjPUPcSsZnnrm6KKYdRwXHYagBF76j3olCzJalQiMTVr+hFNz?= =?us-ascii?Q?MOQBIjSg+f330kcsKLnktIjvnz6tsa6VqZRl/oT+puD8vhv0lcOrJ+lkY6de?= =?us-ascii?Q?vCtysMYo8YL6nqJWxYV94ijKC7kurm4Te+PkR0dWQ3GdX/DW206+cztoR0YO?= =?us-ascii?Q?LqacWOEI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DhzCrZYdpN0b76NK5uQc06tTzsnTjfNYYPeEYAYk34hWDWQbSpm7KMiBFcc9cm75D2LFFQYmp3Q+mi6cpfn75/mHlD6IurU4x4tzKr5DCPQldBicKIthANm4B3VoRrUjQKyU71OcNDW7IuvgYMVxh23jzwKqJpVrNX9ZxboOWU+99Pe/TONq94Am5UpGx3gmPZYjqedas9bc/yczBUis7SxJYTr+Hm/J+xe/k2S6XEes7VzP1F/cmFe1AUNqdOThntzB13kcDdD91f4E1lIpp4cG1abO+Q2A/mofRV3/cVU7Y/TpoJbQ66l7ThuwogZmv4r0+QNRFei4Zz1WPNZ4VIIKZlOGcm+uc4tlGTRuD7zLkGhss7QDDtDIxp28l4+z/tCDEkU7pxnH1+AW8= SpamDiagnosticOutput: 1:22 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2311; 7:GOWMFzhlAWr8b80RCXreQz1rirOPUr4DvQ0XZfpDHdbG/1qDlV3gN2KwLc/phRJkkZ50MB9Ym4eXINMxmvJN6299Puh4V8DqJ09C54CvUONrJLOVdeR2v9Vpo1KzdmG+PPYFkN9TQi+QjxUTJOICHIEsKMfGicAPXjlcgK/10pJmvXKSv+603aKp+vus+l4gG+Y4i8715tvQdM+Mk4md/1X6F9boHGchswgezdFkQ1WHNYAQ5C+89ax7YSFDCUEt X-MS-Office365-Filtering-Correlation-Id: 17497ba1-4c16-42cb-35cc-08d5a8447424 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2018 11:30:29.0534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17497ba1-4c16-42cb-35cc-08d5a8447424 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0501MB2311 Subject: [dpdk-dev] [PATCH v2 2/2] net/tap: support TSO (TCP Segment Offload) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Apr 2018 11:30:41 -0000 This commit implements TCP segmentation offload in TAP. librte_gso library is used to segment large TCP payloads (e.g. packets of 64K bytes size) into smaller MTU size buffers. By supporting TSO offload capability in software a TAP device can be used as a failsafe sub device and be paired with another PCI device which supports TSO capability in HW. For more details on librte_gso implementation please refer to dpdk documentation. The number of newly generated TCP TSO segments is limited to 64. Signed-off-by: Ophir Munk --- drivers/net/tap/Makefile | 2 +- drivers/net/tap/rte_eth_tap.c | 159 +++++++++++++++++++++++++++++++++++------- drivers/net/tap/rte_eth_tap.h | 4 ++ mk/rte.app.mk | 4 +- 4 files changed, 139 insertions(+), 30 deletions(-) diff --git a/drivers/net/tap/Makefile b/drivers/net/tap/Makefile index ccc5c5f..3243365 100644 --- a/drivers/net/tap/Makefile +++ b/drivers/net/tap/Makefile @@ -24,7 +24,7 @@ CFLAGS += -I. CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_hash -LDLIBS += -lrte_bus_vdev +LDLIBS += -lrte_bus_vdev -lrte_gso CFLAGS += -DTAP_MAX_QUEUES=$(TAP_MAX_QUEUES) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index d77a64f..fe62ab3 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -408,7 +409,8 @@ tap_tx_offload_get_port_capa(void) return DEV_TX_OFFLOAD_MULTI_SEGS | DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM | - DEV_TX_OFFLOAD_TCP_CKSUM; + DEV_TX_OFFLOAD_TCP_CKSUM | + DEV_TX_OFFLOAD_TCP_TSO; } static uint64_t @@ -417,7 +419,8 @@ tap_tx_offload_get_queue_capa(void) return DEV_TX_OFFLOAD_MULTI_SEGS | DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM | - DEV_TX_OFFLOAD_TCP_CKSUM; + DEV_TX_OFFLOAD_TCP_CKSUM | + DEV_TX_OFFLOAD_TCP_TSO; } static bool @@ -500,23 +503,15 @@ tap_tx_l3_cksum(char *packet, uint64_t ol_flags, unsigned int l2_len, } } -/* Callback to handle sending packets from the tap interface - */ -static uint16_t -pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) +static inline void +tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, + struct rte_mbuf **pmbufs, uint16_t l234_hlen, + uint16_t *num_packets, unsigned long *num_tx_bytes) { - struct tx_queue *txq = queue; - uint16_t num_tx = 0; - unsigned long num_tx_bytes = 0; - uint32_t max_size; int i; - if (unlikely(nb_pkts == 0)) - return 0; - - max_size = *txq->mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN + 4); - for (i = 0; i < nb_pkts; i++) { - struct rte_mbuf *mbuf = bufs[num_tx]; + for (i = 0; i < num_mbufs; i++) { + struct rte_mbuf *mbuf = pmbufs[i]; struct iovec iovecs[mbuf->nb_segs + 2]; struct tun_pi pi = { .flags = 0, .proto = 0x00 }; struct rte_mbuf *seg = mbuf; @@ -524,17 +519,13 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) int proto; int n; int j; - int k; /* first index in iovecs for copying segments */ - uint16_t l234_hlen; /* length of layers 2,3,4 headers */ + int k; /* current index in iovecs for copying segments */ uint16_t seg_len; /* length of first segment */ uint16_t nb_segs; uint16_t *l4_cksum; /* l4 checksum (pseudo header + payload) */ uint32_t l4_raw_cksum = 0; /* TCP/UDP payload raw checksum */ uint16_t l4_phdr_cksum = 0; /* TCP/UDP pseudo header checksum */ - /* stats.errs will be incremented */ - if (rte_pktmbuf_pkt_len(mbuf) > max_size) - break; l4_cksum = NULL; /* * TUN and TAP are created with IFF_NO_PI disabled. @@ -567,9 +558,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) l234_hlen = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; if (seg_len < l234_hlen) break; - - /* To change checksums, work on a - * copy of l2, l3 l4 headers. + /* To change checksums, work on a * copy of l2, l3 + * headers + l4 pseudo header */ rte_memcpy(m_copy, rte_pktmbuf_mtod(mbuf, void *), l234_hlen); @@ -609,13 +599,78 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) n = writev(txq->fd, iovecs, j); if (n <= 0) break; + (*num_packets)++; + (*num_tx_bytes) += rte_pktmbuf_pkt_len(mbuf); + } +} + +/* Callback to handle sending packets from the tap interface + */ +static uint16_t +pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) +{ + struct tx_queue *txq = queue; + uint16_t num_tx = 0; + uint16_t num_packets = 0; + unsigned long num_tx_bytes = 0; + uint16_t tso_segsz = 0; + uint16_t hdrs_len; + uint32_t max_size; + int i; + uint64_t tso; + int ret; + + if (unlikely(nb_pkts == 0)) + return 0; + + struct rte_mbuf *gso_mbufs[MAX_GSO_MBUFS]; + max_size = *txq->mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN + 4); + for (i = 0; i < nb_pkts; i++) { + struct rte_mbuf *mbuf_in = bufs[num_tx]; + struct rte_mbuf **mbuf; + uint16_t num_mbufs; + + tso = mbuf_in->ol_flags & PKT_TX_TCP_SEG; + if (tso) { + struct rte_gso_ctx *gso_ctx = &txq->gso_ctx; + assert(gso_ctx != NULL); + /* gso size is calculated without ETHER_CRC_LEN */ + hdrs_len = mbuf_in->l2_len + mbuf_in->l3_len + + mbuf_in->l4_len; + tso_segsz = mbuf_in->tso_segsz + hdrs_len; + if (unlikely(tso_segsz == hdrs_len) || + tso_segsz > max_size) { + txq->stats.errs++; + break; + } + gso_ctx->gso_size = tso_segsz; + ret = rte_gso_segment(mbuf_in, /* packet to segment */ + gso_ctx, /* gso control block */ + (struct rte_mbuf **)&gso_mbufs, /* out mbufs */ + RTE_DIM(gso_mbufs)); /* max tso mbufs */ + + /* ret contains the number of new created mbufs */ + if (ret < 0) + break; + mbuf = gso_mbufs; + num_mbufs = ret; + } else { + /* stats.errs will be incremented */ + if (rte_pktmbuf_pkt_len(mbuf_in) > max_size) + break; + + mbuf = &mbuf_in; + num_mbufs = 1; + } + + tap_write_mbufs(txq, num_mbufs, mbuf, hdrs_len, + &num_packets, &num_tx_bytes); num_tx++; - num_tx_bytes += mbuf->pkt_len; - rte_pktmbuf_free(mbuf); + rte_pktmbuf_free(mbuf_in); } - txq->stats.opackets += num_tx; + txq->stats.opackets += num_packets; txq->stats.errs += nb_pkts - num_tx; txq->stats.obytes += num_tx_bytes; @@ -1064,32 +1119,77 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) return 0; } +#define TAP_GSO_MBUFS_NUM 64 +#define TAP_GSO_MBUF_SEG_SIZE 128 + +static int +tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) +{ + uint32_t gso_types; + char pool_name[64]; + + /* Create private mbuf pool with 128 bytes size per mbuf + * use this pool for both direct and indirect mbufs + */ + + struct rte_mempool *mp; /* Mempool for GSO packets */ + /* initialize GSO context */ + gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO | + DEV_TX_OFFLOAD_GRE_TNL_TSO; + snprintf(pool_name, sizeof(pool_name), "mp_%s", dev->device->name); + mp = rte_mempool_lookup((const char *)pool_name); + if (!mp) { + mp = rte_pktmbuf_pool_create(pool_name, TAP_GSO_MBUFS_NUM, + 0, 0, RTE_PKTMBUF_HEADROOM + TAP_GSO_MBUF_SEG_SIZE, + SOCKET_ID_ANY); + if (!mp) { + struct pmd_internals *pmd = dev->data->dev_private; + RTE_LOG(DEBUG, PMD, "%s: failed to create mbuf pool for device %s\n", + pmd->name, dev->device->name); + return -1; + } + } + + gso_ctx->direct_pool = mp; + gso_ctx->indirect_pool = mp; + gso_ctx->gso_types = gso_types; + gso_ctx->gso_size = 0; /* gso_size is set in tx_burst() per packet */ + gso_ctx->flag = 0; + + return 0; +} + static int tap_setup_queue(struct rte_eth_dev *dev, struct pmd_internals *internals, uint16_t qid, int is_rx) { + int ret; int *fd; int *other_fd; const char *dir; struct pmd_internals *pmd = dev->data->dev_private; struct rx_queue *rx = &internals->rxq[qid]; struct tx_queue *tx = &internals->txq[qid]; + struct rte_gso_ctx *gso_ctx; if (is_rx) { fd = &rx->fd; other_fd = &tx->fd; dir = "rx"; + gso_ctx = NULL; } else { fd = &tx->fd; other_fd = &rx->fd; dir = "tx"; + gso_ctx = &tx->gso_ctx; } if (*fd != -1) { /* fd for this queue already exists */ RTE_LOG(DEBUG, PMD, "%s: fd %d for %s queue qid %d exists\n", pmd->name, *fd, dir, qid); + gso_ctx = NULL; } else if (*other_fd != -1) { /* Only other_fd exists. dup it */ *fd = dup(*other_fd); @@ -1116,6 +1216,11 @@ tap_setup_queue(struct rte_eth_dev *dev, tx->mtu = &dev->data->mtu; rx->rxmode = &dev->data->dev_conf.rxmode; + if (gso_ctx) { + ret = tap_gso_ctx_setup(gso_ctx, dev); + if (ret) + return -1; + } return *fd; } diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 25b65bf..69f746f 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -15,6 +15,7 @@ #include #include +#include #ifdef IFF_MULTI_QUEUE #define RTE_PMD_TAP_MAX_QUEUES TAP_MAX_QUEUES @@ -22,6 +23,8 @@ #define RTE_PMD_TAP_MAX_QUEUES 1 #endif +#define MAX_GSO_MBUFS 64 + struct pkt_stats { uint64_t opackets; /* Number of output packets */ uint64_t ipackets; /* Number of input packets */ @@ -50,6 +53,7 @@ struct tx_queue { uint16_t *mtu; /* Pointer to MTU from dev_data */ uint16_t csum:1; /* Enable checksum offloading */ struct pkt_stats stats; /* Stats for this TX queue */ + struct rte_gso_ctx gso_ctx; /* GSO context */ }; struct pmd_internals { diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 0e18d0f..cd09dc6 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -66,8 +66,6 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PORT) += -lrte_port _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP) += -lrte_pdump _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += -lrte_distributor _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG) += -lrte_ip_frag -_LDLIBS-$(CONFIG_RTE_LIBRTE_GRO) += -lrte_gro -_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO) += -lrte_gso _LDLIBS-$(CONFIG_RTE_LIBRTE_METER) += -lrte_meter _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM) += -lrte_lpm # librte_acl needs --whole-archive because of weak functions @@ -85,6 +83,8 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_EFD) += -lrte_efd _LDLIBS-y += --whole-archive _LDLIBS-$(CONFIG_RTE_LIBRTE_CFGFILE) += -lrte_cfgfile +_LDLIBS-$(CONFIG_RTE_LIBRTE_GRO) += -lrte_gro +_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO) += -lrte_gso _LDLIBS-$(CONFIG_RTE_LIBRTE_HASH) += -lrte_hash _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMBER) += -lrte_member _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lrte_vhost -- 2.7.4