From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EX13-EDG-OU-001.vmware.com (ex13-edg-ou-001.vmware.com [208.91.0.189]) by dpdk.org (Postfix) with ESMTP id 16F2E2B84 for ; Thu, 3 Nov 2016 02:25:17 +0100 (CET) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Wed, 2 Nov 2016 18:25:01 -0700 Received: from EX13-CAS-005.vmware.com (ex13-cas-005.vmware.com [10.113.191.55]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id C2BDFB090A; Wed, 2 Nov 2016 18:25:16 -0700 (PDT) Received: from EX13-CAS-005.vmware.com (10.113.191.55) by EX13-MBX-028.vmware.com (10.113.191.48) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Wed, 2 Nov 2016 18:24:53 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.113.170.11) by EX13-CAS-005.vmware.com (10.113.191.55) with Microsoft SMTP Server (TLS) id 15.0.1156.6 via Frontend Transport; Wed, 2 Nov 2016 18:24:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=fdqQcIA2g369uaTYLs7mybqd0P/DvtpSFk3P+SztOeg=; b=jbpub6QUMVpwOQCHEn0G/ZjTPG5+XakcACU6NecE9ssX01AhOhtqidMoiEtRgFb52wxYdE5iS08cR7LWA/NgaWnQaLnYK4jhQEFDrGhAA8U7HZU9Y1qCvjoYn/txG/v4SnNRBAVL+dHxuQbSt1vi7I3r22E/A23k3Lnjd0/doso= Received: from BY2PR05MB2359.namprd05.prod.outlook.com (10.166.113.11) by BY2PR05MB2359.namprd05.prod.outlook.com (10.166.113.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.707.1; Thu, 3 Nov 2016 01:24:51 +0000 Received: from BY2PR05MB2359.namprd05.prod.outlook.com ([10.166.113.11]) by BY2PR05MB2359.namprd05.prod.outlook.com ([10.166.113.11]) with mapi id 15.01.0707.004; Thu, 3 Nov 2016 01:24:51 +0000 From: Yong Wang To: Ferruh Yigit Thread-Topic: [dpdk-dev] [PATCH v3] net/kni: add KNI PMD Thread-Index: AQHSIvs+nF23r+FF7EecOFMLPL/F5qDGbDzQ Date: Thu, 3 Nov 2016 01:24:51 +0000 Message-ID: References: <1474025398-18553-1-git-send-email-ferruh.yigit@intel.com> <20161010131946.13303-1-ferruh.yigit@intel.com> In-Reply-To: <20161010131946.13303-1-ferruh.yigit@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=yongwang@vmware.com; x-originating-ip: [208.91.1.34] x-ms-office365-filtering-correlation-id: e88e9197-a441-4d05-622e-08d403883561 x-microsoft-exchange-diagnostics: 1; BY2PR05MB2359; 7:vFgOYs5ibedAwSoej28nKW37l7IHVQB3vRksLb8QNCyQmrMDxbo9MlR4JQOmdZE7/E7R1Ym+6Olzw4WeCewCqy4k2o1hNFZPHHqVN8/1I7iC8rQYzalDsaM0B0QLEXLvjXKMl7XNOiJOs0ezIN1/6LqLOf6zhg6FBjb5Cp2KSvWjcQsB/OFafzVzoYlCgJKunjFn/ZYqM3AjN7o+pODstKWzPGjoEjblDU6A4uNV0mvIX3gPqGHreDfxK4yTP9c4JWeqfmZyfIs9vqisz5wbiaPgPNZem9A9TkgH7R3sgwTTPk2/IxgUR8Ln783ATtY1su/fAPUKwldy9ByzKk3vxh+OM1WwKxFRDUDJ6MHYQug=; 20:0SI2Yus0qNF4uSJNuswm+ZgKEof0geZXu9AA5s7baI4uldKgbUITYT3NeKoeAbsoPl7kWkZ9QSZjyZ/fil/THuoKD+uvsPjbJz9hMzXraQ9wV8XphLSdKpCVpWvzw5bF3Aa4iRGGFleaO9KOtVMpxSmO4jK69juL8cwM7kAf+jg= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR05MB2359; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:BY2PR05MB2359; BCL:0; PCL:0; RULEID:; SRVR:BY2PR05MB2359; x-forefront-prvs: 011579F31F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(199003)(189002)(377454003)(13464003)(74316002)(10400500002)(3280700002)(3660700001)(2906002)(122556002)(305945005)(4326007)(6916009)(77096005)(33656002)(2950100002)(97736004)(11100500001)(2900100001)(92566002)(87936001)(86362001)(110136003)(189998001)(7696004)(68736007)(76176999)(81156014)(586003)(3846002)(54356999)(101416001)(19580395003)(5660300001)(5002640100001)(50986999)(8936002)(106116001)(76576001)(6116002)(7736002)(102836003)(105586002)(8676002)(66066001)(9686002)(81166006)(19580405001)(106356001)(99286002)(7846002)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR05MB2359; H:BY2PR05MB2359.namprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (EX13-EDG-OU-001.vmware.com: yongwang@vmware.com does not designate permitted sender hosts) received-spf: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Nov 2016 01:24:51.0550 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR05MB2359 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH v3] net/kni: add KNI PMD 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: Thu, 03 Nov 2016 01:25:18 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ferruh Yigit > Sent: Monday, October 10, 2016 6:20 AM > To: dev@dpdk.org > Cc: Ferruh Yigit > Subject: [dpdk-dev] [PATCH v3] net/kni: add KNI PMD >=20 > Add KNI PMD which wraps librte_kni for ease of use. >=20 > KNI PMD can be used as any regular PMD to send / receive packets to the > Linux networking stack. >=20 > Signed-off-by: Ferruh Yigit > --- >=20 > v3: > * rebase on top of latest master >=20 > v2: > * updated driver name eth_kni -> net_kni > --- > config/common_base | 1 + > config/common_linuxapp | 1 + > drivers/net/Makefile | 1 + > drivers/net/kni/Makefile | 63 +++++ > drivers/net/kni/rte_eth_kni.c | 463 > ++++++++++++++++++++++++++++++++ > drivers/net/kni/rte_pmd_kni_version.map | 4 + > mk/rte.app.mk | 10 +- > 7 files changed, 538 insertions(+), 5 deletions(-) > create mode 100644 drivers/net/kni/Makefile > create mode 100644 drivers/net/kni/rte_eth_kni.c > create mode 100644 drivers/net/kni/rte_pmd_kni_version.map >=20 > diff --git a/config/common_base b/config/common_base > index f5d2eff..03b93c7 100644 > --- a/config/common_base > +++ b/config/common_base > @@ -543,6 +543,7 @@ CONFIG_RTE_PIPELINE_STATS_COLLECT=3Dn > # Compile librte_kni > # > CONFIG_RTE_LIBRTE_KNI=3Dn > +CONFIG_RTE_LIBRTE_PMD_KNI=3Dn Nit: change this to CONFIG_RTE_LIBRTE_KNI_PMD instead to be consistent with= all other pmds. > CONFIG_RTE_KNI_KMOD=3Dn > CONFIG_RTE_KNI_PREEMPT_DEFAULT=3Dy > CONFIG_RTE_KNI_KO_DEBUG=3Dn > diff --git a/config/common_linuxapp b/config/common_linuxapp > index 2483dfa..2ecd510 100644 > --- a/config/common_linuxapp > +++ b/config/common_linuxapp > @@ -39,6 +39,7 @@ CONFIG_RTE_EAL_IGB_UIO=3Dy > CONFIG_RTE_EAL_VFIO=3Dy > CONFIG_RTE_KNI_KMOD=3Dy > CONFIG_RTE_LIBRTE_KNI=3Dy > +CONFIG_RTE_LIBRTE_PMD_KNI=3Dy > CONFIG_RTE_LIBRTE_VHOST=3Dy > CONFIG_RTE_LIBRTE_PMD_VHOST=3Dy > CONFIG_RTE_LIBRTE_PMD_AF_PACKET=3Dy > diff --git a/drivers/net/Makefile b/drivers/net/Makefile > index bc93230..c4771cd 100644 > --- a/drivers/net/Makefile > +++ b/drivers/net/Makefile > @@ -41,6 +41,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) +=3D enic > DIRS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) +=3D fm10k > DIRS-$(CONFIG_RTE_LIBRTE_I40E_PMD) +=3D i40e > DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) +=3D ixgbe > +DIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D kni > DIRS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) +=3D mlx4 > DIRS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5 > DIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) +=3D mpipe > diff --git a/drivers/net/kni/Makefile b/drivers/net/kni/Makefile > new file mode 100644 > index 0000000..0b7cf91 > --- /dev/null > +++ b/drivers/net/kni/Makefile > @@ -0,0 +1,63 @@ > +# BSD LICENSE > +# > +# Copyright(c) 2016 Intel Corporation. All rights reserved. > +# > +# 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 copyrigh= t > +# notice, this list of conditions and the following disclaimer in > +# the documentation and/or other materials provided with the > +# distribution. > +# * Neither the name of Intel Corporation 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 $(RTE_SDK)/mk/rte.vars.mk > + > +# > +# library name > +# > +LIB =3D librte_pmd_kni.a > + > +CFLAGS +=3D -O3 > +CFLAGS +=3D $(WERROR_FLAGS) > +LDLIBS +=3D -lpthread > + > +EXPORT_MAP :=3D rte_pmd_kni_version.map > + > +LIBABIVER :=3D 1 > + > +# > +# all source are stored in SRCS-y > +# > +SRCS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D rte_eth_kni.c > + > +# > +# Export include files > +# > +SYMLINK-y-include +=3D > + > +# this lib depends upon: > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_eal > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_ether > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_kni > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_mbuf > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_mempool > + > +include $(RTE_SDK)/mk/rte.lib.mk > diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.= c > new file mode 100644 > index 0000000..ce9e758 > --- /dev/null > +++ b/drivers/net/kni/rte_eth_kni.c > @@ -0,0 +1,463 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2016 Intel Corporation. All rights reserved. > + * All rights reserved. > + * > + * 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 copyrig= ht > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Intel Corporation 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 > + > +#define KNI_MAX_QUEUE_PER_PORT 8 > +#define MAX_PACKET_SZ 2048 > +#define MAX_KNI_PORTS 8 > +#define DRV_NAME net_kni The name generated this way is not consistent with other vdevs. Why not si= mply assign "KNI PMD" to drv_name? > + > +struct pmd_queue_stats { > + uint64_t pkts; > + uint64_t bytes; > + uint64_t err_pkts; > +}; > + > +struct pmd_queue { > + struct pmd_internals *internals; > + struct rte_mempool *mb_pool; > + > + struct pmd_queue_stats rx; > + struct pmd_queue_stats tx; > +}; > + > +struct pmd_internals { > + struct rte_kni *kni; > + int is_kni_started; > + > + pthread_t thread; > + int stop_thread; > + > + struct pmd_queue rx_queues[KNI_MAX_QUEUE_PER_PORT]; > + struct pmd_queue tx_queues[KNI_MAX_QUEUE_PER_PORT]; > +}; > + > +static struct ether_addr eth_addr; > +static const char *drivername =3D RTE_STR(DRV_NAME); > +static struct rte_eth_link pmd_link =3D { > + .link_speed =3D 10000, > + .link_duplex =3D ETH_LINK_FULL_DUPLEX, > + .link_status =3D 0 > +}; > +static int is_kni_initialized; > + > +static uint16_t > +eth_kni_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) > +{ > + struct pmd_queue *kni_q =3D q; > + struct rte_kni *kni =3D kni_q->internals->kni; > + uint16_t nb_pkts; > + > + nb_pkts =3D rte_kni_rx_burst(kni, bufs, nb_bufs); > + > + kni_q->rx.pkts +=3D nb_pkts; > + kni_q->rx.err_pkts +=3D nb_bufs - nb_pkts; > + > + return nb_pkts; > +} > + I don't think it's safe to do receive from two queues concurrently on two c= ores sharing the same underlying KNI device due to the current limitation o= f KNI user-space queues not being multi-thread safe. Is the proposed plan = to have the application layer implement synchronization logic? If that's t= he case, it needs to be clearly documented and depending on the implementat= ion, measurable overhead will be incurred. Otherwise (only single-queue su= pported), could you check queue number if the application tries to configur= e multi-queue? > +static uint16_t > +eth_kni_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) > +{ > + struct pmd_queue *kni_q =3D q; > + struct rte_kni *kni =3D kni_q->internals->kni; > + uint16_t nb_pkts; > + > + nb_pkts =3D rte_kni_tx_burst(kni, bufs, nb_bufs); > + > + kni_q->tx.pkts +=3D nb_pkts; > + kni_q->tx.err_pkts +=3D nb_bufs - nb_pkts; > + > + return nb_pkts; > +} > + > +static void * > +kni_handle_request(void *param) > +{ > + struct pmd_internals *internals =3D param; > +#define MS 1000 > + > + while (!internals->stop_thread) { > + rte_kni_handle_request(internals->kni); > + usleep(500 * MS); > + } > + > + return param; > +} > + > +static int > +eth_kni_start(struct rte_eth_dev *dev) > +{ > + struct pmd_internals *internals =3D dev->data->dev_private; > + uint16_t port_id =3D dev->data->port_id; > + struct rte_mempool *mb_pool; > + struct rte_kni_conf conf; > + const char *name =3D dev->data->name + 4; /* remove eth_ */ > + > + snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", name); > + conf.force_bind =3D 0; > + conf.group_id =3D port_id; > + conf.mbuf_size =3D MAX_PACKET_SZ; > + mb_pool =3D internals->rx_queues[0].mb_pool; > + > + internals->kni =3D rte_kni_alloc(mb_pool, &conf, NULL); > + if (internals->kni =3D=3D NULL) { > + RTE_LOG(ERR, PMD, > + "Fail to create kni for port: %d\n", port_id); > + return -1; > + } > + > + return 0; > +} > + > +static int > +eth_kni_dev_start(struct rte_eth_dev *dev) > +{ > + struct pmd_internals *internals =3D dev->data->dev_private; > + int ret; > + > + if (internals->is_kni_started =3D=3D 0) { > + ret =3D eth_kni_start(dev); > + if (ret) > + return -1; > + internals->is_kni_started =3D 1; > + } > + > + ret =3D pthread_create(&internals->thread, NULL, kni_handle_request, > + internals); > + if (ret) { > + RTE_LOG(ERR, PMD, "Fail to create kni request thread\n"); > + return -1; > + } > + > + dev->data->dev_link.link_status =3D 1; > + > + return 0; > +} > + > +static void > +eth_kni_dev_stop(struct rte_eth_dev *dev) > +{ > + struct pmd_internals *internals =3D dev->data->dev_private; > + int ret; > + > + internals->stop_thread =3D 1; > + > + ret =3D pthread_cancel(internals->thread); > + if (ret) > + RTE_LOG(ERR, PMD, "Can't cancel the thread\n"); > + > + ret =3D pthread_join(internals->thread, NULL); > + if (ret) > + RTE_LOG(ERR, PMD, "Can't join the thread\n"); > + > + internals->stop_thread =3D 0; > + > + dev->data->dev_link.link_status =3D 0; > +} > + > +static int > +eth_kni_dev_configure(struct rte_eth_dev *dev __rte_unused) > +{ > + return 0; > +} > + > +static void > +eth_kni_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info > *dev_info) > +{ > + struct rte_eth_dev_data *data =3D dev->data; > + struct pmd_internals *internals =3D data->dev_private; > + > + dev_info->driver_name =3D data->drv_name; > + dev_info->max_mac_addrs =3D 1; > + dev_info->max_rx_pktlen =3D (uint32_t)-1; > + dev_info->max_rx_queues =3D RTE_DIM(internals->rx_queues); > + dev_info->max_tx_queues =3D RTE_DIM(internals->tx_queues); > + dev_info->min_rx_bufsize =3D 0; > + dev_info->pci_dev =3D NULL; > +} > + > +static int > +eth_kni_rx_queue_setup(struct rte_eth_dev *dev, > + uint16_t rx_queue_id, > + uint16_t nb_rx_desc __rte_unused, > + unsigned int socket_id __rte_unused, > + const struct rte_eth_rxconf *rx_conf __rte_unused, > + struct rte_mempool *mb_pool) > +{ > + struct pmd_internals *internals =3D dev->data->dev_private; > + struct pmd_queue *q; > + > + q =3D &internals->rx_queues[rx_queue_id]; > + q->internals =3D internals; > + q->mb_pool =3D mb_pool; > + > + dev->data->rx_queues[rx_queue_id] =3D q; > + > + return 0; > +} > + > +static int > +eth_kni_tx_queue_setup(struct rte_eth_dev *dev, > + uint16_t tx_queue_id, > + uint16_t nb_tx_desc __rte_unused, > + unsigned int socket_id __rte_unused, > + const struct rte_eth_txconf *tx_conf __rte_unused) > +{ > + struct pmd_internals *internals =3D dev->data->dev_private; > + struct pmd_queue *q; > + > + q =3D &internals->tx_queues[tx_queue_id]; > + q->internals =3D internals; > + > + dev->data->tx_queues[tx_queue_id] =3D q; > + > + return 0; > +} > + > +static void > +eth_kni_queue_release(void *q __rte_unused) > +{ > +} > + > +static int > +eth_kni_link_update(struct rte_eth_dev *dev __rte_unused, > + int wait_to_complete __rte_unused) > +{ > + return 0; > +} > + > +static void > +eth_kni_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) > +{ > + unsigned long rx_packets_total =3D 0, rx_bytes_total =3D 0; > + unsigned long tx_packets_total =3D 0, tx_bytes_total =3D 0; > + struct rte_eth_dev_data *data =3D dev->data; > + unsigned long tx_packets_err_total =3D 0; > + unsigned int i, num_stats; > + struct pmd_queue *q; > + > + num_stats =3D RTE_MIN((unsigned > int)RTE_ETHDEV_QUEUE_STAT_CNTRS, > + data->nb_rx_queues); > + for (i =3D 0; i < num_stats; i++) { > + q =3D data->rx_queues[i]; > + stats->q_ipackets[i] =3D q->rx.pkts; > + stats->q_ibytes[i] =3D q->rx.bytes; > + rx_packets_total +=3D stats->q_ipackets[i]; > + rx_bytes_total +=3D stats->q_ibytes[i]; > + } > + > + num_stats =3D RTE_MIN((unsigned > int)RTE_ETHDEV_QUEUE_STAT_CNTRS, > + data->nb_tx_queues); > + for (i =3D 0; i < num_stats; i++) { > + q =3D data->tx_queues[i]; > + stats->q_opackets[i] =3D q->tx.pkts; > + stats->q_obytes[i] =3D q->tx.bytes; > + stats->q_errors[i] =3D q->tx.err_pkts; > + tx_packets_total +=3D stats->q_opackets[i]; > + tx_bytes_total +=3D stats->q_obytes[i]; > + tx_packets_err_total +=3D stats->q_errors[i]; > + } > + > + stats->ipackets =3D rx_packets_total; > + stats->ibytes =3D rx_bytes_total; > + stats->opackets =3D tx_packets_total; > + stats->obytes =3D tx_bytes_total; > + stats->oerrors =3D tx_packets_err_total; > +} > + > +static void > +eth_kni_stats_reset(struct rte_eth_dev *dev) > +{ > + struct rte_eth_dev_data *data =3D dev->data; > + struct pmd_queue *q; > + unsigned int i; > + > + for (i =3D 0; i < data->nb_rx_queues; i++) { > + q =3D data->rx_queues[i]; > + q->rx.pkts =3D 0; > + q->rx.bytes =3D 0; > + } > + for (i =3D 0; i < data->nb_tx_queues; i++) { > + q =3D data->tx_queues[i]; > + q->tx.pkts =3D 0; > + q->tx.bytes =3D 0; > + q->tx.err_pkts =3D 0; > + } > +} > + > +static const struct eth_dev_ops eth_kni_ops =3D { > + .dev_start =3D eth_kni_dev_start, > + .dev_stop =3D eth_kni_dev_stop, > + .dev_configure =3D eth_kni_dev_configure, > + .dev_infos_get =3D eth_kni_dev_info, > + .rx_queue_setup =3D eth_kni_rx_queue_setup, > + .tx_queue_setup =3D eth_kni_tx_queue_setup, > + .rx_queue_release =3D eth_kni_queue_release, > + .tx_queue_release =3D eth_kni_queue_release, > + .link_update =3D eth_kni_link_update, > + .stats_get =3D eth_kni_stats_get, > + .stats_reset =3D eth_kni_stats_reset, > +}; > + > +static struct rte_eth_dev * > +eth_kni_create(const char *name, unsigned int numa_node) > +{ > + struct pmd_internals *internals =3D NULL; > + struct rte_eth_dev_data *data; > + struct rte_eth_dev *eth_dev; > + uint16_t nb_rx_queues =3D 1; > + uint16_t nb_tx_queues =3D 1; Since these two values are always 1 here, I think they could be removed. > + > + RTE_LOG(INFO, PMD, "Creating kni ethdev on numa socket %u\n", > + numa_node); > + > + data =3D rte_zmalloc_socket(name, sizeof(*data), 0, numa_node); > + if (data =3D=3D NULL) > + goto error; > + > + internals =3D rte_zmalloc_socket(name, sizeof(*internals), 0, > numa_node); > + if (internals =3D=3D NULL) > + goto error; > + > + /* reserve an ethdev entry */ > + eth_dev =3D rte_eth_dev_allocate(name); > + if (eth_dev =3D=3D NULL) > + goto error; > + > + data->dev_private =3D internals; > + data->port_id =3D eth_dev->data->port_id; > + memmove(data->name, eth_dev->data->name, sizeof(data- > >name)); > + data->nb_rx_queues =3D nb_rx_queues; > + data->nb_tx_queues =3D nb_tx_queues; > + data->dev_link =3D pmd_link; > + data->mac_addrs =3D ð_addr; > + > + eth_dev->data =3D data; > + eth_dev->dev_ops =3D ð_kni_ops; > + eth_dev->driver =3D NULL; > + > + data->dev_flags =3D RTE_ETH_DEV_DETACHABLE; > + data->kdrv =3D RTE_KDRV_NONE; > + data->drv_name =3D drivername; > + data->numa_node =3D numa_node; > + > + return eth_dev; > + > +error: > + rte_free(data); > + rte_free(internals); > + > + return NULL; > +} > + > +static int > +kni_init(void) > +{ > + if (is_kni_initialized =3D=3D 0) > + rte_kni_init(MAX_KNI_PORTS); > + > + is_kni_initialized +=3D 1; > + > + return 0; > +} > + > +static int > +eth_kni_probe(const char *name, const char *params __rte_unused) > +{ > + struct rte_eth_dev *eth_dev; > + int ret; > + > + RTE_LOG(INFO, PMD, "Initializing eth_kni for %s\n", name); > + > + ret =3D kni_init(); > + if (ret < 0) > + /* Not return error to prevent panic in rte_eal_init() */ > + return 0; > + > + eth_dev =3D eth_kni_create(name, rte_socket_id()); > + if (eth_dev =3D=3D NULL) > + return -1; > + > + eth_dev->rx_pkt_burst =3D eth_kni_rx; > + eth_dev->tx_pkt_burst =3D eth_kni_tx; > + > + return 0; > +} > + > +static int > +eth_kni_remove(const char *name) > +{ > + struct rte_eth_dev *eth_dev; > + struct pmd_internals *internals; > + > + RTE_LOG(INFO, PMD, "Un-Initializing eth_kni for %s\n", name); > + > + /* find the ethdev entry */ > + eth_dev =3D rte_eth_dev_allocated(name); > + if (eth_dev =3D=3D NULL) > + return -1; > + > + eth_kni_dev_stop(eth_dev); > + > + if (eth_dev->data) { > + internals =3D eth_dev->data->dev_private; > + rte_kni_release(internals->kni); > + > + rte_free(internals); > + } > + rte_free(eth_dev->data); > + > + rte_eth_dev_release_port(eth_dev); > + > + is_kni_initialized -=3D 1; > + if (is_kni_initialized =3D=3D 0) > + rte_kni_close(); > + > + return 0; > +} > + > +static struct rte_vdev_driver eth_kni_drv =3D { > + .probe =3D eth_kni_probe, > + .remove =3D eth_kni_remove, > +}; > + > +DRIVER_REGISTER_VDEV(DRV_NAME, eth_kni_drv); > diff --git a/drivers/net/kni/rte_pmd_kni_version.map > b/drivers/net/kni/rte_pmd_kni_version.map > new file mode 100644 > index 0000000..61463bf > --- /dev/null > +++ b/drivers/net/kni/rte_pmd_kni_version.map > @@ -0,0 +1,4 @@ > +DPDK_16.11 { > + > + local: *; > +}; > diff --git a/mk/rte.app.mk b/mk/rte.app.mk > index ac50a21..a94983b 100644 > --- a/mk/rte.app.mk > +++ b/mk/rte.app.mk > @@ -59,11 +59,6 @@ _LDLIBS-y +=3D -L$(RTE_SDK_BIN)/lib > # > # Order is important: from higher level to lower level > # > - > -ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y) > -_LDLIBS-$(CONFIG_RTE_LIBRTE_KNI) +=3D -lrte_kni > -endif > - > _LDLIBS-$(CONFIG_RTE_LIBRTE_PIPELINE) +=3D -lrte_pipeline > _LDLIBS-$(CONFIG_RTE_LIBRTE_TABLE) +=3D -lrte_table > _LDLIBS-$(CONFIG_RTE_LIBRTE_PORT) +=3D -lrte_port > @@ -84,6 +79,10 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_POWER) +=3D - > lrte_power >=20 > _LDLIBS-y +=3D --whole-archive >=20 > +ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y) > +_LDLIBS-$(CONFIG_RTE_LIBRTE_KNI) +=3D -lrte_kni > +endif > + > _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER) +=3D -lrte_timer > _LDLIBS-$(CONFIG_RTE_LIBRTE_HASH) +=3D -lrte_hash > _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) +=3D -lrte_vhost > @@ -114,6 +113,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) +=3D - > lrte_pmd_enic > _LDLIBS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) +=3D -lrte_pmd_fm10k > _LDLIBS-$(CONFIG_RTE_LIBRTE_I40E_PMD) +=3D -lrte_pmd_i40e > _LDLIBS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) +=3D -lrte_pmd_ixgbe > +_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D -lrte_pmd_kni > _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) +=3D -lrte_pmd_mlx4 - > libverbs > _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D -lrte_pmd_mlx5 - > libverbs > _LDLIBS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) +=3D -lrte_pmd_mpipe -lgxio > -- > 2.7.4