From patchwork Fri Jan 30 05:42:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 2786 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 1EE1A5ACB; Fri, 30 Jan 2015 06:45:05 +0100 (CET) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by dpdk.org (Postfix) with ESMTP id B70FA5A85 for ; Fri, 30 Jan 2015 06:44:53 +0100 (CET) Received: by mail-pa0-f54.google.com with SMTP id eu11so48143415pac.13 for ; Thu, 29 Jan 2015 21:44:53 -0800 (PST) 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=FzzY3ZxSpgZ1gztv8/e3fJ6HFQ5y1b/aG5jF39A389g=; b=ehbqUxSiyVUjou/1SCBEEcN4sf51tu1iXWOPibP/8Oi+mmk/xDyCZ22suGgJf2qtQA g1p0+SaeDqNWDLzQ5SkbnCQnBUQWKDBB1PTrXGce6ECD6fIaoKFEkevtqQvKJiDM0JVz VcC9FF0zSXBczhkm384Pt9z3vyPiw0BvrKP/njrSjQ5ew1ByoiunoYXhbjkWNpv0+6OR QiNZ14/AXD8/qNHnRbh2dhqRviR1iYvYSHGxk/TDseL6ydP/J5TdEtK1PE+UdXlUz44q kl2HqlF74BteHQF5eKl7u8jaUarWpcezbPAyHq2LWg8fUOHzaxnkVXsQyj6sGeDtkHZX 0eXw== X-Gm-Message-State: ALoCoQkgvmi1giXaBf1tWy+RsKaPfGTemhmuUYQdqLK7HnSZujKPF8n/xYM+GD8V97/Sdr6pec09 X-Received: by 10.69.20.74 with SMTP id ha10mr6611914pbd.10.1422596693125; Thu, 29 Jan 2015 21:44:53 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id ki4sm9482266pdb.34.2015.01.29.21.44.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 21:44:52 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Fri, 30 Jan 2015 14:42:34 +0900 Message-Id: <1422596563-26310-7-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422596563-26310-1-git-send-email-mukawa@igel.co.jp> References: <1421664027-17971-9-git-send-email-mukawa@igel.co.jp> <1422596563-26310-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v5 06/13] eal, ethdev: Add a function and function pointers to close ether device 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The patch adds function pointer to rte_pci_driver and eth_driver structure. These function pointers are used when ports are detached. Also the patch adds rte_eth_dev_uninit(). So far, it's not called by anywhere, but it will be called when port hotplug function is implemented. v4: - Add paramerter checking. - Change function names. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/include/rte_pci.h | 7 ++++++ lib/librte_ether/rte_ethdev.c | 40 +++++++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 24 ++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 4814cd7..87ca4cf 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -189,12 +189,19 @@ struct rte_pci_driver; typedef int (pci_devinit_t)(struct rte_pci_driver *, struct rte_pci_device *); /** + * Uninitialisation function for the driver called during hotplugging. + */ +typedef int (pci_devuninit_t)( + struct rte_pci_driver *, struct rte_pci_device *); + +/** * A structure describing a PCI driver. */ struct rte_pci_driver { TAILQ_ENTRY(rte_pci_driver) next; /**< Next in list. */ const char *name; /**< Driver name. */ pci_devinit_t *devinit; /**< Device init. function. */ + pci_devuninit_t *devuninit; /**< Device uninit function. */ struct rte_pci_id *id_table; /**< ID table, NULL terminated. */ uint32_t drv_flags; /**< Flags contolling handling of device. */ }; diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 0f3094f..fd19140 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -335,6 +335,45 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, return diag; } +static int +rte_eth_dev_uninit(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev) +{ + struct eth_driver *eth_drv; + struct rte_eth_dev *eth_dev; + char ethdev_name[RTE_ETH_NAME_MAX_LEN]; + + if ((pci_drv == NULL) || (pci_dev == NULL)) + return -EINVAL; + + /* Create unique Ethernet device name using PCI address */ + snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d", + pci_dev->addr.bus, pci_dev->addr.devid, + pci_dev->addr.function); + + eth_dev = rte_eth_dev_free(ethdev_name); + if (eth_dev == NULL) + return -ENODEV; + + eth_drv = (struct eth_driver *)pci_drv; + + /* Invoke PMD device uninit function */ + if (*eth_drv->eth_dev_uninit) + (*eth_drv->eth_dev_uninit)(eth_drv, eth_dev); + + /* init user callbacks */ + TAILQ_INIT(&(eth_dev->callbacks)); + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_free(eth_dev->data->dev_private); + + eth_dev->pci_dev = NULL; + eth_dev->driver = NULL; + eth_dev->data = NULL; + + return 0; +} + /** * Register an Ethernet [Poll Mode] driver. * @@ -353,6 +392,7 @@ void rte_eth_driver_register(struct eth_driver *eth_drv) { eth_drv->pci_drv.devinit = rte_eth_dev_init; + eth_drv->pci_drv.devuninit = rte_eth_dev_uninit; rte_eal_pci_register(ð_drv->pci_drv); } diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 6add058..0b4c27c 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1675,6 +1675,27 @@ typedef int (*eth_dev_init_t)(struct eth_driver *eth_drv, /** * @internal + * Finalization function of an Ethernet driver invoked for each matching + * Ethernet PCI device detected during the PCI closing phase. + * + * @param eth_drv + * The pointer to the [matching] Ethernet driver structure supplied by + * the PMD when it registered itself. + * @param eth_dev + * The *eth_dev* pointer is the address of the *rte_eth_dev* structure + * associated with the matching device and which have been [automatically] + * allocated in the *rte_eth_devices* array. + * @return + * - 0: Success, the device is properly finalized by the driver. + * In particular, the driver MUST free the *dev_ops* pointer + * of the *eth_dev* structure. + * - <0: Error code of the device initialization failure. + */ +typedef int (*eth_dev_uninit_t)(struct eth_driver *eth_drv, + struct rte_eth_dev *eth_dev); + +/** + * @internal * The structure associated with a PMD Ethernet driver. * * Each Ethernet driver acts as a PCI driver and is represented by a generic @@ -1684,11 +1705,14 @@ typedef int (*eth_dev_init_t)(struct eth_driver *eth_drv, * * - The *eth_dev_init* function invoked for each matching PCI device. * + * - The *eth_dev_uninit* function invoked for each matching PCI device. + * * - The size of the private data to allocate for each matching device. */ struct eth_driver { struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */ eth_dev_init_t eth_dev_init; /**< Device init function. */ + eth_dev_uninit_t eth_dev_uninit; /**< Device uninit function. */ unsigned int dev_private_size; /**< Size of device private data. */ };