From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01hn0235.outbound.protection.outlook.com [104.47.0.235]) by dpdk.org (Postfix) with ESMTP id 52AA51BB6F for ; Sun, 24 Jun 2018 01:18:08 +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:X-MS-Exchange-SenderADCheck; bh=YUzKGuEagx4Hi9ZUM6dBn0g+6IGQzEVb6L3UQvk0cMA=; b=WMTxGa2ZEM3DNG5gNjKg2cZpimlMxTxy1Tnhqg+5jkgk/iahVcAdtGmSXA7HZtAHvA9VJh2WmHrZuPFxLD3vXhmx0vPg4AVm/htro/2x2beAueR52nyzPnN9OUZQIC4IYbaP2bzrOZjchJem2TlP1H+Wc4+7JvUUemLoLeX8rU4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0501MB2314.eurprd05.prod.outlook.com (2603:10a6:3:27::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.23; Sat, 23 Jun 2018 23:17:58 +0000 From: Ophir Munk To: dev@dpdk.org, Keith Wiles Cc: Thomas Monjalon , Olga Shern , Ophir Munk Date: Sat, 23 Jun 2018 23:17:41 +0000 Message-Id: <1529795861-1361-3-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1529795861-1361-1-git-send-email-ophirmu@mellanox.com> References: <1528821108-12405-3-git-send-email-ophirmu@mellanox.com> <1529795861-1361-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0901CA0090.eurprd09.prod.outlook.com (2603:10a6:800:7e::16) To HE1PR0501MB2314.eurprd05.prod.outlook.com (2603:10a6:3:27::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 926d9c86-0df7-41c9-5930-08d5d95f8f56 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:HE1PR0501MB2314; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2314; 3:qHAP5vRaV9Jo4NVNBb6J2xOmsYZ45coCzjOdrPqqF5hp5xYgXzDVTXOfJvpaSoSzidO9e9KSUPxeFwVDVctLv9jT2+Byt1pJbF7i1TyumSb68rOnSGn/tn53eDdSP+0q9MoTGNPEavDWMsKbrCLE0KNR3iWGXfGPRLvt87AyzCEpBCKtrVew/EMU3nkcjn2G8D+l2yl0ZHkhb2xpRZHLxUrgnb6Lp7qTYVaNmOINVx6ukEL93imwfGWoA6dzogjl; 25:Zt/ar63mRinay9LYCbcH7B7XD9fUb5uEHsColVgc/XHMSn7Cnic8uvhlt+3tYVd7XWEI27+aZdkDAZ/Jn+KjrvsqD/853geew5DsNiV5mMbQmZ41/6gJk0h60vMxEDupliNMVL4ReNNMfyatB3u+AYLxNy95HlqeVGcz5gOs3pm+G1mWQHf+fvCSeiNR/L5cNVOssMABjdzi5Ta798/hZjNo08bmhslNkvew76Tpc4UnI/PXbbWqp0/ExYHHMwvyr1q+JlFVZbCew+dZK+UzOyh8+Y8elgZFH+0iLgSezY8fIGxRiUukV2UAPF/34ophVA1EKXYwltd870m7ojFXXg==; 31:W734Ju/ToGmgdrLjGCYGg/fmQVNQvRbzbest1/CrT5OBG2FncvhKoAbGT1beFXzw84MzI9Y1Lzq1uzwqkPvxQ5GskWOZWDvdLwwLTij6uaoVqiRvpTMyPZ3QmzdbzVTUYhiLnCsuWMwP/80DQy/obWjCoV7yCs6EethHJiuMiaU7LT6UrVRucdUfBOiZOiySpXbGw7NQsnMGBbqZtjibe4uiuOu8Ne1QvhsFvG5aEFk= X-MS-TrafficTypeDiagnostic: HE1PR0501MB2314:|HE1PR0501MB2314: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2314; 20:787nLNCAT/NMmUQyyXNPiBia0PuYRwqhQtMVu7FHCxsDV476Fq5XFZjdxR1/Ged40cFDZymFUqVSoJYox04/gRYxhX0pqc/iave0DG7lsAbitALNtYylPqqlpYgu8TZcQZZ5RcmEsMezn7csaUYeRwr8yiFRO2JaArk6uSA4udWvxAGF+PLl796GBmGq+BoubCfTPDWxWrdi/xJXz85li5cpgUPlXPlDQQxaPzcoDdQGLnhjzIqzYKHLXi4W3gmnHiPK35FqSFgtdEg1rZTwRUnYLQpr8eE6zXQa0FfCCOR26Hx2ioHWEdF7O2Rl2tG4YvUYEPQ+j94jac65oJEYfrbNZguF3rfBKVXai+GTl22jgvF8IDRZqoU5tZYnmHpRZHH8y6rPV3CS+OiLkfhTOu92yOu6VwRKBw5osBynOyN/YsC2V+eef1Iovdma1Ypmygsgoy9QjEnBQbSJh2o/EaZsyDGpvlrCk/d9E+8uuDQayVXKWv+bMIQvNQdgxz6i; 4:bDDgDNYCwQdOpXplSNFXjnEkgoN/Npko/TG5gDtp7klhmR0Il0VirbgotEbiCWKb99EPznoTeEPLpIIXmzTI80/3plNFt/EpVYebAxCpRAexGnIMN9fwTwJJnKEK9MfgZJQ418OTSnf6RIlev3rVteUhmJOWdf5ebTDTfffOAyaohsoaNFobVEfiedon4QFvq39d5E9V/Z8U4KTp+gjx91dD+1iEbOlcBnbbAgdap25viY+t+rPfhwk1bXCrRE/2xHoLMezIu3HvXlqF+PAsIel59aCm0ISx2CPosHdzw1PMu151kLhl1+ZTBa/+2cwn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(66839620246622); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(2232096)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:HE1PR0501MB2314; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2314; X-Forefront-PRVS: 07126E493C X-Forefront-Antispam-Report: SFV:SPM; SFS:(10009020)(366004)(396003)(39860400002)(346002)(39380400002)(376002)(199004)(189003)(575784001)(26005)(86362001)(7696005)(16526019)(51416003)(7736002)(52116002)(55016002)(6666003)(2906002)(107886003)(4326008)(8936002)(4720700003)(16586007)(21086003)(186003)(36756003)(69596002)(3846002)(6116002)(76176011)(386003)(66066001)(47776003)(5660300001)(106356001)(316002)(105586002)(6916009)(53936002)(956004)(476003)(68736007)(48376002)(446003)(486006)(54906003)(50466002)(8676002)(81156014)(2616005)(81166006)(478600001)(11346002)(50226002)(25786009)(305945005)(33026002)(97736004)(59010400001); DIR:OUT; SFP:1501; SCL:5; SRVR:HE1PR0501MB2314; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0501MB2314; 23:D67tKjeY7HiJpQKnTLRWDXcQe89kzTJsaAN1pxx?= =?us-ascii?Q?7Wl88OUV2cnmBkB8ApZGf+K1oUgLk+VIOhH2aY/fEbvMlJarhiKaTRVYCMO6?= =?us-ascii?Q?z9kJmGVDVyk2+I6Plia790JZ+LK7MxLZfa6SP98WdDypwz/ul6Gp4KG/UxpR?= =?us-ascii?Q?/9KLJPEid0nb1SMoWhRFjt2HH7+7RPSHTO31O2sfcSAnwhPW89nAFUJsd6qQ?= =?us-ascii?Q?FOp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xDKfSs1L+3dqzqfdwzeqPTejOJjfr1JeZzMSmuK/QsWI2FUSJDqvYe2DQMoBuoQ9aP2uuoio5KZ9TSvCksXrLGOdoT6PbWLGd7TVKoT0PROKstoHRBdte6U83qnuhYNBbgza9h44g6XEE9HfrAYYzcrGywA= X-Microsoft-Antispam-Message-Info: tQyKgTp5RxTQRYsD4fWHpDkf9eqX8HN/a2bcQtoBNtScln/idBbcoCqq3p8KH/jpXNx+wfzmWkI8A1gPB7iMCWgFUP+3IbsigaEQds1G9ZeQ0wixIuzwiGBp+I6PFP4yTFfsSqtB/etSoeAvhYAwfAD+FpZSoX5AnhsYF7jg1le2pvLJ/1paS48O+yulaXCuIGp+y++wOpngkK1g62SNesRlFHNMHr7p3KD4KywV/TOD7OoQrf9NSkNohN+Siwt4BuOUNvK50sWqjvDr74esLt6oVHd0wjJb5CBAYYADWi/jQw8LJIIm0/bQQVIpZXs7Q/AOBNLCadmRcjBmdz3CEikux6Lug+ZCMoG20TyS6rY47wwcMBJeFkbQJadpqA9dvwk86JhjW4ewVfwjKgzHD8YrfWEllBkcZ9imxtfY4cFBjxKB4i1YFXFuhSKh0XVFQeKi9gvhV4D7EpSA6IBgCu3fhGwEG/25vdkwALhATjOiUt8Ni/+jcvu7jGP5kM0UAz96h8LprbtAqa3Qbcw4n+YbUleAkBgB/jp/JdAQMKjx70ud+lG0Tx7gRae+4VgrzPpW4ifPkmNcQD0kEg9bQccAPabvtMbeHrbIxxO53cO9282oSfthMY5i0hXHU/e1qmOw7uTDV3Y+LspteVDjbtcvSZoSg4sBoE31ak5jI38r0CC/CO8vs+Rv3Zn0zNqwa56EKCdQ77lKPooiGNSDbg== SpamDiagnosticOutput: 1:22 X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2314; 7:ofmOQz69/KowKgkyxfrbccWs/3+33JbaghuLP8lz5B7oNYhpa32MgRfHR1VRweYN5mwXUYsmMULA1TXJxZ9AoRotSc7XIN15CVKV9Izvo243ZKFpgrenRIVqanm8LNWRGmQsIC5OjTXoQYitmSBYtVKwYHOY1b72Os8rNis60qXwu2sWMQBZDQ/pnoX72BHAND7oyzk8M8u84iF68LujBpFxbFrwQK4fPqJPvdq+OUdGklVj1/4EvNlF+LXzavMS X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2018 23:17:58.2606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 926d9c86-0df7-41c9-5930-08d5d95f8f56 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2314 Subject: [dpdk-dev] [PATCH v5 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: Sat, 23 Jun 2018 23:18:08 -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. Reviewed-by: Raslan Darawsheh Signed-off-by: Ophir Munk --- drivers/net/tap/Makefile | 2 +- drivers/net/tap/rte_eth_tap.c | 174 +++++++++++++++++++++++++++++++++++------- drivers/net/tap/rte_eth_tap.h | 3 + mk/rte.app.mk | 4 +- 4 files changed, 154 insertions(+), 29 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 8903646..d137f58 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 @@ -55,6 +56,12 @@ #define ETH_TAP_CMP_MAC_FMT "0123456789ABCDEFabcdef" #define ETH_TAP_MAC_ARG_FMT ETH_TAP_MAC_FIXED "|" ETH_TAP_USR_MAC_FMT +#define TAP_GSO_MBUFS_PER_CORE 128 +#define TAP_GSO_MBUF_SEG_SIZE 128 +#define TAP_GSO_MBUF_CACHE_SIZE 4 +#define TAP_GSO_MBUFS_NUM \ + (TAP_GSO_MBUFS_PER_CORE * TAP_GSO_MBUF_CACHE_SIZE) + static struct rte_vdev_driver pmd_tap_drv; static struct rte_vdev_driver pmd_tun_drv; @@ -412,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; } /* Finalize l4 checksum calculation */ @@ -480,23 +488,16 @@ 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 *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; + uint16_t l234_hlen; - 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; @@ -504,8 +505,7 @@ 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) */ @@ -513,10 +513,6 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) uint16_t l4_phdr_cksum = 0; /* TCP/UDP pseudo header checksum */ uint16_t is_cksum = 0; /* in case cksum should be offloaded */ - /* stats.errs will be incremented */ - if (rte_pktmbuf_pkt_len(mbuf) > max_size) - break; - l4_cksum = NULL; if (txq->type == ETH_TUNTAP_TYPE_TUN) { /* @@ -558,8 +554,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) 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); @@ -603,13 +599,90 @@ 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; + uint32_t max_size; + int i; + + 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 = 0; + uint16_t tso_segsz = 0; + int ret; + uint16_t hdrs_len; + int j; + uint64_t tso; + + tso = mbuf_in->ol_flags & PKT_TX_TCP_SEG; + if (tso) { + struct rte_gso_ctx *gso_ctx = &txq->gso_ctx; + + assert(gso_ctx != NULL); + + /* TCP segmentation implies TCP checksum offload */ + mbuf_in->ol_flags |= PKT_TX_TCP_CKSUM; + + /* 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 > *txq->mtu) { + 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; + + /* ret 0 indicates no new mbufs were created */ + ret = 0; + mbuf = &mbuf_in; + num_mbufs = 1; + } + + tap_write_mbufs(txq, num_mbufs, mbuf, + &num_packets, &num_tx_bytes); num_tx++; - num_tx_bytes += mbuf->pkt_len; - rte_pktmbuf_free(mbuf); + /* free original mbuf */ + rte_pktmbuf_free(mbuf_in); + /* free tso mbufs */ + for (j = 0; j < ret; j++) + rte_pktmbuf_free(mbuf[j]); } - txq->stats.opackets += num_tx; + txq->stats.opackets += num_packets; txq->stats.errs += nb_pkts - num_tx; txq->stats.obytes += num_tx_bytes; @@ -1071,31 +1144,75 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) } 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 TAP_GSO_MBUF_SEG_SIZE 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; + 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, + TAP_GSO_MBUF_CACHE_SIZE, 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 */ TAP_LOG(DEBUG, "%s: fd %d for %s queue qid %d exists", pmd->name, *fd, dir, qid); + gso_ctx = NULL; } else if (*other_fd != -1) { /* Only other_fd exists. dup it */ *fd = dup(*other_fd); @@ -1120,6 +1237,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; + } tx->type = pmd->type; diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 7b21d0d..44e2773 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -15,6 +15,7 @@ #include #include +#include #include "tap_log.h" #ifdef IFF_MULTI_QUEUE @@ -22,6 +23,7 @@ #else #define RTE_PMD_TAP_MAX_QUEUES 1 #endif +#define MAX_GSO_MBUFS 64 enum rte_tuntap_type { ETH_TUNTAP_TYPE_UNKNOWN, @@ -59,6 +61,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 1e32c83..e2ee879 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -38,8 +38,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 @@ -61,6 +59,8 @@ endif _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