From: Jan Viktorin <viktorin@rehivetech.com>
To: dev@dpdk.org
Cc: Jan Viktorin <viktorin@rehivetech.com>
Subject: [dpdk-dev] [PATCH 09/14] lib/ether: generalize attach/detach of devices
Date: Mon, 4 Jan 2016 21:08:21 +0100 [thread overview]
Message-ID: <1451938106-12145-10-git-send-email-viktorin@rehivetech.com> (raw)
In-Reply-To: <1451938106-12145-1-git-send-email-viktorin@rehivetech.com>
Make the attach and detach functions independent on the PCI infra. Mostly, this
means to utilize the rte_bus_addr instead of rte_pci_addr.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_ether/rte_ethdev.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 826d4b9..db12515 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -432,7 +432,7 @@ rte_eth_dev_get_device_type(uint8_t port_id)
}
static int
-rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
+rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_bus_addr *addr)
{
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
@@ -441,8 +441,15 @@ rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
return -EINVAL;
}
- *addr = rte_eth_devices[port_id].pci_dev->addr;
- return 0;
+ if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
+ addr->pci = rte_eth_devices[port_id].pci_dev->addr;
+ addr->dev_magic = RTE_PCI_DEVICE_MAGIC;
+ return 0;
+ } else {
+ rte_panic("%s(): unexpected dev_type: %u\n", __func__,
+ rte_eth_devices[port_id].dev_type);
+ return -ENODEV;
+ }
}
static int
@@ -566,10 +573,10 @@ err:
/* detach the new physical device, then store pci_addr of the device */
static int
-rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
+rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_bus_addr *addr)
{
- struct rte_pci_addr freed_addr;
- struct rte_pci_addr vp;
+ struct rte_bus_addr freed_addr;
+ struct rte_bus_addr vp;
if (addr == NULL)
goto err;
@@ -583,13 +590,16 @@ rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
goto err;
/* Zeroed pci addr means the port comes from virtual device */
- vp.domain = vp.bus = vp.devid = vp.function = 0;
- if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
+ memset(&vp, 0, sizeof(vp));
+ if (rte_eal_compare_bus_addr(&vp, &freed_addr) == 0)
goto err;
/* invoke devuninit func of the pci driver,
* also remove the device from pci_device_list */
- if (rte_eal_pci_detach(&freed_addr))
+ if (freed_addr.dev_magic == RTE_PCI_DEVICE_MAGIC) {
+ if (rte_eal_pci_detach(&freed_addr.pci))
+ goto err;
+ } else
goto err;
*addr = freed_addr;
@@ -683,7 +693,7 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
int
rte_eth_dev_detach(uint8_t port_id, char *name)
{
- struct rte_pci_addr addr;
+ struct rte_bus_addr addr;
int ret;
if (name == NULL)
@@ -698,8 +708,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
if (ret == 0)
snprintf(name, RTE_ETH_NAME_MAX_LEN,
"%04x:%02x:%02x.%d",
- addr.domain, addr.bus,
- addr.devid, addr.function);
+ addr.pci.domain, addr.pci.bus,
+ addr.pci.devid, addr.pci.function);
return ret;
} else
--
2.6.3
next prev parent reply other threads:[~2016-01-04 20:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-04 20:08 [dpdk-dev] [PATCH 00/14] Step towards PCI independency Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 01/14] eal/common: introduce RTE_PCI_DRV_MAGIC Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 02/14] eal/common: introduce RTE_PCI_DEVICE_MAGIC Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 03/14] eal/common: introduce union rte_device and related Jan Viktorin
2016-01-13 14:01 ` Bruce Richardson
2016-01-13 14:12 ` Jan Viktorin
2016-01-13 14:24 ` Bruce Richardson
2016-01-04 20:08 ` [dpdk-dev] [PATCH 04/14] eal/common: introduce function to_pci_driver Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 05/14] eal/common: introduce function to_pci_device Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 06/14] Include rte_dev.h instead of rte_pci.h Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 07/14] lib/ether: generalize rte_eth_dev_init/uninit Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 08/14] eal/common: introduce rte_bus_addr Jan Viktorin
2016-01-04 20:08 ` Jan Viktorin [this message]
2016-01-04 20:08 ` [dpdk-dev] [PATCH 10/14] lib/ether: copy the rte_device union instead of rte_pci_device Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 11/14] lib/ether: extract function rte_device_get_intr_handle Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 12/14] lib/ether: check magic before naming a zone Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 13/14] lib/ether: check magic in rte_eth_copy_pci_info Jan Viktorin
2016-01-04 20:08 ` [dpdk-dev] [PATCH 14/14] lib/ether: introduce rte_eth_copy_dev_info Jan Viktorin
[not found] ` <CALwxeUtxE5Gd+UvZOHz+fyHSjLi9Tjkc=99QHpag62KV+UP+NA@mail.gmail.com>
2016-01-11 17:29 ` [dpdk-dev] [PATCH 00/14] Step towards PCI independency Jan Viktorin
2016-01-13 14:07 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1451938106-12145-10-git-send-email-viktorin@rehivetech.com \
--to=viktorin@rehivetech.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).