From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01hn0246.outbound.protection.outlook.com [104.47.1.246]) by dpdk.org (Postfix) with ESMTP id D97D51BA2F for ; Tue, 10 Apr 2018 00:33:40 +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=QZ1EnjRKh3NSFqkugBj1TaMwXLzpDgs/xEPj5o3DiHk=; b=pe/3j7qCVVj9DT5RTzLLxeu/72Tc2oULqU4EmaE4psPe7m88ejSFVjWeYJNR9wLNDqIRucJ+5n7YB0y5XeZ2lI/UQlD5v24WzM2yGYTHXQD07jrrz+lHcdV7k7UCGwOzJ6UET9yb/sDKCbv3bs1+KZ7nTgtxAAT6GfDkjwaLays= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by DB6PR0501MB2309.eurprd05.prod.outlook.com (2603:10a6:4:4c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Mon, 9 Apr 2018 22:33:32 +0000 From: Ophir Munk To: dev@dpdk.org, Pascal Mazon Cc: Thomas Monjalon , Olga Shern , Ophir Munk Date: Mon, 9 Apr 2018 22:33:12 +0000 Message-Id: <1523313192-18048-3-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1523313192-18048-1-git-send-email-ophirmu@mellanox.com> References: <1520629826-23055-2-git-send-email-ophirmu@mellanox.com> <1523313192-18048-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: DB6P190CA0010.EURP190.PROD.OUTLOOK.COM (2603:10a6:6:2f::23) To DB6PR0501MB2309.eurprd05.prod.outlook.com (2603:10a6:4:4c::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6a454a59-8f79-495d-b6d0-08d59e69ed9c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB6PR0501MB2309; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2309; 3:FI05hr8jKV2WKSyny3r5nnio6wIMnfA70CaiQzufBnyF6awGVNE/H8Nm2OMZFwgemltqYf5bC2wEdVVMIFuj3SdcA+NaEKvFY8Ngd/ScoaHMPTfilxYklFqmPpsNLQta6b7RcCdOZc/PB7wYAnQ2Eb2+xoSMKf8ejy5gbkJUiBYPAaiFng2HMCImnvim5Zzr0mvYUEC9nwt/iheyVvE8jto6a+T6bpvCU+BtDB5qIX+ergHRsH94P451BXttqXZe; 25:3DHmu0HKTNKTwf0SvoVhXnvFXs+zaoOfcTDrhCooeMrG7ayEwLMZXMOturkichFuLxu5L+QKvr5W8yvrWvV57NVRq02P1LNvmyq0P9tjvXWYnIEBst5cAd0Tb0BnbKE8HW8HI1DZfQs6Kb4LXUQGDuOPDqJhFuDpWNlm5X0fsFNx2qB49cSg3sgra8thI1RSSzehbmXSp9BDwWw/XJ2MYD5frFJ3Z9Co7NXH+bRh+38Oum3QRQx8zh3DKi1NgnhuI8tzx8kUoIVl44UhcrtCXIZvz1EE6hQ/L4GWpsftIMrLZauQG/6tyjYhcAUPXCAQisISaRVCwLC7nOJ4XPIC6A==; 31:dbbmsXrVI+H8+wHdx/JikB1mo7rByknTC+RMakStsUJYDEtYnqJ2Kpn5FcLm8l+GGo0Ssls1ZkAcqyN87geuXv8lfHPVvYY0FfO4Q1yT0bYC/FsZZLF0Fu7svSuK6FIRaiKJAtXvKDhTH3SEhzOGbBuy2lt/3FCfL0Ek/pwwYigUzw72um0dU/gi7zTTfgVdMjfFWT12V89R4GbmbccwmMqp3r0aOTdwp5f/yB6P4nY= X-MS-TrafficTypeDiagnostic: DB6PR0501MB2309:|DB6PR0501MB2309: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2309; 20:3I3gHX6QhVjLB4exHuBCmKzmGVgNdmVeX9WGyLqbfPLSSfYIOei3R24xKqpUhlLgPR5hMe4IzXUqs4NpPmkCJJUUGMTTSur4Vgk2tpSyEhk4926QYvEaRyFjPR1wW8YeGJrHUUjV8r6HCStCVS7rtt1L2qVMvKCI+uYn2VDgZ3FhSMLFFoY7ZtGxG6XngVMwZGhVwnT/7V2yv+0vwNt9r5RuN9v6gDFq4IWKqDTcHJSVFS41tRBi6puVn2a2/u1KntLYv5lGgt1KQd7lxTXpo8gquy9H24wBB+OtjqPe4Q8XEwXWwfX8dwb6Eb+j0UJ+J3DVV7LdTLq460ex+H9+bB4bl4WuXyHy+mlefGBGqMM1lU0qhXHA1RN6iiQhEF9LUKUlZZp8HQeTEGRQnBrED2bQ5K5EBQ5Se56IhrVZNGouNZ9ppLK/maG/RwyvaRyFiHBgKYMwkvdN8qdVvLuNR/VhA0xQ2cyKdFSxKSZor5IGSN4LgYp3KHw0fhzxS50T; 4:kxm5qnvypvKVPeviJEFvcTCwut7mgSbIlWVQW46sgxd+WqpzBPiRuAuwZOZYOLWrVNkJvGlLXO5kgqdOhEdEWKOuARqlJJu1KIx44GeIz/qryQC3W5ay6Sab8i4F6gVgwP9A0MudID4eswy/RkEduIMyGS0rFUQosJ/upDPqnOJ+6ZlGo/0VuJkIH2oaFtHUYvyrTdQDwKdVG6Rzlb+7pX/q8MjR6/M/HkRceqyJsUaZqoQYnHOQDMKgi0t3tty06hL9jG/JyW1b5hF7oMAdmlaiuWNLz+E6P+D3keOa+ZphQPI7398e5PRZkoeT7UDa 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)(3231221)(2232076)(944501327)(52105095)(93006095)(93001095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:DB6PR0501MB2309; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0501MB2309; X-Forefront-PRVS: 0637FCE711 X-Forefront-Antispam-Report: SFV:SPM; SFS:(10009020)(366004)(376002)(346002)(396003)(39380400002)(39860400002)(189003)(199004)(478600001)(81156014)(33026002)(21086003)(68736007)(51416003)(81166006)(7696005)(52116002)(476003)(486006)(386003)(50466002)(11346002)(66066001)(8676002)(47776003)(55016002)(105586002)(76176011)(48376002)(59450400001)(106356001)(2906002)(53936002)(2616005)(16526019)(7736002)(956004)(86362001)(446003)(186003)(97736004)(4326008)(107886003)(305945005)(8936002)(69596002)(50226002)(5660300001)(16586007)(25786009)(6916009)(6666003)(4720700003)(316002)(54906003)(3846002)(26005)(6116002)(36756003)(59010400001); DIR:OUT; SFP:1501; SCL:5; SRVR:DB6PR0501MB2309; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0501MB2309; 23:sgqxKjxCyh46hGFu7DEybZokEU4R5JvI1q4BYRK?= =?us-ascii?Q?2z8jcroM9WjV/MojMVYHRZ91Uem5SWOxwOzzjsvJsiUzEdjDz0DHdhPYmwQm?= =?us-ascii?Q?wXdi7Rtclos1yKUX7MJ6jHZCCCwpqZF5v08a5xg7vv7BLlentaBmdUU/F1De?= =?us-ascii?Q?kJtmrxprSY3jwu8ab/P3Z2S+FNzu/VNbBW1cMvueMGXvShPaSf2+Gcp49im5?= =?us-ascii?Q?1p1kv6AsYg+Y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0UxNarSEroFseKg5gGpiwMLHXmniO+YA1CWNyMzvC7Ycqxak7TUSYx2PsSZWGiEK8o9G67bMGJGiYWk+lxSgyEn0Xpxe1Y3hLFer639gAUShSj/FP9zL9OKLNEih6VXgu+1m7K9CXEIv1jHw8= X-Microsoft-Antispam-Message-Info: AWHPuPzV1UmMdHBz1JjdwZTWP3PLOHpCi4zbbqUvxNrYd4WrHx13WcOiA6KvSBxY41Sr/UEtOe0G80p8VKfygO1aKtsROOrlPPHGLe1FOZSTvgIE59fbDh68bgAUdHzLRCY3QbNkCMx8/G0DE4+HaClEVKTAd9FYuTEMDAmKGdASfp6udd9JkQEkGzupKkrbSND+onnKELCNMwyQLoUCwfiZ9jaZaFQeKuA9OC072Xh4Qr4nubEd8tt5o+kExCIpynyM55y4NDCVfqcCPi5VolRKiVprpEm20b/Y3qdeMOyb99iY0i42ZgL9zq86UXz3zkpSr+0kp5sssetWrU0+PHnm7kwUW5rs19tyUlvIXfGdl5zrMOt/DwXLUeSBM6KOROrMyrMJlsVf8LtkhEbwzUCELtY7058SZFR4xshI0fFJlgvODceIW9TNIMkX1ksdTj3STuMVUUSdGYxN1k8lfwENGfEOUZjE8vZWAKzkku1j0oVhIhsYouzMXGJgeQmk9aZiMESiX4mmFGysQnKcAfGcLj1+4TtJtIIKDcevVfQ= SpamDiagnosticOutput: 1:22 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2309; 7:f837moaAvasOZ+N9xKRRuLIHZxySTCdEBVGhs/RmH8Zz35mOnxY5sDXRaX5izWaDLUAsFRtpNT9v1W3ssiv8rpC4WGpJW2Y60E3hNN5xXDPbHtcJ+ZLXcCTtmMzf64BpHXGEo8NNLFckg6hv7D1q4hYfauYCRMKRVXUy8lrTtFAwBvGAPmn65KXMCzw7UCVBMUJPVQ/ktI6hheHTRkyER1gsq5+vAzRvqV/86j/pk9EjnGOYjw3L5Uat2EISBCfv X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2018 22:33:32.9737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a454a59-8f79-495d-b6d0-08d59e69ed9c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0501MB2309 Subject: [dpdk-dev] [PATCH v1 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: Mon, 09 Apr 2018 22:33: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 | 153 +++++++++++++++++++++++++++++++++++------- drivers/net/tap/rte_eth_tap.h | 4 ++ mk/rte.app.mk | 4 +- 4 files changed, 135 insertions(+), 28 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 df23c4d..717a2b1 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 @@ -486,38 +489,26 @@ tap_tx_offload(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; - 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]; - struct iovec iovecs[mbuf->nb_segs + 1]; + 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; char m_copy[mbuf->data_len]; int n; int j; - int k; /* first index in iovecs for copying segments */ + int k; /* current index in iovecs for copying segments */ uint16_t l234_len; /* length of layers 2,3,4 headers */ uint16_t seg_len; /* length of first segment */ uint16_t nb_segs; - /* stats.errs will be incremented */ - if (rte_pktmbuf_pkt_len(mbuf) > max_size) - break; - /* * TUN and TAP are created with IFF_NO_PI disabled. * For TUN PMD this mandatory as fields are used by @@ -581,13 +572,75 @@ 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; + 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 */ + tso_segsz = mbuf_in->tso_segsz; + if (unlikely(tso_segsz == 0) || + 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, + &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; @@ -1027,32 +1080,77 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) } } +#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); @@ -1079,6 +1177,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 53a506a..65da5f8 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 005803a..62cf545 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 @@ -86,6 +84,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