get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2375/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2375,
    "url": "https://patches.dpdk.org/api/patches/2375/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1421664027-17971-11-git-send-email-mukawa@igel.co.jp/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1421664027-17971-11-git-send-email-mukawa@igel.co.jp>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1421664027-17971-11-git-send-email-mukawa@igel.co.jp",
    "date": "2015-01-19T10:40:26",
    "name": "[dpdk-dev,v4,10/11] eal/pci: Add rte_eal_dev_attach/detach() functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "75c53c67f95530b185ff634d3f7ee2cf2bc5262f",
    "submitter": {
        "id": 64,
        "url": "https://patches.dpdk.org/api/people/64/?format=api",
        "name": "Tetsuya Mukawa",
        "email": "mukawa@igel.co.jp"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1421664027-17971-11-git-send-email-mukawa@igel.co.jp/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2375/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2375/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 78C235AD0;\n\tMon, 19 Jan 2015 11:41:46 +0100 (CET)",
            "from mail-pd0-f178.google.com (mail-pd0-f178.google.com\n\t[209.85.192.178]) by dpdk.org (Postfix) with ESMTP id 4A4845ABF\n\tfor <dev@dpdk.org>; Mon, 19 Jan 2015 11:41:26 +0100 (CET)",
            "by mail-pd0-f178.google.com with SMTP id r10so35817348pdi.9\n\tfor <dev@dpdk.org>; Mon, 19 Jan 2015 02:41:25 -0800 (PST)",
            "from localhost.localdomain (napt.igel.co.jp. [219.106.231.132])\n\tby mx.google.com with ESMTPSA id\n\ta13sm11337588pdm.44.2015.01.19.02.41.24\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tMon, 19 Jan 2015 02:41:24 -0800 (PST)"
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=LITgkhtdCaK7RQkGbd0/X/yzjUu1d8oaVe1IbOZHvGc=;\n\tb=MqGZ9UUGoYTxDJPDP5Q0yAtguxyeP2Al1QwVjqgdm8mFFC4QJDQ2GCWwv+UQvO3QFo\n\tPp86BR20wXKZDqoQfr5eYS4bKK0T6jpDIT3Bio1dKAfLmWfBR2X0zFXNIn2MO3SVh8bQ\n\teHiyBoQg/m/ycO/hW5FD57wMmGRHVTDBPL1+tlVQFZeIm/sfX01P91hMtP5Ssh2pHed7\n\tVOUrVMc+P47dzSWALGSOni/XyJamqYB/3lDkPmdFfrmZWRye0HEY/3Z9qZdeyenkagFG\n\tr2HSXmgAXwWZFiBea4k+YXrywhKsmGAv5xjIzHIGfG/VK1kpXLkh+Iwn9y4jN5qsF3hr\n\tWb3w==",
        "X-Gm-Message-State": "ALoCoQmcj2ZkitWvaTkwVNzOgWsu45VS8eh1RiVQsgnPXybZad0JXra4yP0C/0VDw66aBAjmQLm9",
        "X-Received": "by 10.68.242.200 with SMTP id ws8mr43880016pbc.138.1421664085663;\n\tMon, 19 Jan 2015 02:41:25 -0800 (PST)",
        "From": "Tetsuya Mukawa <mukawa@igel.co.jp>",
        "To": "dev@dpdk.org",
        "Date": "Mon, 19 Jan 2015 19:40:26 +0900",
        "Message-Id": "<1421664027-17971-11-git-send-email-mukawa@igel.co.jp>",
        "X-Mailer": "git-send-email 1.9.1",
        "In-Reply-To": "<1421664027-17971-1-git-send-email-mukawa@igel.co.jp>",
        "References": "<1418106629-22227-2-git-send-email-mukawa@igel.co.j>\n\t<1421664027-17971-1-git-send-email-mukawa@igel.co.jp>",
        "Subject": "[dpdk-dev] [PATCH v4 10/11] eal/pci: Add\n\trte_eal_dev_attach/detach() functions",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "These functions are used for attaching or detaching a port.\nWhen rte_eal_dev_attach() is called, the function tries to realize the\ndevice name as pci address. If this is done successfully,\nrte_eal_dev_attach() will attach physical device port. If not, attaches\nvirtual devive port.\nWhen rte_eal_dev_detach() is called, the function gets the device type\nof this port to know whether the port is came from physical or virtual.\nAnd then specific detaching function will be called.\n\nv4:\n- Fix comment.\n- Add error checking.\n- Fix indent of 'if' statement.\n- Change function name.\n\nSigned-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>\n---\n lib/librte_eal/common/eal_common_dev.c  | 273 ++++++++++++++++++++++++++++++++\n lib/librte_eal/common/eal_private.h     |  11 ++\n lib/librte_eal/common/include/rte_dev.h |  33 ++++\n lib/librte_eal/linuxapp/eal/Makefile    |   1 +\n lib/librte_eal/linuxapp/eal/eal_pci.c   |   6 +-\n 5 files changed, 321 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c\nindex eae5656..828bd70 100644\n--- a/lib/librte_eal/common/eal_common_dev.c\n+++ b/lib/librte_eal/common/eal_common_dev.c\n@@ -32,10 +32,13 @@\n  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n  */\n \n+#include <stdio.h>\n+#include <limits.h>\n #include <string.h>\n #include <inttypes.h>\n #include <sys/queue.h>\n \n+#include <rte_ethdev.h>\n #include <rte_dev.h>\n #include <rte_devargs.h>\n #include <rte_debug.h>\n@@ -107,3 +110,273 @@ rte_eal_dev_init(void)\n \t}\n \treturn 0;\n }\n+\n+/* So far, DPDK hotplug function only supports linux */\n+#ifdef ENABLE_HOTPLUG\n+static void\n+rte_eal_dev_invoke(struct rte_driver *driver,\n+\t\tstruct rte_devargs *devargs, enum rte_eal_invoke_type type)\n+{\n+\tif ((driver == NULL) || (devargs == NULL))\n+\t\treturn;\n+\n+\tswitch (type) {\n+\tcase RTE_EAL_INVOKE_TYPE_PROBE:\n+\t\tdriver->init(devargs->virtual.drv_name, devargs->args);\n+\t\tbreak;\n+\tcase RTE_EAL_INVOKE_TYPE_CLOSE:\n+\t\tdriver->uninit(devargs->virtual.drv_name, devargs->args);\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+}\n+\n+static int\n+rte_eal_dev_find_and_invoke(const char *name, int type)\n+{\n+\tstruct rte_devargs *devargs;\n+\tstruct rte_driver *driver;\n+\n+\tif (name == NULL)\n+\t\treturn -EINVAL;\n+\n+\t/* call the init function for each virtual device */\n+\tTAILQ_FOREACH(devargs, &devargs_list, next) {\n+\n+\t\tif (devargs->type != RTE_DEVTYPE_VIRTUAL)\n+\t\t\tcontinue;\n+\n+\t\tif (strncmp(name, devargs->virtual.drv_name, strlen(name)))\n+\t\t\tcontinue;\n+\n+\t\tTAILQ_FOREACH(driver, &dev_driver_list, next) {\n+\t\t\tif (driver->type != PMD_VDEV)\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* search a driver prefix in virtual device name */\n+\t\t\tif (!strncmp(driver->name, devargs->virtual.drv_name,\n+\t\t\t    strlen(driver->name))) {\n+\t\t\t\trte_eal_dev_invoke(driver, devargs, type);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (driver == NULL) {\n+\t\t\tRTE_LOG(WARNING, EAL, \"no driver found for %s\\n\",\n+\t\t\t\t  devargs->virtual.drv_name);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\treturn 1;\n+}\n+\n+/* attach the new physical device, then store port_id of the device */\n+static int\n+rte_eal_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)\n+{\n+\tuint8_t new_port_id;\n+\tstruct rte_eth_dev devs[RTE_MAX_ETHPORTS];\n+\n+\tif ((addr == NULL) || (port_id == NULL))\n+\t\tgoto err;\n+\n+\t/* save current port status */\n+\trte_eth_dev_save(devs);\n+\t/* re-construct pci_device_list */\n+\tif (rte_eal_pci_scan())\n+\t\tgoto err;\n+\t/* invoke probe func of the driver can handle the new device */\n+\tif (rte_eal_pci_probe_one(addr))\n+\t\tgoto err;\n+\t/* get port_id enabled by above procedures */\n+\tif (rte_eth_dev_get_changed_port(devs, &new_port_id))\n+\t\tgoto err;\n+\n+\t*port_id = new_port_id;\n+\treturn 0;\n+err:\n+\tRTE_LOG(ERR, EAL, \"Drver, cannot attach the device\\n\");\n+\treturn -1;\n+}\n+\n+/* detach the new physical device, then store pci_addr of the device */\n+static int\n+rte_eal_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)\n+{\n+\tstruct rte_pci_addr freed_addr;\n+\tstruct rte_pci_addr vp;\n+\n+\tif (addr == NULL)\n+\t\tgoto err;\n+\n+\t/* check whether the driver supports detach feature, or not */\n+\tif (rte_eth_dev_check_detachable(port_id))\n+\t\tgoto err;\n+\n+\t/* get pci address by port id */\n+\tif (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))\n+\t\tgoto err;\n+\n+\t/* Zerod pci addr means the port comes from virtual device */\n+\tvp.domain = vp.bus = vp.devid = vp.function = 0;\n+\tif (eal_compare_pci_addr(&vp, &freed_addr) == 0)\n+\t\tgoto err;\n+\n+\t/* invoke close func of the driver,\n+\t * also remove the device from pci_device_list */\n+\tif (rte_eal_pci_close_one(&freed_addr))\n+\t\tgoto err;\n+\n+\t*addr = freed_addr;\n+\treturn 0;\n+err:\n+\tRTE_LOG(ERR, EAL, \"Drver, cannot detach the device\\n\");\n+\treturn -1;\n+}\n+\n+static void\n+get_vdev_name(char *vdevargs)\n+{\n+\tchar *sep;\n+\n+\tif (vdevargs == NULL)\n+\t\treturn;\n+\n+\t/* set the first ',' to '\\0' to split name and arguments */\n+\tsep = strchr(vdevargs, ',');\n+\tif (sep != NULL)\n+\t\tsep[0] = '\\0';\n+}\n+\n+/* attach the new virtual device, then store port_id of the device */\n+static int\n+rte_eal_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)\n+{\n+\tchar *args;\n+\tuint8_t new_port_id;\n+\tstruct rte_eth_dev devs[RTE_MAX_ETHPORTS];\n+\n+\tif ((vdevargs == NULL) || (port_id == NULL))\n+\t\tgoto err0;\n+\n+\targs = strdup(vdevargs);\n+\tif (args == NULL)\n+\t\tgoto err0;\n+\n+\t/* save current port status */\n+\trte_eth_dev_save(devs);\n+\t/* add the vdevargs to devargs_list */\n+\tif (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, args))\n+\t\tgoto err1;\n+\t/* parse vdevargs, then retrieve device name */\n+\tget_vdev_name(args);\n+\t/* walk around dev_driver_list to find the driver of the device,\n+\t * then invoke probe function o the driver */\n+\tif (rte_eal_dev_find_and_invoke(args, RTE_EAL_INVOKE_TYPE_PROBE))\n+\t\tgoto err2;\n+\t/* get port_id enabled by above procedures */\n+\tif (rte_eth_dev_get_changed_port(devs, &new_port_id))\n+\t\tgoto err2;\n+\n+\tfree(args);\n+\t*port_id = new_port_id;\n+\treturn 0;\n+err2:\n+\trte_eal_devargs_remove(RTE_DEVTYPE_VIRTUAL, args);\n+err1:\n+\tfree(args);\n+err0:\n+\tRTE_LOG(ERR, EAL, \"Drver, cannot detach the device\\n\");\n+\treturn -1;\n+}\n+\n+/* detach the new virtual device, then store the name of the device */\n+static int\n+rte_eal_dev_detach_vdev(uint8_t port_id, char *vdevname)\n+{\n+\tchar name[RTE_ETH_NAME_MAX_LEN];\n+\n+\tif (vdevname == NULL)\n+\t\tgoto err;\n+\n+\t/* check whether the driver supports detach feature, or not */\n+\tif (rte_eth_dev_check_detachable(port_id))\n+\t\tgoto err;\n+\n+\t/* get device name by port id */\n+\tif (rte_eth_dev_get_name_by_port(port_id, name))\n+\t\tgoto err;\n+\t/* walk around dev_driver_list to find the driver of the device,\n+\t * then invoke close function o the driver */\n+\tif (rte_eal_dev_find_and_invoke(name, RTE_EAL_INVOKE_TYPE_CLOSE))\n+\t\tgoto err;\n+\t/* remove the vdevname from devargs_list */\n+\trte_eal_devargs_remove(RTE_DEVTYPE_VIRTUAL, name);\n+\n+\tstrncpy(vdevname, name, sizeof(name));\n+\treturn 0;\n+err:\n+\tRTE_LOG(ERR, EAL, \"Drver, cannot detach the device\\n\");\n+\treturn -1;\n+}\n+\n+/* attach the new device, then store port_id of the device */\n+int\n+rte_eal_dev_attach(const char *devargs, uint8_t *port_id)\n+{\n+\tstruct rte_pci_addr addr;\n+\n+\tif ((devargs == NULL) || (port_id == NULL))\n+\t\treturn -EINVAL;\n+\n+\tif (eal_parse_pci_DomBDF(devargs, &addr) == 0)\n+\t\treturn rte_eal_dev_attach_pdev(&addr, port_id);\n+\telse\n+\t\treturn rte_eal_dev_attach_vdev(devargs, port_id);\n+}\n+\n+/* detach the device, then store the name of the device */\n+int\n+rte_eal_dev_detach(uint8_t port_id, char *name)\n+{\n+\tstruct rte_pci_addr addr;\n+\tint ret;\n+\n+\tif (name == NULL)\n+\t\treturn -EINVAL;\n+\n+\tif (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PHYSICAL) {\n+\t\tret = rte_eth_dev_get_addr_by_port(port_id, &addr);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\n+\t\tret = rte_eal_dev_detach_pdev(port_id, &addr);\n+\t\tif (ret == 0)\n+\t\t\tsnprintf(name, RTE_ETH_NAME_MAX_LEN,\n+\t\t\t\t\"%04x.%02x.%02x.%d\",\n+\t\t\t\taddr.domain, addr.bus,\n+\t\t\t\taddr.devid, addr.function);\n+\n+\t\treturn ret;\n+\t} else\n+\t\treturn rte_eal_dev_detach_vdev(port_id, name);\n+}\n+#else /* ENABLE_HOTPLUG */\n+int\n+rte_eal_dev_attach(const char *devargs __rte_unused,\n+\t\t\tuint8_t *port_id __rte_unused)\n+{\n+\tRTE_LOG(ERR, EAL, \"Hotplug support isn't enabled\\n\");\n+\treturn -1;\n+}\n+\n+/* detach the device, then store the name of the device */\n+int\n+rte_eal_dev_detach(uint8_t port_id __rte_unused,\n+\t\t\tchar *name __rte_unused)\n+{\n+\tRTE_LOG(ERR, EAL, \"Hotplug support isn't enabled\\n\");\n+\treturn -1;\n+}\n+#endif /* ENABLE_HOTPLUG */\ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex a97c5d8..453a1eb 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -164,6 +164,17 @@ enum rte_eal_invoke_type {\n };\n \n /**\n+ * Scan the content of the PCI bus, and the devices in the devices\n+ * list\n+ *\n+ * This function is private to EAL.\n+ *\n+ * @return\n+ *  0 on success, negative on error\n+ */\n+int rte_eal_pci_scan(void);\n+\n+/**\n  * Mmap memory for single PCI device\n  *\n  * This function is private to EAL.\ndiff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h\nindex f7e3a10..e63dd1c 100644\n--- a/lib/librte_eal/common/include/rte_dev.h\n+++ b/lib/librte_eal/common/include/rte_dev.h\n@@ -47,6 +47,7 @@ extern \"C\" {\n #endif\n \n #include <sys/queue.h>\n+#include <rte_pci.h>\n \n /** Double linked list of device drivers. */\n TAILQ_HEAD(rte_driver_list, rte_driver);\n@@ -57,6 +58,11 @@ TAILQ_HEAD(rte_driver_list, rte_driver);\n typedef int (rte_dev_init_t)(const char *name, const char *args);\n \n /**\n+ * Uninitilization function called for each device driver once.\n+ */\n+typedef int (rte_dev_uninit_t)(const char *name, const char *args);\n+\n+/**\n  * Driver type enumeration\n  */\n enum pmd_type {\n@@ -72,6 +78,7 @@ struct rte_driver {\n \tenum pmd_type type;\t\t   /**< PMD Driver type */\n \tconst char *name;                   /**< Driver name. */\n \trte_dev_init_t *init;              /**< Device init. function. */\n+\trte_dev_uninit_t *uninit;          /**< Device uninit. function. */\n };\n \n /**\n@@ -93,6 +100,32 @@ void rte_eal_driver_register(struct rte_driver *driver);\n void rte_eal_driver_unregister(struct rte_driver *driver);\n \n /**\n+ * Attach a new device.\n+ *\n+ * @param devargs\n+ *   A pointer to a strings array describing the new device\n+ *   to be attached. The strings should be a pci address like\n+ *   '0000:01:00.0' or virtual device name like 'eth_pcap0'.\n+ * @param port_id\n+ *  A pointer to a port identifier actually attached.\n+ * @return\n+ *  0 on success and port_id is filled, negative on error\n+ */\n+int rte_eal_dev_attach(const char *devargs, uint8_t *port_id);\n+\n+/**\n+ * Detach a device.\n+ *\n+ * @param port_id\n+ *   The port identifier of the device to detach.\n+ * @param addr\n+ *  A pointer to a device name actually detached.\n+ * @return\n+ *  0 on success and devname is filled, negative on error\n+ */\n+int rte_eal_dev_detach(uint8_t port_id, char *devname);\n+\n+/**\n  * Initalize all the registered drivers in this process\n  */\n int rte_eal_dev_init(void);\ndiff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile\nindex 72ecf3a..0ec83b5 100644\n--- a/lib/librte_eal/linuxapp/eal/Makefile\n+++ b/lib/librte_eal/linuxapp/eal/Makefile\n@@ -41,6 +41,7 @@ CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common/include\n CFLAGS += -I$(RTE_SDK)/lib/librte_ring\n CFLAGS += -I$(RTE_SDK)/lib/librte_mempool\n CFLAGS += -I$(RTE_SDK)/lib/librte_malloc\n+CFLAGS += -I$(RTE_SDK)/lib/librte_mbuf\n CFLAGS += -I$(RTE_SDK)/lib/librte_ether\n CFLAGS += -I$(RTE_SDK)/lib/librte_ivshmem\n CFLAGS += -I$(RTE_SDK)/lib/librte_pmd_ring\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c\nindex a23cc59..8e7e650 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_pci.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c\n@@ -378,8 +378,8 @@ error:\n  * Scan the content of the PCI bus, and the devices in the devices\n  * list\n  */\n-static int\n-pci_scan(void)\n+int\n+rte_eal_pci_scan(void)\n {\n \tstruct dirent *e;\n \tDIR *dir;\n@@ -701,7 +701,7 @@ rte_eal_pci_init(void)\n \tif (internal_config.no_pci)\n \t\treturn 0;\n \n-\tif (pci_scan() < 0) {\n+\tif (rte_eal_pci_scan() < 0) {\n \t\tRTE_LOG(ERR, EAL, \"%s(): Cannot scan PCI bus\\n\", __func__);\n \t\treturn -1;\n \t}\n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "10/11"
    ]
}