From patchwork Thu Jun 28 22:51:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 41891 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7A1DD1B063; Fri, 29 Jun 2018 00:52:07 +0200 (CEST) Received: from mail-ot0-f195.google.com (mail-ot0-f195.google.com [74.125.82.195]) by dpdk.org (Postfix) with ESMTP id 760741B063 for ; Fri, 29 Jun 2018 00:52:05 +0200 (CEST) Received: by mail-ot0-f195.google.com with SMTP id f17-v6so7958198otl.7 for ; Thu, 28 Jun 2018 15:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=djh6S5mwETgXxisTt962bYrDK6hsNfq1oEedVn8n42k=; b=Rd50dxHesmnv0zRxm1Tcll0LsP2GhAMpvQVS6TqUZCIpK1FXKc6FLqbKybaLsKwN4l V5tBOXKY7pWQR2GlmpvkOtoU2+LHp6gmMpClZCbxh9+B/WU6nXnXj7suDV+6nkOnL3Dc k9gC4pxPGIJmSxwOSGFwTY6NDIfhFXLekIbhjnlkEAWzTFegX+DToXmarNVzjeSVKu35 jmdnsnBtvTlRKUHILr7Xb6Y+/RVtSMq7Yo0c8klPWyEGZjhq82/eJ4gDpp9EmsxRwVgx SvudnVYfB6rME+8EsOEvLFSR8OZEu7qEO7AtSwHNS2jhk/4pgAvb5FrFINfgKkIv8pF/ 7ioA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=djh6S5mwETgXxisTt962bYrDK6hsNfq1oEedVn8n42k=; b=aAN9B9tR6Im6SAjMuszUY5VlxlFq20YBNRzZe3uYIMXXfg7s0pcTxJbgSg34sqGn+d B4E16qCViLSsjY/usVavbDMncnWtPGd2JcqDgfxckOwmDzJzwiPcfFspCBasArNoO+i/ xVfoaeg/xJQhBZXDdBiMJZX1tvbv8kMUnanwo6p4GvxqtYUkJCjD9DKrXjRKmAOj/BJm HKtbkEvADOrBzInM/2GeIn0QXJwj259pl9Ow2JdYaXwuQs17AXMN+i+8DNbz6PFOrpPi 6nhXo/YzaTCwD5ULQBO5KUNtL9zOyUb881VvbrQQvgZ5kIXUEHR5uV3vPNWlMHnofTrA haJQ== X-Gm-Message-State: APt69E3mRYSyIMkKhtQnXxMySwuYbg2deMKe3xgCL/lk3TUDl7cX/Rqe hzrMJhlavg5bVVZU8DEzFsY= X-Google-Smtp-Source: AAOMgpce3cC13VboG7sxgxQvxHx7koRmjsEz8bdvplppLK3n9ctiwPgjtXW1sbrrSkT1lZaD3ul8ug== X-Received: by 2002:a9d:3ba1:: with SMTP id k30-v6mr7649009otc.211.1530226324676; Thu, 28 Jun 2018 15:52:04 -0700 (PDT) Received: from linux.adax.com (172-11-198-60.lightspeed.sntcca.sbcglobal.net. [172.11.198.60]) by smtp.gmail.com with ESMTPSA id 78-v6sm4162457oii.0.2018.06.28.15.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 15:52:03 -0700 (PDT) From: Dan Gora To: Ferruh Yigit Cc: dev@dpdk.org, Dan Gora Date: Thu, 28 Jun 2018 15:51:54 -0700 Message-Id: <20180628225154.20556-1-dg@adax.com> X-Mailer: git-send-email 2.18.0.rc1.1.g6f333ff2f Subject: [dpdk-dev] [PATCH 04/10] kni: add rte_kni_free to KNI library 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add the new rte_kni_free() API function to the KNI library. This function will be called by DPDK applications after rte_kni_release() to free the KNI interface resources from the kernel driver. Signed-off-by: Dan Gora --- lib/librte_kni/rte_kni.c | 32 +++++++++++++++++++++++++++++--- lib/librte_kni/rte_kni.h | 31 +++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 8a8f6c1cc..1d84c0b70 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -463,8 +463,6 @@ int rte_kni_release(struct rte_kni *kni) { struct rte_kni_device_info dev_info; - uint32_t slot_id; - uint32_t retry = 5; if (!kni || !kni->in_use) return -1; @@ -475,6 +473,34 @@ rte_kni_release(struct rte_kni *kni) return -1; } + kni->in_use = 0; + return 0; +} + +int +rte_kni_free(struct rte_kni *kni) +{ + uint32_t slot_id; + uint32_t retry = 5; + struct rte_kni_device_info dev_info; + + if (!kni) + return -EINVAL; + + /* Must call rte_kni_release() first */ + if (kni->in_use) + return -EBUSY; + + /* + * Free the FIFOs in the kernel and remove it from the list + * of devices to poll + */ + snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name); + if (ioctl(kni_fd, RTE_KNI_IOCTL_FREE, &dev_info) < 0) { + RTE_LOG(ERR, KNI, "Fail to release kni device\n"); + return -1; + } + /* mbufs in all fifo should be released, except request/response */ /* wait until all rxq packets processed by kernel */ @@ -497,7 +523,7 @@ rte_kni_release(struct rte_kni *kni) if (slot_id > kni_memzone_pool.max_ifaces) { RTE_LOG(ERR, KNI, "KNI pool: corrupted slot ID: %d, max: %d\n", slot_id, kni_memzone_pool.max_ifaces); - return -1; + return -EINVAL; } kni_memzone_pool_release(&kni_memzone_pool.slots[slot_id]); diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 99055e2c2..d1a95f898 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -112,11 +112,17 @@ struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool, const struct rte_kni_conf *conf, struct rte_kni_ops *ops); /** - * Release KNI interface according to the context. It will also release the - * paired KNI interface in kernel space. All processing on the specific KNI - * context need to be stopped before calling this interface. + * Release specified KNI interface. This will stop data transfer to and from + * this interface and will remove the paired KNI interface in kernel space. * - * rte_kni_release is thread safe. + * @note This function will trigger the kernel to remove the interface, which + * may trigger the RTE_KNI_REQ_CFG_NETWORK_IF KNI callback. This function will + * block until this callback is handled or times out. The user should ensure + * that rte_kni_handle_request() is called for this interface in a separate + * thread to handle this callback to avoid this delay. + * + * rte_kni_release() is thread safe, but should not be called from the same + * thread as rte_kni_handle_request(). * * @param kni * The pointer to the context of an existent KNI interface. @@ -127,6 +133,23 @@ struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool, */ int rte_kni_release(struct rte_kni *kni); +/** + * Free specified KNI interface. It will also free the KNI interface resources + * in kernel space. No KNI functions for this interface should be called after + * or at the same time as calling this function. rte_kni_release() must be + * called before this function to release the kernel interface. + * + * @param kni + * The pointer to the context of an existent KNI interface. + * + * @return + * - 0 indicates success. + * - -EINVAL: Invalid kni structure. + * - -EBUSY: KNI interface still in use. Must call rte_kni_release(). + */ +int __rte_experimental +rte_kni_free(struct rte_kni *kni); + /** * It is used to handle the request mbufs sent from kernel space. * Then analyzes it and calls the specific actions for the specific requests.