From patchwork Fri Jun 29 01:55:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Gora X-Patchwork-Id: 41904 X-Patchwork-Delegate: thomas@monjalon.net 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 C698D1B554; Fri, 29 Jun 2018 03:56:00 +0200 (CEST) Received: from mail-oi0-f65.google.com (mail-oi0-f65.google.com [209.85.218.65]) by dpdk.org (Postfix) with ESMTP id D90F71B547 for ; Fri, 29 Jun 2018 03:55:53 +0200 (CEST) Received: by mail-oi0-f65.google.com with SMTP id y207-v6so7023675oie.13 for ; Thu, 28 Jun 2018 18:55:53 -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:in-reply-to:references; bh=djh6S5mwETgXxisTt962bYrDK6hsNfq1oEedVn8n42k=; b=Ka7fMH//SLn057O89CkrHjB2NegL3j09B/tMHS0Pe7+uxHnOXCqr95BgG3OshdCHVM w2Sle/QCU9MHDU+QDrtO3tU0HeNGthko6whc2LuFbeM6PMdBcu4S2QoMOkiTaSKngh6/ t60U8UL68vdz944CMC5RhRCUZkJiWA33D4ICwkaCtlrvzZdLB5Nilqkks2J7ORveFc3f /gHiKXZ3l9AtoWDxNiOTUYd5lauKM6LHhZ0IpSG5wVhzL1xuTXcLNNrwFWdWlnEEUXT8 x8kKGm7s798M3mbqegBKZykZawHrAb3c8gqgVlvUzbUXaKhelQwovTyZjT0WAg9lnZJl aEig== 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 :in-reply-to:references; bh=djh6S5mwETgXxisTt962bYrDK6hsNfq1oEedVn8n42k=; b=QBcUIlsCWcSVy2ICzWAMQ6NnemrFOU0AWh6eT8wOAVEBmrRQVO23F6okpA/m+suPCJ P9W/CJzjms6x96FO7QANxbVleSq0ups6W+240gKjXlT4NlopqCX16TnzanoHdcq4Qg14 KyqxV+ipDaaHI3qDkmqF5bfuOTiLSVEn0hxDToE4vY1BVl2zdqGHup9n1qVllPn5yvIw UOzGF76N3K1m+LwMaXvfuQkB63iX2RxfwCdSn9Z3spVH/RX8p0o0b9yiNpzorTJDgQvO ufnpgQRiR91dbREyYzbuTa/DiYL5ZeHMHSAPADAyWq8M0/PFcec21PoiyxP+VeuG8xnc HyGg== X-Gm-Message-State: APt69E0wIQVhrpnmyyoygCjnGrsVybqMtkGHEw3GoAu905kzepirf4gT hI7v4C/PicojIVwA5Tgh2/uuYQ== X-Google-Smtp-Source: AAOMgpeQx+Sg82B5guPaI7alE2OtxZh3S6TaE9d4EjN4fjUvfmXAXg2X7WOAcYih0bbzqNPY6by9Ow== X-Received: by 2002:aca:bdc1:: with SMTP id n184-v6mr6727047oif.305.1530237353076; Thu, 28 Jun 2018 18:55:53 -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 n3-v6sm3941288otk.38.2018.06.28.18.55.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 18:55:52 -0700 (PDT) From: Dan Gora To: ferruh.yigit@intel.com Cc: dev@dpdk.org, Dan Gora Date: Thu, 28 Jun 2018 18:55:02 -0700 Message-Id: <20180629015508.26599-5-dg@adax.com> X-Mailer: git-send-email 2.18.0.rc1.1.g6f333ff2f In-Reply-To: <20180629015508.26599-1-dg@adax.com> References: <20180628224513.18391-1-dg@adax.com> <20180629015508.26599-1-dg@adax.com> Subject: [dpdk-dev] [PATCH v2 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.