From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 82DB92E83 for ; Tue, 9 Feb 2016 17:09:18 +0100 (CET) Received: by mail-wm0-f52.google.com with SMTP id g62so180843542wme.0 for ; Tue, 09 Feb 2016 08:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=siLmFUxdJFZFPcG8+1yD20/jE2N5R/8YcmGC6ztbQWQ=; b=xyf19tH9tjxrxOGBCtPkAuZWD9zljzs0e9NCGmt59CsH9AGBlEF3c+/jmCx2cp9Sj7 z3Ktqb7QQz+PVISVw5TFrH7l1GN5EbT21L+SyQCik8Bxf7Dlz77LxYARwx0vqSb1ursT 811nG6ocNRGBb+eJmzv6+qMWfbsHurYbIn7Q0CwrS801jI/z7EbZJyJCorzUbGjOyXzY mAQb4NQCJgxGmf3WrxvMS+Qo6PTkaaOur/s1OHcfnnzg040cp4vqPDB8Ky8QChNMzpDo cMRCWAB7HXaxZkeO3U+J32h9wtdnDIQBCF3ocfLTbx74isGhNCKHutJ33Xo0GcTPziDD OGiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=siLmFUxdJFZFPcG8+1yD20/jE2N5R/8YcmGC6ztbQWQ=; b=eV4qOJf3qOdnxPkYj48g1X1+GpEprSzWDJpj5xPvNHuL/wcOu6boxlYamhAZ9K6zSo y37iyHCdO2st4Xa3qJWLjS78VXw5Q5xPrDs+AlByG3WcNEh4xUNmAHnQFCR6j1nFgyPS 4sAfbmB/888x2czwP0joycjPbN5Qx19GunXVB2GWJj6Veu0IQEnLY4Mma01oD3LFtTf3 B93bY/bvAyvm01JWxBQwo0uHb0Yin2fgXM3arleR9e4ho6rBaLMgD4J3YLgz2RTpFARy pGRgMIWoI6zkMV14QUQ7MzYapL1tQbsr/rArTAKW29lOWYLhMd+aDJFe9r/F7yRoHjNl PxCQ== X-Gm-Message-State: AG10YOSzPDlR/xVG9mAlAauZJfwO+qZ5qif3lKdLUXFf7P85hhLmkRRv1dpszYQEj6r/wg== X-Received: by 10.28.211.141 with SMTP id k135mr5468229wmg.51.1455034158345; Tue, 09 Feb 2016 08:09:18 -0800 (PST) Received: from woz.semihalf.local ([80.82.22.190]) by smtp.gmail.com with ESMTPSA id gg7sm35422659wjd.10.2016.02.09.08.09.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Feb 2016 08:09:17 -0800 (PST) From: Wojciech Zmuda To: bernard.iremonger@intel.com, dev@dpdk.org Date: Tue, 9 Feb 2016 17:09:06 +0100 Message-Id: <1455034146-24036-1-git-send-email-woz@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452002675-8919-1-git-send-email-woz@semihalf.com> References: <1452002675-8919-1-git-send-email-woz@semihalf.com> Subject: [dpdk-dev] [PATCH v2] af_packet: make the device detachable 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: Tue, 09 Feb 2016 16:09:18 -0000 Implement rte_pmd_af_packet_devuninit() exposed through struct rte_driver.uninit() and set dev_flags to RTE_ETH_DEV_DETACHABLE, to allow af_packet device deinitialization with API function rte_eth_dev_detach(). This fixes memory leak by freeing memory allocated during initialization. During device initialization copy device name to ethdev->data to make it compatible with rte_eth_dev_allocated(). Signed-off-by: Wojciech Zmuda --- v2: * Fixed typo and a comment. * Added feature to the 2.3 release notes. * Free memory allocated for rx and tx queues. doc/guides/rel_notes/release_2_3.rst | 4 ++++ drivers/net/af_packet/rte_eth_af_packet.c | 37 ++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst index 7945694..4694646 100644 --- a/doc/guides/rel_notes/release_2_3.rst +++ b/doc/guides/rel_notes/release_2_3.rst @@ -39,6 +39,10 @@ This section should contain new features added in this release. Sample format: Enabled virtio 1.0 support for virtio pmd driver. +* **Added af_packet driver deinitialization function.** + + Implemented rte_pmd_af_packet_devuninit() exposed through struct + rte_driver.uninit() to allow af_packet device deinitialization with API function. Resolved Issues --------------- diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 767f36b..eaed916 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -667,11 +667,13 @@ rte_pmd_init_internals(const char *name, data->nb_tx_queues = (uint16_t)nb_queues; data->dev_link = pmd_link; data->mac_addrs = &(*internals)->eth_addr; + strncpy(data->name, + (*eth_dev)->data->name, strlen((*eth_dev)->data->name)); (*eth_dev)->data = data; (*eth_dev)->dev_ops = &ops; (*eth_dev)->driver = NULL; - (*eth_dev)->data->dev_flags = 0; + (*eth_dev)->data->dev_flags = RTE_ETH_DEV_DETACHABLE; (*eth_dev)->data->drv_name = drivername; (*eth_dev)->data->kdrv = RTE_KDRV_NONE; (*eth_dev)->data->numa_node = numa_node; @@ -836,10 +838,43 @@ exit: return ret; } +static int +rte_pmd_af_packet_devuninit(const char *name) +{ + struct rte_eth_dev *eth_dev = NULL; + struct pmd_internals *internals; + unsigned q; + + RTE_LOG(INFO, PMD, "Closing AF_PACKET ethdev on numa socket %u\n", + rte_socket_id()); + + if (name == NULL) + return -1; + + /* find the ethdev entry */ + eth_dev = rte_eth_dev_allocated(name); + if (eth_dev == NULL) + return -1; + + internals = eth_dev->data->dev_private; + for (q = 0; q < internals->nb_queues; q++) { + rte_free(internals->rx_queue[q].rd); + rte_free(internals->tx_queue[q].rd); + } + + rte_free(eth_dev->data->dev_private); + rte_free(eth_dev->data); + + rte_eth_dev_release_port(eth_dev); + + return 0; +} + static struct rte_driver pmd_af_packet_drv = { .name = "eth_af_packet", .type = PMD_VDEV, .init = rte_pmd_af_packet_devinit, + .uninit = rte_pmd_af_packet_devuninit, }; PMD_REGISTER_DRIVER(pmd_af_packet_drv); -- 1.9.1