From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by dpdk.org (Postfix) with ESMTP id 31BB17D18 for ; Wed, 24 May 2017 17:18:44 +0200 (CEST) Received: by mail-wm0-f45.google.com with SMTP id b84so68114798wmh.0 for ; Wed, 24 May 2017 08:18:44 -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=aAC2ufzA2NNnYaGHStLyOpSMmbdn5cipdwDpMrJN28A=; b=kys0w8b1BZOj+GWRwk9i6zINbzMcacRr70wXtHekmWAUXryK9iVkZ8B/MwgMrWR3go tGN73H/Bw5mdter5BzIVlK5b4OerxNGqu6aBRczlUqr1UUlfFDPAfVe8EPletEH7/mI+ rg5TPpTsbBoI6MjNUMdhEGUGf6Zn/SbFA+zjnXQU5/FWP5LyKUR22v/dlpOatFtWjN3L eNSAR12yYvYj7heSp3zQhLhX6xf//3f5FHCL4xR34nsFH9K6APOubVbAbFqCKnbe1uPj mnLluFShTBBN5NGdv17+XsDy/Ak3XBX1RYV0z1o4azgXRtwnttEhFxf/7eriOHIAmyHS lBqw== 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=aAC2ufzA2NNnYaGHStLyOpSMmbdn5cipdwDpMrJN28A=; b=Fg+/YoHr83pn/2dxfE3ez0rNPjw4qSRkf0tjJ8BW+7Ume+jddcf0CAdKhKEOwzUlKp OwdUvvrCZZdAnyoJYXA5jZjhCmZtmy+cfWPy3TAJWjMPCrIGM8UkkkFP/MKqLUdEI+dV OLnAwbdN5iw4/KiKRx2ICf3EIlphbfXyqe7GYBfwsH/39oCDC2icZtt97OYESjcZIDeK 7hpDO1unXZuuIRsOHEf3qGbkewYOPebo87YatboPfHDGUN8+7xGC/baYnLLsCGFLV9Ks 0Su0jeRJQs05raRO0rj14Z3Uo78j7JxPdtwpm9hd2CxDcB9DUNdXpv+/+96Q/xC9lLUd 8T3A== X-Gm-Message-State: AODbwcBaFGNydLAMrkrWBs5pHyBNnphw+hmCEl7XRFdKiVePp8seN4ST rvaJmIbej+UZY5bTVis= X-Received: by 10.28.191.26 with SMTP id p26mr6685831wmf.54.1495639123532; Wed, 24 May 2017 08:18: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 p107sm5880800wrb.64.2017.05.24.08.18.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:18:42 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , Jan Blunck , Stephen Hemminger , Maxime Coquelin , Jerin Jacob , David Marchand Date: Wed, 24 May 2017 17:18:30 +0200 Message-Id: <0b2ee4823592849eef67bc28896399637d97acad.1495629219.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 2/3] vdev: implement attach 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, 24 May 2017 15:18:44 -0000 Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 53 +++++++++++++++++++-------------- lib/librte_eal/common/eal_common_vdev.c | 8 ++++- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 829d7f3..fdd06be 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -61,6 +61,9 @@ static int cmp_detached_dev_name(const struct rte_device *dev, int rte_eal_dev_attach(const char *name, const char *devargs) { struct rte_device *dev; + struct rte_device device; + struct rte_devargs da; + struct rte_bus *bus; int ret; if (name == NULL || devargs == NULL) { @@ -69,31 +72,35 @@ int rte_eal_dev_attach(const char *name, const char *devargs) } dev = rte_bus_find_device(NULL, cmp_detached_dev_name, name); - if (dev) { - struct rte_bus *bus; - + if (dev) bus = rte_bus_find_by_device(dev); - if (!bus) { - RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", - name); - return -EINVAL; - } - - if (!bus->attach) { - RTE_LOG(ERR, EAL, "Bus function not supported\n"); - return -ENOTSUP; - } - - ret = bus->attach(dev); - goto out; + else + bus = rte_bus_from_dev(name); + if (!bus) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", + name); + return -EINVAL; } - - /* - * If we haven't found a bus device the user meant to "hotplug" a - * virtual device instead. - */ - ret = rte_vdev_init(name, devargs); -out: + if (!bus->attach) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; + } + if (!dev) { + char da_str[snprintf(NULL, 0, "%s,%s", name, devargs) + 1]; + + /* + * If we haven't found a bus device the user meant to "hotplug" + * a device instead. + */ + dev = &device; + snprintf(da_str, sizeof(da_str), "%s,%s", name, devargs); + ret = rte_eal_devargs_parse(da_str, &da); + if (ret) + return ret; + dev->name = da.name; + dev->devargs = &da; + } + ret = bus->attach(dev); if (ret) RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name); diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c index fc5e2d2..4e83326 100644 --- a/lib/librte_eal/common/eal_common_vdev.c +++ b/lib/librte_eal/common/eal_common_vdev.c @@ -356,6 +356,12 @@ vdev_find_device(int (*match)(const struct rte_device *dev, const void *data), } static int +vdev_attach(struct rte_device *dev) +{ + return rte_vdev_init(dev->devargs->name, dev->devargs->args); +} + +static int vdev_detach(struct rte_device *dev) { /* @@ -369,7 +375,7 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, - /* .attach = NULL, see comment on vdev_detach */ + .attach = vdev_attach, .detach = vdev_detach, .parse = vdev_parse, }; -- 2.1.4