From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by dpdk.org (Postfix) with ESMTP id AF6E137A2 for ; Thu, 8 Jun 2017 01:58:43 +0200 (CEST) Received: by mail-wm0-f41.google.com with SMTP id m7so35446372wmg.0 for ; Wed, 07 Jun 2017 16:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2zR3WDLCOR2hd4VsjOrcOgR+jB4C03dhSG1Go5v7B4A=; b=NlFeRIcjGgY8uU+aPgLp72WYwiHEFjqMxUY6BnMVoB6PhorZ8gv/CUY4EkmhHQpR+z t83dwNd/xWGHArifGRGUN8o2ZrT6pBs/yLyETRz7TS2sJz5YkCJfseCjKuVR1rZsJBxw So/H4/xe3KuuGzzu7zEZtBC0SY/QydprIcvUYDvsZHKbvUeK71Zh4tDzutsu4N52IEws Z+9Via/mk2b+A6gUavGhY5Bbru7ioFx7hNERwr4L0BBZKJM0W7JoamgN58QhORpwH8oh +8bPLeyLT+DoaPkdiZb7AmE/txzwzGZ1nJU+V4yCJ8P88jmk8Glzb8z60fw4pMDnbSOL SsbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=2zR3WDLCOR2hd4VsjOrcOgR+jB4C03dhSG1Go5v7B4A=; b=WziKVUQv0ejpmXOYgtsCzgKrHi59vOIfy4NChVFoYk+Fq6XwpTe3P+RAWtn+v2ZdGF W0viMtsxyzbGFVVmtZgRxzlLgVDiMp8owub6codj+p9lbebRZrRTDLOzIUCdAROgWR2g 5XaK/k9PTopX1eAxxqJ7RmxrA+7xKK5pvrynt+9y/cYZZ8LhrHUchhbYWLHFYD89563J V3fse+UsKc8ZfeACfyytMzB53Elm6hLK7dXEB/J1yLwmQoqzDWhVrG4sVRKcQv/8HiQC nw7hU+z+PkLTHRmCnq1IaHkrEEgI8uo6+1qoLflmz6gF4R9nKDSBT38YdZzuzwG9hhQ2 nbLA== X-Gm-Message-State: AODbwcCqUJ/LTf0JIT2brPZWMLJamhrjEWLN5HmhmAjjiKY0+7c0vKy2 bU6Y1HtfOQ1cQ0+0Kxw= X-Received: by 10.28.137.206 with SMTP id l197mr1270255wmd.41.1496879923107; Wed, 07 Jun 2017 16:58:43 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p65sm5098653wrb.64.2017.06.07.16.58.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 16:58:42 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 8 Jun 2017 01:58:28 +0200 Message-Id: <60a7c41e72b5aa9bb17e4729d081ec0a783b9054.1496876926.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 1/3] pci: implement hotplug bus operation 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: , X-List-Received-Date: Wed, 07 Jun 2017 23:58:44 -0000 Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_pci.c | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index b4f8056..6049b49 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -517,12 +518,78 @@ pci_find_device(rte_dev_cmp_t cmp, const void *data) return NULL; } +static struct rte_device * +pci_plug(struct rte_devargs *da) +{ + struct rte_pci_device *pdev; + struct rte_pci_addr addr; + + if (pci_parse(da->name, &addr)) { + rte_errno = EFAULT; + return NULL; + } + /* + * Update eventual pci device in global list. + * Insert it if none was found. + */ + if (pci_update_device(&addr) < 0) { + rte_errno = EIO; + return NULL; + } + /* Find the current device holding this address in the bus. */ + FOREACH_DEVICE_ON_PCIBUS(pdev) { + if (rte_eal_compare_pci_addr(&pdev->addr, &addr)) + continue; + /* Update eventual devargs. */ + pdev->device.devargs = rte_eal_devargs_clone(da); + if (pdev->device.devargs == NULL) { + rte_errno = ENOMEM; + return NULL; + } + break; + } + if (rte_pci_probe_one(&addr)) { + rte_errno = ENODEV; + return NULL; + } + /* Get back new device name. */ + if (pdev->device.devargs && + da != pdev->device.devargs) + snprintf(da->name, sizeof(da->name), "%s", + pdev->device.devargs->name); + return &pdev->device; +} + +static int +pci_unplug(struct rte_device *dev) +{ + struct rte_pci_addr addr; + + if (dev == NULL) { + rte_errno = EINVAL; + return -1; + } + if (pci_parse(dev->name, &addr)) { + rte_errno = EFAULT; + return -1; + } + if (rte_pci_detach(&addr)) { + rte_errno = ENODEV; + return -1; + } + if (dev->devargs) + rte_eal_devargs_rmv(dev->devargs); + return 0; +} + struct rte_pci_bus rte_pci_bus = { .bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, .parse = pci_parse, + .plug = pci_plug, + .unplug = pci_unplug, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), -- 2.1.4