Skip to contentSkip to conversation

prepare for rte_device / rte_driver

PATCH Superseded David Marchand 15 participants 375 messages Jan 29, 2016 – Oct 26, 2016 1 message not in the archive Page 1 of 5

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover prepare for rte_device / rte_driver

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

Patches 1 to 3 convert all existing pdev drivers into pci drivers and move their registration in constructors.

Patch 4 might be of interest to Chelsio guys, following a regression they reported [2].

Patches 5 and 6 align pci drivers and vdev drivers init.

Patches 7 to 9 move hotplug where it belongs.
I did not test patch 8 on FreeBSD (did not even compile it, for now).

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html
[2] http://dpdk.org/ml/archives/dev/2015-November/028289.html

Regards,

Signature · 59 lines
David Marchand

David Marchand (9):
  pci: no need for dynamic tailq init
  pci: register all pdev as pci drivers
  drivers: no more pdev drivers
  eal/linux: move back interrupt thread init before setting affinity
  eal: get rid of pmd type
  eal: initialize vdevs right next to pci devices
  pci: add a helper for device name
  pci: add a helper to refresh a device
  eal: relocate hotplug code from ethdev

 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c      |   2 +
 drivers/crypto/qat/rte_qat_cryptodev.c          |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |   2 +
 drivers/net/bnx2x/bnx2x_ethdev.c                |  34 +--
 drivers/net/bonding/rte_eth_bond_pmd.c          |   2 +
 drivers/net/cxgbe/cxgbe_ethdev.c                |  24 +-
 drivers/net/e1000/em_ethdev.c                   |  17 +-
 drivers/net/e1000/igb_ethdev.c                  |  40 +---
 drivers/net/enic/enic_ethdev.c                  |  23 +-
 drivers/net/fm10k/fm10k_ethdev.c                |  23 +-
 drivers/net/i40e/i40e_ethdev.c                  |  24 +-
 drivers/net/i40e/i40e_ethdev_vf.c               |  25 +-
 drivers/net/ixgbe/ixgbe_ethdev.c                |  46 +---
 drivers/net/mlx4/mlx4.c                         |  19 +-
 drivers/net/mlx5/mlx5.c                         |  19 +-
 drivers/net/mpipe/mpipe_tilegx.c                |   4 +
 drivers/net/nfp/nfp_net.c                       |  21 +-
 drivers/net/null/rte_eth_null.c                 |   2 +
 drivers/net/pcap/rte_eth_pcap.c                 |   2 +
 drivers/net/ring/rte_eth_ring.c                 |   2 +
 drivers/net/szedata2/rte_eth_szedata2.c         |   2 +
 drivers/net/virtio/virtio_ethdev.c              |  26 +--
 drivers/net/vmxnet3/vmxnet3_ethdev.c            |  23 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   2 +
 lib/librte_cryptodev/rte_cryptodev.c            |  32 ++-
 lib/librte_cryptodev/rte_cryptodev.h            |   2 +
 lib/librte_cryptodev/rte_cryptodev_pmd.h        |  18 ++
 lib/librte_cryptodev/rte_cryptodev_version.map  |  10 +-
 lib/librte_eal/bsdapp/eal/eal.c                 |   7 +
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  52 ++++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   8 +
 lib/librte_eal/common/eal_common_dev.c          |  50 +++-
 lib/librte_eal/common/eal_common_pci.c          |  17 +-
 lib/librte_eal/common/eal_private.h             |  13 ++
 lib/librte_eal/common/include/rte_dev.h         |  31 ++-
 lib/librte_eal/common/include/rte_pci.h         |  28 +++
 lib/librte_eal/linuxapp/eal/eal.c               |  13 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c           |  16 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   8 +
 lib/librte_ether/rte_ethdev.c                   | 296 ++++--------------------
 lib/librte_ether/rte_ethdev.h                   |  15 ++
 lib/librte_ether/rte_ether_version.map          |   8 +
 42 files changed, 465 insertions(+), 561 deletions(-)

-- 
1.9.1
#1 lore raw

PATCH 1/9 pci: no need for dynamic tailq init

These lists can be initialized once and for all at build time. With this, those lists are only manipulated in a common place (and we could even make them private).

A nice side effect is that pci drivers can now register in constructors.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c    | 3 ---
 lib/librte_eal/common/eal_common_pci.c | 6 ++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 3 ---
 3 files changed, 4 insertions(+), 8 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -3
index 6c21fbd..4584522 100644
@@ -483,9 +483,6 @@ int rte_eal_pci_write_config(const struct rte_pci_device *dev,
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
lib/librte_eal/common/eal_common_pci.c +4 -2
index dcfe947..1e12776 100644
@@ -82,8 +82,10 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list;
-struct pci_device_list pci_device_list;
+struct pci_driver_list pci_driver_list =
+	TAILQ_HEAD_INITIALIZER(pci_driver_list);
+struct pci_device_list pci_device_list =
+	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
 static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 {
lib/librte_eal/linuxapp/eal/eal_pci.c +0 -3
index bc5b5be..a354f76 100644
@@ -625,9 +625,6 @@ int rte_eal_pci_write_config(const struct rte_pci_device *device,
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
Signature · 1 line
1.9.1
#3 lore raw

PATCH 2/9 pci: register all pdev as pci drivers

In reply to David Marchand

pdev drivers are actually pci drivers.
Wrappers for ethdev and crypto pci drivers, that assume a 1 to 1 association between pci device and upper device, have been added so that current drivers are not impacted.

---
 drivers/crypto/qat/rte_qat_cryptodev.c         |  7 +++++--
 drivers/net/bnx2x/bnx2x_ethdev.c               | 16 ++++++++++------
 drivers/net/cxgbe/cxgbe_ethdev.c               |  5 +++--
 drivers/net/e1000/em_ethdev.c                  |  4 +++-
 drivers/net/e1000/igb_ethdev.c                 | 14 +++++++++-----
 drivers/net/enic/enic_ethdev.c                 |  5 +++--
 drivers/net/fm10k/fm10k_ethdev.c               |  4 +++-
 drivers/net/i40e/i40e_ethdev.c                 |  5 +++--
 drivers/net/i40e/i40e_ethdev_vf.c              |  6 +++---
 drivers/net/ixgbe/ixgbe_ethdev.c               | 10 ++++++----
 drivers/net/nfp/nfp_net.c                      |  7 ++++---
 drivers/net/virtio/virtio_ethdev.c             |  4 +++-
 drivers/net/vmxnet3/vmxnet3_ethdev.c           |  5 +++--
 lib/librte_cryptodev/rte_cryptodev.c           | 18 ++++++++++--------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 14 ++++++++++++++
 lib/librte_cryptodev/rte_cryptodev_version.map | 10 +++++++++-
 lib/librte_ether/rte_ethdev.c                  | 16 +++++++++-------
 lib/librte_ether/rte_ethdev.h                  | 15 +++++++++++++++
 lib/librte_ether/rte_ether_version.map         |  8 ++++++++
 19 files changed, 123 insertions(+), 50 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +5 -2
index e500c1e..6853aee 100644
@@ -113,10 +113,12 @@ crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_
 }
 
 static struct rte_cryptodev_driver rte_qat_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_cryptodev_pci_probe,
+		.devuninit = rte_cryptodev_pci_remove,
 	},
 	.cryptodev_init = crypto_qat_dev_init,
 	.dev_private_size = sizeof(struct qat_pmd_private),
@@ -126,7 +128,8 @@ static int
 rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-	return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
+	rte_eal_pci_register(&rte_qat_pmd.pci_drv);
+	return 0;
 }
 
 static struct rte_driver pmd_qat_drv = {
drivers/net/bnx2x/bnx2x_ethdev.c +10 -6
index 69df02e..916b9da 100644
@@ -501,6 +501,8 @@ static struct eth_driver rte_bnx2x_pmd = {
 		.name = "rte_bnx2x_pmd",
 		.id_table = pci_id_bnx2x_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2x_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
@@ -514,24 +516,26 @@ static struct eth_driver rte_bnx2xvf_pmd = {
 		.name = "rte_bnx2xvf_pmd",
 		.id_table = pci_id_bnx2xvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2xvf_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
-static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+static int rte_bnx2x_pmd_init(const char *name __rte_unused,
+			      const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2x_pmd);
-
+	rte_eal_pci_register(&rte_bnx2x_pmd.pci_drv);
 	return 0;
 }
 
-static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+static int rte_bnx2xvf_pmd_init(const char *name __rte_unused,
+				const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2xvf_pmd);
-
+	rte_eal_pci_register(&rte_bnx2xvf_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/cxgbe/cxgbe_ethdev.c +3 -2
index 97ef152..e425ef2 100644
@@ -851,6 +851,8 @@ static struct eth_driver rte_cxgbe_pmd = {
 		.name = "rte_cxgbe_pmd",
 		.id_table = cxgb4_pci_tbl,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_cxgbe_dev_init,
 	.dev_private_size = sizeof(struct port_info),
@@ -865,8 +867,7 @@ static int rte_cxgbe_pmd_init(const char *name __rte_unused,
 			      const char *params __rte_unused)
 {
 	CXGBE_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_cxgbe_pmd);
+	rte_eal_pci_register(&rte_cxgbe_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/e1000/em_ethdev.c +3 -1
index 66e8993..973ec97 100644
@@ -340,6 +340,8 @@ static struct eth_driver rte_em_pmd = {
 		.id_table = pci_id_em_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_em_dev_init,
 	.eth_dev_uninit = eth_em_dev_uninit,
@@ -349,7 +351,7 @@ static struct eth_driver rte_em_pmd = {
 static int
 rte_em_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
 {
-	rte_eth_driver_register(&rte_em_pmd);
+	rte_eal_pci_register(&rte_em_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/e1000/igb_ethdev.c +9 -5
index d1bbcda..a8d94a4 100644
@@ -961,6 +961,8 @@ static struct eth_driver rte_igb_pmd = {
 		.id_table = pci_id_igb_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igb_dev_init,
 	.eth_dev_uninit = eth_igb_dev_uninit,
@@ -975,6 +977,8 @@ static struct eth_driver rte_igbvf_pmd = {
 		.name = "rte_igbvf_pmd",
 		.id_table = pci_id_igbvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igbvf_dev_init,
 	.eth_dev_uninit = eth_igbvf_dev_uninit,
@@ -984,7 +988,7 @@ static struct eth_driver rte_igbvf_pmd = {
 static int
 rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
 {
-	rte_eth_driver_register(&rte_igb_pmd);
+	rte_eal_pci_register(&rte_igb_pmd.pci_drv);
 	return 0;
 }
 
@@ -1005,12 +1009,12 @@ igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
  * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
  */
 static int
-rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+rte_igbvf_pmd_init(const char *name __rte_unused,
+		   const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_igbvf_pmd);
-	return (0);
+	rte_eal_pci_register(&rte_igbvf_pmd.pci_drv);
+	return 0;
 }
 
 static int
drivers/net/enic/enic_ethdev.c +3 -2
index 2a88043..7678c0a 100644
@@ -625,6 +625,8 @@ static struct eth_driver rte_enic_pmd = {
 		.name = "rte_enic_pmd",
 		.id_table = pci_id_enic_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_enicpmd_dev_init,
 	.dev_private_size = sizeof(struct enic),
@@ -639,8 +641,7 @@ rte_enic_pmd_init(const char *name __rte_unused,
 	const char *params __rte_unused)
 {
 	ENICPMD_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_enic_pmd);
+	rte_eal_pci_register(&rte_enic_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/fm10k/fm10k_ethdev.c +3 -1
index e4aed94..75537e0 100644
@@ -2752,6 +2752,8 @@ static struct eth_driver rte_pmd_fm10k = {
 		.name = "rte_pmd_fm10k",
 		.id_table = pci_id_fm10k_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_fm10k_dev_init,
 	.eth_dev_uninit = eth_fm10k_dev_uninit,
@@ -2768,7 +2770,7 @@ rte_pmd_fm10k_init(__rte_unused const char *name,
 	__rte_unused const char *params)
 {
 	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_pmd_fm10k);
+	rte_eal_pci_register(&rte_pmd_fm10k.pci_drv);
 	return 0;
 }
 
drivers/net/i40e/i40e_ethdev.c +3 -2
index bf6220d..ab24115 100644
@@ -603,6 +603,8 @@ static struct eth_driver rte_i40e_pmd = {
 		.id_table = pci_id_i40e_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_i40e_dev_init,
 	.eth_dev_uninit = eth_i40e_dev_uninit,
@@ -647,8 +649,7 @@ rte_i40e_pmd_init(const char *name __rte_unused,
 		  const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_i40e_pmd);
-
+	rte_eal_pci_register(&rte_i40e_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/i40e/i40e_ethdev_vf.c +3 -3
index 14d2a50..050d7ea 100644
@@ -1366,6 +1366,8 @@ static struct eth_driver rte_i40evf_pmd = {
 		.name = "rte_i40evf_pmd",
 		.id_table = pci_id_i40evf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = i40evf_dev_init,
 	.eth_dev_uninit = i40evf_dev_uninit,
@@ -1382,9 +1384,7 @@ rte_i40evf_pmd_init(const char *name __rte_unused,
 		    const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_i40evf_pmd);
-
+	rte_eal_pci_register(&rte_i40evf_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/ixgbe/ixgbe_ethdev.c +6 -4
index 4c4c6df..970528e 100644
@@ -1433,6 +1433,8 @@ static struct eth_driver rte_ixgbe_pmd = {
 		.id_table = pci_id_ixgbe_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_ixgbe_dev_init,
 	.eth_dev_uninit = eth_ixgbe_dev_uninit,
@@ -1447,6 +1449,8 @@ static struct eth_driver rte_ixgbevf_pmd = {
 		.name = "rte_ixgbevf_pmd",
 		.id_table = pci_id_ixgbevf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_ixgbevf_dev_init,
 	.eth_dev_uninit = eth_ixgbevf_dev_uninit,
@@ -1462,8 +1466,7 @@ static int
 rte_ixgbe_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_ixgbe_pmd);
+	rte_eal_pci_register(&rte_ixgbe_pmd.pci_drv);
 	return 0;
 }
 
@@ -1476,8 +1479,7 @@ static int
 rte_ixgbevf_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_ixgbevf_pmd);
+	rte_eal_pci_register(&rte_ixgbevf_pmd.pci_drv);
 	return (0);
 }
 
drivers/net/nfp/nfp_net.c +4 -3
index bc2089f..89ba703 100644
@@ -2463,10 +2463,12 @@ static struct rte_pci_id pci_id_nfp_net_map[] = {
 };
 
 static struct eth_driver rte_nfp_net_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_nfp_net_pmd",
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = nfp_net_init,
 	.dev_private_size = sizeof(struct nfp_net_adapter),
@@ -2479,8 +2481,7 @@ nfp_net_pmd_init(const char *name __rte_unused,
 	PMD_INIT_FUNC_TRACE();
 	PMD_INIT_LOG(INFO, "librte_pmd_nfp_net version %s\n",
 		     NFP_NET_PMD_VERSION);
-
-	rte_eth_driver_register(&rte_nfp_net_pmd);
+	rte_eal_pci_register(&rte_nfp_net_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/virtio/virtio_ethdev.c +3 -1
index d928339..08f386a 100644
@@ -1439,6 +1439,8 @@ static struct eth_driver rte_virtio_pmd = {
 		.name = "rte_virtio_pmd",
 		.id_table = pci_id_virtio_map,
 		.drv_flags = RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_virtio_dev_init,
 	.eth_dev_uninit = eth_virtio_dev_uninit,
@@ -1460,7 +1462,7 @@ rte_virtio_pmd_init(const char *name __rte_unused,
 		return -1;
 	}
 
-	rte_eth_driver_register(&rte_virtio_pmd);
+	rte_eal_pci_register(&rte_virtio_pmd.pci_drv);
 	return 0;
 }
 
drivers/net/vmxnet3/vmxnet3_ethdev.c +3 -2
index c363bf6..1a3bc66 100644
@@ -325,6 +325,8 @@ static struct eth_driver rte_vmxnet3_pmd = {
 		.name = "rte_vmxnet3_pmd",
 		.id_table = pci_id_vmxnet3_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_vmxnet3_dev_init,
 	.eth_dev_uninit = eth_vmxnet3_dev_uninit,
@@ -340,8 +342,7 @@ static int
 rte_vmxnet3_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_vmxnet3_pmd);
+	rte_eal_pci_register(&rte_vmxnet3_pmd.pci_drv);
 	return 0;
 }
 
lib/librte_cryptodev/rte_cryptodev.c +10 -8
index f09f67e..1950020 100644
@@ -313,9 +313,9 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	return cryptodev;
 }
 
-static int
-rte_cryptodev_init(struct rte_pci_driver *pci_drv,
-		struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			struct rte_pci_device *pci_dev)
 {
 	struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -375,8 +375,8 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	return -ENXIO;
 }
 
-static int
-rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -418,26 +418,28 @@ rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
+#ifndef RTE_NEXT_ABI
 int
 rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
 		enum pmd_type type)
 {
 	/* Call crypto device initialization directly if device is virtual */
 	if (type == PMD_VDEV)
-		return rte_cryptodev_init((struct rte_pci_driver *)cryptodrv,
+		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
 				NULL);
 
 	/*
 	 * Register PCI driver for physical device intialisation during
 	 * PCI probing
 	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_init;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_uninit;
+	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
+	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
 
 	rte_eal_pci_register(&cryptodrv->pci_drv);
 
 	return 0;
 }
+#endif
 
 
 uint16_t
lib/librte_cryptodev/rte_cryptodev_pmd.h +14 -0
index 8270afa..1c5ee14 100644
@@ -499,6 +499,7 @@ extern int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 
 
+#ifndef RTE_NEXT_ABI
 /**
  * Register a Crypto [Poll Mode] driver.
  *
@@ -527,6 +528,7 @@ rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 extern int
 rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 		enum pmd_type type);
+#endif
 
 /**
  * Executes all the user application registered callbacks for the specific
@@ -541,6 +543,18 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
 				enum rte_cryptodev_event_type event);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			    struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
 
 #ifdef __cplusplus
 }
lib/librte_cryptodev/rte_cryptodev_version.map +9 -1
index ff8e93d..3f838a4 100644
@@ -29,4 +29,12 @@ DPDK_2.2 {
 	rte_cryptodev_queue_pair_stop;
 
 	local: *;
-};
\ No newline at end of file
+};
+
+DPDK_2.3 {
+	global:
+
+	rte_cryptodev_pci_probe;
+	rte_cryptodev_pci_remove;
+
+} DPDK_2.2;
lib/librte_ether/rte_ethdev.c +9 -7
index 756b234..17e4f4d 100644
@@ -239,9 +239,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 	return 0;
 }
 
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-		 struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+		      struct rte_pci_device *pci_dev)
 {
 	struct eth_driver    *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -293,8 +293,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	return diag;
 }
 
-static int
-rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct eth_driver *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -334,6 +334,7 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
+#ifndef RTE_NEXT_ABI
 /**
  * Register an Ethernet [Poll Mode] driver.
  *
@@ -351,10 +352,11 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 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;
+	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
+	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
+#endif
 
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
lib/librte_ether/rte_ethdev.h +15 -0
index 8710dd7..af051d1 100644
@@ -1774,6 +1774,7 @@ struct eth_driver {
 	unsigned int dev_private_size;    /**< Size of device private data. */
 };
 
+#ifndef RTE_NEXT_ABI
 /**
  * @internal
  * A function invoked by the initialization function of an Ethernet driver
@@ -1785,6 +1786,7 @@ struct eth_driver {
  *   the Ethernet driver.
  */
 void rte_eth_driver_register(struct eth_driver *eth_drv);
+#endif
 
 /**
  * Configure an Ethernet device.
@@ -3880,6 +3882,19 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
 			 uint16_t queue_id, size_t size,
 			 unsigned align, int socket_id);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+			  struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_ether/rte_ether_version.map +8 -0
index d8db24d..07b2d8b 100644
@@ -117,3 +117,11 @@ DPDK_2.2 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_eth_dev_pci_probe;
+	rte_eth_dev_pci_remove;
+
+} DPDK_2.2;
Signature · 1 line
1.9.1
#6 lore raw

PATCH 3/9 drivers: no more pdev drivers

In reply to David Marchand

Now that pdev drivers have been converted to pci drivers, there is nothing left in their init functions that can't go in a constructor. pdev / vdev drivers init order is changed by this commit, but I can't see why we would need to preserve it.

---
 drivers/crypto/qat/rte_qat_cryptodev.c | 13 +++---------
 drivers/net/bnx2x/bnx2x_ethdev.c       | 26 +++---------------------
 drivers/net/cxgbe/cxgbe_ethdev.c       | 19 +++---------------
 drivers/net/e1000/em_ethdev.c          | 13 +++---------
 drivers/net/e1000/igb_ethdev.c         | 34 ++++----------------------------
 drivers/net/enic/enic_ethdev.c         | 18 +++--------------
 drivers/net/fm10k/fm10k_ethdev.c       | 19 +++---------------
 drivers/net/i40e/i40e_ethdev.c         | 19 +++---------------
 drivers/net/i40e/i40e_ethdev_vf.c      | 19 +++---------------
 drivers/net/ixgbe/ixgbe_ethdev.c       | 36 +++-------------------------------
 drivers/net/mlx4/mlx4.c                | 19 +++---------------
 drivers/net/mlx5/mlx5.c                | 19 +++---------------
 drivers/net/nfp/nfp_net.c              | 14 +++----------
 drivers/net/virtio/virtio_ethdev.c     | 22 ++++-----------------
 drivers/net/vmxnet3/vmxnet3_ethdev.c   | 18 +++--------------
 15 files changed, 47 insertions(+), 261 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +3 -10
index 6853aee..ded5d60 100644
@@ -124,17 +124,10 @@ static struct rte_cryptodev_driver rte_qat_pmd = {
 	.dev_private_size = sizeof(struct qat_pmd_private),
 };
 
-static int
-rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_qat_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_qat_pmd.pci_drv);
-	return 0;
 }
-
-static struct rte_driver pmd_qat_drv = {
-	.type = PMD_PDEV,
-	.init = rte_qat_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(pmd_qat_drv);
drivers/net/bnx2x/bnx2x_ethdev.c +3 -23
index 916b9da..a4b1599 100644
@@ -523,31 +523,11 @@ static struct eth_driver rte_bnx2xvf_pmd = {
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
-static int rte_bnx2x_pmd_init(const char *name __rte_unused,
-			      const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_bnx2x_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_bnx2x_pmd.pci_drv);
-	return 0;
-}
-
-static int rte_bnx2xvf_pmd_init(const char *name __rte_unused,
-				const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_bnx2xvf_pmd.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_bnx2x_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2x_pmd_init,
-};
-
-static struct rte_driver rte_bnx2xvf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2xvf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_bnx2x_driver);
-PMD_REGISTER_DRIVER(rte_bnx2xvf_driver);
drivers/net/cxgbe/cxgbe_ethdev.c +3 -16
index e425ef2..9654ced 100644
@@ -858,23 +858,10 @@ static struct eth_driver rte_cxgbe_pmd = {
 	.dev_private_size = sizeof(struct port_info),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI CXGBE devices.
- */
-static int rte_cxgbe_pmd_init(const char *name __rte_unused,
-			      const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_cxgbe_pmd_init(void)
 {
 	CXGBE_FUNC_TRACE();
 	rte_eal_pci_register(&rte_cxgbe_pmd.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_cxgbe_driver = {
-	.name = "cxgbe_driver",
-	.type = PMD_PDEV,
-	.init = rte_cxgbe_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_cxgbe_driver);
drivers/net/e1000/em_ethdev.c +3 -10
index 973ec97..19b2645 100644
@@ -348,11 +348,11 @@ static struct eth_driver rte_em_pmd = {
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_em_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_em_pmd_init(void)
 {
 	rte_eal_pci_register(&rte_em_pmd.pci_drv);
-	return 0;
 }
 
 static int
@@ -1738,10 +1738,3 @@ eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
 	e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
 	return 0;
 }
-
-struct rte_driver em_pmd_drv = {
-	.type = PMD_PDEV,
-	.init = rte_em_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(em_pmd_drv);
drivers/net/e1000/igb_ethdev.c +4 -30
index a8d94a4..da63365 100644
@@ -985,11 +985,12 @@ static struct eth_driver rte_igbvf_pmd = {
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_igb_pmd_init(void)
 {
 	rte_eal_pci_register(&rte_igb_pmd.pci_drv);
-	return 0;
+	rte_eal_pci_register(&rte_igbvf_pmd.pci_drv);
 }
 
 static void
@@ -1003,20 +1004,6 @@ igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
 }
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
- */
-static int
-rte_igbvf_pmd_init(const char *name __rte_unused,
-		   const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eal_pci_register(&rte_igbvf_pmd.pci_drv);
-	return 0;
-}
-
 static int
 igb_check_mq_mode(struct rte_eth_dev *dev)
 {
@@ -4696,16 +4683,6 @@ eth_igb_set_eeprom(struct rte_eth_dev *dev,
 	return nvm->ops.write(hw,  first, length, data);
 }
 
-static struct rte_driver pmd_igb_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igb_pmd_init,
-};
-
-static struct rte_driver pmd_igbvf_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igbvf_pmd_init,
-};
-
 static int
 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
@@ -4866,6 +4843,3 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 
 	E1000_WRITE_FLUSH(hw);
 }
-
-PMD_REGISTER_DRIVER(pmd_igb_drv);
-PMD_REGISTER_DRIVER(pmd_igbvf_drv);
drivers/net/enic/enic_ethdev.c +3 -15
index 7678c0a..9f997b1 100644
@@ -632,22 +632,10 @@ static struct eth_driver rte_enic_pmd = {
 	.dev_private_size = sizeof(struct enic),
 };
 
-/* Driver initialization routine.
- * Invoked once at EAL init time.
- * Register as the [Poll Mode] Driver of Cisco ENIC device.
- */
-static int
-rte_enic_pmd_init(const char *name __rte_unused,
-	const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_enic_pmd_init(void)
 {
 	ENICPMD_FUNC_TRACE();
 	rte_eal_pci_register(&rte_enic_pmd.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_enic_driver = {
-	.type = PMD_PDEV,
-	.init = rte_enic_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_enic_driver);
drivers/net/fm10k/fm10k_ethdev.c +3 -16
index 75537e0..b69fc22 100644
@@ -2760,23 +2760,10 @@ static struct eth_driver rte_pmd_fm10k = {
 	.dev_private_size = sizeof(struct fm10k_adapter),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI FM10K devices.
- */
-static int
-rte_pmd_fm10k_init(__rte_unused const char *name,
-	__rte_unused const char *params)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_pmd_fm10k_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_pmd_fm10k.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_fm10k_driver = {
-	.type = PMD_PDEV,
-	.init = rte_pmd_fm10k_init,
-};
-
-PMD_REGISTER_DRIVER(rte_fm10k_driver);
drivers/net/i40e/i40e_ethdev.c +3 -16
index ab24115..f47bb4b 100644
@@ -639,27 +639,14 @@ rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
 	return 0;
 }
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
- */
-static int
-rte_i40e_pmd_init(const char *name __rte_unused,
-		  const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_i40e_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_i40e_pmd.pci_drv);
-	return 0;
 }
 
-static struct rte_driver rte_i40e_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40e_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40e_driver);
-
 /*
  * Initialize registers for flexible payload, which should be set by NVM.
  * This should be removed from code once it is fixed in NVM.
drivers/net/i40e/i40e_ethdev_vf.c +3 -16
index 050d7ea..2e11ff9 100644
@@ -1374,27 +1374,14 @@ static struct eth_driver rte_i40evf_pmd = {
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
- */
-static int
-rte_i40evf_pmd_init(const char *name __rte_unused,
-		    const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_i40evf_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_i40evf_pmd.pci_drv);
-	return 0;
 }
 
-static struct rte_driver rte_i40evf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40evf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40evf_driver);
-
 static int
 i40evf_dev_configure(struct rte_eth_dev *dev)
 {
drivers/net/ixgbe/ixgbe_ethdev.c +3 -33
index 970528e..9f29525 100644
@@ -1457,30 +1457,13 @@ static struct eth_driver rte_ixgbevf_pmd = {
 	.dev_private_size = sizeof(struct ixgbe_adapter),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
- */
-static int
-rte_ixgbe_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_ixgbe_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_ixgbe_pmd.pci_drv);
-	return 0;
-}
-
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI niantic devices.
- */
-static int
-rte_ixgbevf_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_ixgbevf_pmd.pci_drv);
-	return (0);
 }
 
 static int
@@ -6192,16 +6175,3 @@ ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
 	}
 	return 0;
 }
-
-static struct rte_driver rte_ixgbe_driver = {
-	.type = PMD_PDEV,
-	.init = rte_ixgbe_pmd_init,
-};
-
-static struct rte_driver rte_ixgbevf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_ixgbevf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_ixgbe_driver);
-PMD_REGISTER_DRIVER(rte_ixgbevf_driver);
drivers/net/mlx4/mlx4.c +3 -16
index 207bfe2..bd223c0 100644
@@ -5677,14 +5677,10 @@ static struct eth_driver mlx4_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx4_pmd_init(const char *name, const char *args)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_mlx4_pmd_init(void)
 {
-	(void)name;
-	(void)args;
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
 	 * huge pages. Calling ibv_fork_init() during init allows
@@ -5694,13 +5690,4 @@ rte_mlx4_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx4_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx4_driver = {
-	.type = PMD_PDEV,
-	.name = MLX4_DRIVER_NAME,
-	.init = rte_mlx4_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx4_driver)
drivers/net/mlx5/mlx5.c +3 -16
index 821ee0f..8d23068 100644
@@ -542,14 +542,10 @@ static struct eth_driver mlx5_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx5_pmd_init(const char *name, const char *args)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_mlx5_pmd_init(void)
 {
-	(void)name;
-	(void)args;
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
 	 * huge pages. Calling ibv_fork_init() during init allows
@@ -559,13 +555,4 @@ rte_mlx5_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx5_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx5_driver = {
-	.type = PMD_PDEV,
-	.name = MLX5_DRIVER_NAME,
-	.init = rte_mlx5_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx5_driver)
drivers/net/nfp/nfp_net.c +3 -11
index 89ba703..6e4bc16 100644
@@ -2474,24 +2474,16 @@ static struct eth_driver rte_nfp_net_pmd = {
 	.dev_private_size = sizeof(struct nfp_net_adapter),
 };
 
-static int
-nfp_net_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+nfp_net_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	PMD_INIT_LOG(INFO, "librte_pmd_nfp_net version %s\n",
 		     NFP_NET_PMD_VERSION);
 	rte_eal_pci_register(&rte_nfp_net_pmd.pci_drv);
-	return 0;
 }
 
-static struct rte_driver rte_nfp_net_driver = {
-	.type = PMD_PDEV,
-	.init = nfp_net_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_nfp_net_driver);
-
 /*
  * Local variables:
  * c-file-style: "Linux"
drivers/net/virtio/virtio_ethdev.c +4 -18
index 08f386a..e44411e 100644
@@ -1447,23 +1447,16 @@ static struct eth_driver rte_virtio_pmd = {
 	.dev_private_size = sizeof(struct virtio_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI virtio devices.
- * Returns 0 on success.
- */
-static int
-rte_virtio_pmd_init(const char *name __rte_unused,
-		    const char *param __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_virtio_pmd_init(void)
 {
 	if (rte_eal_iopl_init() != 0) {
 		PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
-		return -1;
+		return;
 	}
 
 	rte_eal_pci_register(&rte_virtio_pmd.pci_drv);
-	return 0;
 }
 
 /*
@@ -1684,10 +1677,3 @@ __rte_unused uint8_t is_rx)
 {
 	return 0;
 }
-
-static struct rte_driver rte_virtio_driver = {
-	.type = PMD_PDEV,
-	.init = rte_virtio_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_virtio_driver);
drivers/net/vmxnet3/vmxnet3_ethdev.c +3 -15
index 1a3bc66..a065610 100644
@@ -333,17 +333,12 @@ static struct eth_driver rte_vmxnet3_pmd = {
 	.dev_private_size = sizeof(struct vmxnet3_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of Virtual PCI VMXNET3 devices.
- */
-static int
-rte_vmxnet3_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_vmxnet3_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();
 	rte_eal_pci_register(&rte_vmxnet3_pmd.pci_drv);
-	return 0;
 }
 
 static int
@@ -922,10 +917,3 @@ vmxnet3_process_events(struct vmxnet3_hw *hw)
 
 }
 #endif
-
-static struct rte_driver rte_vmxnet3_driver = {
-	.type = PMD_PDEV,
-	.init = rte_vmxnet3_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_vmxnet3_driver);
Signature · 1 line
1.9.1
#13 lore raw

PATCH 4/9 eal/linux: move back interrupt thread init before setting affinity

In reply to David Marchand

Now that virtio pci driver is initialized in a constructor, we only need to move the interrupt thread init after loading the plugins.
This way, chelsio driver should be happy again [1].

[1] http://dpdk.org/ml/archives/dev/2015-November/028289.html

---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal.c +3 -3
index 635ec36..62241ee 100644
@@ -823,6 +823,9 @@ rte_eal_init(int argc, char **argv)
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
+	if (rte_eal_intr_init() < 0)
+		rte_panic("Cannot init interrupt-handling thread\n");
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
@@ -834,9 +837,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-	if (rte_eal_intr_init() < 0)
-		rte_panic("Cannot init interrupt-handling thread\n");
-
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
 		/*
Signature · 1 line
1.9.1
#17 lore raw

PATCH 5/9 eal: get rid of pmd type

In reply to David Marchand

Now that we only have vdev drivers, there is no need for a pmd type in rte_driver.
rte_driver is now purely a vdev thing, and could be renamed later (then .init would become .probe, .uninit would become .remove).

---
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c |  2 ++
 drivers/net/af_packet/rte_eth_af_packet.c  |  2 ++
 drivers/net/bonding/rte_eth_bond_pmd.c     |  2 ++
 drivers/net/mpipe/mpipe_tilegx.c           |  4 ++++
 drivers/net/null/rte_eth_null.c            |  2 ++
 drivers/net/pcap/rte_eth_pcap.c            |  2 ++
 drivers/net/ring/rte_eth_ring.c            |  2 ++
 drivers/net/szedata2/rte_eth_szedata2.c    |  2 ++
 drivers/net/xenvirt/rte_eth_xenvirt.c      |  2 ++
 lib/librte_cryptodev/rte_cryptodev.c       | 14 ++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.h       |  2 ++
 lib/librte_cryptodev/rte_cryptodev_pmd.h   |  4 ++++
 lib/librte_eal/common/eal_common_dev.c     | 11 ++++++++---
 lib/librte_eal/common/include/rte_dev.h    |  4 ++++
 14 files changed, 52 insertions(+), 3 deletions(-)
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +2 -0
index d8ccf05..94752de 100644
@@ -661,7 +661,9 @@ cryptodev_aesni_mb_uninit(const char *name)
 
 static struct rte_driver cryptodev_aesni_mb_pmd_drv = {
 	.name = CRYPTODEV_NAME_AESNI_MB_PMD,
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = cryptodev_aesni_mb_init,
 	.uninit = cryptodev_aesni_mb_uninit
 };
drivers/net/af_packet/rte_eth_af_packet.c +2 -0
index 767f36b..6603462 100644
@@ -838,7 +838,9 @@ exit:
 
 static struct rte_driver pmd_af_packet_drv = {
 	.name = "eth_af_packet",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_af_packet_devinit,
 };
 
drivers/net/bonding/rte_eth_bond_pmd.c +2 -0
index b1373c6..d19d745 100644
@@ -2493,7 +2493,9 @@ bond_ethdev_configure(struct rte_eth_dev *dev)
 
 static struct rte_driver bond_drv = {
 	.name = "eth_bond",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = bond_init,
 	.uninit = bond_uninit,
 };
drivers/net/mpipe/mpipe_tilegx.c +4 -0
index 35134ba..3eaf0db 100644
@@ -1608,13 +1608,17 @@ rte_pmd_mpipe_devinit(const char *ifname,
 
 static struct rte_driver pmd_mpipe_xgbe_drv = {
 	.name = "xgbe",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_mpipe_devinit,
 };
 
 static struct rte_driver pmd_mpipe_gbe_drv = {
 	.name = "gbe",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_mpipe_devinit,
 };
 
drivers/net/null/rte_eth_null.c +2 -0
index 77fc988..f5700bb 100644
@@ -695,7 +695,9 @@ rte_pmd_null_devuninit(const char *name)
 
 static struct rte_driver pmd_null_drv = {
 	.name = "eth_null",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_null_devinit,
 	.uninit = rte_pmd_null_devuninit,
 };
drivers/net/pcap/rte_eth_pcap.c +2 -0
index f9230eb..9ab22be 100644
@@ -1092,7 +1092,9 @@ rte_pmd_pcap_devuninit(const char *name)
 
 static struct rte_driver pmd_pcap_drv = {
 	.name = "eth_pcap",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_pcap_devinit,
 	.uninit = rte_pmd_pcap_devuninit,
 };
drivers/net/ring/rte_eth_ring.c +2 -0
index d92b088..9941a1c 100644
@@ -596,7 +596,9 @@ rte_pmd_ring_devuninit(const char *name)
 
 static struct rte_driver pmd_ring_drv = {
 	.name = "eth_ring",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_ring_devinit,
 	.uninit = rte_pmd_ring_devuninit,
 };
drivers/net/szedata2/rte_eth_szedata2.c +2 -0
index 9f86c99..6bbb6b0 100644
@@ -1616,7 +1616,9 @@ rte_pmd_szedata2_devuninit(const char *name)
 
 static struct rte_driver pmd_szedata2_drv = {
 	.name = "eth_szedata2",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_szedata2_devinit,
 	.uninit = rte_pmd_szedata2_devuninit,
 };
drivers/net/xenvirt/rte_eth_xenvirt.c +2 -0
index 3f31806..d5f3bbb 100644
@@ -769,7 +769,9 @@ rte_pmd_xenvirt_devuninit(const char *name)
 
 static struct rte_driver pmd_xenvirt_drv = {
 	.name = "eth_xenvirt",
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif
 	.init = rte_pmd_xenvirt_devinit,
 	.uninit = rte_pmd_xenvirt_devuninit,
 };
lib/librte_cryptodev/rte_cryptodev.c +14 -0
index 1950020..f499bc6 100644
@@ -202,7 +202,11 @@ rte_cryptodev_find_free_device_index(void)
 }
 
 struct rte_cryptodev *
+#ifndef RTE_NEXT_ABI
 rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
+#else
+rte_cryptodev_pmd_allocate(const char *name, int socket_id)
+#endif
 {
 	struct rte_cryptodev *cryptodev;
 	uint8_t dev_id;
@@ -241,7 +245,9 @@ rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
 		cryptodev->data->dev_started = 0;
 
 		cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
+#ifndef RTE_NEXT_ABI
 		cryptodev->pmd_type = type;
+#endif
 
 		cryptodev_globals.nb_devs++;
 	}
@@ -290,7 +296,11 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	struct rte_cryptodev *cryptodev;
 
 	/* allocate device structure */
+#ifndef RTE_NEXT_ABI
 	cryptodev = rte_cryptodev_pmd_allocate(name, PMD_VDEV, socket_id);
+#else
+	cryptodev = rte_cryptodev_pmd_allocate(name, socket_id);
+#endif
 	if (cryptodev == NULL)
 		return NULL;
 
@@ -332,8 +342,12 @@ rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
 	rte_cryptodev_create_unique_device_name(cryptodev_name,
 			sizeof(cryptodev_name), pci_dev);
 
+#ifndef RTE_NEXT_ABI
 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, PMD_PDEV,
 			rte_socket_id());
+#else
+	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
+#endif
 	if (cryptodev == NULL)
 		return -ENOMEM;
 
lib/librte_cryptodev/rte_cryptodev.h +2 -0
index 892375d..4813ec1 100644
@@ -471,9 +471,11 @@ struct rte_cryptodev {
 	/**< PCI info. supplied by probing */
 
 	enum rte_cryptodev_type dev_type;
+#ifndef RTE_NEXT_ABI
 	/**< Crypto device type */
 	enum pmd_type pmd_type;
 	/**< PMD type - PDEV / VDEV */
+#endif
 
 	struct rte_cryptodev_cb_list link_intr_cbs;
 	/**< User application callback for interrupts if present */
lib/librte_cryptodev/rte_cryptodev_pmd.h +4 -0
index 1c5ee14..4a84757 100644
@@ -466,7 +466,11 @@ struct rte_cryptodev_ops {
  *   - Slot in the rte_dev_devices array for a new device;
  */
 struct rte_cryptodev *
+#ifndef RTE_NEXT_ABI
 rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id);
+#else
+rte_cryptodev_pmd_allocate(const char *name, int socket_id);
+#endif
 
 /**
  * Creates a new virtual crypto device and returns the pointer
lib/librte_eal/common/eal_common_dev.c +8 -3
index a8a4146..5137172 100644
@@ -72,9 +72,10 @@ rte_eal_vdev_init(const char *name, const char *args)
 		return -EINVAL;
 
 	TAILQ_FOREACH(driver, &dev_driver_list, next) {
+#ifndef RTE_NEXT_ABI
 		if (driver->type != PMD_VDEV)
 			continue;
-
+#endif
 		/*
 		 * search a driver prefix in virtual device name.
 		 * For example, if the driver is pcap PMD, driver->name
@@ -93,7 +94,9 @@ int
 rte_eal_dev_init(void)
 {
 	struct rte_devargs *devargs;
+#ifndef RTE_NEXT_ABI
 	struct rte_driver *driver;
+#endif
 
 	/*
 	 * Note that the dev_driver_list is populated here
@@ -114,7 +117,7 @@ rte_eal_dev_init(void)
 			return -1;
 		}
 	}
-
+#ifndef RTE_NEXT_ABI
 	/* Once the vdevs are initalized, start calling all the pdev drivers */
 	TAILQ_FOREACH(driver, &dev_driver_list, next) {
 		if (driver->type != PMD_PDEV)
@@ -122,6 +125,7 @@ rte_eal_dev_init(void)
 		/* PDEV drivers don't get passed any parameters */
 		driver->init(NULL, NULL);
 	}
+#endif
 	return 0;
 }
 
@@ -134,9 +138,10 @@ rte_eal_vdev_uninit(const char *name)
 		return -EINVAL;
 
 	TAILQ_FOREACH(driver, &dev_driver_list, next) {
+#ifndef RTE_NEXT_ABI
 		if (driver->type != PMD_VDEV)
 			continue;
-
+#endif
 		/*
 		 * search a driver prefix in virtual device name.
 		 * For example, if the driver is pcap PMD, driver->name
lib/librte_eal/common/include/rte_dev.h +4 -0
index f1b5507..88c1a19 100644
@@ -114,6 +114,7 @@ typedef int (rte_dev_init_t)(const char *name, const char *args);
  */
 typedef int (rte_dev_uninit_t)(const char *name);
 
+#ifndef RTE_NEXT_ABI
 /**
  * Driver type enumeration
  */
@@ -121,13 +122,16 @@ enum pmd_type {
 	PMD_VDEV = 0,
 	PMD_PDEV = 1,
 };
+#endif
 
 /**
  * A structure describing a device driver.
  */
 struct rte_driver {
 	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
+#ifndef RTE_NEXT_ABI
 	enum pmd_type type;		   /**< PMD Driver type */
+#endif
 	const char *name;                   /**< Driver name. */
 	rte_dev_init_t *init;              /**< Device init. function. */
 	rte_dev_uninit_t *uninit;          /**< Device uninit. function. */
Signature · 1 line
1.9.1
#19 lore raw

PATCH 6/9 eal: initialize vdevs right next to pci devices

In reply to David Marchand

This way, the resources probing happens in a common place.

---
 lib/librte_eal/bsdapp/eal/eal.c         | 7 +++++++
 lib/librte_eal/common/include/rte_dev.h | 2 +-
 lib/librte_eal/linuxapp/eal/eal.c       | 7 +++++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal.c +7 -0
index a34e61d..b557a9f 100644
@@ -582,8 +582,10 @@ rte_eal_init(int argc, char **argv)
 		rte_config.master_lcore, thread_id, cpuset,
 		ret == 0 ? "" : "...");
 
+#ifndef RTE_NEXT_ABI
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
+#endif
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
@@ -617,6 +619,11 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
+#ifdef RTE_NEXT_ABI
+	if (rte_eal_dev_init() < 0)
+		rte_panic("Cannot probe vdev devices\n");
+#endif
+
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
lib/librte_eal/common/include/rte_dev.h +1 -1
index 88c1a19..df69e28 100644
@@ -156,7 +156,7 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
+ * Scan all devargs and attach to drivers if available
  */
 int rte_eal_dev_init(void);
 
lib/librte_eal/linuxapp/eal/eal.c +7 -0
index 62241ee..95313af 100644
@@ -834,8 +834,10 @@ rte_eal_init(int argc, char **argv)
 		rte_config.master_lcore, (int)thread_id, cpuset,
 		ret == 0 ? "" : "...");
 
+#ifndef RTE_NEXT_ABI
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
+#endif
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
@@ -873,6 +875,11 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
+#ifdef RTE_NEXT_ABI
+	if (rte_eal_dev_init() < 0)
+		rte_panic("Cannot probe vdev devices\n");
+#endif
+
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
Signature · 1 line
1.9.1
#22 lore raw

PATCH 7/9 pci: add a helper for device name

In reply to David Marchand

eal is a better place than ethdev for naming resources. Add a helper here, and make use of it in ethdev hotplug code.

---
 lib/librte_eal/common/include/rte_pci.h | 28 ++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 22 ++--------------------
 2 files changed, 30 insertions(+), 20 deletions(-)
lib/librte_eal/common/include/rte_pci.h +28 -0
index 334c12e..9edd5f5 100644
@@ -309,6 +309,34 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using above functions.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address
+ * @param output
+ *	The output buffer string
+ * @param size
+ *	The output buffer size
+ * @return
+ *  0 on success, negative on error.
+ */
+static inline int
+eal_pci_device_name(const struct rte_pci_addr *addr,
+		    char *output, int size)
+{
+	int ret;
+
+	ret = snprintf(output, size, PCI_PRI_FMT,
+		       addr->domain, addr->bus,
+		       addr->devid, addr->function);
+	if (ret < 0 || ret >= size)
+		return -1;
+
+	return 0;
+}
+
 /* Compare two PCI device addresses. */
 /**
  * Utility function to compare two PCI device addresses.
lib/librte_ether/rte_ethdev.c +2 -20
index 17e4f4d..5ba7479 100644
@@ -214,20 +214,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	return eth_dev;
 }
 
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -251,9 +237,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 
 	eth_drv = (struct eth_driver *)pci_drv;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	eal_pci_device_name(&pci_dev->addr, ethdev_name, sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
 	if (eth_dev == NULL)
@@ -304,9 +288,7 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	eal_pci_device_name(&pci_dev->addr, ethdev_name, sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocated(ethdev_name);
 	if (eth_dev == NULL)
Signature · 1 line
1.9.1
#25 lore raw

PATCH 8/9 pci: add a helper to refresh a device

In reply to David Marchand

It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c   | 49 +++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h   | 13 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++++++++
 3 files changed, 75 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +49 -0
index 4584522..5dd89e3 100644
@@ -396,6 +396,55 @@ error:
 	return -1;
 }
 
+int
+pci_refresh_device(const struct rte_pci_addr *addr)
+{
+	int fd;
+	struct pci_conf matches[2];
+	struct pci_match_conf match = {
+		.pc_sel = {
+			.pc_domain = addr->domain,
+			.pc_bus = addr->bus,
+			.pc_dev = addr->devid,
+			.pc_func = addr->function,
+		},
+	};
+	struct pci_conf_io conf_io = {
+		.pat_buf_len = 0,
+		.num_patterns = 1,
+		.patterns = { &match },
+		.match_buf_len = sizeof(matches),
+		.matches = &matches[0],
+	};
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+				__func__, strerror(errno));
+		goto error;
+	}
+
+	if (conf_io.num_matches != 1)
+		goto error;
+
+	if (pci_scan_one(fd, &matches[0]) < 0)
+		goto error;
+
+	close(fd);
+
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
 			    void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_private.h +13 -0
index 072e672..ed1903f 100644
@@ -155,6 +155,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Refresh a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.
+ */
+int pci_refresh_device(const struct rte_pci_addr *addr);
+
+/**
  * Unbind kernel driver for this device
  *
  * This function is private to EAL.
lib/librte_eal/linuxapp/eal/eal_pci.c +13 -0
index a354f76..4fe8b60 100644
@@ -393,6 +393,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 	return 0;
 }
 
+int
+pci_refresh_device(const struct rte_pci_addr *addr)
+{
+	char filename[PATH_MAX];
+
+	snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
+		 SYSFS_PCI_DEVICES, addr->domain, addr->bus, addr->devid,
+		 addr->function);
+
+	return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
+			    addr->function);
+}
+
 /*
  * split up a pci address into its constituent parts.
  */
Signature · 1 line
1.9.1
#29 lore raw

PATCH 9/9 eal: relocate hotplug code from ethdev

In reply to David Marchand

hotplug which deals with resources should come from the layer that already handles them, i.e. eal.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   8 +
 lib/librte_eal/common/eal_common_dev.c          |  39 ++++
 lib/librte_eal/common/eal_common_pci.c          |  11 +-
 lib/librte_eal/common/include/rte_dev.h         |  25 +++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   8 +
 lib/librte_ether/rte_ethdev.c                   | 258 ++++--------------------
 6 files changed, 125 insertions(+), 224 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +8 -0
index 9d7adf1..9aad048 100644
@@ -135,3 +135,11 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
+
+} DPDK_2.2;
lib/librte_eal/common/eal_common_dev.c +39 -0
index 5137172..ec04b3a 100644
@@ -155,3 +155,42 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+int rte_eal_dev_attach(const char *name, const char *devargs)
+{
+	struct rte_pci_addr addr;
+	int ret = -1;
+
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_probe_one(&addr) < 0)
+			goto err;
+
+	} else {
+		if (rte_eal_vdev_init(name, devargs))
+			goto err;
+	}
+
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	return ret;
+}
+
+int rte_eal_dev_detach(const char *name)
+{
+	struct rte_pci_addr addr;
+
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_detach(&addr) < 0)
+			goto err;
+	} else {
+		if (rte_eal_vdev_uninit(name))
+			goto err;
+	}
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
+	return -1;
+}
lib/librte_eal/common/eal_common_pci.c +8 -3
index 1e12776..d9aa66b 100644
@@ -332,6 +332,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
+	/* update current pci device in global list, kernel bindings might have
+	 * changed since last time we looked at it */
+	if (pci_refresh_device(addr) < 0)
+		goto err_return;
+
 	TAILQ_FOREACH(dev, &pci_device_list, next) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
@@ -344,9 +349,9 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	return -1;
 
 err_return:
-	RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
-			" cannot be used\n", dev->addr.domain, dev->addr.bus,
-			dev->addr.devid, dev->addr.function);
+	RTE_LOG(WARNING, EAL,
+		"Requested device " PCI_PRI_FMT " cannot be used\n",
+		addr->domain, addr->bus, addr->devid, addr->function);
 	return -1;
 }
 
lib/librte_eal/common/include/rte_dev.h +25 -0
index df69e28..6f026ff 100644
@@ -182,6 +182,31 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * Attach a resource to a registered driver.
+ *
+ * @param name
+ *   The resource name, that refers to a pci resource or some private
+ *   way of designating a resource for vdev drivers. Based on this
+ *   resource name, eal will identify a driver capable of handling
+ *   this resource and pass this resource to the driver probing
+ *   function.
+ * @param devargs
+ *   Device arguments to be passed to the driver.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_attach(const char *name, const char *devargs);
+
+/**
+ * Detach a resource from its driver.
+ *
+ * @param name
+ *   Same description as for rte_eal_dev_attach().
+ *   Here, eal will call the driver detaching function.
+ */
+int rte_eal_dev_detach(const char *name);
+
 #define PMD_REGISTER_DRIVER(d)\
 void devinitfn_ ##d(void);\
 void __attribute__((constructor, used)) devinitfn_ ##d(void)\
lib/librte_eal/linuxapp/eal/rte_eal_version.map +8 -0
index cbe175f..ba0ff56 100644
@@ -138,3 +138,11 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
+
+} DPDK_2.2;
lib/librte_ether/rte_ethdev.c +37 -221

316 lines not on this page · raw message

Signature · 1 line
1.9.1
#14 lore raw

Re: [PATCH 4/9] eal/linux: move back interrupt thread init before setting affinity

In reply to David Marchand

Hi David,

Quoted 38 lines · David Marchand

Now that virtio pci driver is initialized in a constructor, we only need to move the interrupt thread init after loading the plugins.
This way, chelsio driver should be happy again [1].

[1] http://dpdk.org/ml/archives/dev/2015-November/028289.html

---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal.c +3 -3
index 635ec36..62241ee 100644
@@ -823,6 +823,9 @@ rte_eal_init(int argc, char **argv)
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
+	if (rte_eal_intr_init() < 0)
+		rte_panic("Cannot init interrupt-handling thread\n");
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
@@ -834,9 +837,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-	if (rte_eal_intr_init() < 0)
-		rte_panic("Cannot init interrupt-handling thread\n");
-
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
 		/*
Signature · 1 line
1.9.1

Thank you for this patch. I've tested it and it does improve the perf. back when there is a queue on master lcore in l3fwd app.

Thanks,
Rahul

#15 lore raw

Re: [PATCH 4/9] eal/linux: move back interrupt thread init before setting affinity

Hello Rahul,

Quoted 7 lines · Rahul Lakkireddy
Quoted 3 lines · David Marchand

Now that virtio pci driver is initialized in a constructor, we only need to move the interrupt thread init after loading the plugins.
This way, chelsio driver should be happy again [1].

Thank you for this patch. I've tested it and it does improve the perf. back when there is a queue on master lcore in l3fwd app.

Did you test the whole series ? or just this specific patch ?

Anyway, great, but this is still too fragile.

As discussed in the same thread as the problem you reported, there is some work over there to be done so that interrupts are "distributed" in a more flexible way.
Did someone look at this ?
Plans to work on this ? (post 2.3, I suppose)

Signature · 1 line
David Marchand
#16 lore raw

Re: [PATCH 4/9] eal/linux: move back interrupt thread init before setting affinity

Hi David,

Quoted 5 lines · David Marchand

Hello Rahul,

Quoted 1 line · Rahul Lakkireddy

On Friday, January 01/29/16, 2016 at 15:08:31 +0100, David Marchand wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Now that virtio pci driver is initialized in a constructor, we only need to move the interrupt thread init after loading the plugins.
This way, chelsio driver should be happy again [1].

Thank you for this patch. I've tested it and it does improve the perf. back when there is a queue on master lcore in l3fwd app.

Did you test the whole series ? or just this specific patch ?

I've tested only this particular patch, not the whole series.

Quoted 11 lines

Anyway, great, but this is still too fragile.

As discussed in the same thread as the problem you reported, there is some work over there to be done so that interrupts are "distributed" in a more flexible way.
Did someone look at this ?
Plans to work on this ? (post 2.3, I suppose)

Signature · 1 line
David Marchand

Thanks,
Rahul

Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] pci: no need for dynamic tailq init

In reply to David Marchand
Quoted 7 lines · On Fri, 29 Jan 2016 15:08:28 +0100 David Marchand <[email protected]>…

These lists can be initialized once and for all at build time. With this, those lists are only manipulated in a common place (and we could even make them private).

A nice side effect is that pci drivers can now register in constructors.

#4 lore raw

Re: [PATCH 2/9] pci: register all pdev as pci drivers

In reply to David Marchand
Quoted 4 lines · On Fri, 29 Jan 2016 15:08:29 +0100 David Marchand <[email protected]>…

pdev drivers are actually pci drivers.
Wrappers for ethdev and crypto pci drivers, that assume a 1 to 1 association between pci device and upper device, have been added so that current drivers are not impacted.

It took me a while to find out what's going on in this patch. I could see several not-so-related changes down the e-mail. I'd suggest to split it this way:

1) separate coding style fixes
2) rename init/uninit to probe/remove (preserve the 'static' there)
3) remove rte_eth_driver_register invocations
4) separate VDEV and PDEV for cryptodev
5) play with the NEXT_ABI (remove those 'static' keywords?)

A more detailed commit log would help too. But this would be automatically solved by the separation, I think.

See comments below...

Regards
Jan

Quoted 29 lines
---
 drivers/crypto/qat/rte_qat_cryptodev.c         |  7 +++++--
 drivers/net/bnx2x/bnx2x_ethdev.c               | 16 ++++++++++------
 drivers/net/cxgbe/cxgbe_ethdev.c               |  5 +++--
 drivers/net/e1000/em_ethdev.c                  |  4 +++-
 drivers/net/e1000/igb_ethdev.c                 | 14 +++++++++-----
 drivers/net/enic/enic_ethdev.c                 |  5 +++--
 drivers/net/fm10k/fm10k_ethdev.c               |  4 +++-
 drivers/net/i40e/i40e_ethdev.c                 |  5 +++--
 drivers/net/i40e/i40e_ethdev_vf.c              |  6 +++---
 drivers/net/ixgbe/ixgbe_ethdev.c               | 10 ++++++----
 drivers/net/nfp/nfp_net.c                      |  7 ++++---
 drivers/net/virtio/virtio_ethdev.c             |  4 +++-
 drivers/net/vmxnet3/vmxnet3_ethdev.c           |  5 +++--
 lib/librte_cryptodev/rte_cryptodev.c           | 18 ++++++++++--------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 14 ++++++++++++++
 lib/librte_cryptodev/rte_cryptodev_version.map | 10 +++++++++-
 lib/librte_ether/rte_ethdev.c                  | 16 +++++++++-------
 lib/librte_ether/rte_ethdev.h                  | 15 +++++++++++++++
 lib/librte_ether/rte_ether_version.map         |  8 ++++++++
 19 files changed, 123 insertions(+), 50 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +0 -0
index e500c1e..6853aee 100644

drivers/crypto/qat/rte_qat_cryptodev.c crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_ · line 116

Quoted 5 lines
drivers/crypto/qat/rte_qat_cryptodev.c +1 -1
@@ -113,10 +113,12 @@ crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_
 }
 
 static struct rte_cryptodev_driver rte_qat_pmd = {
-	{
+	.pci_drv = {

I believe that you are making the driver independent on the exact location of the pci_drv member in the rte_cryptodev_drivers struct. Is it true? Why is that important?

Quoted 9 lines
drivers/crypto/qat/rte_qat_cryptodev.c +2 -0
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_cryptodev_pci_probe,
+		.devuninit = rte_cryptodev_pci_remove,
 	},
 	.cryptodev_init = crypto_qat_dev_init,
 	.dev_private_size = sizeof(struct qat_pmd_private),

drivers/crypto/qat/rte_qat_cryptodev.c static int · line 132

Quoted 6 lines
drivers/crypto/qat/rte_qat_cryptodev.c +2 -1
@@ -126,7 +128,8 @@ static int
 rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-	return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
+	rte_eal_pci_register(&rte_qat_pmd.pci_drv);
+	return 0;

So, I finally discovered that this change somehow separates the PCI (PDEV) and VDEV initialization. Is that correct?

Quoted 25 lines
drivers/crypto/qat/rte_qat_cryptodev.c +0 -0
 }
 
 static struct rte_driver pmd_qat_drv = {
drivers/net/bnx2x/bnx2x_ethdev.c +4 -0
index 69df02e..916b9da 100644
@@ -501,6 +501,8 @@ static struct eth_driver rte_bnx2x_pmd = {
 		.name = "rte_bnx2x_pmd",
 		.id_table = pci_id_bnx2x_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2x_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
@@ -514,24 +516,26 @@ static struct eth_driver rte_bnx2xvf_pmd = {
 		.name = "rte_bnx2xvf_pmd",
 		.id_table = pci_id_bnx2xvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2xvf_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),

drivers/net/bnx2x/bnx2x_ethdev.c static struct eth_driver rte_bnx2xvf_pmd = { · line 530

Quoted 10 lines
drivers/net/bnx2x/bnx2x_ethdev.c +3 -3
 };
 
-static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+static int rte_bnx2x_pmd_init(const char *name __rte_unused,
+			      const char *params __rte_unused)
 {
 	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2x_pmd);
-
+	rte_eal_pci_register(&rte_bnx2x_pmd.pci_drv);

Here, I think you are trying to remove calls to the rte_eth_driver_register as it does not do anything important.

Similar below (snipped)...

drivers/net/bnx2x/bnx2x_ethdev.c static struct eth_driver rte_bnx2xvf_pmd = { · line 535

Quoted 6 lines
drivers/net/bnx2x/bnx2x_ethdev.c +2 -1
 	return 0;
 }
 
-static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+static int rte_bnx2xvf_pmd_init(const char *name __rte_unused,
+				const char *params __rte_unused)

Coding style fixes should be in a separate patch. More occurences below (snipped).

Quoted 127 lines
drivers/net/bnx2x/bnx2x_ethdev.c +0 -0
 {
 	PMD_INIT_FUNC_TRACE();
[snip]
lib/librte_cryptodev/rte_cryptodev.c +10 -8
index f09f67e..1950020 100644
@@ -313,9 +313,9 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	return cryptodev;
 }
 
-static int
-rte_cryptodev_init(struct rte_pci_driver *pci_drv,
-		struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			struct rte_pci_device *pci_dev)
 {
 	struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -375,8 +375,8 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	return -ENXIO;
 }
 
-static int
-rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -418,26 +418,28 @@ rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
+#ifndef RTE_NEXT_ABI
 int
 rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
 		enum pmd_type type)
 {
 	/* Call crypto device initialization directly if device is virtual */
 	if (type == PMD_VDEV)
-		return rte_cryptodev_init((struct rte_pci_driver *)cryptodrv,
+		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
 				NULL);
 
 	/*
 	 * Register PCI driver for physical device intialisation during
 	 * PCI probing
 	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_init;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_uninit;
+	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
+	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
 
 	rte_eal_pci_register(&cryptodrv->pci_drv);
 
 	return 0;
 }
+#endif
 
 
 uint16_t
lib/librte_cryptodev/rte_cryptodev_pmd.h +14 -0
index 8270afa..1c5ee14 100644
@@ -499,6 +499,7 @@ extern int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 
 
+#ifndef RTE_NEXT_ABI
 /**
  * Register a Crypto [Poll Mode] driver.
  *
@@ -527,6 +528,7 @@ rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 extern int
 rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 		enum pmd_type type);
+#endif
 
 /**
  * Executes all the user application registered callbacks for the specific
@@ -541,6 +543,18 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
 				enum rte_cryptodev_event_type event);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			    struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
 
 #ifdef __cplusplus
 }
lib/librte_cryptodev/rte_cryptodev_version.map +9 -1
index ff8e93d..3f838a4 100644
@@ -29,4 +29,12 @@ DPDK_2.2 {
 	rte_cryptodev_queue_pair_stop;
 
 	local: *;
-};
\ No newline at end of file
+};
+
+DPDK_2.3 {
+	global:
+
+	rte_cryptodev_pci_probe;
+	rte_cryptodev_pci_remove;
+
+} DPDK_2.2;
lib/librte_ether/rte_ethdev.c +0 -0
index 756b234..17e4f4d 100644

lib/librte_ether/rte_ethdev.c rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) · line 244

Quoted 9 lines
lib/librte_ether/rte_ethdev.c +3 -3
@@ -239,9 +239,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 	return 0;
 }
 
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-		 struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+		      struct rte_pci_device *pci_dev)

As I've suggested at the beginning, what about "first just rename then make it public (non-static)"? I don't see the connection between the rename and the NEXT_ABI conditional.

Quoted 92 lines
lib/librte_ether/rte_ethdev.c +6 -4
 {
 	struct eth_driver    *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -293,8 +293,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	return diag;
 }
 
-static int
-rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct eth_driver *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -334,6 +334,7 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
+#ifndef RTE_NEXT_ABI
 /**
  * Register an Ethernet [Poll Mode] driver.
  *
@@ -351,10 +352,11 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 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;
+	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
+	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
+#endif
 
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
lib/librte_ether/rte_ethdev.h +15 -0
index 8710dd7..af051d1 100644
@@ -1774,6 +1774,7 @@ struct eth_driver {
 	unsigned int dev_private_size;    /**< Size of device private data. */
 };
 
+#ifndef RTE_NEXT_ABI
 /**
  * @internal
  * A function invoked by the initialization function of an Ethernet driver
@@ -1785,6 +1786,7 @@ struct eth_driver {
  *   the Ethernet driver.
  */
 void rte_eth_driver_register(struct eth_driver *eth_drv);
+#endif
 
 /**
  * Configure an Ethernet device.
@@ -3880,6 +3882,19 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
 			 uint16_t queue_id, size_t size,
 			 unsigned align, int socket_id);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+			  struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_ether/rte_ether_version.map +8 -0
index d8db24d..07b2d8b 100644
@@ -117,3 +117,11 @@ DPDK_2.2 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_eth_dev_pci_probe;
+	rte_eth_dev_pci_remove;
+
+} DPDK_2.2;
Signature · 4 lines
  Jan Viktorin                E-mail: [email protected]
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic
#5 lore raw

Re: [PATCH 2/9] pci: register all pdev as pci drivers

Quoted 12 lines · Jan Viktorin
Quoted 4 lines · On Fri, 29 Jan 2016 15:08:29 +0100 David Marchand <[email protected]>…

pdev drivers are actually pci drivers.
Wrappers for ethdev and crypto pci drivers, that assume a 1 to 1 association between pci device and upper device, have been added so that current drivers are not impacted.

It took me a while to find out what's going on in this patch. I could see several not-so-related changes down the e-mail. I'd suggest to split it this way:

Quoted 8 lines

1) separate coding style fixes
2) rename init/uninit to probe/remove (preserve the 'static' there)
3) remove rte_eth_driver_register invocations
4) separate VDEV and PDEV for cryptodev
5) play with the NEXT_ABI (remove those 'static' keywords?)

A more detailed commit log would help too. But this would be automatically solved by the separation, I think.

Yes, I rushed for this patchset to still be in the proposal window ... Sorry, I will split for next version.

Quoted 1 line

See comments below...

Globally, all my answers are "Yes, will do and it will be easier with smaller patches".
Just added some comments where appropriate.

Quoted 7 lines
Quoted 7 lines
drivers/crypto/qat/rte_qat_cryptodev.c +0 -0
index e500c1e..6853aee 100644
@@ -113,10 +113,12 @@ crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_
 }
 
Quoted 7 lines

drivers/crypto/qat/rte_qat_cryptodev.c crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_ · line 116

Quoted 3 lines
drivers/crypto/qat/rte_qat_cryptodev.c +1 -1
 static struct rte_cryptodev_driver rte_qat_pmd = {
-     {
+     .pci_drv = {

I believe that you are making the driver independent on the exact location of the pci_drv member in the rte_cryptodev_drivers struct. Is it true? Why is that important?

Yes, plus all other drivers are doing this, there were little exception to this convention, so I just aligned here.

Quoted 10 lines
Quoted 10 lines
drivers/crypto/qat/rte_qat_cryptodev.c +2 -0
              .name = "rte_qat_pmd",
              .id_table = pci_id_qat_map,
              .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+             .devinit = rte_cryptodev_pci_probe,
+             .devuninit = rte_cryptodev_pci_remove,
      },
      .cryptodev_init = crypto_qat_dev_init,
      .dev_private_size = sizeof(struct qat_pmd_private),
@@ -126,7 +128,8 @@ static int
 rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
Quoted 8 lines

drivers/crypto/qat/rte_qat_cryptodev.c static int · line 132

Quoted 5 lines
drivers/crypto/qat/rte_qat_cryptodev.c +2 -1
 {
      PMD_INIT_FUNC_TRACE();
-     return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
+     rte_eal_pci_register(&rte_qat_pmd.pci_drv);
+     return 0;

So, I finally discovered that this change somehow separates the PCI (PDEV) and VDEV initialization. Is that correct?

Yes.
I will separate crypto updates from netdev updates since crypto framework has a slight different way of initialising.

Quoted 8 lines
Quoted 8 lines
lib/librte_ether/rte_ethdev.c +0 -0
index 756b234..17e4f4d 100644
@@ -239,9 +239,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
      return 0;
 }
 
Quoted 10 lines

lib/librte_ether/rte_ethdev.c rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) · line 244

Quoted 6 lines
lib/librte_ether/rte_ethdev.c +3 -3
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-              struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+                   struct rte_pci_device *pci_dev)

As I've suggested at the beginning, what about "first just rename then make it public (non-static)"? I don't see the connection between the rename and the NEXT_ABI conditional.

I don't think we need NEXT_ABI checks here.
I am not breaking anything here, just adding a new symbol.

I will introduce this new symbol, then convert all existing pdev/eth_driver to pdev/pci_driver in a second patch.

Signature · 1 line
David Marchand
#7 lore raw

Re: [PATCH 3/9] drivers: no more pdev drivers

In reply to David Marchand

Maybe, a better subject?

drivers: init pdev drivers in constructors

Quoted 39 lines · On Fri, 29 Jan 2016 15:08:30 +0100 David Marchand <[email protected]>…

Now that pdev drivers have been converted to pci drivers, there is nothing left in their init functions that can't go in a constructor. pdev / vdev drivers init order is changed by this commit, but I can't see why we would need to preserve it.

---
 drivers/crypto/qat/rte_qat_cryptodev.c | 13 +++---------
 drivers/net/bnx2x/bnx2x_ethdev.c       | 26 +++---------------------
 drivers/net/cxgbe/cxgbe_ethdev.c       | 19 +++---------------
 drivers/net/e1000/em_ethdev.c          | 13 +++---------
 drivers/net/e1000/igb_ethdev.c         | 34 ++++----------------------------
 drivers/net/enic/enic_ethdev.c         | 18 +++--------------
 drivers/net/fm10k/fm10k_ethdev.c       | 19 +++---------------
 drivers/net/i40e/i40e_ethdev.c         | 19 +++---------------
 drivers/net/i40e/i40e_ethdev_vf.c      | 19 +++---------------
 drivers/net/ixgbe/ixgbe_ethdev.c       | 36 +++-------------------------------
 drivers/net/mlx4/mlx4.c                | 19 +++---------------
 drivers/net/mlx5/mlx5.c                | 19 +++---------------
 drivers/net/nfp/nfp_net.c              | 14 +++----------
 drivers/net/virtio/virtio_ethdev.c     | 22 ++++-----------------
 drivers/net/vmxnet3/vmxnet3_ethdev.c   | 18 +++--------------
 15 files changed, 47 insertions(+), 261 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +3 -2
index 6853aee..ded5d60 100644
@@ -124,17 +124,10 @@ static struct rte_cryptodev_driver rte_qat_pmd = {
 	.dev_private_size = sizeof(struct qat_pmd_private),
 };
 
-static int
-rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_qat_pmd_init(void)
 {
 	PMD_INIT_FUNC_TRACE();

drivers/crypto/qat/rte_qat_cryptodev.c static struct rte_cryptodev_driver rte_qat_pmd = { · line 140

Quoted 10 lines
drivers/crypto/qat/rte_qat_cryptodev.c +0 -8
 	rte_eal_pci_register(&rte_qat_pmd.pci_drv);
-	return 0;
 }
-
-static struct rte_driver pmd_qat_drv = {
-	.type = PMD_PDEV,
-	.init = rte_qat_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(pmd_qat_drv);

What about introducing a macro for this?

RTE_REGISTER_PCI_DRIVER(rte_qad_pmd);

Regards
Jan

#18 lore raw

Re: [PATCH 5/9] eal: get rid of pmd type

In reply to David Marchand
Quoted 28 lines · On Fri, 29 Jan 2016 15:08:32 +0100 David Marchand <[email protected]>…

Now that we only have vdev drivers, there is no need for a pmd type in rte_driver.
rte_driver is now purely a vdev thing, and could be renamed later (then .init would become .probe, .uninit would become .remove).

---
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c |  2 ++
 drivers/net/af_packet/rte_eth_af_packet.c  |  2 ++
 drivers/net/bonding/rte_eth_bond_pmd.c     |  2 ++
 drivers/net/mpipe/mpipe_tilegx.c           |  4 ++++
 drivers/net/null/rte_eth_null.c            |  2 ++
 drivers/net/pcap/rte_eth_pcap.c            |  2 ++
 drivers/net/ring/rte_eth_ring.c            |  2 ++
 drivers/net/szedata2/rte_eth_szedata2.c    |  2 ++
 drivers/net/xenvirt/rte_eth_xenvirt.c      |  2 ++
 lib/librte_cryptodev/rte_cryptodev.c       | 14 ++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.h       |  2 ++
 lib/librte_cryptodev/rte_cryptodev_pmd.h   |  4 ++++
 lib/librte_eal/common/eal_common_dev.c     | 11 ++++++++---
 lib/librte_eal/common/include/rte_dev.h    |  4 ++++
 14 files changed, 52 insertions(+), 3 deletions(-)
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +0 -0
index d8ccf05..94752de 100644

drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c cryptodev_aesni_mb_uninit(const char *name) · line 666

Quoted 6 lines
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +2 -0
@@ -661,7 +661,9 @@ cryptodev_aesni_mb_uninit(const char *name)
 
 static struct rte_driver cryptodev_aesni_mb_pmd_drv = {
 	.name = CRYPTODEV_NAME_AESNI_MB_PMD,
+#ifndef RTE_NEXT_ABI
 	.type = PMD_VDEV,
+#endif

What about something like:

#ifdef RTE_NEXT_ABI
#define RTE_PMD_SET_TYPE(t)
#else
#define RTE_PMD_SET_TYPE(t) .type = PMD_##t
#endif

and then just:

static struct rte_driver cryptodev_aesni_mb_pmd_drv = {
	.name = CRYPTODEV_NAME_AESNI_MB_PMD,
	RTE_PMD_SET_TYPE(VDEV),

drivers/net/af_packet/rte_eth_af_packet.c exit:

Quoted 12 lines
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +0 -0
 	.init = cryptodev_aesni_mb_init,
 	.uninit = cryptodev_aesni_mb_uninit
 };
drivers/net/af_packet/rte_eth_af_packet.c +1 -0
index 767f36b..6603462 100644
@@ -838,7 +838,9 @@ exit:
[snip]
 
 struct rte_cryptodev *
+#ifndef RTE_NEXT_ABI

And maybe...

#ifndef RTE_NEXT_ABI
#define RTE_PMD_HAS_TYPE
#endif

#ifdef RTE_PMD_HAS_TYPE

drivers/net/af_packet/rte_eth_af_packet.c

Quoted 8 lines

rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)

drivers/net/af_packet/rte_eth_af_packet.c +3 -0
+#else
+rte_cryptodev_pmd_allocate(const char *name, int socket_id)
+#endif
 {
 	struct rte_cryptodev *cryptodev;
 	uint8_t dev_id;
[snip]

Regards
Jan

#8 lore raw

Re: [PATCH 3/9] drivers: no more pdev drivers

In reply to Jan Viktorin
Quoted 3 lines · Jan Viktorin

Maybe, a better subject?

drivers: init pdev drivers in constructors

Why not, I will try to find a best one, and if I can't, I will go with this.

Quoted 22 lines
Quoted 7 lines · On Fri, 29 Jan 2016 15:08:30 +0100 David Marchand <[email protected]>…
drivers/crypto/qat/rte_qat_cryptodev.c +3 -2
-static int
-rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
+/* Driver registration */
+static void __attribute__((constructor, used))
+rte_qat_pmd_init(void)
 {
      PMD_INIT_FUNC_TRACE();

drivers/crypto/qat/rte_qat_cryptodev.c static struct rte_cryptodev_driver rte_qat_pmd = { · line 140

Quoted 10 lines
drivers/crypto/qat/rte_qat_cryptodev.c +0 -8
      rte_eal_pci_register(&rte_qat_pmd.pci_drv);
-     return 0;
 }
-
-static struct rte_driver pmd_qat_drv = {
-     .type = PMD_PDEV,
-     .init = rte_qat_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(pmd_qat_drv);

What about introducing a macro for this?

Quoted 1 line

RTE_REGISTER_PCI_DRIVER(rte_qad_pmd);

Yes.

Signature · 1 line
David Marchand
#9 lore raw

Re: [PATCH 3/9] drivers: no more pdev drivers

Quoted 6 lines · David Marchand
Quoted 3 lines · Jan Viktorin

What about introducing a macro for this?

RTE_REGISTER_PCI_DRIVER(rte_qad_pmd);

Yes.

The only problem here, is that rte_qad_pmd is a crypto structure (same problem with ethdev), so I can't just pass it to eal.
I can't just pass the pci driver, for the cases where multiple drivers are registered in a single file (look at ixgbe driver).

So, how about :

In rte_pci.h :

#define RTE_EAL_PCI_REGISTER(name, d)\
void pciinitfn_ ##name(void);\
void __attribute__((constructor, used)) pciinitfn_ ##name(void)\

{\
        rte_eal_pci_register(d);\
}

Then, in qat driver :
RTE_EAL_PCI_REGISTER(qat, &rte_qat_pmd.pci_drv);

Signature · 1 line
David Marchand
#10 lore raw

Re: [PATCH 3/9] drivers: no more pdev drivers

Quoted 16 lines · On Wed, 10 Feb 2016 10:27:14 +0100 David Marchand <[email protected]>…
Quoted 6 lines · David Marchand
Quoted 3 lines · Jan Viktorin

What about introducing a macro for this?

RTE_REGISTER_PCI_DRIVER(rte_qad_pmd);

Yes.

The only problem here, is that rte_qad_pmd is a crypto structure (same problem with ethdev), so I can't just pass it to eal.
I can't just pass the pci driver, for the cases where multiple drivers are registered in a single file (look at ixgbe driver).

So, how about :

Quoted 7 lines

In rte_pci.h :

#define RTE_EAL_PCI_REGISTER(name, d)\
void pciinitfn_ ##name(void);\
void __attribute__((constructor, used)) pciinitfn_ ##name(void)\

{\
        rte_eal_pci_register(d);\

I meant

	rte_eal_pci_register(&(d)->pci_drv);\

Perhaps, my assumption that a PCI driver is always referred as pci_drv is wrong...

Quoted 5 lines

}

Then, in qat driver :
RTE_EAL_PCI_REGISTER(qat, &rte_qat_pmd.pci_drv);

However, I think that this is a detail. Passing rte_pci_driver is good.

Regards
Jan

Signature · 4 lines
   Jan Viktorin                  E-mail: [email protected]
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic
#20 lore raw

Re: [PATCH 6/9] eal: initialize vdevs right next to pci devices

In reply to David Marchand
Quoted 41 lines · On Fri, 29 Jan 2016 15:08:33 +0100 David Marchand <[email protected]>…

This way, the resources probing happens in a common place.

---
 lib/librte_eal/bsdapp/eal/eal.c         | 7 +++++++
 lib/librte_eal/common/include/rte_dev.h | 2 +-
 lib/librte_eal/linuxapp/eal/eal.c       | 7 +++++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal.c +7 -0
index a34e61d..b557a9f 100644
@@ -582,8 +582,10 @@ rte_eal_init(int argc, char **argv)
 		rte_config.master_lcore, thread_id, cpuset,
 		ret == 0 ? "" : "...");
 
+#ifndef RTE_NEXT_ABI
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
+#endif
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
@@ -617,6 +619,11 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
+#ifdef RTE_NEXT_ABI
+	if (rte_eal_dev_init() < 0)
+		rte_panic("Cannot probe vdev devices\n");
+#endif
+
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
lib/librte_eal/common/include/rte_dev.h +0 -0
index 88c1a19..df69e28 100644

lib/librte_eal/common/include/rte_dev.h void rte_eal_driver_register(struct rte_driver *driver); · line 161

Quoted 7 lines
lib/librte_eal/common/include/rte_dev.h +1 -1
@@ -156,7 +156,7 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
+ * Scan all devargs and attach to drivers if available
  */
 int rte_eal_dev_init(void);

Move this to a separate commit? Is it just a forgotten doc comment?

Quoted 18 lines
lib/librte_eal/linuxapp/eal/eal.c +2 -0
index 62241ee..95313af 100644
@@ -834,8 +834,10 @@ rte_eal_init(int argc, char **argv)
 		rte_config.master_lcore, (int)thread_id, cpuset,
 		ret == 0 ? "" : "...");
 
+#ifndef RTE_NEXT_ABI
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
+#endif
 
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
@@ -873,6 +875,11 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);

lib/librte_eal/linuxapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 885

Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal.c +5 -0
 	rte_eal_mp_wait_lcore();
 
+#ifdef RTE_NEXT_ABI
+	if (rte_eal_dev_init() < 0)
+		rte_panic("Cannot probe vdev devices\n");
+#endif
+
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");

I cannot see the point why it is enclosed in the RTE_NEXT_ABI. Is it such a serious breakage?

Regards
Jan

#23 lore raw

Re: [PATCH 7/9] pci: add a helper for device name

In reply to David Marchand
Quoted 23 lines · On Fri, 29 Jan 2016 15:08:34 +0100 David Marchand <[email protected]>…

eal is a better place than ethdev for naming resources. Add a helper here, and make use of it in ethdev hotplug code.

---
 lib/librte_eal/common/include/rte_pci.h | 28 ++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 22 ++--------------------
 2 files changed, 30 insertions(+), 20 deletions(-)
lib/librte_eal/common/include/rte_pci.h +6 -0
index 334c12e..9edd5f5 100644
@@ -309,6 +309,34 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using above functions.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address

lib/librte_eal/common/include/rte_pci.h eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr) · line 327

Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +10 -0
+ * @param output
+ *	The output buffer string
+ * @param size
+ *	The output buffer size
+ * @return
+ *  0 on success, negative on error.
+ */
+static inline int
+eal_pci_device_name(const struct rte_pci_addr *addr,
+		    char *output, int size)

"size_t size" (or unsigned int) seems to be better to me.

lib/librte_eal/common/include/rte_pci.h eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr) · line 335

Quoted 8 lines
lib/librte_eal/common/include/rte_pci.h +8 -0
+{
+	int ret;
+
+	ret = snprintf(output, size, PCI_PRI_FMT,
+		       addr->domain, addr->bus,
+		       addr->devid, addr->function);
+	if (ret < 0 || ret >= size)
+		return -1;

The return value is not checked (below). I think, such functions are usually missing error checking as nobody expects them to fail. Wouldn't it be better to panic here?

Quoted 54 lines
lib/librte_eal/common/include/rte_pci.h +4 -0
+
+	return 0;
+}
+
 /* Compare two PCI device addresses. */
 /**
  * Utility function to compare two PCI device addresses.
lib/librte_ether/rte_ethdev.c +2 -20
index 17e4f4d..5ba7479 100644
@@ -214,20 +214,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	return eth_dev;
 }
 
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -251,9 +237,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 
 	eth_drv = (struct eth_driver *)pci_drv;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	eal_pci_device_name(&pci_dev->addr, ethdev_name, sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
 	if (eth_dev == NULL)
@@ -304,9 +288,7 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	eal_pci_device_name(&pci_dev->addr, ethdev_name, sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocated(ethdev_name);
 	if (eth_dev == NULL)
Signature · 4 lines
   Jan Viktorin                  E-mail: [email protected]
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic
#26 lore raw

Re: [PATCH 8/9] pci: add a helper to refresh a device

In reply to David Marchand
Quoted 14 lines · On Fri, 29 Jan 2016 15:08:35 +0100 David Marchand <[email protected]>…

It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c   | 49 +++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h   | 13 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++++++++
 3 files changed, 75 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -0
index 4584522..5dd89e3 100644

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 400

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
@@ -396,6 +396,55 @@ error:
 	return -1;
 }
 
+int
+pci_refresh_device(const struct rte_pci_addr *addr)

What about pci_reload_device or pci_reload_device_info? I don't mind too much, only the word 'refresh' reminds me other associations.

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +10 -0
+{
+	int fd;
+	struct pci_conf matches[2];
+	struct pci_match_conf match = {
+		.pc_sel = {
+			.pc_domain = addr->domain,
+			.pc_bus = addr->bus,
+			.pc_dev = addr->devid,
+			.pc_func = addr->function,
+		},

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 420

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +10 -0
+	};
+	struct pci_conf_io conf_io = {
+		.pat_buf_len = 0,
+		.num_patterns = 1,
+		.patterns = { &match },
+		.match_buf_len = sizeof(matches),
+		.matches = &matches[0],
+	};
+
+	fd = open("/dev/pci", O_RDONLY);

Just courious who provides this special file... is a DPDK-specific thing? I haven't noticed it anywhere in Linux.

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 423

Quoted 3 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -0
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;

If you write:

		return -1;

then you can...

Quoted 9 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +9 -0
+	}
+
+	if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+				__func__, strerror(errno));
+		goto error;
+	}
+
+	if (conf_io.num_matches != 1)

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 442

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +10 -0
+		goto error;
+
+	if (pci_scan_one(fd, &matches[0]) < 0)
+		goto error;
+
+	close(fd);
+
+	return 0;
+
+error:

...remove this if:

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 444

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
+	if (fd >= 0)
+		close(fd);

Or, do you consider it more stable in the orignal way?

Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -0
+	return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
 			    void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_private.h +0 -0
index 072e672..ed1903f 100644
@@ -155,6 +155,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 

lib/librte_eal/common/eal_private.h struct rte_pci_driver; · line 166

Quoted 10 lines
lib/librte_eal/common/eal_private.h +9 -0
 /**
+ * Refresh a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.

I don't know whether this is a convention in DPDK, anyway, I don't like to restrict errors to just negatives. You cannot write

if ((err = pci_refresh_device(...)) /* < 0 */) {
	handle_error(err);
}

as the check for < 0 is required (easy to be avoided).

Quoted 31 lines
lib/librte_eal/common/eal_private.h +4 -0
+ */
+int pci_refresh_device(const struct rte_pci_addr *addr);
+
+/**
  * Unbind kernel driver for this device
  *
  * This function is private to EAL.
lib/librte_eal/linuxapp/eal/eal_pci.c +13 -0
index a354f76..4fe8b60 100644
@@ -393,6 +393,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 	return 0;
 }
 
+int
+pci_refresh_device(const struct rte_pci_addr *addr)
+{
+	char filename[PATH_MAX];
+
+	snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
+		 SYSFS_PCI_DEVICES, addr->domain, addr->bus, addr->devid,
+		 addr->function);
+
+	return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
+			    addr->function);
+}
+
 /*
  * split up a pci address into its constituent parts.
  */
Signature · 4 lines
   Jan Viktorin                  E-mail: [email protected]
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic
#11 lore raw

Re: [PATCH 3/9] drivers: no more pdev drivers

In reply to Jan Viktorin
Quoted 8 lines · Jan Viktorin
Quoted 5 lines · On Wed, 10 Feb 2016 10:27:14 +0100 David Marchand <[email protected]>…

#define RTE_EAL_PCI_REGISTER(name, d)\
void pciinitfn_ ##name(void);\
void __attribute__((constructor, used)) pciinitfn_ ##name(void)\

{\
        rte_eal_pci_register(d);\
Quoted 4 lines

I meant

        rte_eal_pci_register(&(d)->pci_drv);\

Perhaps, my assumption that a PCI driver is always referred as pci_drv is wrong...

Well, I suppose we will always have a pci driver embedded in some other internal pmd structure.
So we can always expect it to be called pci_drv ...

Btw, for drivers like mlx or virtio that need to do some more stuff in their constructor (the iopl stuff for virtio is the most interesting case, since the pci register happens only if iopl succeeded), we might need some RTE_MODULE_INIT for those.

But in such a case, I think having RTE_MODULE_INIT in all pmds would make more sense, and RTE_EAL_PCI_REGISTER looks unneeded ?

Signature · 1 line
David Marchand
#21 lore raw

Re: [PATCH 6/9] eal: initialize vdevs right next to pci devices

In reply to Jan Viktorin
Quoted 7 lines · Jan Viktorin
Quoted 5 lines · On Fri, 29 Jan 2016 15:08:33 +0100 David Marchand <[email protected]>…
lib/librte_eal/common/include/rte_dev.h +0 -0
@@ -156,7 +156,7 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
Quoted 7 lines

lib/librte_eal/common/include/rte_dev.h void rte_eal_driver_register(struct rte_driver *driver); · line 161

Quoted 5 lines
lib/librte_eal/common/include/rte_dev.h +1 -1
 /**
- * Initalize all the registered drivers in this process
+ * Scan all devargs and attach to drivers if available
  */
 int rte_eal_dev_init(void);

Move this to a separate commit? Is it just a forgotten doc comment?

Should be in previous commit, yes.

Quoted 20 lines
Quoted 20 lines
lib/librte_eal/linuxapp/eal/eal.c +2 -0
index 62241ee..95313af 100644
@@ -834,8 +834,10 @@ rte_eal_init(int argc, char **argv)
              rte_config.master_lcore, (int)thread_id, cpuset,
              ret == 0 ? "" : "...");
 
+#ifndef RTE_NEXT_ABI
      if (rte_eal_dev_init() < 0)
              rte_panic("Cannot init pmd devices\n");
+#endif
 
      RTE_LCORE_FOREACH_SLAVE(i) {
 
@@ -873,6 +875,11 @@ rte_eal_init(int argc, char **argv)
      rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
      rte_eal_mp_wait_lcore();
 
Quoted 11 lines

lib/librte_eal/linuxapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 885

Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal.c +5 -0
+#ifdef RTE_NEXT_ABI
+     if (rte_eal_dev_init() < 0)
+             rte_panic("Cannot probe vdev devices\n");
+#endif
+
      /* Probe & Initialize PCI devices */
      if (rte_eal_pci_probe())
              rte_panic("Cannot probe PCI\n");

I cannot see the point why it is enclosed in the RTE_NEXT_ABI. Is it such a serious breakage?

No.
We can make this move unconditional.

Thanks.

Signature · 1 line
David Marchand
#27 lore raw

Re: [PATCH 8/9] pci: add a helper to refresh a device

In reply to Jan Viktorin
Quoted 20 lines · Jan Viktorin
Quoted 17 lines · On Fri, 29 Jan 2016 15:08:35 +0100 David Marchand <[email protected]>…

It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c   | 49 +++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h   | 13 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++++++++
 3 files changed, 75 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -0
index 4584522..5dd89e3 100644
@@ -396,6 +396,55 @@ error:
      return -1;
 }
 
Quoted 5 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 400

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
+int
+pci_refresh_device(const struct rte_pci_addr *addr)

What about pci_reload_device or pci_reload_device_info? I don't mind too much, only the word 'refresh' reminds me other associations.

Or maybe pci_update_device ?
I added pci_add_device in my other pci patchset, so update sounds better to me.

Quoted 15 lines
Quoted 15 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +15 -0
+{
+     int fd;
+     struct pci_conf matches[2];
+     struct pci_match_conf match = {
+             .pc_sel = {
+                     .pc_domain = addr->domain,
+                     .pc_bus = addr->bus,
+                     .pc_dev = addr->devid,
+                     .pc_func = addr->function,
+             },
+     };
+     struct pci_conf_io conf_io = {
+             .pat_buf_len = 0,
+             .num_patterns = 1,
+             .patterns = { &match },
Quoted 8 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 420

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +5 -0
+             .match_buf_len = sizeof(matches),
+             .matches = &matches[0],
+     };
+
+     fd = open("/dev/pci", O_RDONLY);

Just courious who provides this special file... is a DPDK-specific thing? I haven't noticed it anywhere in Linux.

I don't know, just took the bsd pci code and plugged myself in it. So for me this is a special bsd device.

This is mainly copy/paste.
Look at rte_eal_pci_scan() from lib/librte_eal/bsdapp/eal/eal_pci.c.

Quoted 32 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 423

Quoted 4 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -0
+     if (fd < 0) {
+             RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+             goto error;

If you write:

                return -1;

then you can...

Quoted 9 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +9 -0
+     }
+
+     if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+             RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+                             __func__, strerror(errno));
+             goto error;
+     }
+
+     if (conf_io.num_matches != 1)

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 442

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +10 -0
+             goto error;
+
+     if (pci_scan_one(fd, &matches[0]) < 0)
+             goto error;
+
+     close(fd);
+
+     return 0;
+
+error:

...remove this if:

Quoted 4 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 444

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
+     if (fd >= 0)
+             close(fd);

Or, do you consider it more stable in the orignal way?

Well, as said above, this is copy/paste code.
But, anyway, when I write functions with goto statements, I prefer having a minimal number of return statements, matter of taste. Another way is to add two label error_close: error: but this is a bit overkill here.

Quoted 27 lines
Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -0
+     return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
                          void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_private.h +0 -0
index 072e672..ed1903f 100644
@@ -155,6 +155,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 

lib/librte_eal/common/eal_private.h struct rte_pci_driver; · line 166

Quoted 10 lines
lib/librte_eal/common/eal_private.h +9 -0
 /**
+ * Refresh a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *   The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.

I don't know whether this is a convention in DPDK, anyway, I don't like to restrict errors to just negatives. You cannot write

Quoted 5 lines
if ((err = pci_refresh_device(...)) /* < 0 */) {
        handle_error(err);
}

as the check for < 0 is required (easy to be avoided).

It is a remnant of a lot of code in eal that tries to have 0 for success, < 0 for errors, > 0 for special cases.

Signature · 1 line
David Marchand
#24 lore raw

Re: [PATCH 7/9] pci: add a helper for device name

In reply to Jan Viktorin
Quoted 30 lines · Jan Viktorin
Quoted 27 lines · On Fri, 29 Jan 2016 15:08:34 +0100 David Marchand <[email protected]>…

eal is a better place than ethdev for naming resources. Add a helper here, and make use of it in ethdev hotplug code.

---
 lib/librte_eal/common/include/rte_pci.h | 28 ++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 22 ++--------------------
 2 files changed, 30 insertions(+), 20 deletions(-)
lib/librte_eal/common/include/rte_pci.h +10 -0
index 334c12e..9edd5f5 100644
@@ -309,6 +309,34 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using above functions.
+ *
+ * @param addr
+ *   The PCI Bus-Device-Function address
+ * @param output
+ *   The output buffer string
+ * @param size
+ *   The output buffer size
Quoted 8 lines

lib/librte_eal/common/include/rte_pci.h eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr) · line 327

Quoted 6 lines
lib/librte_eal/common/include/rte_pci.h +6 -0
+ * @return
+ *  0 on success, negative on error.
+ */
+static inline int
+eal_pci_device_name(const struct rte_pci_addr *addr,
+                 char *output, int size)

"size_t size" (or unsigned int) seems to be better to me.

Yes.

Quoted 13 lines

lib/librte_eal/common/include/rte_pci.h eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr) · line 335

Quoted 9 lines
lib/librte_eal/common/include/rte_pci.h +8 -0
+{
+     int ret;
+
+     ret = snprintf(output, size, PCI_PRI_FMT,
+                    addr->domain, addr->bus,
+                    addr->devid, addr->function);
+     if (ret < 0 || ret >= size)
+             return -1;

The return value is not checked (below). I think, such functions are usually missing error checking as nobody expects them to fail. Wouldn't it be better to panic here?

assert or panic, yes.

Signature · 1 line
David Marchand
#28 lore raw

Re: [PATCH 8/9] pci: add a helper to refresh a device

In reply to David Marchand
Quoted 21 lines · On Wed, 10 Feb 2016 13:00:50 +0100 David Marchand <[email protected]>…
Quoted 20 lines · Jan Viktorin
Quoted 17 lines · On Fri, 29 Jan 2016 15:08:35 +0100 David Marchand <[email protected]>…

It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c   | 49 +++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h   | 13 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++++++++
 3 files changed, 75 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -0
index 4584522..5dd89e3 100644
@@ -396,6 +396,55 @@ error:
      return -1;
 }
 
Quoted 9 lines
Quoted 5 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 400

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
+int
+pci_refresh_device(const struct rte_pci_addr *addr)  

What about pci_reload_device or pci_reload_device_info? I don't mind too much, only the word 'refresh' reminds me other associations.

Or maybe pci_update_device ?
I added pci_add_device in my other pci patchset, so update sounds better to me.

OK.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +15 -0
+{
+     int fd;
+     struct pci_conf matches[2];
+     struct pci_match_conf match = {
+             .pc_sel = {
+                     .pc_domain = addr->domain,
+                     .pc_bus = addr->bus,
+                     .pc_dev = addr->devid,
+                     .pc_func = addr->function,
+             },
+     };
+     struct pci_conf_io conf_io = {
+             .pat_buf_len = 0,
+             .num_patterns = 1,
+             .patterns = { &match },
Quoted 8 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 420

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +5 -0
+             .match_buf_len = sizeof(matches),
+             .matches = &matches[0],
+     };
+
+     fd = open("/dev/pci", O_RDONLY);  

Just courious who provides this special file... is a DPDK-specific thing? I haven't noticed it anywhere in Linux.

Quoted 5 lines

I don't know, just took the bsd pci code and plugged myself in it. So for me this is a special bsd device.

This is mainly copy/paste.
Look at rte_eal_pci_scan() from lib/librte_eal/bsdapp/eal/eal_pci.c.

BSD... I didn't notice. That's the answer.

Quoted 36 lines
Quoted 36 lines

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 423

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -0
+     if (fd < 0) {
+             RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+             goto error;  

If you write:

                return -1;

then you can...

Quoted 9 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +9 -0
+     }
+
+     if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+             RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+                             __func__, strerror(errno));
+             goto error;
+     }
+
+     if (conf_io.num_matches != 1)

lib/librte_eal/bsdapp/eal/eal_pci.c error: · line 442

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +10 -0
+             goto error;
+
+     if (pci_scan_one(fd, &matches[0]) < 0)
+             goto error;
+
+     close(fd);
+
+     return 0;
+
+error:  

...remove this if:

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
+     if (fd >= 0)
+             close(fd);  
Quoted 7 lines
Quoted 1 line

Or, do you consider it more stable in the orignal way?

Well, as said above, this is copy/paste code.
But, anyway, when I write functions with goto statements, I prefer having a minimal number of return statements, matter of taste. Another way is to add two label error_close: error: but this is a bit overkill here.

All of them are OK. As for me, I prefer to not hide simple returns.

Quoted 29 lines
Quoted 29 lines
Quoted 15 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -0
+     return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
                          void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_private.h +0 -0
index 072e672..ed1903f 100644
@@ -155,6 +155,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 

lib/librte_eal/common/eal_private.h struct rte_pci_driver; · line 166

Quoted 10 lines
lib/librte_eal/common/eal_private.h +9 -0
 /**
+ * Refresh a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *   The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.  

I don't know whether this is a convention in DPDK, anyway, I don't like to restrict errors to just negatives. You cannot write

Quoted 9 lines
Quoted 5 lines
if ((err = pci_refresh_device(...)) /* < 0 */) {
        handle_error(err);
}

as the check for < 0 is required (easy to be avoided).

It is a remnant of a lot of code in eal that tries to have 0 for success, < 0 for errors, > 0 for special cases.

OK, makes sense.

Quoted 1 line
Signature · 4 lines
   Jan Viktorin                  E-mail: [email protected]
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic
#12 lore raw

Re: [PATCH 3/9] drivers: no more pdev drivers

In reply to David Marchand
Quoted 18 lines · On Wed, 10 Feb 2016 12:38:20 +0100 David Marchand <[email protected]>…
Quoted 8 lines · Jan Viktorin
Quoted 5 lines · On Wed, 10 Feb 2016 10:27:14 +0100 David Marchand <[email protected]>…

#define RTE_EAL_PCI_REGISTER(name, d)\
void pciinitfn_ ##name(void);\
void __attribute__((constructor, used)) pciinitfn_ ##name(void)\

{\
        rte_eal_pci_register(d);\  
Quoted 4 lines

I meant

        rte_eal_pci_register(&(d)->pci_drv);\

Perhaps, my assumption that a PCI driver is always referred as pci_drv is wrong...

Well, I suppose we will always have a pci driver embedded in some other internal pmd structure.
So we can always expect it to be called pci_drv ...

Quoted 8 lines

Btw, for drivers like mlx or virtio that need to do some more stuff in their constructor (the iopl stuff for virtio is the most interesting case, since the pci register happens only if iopl succeeded), we might need some RTE_MODULE_INIT for those.

But in such a case, I think having RTE_MODULE_INIT in all pmds would make more sense, and RTE_EAL_PCI_REGISTER looks unneeded ?

The Linux Kernel solves this by allowing both ways. You can do it by hand and for most cases you can use just a simple oneliner.

So, we can have the RTE_(EAL_)MODULE_INIT for the general case. And then eg. RTE_EAL_PCI_MODULE_INIT that makes the most common glue code to register a single driver and who finally calls the RTE_EAL_MODULE_INIT.

Regards
Jan

#30 lore raw

v2 cover prepare for rte_device / rte_driver

In reply to David Marchand

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

Quoted 1 line

From my pov, eal hotplug api introduced in this patchset still needs more

work so that it does not need to know about devargs. So a new devargs api is needed.

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Regards,

Signature · 72 lines
David Marchand

David Marchand (17):
  pci: no need for dynamic tailq init
  crypto: no need for a crypto pmd type
  drivers: align pci driver definitions
  eal: remove duplicate function declaration
  eal: introduce init macros
  crypto: export init/uninit common wrappers for pci drivers
  ethdev: export init/uninit common wrappers for pci drivers
  drivers: convert all pdev drivers as pci drivers
  crypto: get rid of crypto driver register callback
  ethdev: get rid of eth driver register callback
  eal/linux: move back interrupt thread init before setting affinity
  pci: add a helper for device name
  pci: add a helper to update a device
  ethdev: do not scan all pci devices on attach
  eal: add hotplug operations for pci and vdev
  ethdev: convert to eal hotplug
  ethdev: get rid of device type

 app/test/virtual_pmd.c                          |   2 +-
 drivers/crypto/qat/rte_qat_cryptodev.c          |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |   2 +-
 drivers/net/bnx2x/bnx2x_ethdev.c                |  35 +--
 drivers/net/bonding/rte_eth_bond_api.c          |   2 +-
 drivers/net/cxgbe/cxgbe_ethdev.c                |  24 +-
 drivers/net/cxgbe/cxgbe_main.c                  |   2 +-
 drivers/net/e1000/em_ethdev.c                   |  16 +-
 drivers/net/e1000/igb_ethdev.c                  |  40 +--
 drivers/net/ena/ena_ethdev.c                    |  20 +-
 drivers/net/enic/enic_ethdev.c                  |  23 +-
 drivers/net/fm10k/fm10k_ethdev.c                |  23 +-
 drivers/net/i40e/i40e_ethdev.c                  |  26 +-
 drivers/net/i40e/i40e_ethdev_vf.c               |  25 +-
 drivers/net/ixgbe/ixgbe_ethdev.c                |  47 +---
 drivers/net/mlx4/mlx4.c                         |  22 +-
 drivers/net/mlx5/mlx5.c                         |  21 +-
 drivers/net/mpipe/mpipe_tilegx.c                |   2 +-
 drivers/net/nfp/nfp_net.c                       |  23 +-
 drivers/net/null/rte_eth_null.c                 |   2 +-
 drivers/net/pcap/rte_eth_pcap.c                 |   2 +-
 drivers/net/ring/rte_eth_ring.c                 |   2 +-
 drivers/net/szedata2/rte_eth_szedata2.c         |  25 +-
 drivers/net/vhost/rte_eth_vhost.c               |   2 +-
 drivers/net/virtio/virtio_ethdev.c              |  26 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c            |  23 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   2 +-
 examples/ip_pipeline/init.c                     |  22 --
 lib/librte_cryptodev/rte_cryptodev.c            |  67 +----
 lib/librte_cryptodev/rte_cryptodev.h            |   2 -
 lib/librte_cryptodev/rte_cryptodev_pmd.h        |  45 +---
 lib/librte_cryptodev/rte_cryptodev_version.map  |   9 +-
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  52 +++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   8 +
 lib/librte_eal/common/eal_common_dev.c          |  39 +++
 lib/librte_eal/common/eal_common_pci.c          |  17 +-
 lib/librte_eal/common/eal_private.h             |  20 +-
 lib/librte_eal/common/include/rte_dev.h         |  29 ++-
 lib/librte_eal/common/include/rte_eal.h         |   3 +
 lib/librte_eal/common/include/rte_pci.h         |  32 +++
 lib/librte_eal/common/include/rte_tailq.h       |   4 +-
 lib/librte_eal/linuxapp/eal/eal.c               |   7 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c           |  16 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   8 +
 lib/librte_ether/rte_ethdev.c                   | 316 ++++--------------------
 lib/librte_ether/rte_ethdev.h                   |  40 ++-
 lib/librte_ether/rte_ether_version.map          |   9 +-
 47 files changed, 392 insertions(+), 810 deletions(-)

-- 
1.9.1
#31 lore raw

PATCH v2 1/17 pci: no need for dynamic tailq init

These lists can be initialized once and for all at build time. With this, those lists are only manipulated in a common place (and we could even make them private).

A nice side effect is that pci drivers can now register in constructors.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c    | 3 ---
 lib/librte_eal/common/eal_common_pci.c | 6 ++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 3 ---
 3 files changed, 4 insertions(+), 8 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -3
index 2d16d78..cd8e8d3 100644
@@ -618,9 +618,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
lib/librte_eal/common/eal_common_pci.c +4 -2
index 40f4922..80d8ec6 100644
@@ -82,8 +82,10 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list;
-struct pci_device_list pci_device_list;
+struct pci_driver_list pci_driver_list =
+	TAILQ_HEAD_INITIALIZER(pci_driver_list);
+struct pci_device_list pci_device_list =
+	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
 static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 {
lib/librte_eal/linuxapp/eal/eal_pci.c +0 -3
index dbf12a8..3fc82b0 100644
@@ -731,9 +731,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
Signature · 1 line
1.9.1
#32 lore raw

PATCH v2 2/17 crypto: no need for a crypto pmd type

In reply to David Marchand

This information is not used and just adds noise.

---
 lib/librte_cryptodev/rte_cryptodev.c     | 8 +++-----
 lib/librte_cryptodev/rte_cryptodev.h     | 2 --
 lib/librte_cryptodev/rte_cryptodev_pmd.h | 3 +--
 3 files changed, 4 insertions(+), 9 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +3 -5
index aa4ea42..bf35df0 100644
@@ -230,7 +230,7 @@ rte_cryptodev_find_free_device_index(void)
 }
 
 struct rte_cryptodev *
-rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
+rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 {
 	struct rte_cryptodev *cryptodev;
 	uint8_t dev_id;
@@ -269,7 +269,6 @@ rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
 		cryptodev->data->dev_started = 0;
 
 		cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
-		cryptodev->pmd_type = type;
 
 		cryptodev_globals.nb_devs++;
 	}
@@ -318,7 +317,7 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	struct rte_cryptodev *cryptodev;
 
 	/* allocate device structure */
-	cryptodev = rte_cryptodev_pmd_allocate(name, PMD_VDEV, socket_id);
+	cryptodev = rte_cryptodev_pmd_allocate(name, socket_id);
 	if (cryptodev == NULL)
 		return NULL;
 
@@ -360,8 +359,7 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	rte_cryptodev_create_unique_device_name(cryptodev_name,
 			sizeof(cryptodev_name), pci_dev);
 
-	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, PMD_PDEV,
-			rte_socket_id());
+	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
 		return -ENOMEM;
 
lib/librte_cryptodev/rte_cryptodev.h +0 -2
index d47f1e8..2d0b809 100644
@@ -697,8 +697,6 @@ struct rte_cryptodev {
 
 	enum rte_cryptodev_type dev_type;
 	/**< Crypto device type */
-	enum pmd_type pmd_type;
-	/**< PMD type - PDEV / VDEV */
 
 	struct rte_cryptodev_cb_list link_intr_cbs;
 	/**< User application callback for interrupts if present */
lib/librte_cryptodev/rte_cryptodev_pmd.h +1 -2
index 7d049ea..c977c61 100644
@@ -454,13 +454,12 @@ struct rte_cryptodev_ops {
  * to that slot for the driver to use.
  *
  * @param	name		Unique identifier name for each device
- * @param	type		Device type of this Crypto device
  * @param	socket_id	Socket to allocate resources on.
  * @return
  *   - Slot in the rte_dev_devices array for a new device;
  */
 struct rte_cryptodev *
-rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id);
+rte_cryptodev_pmd_allocate(const char *name, int socket_id);
 
 /**
  * Creates a new virtual crypto device and returns the pointer
Signature · 1 line
1.9.1
#33 lore raw

PATCH v2 3/17 drivers: align pci driver definitions

In reply to David Marchand

Pure coding style, but it might make it easier later if we want to move fields in rte_cryptodev_driver and eth_driver structures.

---
 drivers/crypto/qat/rte_qat_cryptodev.c | 2 +-
 drivers/net/ena/ena_ethdev.c           | 2 +-
 drivers/net/nfp/nfp_net.c              | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +1 -1
index a7912f5..08496ab 100644
@@ -116,7 +116,7 @@ crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_
 }
 
 static struct rte_cryptodev_driver rte_qat_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
drivers/net/ena/ena_ethdev.c +1 -1
index 02af67a..fbc96ae 100644
@@ -1429,7 +1429,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 }
 
 static struct eth_driver rte_ena_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_ena_pmd",
 		.id_table = pci_id_ena_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
drivers/net/nfp/nfp_net.c +1 -1
index bcf5fa9..fb23b74 100644
@@ -2474,7 +2474,7 @@ static struct rte_pci_id pci_id_nfp_net_map[] = {
 };
 
 static struct eth_driver rte_nfp_net_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_nfp_net_pmd",
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
Signature · 1 line
1.9.1
#34 lore raw

PATCH v2 4/17 eal: remove duplicate function declaration

In reply to David Marchand

rte_eal_dev_init is declared in both eal_private.h and rte_dev.h since its introduction.
This function has been exported in ABI, so remove it from eal_private.h

Fixes e57f20e05177 ("eal: make vdev init path generic for both virtual and pci devices")
---
 lib/librte_eal/common/eal_private.h | 7 -------
 lib/librte_eal/linuxapp/eal/eal.c   | 1 +
 2 files changed, 1 insertion(+), 7 deletions(-)
lib/librte_eal/common/eal_private.h +0 -7
index 2342fa1..855fd25 100644
@@ -262,13 +262,6 @@ int rte_eal_intr_init(void);
 int rte_eal_alarm_init(void);
 
 /**
- * This function initialises any virtual devices
- *
- * This function is private to the EAL.
- */
-int rte_eal_dev_init(void);
-
-/**
  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
  * etc.) loaded.
  *
lib/librte_eal/linuxapp/eal/eal.c +1 -0
index 8aafd51..f26f8d3 100644
@@ -70,6 +70,7 @@
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
+#include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_common.h>
 #include <rte_version.h>
Signature · 1 line
1.9.1
#35 lore raw

PATCH v2 5/17 eal: introduce init macros

In reply to David Marchand

Introduce a RTE_INIT macro used to mark an init function as a constructor. Current eal macros have been converted to use this (no functional impact). RTE_EAL_PCI_REGISTER is added as a helper for pci drivers.

---
 lib/librte_eal/common/include/rte_dev.h   | 4 ++--
 lib/librte_eal/common/include/rte_eal.h   | 3 +++
 lib/librte_eal/common/include/rte_pci.h   | 7 +++++++
 lib/librte_eal/common/include/rte_tailq.h | 4 ++--
 4 files changed, 14 insertions(+), 4 deletions(-)
lib/librte_eal/common/include/rte_dev.h +2 -2
index f1b5507..85e48f2 100644
@@ -179,8 +179,8 @@ int rte_eal_vdev_init(const char *name, const char *args);
 int rte_eal_vdev_uninit(const char *name);
 
 #define PMD_REGISTER_DRIVER(d)\
-void devinitfn_ ##d(void);\
-void __attribute__((constructor, used)) devinitfn_ ##d(void)\
+RTE_INIT(devinitfn_ ##d);\
+static void devinitfn_ ##d(void)\
 {\
 	rte_eal_driver_register(&d);\
 }
lib/librte_eal/common/include/rte_eal.h +3 -0
index a71d6f5..186f3c6 100644
@@ -252,6 +252,9 @@ static inline int rte_gettid(void)
 	return RTE_PER_LCORE(_thread_id);
 }
 
+#define RTE_INIT(func) \
+static void __attribute__((constructor, used)) func(void)
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/rte_pci.h +7 -0
index e692094..f99b33a 100644
@@ -471,6 +471,13 @@ void rte_eal_pci_dump(FILE *f);
  */
 void rte_eal_pci_register(struct rte_pci_driver *driver);
 
+#define RTE_EAL_PCI_REGISTER(name, d) \
+RTE_INIT(pciinitfn_ ##name); \
+static void pciinitfn_ ##name(void) \
+{ \
+	rte_eal_pci_register(&d); \
+}
+
 /**
  * Unregister a PCI driver.
  *
lib/librte_eal/common/include/rte_tailq.h +2 -2
index 4a686e6..71ed3bb 100644
@@ -148,8 +148,8 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
 int rte_eal_tailq_register(struct rte_tailq_elem *t);
 
 #define EAL_REGISTER_TAILQ(t) \
-void tailqinitfn_ ##t(void); \
-void __attribute__((constructor, used)) tailqinitfn_ ##t(void) \
+RTE_INIT(tailqinitfn_ ##t); \
+static void tailqinitfn_ ##t(void) \
 { \
 	if (rte_eal_tailq_register(&t) < 0) \
 		rte_panic("Cannot initialize tailq: %s\n", t.name); \
Signature · 1 line
1.9.1
#37 lore raw

PATCH v2 6/17 crypto: export init/uninit common wrappers for pci drivers

In reply to David Marchand

Preparing for getting rid of rte_cryptodev_driver, here are two wrappers that can be used by pci drivers that assume a 1 to 1 association between pci resource and upper interface.

---
 lib/librte_cryptodev/rte_cryptodev.c           | 16 ++++++++--------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 12 ++++++++++++
 lib/librte_cryptodev/rte_cryptodev_version.map |  8 ++++++++
 3 files changed, 28 insertions(+), 8 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +8 -8
index bf35df0..19a9939 100644
@@ -340,9 +340,9 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	return cryptodev;
 }
 
-static int
-rte_cryptodev_init(struct rte_pci_driver *pci_drv,
-		struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			struct rte_pci_device *pci_dev)
 {
 	struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -401,8 +401,8 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	return -ENXIO;
 }
 
-static int
-rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -450,15 +450,15 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
 {
 	/* Call crypto device initialization directly if device is virtual */
 	if (type == PMD_VDEV)
-		return rte_cryptodev_init((struct rte_pci_driver *)cryptodrv,
+		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
 				NULL);
 
 	/*
 	 * Register PCI driver for physical device intialisation during
 	 * PCI probing
 	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_init;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_uninit;
+	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
+	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
 
 	rte_eal_pci_register(&cryptodrv->pci_drv);
 
lib/librte_cryptodev/rte_cryptodev_pmd.h +12 -0
index c977c61..3fb7c7c 100644
@@ -534,6 +534,18 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
 				enum rte_cryptodev_event_type event);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			    struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
 
 #ifdef __cplusplus
 }
lib/librte_cryptodev/rte_cryptodev_version.map +8 -0
index 41004e1..8d0edfb 100644
@@ -32,3 +32,11 @@ DPDK_16.04 {
 
 	local: *;
 };
+
+DPDK_16.07 {
+	global:
+
+	rte_cryptodev_pci_probe;
+	rte_cryptodev_pci_remove;
+
+} DPDK_16.04;
Signature · 1 line
1.9.1
#38 lore raw

PATCH v2 7/17 ethdev: export init/uninit common wrappers for pci drivers

In reply to David Marchand

Preparing for getting rid of eth_drv, here are two wrappers that can be used by pci drivers that assume a 1 to 1 association between pci resource and upper interface.

---
 lib/librte_ether/rte_ethdev.c          | 14 +++++++-------
 lib/librte_ether/rte_ethdev.h          | 13 +++++++++++++
 lib/librte_ether/rte_ether_version.map |  8 ++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
lib/librte_ether/rte_ethdev.c +7 -7
index a31018e..7b908a7 100644
@@ -239,9 +239,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 	return 0;
 }
 
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-		 struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+		      struct rte_pci_device *pci_dev)
 {
 	struct eth_driver    *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -293,8 +293,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	return diag;
 }
 
-static int
-rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct eth_driver *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -351,8 +351,8 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 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;
+	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
+	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
 
lib/librte_ether/rte_ethdev.h +13 -0
index 022733e..7a7a69e 100644
@@ -4279,6 +4279,19 @@ rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
 				  uint32_t mask,
 				  uint8_t en);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+			  struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_ether/rte_ether_version.map +8 -0
index 214ecc7..31017d4 100644
@@ -132,3 +132,11 @@ DPDK_16.04 {
 	rte_eth_tx_buffer_set_err_callback;
 
 } DPDK_2.2;
+
+DPDK_16.07 {
+	global:
+
+	rte_eth_dev_pci_probe;
+	rte_eth_dev_pci_remove;
+
+} DPDK_16.04;
Signature · 1 line
1.9.1
#39 lore raw

PATCH v2 8/17 drivers: convert all pdev drivers as pci drivers

In reply to David Marchand

Simplify crypto and ethdev pci drivers init by using newly introduced init macros and helpers.
Those drivers then don't need to register as "rte_driver"s anymore.

virtio and mlx* drivers use the general purpose RTE_INIT macro, as they both need some special stuff to be done before registering a pci driver.

---
 drivers/crypto/qat/rte_qat_cryptodev.c  | 16 +++--------
 drivers/net/bnx2x/bnx2x_ethdev.c        | 35 +++++-------------------
 drivers/net/cxgbe/cxgbe_ethdev.c        | 24 +++--------------
 drivers/net/e1000/em_ethdev.c           | 16 +++--------
 drivers/net/e1000/igb_ethdev.c          | 40 +++++-----------------------
 drivers/net/ena/ena_ethdev.c            | 18 +++----------
 drivers/net/enic/enic_ethdev.c          | 23 +++-------------
 drivers/net/fm10k/fm10k_ethdev.c        | 23 +++-------------
 drivers/net/i40e/i40e_ethdev.c          | 26 +++---------------
 drivers/net/i40e/i40e_ethdev_vf.c       | 25 +++---------------
 drivers/net/ixgbe/ixgbe_ethdev.c        | 47 +++++----------------------------
 drivers/net/mlx4/mlx4.c                 | 20 +++-----------
 drivers/net/mlx5/mlx5.c                 | 19 +++----------
 drivers/net/nfp/nfp_net.c               | 21 +++------------
 drivers/net/szedata2/rte_eth_szedata2.c | 25 +++---------------
 drivers/net/virtio/virtio_ethdev.c      | 26 +++++-------------
 drivers/net/vmxnet3/vmxnet3_ethdev.c    | 23 +++-------------
 17 files changed, 68 insertions(+), 359 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +3 -13
index 08496ab..54f0c95 100644
@@ -120,21 +120,11 @@ static struct rte_cryptodev_driver rte_qat_pmd = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_cryptodev_pci_probe,
+		.devuninit = rte_cryptodev_pci_remove,
 	},
 	.cryptodev_init = crypto_qat_dev_init,
 	.dev_private_size = sizeof(struct qat_pmd_private),
 };
 
-static int
-rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
-}
-
-static struct rte_driver pmd_qat_drv = {
-	.type = PMD_PDEV,
-	.init = rte_qat_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(pmd_qat_drv);
+RTE_EAL_PCI_REGISTER(qat, rte_qat_pmd.pci_drv);
drivers/net/bnx2x/bnx2x_ethdev.c +7 -28
index 071b44f..ba194b5 100644
@@ -506,11 +506,15 @@ static struct eth_driver rte_bnx2x_pmd = {
 		.name = "rte_bnx2x_pmd",
 		.id_table = pci_id_bnx2x_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2x_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
+RTE_EAL_PCI_REGISTER(bnx2x, rte_bnx2x_pmd.pci_drv);
+
 /*
  * virtual function driver struct
  */
@@ -519,36 +523,11 @@ static struct eth_driver rte_bnx2xvf_pmd = {
 		.name = "rte_bnx2xvf_pmd",
 		.id_table = pci_id_bnx2xvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2xvf_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
-static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2x_pmd);
-
-	return 0;
-}
-
-static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2xvf_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_bnx2x_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2x_pmd_init,
-};
-
-static struct rte_driver rte_bnx2xvf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2xvf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_bnx2x_driver);
-PMD_REGISTER_DRIVER(rte_bnx2xvf_driver);
+RTE_EAL_PCI_REGISTER(bnx2xvf, rte_bnx2xvf_pmd.pci_drv);
drivers/net/cxgbe/cxgbe_ethdev.c +3 -21
index bb134e5..72b1a7b 100644
@@ -870,29 +870,11 @@ static struct eth_driver rte_cxgbe_pmd = {
 		.name = "rte_cxgbe_pmd",
 		.id_table = cxgb4_pci_tbl,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_cxgbe_dev_init,
 	.dev_private_size = sizeof(struct port_info),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI CXGBE devices.
- */
-static int rte_cxgbe_pmd_init(const char *name __rte_unused,
-			      const char *params __rte_unused)
-{
-	CXGBE_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_cxgbe_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_cxgbe_driver = {
-	.name = "cxgbe_driver",
-	.type = PMD_PDEV,
-	.init = rte_cxgbe_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_cxgbe_driver);
+RTE_EAL_PCI_REGISTER(cxgbe, rte_cxgbe_pmd.pci_drv);
drivers/net/e1000/em_ethdev.c +3 -13
index 653be09..1f80c05 100644
@@ -368,18 +368,15 @@ static struct eth_driver rte_em_pmd = {
 		.id_table = pci_id_em_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_em_dev_init,
 	.eth_dev_uninit = eth_em_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_em_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_em_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(em, rte_em_pmd.pci_drv);
 
 static int
 em_hw_init(struct e1000_hw *hw)
@@ -1771,10 +1768,3 @@ eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
 	e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
 	return 0;
 }
-
-struct rte_driver em_pmd_drv = {
-	.type = PMD_PDEV,
-	.init = rte_em_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(em_pmd_drv);
drivers/net/e1000/igb_ethdev.c +7 -33
index e0053fe..9b5f985 100644
@@ -975,12 +975,16 @@ static struct eth_driver rte_igb_pmd = {
 		.id_table = pci_id_igb_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igb_dev_init,
 	.eth_dev_uninit = eth_igb_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
+RTE_EAL_PCI_REGISTER(igb, rte_igb_pmd.pci_drv);
+
 /*
  * virtual function driver struct
  */
@@ -989,18 +993,15 @@ static struct eth_driver rte_igbvf_pmd = {
 		.name = "rte_igbvf_pmd",
 		.id_table = pci_id_igbvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igbvf_dev_init,
 	.eth_dev_uninit = eth_igbvf_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_igb_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(igbvf, rte_igbvf_pmd.pci_drv);
 
 static void
 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
@@ -1013,20 +1014,6 @@ igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
 }
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
- */
-static int
-rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_igbvf_pmd);
-	return 0;
-}
-
 static int
 igb_check_mq_mode(struct rte_eth_dev *dev)
 {
@@ -4807,16 +4794,6 @@ eth_igb_set_eeprom(struct rte_eth_dev *dev,
 	return nvm->ops.write(hw,  first, length, data);
 }
 
-static struct rte_driver pmd_igb_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igb_pmd_init,
-};
-
-static struct rte_driver pmd_igbvf_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igbvf_pmd_init,
-};
-
 static int
 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
@@ -4977,6 +4954,3 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 
 	E1000_WRITE_FLUSH(hw);
 }
-
-PMD_REGISTER_DRIVER(pmd_igb_drv);
-PMD_REGISTER_DRIVER(pmd_igbvf_drv);
drivers/net/ena/ena_ethdev.c +3 -15
index fbc96ae..2b60a67 100644
@@ -1433,23 +1433,11 @@ static struct eth_driver rte_ena_pmd = {
 		.name = "rte_ena_pmd",
 		.id_table = pci_id_ena_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_ena_dev_init,
 	.dev_private_size = sizeof(struct ena_adapter),
 };
 
-static int
-rte_ena_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_ena_pmd);
-	return 0;
-};
-
-struct rte_driver ena_pmd_drv = {
-	.name = "ena_driver",
-	.type = PMD_PDEV,
-	.init = rte_ena_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(ena_pmd_drv);
+RTE_EAL_PCI_REGISTER(ena, rte_ena_pmd.pci_drv);
drivers/net/enic/enic_ethdev.c +3 -20
index 6bea940..7539811 100644
@@ -660,28 +660,11 @@ static struct eth_driver rte_enic_pmd = {
 		.name = "rte_enic_pmd",
 		.id_table = pci_id_enic_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_enicpmd_dev_init,
 	.dev_private_size = sizeof(struct enic),
 };
 
-/* Driver initialization routine.
- * Invoked once at EAL init time.
- * Register as the [Poll Mode] Driver of Cisco ENIC device.
- */
-static int
-rte_enic_pmd_init(__rte_unused const char *name,
-	 __rte_unused const char *params)
-{
-	ENICPMD_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_enic_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_enic_driver = {
-	.type = PMD_PDEV,
-	.init = rte_enic_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_enic_driver);
+RTE_EAL_PCI_REGISTER(enic, rte_enic_pmd.pci_drv);
drivers/net/fm10k/fm10k_ethdev.c +3 -20
index c2d377f..146bc2a 100644
@@ -3030,29 +3030,12 @@ static struct eth_driver rte_pmd_fm10k = {
 		.id_table = pci_id_fm10k_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_fm10k_dev_init,
 	.eth_dev_uninit = eth_fm10k_dev_uninit,
 	.dev_private_size = sizeof(struct fm10k_adapter),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI FM10K devices.
- */
-static int
-rte_pmd_fm10k_init(__rte_unused const char *name,
-	__rte_unused const char *params)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_pmd_fm10k);
-	return 0;
-}
-
-static struct rte_driver rte_fm10k_driver = {
-	.type = PMD_PDEV,
-	.init = rte_pmd_fm10k_init,
-};
-
-PMD_REGISTER_DRIVER(rte_fm10k_driver);
+RTE_EAL_PCI_REGISTER(fm10k, rte_pmd_fm10k.pci_drv);
drivers/net/i40e/i40e_ethdev.c +4 -22
index bc28d3c..4e87399 100644
@@ -641,12 +641,16 @@ static struct eth_driver rte_i40e_pmd = {
 		.id_table = pci_id_i40e_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_i40e_dev_init,
 	.eth_dev_uninit = eth_i40e_dev_uninit,
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
+RTE_EAL_PCI_REGISTER(i40e, rte_i40e_pmd.pci_drv);
+
 static inline int
 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
 				     struct rte_eth_link *link)
@@ -676,28 +680,6 @@ rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
 }
 
 /*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
- */
-static int
-rte_i40e_pmd_init(const char *name __rte_unused,
-		  const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_i40e_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_i40e_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40e_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40e_driver);
-
-/*
  * Initialize registers for flexible payload, which should be set by NVM.
  * This should be removed from code once it is fixed in NVM.
  */
drivers/net/i40e/i40e_ethdev_vf.c +3 -22
index 2bce69b..1e41b3a 100644
@@ -1533,34 +1533,15 @@ static struct eth_driver rte_i40evf_pmd = {
 		.name = "rte_i40evf_pmd",
 		.id_table = pci_id_i40evf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = i40evf_dev_init,
 	.eth_dev_uninit = i40evf_dev_uninit,
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
- */
-static int
-rte_i40evf_pmd_init(const char *name __rte_unused,
-		    const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_i40evf_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_i40evf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40evf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40evf_driver);
+RTE_EAL_PCI_REGISTER(i40evf, rte_i40evf_pmd.pci_drv);
 
 static int
 i40evf_dev_configure(struct rte_eth_dev *dev)
drivers/net/ixgbe/ixgbe_ethdev.c +7 -40

74 lines not on this page · raw message

drivers/net/mlx4/mlx4.c +3 -17
index 4f21dbe..8e4b0cc 100644
@@ -5789,15 +5789,10 @@ static struct eth_driver mlx4_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx4_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx4_pmd_init);
+static void
+rte_mlx4_pmd_init(void)
 {
-	(void)name;
-	(void)args;
-
 	RTE_BUILD_BUG_ON(sizeof(wr_id_t) != sizeof(uint64_t));
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
@@ -5808,13 +5803,4 @@ rte_mlx4_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx4_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx4_driver = {
-	.type = PMD_PDEV,
-	.name = MLX4_DRIVER_NAME,
-	.init = rte_mlx4_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx4_driver)
drivers/net/mlx5/mlx5.c +3 -16
index 041cfc3..1989a37 100644
@@ -646,14 +646,10 @@ static struct eth_driver mlx5_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx5_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx5_pmd_init);
+static void
+rte_mlx5_pmd_init(void)
 {
-	(void)name;
-	(void)args;
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
 	 * huge pages. Calling ibv_fork_init() during init allows
@@ -663,13 +659,4 @@ rte_mlx5_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx5_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx5_driver = {
-	.type = PMD_PDEV,
-	.name = MLX5_DRIVER_NAME,
-	.init = rte_mlx5_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx5_driver)
drivers/net/nfp/nfp_net.c +3 -18
index fb23b74..baa840e 100644
@@ -2478,29 +2478,14 @@ static struct eth_driver rte_nfp_net_pmd = {
 		.name = "rte_nfp_net_pmd",
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = nfp_net_init,
 	.dev_private_size = sizeof(struct nfp_net_adapter),
 };
 
-static int
-nfp_net_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	PMD_INIT_LOG(INFO, "librte_pmd_nfp_net version %s\n",
-		     NFP_NET_PMD_VERSION);
-
-	rte_eth_driver_register(&rte_nfp_net_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_nfp_net_driver = {
-	.type = PMD_PDEV,
-	.init = nfp_net_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_nfp_net_driver);
+RTE_EAL_PCI_REGISTER(nfp_net, rte_nfp_net_pmd.pci_drv);
 
 /*
  * Local variables:
drivers/net/szedata2/rte_eth_szedata2.c +3 -22
index 78c43b0..acada05 100644
@@ -1574,31 +1574,12 @@ static struct eth_driver szedata2_eth_driver = {
 	.pci_drv = {
 		.name     = RTE_SZEDATA2_PCI_DRIVER_NAME,
 		.id_table = rte_szedata2_pci_id_table,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init     = rte_szedata2_eth_dev_init,
 	.eth_dev_uninit   = rte_szedata2_eth_dev_uninit,
 	.dev_private_size = sizeof(struct pmd_internals),
 };
 
-static int
-rte_szedata2_init(const char *name __rte_unused,
-		const char *args __rte_unused)
-{
-	rte_eth_driver_register(&szedata2_eth_driver);
-	return 0;
-}
-
-static int
-rte_szedata2_uninit(const char *name __rte_unused)
-{
-	return 0;
-}
-
-static struct rte_driver rte_szedata2_driver = {
-	.type = PMD_PDEV,
-	.name = RTE_SZEDATA2_DRIVER_NAME,
-	.init = rte_szedata2_init,
-	.uninit = rte_szedata2_uninit,
-};
-
-PMD_REGISTER_DRIVER(rte_szedata2_driver);
+RTE_EAL_PCI_REGISTER(szedata2, szedata2_eth_driver.pci_drv);
drivers/net/virtio/virtio_ethdev.c +7 -19
index 63a368a..f8cc158 100644
@@ -1206,29 +1206,24 @@ static struct eth_driver rte_virtio_pmd = {
 		.name = "rte_virtio_pmd",
 		.id_table = pci_id_virtio_map,
 		.drv_flags = RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_virtio_dev_init,
 	.eth_dev_uninit = eth_virtio_dev_uninit,
 	.dev_private_size = sizeof(struct virtio_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI virtio devices.
- * Returns 0 on success.
- */
-static int
-rte_virtio_pmd_init(const char *name __rte_unused,
-		    const char *param __rte_unused)
+RTE_INIT(rte_virtio_pmd_init);
+static void
+rte_virtio_pmd_init(void)
 {
 	if (rte_eal_iopl_init() != 0) {
 		PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
-		return -1;
+		return;
 	}
 
-	rte_eth_driver_register(&rte_virtio_pmd);
-	return 0;
+	rte_eal_pci_register(&rte_virtio_pmd.pci_drv);
 }
 
 /*
@@ -1452,10 +1447,3 @@ __rte_unused uint8_t is_rx)
 {
 	return 0;
 }
-
-static struct rte_driver rte_virtio_driver = {
-	.type = PMD_PDEV,
-	.init = rte_virtio_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_virtio_driver);
drivers/net/vmxnet3/vmxnet3_ethdev.c +3 -20
index bd7a2bb..375e681 100644
@@ -332,25 +332,15 @@ static struct eth_driver rte_vmxnet3_pmd = {
 		.name = "rte_vmxnet3_pmd",
 		.id_table = pci_id_vmxnet3_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_vmxnet3_dev_init,
 	.eth_dev_uninit = eth_vmxnet3_dev_uninit,
 	.dev_private_size = sizeof(struct vmxnet3_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of Virtual PCI VMXNET3 devices.
- */
-static int
-rte_vmxnet3_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_vmxnet3_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(vmxnet3, rte_vmxnet3_pmd.pci_drv);
 
 static int
 vmxnet3_dev_configure(struct rte_eth_dev *dev)
@@ -949,10 +939,3 @@ vmxnet3_process_events(struct vmxnet3_hw *hw)
 
 }
 #endif
-
-static struct rte_driver rte_vmxnet3_driver = {
-	.type = PMD_PDEV,
-	.init = rte_vmxnet3_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_vmxnet3_driver);
Signature · 1 line
1.9.1
#40 lore raw

PATCH v2 9/17 crypto: get rid of crypto driver register callback

In reply to David Marchand

Now that all pdev are pci drivers, we don't need to register crypto drivers through a dedicated channel.

---
 lib/librte_cryptodev/rte_cryptodev.c           | 22 -------------------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 30 --------------------------
 lib/librte_cryptodev/rte_cryptodev_version.map |  1 -
 3 files changed, 53 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +0 -22
index 19a9939..d9648a2 100644
@@ -444,28 +444,6 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-int
-rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
-		enum pmd_type type)
-{
-	/* Call crypto device initialization directly if device is virtual */
-	if (type == PMD_VDEV)
-		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
-				NULL);
-
-	/*
-	 * Register PCI driver for physical device intialisation during
-	 * PCI probing
-	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
-
-	rte_eal_pci_register(&cryptodrv->pci_drv);
-
-	return 0;
-}
-
-
 uint16_t
 rte_cryptodev_queue_pair_count(uint8_t dev_id)
 {
lib/librte_cryptodev/rte_cryptodev_pmd.h +0 -30
index 3fb7c7c..99fd69e 100644
@@ -491,36 +491,6 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 extern int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 
-
-/**
- * Register a Crypto [Poll Mode] driver.
- *
- * Function invoked by the initialization function of a Crypto driver
- * to simultaneously register itself as Crypto Poll Mode Driver and to either:
- *
- *	a - register itself as PCI driver if the crypto device is a physical
- *		device, by invoking the rte_eal_pci_register() function to
- *		register the *pci_drv* structure embedded in the *crypto_drv*
- *		structure, after having stored the address of the
- *		rte_cryptodev_init() function in the *devinit* field of the
- *		*pci_drv* structure.
- *
- *		During the PCI probing phase, the rte_cryptodev_init()
- *		function is invoked for each PCI [device] matching the
- *		embedded PCI identifiers provided by the driver.
- *
- *	b, complete the initialization sequence if the device is a virtual
- *		device by calling the rte_cryptodev_init() directly passing a
- *		NULL parameter for the rte_pci_device structure.
- *
- *   @param crypto_drv	crypto_driver structure associated with the crypto
- *					driver.
- *   @param type		pmd type
- */
-extern int
-rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
-		enum pmd_type type);
-
 /**
  * Executes all the user application registered callbacks for the specific
  * device.
lib/librte_cryptodev/rte_cryptodev_version.map +0 -1
index 8d0edfb..e0a9620 100644
@@ -14,7 +14,6 @@ DPDK_16.04 {
 	rte_cryptodev_info_get;
 	rte_cryptodev_pmd_allocate;
 	rte_cryptodev_pmd_callback_process;
-	rte_cryptodev_pmd_driver_register;
 	rte_cryptodev_pmd_release_device;
 	rte_cryptodev_pmd_virtual_dev_init;
 	rte_cryptodev_sym_session_create;
Signature · 1 line
1.9.1
#41 lore raw

PATCH v2 10/17 ethdev: get rid of eth driver register callback

In reply to David Marchand

Now that all pdev are pci drivers, we don't need to register ethdev drivers through a dedicated channel.

---
 lib/librte_ether/rte_ethdev.c          | 22 ----------------------
 lib/librte_ether/rte_ethdev.h          | 12 ------------
 lib/librte_ether/rte_ether_version.map |  1 -
 3 files changed, 35 deletions(-)
lib/librte_ether/rte_ethdev.c +0 -22
index 7b908a7..7ec8cdb 100644
@@ -334,28 +334,6 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-/**
- * Register an Ethernet [Poll Mode] driver.
- *
- * Function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver.
- * Invokes the rte_eal_pci_register() function to register the *pci_drv*
- * structure embedded in the *eth_drv* structure, after having stored the
- * address of the rte_eth_dev_init() function in the *devinit* field of
- * the *pci_drv* structure.
- * During the PCI probing phase, the rte_eth_dev_init() function is
- * invoked for each PCI [Ethernet device] matching the embedded PCI
- * identifiers provided by the driver.
- */
-void
-rte_eth_driver_register(struct eth_driver *eth_drv)
-{
-	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
-	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
-	rte_eal_pci_register(&eth_drv->pci_drv);
-}
-
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
lib/librte_ether/rte_ethdev.h +0 -12
index 7a7a69e..016ce33 100644
@@ -1868,18 +1868,6 @@ struct eth_driver {
 };
 
 /**
- * @internal
- * A function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver (PMD).
- *
- * @param eth_drv
- *   The pointer to the *eth_driver* structure associated with
- *   the Ethernet driver.
- */
-void rte_eth_driver_register(struct eth_driver *eth_drv);
-
-/**
  * Convert a numerical speed in Mbps to a bitmap flag that can be used in
  * the bitmap link_speeds of the struct rte_eth_conf
  *
lib/librte_ether/rte_ether_version.map +0 -1
index 31017d4..d457b21 100644
@@ -80,7 +80,6 @@ DPDK_2.2 {
 	rte_eth_dev_vlan_filter;
 	rte_eth_dev_wd_timeout_store;
 	rte_eth_dma_zone_reserve;
-	rte_eth_driver_register;
 	rte_eth_led_off;
 	rte_eth_led_on;
 	rte_eth_link;
Signature · 1 line
1.9.1
#42 lore raw

PATCH v2 11/17 eal/linux: move back interrupt thread init before setting affinity

In reply to David Marchand

Now that virtio pci driver is initialized in a constructor, iopl() stuff happens early enough so that interrupt thread can be created right after plugin loading.
This way, chelsio driver should be happy again [1].

[1] http://dpdk.org/ml/archives/dev/2015-November/028289.html

---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal.c +3 -3
index f26f8d3..4b28197 100644
@@ -825,6 +825,9 @@ rte_eal_init(int argc, char **argv)
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
+	if (rte_eal_intr_init() < 0)
+		rte_panic("Cannot init interrupt-handling thread\n");
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
@@ -836,9 +839,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-	if (rte_eal_intr_init() < 0)
-		rte_panic("Cannot init interrupt-handling thread\n");
-
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
 		/*
Signature · 1 line
1.9.1
#43 lore raw

PATCH v2 12/17 pci: add a helper for device name

In reply to David Marchand

eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev.

---
 lib/librte_cryptodev/rte_cryptodev.c    | 27 ++++-----------------------
 lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 24 ++++--------------------
 3 files changed, 33 insertions(+), 43 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +4 -23
index d9648a2..6f4d1c4 100644
@@ -276,23 +276,6 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 	return cryptodev;
 }
 
-static inline int
-rte_cryptodev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	if ((name == NULL) || (pci_dev == NULL))
-		return -EINVAL;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
 {
@@ -355,9 +338,8 @@ rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
 	if (cryptodrv == NULL)
 		return -ENODEV;
 
-	/* Create unique Crypto device name using PCI address */
-	rte_cryptodev_create_unique_device_name(cryptodev_name,
-			sizeof(cryptodev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+			sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
@@ -412,9 +394,8 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique device name using PCI address */
-	rte_cryptodev_create_unique_device_name(cryptodev_name,
-			sizeof(cryptodev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+			sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
 	if (cryptodev == NULL)
lib/librte_eal/common/include/rte_pci.h +25 -0
index f99b33a..3bb1833 100644
@@ -82,6 +82,7 @@ extern "C" {
 #include <stdint.h>
 #include <inttypes.h>
 
+#include <rte_debug.h>
 #include <rte_interrupts.h>
 
 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
@@ -95,6 +96,7 @@ extern struct pci_device_list pci_device_list; /**< Global list of PCI devices.
 
 /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
 #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
+#define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X")
 
 /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
@@ -309,6 +311,29 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using above functions.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address
+ * @param output
+ *	The output buffer string
+ * @param size
+ *	The output buffer size
+ * @return
+ *  0 on success, negative on error.
+ */
+static inline void
+rte_eal_pci_device_name(const struct rte_pci_addr *addr,
+		    char *output, size_t size)
+{
+	RTE_VERIFY(size >= PCI_PRI_STR_SIZE);
+	RTE_VERIFY(snprintf(output, size, PCI_PRI_FMT,
+			    addr->domain, addr->bus,
+			    addr->devid, addr->function) >= 0);
+}
+
 /* Compare two PCI device addresses. */
 /**
  * Utility function to compare two PCI device addresses.
lib/librte_ether/rte_ethdev.c +4 -20
index 7ec8cdb..9d5827b 100644
@@ -214,20 +214,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	return eth_dev;
 }
 
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -251,9 +237,8 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 
 	eth_drv = (struct eth_driver *)pci_drv;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+			sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
 	if (eth_dev == NULL)
@@ -304,9 +289,8 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+			sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocated(ethdev_name);
 	if (eth_dev == NULL)
Signature · 1 line
1.9.1
#47 lore raw

PATCH v2 13/17 pci: add a helper to update a device

In reply to David Marchand

This helper updates a pci device object with latest information it can find.
It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c   | 49 +++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h   | 13 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++++++++
 3 files changed, 75 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +49 -0
index cd8e8d3..85e49f6 100644
@@ -401,6 +401,55 @@ error:
 	return -1;
 }
 
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+	int fd;
+	struct pci_conf matches[2];
+	struct pci_match_conf match = {
+		.pc_sel = {
+			.pc_domain = addr->domain,
+			.pc_bus = addr->bus,
+			.pc_dev = addr->devid,
+			.pc_func = addr->function,
+		},
+	};
+	struct pci_conf_io conf_io = {
+		.pat_buf_len = 0,
+		.num_patterns = 1,
+		.patterns = &match,
+		.match_buf_len = sizeof(matches),
+		.matches = &matches[0],
+	};
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+				__func__, strerror(errno));
+		goto error;
+	}
+
+	if (conf_io.num_matches != 1)
+		goto error;
+
+	if (pci_scan_one(fd, &matches[0]) < 0)
+		goto error;
+
+	close(fd);
+
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
 			    void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_private.h +13 -0
index 855fd25..81816a6 100644
@@ -155,6 +155,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Update a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.
+ */
+int pci_update_device(const struct rte_pci_addr *addr);
+
+/**
  * Unbind kernel driver for this device
  *
  * This function is private to EAL.
lib/librte_eal/linuxapp/eal/eal_pci.c +13 -0
index 3fc82b0..61ac21f 100644
@@ -393,6 +393,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 	return 0;
 }
 
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+	char filename[PATH_MAX];
+
+	snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
+		 SYSFS_PCI_DEVICES, addr->domain, addr->bus, addr->devid,
+		 addr->function);
+
+	return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
+			    addr->function);
+}
+
 /*
  * split up a pci address into its constituent parts.
  */
Signature · 1 line
1.9.1
#48 lore raw

PATCH v2 14/17 ethdev: do not scan all pci devices on attach

In reply to David Marchand

No need to scan all devices, we only need to update the device being attached.

---
 lib/librte_eal/common/eal_common_pci.c | 11 ++++++++---
 lib/librte_ether/rte_ethdev.c          |  3 ---
 2 files changed, 8 insertions(+), 6 deletions(-)
lib/librte_eal/common/eal_common_pci.c +8 -3
index 80d8ec6..d63b47b 100644
@@ -325,6 +325,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
+	/* update current pci device in global list, kernel bindings might have
+	 * changed since last time we looked at it */
+	if (pci_update_device(addr) < 0)
+		goto err_return;
+
 	TAILQ_FOREACH(dev, &pci_device_list, next) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
@@ -337,9 +342,9 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	return -1;
 
 err_return:
-	RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
-			" cannot be used\n", dev->addr.domain, dev->addr.bus,
-			dev->addr.devid, dev->addr.function);
+	RTE_LOG(WARNING, EAL,
+		"Requested device " PCI_PRI_FMT " cannot be used\n",
+		addr->domain, addr->bus, addr->devid, addr->function);
 	return -1;
 }
 
lib/librte_ether/rte_ethdev.c +0 -3
index 9d5827b..6cd6455 100644
@@ -468,9 +468,6 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 static int
 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
 {
-	/* re-construct pci_device_list */
-	if (rte_eal_pci_scan())
-		goto err;
 	/* Invoke probe func of the driver can handle the new device. */
 	if (rte_eal_pci_probe_one(addr))
 		goto err;
Signature · 1 line
1.9.1
#49 lore raw

PATCH v2 15/17 eal: add hotplug operations for pci and vdev

In reply to David Marchand

hotplug which deals with resources should come from the layer that already handles them, i.e. eal.

For both attach and detach operations, 'name' is used to select the bus that will handle the request.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 25 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++++
 4 files changed, 80 insertions(+)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +8 -0
index 58c2951..4d075df 100644
@@ -151,3 +151,11 @@ DPDK_16.04 {
 	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
+
+DPDK_16.07 {
+	global:
+
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
+
+} DPDK_16.04;
lib/librte_eal/common/eal_common_dev.c +39 -0
index a8a4146..59ed3a0 100644
@@ -150,3 +150,42 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+int rte_eal_dev_attach(const char *name, const char *devargs)
+{
+	struct rte_pci_addr addr;
+	int ret = -1;
+
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_probe_one(&addr) < 0)
+			goto err;
+
+	} else {
+		if (rte_eal_vdev_init(name, devargs))
+			goto err;
+	}
+
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	return ret;
+}
+
+int rte_eal_dev_detach(const char *name)
+{
+	struct rte_pci_addr addr;
+
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_detach(&addr) < 0)
+			goto err;
+	} else {
+		if (rte_eal_vdev_uninit(name))
+			goto err;
+	}
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
+	return -1;
+}
lib/librte_eal/common/include/rte_dev.h +25 -0
index 85e48f2..b1c0520 100644
@@ -178,6 +178,31 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * Attach a resource to a registered driver.
+ *
+ * @param name
+ *   The resource name, that refers to a pci resource or some private
+ *   way of designating a resource for vdev drivers. Based on this
+ *   resource name, eal will identify a driver capable of handling
+ *   this resource and pass this resource to the driver probing
+ *   function.
+ * @param devargs
+ *   Device arguments to be passed to the driver.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_attach(const char *name, const char *devargs);
+
+/**
+ * Detach a resource from its driver.
+ *
+ * @param name
+ *   Same description as for rte_eal_dev_attach().
+ *   Here, eal will call the driver detaching function.
+ */
+int rte_eal_dev_detach(const char *name);
+
 #define PMD_REGISTER_DRIVER(d)\
 RTE_INIT(devinitfn_ ##d);\
 static void devinitfn_ ##d(void)\
lib/librte_eal/linuxapp/eal/rte_eal_version.map +8 -0
index 12503ef..0404a52 100644
@@ -154,3 +154,11 @@ DPDK_16.04 {
 	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
+
+DPDK_16.07 {
+	global:
+
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
+
+} DPDK_16.04;
Signature · 1 line
1.9.1
#51 lore raw

PATCH v2 16/17 ethdev: convert to eal hotplug

In reply to David Marchand

Remove bus logic from ethdev hotplug by using eal for this.

Current api is preserved:
- the last port that has been created is tracked to return it to the application when attaching,
- the internal device name is reused when detaching.

We can not get rid of ethdev hotplug yet since we still need some mechanism to inform applications of port creation/removal to substitute for ethdev hotplug api.

dev_type field in struct rte_eth_dev and rte_eth_dev_allocate are kept as is, but this information is not needed anymore and is removed in the following commit.

---
 lib/librte_ether/rte_ethdev.c | 252 ++++++------------------------------------
 1 file changed, 33 insertions(+), 219 deletions(-)
lib/librte_ether/rte_ethdev.c +33 -219
index 6cd6455..1794025 100644
@@ -72,6 +72,7 @@
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
 static struct rte_eth_dev_data *rte_eth_dev_data;
+static uint8_t eth_dev_last_created_port;
 static uint8_t nb_ports;
 
 /* spinlock for eth device callbacks */
@@ -210,6 +211,7 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	eth_dev->data->port_id = port_id;
 	eth_dev->attached = DEV_ATTACHED;
 	eth_dev->dev_type = type;
+	eth_dev_last_created_port = port_id;
 	nb_ports++;
 	return eth_dev;
 }
@@ -342,100 +344,6 @@ rte_eth_dev_count(void)
 	return nb_ports;
 }
 
-static enum rte_eth_dev_type
-rte_eth_dev_get_device_type(uint8_t port_id)
-{
-	if (!rte_eth_dev_is_valid_port(port_id))
-		return RTE_ETH_DEV_UNKNOWN;
-	return rte_eth_devices[port_id].dev_type;
-}
-
-static int
-rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
-{
-	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
-
-	if (addr == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	*addr = rte_eth_devices[port_id].pci_dev->addr;
-	return 0;
-}
-
-static int
-rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
-{
-	char *tmp;
-
-	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
-
-	if (name == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	/* shouldn't check 'rte_eth_devices[i].data',
-	 * because it might be overwritten by VDEV PMD */
-	tmp = rte_eth_dev_data[port_id].name;
-	strcpy(name, tmp);
-	return 0;
-}
-
-static int
-rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
-{
-	int i;
-
-	if (name == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	*port_id = RTE_MAX_ETHPORTS;
-
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-
-		if (!strncmp(name,
-			rte_eth_dev_data[i].name, strlen(name))) {
-
-			*port_id = i;
-
-			return 0;
-		}
-	}
-	return -ENODEV;
-}
-
-static int
-rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
-{
-	int i;
-	struct rte_pci_device *pci_dev = NULL;
-
-	if (addr == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	*port_id = RTE_MAX_ETHPORTS;
-
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-
-		pci_dev = rte_eth_devices[i].pci_dev;
-
-		if (pci_dev &&
-			!rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
-
-			*port_id = i;
-
-			return 0;
-		}
-	}
-	return -ENODEV;
-}
-
 static int
 rte_eth_dev_is_detachable(uint8_t port_id)
 {
@@ -464,124 +372,45 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		return 1;
 }
 
-/* attach the new physical device, then store port_id of the device */
-static int
-rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
-{
-	/* Invoke probe func of the driver can handle the new device. */
-	if (rte_eal_pci_probe_one(addr))
-		goto err;
-
-	if (rte_eth_dev_get_port_by_addr(addr, port_id))
-		goto err;
-
-	return 0;
-err:
-	return -1;
-}
-
-/* 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)
-{
-	struct rte_pci_addr freed_addr;
-	struct rte_pci_addr vp;
-
-	/* get pci address by port id */
-	if (rte_eth_dev_get_addr_by_port(port_id, &freed_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)
-		goto err;
-
-	/* invoke devuninit func of the pci driver,
-	 * also remove the device from pci_device_list */
-	if (rte_eal_pci_detach(&freed_addr))
-		goto err;
-
-	*addr = freed_addr;
-	return 0;
-err:
-	return -1;
-}
-
-/* attach the new virtual device, then store port_id of the device */
-static int
-rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
-{
-	char *name = NULL, *args = NULL;
-	int ret = -1;
-
-	/* parse vdevargs, then retrieve device name and args */
-	if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
-		goto end;
-
-	/* walk around dev_driver_list to find the driver of the device,
-	 * then invoke probe function of the driver.
-	 * rte_eal_vdev_init() updates port_id allocated after
-	 * initialization.
-	 */
-	if (rte_eal_vdev_init(name, args))
-		goto end;
-
-	if (rte_eth_dev_get_port_by_name(name, port_id))
-		goto end;
-
-	ret = 0;
-end:
-	free(name);
-	free(args);
-
-	return ret;
-}
-
-/* detach the new virtual device, then store the name of the device */
-static int
-rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
-{
-	char name[RTE_ETH_NAME_MAX_LEN];
-
-	/* get device name by port id */
-	if (rte_eth_dev_get_name_by_port(port_id, name))
-		goto err;
-	/* walk around dev_driver_list to find the driver of the device,
-	 * then invoke uninit function of the driver */
-	if (rte_eal_vdev_uninit(name))
-		goto err;
-
-	strncpy(vdevname, name, sizeof(name));
-	return 0;
-err:
-	return -1;
-}
-
 /* attach the new device, then store port_id of the device */
 int
 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
-	struct rte_pci_addr addr;
 	int ret = -1;
+	int current = eth_dev_last_created_port;
+	char *name = NULL;
+	char *args = NULL;
 
 	if ((devargs == NULL) || (port_id == NULL)) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
-		ret = rte_eth_dev_attach_pdev(&addr, port_id);
-		if (ret < 0)
-			goto err;
-	} else {
-		ret = rte_eth_dev_attach_vdev(devargs, port_id);
-		if (ret < 0)
-			goto err;
+	/* parse devargs, then retrieve device name and args */
+	if (rte_eal_parse_devargs_str(devargs, &name, &args))
+		goto err;
+
+	ret = rte_eal_dev_attach(name, args);
+	if (ret < 0)
+		goto err;
+
+	/* no point looking at eth_dev_last_created_port if no port exists */
+	if (!nb_ports) {
+		ret = -1;
+		goto err;
 	}
+	/* if nothing happened, there is a bug here, since some driver told us
+	 * it did attach a device, but did not create a port */
+	if (current == eth_dev_last_created_port) {
+		ret = -1;
+		goto err;
+	}
+	*port_id = eth_dev_last_created_port;
+	ret = 0;
 
-	return 0;
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	free(name);
+	free(args);
 	return ret;
 }
 
@@ -589,7 +418,6 @@ err:
 int
 rte_eth_dev_detach(uint8_t port_id, char *name)
 {
-	struct rte_pci_addr addr;
 	int ret = -1;
 
 	if (name == NULL) {
@@ -597,33 +425,19 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 		goto err;
 	}
 
-	/* check whether the driver supports detach feature, or not */
+	/* FIXME: move this to eal, once device flags are relocated there */
 	if (rte_eth_dev_is_detachable(port_id))
 		goto err;
 
-	if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
-		ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
-		if (ret < 0)
-			goto err;
-
-		ret = rte_eth_dev_detach_pdev(port_id, &addr);
-		if (ret < 0)
-			goto err;
-
-		snprintf(name, RTE_ETH_NAME_MAX_LEN,
-			"%04x:%02x:%02x.%d",
-			addr.domain, addr.bus,
-			addr.devid, addr.function);
-	} else {
-		ret = rte_eth_dev_detach_vdev(port_id, name);
-		if (ret < 0)
-			goto err;
-	}
+	snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
+		 "%s", rte_eth_devices[port_id].data->name);
+	ret = rte_eal_dev_detach(name);
+	if (ret < 0)
+		goto err;
 
 	return 0;
 
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
 	return ret;
 }
 
Signature · 1 line
1.9.1
#52 lore raw

PATCH v2 17/17 ethdev: get rid of device type

In reply to David Marchand

Now that hotplug has been moved to eal, there is no reason to keep the device type in this layer.

---
 app/test/virtual_pmd.c                    |  2 +-
 drivers/net/af_packet/rte_eth_af_packet.c |  2 +-
 drivers/net/bonding/rte_eth_bond_api.c    |  2 +-
 drivers/net/cxgbe/cxgbe_main.c            |  2 +-
 drivers/net/mlx4/mlx4.c                   |  2 +-
 drivers/net/mlx5/mlx5.c                   |  2 +-
 drivers/net/mpipe/mpipe_tilegx.c          |  2 +-
 drivers/net/null/rte_eth_null.c           |  2 +-
 drivers/net/pcap/rte_eth_pcap.c           |  2 +-
 drivers/net/ring/rte_eth_ring.c           |  2 +-
 drivers/net/vhost/rte_eth_vhost.c         |  2 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c     |  2 +-
 examples/ip_pipeline/init.c               | 22 ----------------------
 lib/librte_ether/rte_ethdev.c             |  5 ++---
 lib/librte_ether/rte_ethdev.h             | 15 +--------------
 15 files changed, 15 insertions(+), 51 deletions(-)
app/test/virtual_pmd.c +1 -1
index b4bd2f2..8a1f0d0 100644
@@ -581,7 +581,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 		goto err;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto err;
 
drivers/net/af_packet/rte_eth_af_packet.c +1 -1
index f17bd7e..36ac102 100644
@@ -648,7 +648,7 @@ rte_pmd_init_internals(const char *name,
 	}
 
 	/* reserve an ethdev entry */
-	*eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	*eth_dev = rte_eth_dev_allocate(name);
 	if (*eth_dev == NULL)
 		goto error;
 
drivers/net/bonding/rte_eth_bond_api.c +1 -1
index e9247b5..c72807c 100644
@@ -193,7 +193,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 	}
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL) {
 		RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev");
 		goto err;
drivers/net/cxgbe/cxgbe_main.c +1 -1
index ceaf5ab..922155b 100644
@@ -1150,7 +1150,7 @@ int cxgbe_probe(struct adapter *adapter)
 		 */
 
 		/* reserve an ethdev entry */
-		pi->eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+		pi->eth_dev = rte_eth_dev_allocate(name);
 		if (!pi->eth_dev)
 			goto out_free;
 
drivers/net/mlx4/mlx4.c +1 -1
index 8e4b0cc..0c76e72 100644
@@ -5667,7 +5667,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
 			snprintf(name, sizeof(name), "%s port %u",
 				 ibv_get_device_name(ibv_dev), port);
-			eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+			eth_dev = rte_eth_dev_allocate(name);
 		}
 		if (eth_dev == NULL) {
 			ERROR("can not allocate rte ethdev");
drivers/net/mlx5/mlx5.c +1 -1
index 1989a37..f6399fc 100644
@@ -519,7 +519,7 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
 			snprintf(name, sizeof(name), "%s port %u",
 				 ibv_get_device_name(ibv_dev), port);
-			eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+			eth_dev = rte_eth_dev_allocate(name);
 		}
 		if (eth_dev == NULL) {
 			ERROR("can not allocate rte ethdev");
drivers/net/mpipe/mpipe_tilegx.c +1 -1
index adcbc19..4e29931 100644
@@ -1587,7 +1587,7 @@ rte_pmd_mpipe_devinit(const char *ifname,
 		return -ENODEV;
 	}
 
-	eth_dev = rte_eth_dev_allocate(ifname, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(ifname);
 	if (!eth_dev) {
 		RTE_LOG(ERR, PMD, "%s: Failed to allocate device.\n", ifname);
 		rte_free(priv);
drivers/net/null/rte_eth_null.c +1 -1
index 5e8e203..e6c74a6 100644
@@ -514,7 +514,7 @@ eth_dev_null_create(const char *name,
 		goto error;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto error;
 
drivers/net/pcap/rte_eth_pcap.c +1 -1
index c98e234..2d00d04 100644
@@ -822,7 +822,7 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
 		goto error;
 
 	/* reserve an ethdev entry */
-	*eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	*eth_dev = rte_eth_dev_allocate(name);
 	if (*eth_dev == NULL)
 		goto error;
 
drivers/net/ring/rte_eth_ring.c +1 -1
index b1783c3..b78d1cf 100644
@@ -303,7 +303,7 @@ do_eth_dev_ring_create(const char *name,
 	}
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL) {
 		rte_errno = ENOSPC;
 		goto error;
drivers/net/vhost/rte_eth_vhost.c +1 -1
index 310cbef..4e99360 100644
@@ -717,7 +717,7 @@ eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues,
 		goto error;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto error;
 
drivers/net/xenvirt/rte_eth_xenvirt.c +1 -1
index b9638d9..663fb14 100644
@@ -663,7 +663,7 @@ eth_dev_xenvirt_create(const char *name, const char *params,
 		goto err;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto err;
 
examples/ip_pipeline/init.c +0 -22
index 83422e8..476d372 100644
@@ -604,29 +604,12 @@ app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
 	}
 }
 
-static int
-app_link_is_virtual(struct app_link_params *p)
-{
-	uint32_t pmd_id = p->pmd_id;
-	struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
-
-	if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
-		return 1;
-
-	return 0;
-}
-
 void
 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
 {
 	uint32_t i;
 	int status;
 
-	if (app_link_is_virtual(cp)) {
-		cp->state = 1;
-		return;
-	}
-
 	/* For each link, add filters for IP of current link */
 	if (cp->ip != 0) {
 		for (i = 0; i < app->n_links; i++) {
@@ -734,11 +717,6 @@ app_link_down_internal(struct app_params *app, struct app_link_params *cp)
 	uint32_t i;
 	int status;
 
-	if (app_link_is_virtual(cp)) {
-		cp->state = 0;
-		return;
-	}
-
 	/* PMD link down */
 	status = rte_eth_dev_set_link_down(cp->pmd_id);
 	if (status < 0)
lib/librte_ether/rte_ethdev.c +2 -3
index 1794025..55b32da 100644
@@ -185,7 +185,7 @@ rte_eth_dev_find_free_port(void)
 }
 
 struct rte_eth_dev *
-rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
+rte_eth_dev_allocate(const char *name)
 {
 	uint8_t port_id;
 	struct rte_eth_dev *eth_dev;
@@ -210,7 +210,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
 	eth_dev->data->port_id = port_id;
 	eth_dev->attached = DEV_ATTACHED;
-	eth_dev->dev_type = type;
 	eth_dev_last_created_port = port_id;
 	nb_ports++;
 	return eth_dev;
@@ -242,7 +241,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
 			sizeof(ethdev_name));
 
-	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
+	eth_dev = rte_eth_dev_allocate(ethdev_name);
 	if (eth_dev == NULL)
 		return -ENOMEM;
 
lib/librte_ether/rte_ethdev.h +1 -14
index 016ce33..d120522 100644
@@ -1600,17 +1600,6 @@ struct rte_eth_rxtx_callback {
 };
 
 /**
- * The eth device type.
- */
-enum rte_eth_dev_type {
-	RTE_ETH_DEV_UNKNOWN,	/**< unknown device type */
-	RTE_ETH_DEV_PCI,
-		/**< Physical function and Virtual function of PCI devices */
-	RTE_ETH_DEV_VIRTUAL,	/**< non hardware device */
-	RTE_ETH_DEV_MAX		/**< max value of this enum */
-};
-
-/**
  * @internal
  * The generic data structure associated with each ethernet device.
  *
@@ -1640,7 +1629,6 @@ struct rte_eth_dev {
 	 */
 	struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
 	uint8_t attached; /**< Flag indicating the port is attached */
-	enum rte_eth_dev_type dev_type; /**< Flag indicating the device type */
 };
 
 struct rte_eth_dev_sriov {
@@ -1753,8 +1741,7 @@ struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
  * @return
  *   - Slot in the rte_dev_devices array for a new device;
  */
-struct rte_eth_dev *rte_eth_dev_allocate(const char *name,
-		enum rte_eth_dev_type type);
+struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
 
 /**
  * @internal
Signature · 1 line
1.9.1
#53 lore raw
In reply to David Marchand
Quoted 25 lines · David Marchand

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

From my pov, eal hotplug api introduced in this patchset still needs more work so that it does not need to know about devargs. So a new devargs api is needed.

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

Quoted 6 lines

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Regards,

Signature · 1 line
David Marchand

Nice, David. Looks to be some good improvements in there!

/Bruce

#36 lore raw

Re: [PATCH v2 05/17] eal: introduce init macros

In reply to David Marchand

Hello,

just an idea...

Quoted 7 lines · On Wed, 20 Apr 2016 13:44:05 +0200 David Marchand <[email protected]>…

Introduce a RTE_INIT macro used to mark an init function as a constructor. Current eal macros have been converted to use this (no functional impact). RTE_EAL_PCI_REGISTER is added as a helper for pci drivers.

---

[...]

lib/librte_eal/common/include/rte_pci.h void rte_eal_pci_dump(FILE *f); · line 474

Quoted 9 lines
lib/librte_eal/common/include/rte_pci.h +1 -0
index e692094..f99b33a 100644
@@ -471,6 +471,13 @@ void rte_eal_pci_dump(FILE *f);
  */
 void rte_eal_pci_register(struct rte_pci_driver *driver);
 
+#define RTE_EAL_PCI_REGISTER(name, d) \

What about a simple version with just a single argument?

#define RTE_EAL_PCI_REGISTER(name)
RTE_INIT(pciinitfn_ ##name); \
static void pciinitfn_ ##name(void) \

{ \
	rte_eal_pci_register(&(name).pci_drv); \
}

Then the name pci_drv would be mandatory... But anyway, the 'name' and 'd' are usually duplicates.

Regards
Jan

Quoted 24 lines
lib/librte_eal/common/include/rte_pci.h +6 -0
+RTE_INIT(pciinitfn_ ##name); \
+static void pciinitfn_ ##name(void) \
+{ \
+	rte_eal_pci_register(&d); \
+}
+
 /**
  * Unregister a PCI driver.
  *
lib/librte_eal/common/include/rte_tailq.h +2 -2
index 4a686e6..71ed3bb 100644
@@ -148,8 +148,8 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
 int rte_eal_tailq_register(struct rte_tailq_elem *t);
 
 #define EAL_REGISTER_TAILQ(t) \
-void tailqinitfn_ ##t(void); \
-void __attribute__((constructor, used)) tailqinitfn_ ##t(void) \
+RTE_INIT(tailqinitfn_ ##t); \
+static void tailqinitfn_ ##t(void) \
 { \
 	if (rte_eal_tailq_register(&t) < 0) \
 		rte_panic("Cannot initialize tailq: %s\n", t.name); \
#54 lore raw
In reply to Bruce Richardson
Quoted 28 lines · On Wed, 20 Apr 2016 13:05:24 +0100 Bruce Richardson…
Quoted 27 lines · David Marchand

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

From my pov, eal hotplug api introduced in this patchset still needs more work so that it does not need to know about devargs. So a new devargs api is needed.

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Quoted 7 lines
Quoted 4 lines

Regards,

Signature · 1 line
David Marchand

Nice, David. Looks to be some good improvements in there!

/Bruce

Looks good for me but I've failed to apply the series on top of

commit 7d619406f31ddf115714b32778c33f6dc0ead470

Author: Thomas Monjalon <[email protected]>
Date:   Thu Apr 14 20:49:49 2016 +0200

pci: remove deprecated specific config

Jan

#55 lore raw

[...]

Quoted 19 lines
Quoted 11 lines
Quoted 11 lines

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Quoted 7 lines
Quoted 4 lines

Regards,

Signature · 1 line
David Marchand

Nice, David. Looks to be some good improvements in there!

/Bruce

Quoted 7 lines

Looks good for me but I've failed to apply the series on top of

commit 7d619406f31ddf115714b32778c33f6dc0ead470

Author: Thomas Monjalon <[email protected]>
Date:   Thu Apr 14 20:49:49 2016 +0200

pci: remove deprecated specific config

OK, it works, my fault.

What is the way of removing the pmd_type? Would you like to introduce something like rte_virt_device/driver pair for this purpose? Or should they use the rte_device/rte_driver directly?

Other points:

* The devinit/devuninit should be generalized and moved to rte_driver, right?
* Fields name, drv_flags should be moved to rte_driver.
* Fields devargs, intr_handle, numa_node should be moved to rte_device.
* Do we want getter/setters for those? Otherwise, it always looks like pci_dev->dev.numa_node.

* What about pci_driver_list and pci_device_list? Should we have separated lists for every kind of device + driver? or should there be a single list (and so we have to put some discriminator into the rte_device/driver)? This influences placing of the TAILQ_ENTRY(...) next.
* if we move the next into the rte_driver/device and a discriminator of their type there, all TAILQ_FOREACH loops will look ugly as we have to check the discriminator...

Regards
Jan

Quoted 2 lines

Jan

Signature · 4 lines
   Jan Viktorin                  E-mail: [email protected]
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic
#44 lore raw

Re: [PATCH v2 12/17] pci: add a helper for device name

In reply to David Marchand
Quoted 10 lines · David Marchand

eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev.

---
 lib/librte_cryptodev/rte_cryptodev.c    | 27 ++++-----------------------
 lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 24 ++++--------------------
 3 files changed, 33 insertions(+), 43 deletions(-)

FYI: I see a compile error after applying this patch. It's unrelated directly to this patch as root cause seems to be rte_debug.h missing an include for rte_branch_prediction.h

/Bruce

#45 lore raw

Re: [PATCH v2 12/17] pci: add a helper for device name

2016-05-04 16:25, Bruce Richardson:

Quoted 11 lines · David Marchand
Quoted 10 lines

eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev.

---
 lib/librte_cryptodev/rte_cryptodev.c    | 27 ++++-----------------------
 lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 24 ++++--------------------
 3 files changed, 33 insertions(+), 43 deletions(-)
Quoted 3 lines

FYI: I see a compile error after applying this patch. It's unrelated directly to this patch as root cause seems to be rte_debug.h missing an include for rte_branch_prediction.h

It's probably due to this recent commit:

	http://dpdk.org/browse/dpdk/diff/lib/librte_eal/common/include/rte_debug.h?id=50705e
#46 lore raw

Re: [PATCH v2 12/17] pci: add a helper for device name

Quoted 12 lines · Thomas Monjalon

2016-05-04 16:25, Bruce Richardson:

Quoted 11 lines · David Marchand
Quoted 10 lines

eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev.

---
 lib/librte_cryptodev/rte_cryptodev.c    | 27 ++++-----------------------
 lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 24 ++++--------------------
 3 files changed, 33 insertions(+), 43 deletions(-)
Quoted 6 lines
Quoted 3 lines

FYI: I see a compile error after applying this patch. It's unrelated directly to this patch as root cause seems to be rte_debug.h missing an include for rte_branch_prediction.h

It's probably due to this recent commit:

	http://dpdk.org/browse/dpdk/diff/lib/librte_eal/common/include/rte_debug.h?id=50705e

Yes, patch is in the works here...

#56 lore raw
In reply to Jan Viktorin
Quoted 41 lines · Jan Viktorin
Quoted 28 lines · On Wed, 20 Apr 2016 13:05:24 +0100 Bruce Richardson…
Quoted 27 lines · David Marchand

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

From my pov, eal hotplug api introduced in this patchset still needs more work so that it does not need to know about devargs. So a new devargs api is needed.

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Quoted 7 lines
Quoted 4 lines

Regards,
--
David Marchand

Nice, David. Looks to be some good improvements in there!

/Bruce

Looks good for me but I've failed to apply the series on top of

Quoted 8 lines

commit 7d619406f31ddf115714b32778c33f6dc0ead470

Author: Thomas Monjalon <[email protected]>
Date:   Thu Apr 14 20:49:49 2016 +0200

pci: remove deprecated specific config

Jan

The changes look good to me, nice to remove some of the duplication ethdev/cryptodev.

Regarding enabling hot-plugging for crypto devices it looks like it should be possible now to implement a mostly generic device attach/detach functions, just with a simple wrapper to identify a specific crypto or ethdev device structure. Do you have plans to do this? If not, I can have a look as I would like to enable hot-plugging for crypto devices, without duplicating things that still reside in the ethdev library at the moment.

#57 lore raw

Hello,

Quoted 8 lines · On Fri, 6 May 2016 10:26:45 +0100 Declan Doherty <[email protected]>…
Quoted 7 lines · Jan Viktorin
Quoted 4 lines · On Wed, 20 Apr 2016 13:05:24 +0100 Bruce Richardson…
Quoted 3 lines · David Marchand

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

[...]

Quoted 3 lines

The changes look good to me, nice to remove some of the duplication ethdev/cryptodev.

Yes, I like them too.

Quoted 6 lines

Regarding enabling hot-plugging for crypto devices it looks like it should be possible now to implement a mostly generic device attach/detach functions, just with a simple wrapper to identify a specific crypto or ethdev device structure. Do you have plans to do this? If not, I can have a look as I would like to enable hot-plugging

Yes. But, first I focused on the new SoC infra to find out what can be shared by the generic layer. I've got almost ready patch series, I will post it soon to the mailing list. It does not introduce the generic rte_driver/device yet, however, it shows that with

[PATCH v2 00/17] prepare for rte_device / rte_driver

it is now possible to do it quite easily.

However, what I am not very sure about is whether we separate management of the PCI devices and SoC devices and any other such devices. Or whether we should have a single list for all.

Second, the rte_driver must be removed from DPDK as it conflicts with the new rte_driver structure to be introduced. This should include removing of pmd_type, I think. I've expected that David M. will continue with v3 to move on (otherwise we'll get some merge conflicts I'd like to avoid).

Another thing, there are structs like rte_pci_addr (etc.) which must (but I am not so sure) be probably generalized as well.

And, devargs...

Regards
Jan

Quoted 6 lines

for crypto devices, without duplicating things that still reside in the ethdev library at the moment.

Signature · 4 lines
  Jan Viktorin                E-mail: [email protected]
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic
#58 lore raw
In reply to David Marchand

Hi David,

Quoted 106 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of David Marchand
Sent: Wednesday, April 20, 2016 12:44 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH v2 00/17] prepare for rte_device / rte_driver

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

From my pov, eal hotplug api introduced in this patchset still needs more work so that it does not need to know about devargs. So a new devargs api is needed.

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Regards,
--
David Marchand

David Marchand (17):
pci: no need for dynamic tailq init
crypto: no need for a crypto pmd type
drivers: align pci driver definitions
eal: remove duplicate function declaration
eal: introduce init macros
crypto: export init/uninit common wrappers for pci drivers
ethdev: export init/uninit common wrappers for pci drivers
drivers: convert all pdev drivers as pci drivers
crypto: get rid of crypto driver register callback
ethdev: get rid of eth driver register callback eal/linux: move back interrupt thread init before setting affinity
pci: add a helper for device name
pci: add a helper to update a device
ethdev: do not scan all pci devices on attach
eal: add hotplug operations for pci and vdev
ethdev: convert to eal hotplug
ethdev: get rid of device type

 app/test/virtual_pmd.c                          |   2 +-
 drivers/crypto/qat/rte_qat_cryptodev.c          |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |   2 +-
 drivers/net/bnx2x/bnx2x_ethdev.c                |  35 +--
 drivers/net/bonding/rte_eth_bond_api.c          |   2 +-
 drivers/net/cxgbe/cxgbe_ethdev.c                |  24 +-
 drivers/net/cxgbe/cxgbe_main.c                  |   2 +-
 drivers/net/e1000/em_ethdev.c                   |  16 +-
 drivers/net/e1000/igb_ethdev.c                  |  40 +--
 drivers/net/ena/ena_ethdev.c                    |  20 +-
 drivers/net/enic/enic_ethdev.c                  |  23 +-
 drivers/net/fm10k/fm10k_ethdev.c                |  23 +-
 drivers/net/i40e/i40e_ethdev.c                  |  26 +-
 drivers/net/i40e/i40e_ethdev_vf.c               |  25 +-
 drivers/net/ixgbe/ixgbe_ethdev.c                |  47 +---
 drivers/net/mlx4/mlx4.c                         |  22 +-
 drivers/net/mlx5/mlx5.c                         |  21 +-
 drivers/net/mpipe/mpipe_tilegx.c                |   2 +-
 drivers/net/nfp/nfp_net.c                       |  23 +-
 drivers/net/null/rte_eth_null.c                 |   2 +-
 drivers/net/pcap/rte_eth_pcap.c                 |   2 +-
 drivers/net/ring/rte_eth_ring.c                 |   2 +-
 drivers/net/szedata2/rte_eth_szedata2.c         |  25 +-
 drivers/net/vhost/rte_eth_vhost.c               |   2 +-
 drivers/net/virtio/virtio_ethdev.c              |  26 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c            |  23 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   2 +-
 examples/ip_pipeline/init.c                     |  22 --
 lib/librte_cryptodev/rte_cryptodev.c            |  67 +----
 lib/librte_cryptodev/rte_cryptodev.h            |   2 -
 lib/librte_cryptodev/rte_cryptodev_pmd.h        |  45 +---
 lib/librte_cryptodev/rte_cryptodev_version.map  |   9 +-
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  52 +++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   8 +
 lib/librte_eal/common/eal_common_dev.c          |  39 +++
 lib/librte_eal/common/eal_common_pci.c          |  17 +-
 lib/librte_eal/common/eal_private.h             |  20 +-
 lib/librte_eal/common/include/rte_dev.h         |  29 ++-
 lib/librte_eal/common/include/rte_eal.h         |   3 +
 lib/librte_eal/common/include/rte_pci.h         |  32 +++
 lib/librte_eal/common/include/rte_tailq.h       |   4 +-
 lib/librte_eal/linuxapp/eal/eal.c               |   7 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c           |  16 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   8 +
 lib/librte_ether/rte_ethdev.c                   | 316 ++++--------------------
 lib/librte_ether/rte_ethdev.h                   |  40 ++-
 lib/librte_ether/rte_ether_version.map          |   9 +-
 47 files changed, 392 insertions(+), 810 deletions(-)
Quoted 2 lines

--
1.9.1

Patches 3,8,16 and 17 no longer apply to the latest master branch. A rebase is needed.

Regards,

Bernard.

#50 lore raw

Re: [PATCH v2 15/17] eal: add hotplug operations for pci and vdev

In reply to David Marchand

Hi David,

Quoted 46 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of David Marchand
Sent: Wednesday, April 20, 2016 12:44 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH v2 15/17] eal: add hotplug operations for pci and vdev

hotplug which deals with resources should come from the layer that already handles them, i.e. eal.

For both attach and detach operations, 'name' is used to select the bus that will handle the request.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++++
 lib/librte_eal/common/eal_common_dev.c          | 39
+++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 25 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++++
 4 files changed, 80 insertions(+)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +8 -0
index 58c2951..4d075df 100644
@@ -151,3 +151,11 @@ DPDK_16.04 {
 	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
+
+DPDK_16.07 {
+	global:
+
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
+
+} DPDK_16.04;
lib/librte_eal/common/eal_common_dev.c +0 -0
index a8a4146..59ed3a0 100644

lib/librte_eal/common/eal_common_dev.c rte_eal_vdev_uninit(const char *name) · line 157

Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c +5 -0
@@ -150,3 +150,42 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+int rte_eal_dev_attach(const char *name, const char *devargs) {
+	struct rte_pci_addr addr;
+	int ret = -1;
+

Should the input parameters name and devargs be checked?

Quoted 9 lines
lib/librte_eal/common/eal_common_dev.c +9 -0
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_probe_one(&addr) < 0)
+			goto err;
+
+	} else {
+		if (rte_eal_vdev_init(name, devargs))
+			goto err;
+	}
+

lib/librte_eal/common/eal_common_dev.c rte_eal_vdev_uninit(const char *name) · line 178

Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10 -0
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	return ret;
+}
+
+int rte_eal_dev_detach(const char *name) {
+	struct rte_pci_addr addr;
+

Should the name parameter be checked?

Quoted 69 lines
lib/librte_eal/common/eal_common_dev.c +13 -0
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_detach(&addr) < 0)
+			goto err;
+	} else {
+		if (rte_eal_vdev_uninit(name))
+			goto err;
+	}
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
+	return -1;
+}
lib/librte_eal/common/include/rte_dev.h +25 -0
index 85e48f2..b1c0520 100644
@@ -178,6 +178,31 @@ int rte_eal_vdev_init(const char *name, const char
 *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * Attach a resource to a registered driver.
+ *
+ * @param name
+ *   The resource name, that refers to a pci resource or some private
+ *   way of designating a resource for vdev drivers. Based on this
+ *   resource name, eal will identify a driver capable of handling
+ *   this resource and pass this resource to the driver probing
+ *   function.
+ * @param devargs
+ *   Device arguments to be passed to the driver.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_attach(const char *name, const char *devargs);
+
+/**
+ * Detach a resource from its driver.
+ *
+ * @param name
+ *   Same description as for rte_eal_dev_attach().
+ *   Here, eal will call the driver detaching function.
+ */
+int rte_eal_dev_detach(const char *name);
+
 #define PMD_REGISTER_DRIVER(d)\
 RTE_INIT(devinitfn_ ##d);\

static void devinitfn_ ##d(void)\

lib/librte_eal/linuxapp/eal/rte_eal_version.map +8 -1
index 12503ef..0404a52 100644
@@ -154,3 +154,11 @@ DPDK_16.04 {
 	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
+
+DPDK_16.07 {
+	global:
+
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
+
+} DPDK_16.04;
--
Quoted 1 line

1.9.1

Regards,

Bernard.

#59 lore raw
In reply to Iremonger, Bernard

Hi David,

Quoted 119 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Iremonger, Bernard
Sent: Friday, May 27, 2016 3:54 PM
To: David Marchand <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 00/17] prepare for rte_device / rte_driver

Hi David,

Quoted 11 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of David Marchand
Sent: Wednesday, April 20, 2016 12:44 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH v2 00/17] prepare for rte_device / rte_driver

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least,

I

Quoted 3 lines

think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it

concerned

Quoted 8 lines

a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

From my pov, eal hotplug api introduced in this patchset still needs more work so that it does not need to know about devargs. So a new devargs api

is

Quoted 72 lines

needed.

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

Regards,
--
David Marchand

David Marchand (17):
pci: no need for dynamic tailq init
crypto: no need for a crypto pmd type
drivers: align pci driver definitions
eal: remove duplicate function declaration
eal: introduce init macros
crypto: export init/uninit common wrappers for pci drivers
ethdev: export init/uninit common wrappers for pci drivers
drivers: convert all pdev drivers as pci drivers
crypto: get rid of crypto driver register callback
ethdev: get rid of eth driver register callback eal/linux: move back interrupt thread init before setting affinity
pci: add a helper for device name
pci: add a helper to update a device
ethdev: do not scan all pci devices on attach
eal: add hotplug operations for pci and vdev
ethdev: convert to eal hotplug
ethdev: get rid of device type

 app/test/virtual_pmd.c                          |   2 +-
 drivers/crypto/qat/rte_qat_cryptodev.c          |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |   2 +-
 drivers/net/bnx2x/bnx2x_ethdev.c                |  35 +--
 drivers/net/bonding/rte_eth_bond_api.c          |   2 +-
 drivers/net/cxgbe/cxgbe_ethdev.c                |  24 +-
 drivers/net/cxgbe/cxgbe_main.c                  |   2 +-
 drivers/net/e1000/em_ethdev.c                   |  16 +-
 drivers/net/e1000/igb_ethdev.c                  |  40 +--
 drivers/net/ena/ena_ethdev.c                    |  20 +-
 drivers/net/enic/enic_ethdev.c                  |  23 +-
 drivers/net/fm10k/fm10k_ethdev.c                |  23 +-
 drivers/net/i40e/i40e_ethdev.c                  |  26 +-
 drivers/net/i40e/i40e_ethdev_vf.c               |  25 +-
 drivers/net/ixgbe/ixgbe_ethdev.c                |  47 +---
 drivers/net/mlx4/mlx4.c                         |  22 +-
 drivers/net/mlx5/mlx5.c                         |  21 +-
 drivers/net/mpipe/mpipe_tilegx.c                |   2 +-
 drivers/net/nfp/nfp_net.c                       |  23 +-
 drivers/net/null/rte_eth_null.c                 |   2 +-
 drivers/net/pcap/rte_eth_pcap.c                 |   2 +-
 drivers/net/ring/rte_eth_ring.c                 |   2 +-
 drivers/net/szedata2/rte_eth_szedata2.c         |  25 +-
 drivers/net/vhost/rte_eth_vhost.c               |   2 +-
 drivers/net/virtio/virtio_ethdev.c              |  26 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c            |  23 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   2 +-
 examples/ip_pipeline/init.c                     |  22 --
 lib/librte_cryptodev/rte_cryptodev.c            |  67 +----
 lib/librte_cryptodev/rte_cryptodev.h            |   2 -
 lib/librte_cryptodev/rte_cryptodev_pmd.h        |  45 +---
 lib/librte_cryptodev/rte_cryptodev_version.map  |   9 +-
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  52 +++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   8 +
 lib/librte_eal/common/eal_common_dev.c          |  39 +++
 lib/librte_eal/common/eal_common_pci.c          |  17 +-
 lib/librte_eal/common/eal_private.h             |  20 +-
Quoted 8 lines
 lib/librte_eal/common/include/rte_dev.h         |  29 ++-
 lib/librte_eal/common/include/rte_eal.h         |   3 +
 lib/librte_eal/common/include/rte_pci.h         |  32 +++
 lib/librte_eal/common/include/rte_tailq.h       |   4 +-
 lib/librte_eal/linuxapp/eal/eal.c               |   7 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c           |  16 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   8 +
 lib/librte_ether/rte_ethdev.c                   | 316 ++++----------------

----

Quoted 4 lines
 lib/librte_ether/rte_ethdev.h                   |  40 ++-
 lib/librte_ether/rte_ether_version.map          |   9 +-
 47 files changed, 392 insertions(+), 810 deletions(-)
Quoted 6 lines
Quoted 2 lines

--
1.9.1

Patches 3,8,16 and 17 no longer apply to the latest master branch. A rebase is needed.

[...]

With the recent most head (04920e6): 01, 03, 08, 15, 16 and 17 are failing.

Just wanted to check if there is a rebase of this series anytime soon? I was looking at Jan's non-PCI patchset [1] and they are based on this series.

[1] http://thread.gmane.org/gmane.comp.networking.dpdk.devel/30913/focus=38486

-
Shreyansh

#60 lore raw

2016-06-16 06:32, Shreyansh Jain:

Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Iremonger, Bernard

Quoted 2 lines

Patches 3,8,16 and 17 no longer apply to the latest master branch. A rebase is needed.

With the recent most head (04920e6): 01, 03, 08, 15, 16 and 17 are failing.

Just wanted to check if there is a rebase of this series anytime soon?

I will take care of this series if time permit.
It would help to have more reviews on other series touching EAL, like pmdinfo.

Quoted 3 lines

I was looking at Jan's non-PCI patchset [1] and they are based on this series.

[1] http://thread.gmane.org/gmane.comp.networking.dpdk.devel/30913/focus=38486

#61 lore raw

I think, we should consider to move it to somebody else. I would work on it, however, I don't see all the tasks that are to be done. That's why I was waiting to finalize those patchs by David or Thomas. For me, the important things were to generalize certain things to remove dependency on PCI. This is mostly done (otherwise the SoC patchset couldn't be done in the way I've posted it).

Now, there is some pending work to remove pmd_type. Next, to find out some generalization of rte_pci_device/driver to create rte_device/driver (I've posted several suggestions in the 0000 of SoC patchset).

What more?

Jan Viktorin
RehiveTech
Sent from a mobile device
  Původní zpráva
Od: Thomas Monjalon
Odesláno: čtvrtek, 16. června 2016 9:34
Komu: Shreyansh Jain
Kopie: David Marchand; [email protected]; [email protected]; Iremonger, Bernard Předmět: Re: [dpdk-dev] [PATCH v2 00/17] prepare for rte_device / rte_driver

2016-06-16 06:32, Shreyansh Jain:

Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Iremonger, Bernard

Quoted 2 lines

Patches 3,8,16 and 17 no longer apply to the latest master branch. A rebase is needed.

With the recent most head (04920e6): 01, 03, 08, 15, 16 and 17 are failing.

Just wanted to check if there is a rebase of this series anytime soon?

I will take care of this series if time permit.
It would help to have more reviews on other series touching EAL, like pmdinfo.

Quoted 3 lines

I was looking at Jan's non-PCI patchset [1] and they are based on this series.

[1] http://thread.gmane.org/gmane.comp.networking.dpdk.devel/30913/focus=38486

#64 lore raw
In reply to Thomas Monjalon

Hi,

Quoted 10 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, June 16, 2016 1:04 PM
To: Shreyansh Jain <[email protected]>
Cc: David Marchand <[email protected]>; [email protected]; [email protected]; Iremonger, Bernard <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 00/17] prepare for rte_device / rte_driver

2016-06-16 06:32, Shreyansh Jain:

Quoted 1 line

From: dev [mailto:[email protected]] On Behalf Of Iremonger, Bernard

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Patches 3,8,16 and 17 no longer apply to the latest master branch. A rebase is needed.

With the recent most head (04920e6): 01, 03, 08, 15, 16 and 17 are failing.

Just wanted to check if there is a rebase of this series anytime soon?

I will take care of this series if time permit.

Ok.
By the way, I have already rebased it on master. I can post the patches here if you want. (only trivial conflicts were there)

Quoted 2 lines

It would help to have more reviews on other series touching EAL, like pmdinfo.

Ok. I can try and review this, non-PCI/SoC and similar patchset in next few days.

Quoted 6 lines
Quoted 2 lines

I was looking at Jan's non-PCI patchset [1] and they are based on this

series.

Quoted 2 lines

[1]

http://thread.gmane.org/gmane.comp.networking.dpdk.devel/30913/focus=38486

-
Shreyansh

#62 lore raw
In reply to Jan Viktorin

2016-06-16 10:23, Jan Viktorin:

Quoted 5 lines

I think, we should consider to move it to somebody else. I would work on it, however, I don't see all the tasks that are to be done. That's why I was waiting to finalize those patchs by David or Thomas. For me, the important things were to generalize certain things to remove dependency on PCI. This is mostly done (otherwise the SoC patchset couldn't be done in the way I've posted it).

Now, there is some pending work to remove pmd_type. Next, to find out some generalization of rte_pci_device/driver to create rte_device/driver (I've posted several suggestions in the 0000 of SoC patchset).

What more?

We need a clean devargs API in EAL, not directly related to hotplug. Then the hotplug can benefit of the devargs API as any other device config.

The EAL resources (also called devices) need an unique naming convention.

#63 lore raw
Quoted 4 lines · On Thu, 16 Jun 2016 11:19:59 +0200 Thomas Monjalon <[email protected]>…

2016-06-16 10:23, Jan Viktorin:

Quoted 3 lines

I think, we should consider to move it to somebody else. I would work on it, however, I don't see all the tasks that are to be done. That's why I was waiting to finalize those patchs by David or Thomas. For me, the important things were to generalize certain things to remove dependency on PCI. This is mostly done (otherwise the SoC patchset couldn't be done in the way I've posted it).

Now, there is some pending work to remove pmd_type. Next, to find out some generalization of rte_pci_device/driver to create rte_device/driver (I've posted several suggestions in the 0000 of SoC patchset).

For the pmd_type removal, I am not very sure about the original David's intentions. What should be the result?

Should there be a special struct rte_virt_device or something like that?

Quoted 5 lines
Quoted 2 lines

What more?

We need a clean devargs API in EAL, not directly related to hotplug. Then the hotplug can benefit of the devargs API as any other device config.

Do we have some requirements for this? Would it be a complete redefinition of the API? I don't see the relations to hotplug.

Quoted 3 lines

The EAL resources (also called devices) need an unique naming convention.

No idea about this. What do you mean by the unique naming convention?

Jan

#65 lore raw
In reply to Shreyansh Jain
Quoted 17 lines · On Thu, 16 Jun 2016 08:42:29 +0000 Shreyansh Jain <[email protected]>…

Hi,

Quoted 15 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, June 16, 2016 1:04 PM
To: Shreyansh Jain <[email protected]>
Cc: David Marchand <[email protected]>; [email protected]; [email protected]; Iremonger, Bernard <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 00/17] prepare for rte_device / rte_driver

2016-06-16 06:32, Shreyansh Jain:

Quoted 6 lines

From: dev [mailto:[email protected]] On Behalf Of Iremonger, Bernard

Quoted 2 lines

Patches 3,8,16 and 17 no longer apply to the latest master branch. A rebase is needed.

With the recent most head (04920e6): 01, 03, 08, 15, 16 and 17 are failing.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Just wanted to check if there is a rebase of this series anytime soon?

I will take care of this series if time permit.

Ok.
By the way, I have already rebased it on master. I can post the patches here if you want. (only trivial conflicts were there)

Sounds good. +1

I'd rebase my patchset on top of it and repost.

Quoted 5 lines
Quoted 3 lines

It would help to have more reviews on other series touching EAL, like pmdinfo.

Ok. I can try and review this, non-PCI/SoC and similar patchset in next few days.

The original David's patchset was quite OK. I didn't have any comments. The thing is (from my POV) that it was incomplete.

Jan

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

I was looking at Jan's non-PCI patchset [1] and they are based on this

series.

Quoted 2 lines

[1]

http://thread.gmane.org/gmane.comp.networking.dpdk.devel/30913/focus=38486

-
Shreyansh

#66 lore raw

v3 cover prepare for rte_device / rte_driver

In reply to David Marchand

From: David Marchand <[email protected]>

* Original patch series is from David Marchand. This is just a rebase over master (d76c19309) *

Following discussions with Jan [1] and some cleanup I started on pci code, here is a patchset that reworks pdev drivers registration and hotplug api.

The structures changes mentioned in [1] are still to be done, but at least, I think we are one step closer to it.

Before this patchset, rte_driver .init semantics differed whether it concerned a pdev or a vdev driver:
- for vdev, it actually meant that a devargs is given to the driver so that it creates ethdev / crypto objects, so it was a probing action
- for pdev, it only registered the driver triggering no ethdev / crypto objects

Quoted 1 line

From my pov, eal hotplug api introduced in this patchset still needs more

work so that it does not need to know about devargs. So a new devargs api is needed.

Changes since v2:
- rebase over HEAD (d76c193)
- Move SYSFS_PCI_DRIVERS macro to rte_pci.h to avoid compilation issue

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/031390.html

David Marchand (17):
pci: no need for dynamic tailq init
crypto: no need for a crypto pmd type
drivers: align pci driver definitions
eal: remove duplicate function declaration
eal: introduce init macros
crypto: export init/uninit common wrappers for pci drivers
ethdev: export init/uninit common wrappers for pci drivers
drivers: convert all pdev drivers as pci drivers
crypto: get rid of crypto driver register callback
ethdev: get rid of eth driver register callback eal/linux: move back interrupt thread init before setting affinity
pci: add a helper for device name
pci: add a helper to update a device
ethdev: do not scan all pci devices on attach
eal: add hotplug operations for pci and vdev
ethdev: convert to eal hotplug
ethdev: get rid of device type

 app/test/virtual_pmd.c                          |   2 +-
 drivers/crypto/qat/rte_qat_cryptodev.c          |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |   2 +-
 drivers/net/bnx2x/bnx2x_ethdev.c                |  35 +--
 drivers/net/bonding/rte_eth_bond_api.c          |   2 +-
 drivers/net/cxgbe/cxgbe_ethdev.c                |  24 +-
 drivers/net/cxgbe/cxgbe_main.c                  |   2 +-
 drivers/net/e1000/em_ethdev.c                   |  16 +-
 drivers/net/e1000/igb_ethdev.c                  |  40 +--
 drivers/net/ena/ena_ethdev.c                    |  20 +-
 drivers/net/enic/enic_ethdev.c                  |  23 +-
 drivers/net/fm10k/fm10k_ethdev.c                |  23 +-
 drivers/net/i40e/i40e_ethdev.c                  |  26 +-
 drivers/net/i40e/i40e_ethdev_vf.c               |  25 +-
 drivers/net/ixgbe/ixgbe_ethdev.c                |  47 +---
 drivers/net/mlx4/mlx4.c                         |  22 +-
 drivers/net/mlx5/mlx5.c                         |  21 +-
 drivers/net/mpipe/mpipe_tilegx.c                |   2 +-
 drivers/net/nfp/nfp_net.c                       |  23 +-
 drivers/net/null/rte_eth_null.c                 |   2 +-
 drivers/net/pcap/rte_eth_pcap.c                 |   2 +-
 drivers/net/ring/rte_eth_ring.c                 |   2 +-
 drivers/net/szedata2/rte_eth_szedata2.c         |  25 +-
 drivers/net/vhost/rte_eth_vhost.c               |   2 +-
 drivers/net/virtio/virtio_ethdev.c              |  26 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c            |  23 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   2 +-
 examples/ip_pipeline/init.c                     |  22 --
 lib/librte_cryptodev/rte_cryptodev.c            |  67 +----
 lib/librte_cryptodev/rte_cryptodev.h            |   2 -
 lib/librte_cryptodev/rte_cryptodev_pmd.h        |  45 +---
 lib/librte_cryptodev/rte_cryptodev_version.map  |   9 +-
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  52 +++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   2 +
 lib/librte_eal/common/eal_common_dev.c          |  39 +++
 lib/librte_eal/common/eal_common_pci.c          |  19 +-
 lib/librte_eal/common/eal_private.h             |  20 +-
 lib/librte_eal/common/include/rte_dev.h         |  29 ++-
 lib/librte_eal/common/include/rte_eal.h         |   3 +
 lib/librte_eal/common/include/rte_pci.h         |  35 +++
 lib/librte_eal/common/include/rte_tailq.h       |   4 +-
 lib/librte_eal/linuxapp/eal/eal.c               |   7 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c           |  16 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   2 +
 lib/librte_ether/rte_ethdev.c                   | 315 ++++--------------------
 lib/librte_ether/rte_ethdev.h                   |  40 ++-
 lib/librte_ether/rte_ether_version.map          |   9 +-
 47 files changed, 383 insertions(+), 811 deletions(-)
Signature · 1 line
2.7.4
#67 lore raw

PATCH v3 1/17 pci: no need for dynamic tailq init

From: David Marchand <[email protected]>

These lists can be initialized once and for all at build time. With this, those lists are only manipulated in a common place (and we could even make them private).

A nice side effect is that pci drivers can now register in constructors.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c    | 3 ---
 lib/librte_eal/common/eal_common_pci.c | 6 ++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 3 ---
 3 files changed, 4 insertions(+), 8 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -3
index 7fdd6f1..880483d 100644
@@ -623,9 +623,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
lib/librte_eal/common/eal_common_pci.c +4 -2
index ba5283d..fee4aa5 100644
@@ -82,8 +82,10 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list;
-struct pci_device_list pci_device_list;
+struct pci_driver_list pci_driver_list =
+	TAILQ_HEAD_INITIALIZER(pci_driver_list);
+struct pci_device_list pci_device_list =
+	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
lib/librte_eal/linuxapp/eal/eal_pci.c +0 -3
index f9c3efd..bfc410f 100644
@@ -743,9 +743,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
Signature · 1 line
2.7.4
#68 lore raw

PATCH v3 2/17 crypto: no need for a crypto pmd type

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

This information is not used and just adds noise.

---
 lib/librte_cryptodev/rte_cryptodev.c     | 8 +++-----
 lib/librte_cryptodev/rte_cryptodev.h     | 2 --
 lib/librte_cryptodev/rte_cryptodev_pmd.h | 3 +--
 3 files changed, 4 insertions(+), 9 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +3 -5
index 960e2d5..b0d806c 100644
@@ -230,7 +230,7 @@ rte_cryptodev_find_free_device_index(void)
 }
 
 struct rte_cryptodev *
-rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
+rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 {
 	struct rte_cryptodev *cryptodev;
 	uint8_t dev_id;
@@ -269,7 +269,6 @@ rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
 		cryptodev->data->dev_started = 0;
 
 		cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
-		cryptodev->pmd_type = type;
 
 		cryptodev_globals.nb_devs++;
 	}
@@ -318,7 +317,7 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	struct rte_cryptodev *cryptodev;
 
 	/* allocate device structure */
-	cryptodev = rte_cryptodev_pmd_allocate(name, PMD_VDEV, socket_id);
+	cryptodev = rte_cryptodev_pmd_allocate(name, socket_id);
 	if (cryptodev == NULL)
 		return NULL;
 
@@ -360,8 +359,7 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	rte_cryptodev_create_unique_device_name(cryptodev_name,
 			sizeof(cryptodev_name), pci_dev);
 
-	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, PMD_PDEV,
-			rte_socket_id());
+	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
 		return -ENOMEM;
 
lib/librte_cryptodev/rte_cryptodev.h +0 -2
index d47f1e8..2d0b809 100644
@@ -697,8 +697,6 @@ struct rte_cryptodev {
 
 	enum rte_cryptodev_type dev_type;
 	/**< Crypto device type */
-	enum pmd_type pmd_type;
-	/**< PMD type - PDEV / VDEV */
 
 	struct rte_cryptodev_cb_list link_intr_cbs;
 	/**< User application callback for interrupts if present */
lib/librte_cryptodev/rte_cryptodev_pmd.h +1 -2
index 7d049ea..c977c61 100644
@@ -454,13 +454,12 @@ struct rte_cryptodev_ops {
  * to that slot for the driver to use.
  *
  * @param	name		Unique identifier name for each device
- * @param	type		Device type of this Crypto device
  * @param	socket_id	Socket to allocate resources on.
  * @return
  *   - Slot in the rte_dev_devices array for a new device;
  */
 struct rte_cryptodev *
-rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id);
+rte_cryptodev_pmd_allocate(const char *name, int socket_id);
 
 /**
  * Creates a new virtual crypto device and returns the pointer
Signature · 1 line
2.7.4
#69 lore raw

PATCH v3 3/17 drivers: align pci driver definitions

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Pure coding style, but it might make it easier later if we want to move fields in rte_cryptodev_driver and eth_driver structures.

---
 drivers/crypto/qat/rte_qat_cryptodev.c | 2 +-
 drivers/net/ena/ena_ethdev.c           | 2 +-
 drivers/net/nfp/nfp_net.c              | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +1 -1
index a7912f5..08496ab 100644
@@ -116,7 +116,7 @@ crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_
 }
 
 static struct rte_cryptodev_driver rte_qat_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
drivers/net/ena/ena_ethdev.c +1 -1
index e157587..8d01e9a 100644
@@ -1427,7 +1427,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 }
 
 static struct eth_driver rte_ena_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_ena_pmd",
 		.id_table = pci_id_ena_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
drivers/net/nfp/nfp_net.c +1 -1
index 5c9f350..ef7011e 100644
@@ -2463,7 +2463,7 @@ static struct rte_pci_id pci_id_nfp_net_map[] = {
 };
 
 static struct eth_driver rte_nfp_net_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_nfp_net_pmd",
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
Signature · 1 line
2.7.4
#70 lore raw

PATCH v3 4/17 eal: remove duplicate function declaration

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

rte_eal_dev_init is declared in both eal_private.h and rte_dev.h since its introduction.
This function has been exported in ABI, so remove it from eal_private.h

Fixes e57f20e05177 ("eal: make vdev init path generic for both virtual and pci devices")
---
 lib/librte_eal/common/eal_private.h | 7 -------
 lib/librte_eal/linuxapp/eal/eal.c   | 1 +
 2 files changed, 1 insertion(+), 7 deletions(-)
lib/librte_eal/common/eal_private.h +0 -7
index 857dc3e..06a68f6 100644
@@ -259,13 +259,6 @@ int rte_eal_intr_init(void);
 int rte_eal_alarm_init(void);
 
 /**
- * This function initialises any virtual devices
- *
- * This function is private to the EAL.
- */
-int rte_eal_dev_init(void);
-
-/**
  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
  * etc.) loaded.
  *
lib/librte_eal/linuxapp/eal/eal.c +1 -0
index bba8fea..5ec3d4e 100644
@@ -70,6 +70,7 @@
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
+#include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_common.h>
 #include <rte_version.h>
Signature · 1 line
2.7.4
#71 lore raw

PATCH v3 5/17 eal: introduce init macros

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Introduce a RTE_INIT macro used to mark an init function as a constructor. Current eal macros have been converted to use this (no functional impact). RTE_EAL_PCI_REGISTER is added as a helper for pci drivers.

---
 lib/librte_eal/common/include/rte_dev.h   | 4 ++--
 lib/librte_eal/common/include/rte_eal.h   | 3 +++
 lib/librte_eal/common/include/rte_pci.h   | 7 +++++++
 lib/librte_eal/common/include/rte_tailq.h | 4 ++--
 4 files changed, 14 insertions(+), 4 deletions(-)
lib/librte_eal/common/include/rte_dev.h +2 -2
index f1b5507..85e48f2 100644
@@ -179,8 +179,8 @@ int rte_eal_vdev_init(const char *name, const char *args);
 int rte_eal_vdev_uninit(const char *name);
 
 #define PMD_REGISTER_DRIVER(d)\
-void devinitfn_ ##d(void);\
-void __attribute__((constructor, used)) devinitfn_ ##d(void)\
+RTE_INIT(devinitfn_ ##d);\
+static void devinitfn_ ##d(void)\
 {\
 	rte_eal_driver_register(&d);\
 }
lib/librte_eal/common/include/rte_eal.h +3 -0
index a71d6f5..186f3c6 100644
@@ -252,6 +252,9 @@ static inline int rte_gettid(void)
 	return RTE_PER_LCORE(_thread_id);
 }
 
+#define RTE_INIT(func) \
+static void __attribute__((constructor, used)) func(void)
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/rte_pci.h +7 -0
index fa74962..d7df1d9 100644
@@ -470,6 +470,13 @@ void rte_eal_pci_dump(FILE *f);
  */
 void rte_eal_pci_register(struct rte_pci_driver *driver);
 
+#define RTE_EAL_PCI_REGISTER(name, d) \
+RTE_INIT(pciinitfn_ ##name); \
+static void pciinitfn_ ##name(void) \
+{ \
+	rte_eal_pci_register(&d); \
+}
+
 /**
  * Unregister a PCI driver.
  *
lib/librte_eal/common/include/rte_tailq.h +2 -2
index 4a686e6..71ed3bb 100644
@@ -148,8 +148,8 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
 int rte_eal_tailq_register(struct rte_tailq_elem *t);
 
 #define EAL_REGISTER_TAILQ(t) \
-void tailqinitfn_ ##t(void); \
-void __attribute__((constructor, used)) tailqinitfn_ ##t(void) \
+RTE_INIT(tailqinitfn_ ##t); \
+static void tailqinitfn_ ##t(void) \
 { \
 	if (rte_eal_tailq_register(&t) < 0) \
 		rte_panic("Cannot initialize tailq: %s\n", t.name); \
Signature · 1 line
2.7.4
#72 lore raw

PATCH v3 6/17 crypto: export init/uninit common wrappers for pci drivers

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Preparing for getting rid of rte_cryptodev_driver, here are two wrappers that can be used by pci drivers that assume a 1 to 1 association between pci resource and upper interface.

---
 lib/librte_cryptodev/rte_cryptodev.c           | 16 ++++++++--------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 12 ++++++++++++
 lib/librte_cryptodev/rte_cryptodev_version.map |  8 ++++++++
 3 files changed, 28 insertions(+), 8 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +8 -8
index b0d806c..65a2e29 100644
@@ -340,9 +340,9 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	return cryptodev;
 }
 
-static int
-rte_cryptodev_init(struct rte_pci_driver *pci_drv,
-		struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			struct rte_pci_device *pci_dev)
 {
 	struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -401,8 +401,8 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	return -ENXIO;
 }
 
-static int
-rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -450,15 +450,15 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
 {
 	/* Call crypto device initialization directly if device is virtual */
 	if (type == PMD_VDEV)
-		return rte_cryptodev_init((struct rte_pci_driver *)cryptodrv,
+		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
 				NULL);
 
 	/*
 	 * Register PCI driver for physical device intialisation during
 	 * PCI probing
 	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_init;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_uninit;
+	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
+	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
 
 	rte_eal_pci_register(&cryptodrv->pci_drv);
 
lib/librte_cryptodev/rte_cryptodev_pmd.h +12 -0
index c977c61..3fb7c7c 100644
@@ -534,6 +534,18 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
 				enum rte_cryptodev_event_type event);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			    struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
 
 #ifdef __cplusplus
 }
lib/librte_cryptodev/rte_cryptodev_version.map +8 -0
index 41004e1..8d0edfb 100644
@@ -32,3 +32,11 @@ DPDK_16.04 {
 
 	local: *;
 };
+
+DPDK_16.07 {
+	global:
+
+	rte_cryptodev_pci_probe;
+	rte_cryptodev_pci_remove;
+
+} DPDK_16.04;
Signature · 1 line
2.7.4
#73 lore raw

PATCH v3 7/17 ethdev: export init/uninit common wrappers for pci drivers

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Preparing for getting rid of eth_drv, here are two wrappers that can be used by pci drivers that assume a 1 to 1 association between pci resource and upper interface.

---
 lib/librte_ether/rte_ethdev.c          | 14 +++++++-------
 lib/librte_ether/rte_ethdev.h          | 13 +++++++++++++
 lib/librte_ether/rte_ether_version.map |  8 ++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
lib/librte_ether/rte_ethdev.c +7 -7
index e148028..d05eada 100644
@@ -239,9 +239,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 	return 0;
 }
 
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-		 struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+		      struct rte_pci_device *pci_dev)
 {
 	struct eth_driver    *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -293,8 +293,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	return diag;
 }
 
-static int
-rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct eth_driver *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -351,8 +351,8 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 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;
+	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
+	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
 
lib/librte_ether/rte_ethdev.h +13 -0
index e5e91e4..6deafa2 100644
@@ -4254,6 +4254,19 @@ rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
 				  uint32_t mask,
 				  uint8_t en);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+			  struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_ether/rte_ether_version.map +8 -0
index 214ecc7..31017d4 100644
@@ -132,3 +132,11 @@ DPDK_16.04 {
 	rte_eth_tx_buffer_set_err_callback;
 
 } DPDK_2.2;
+
+DPDK_16.07 {
+	global:
+
+	rte_eth_dev_pci_probe;
+	rte_eth_dev_pci_remove;
+
+} DPDK_16.04;
Signature · 1 line
2.7.4
#74 lore raw

PATCH v3 8/17 drivers: convert all pdev drivers as pci drivers

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Simplify crypto and ethdev pci drivers init by using newly introduced init macros and helpers.
Those drivers then don't need to register as "rte_driver"s anymore.

virtio and mlx* drivers use the general purpose RTE_INIT macro, as they both need some special stuff to be done before registering a pci driver.

---
 drivers/crypto/qat/rte_qat_cryptodev.c  | 16 +++--------
 drivers/net/bnx2x/bnx2x_ethdev.c        | 35 +++++-------------------
 drivers/net/cxgbe/cxgbe_ethdev.c        | 24 +++--------------
 drivers/net/e1000/em_ethdev.c           | 16 +++--------
 drivers/net/e1000/igb_ethdev.c          | 40 +++++-----------------------
 drivers/net/ena/ena_ethdev.c            | 18 +++----------
 drivers/net/enic/enic_ethdev.c          | 23 +++-------------
 drivers/net/fm10k/fm10k_ethdev.c        | 23 +++-------------
 drivers/net/i40e/i40e_ethdev.c          | 26 +++---------------
 drivers/net/i40e/i40e_ethdev_vf.c       | 25 +++---------------
 drivers/net/ixgbe/ixgbe_ethdev.c        | 47 +++++----------------------------
 drivers/net/mlx4/mlx4.c                 | 20 +++-----------
 drivers/net/mlx5/mlx5.c                 | 19 +++----------
 drivers/net/nfp/nfp_net.c               | 21 +++------------
 drivers/net/szedata2/rte_eth_szedata2.c | 25 +++---------------
 drivers/net/virtio/virtio_ethdev.c      | 26 +++++-------------
 drivers/net/vmxnet3/vmxnet3_ethdev.c    | 23 +++-------------
 17 files changed, 68 insertions(+), 359 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +3 -13
index 08496ab..54f0c95 100644
@@ -120,21 +120,11 @@ static struct rte_cryptodev_driver rte_qat_pmd = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_cryptodev_pci_probe,
+		.devuninit = rte_cryptodev_pci_remove,
 	},
 	.cryptodev_init = crypto_qat_dev_init,
 	.dev_private_size = sizeof(struct qat_pmd_private),
 };
 
-static int
-rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
-}
-
-static struct rte_driver pmd_qat_drv = {
-	.type = PMD_PDEV,
-	.init = rte_qat_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(pmd_qat_drv);
+RTE_EAL_PCI_REGISTER(qat, rte_qat_pmd.pci_drv);
drivers/net/bnx2x/bnx2x_ethdev.c +7 -28
index 071b44f..ba194b5 100644
@@ -506,11 +506,15 @@ static struct eth_driver rte_bnx2x_pmd = {
 		.name = "rte_bnx2x_pmd",
 		.id_table = pci_id_bnx2x_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2x_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
+RTE_EAL_PCI_REGISTER(bnx2x, rte_bnx2x_pmd.pci_drv);
+
 /*
  * virtual function driver struct
  */
@@ -519,36 +523,11 @@ static struct eth_driver rte_bnx2xvf_pmd = {
 		.name = "rte_bnx2xvf_pmd",
 		.id_table = pci_id_bnx2xvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2xvf_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
-static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2x_pmd);
-
-	return 0;
-}
-
-static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2xvf_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_bnx2x_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2x_pmd_init,
-};
-
-static struct rte_driver rte_bnx2xvf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2xvf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_bnx2x_driver);
-PMD_REGISTER_DRIVER(rte_bnx2xvf_driver);
+RTE_EAL_PCI_REGISTER(bnx2xvf, rte_bnx2xvf_pmd.pci_drv);
drivers/net/cxgbe/cxgbe_ethdev.c +3 -21
index 04eddaf..358c240 100644
@@ -869,29 +869,11 @@ static struct eth_driver rte_cxgbe_pmd = {
 		.name = "rte_cxgbe_pmd",
 		.id_table = cxgb4_pci_tbl,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_cxgbe_dev_init,
 	.dev_private_size = sizeof(struct port_info),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI CXGBE devices.
- */
-static int rte_cxgbe_pmd_init(const char *name __rte_unused,
-			      const char *params __rte_unused)
-{
-	CXGBE_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_cxgbe_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_cxgbe_driver = {
-	.name = "cxgbe_driver",
-	.type = PMD_PDEV,
-	.init = rte_cxgbe_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_cxgbe_driver);
+RTE_EAL_PCI_REGISTER(cxgbe, rte_cxgbe_pmd.pci_drv);
drivers/net/e1000/em_ethdev.c +3 -13
index 653be09..1f80c05 100644
@@ -368,18 +368,15 @@ static struct eth_driver rte_em_pmd = {
 		.id_table = pci_id_em_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_em_dev_init,
 	.eth_dev_uninit = eth_em_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_em_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_em_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(em, rte_em_pmd.pci_drv);
 
 static int
 em_hw_init(struct e1000_hw *hw)
@@ -1771,10 +1768,3 @@ eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
 	e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
 	return 0;
 }
-
-struct rte_driver em_pmd_drv = {
-	.type = PMD_PDEV,
-	.init = rte_em_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(em_pmd_drv);
drivers/net/e1000/igb_ethdev.c +7 -33
index f0921ee..1fc6e83 100644
@@ -975,12 +975,16 @@ static struct eth_driver rte_igb_pmd = {
 		.id_table = pci_id_igb_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igb_dev_init,
 	.eth_dev_uninit = eth_igb_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
+RTE_EAL_PCI_REGISTER(igb, rte_igb_pmd.pci_drv);
+
 /*
  * virtual function driver struct
  */
@@ -989,18 +993,15 @@ static struct eth_driver rte_igbvf_pmd = {
 		.name = "rte_igbvf_pmd",
 		.id_table = pci_id_igbvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igbvf_dev_init,
 	.eth_dev_uninit = eth_igbvf_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_igb_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(igbvf, rte_igbvf_pmd.pci_drv);
 
 static void
 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
@@ -1013,20 +1014,6 @@ igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
 }
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
- */
-static int
-rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_igbvf_pmd);
-	return 0;
-}
-
 static int
 igb_check_mq_mode(struct rte_eth_dev *dev)
 {
@@ -4802,16 +4789,6 @@ eth_igb_set_eeprom(struct rte_eth_dev *dev,
 	return nvm->ops.write(hw,  first, length, data);
 }
 
-static struct rte_driver pmd_igb_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igb_pmd_init,
-};
-
-static struct rte_driver pmd_igbvf_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igbvf_pmd_init,
-};
-
 static int
 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
@@ -4972,6 +4949,3 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 
 	E1000_WRITE_FLUSH(hw);
 }
-
-PMD_REGISTER_DRIVER(pmd_igb_drv);
-PMD_REGISTER_DRIVER(pmd_igbvf_drv);
drivers/net/ena/ena_ethdev.c +3 -15
index 8d01e9a..ba6f771 100644
@@ -1431,23 +1431,11 @@ static struct eth_driver rte_ena_pmd = {
 		.name = "rte_ena_pmd",
 		.id_table = pci_id_ena_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_ena_dev_init,
 	.dev_private_size = sizeof(struct ena_adapter),
 };
 
-static int
-rte_ena_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_ena_pmd);
-	return 0;
-};
-
-struct rte_driver ena_pmd_drv = {
-	.name = "ena_driver",
-	.type = PMD_PDEV,
-	.init = rte_ena_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(ena_pmd_drv);
+RTE_EAL_PCI_REGISTER(ena, rte_ena_pmd.pci_drv);
drivers/net/enic/enic_ethdev.c +3 -20
index 6bea940..7539811 100644
@@ -660,28 +660,11 @@ static struct eth_driver rte_enic_pmd = {
 		.name = "rte_enic_pmd",
 		.id_table = pci_id_enic_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_enicpmd_dev_init,
 	.dev_private_size = sizeof(struct enic),
 };
 
-/* Driver initialization routine.
- * Invoked once at EAL init time.
- * Register as the [Poll Mode] Driver of Cisco ENIC device.
- */
-static int
-rte_enic_pmd_init(__rte_unused const char *name,
-	 __rte_unused const char *params)
-{
-	ENICPMD_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_enic_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_enic_driver = {
-	.type = PMD_PDEV,
-	.init = rte_enic_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_enic_driver);
+RTE_EAL_PCI_REGISTER(enic, rte_enic_pmd.pci_drv);
drivers/net/fm10k/fm10k_ethdev.c +3 -20
index c2d377f..146bc2a 100644
@@ -3030,29 +3030,12 @@ static struct eth_driver rte_pmd_fm10k = {
 		.id_table = pci_id_fm10k_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_fm10k_dev_init,
 	.eth_dev_uninit = eth_fm10k_dev_uninit,
 	.dev_private_size = sizeof(struct fm10k_adapter),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI FM10K devices.
- */
-static int
-rte_pmd_fm10k_init(__rte_unused const char *name,
-	__rte_unused const char *params)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_pmd_fm10k);
-	return 0;
-}
-
-static struct rte_driver rte_fm10k_driver = {
-	.type = PMD_PDEV,
-	.init = rte_pmd_fm10k_init,
-};
-
-PMD_REGISTER_DRIVER(rte_fm10k_driver);
+RTE_EAL_PCI_REGISTER(fm10k, rte_pmd_fm10k.pci_drv);
drivers/net/i40e/i40e_ethdev.c +4 -22
index 24777d5..07c36d7 100644
@@ -641,12 +641,16 @@ static struct eth_driver rte_i40e_pmd = {
 		.id_table = pci_id_i40e_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_i40e_dev_init,
 	.eth_dev_uninit = eth_i40e_dev_uninit,
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
+RTE_EAL_PCI_REGISTER(i40e, rte_i40e_pmd.pci_drv);
+
 static inline int
 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
 				     struct rte_eth_link *link)
@@ -676,28 +680,6 @@ rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
 }
 
 /*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
- */
-static int
-rte_i40e_pmd_init(const char *name __rte_unused,
-		  const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_i40e_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_i40e_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40e_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40e_driver);
-
-/*
  * Initialize registers for flexible payload, which should be set by NVM.
  * This should be removed from code once it is fixed in NVM.
  */
drivers/net/i40e/i40e_ethdev_vf.c +3 -22
index 90682ac..4782ac0 100644
@@ -1536,34 +1536,15 @@ static struct eth_driver rte_i40evf_pmd = {
 		.name = "rte_i40evf_pmd",
 		.id_table = pci_id_i40evf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = i40evf_dev_init,
 	.eth_dev_uninit = i40evf_dev_uninit,
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
- */
-static int
-rte_i40evf_pmd_init(const char *name __rte_unused,
-		    const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_i40evf_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_i40evf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40evf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40evf_driver);
+RTE_EAL_PCI_REGISTER(i40evf, rte_i40evf_pmd.pci_drv);
 
 static int
 i40evf_dev_configure(struct rte_eth_dev *dev)
drivers/net/ixgbe/ixgbe_ethdev.c +7 -40

74 lines not on this page · raw message

drivers/net/mlx4/mlx4.c +3 -17
index 9ed1491..b594433 100644
@@ -5837,15 +5837,10 @@ static struct eth_driver mlx4_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx4_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx4_pmd_init);
+static void
+rte_mlx4_pmd_init(void)
 {
-	(void)name;
-	(void)args;
-
 	RTE_BUILD_BUG_ON(sizeof(wr_id_t) != sizeof(uint64_t));
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
@@ -5856,13 +5851,4 @@ rte_mlx4_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx4_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx4_driver = {
-	.type = PMD_PDEV,
-	.name = MLX4_DRIVER_NAME,
-	.init = rte_mlx4_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx4_driver)
drivers/net/mlx5/mlx5.c +3 -16
index 041cfc3..1989a37 100644
@@ -646,14 +646,10 @@ static struct eth_driver mlx5_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx5_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx5_pmd_init);
+static void
+rte_mlx5_pmd_init(void)
 {
-	(void)name;
-	(void)args;
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
 	 * huge pages. Calling ibv_fork_init() during init allows
@@ -663,13 +659,4 @@ rte_mlx5_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx5_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx5_driver = {
-	.type = PMD_PDEV,
-	.name = MLX5_DRIVER_NAME,
-	.init = rte_mlx5_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx5_driver)
drivers/net/nfp/nfp_net.c +3 -18
index ef7011e..c135f8c 100644
@@ -2468,29 +2468,14 @@ static struct eth_driver rte_nfp_net_pmd = {
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			     RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = nfp_net_init,
 	.dev_private_size = sizeof(struct nfp_net_adapter),
 };
 
-static int
-nfp_net_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	PMD_INIT_LOG(INFO, "librte_pmd_nfp_net version %s\n",
-		     NFP_NET_PMD_VERSION);
-
-	rte_eth_driver_register(&rte_nfp_net_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_nfp_net_driver = {
-	.type = PMD_PDEV,
-	.init = nfp_net_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_nfp_net_driver);
+RTE_EAL_PCI_REGISTER(nfp_net, rte_nfp_net_pmd.pci_drv);
 
 /*
  * Local variables:
drivers/net/szedata2/rte_eth_szedata2.c +3 -22
index 985a8d6..9adccba 100644
@@ -1574,31 +1574,12 @@ static struct eth_driver szedata2_eth_driver = {
 	.pci_drv = {
 		.name     = RTE_SZEDATA2_PCI_DRIVER_NAME,
 		.id_table = rte_szedata2_pci_id_table,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init     = rte_szedata2_eth_dev_init,
 	.eth_dev_uninit   = rte_szedata2_eth_dev_uninit,
 	.dev_private_size = sizeof(struct pmd_internals),
 };
 
-static int
-rte_szedata2_init(const char *name __rte_unused,
-		const char *args __rte_unused)
-{
-	rte_eth_driver_register(&szedata2_eth_driver);
-	return 0;
-}
-
-static int
-rte_szedata2_uninit(const char *name __rte_unused)
-{
-	return 0;
-}
-
-static struct rte_driver rte_szedata2_driver = {
-	.type = PMD_PDEV,
-	.name = RTE_SZEDATA2_DRIVER_NAME,
-	.init = rte_szedata2_init,
-	.uninit = rte_szedata2_uninit,
-};
-
-PMD_REGISTER_DRIVER(rte_szedata2_driver);
+RTE_EAL_PCI_REGISTER(szedata2, szedata2_eth_driver.pci_drv);
drivers/net/virtio/virtio_ethdev.c +7 -19
index c3fb628..14d05fd 100644
@@ -1209,29 +1209,24 @@ static struct eth_driver rte_virtio_pmd = {
 		.name = "rte_virtio_pmd",
 		.id_table = pci_id_virtio_map,
 		.drv_flags = RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_virtio_dev_init,
 	.eth_dev_uninit = eth_virtio_dev_uninit,
 	.dev_private_size = sizeof(struct virtio_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI virtio devices.
- * Returns 0 on success.
- */
-static int
-rte_virtio_pmd_init(const char *name __rte_unused,
-		    const char *param __rte_unused)
+RTE_INIT(rte_virtio_pmd_init);
+static void
+rte_virtio_pmd_init(void)
 {
 	if (rte_eal_iopl_init() != 0) {
 		PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
-		return -1;
+		return;
 	}
 
-	rte_eth_driver_register(&rte_virtio_pmd);
-	return 0;
+	rte_eal_pci_register(&rte_virtio_pmd.pci_drv);
 }
 
 /*
@@ -1453,10 +1448,3 @@ __rte_unused uint8_t is_rx)
 {
 	return 0;
 }
-
-static struct rte_driver rte_virtio_driver = {
-	.type = PMD_PDEV,
-	.init = rte_virtio_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_virtio_driver);
drivers/net/vmxnet3/vmxnet3_ethdev.c +3 -20
index 29b469c..25fec79 100644
@@ -332,25 +332,15 @@ static struct eth_driver rte_vmxnet3_pmd = {
 		.name = "rte_vmxnet3_pmd",
 		.id_table = pci_id_vmxnet3_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_vmxnet3_dev_init,
 	.eth_dev_uninit = eth_vmxnet3_dev_uninit,
 	.dev_private_size = sizeof(struct vmxnet3_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of Virtual PCI VMXNET3 devices.
- */
-static int
-rte_vmxnet3_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_vmxnet3_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(vmxnet3, rte_vmxnet3_pmd.pci_drv);
 
 static int
 vmxnet3_dev_configure(struct rte_eth_dev *dev)
@@ -948,10 +938,3 @@ vmxnet3_process_events(struct vmxnet3_hw *hw)
 
 }
 #endif
-
-static struct rte_driver rte_vmxnet3_driver = {
-	.type = PMD_PDEV,
-	.init = rte_vmxnet3_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_vmxnet3_driver);
Signature · 1 line
2.7.4
#75 lore raw

PATCH v3 9/17 crypto: get rid of crypto driver register callback

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Now that all pdev are pci drivers, we don't need to register crypto drivers through a dedicated channel.

---
 lib/librte_cryptodev/rte_cryptodev.c           | 22 -------------------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 30 --------------------------
 lib/librte_cryptodev/rte_cryptodev_version.map |  1 -
 3 files changed, 53 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +0 -22
index 65a2e29..a7cb33a 100644
@@ -444,28 +444,6 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-int
-rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
-		enum pmd_type type)
-{
-	/* Call crypto device initialization directly if device is virtual */
-	if (type == PMD_VDEV)
-		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
-				NULL);
-
-	/*
-	 * Register PCI driver for physical device intialisation during
-	 * PCI probing
-	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
-
-	rte_eal_pci_register(&cryptodrv->pci_drv);
-
-	return 0;
-}
-
-
 uint16_t
 rte_cryptodev_queue_pair_count(uint8_t dev_id)
 {
lib/librte_cryptodev/rte_cryptodev_pmd.h +0 -30
index 3fb7c7c..99fd69e 100644
@@ -491,36 +491,6 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 extern int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 
-
-/**
- * Register a Crypto [Poll Mode] driver.
- *
- * Function invoked by the initialization function of a Crypto driver
- * to simultaneously register itself as Crypto Poll Mode Driver and to either:
- *
- *	a - register itself as PCI driver if the crypto device is a physical
- *		device, by invoking the rte_eal_pci_register() function to
- *		register the *pci_drv* structure embedded in the *crypto_drv*
- *		structure, after having stored the address of the
- *		rte_cryptodev_init() function in the *devinit* field of the
- *		*pci_drv* structure.
- *
- *		During the PCI probing phase, the rte_cryptodev_init()
- *		function is invoked for each PCI [device] matching the
- *		embedded PCI identifiers provided by the driver.
- *
- *	b, complete the initialization sequence if the device is a virtual
- *		device by calling the rte_cryptodev_init() directly passing a
- *		NULL parameter for the rte_pci_device structure.
- *
- *   @param crypto_drv	crypto_driver structure associated with the crypto
- *					driver.
- *   @param type		pmd type
- */
-extern int
-rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
-		enum pmd_type type);
-
 /**
  * Executes all the user application registered callbacks for the specific
  * device.
lib/librte_cryptodev/rte_cryptodev_version.map +0 -1
index 8d0edfb..e0a9620 100644
@@ -14,7 +14,6 @@ DPDK_16.04 {
 	rte_cryptodev_info_get;
 	rte_cryptodev_pmd_allocate;
 	rte_cryptodev_pmd_callback_process;
-	rte_cryptodev_pmd_driver_register;
 	rte_cryptodev_pmd_release_device;
 	rte_cryptodev_pmd_virtual_dev_init;
 	rte_cryptodev_sym_session_create;
Signature · 1 line
2.7.4
#76 lore raw

PATCH v3 10/17 ethdev: get rid of eth driver register callback

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Now that all pdev are pci drivers, we don't need to register ethdev drivers through a dedicated channel.

---
 lib/librte_ether/rte_ethdev.c          | 22 ----------------------
 lib/librte_ether/rte_ethdev.h          | 12 ------------
 lib/librte_ether/rte_ether_version.map |  1 -
 3 files changed, 35 deletions(-)
lib/librte_ether/rte_ethdev.c +0 -22
index d05eada..7258062 100644
@@ -334,28 +334,6 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-/**
- * Register an Ethernet [Poll Mode] driver.
- *
- * Function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver.
- * Invokes the rte_eal_pci_register() function to register the *pci_drv*
- * structure embedded in the *eth_drv* structure, after having stored the
- * address of the rte_eth_dev_init() function in the *devinit* field of
- * the *pci_drv* structure.
- * During the PCI probing phase, the rte_eth_dev_init() function is
- * invoked for each PCI [Ethernet device] matching the embedded PCI
- * identifiers provided by the driver.
- */
-void
-rte_eth_driver_register(struct eth_driver *eth_drv)
-{
-	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
-	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
-	rte_eal_pci_register(&eth_drv->pci_drv);
-}
-
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
lib/librte_ether/rte_ethdev.h +0 -12
index 6deafa2..64d889e 100644
@@ -1842,18 +1842,6 @@ struct eth_driver {
 };
 
 /**
- * @internal
- * A function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver (PMD).
- *
- * @param eth_drv
- *   The pointer to the *eth_driver* structure associated with
- *   the Ethernet driver.
- */
-void rte_eth_driver_register(struct eth_driver *eth_drv);
-
-/**
  * Convert a numerical speed in Mbps to a bitmap flag that can be used in
  * the bitmap link_speeds of the struct rte_eth_conf
  *
lib/librte_ether/rte_ether_version.map +0 -1
index 31017d4..d457b21 100644
@@ -80,7 +80,6 @@ DPDK_2.2 {
 	rte_eth_dev_vlan_filter;
 	rte_eth_dev_wd_timeout_store;
 	rte_eth_dma_zone_reserve;
-	rte_eth_driver_register;
 	rte_eth_led_off;
 	rte_eth_led_on;
 	rte_eth_link;
Signature · 1 line
2.7.4
#78 lore raw

PATCH v3 11/17 eal/linux: move back interrupt thread init before setting affinity

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Now that virtio pci driver is initialized in a constructor, iopl() stuff happens early enough so that interrupt thread can be created right after plugin loading.
This way, chelsio driver should be happy again [1].

[1] http://dpdk.org/ml/archives/dev/2015-November/028289.html

---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal.c +3 -3
index 5ec3d4e..6eca741 100644
@@ -821,6 +821,9 @@ rte_eal_init(int argc, char **argv)
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
+	if (rte_eal_intr_init() < 0)
+		rte_panic("Cannot init interrupt-handling thread\n");
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
@@ -832,9 +835,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-	if (rte_eal_intr_init() < 0)
-		rte_panic("Cannot init interrupt-handling thread\n");
-
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
 		/*
Signature · 1 line
2.7.4
#79 lore raw

PATCH v3 12/17 pci: add a helper for device name

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev.

---
 lib/librte_cryptodev/rte_cryptodev.c    | 27 ++++-----------------------
 lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 24 ++++--------------------
 3 files changed, 33 insertions(+), 43 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +4 -23
index a7cb33a..3b587e4 100644
@@ -276,23 +276,6 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 	return cryptodev;
 }
 
-static inline int
-rte_cryptodev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	if ((name == NULL) || (pci_dev == NULL))
-		return -EINVAL;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
 {
@@ -355,9 +338,8 @@ rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
 	if (cryptodrv == NULL)
 		return -ENODEV;
 
-	/* Create unique Crypto device name using PCI address */
-	rte_cryptodev_create_unique_device_name(cryptodev_name,
-			sizeof(cryptodev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+			sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
@@ -412,9 +394,8 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique device name using PCI address */
-	rte_cryptodev_create_unique_device_name(cryptodev_name,
-			sizeof(cryptodev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+			sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
 	if (cryptodev == NULL)
lib/librte_eal/common/include/rte_pci.h +25 -0
index d7df1d9..5e8bd89 100644
@@ -82,6 +82,7 @@ extern "C" {
 #include <stdint.h>
 #include <inttypes.h>
 
+#include <rte_debug.h>
 #include <rte_interrupts.h>
 
 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
@@ -95,6 +96,7 @@ const char *pci_get_sysfs_path(void);
 
 /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
 #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
+#define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X")
 
 /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
@@ -308,6 +310,29 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using above functions.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address
+ * @param output
+ *	The output buffer string
+ * @param size
+ *	The output buffer size
+ * @return
+ *  0 on success, negative on error.
+ */
+static inline void
+rte_eal_pci_device_name(const struct rte_pci_addr *addr,
+		    char *output, size_t size)
+{
+	RTE_VERIFY(size >= PCI_PRI_STR_SIZE);
+	RTE_VERIFY(snprintf(output, size, PCI_PRI_FMT,
+			    addr->domain, addr->bus,
+			    addr->devid, addr->function) >= 0);
+}
+
 /* Compare two PCI device addresses. */
 /**
  * Utility function to compare two PCI device addresses.
lib/librte_ether/rte_ethdev.c +4 -20
index 7258062..5bcf610 100644
@@ -214,20 +214,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	return eth_dev;
 }
 
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -251,9 +237,8 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 
 	eth_drv = (struct eth_driver *)pci_drv;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+			sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
 	if (eth_dev == NULL)
@@ -304,9 +289,8 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+			sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocated(ethdev_name);
 	if (eth_dev == NULL)
Signature · 1 line
2.7.4
#81 lore raw

PATCH v3 14/17 ethdev: do not scan all pci devices on attach

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

No need to scan all devices, we only need to update the device being attached.

---
 lib/librte_eal/common/eal_common_pci.c | 11 ++++++++---
 lib/librte_ether/rte_ethdev.c          |  3 ---
 2 files changed, 8 insertions(+), 6 deletions(-)
lib/librte_eal/common/eal_common_pci.c +8 -3
index dfd0a8c..d05dda4 100644
@@ -339,6 +339,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
+	/* update current pci device in global list, kernel bindings might have
+	 * changed since last time we looked at it */
+	if (pci_update_device(addr) < 0)
+		goto err_return;
+
 	TAILQ_FOREACH(dev, &pci_device_list, next) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
@@ -351,9 +356,9 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	return -1;
 
 err_return:
-	RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
-			" cannot be used\n", dev->addr.domain, dev->addr.bus,
-			dev->addr.devid, dev->addr.function);
+	RTE_LOG(WARNING, EAL,
+		"Requested device " PCI_PRI_FMT " cannot be used\n",
+		addr->domain, addr->bus, addr->devid, addr->function);
 	return -1;
 }
 
lib/librte_ether/rte_ethdev.c +0 -3
index 5bcf610..a496521 100644
@@ -463,9 +463,6 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 static int
 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
 {
-	/* re-construct pci_device_list */
-	if (rte_eal_pci_scan())
-		goto err;
 	/* Invoke probe func of the driver can handle the new device. */
 	if (rte_eal_pci_probe_one(addr))
 		goto err;
Signature · 1 line
2.7.4
#82 lore raw

PATCH v3 15/17 eal: add hotplug operations for pci and vdev

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

hotplug which deals with resources should come from the layer that already handles them, i.e. eal.

For both attach and detach operations, 'name' is used to select the bus that will handle the request.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 ++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 25 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 ++
 4 files changed, 68 insertions(+)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
index f8c3dea..e776768 100644
@@ -156,5 +156,7 @@ DPDK_16.07 {
 	global:
 
 	pci_get_sysfs_path;
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
 
 } DPDK_16.04;
lib/librte_eal/common/eal_common_dev.c +39 -0
index a8a4146..59ed3a0 100644
@@ -150,3 +150,42 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+int rte_eal_dev_attach(const char *name, const char *devargs)
+{
+	struct rte_pci_addr addr;
+	int ret = -1;
+
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_probe_one(&addr) < 0)
+			goto err;
+
+	} else {
+		if (rte_eal_vdev_init(name, devargs))
+			goto err;
+	}
+
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	return ret;
+}
+
+int rte_eal_dev_detach(const char *name)
+{
+	struct rte_pci_addr addr;
+
+	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+		if (rte_eal_pci_detach(&addr) < 0)
+			goto err;
+	} else {
+		if (rte_eal_vdev_uninit(name))
+			goto err;
+	}
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
+	return -1;
+}
lib/librte_eal/common/include/rte_dev.h +25 -0
index 85e48f2..b1c0520 100644
@@ -178,6 +178,31 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * Attach a resource to a registered driver.
+ *
+ * @param name
+ *   The resource name, that refers to a pci resource or some private
+ *   way of designating a resource for vdev drivers. Based on this
+ *   resource name, eal will identify a driver capable of handling
+ *   this resource and pass this resource to the driver probing
+ *   function.
+ * @param devargs
+ *   Device arguments to be passed to the driver.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_attach(const char *name, const char *devargs);
+
+/**
+ * Detach a resource from its driver.
+ *
+ * @param name
+ *   Same description as for rte_eal_dev_attach().
+ *   Here, eal will call the driver detaching function.
+ */
+int rte_eal_dev_detach(const char *name);
+
 #define PMD_REGISTER_DRIVER(d)\
 RTE_INIT(devinitfn_ ##d);\
 static void devinitfn_ ##d(void)\
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
index 3d0ff93..50b774b 100644
@@ -159,5 +159,7 @@ DPDK_16.07 {
 	global:
 
 	pci_get_sysfs_path;
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
 
 } DPDK_16.04;
Signature · 1 line
2.7.4
#83 lore raw

PATCH v3 16/17 ethdev: convert to eal hotplug

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Remove bus logic from ethdev hotplug by using eal for this.

Current api is preserved:
- the last port that has been created is tracked to return it to the application when attaching,
- the internal device name is reused when detaching.

We can not get rid of ethdev hotplug yet since we still need some mechanism to inform applications of port creation/removal to substitute for ethdev hotplug api.

dev_type field in struct rte_eth_dev and rte_eth_dev_allocate are kept as is, but this information is not needed anymore and is removed in the following commit.

---
 lib/librte_ether/rte_ethdev.c | 251 ++++++------------------------------------
 1 file changed, 33 insertions(+), 218 deletions(-)
lib/librte_ether/rte_ethdev.c +33 -218
index a496521..12d24ff 100644
@@ -72,6 +72,7 @@
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
 static struct rte_eth_dev_data *rte_eth_dev_data;
+static uint8_t eth_dev_last_created_port;
 static uint8_t nb_ports;
 
 /* spinlock for eth device callbacks */
@@ -210,6 +211,7 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	eth_dev->data->port_id = port_id;
 	eth_dev->attached = DEV_ATTACHED;
 	eth_dev->dev_type = type;
+	eth_dev_last_created_port = port_id;
 	nb_ports++;
 	return eth_dev;
 }
@@ -341,99 +343,6 @@ rte_eth_dev_count(void)
 	return nb_ports;
 }
 
-static enum rte_eth_dev_type
-rte_eth_dev_get_device_type(uint8_t port_id)
-{
-	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, RTE_ETH_DEV_UNKNOWN);
-	return rte_eth_devices[port_id].dev_type;
-}
-
-static int
-rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
-{
-	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
-
-	if (addr == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	*addr = rte_eth_devices[port_id].pci_dev->addr;
-	return 0;
-}
-
-static int
-rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
-{
-	char *tmp;
-
-	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
-
-	if (name == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	/* shouldn't check 'rte_eth_devices[i].data',
-	 * because it might be overwritten by VDEV PMD */
-	tmp = rte_eth_dev_data[port_id].name;
-	strcpy(name, tmp);
-	return 0;
-}
-
-static int
-rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
-{
-	int i;
-
-	if (name == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	*port_id = RTE_MAX_ETHPORTS;
-
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-
-		if (!strncmp(name,
-			rte_eth_dev_data[i].name, strlen(name))) {
-
-			*port_id = i;
-
-			return 0;
-		}
-	}
-	return -ENODEV;
-}
-
-static int
-rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
-{
-	int i;
-	struct rte_pci_device *pci_dev = NULL;
-
-	if (addr == NULL) {
-		RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
-		return -EINVAL;
-	}
-
-	*port_id = RTE_MAX_ETHPORTS;
-
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-
-		pci_dev = rte_eth_devices[i].pci_dev;
-
-		if (pci_dev &&
-			!rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
-
-			*port_id = i;
-
-			return 0;
-		}
-	}
-	return -ENODEV;
-}
-
 static int
 rte_eth_dev_is_detachable(uint8_t port_id)
 {
@@ -459,124 +368,45 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		return 1;
 }
 
-/* attach the new physical device, then store port_id of the device */
-static int
-rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
-{
-	/* Invoke probe func of the driver can handle the new device. */
-	if (rte_eal_pci_probe_one(addr))
-		goto err;
-
-	if (rte_eth_dev_get_port_by_addr(addr, port_id))
-		goto err;
-
-	return 0;
-err:
-	return -1;
-}
-
-/* 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)
-{
-	struct rte_pci_addr freed_addr;
-	struct rte_pci_addr vp;
-
-	/* get pci address by port id */
-	if (rte_eth_dev_get_addr_by_port(port_id, &freed_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)
-		goto err;
-
-	/* invoke devuninit func of the pci driver,
-	 * also remove the device from pci_device_list */
-	if (rte_eal_pci_detach(&freed_addr))
-		goto err;
-
-	*addr = freed_addr;
-	return 0;
-err:
-	return -1;
-}
-
-/* attach the new virtual device, then store port_id of the device */
-static int
-rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
-{
-	char *name = NULL, *args = NULL;
-	int ret = -1;
-
-	/* parse vdevargs, then retrieve device name and args */
-	if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
-		goto end;
-
-	/* walk around dev_driver_list to find the driver of the device,
-	 * then invoke probe function of the driver.
-	 * rte_eal_vdev_init() updates port_id allocated after
-	 * initialization.
-	 */
-	if (rte_eal_vdev_init(name, args))
-		goto end;
-
-	if (rte_eth_dev_get_port_by_name(name, port_id))
-		goto end;
-
-	ret = 0;
-end:
-	free(name);
-	free(args);
-
-	return ret;
-}
-
-/* detach the new virtual device, then store the name of the device */
-static int
-rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
-{
-	char name[RTE_ETH_NAME_MAX_LEN];
-
-	/* get device name by port id */
-	if (rte_eth_dev_get_name_by_port(port_id, name))
-		goto err;
-	/* walk around dev_driver_list to find the driver of the device,
-	 * then invoke uninit function of the driver */
-	if (rte_eal_vdev_uninit(name))
-		goto err;
-
-	strncpy(vdevname, name, sizeof(name));
-	return 0;
-err:
-	return -1;
-}
-
 /* attach the new device, then store port_id of the device */
 int
 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
-	struct rte_pci_addr addr;
 	int ret = -1;
+	int current = eth_dev_last_created_port;
+	char *name = NULL;
+	char *args = NULL;
 
 	if ((devargs == NULL) || (port_id == NULL)) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
-		ret = rte_eth_dev_attach_pdev(&addr, port_id);
-		if (ret < 0)
-			goto err;
-	} else {
-		ret = rte_eth_dev_attach_vdev(devargs, port_id);
-		if (ret < 0)
-			goto err;
+	/* parse devargs, then retrieve device name and args */
+	if (rte_eal_parse_devargs_str(devargs, &name, &args))
+		goto err;
+
+	ret = rte_eal_dev_attach(name, args);
+	if (ret < 0)
+		goto err;
+
+	/* no point looking at eth_dev_last_created_port if no port exists */
+	if (!nb_ports) {
+		ret = -1;
+		goto err;
 	}
+	/* if nothing happened, there is a bug here, since some driver told us
+	 * it did attach a device, but did not create a port */
+	if (current == eth_dev_last_created_port) {
+		ret = -1;
+		goto err;
+	}
+	*port_id = eth_dev_last_created_port;
+	ret = 0;
 
-	return 0;
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	free(name);
+	free(args);
 	return ret;
 }
 
@@ -584,7 +414,6 @@ err:
 int
 rte_eth_dev_detach(uint8_t port_id, char *name)
 {
-	struct rte_pci_addr addr;
 	int ret = -1;
 
 	if (name == NULL) {
@@ -592,33 +421,19 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 		goto err;
 	}
 
-	/* check whether the driver supports detach feature, or not */
+	/* FIXME: move this to eal, once device flags are relocated there */
 	if (rte_eth_dev_is_detachable(port_id))
 		goto err;
 
-	if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
-		ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
-		if (ret < 0)
-			goto err;
-
-		ret = rte_eth_dev_detach_pdev(port_id, &addr);
-		if (ret < 0)
-			goto err;
-
-		snprintf(name, RTE_ETH_NAME_MAX_LEN,
-			"%04x:%02x:%02x.%d",
-			addr.domain, addr.bus,
-			addr.devid, addr.function);
-	} else {
-		ret = rte_eth_dev_detach_vdev(port_id, name);
-		if (ret < 0)
-			goto err;
-	}
+	snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
+		 "%s", rte_eth_devices[port_id].data->name);
+	ret = rte_eal_dev_detach(name);
+	if (ret < 0)
+		goto err;
 
 	return 0;
 
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
 	return ret;
 }
 
Signature · 1 line
2.7.4
#80 lore raw

PATCH v3 13/17 pci: add a helper to update a device

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

This helper updates a pci device object with latest information it can find.
It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c     | 49 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c  |  2 --
 lib/librte_eal/common/eal_private.h     | 13 +++++++++
 lib/librte_eal/common/include/rte_pci.h |  3 ++
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 13 +++++++++
 5 files changed, 78 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +49 -0
index 880483d..013c953 100644
@@ -406,6 +406,55 @@ error:
 	return -1;
 }
 
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+	int fd;
+	struct pci_conf matches[2];
+	struct pci_match_conf match = {
+		.pc_sel = {
+			.pc_domain = addr->domain,
+			.pc_bus = addr->bus,
+			.pc_dev = addr->devid,
+			.pc_func = addr->function,
+		},
+	};
+	struct pci_conf_io conf_io = {
+		.pat_buf_len = 0,
+		.num_patterns = 1,
+		.patterns = &match,
+		.match_buf_len = sizeof(matches),
+		.matches = &matches[0],
+	};
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+				__func__, strerror(errno));
+		goto error;
+	}
+
+	if (conf_io.num_matches != 1)
+		goto error;
+
+	if (pci_scan_one(fd, &matches[0]) < 0)
+		goto error;
+
+	close(fd);
+
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
 			    void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_common_pci.c +0 -2
index fee4aa5..dfd0a8c 100644
@@ -87,8 +87,6 @@ struct pci_driver_list pci_driver_list =
 struct pci_device_list pci_device_list =
 	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
-#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
-
 const char *pci_get_sysfs_path(void)
 {
 	const char *path = NULL;
lib/librte_eal/common/eal_private.h +13 -0
index 06a68f6..b8ff9c5 100644
@@ -152,6 +152,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Update a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.
+ */
+int pci_update_device(const struct rte_pci_addr *addr);
+
+/**
  * Unbind kernel driver for this device
  *
  * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +3 -0
index 5e8bd89..02d460a 100644
@@ -107,6 +107,9 @@ const char *pci_get_sysfs_path(void);
 /** Nb. of values in PCI resource format. */
 #define PCI_RESOURCE_FMT_NVAL 3
 
+/** Default sysfs path for PCI device search. */
+#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
+
 /**
  * A structure describing a PCI resource.
  */
lib/librte_eal/linuxapp/eal/eal_pci.c +13 -0
index bfc410f..0a368c5 100644
@@ -417,6 +417,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 	return 0;
 }
 
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+	char filename[PATH_MAX];
+
+	snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
+		 SYSFS_PCI_DEVICES, addr->domain, addr->bus, addr->devid,
+		 addr->function);
+
+	return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
+			    addr->function);
+}
+
 /*
  * split up a pci address into its constituent parts.
  */
Signature · 1 line
2.7.4
#84 lore raw

PATCH v3 17/17 ethdev: get rid of device type

In reply to Shreyansh Jain

From: David Marchand <[email protected]>

Now that hotplug has been moved to eal, there is no reason to keep the device type in this layer.

---
 app/test/virtual_pmd.c                    |  2 +-
 drivers/net/af_packet/rte_eth_af_packet.c |  2 +-
 drivers/net/bonding/rte_eth_bond_api.c    |  2 +-
 drivers/net/cxgbe/cxgbe_main.c            |  2 +-
 drivers/net/mlx4/mlx4.c                   |  2 +-
 drivers/net/mlx5/mlx5.c                   |  2 +-
 drivers/net/mpipe/mpipe_tilegx.c          |  2 +-
 drivers/net/null/rte_eth_null.c           |  2 +-
 drivers/net/pcap/rte_eth_pcap.c           |  2 +-
 drivers/net/ring/rte_eth_ring.c           |  2 +-
 drivers/net/vhost/rte_eth_vhost.c         |  2 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c     |  2 +-
 examples/ip_pipeline/init.c               | 22 ----------------------
 lib/librte_ether/rte_ethdev.c             |  5 ++---
 lib/librte_ether/rte_ethdev.h             | 15 +--------------
 15 files changed, 15 insertions(+), 51 deletions(-)
app/test/virtual_pmd.c +1 -1
index b4bd2f2..8a1f0d0 100644
@@ -581,7 +581,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 		goto err;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto err;
 
drivers/net/af_packet/rte_eth_af_packet.c +1 -1
index f17bd7e..36ac102 100644
@@ -648,7 +648,7 @@ rte_pmd_init_internals(const char *name,
 	}
 
 	/* reserve an ethdev entry */
-	*eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	*eth_dev = rte_eth_dev_allocate(name);
 	if (*eth_dev == NULL)
 		goto error;
 
drivers/net/bonding/rte_eth_bond_api.c +1 -1
index 53df9fe..b858ee1 100644
@@ -189,7 +189,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 	}
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL) {
 		RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev");
 		goto err;
drivers/net/cxgbe/cxgbe_main.c +1 -1
index ceaf5ab..922155b 100644
@@ -1150,7 +1150,7 @@ int cxgbe_probe(struct adapter *adapter)
 		 */
 
 		/* reserve an ethdev entry */
-		pi->eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+		pi->eth_dev = rte_eth_dev_allocate(name);
 		if (!pi->eth_dev)
 			goto out_free;
 
drivers/net/mlx4/mlx4.c +1 -1
index b594433..ba42c33 100644
@@ -5715,7 +5715,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
 			snprintf(name, sizeof(name), "%s port %u",
 				 ibv_get_device_name(ibv_dev), port);
-			eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+			eth_dev = rte_eth_dev_allocate(name);
 		}
 		if (eth_dev == NULL) {
 			ERROR("can not allocate rte ethdev");
drivers/net/mlx5/mlx5.c +1 -1
index 1989a37..f6399fc 100644
@@ -519,7 +519,7 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
 			snprintf(name, sizeof(name), "%s port %u",
 				 ibv_get_device_name(ibv_dev), port);
-			eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+			eth_dev = rte_eth_dev_allocate(name);
 		}
 		if (eth_dev == NULL) {
 			ERROR("can not allocate rte ethdev");
drivers/net/mpipe/mpipe_tilegx.c +1 -1
index 26e1424..9de556e 100644
@@ -1587,7 +1587,7 @@ rte_pmd_mpipe_devinit(const char *ifname,
 		return -ENODEV;
 	}
 
-	eth_dev = rte_eth_dev_allocate(ifname, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(ifname);
 	if (!eth_dev) {
 		RTE_LOG(ERR, PMD, "%s: Failed to allocate device.\n", ifname);
 		rte_free(priv);
drivers/net/null/rte_eth_null.c +1 -1
index 5e8e203..e6c74a6 100644
@@ -514,7 +514,7 @@ eth_dev_null_create(const char *name,
 		goto error;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto error;
 
drivers/net/pcap/rte_eth_pcap.c +1 -1
index c98e234..2d00d04 100644
@@ -822,7 +822,7 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
 		goto error;
 
 	/* reserve an ethdev entry */
-	*eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	*eth_dev = rte_eth_dev_allocate(name);
 	if (*eth_dev == NULL)
 		goto error;
 
drivers/net/ring/rte_eth_ring.c +1 -1
index b1783c3..b78d1cf 100644
@@ -303,7 +303,7 @@ do_eth_dev_ring_create(const char *name,
 	}
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL) {
 		rte_errno = ENOSPC;
 		goto error;
drivers/net/vhost/rte_eth_vhost.c +1 -1
index 310cbef..4e99360 100644
@@ -717,7 +717,7 @@ eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues,
 		goto error;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto error;
 
drivers/net/xenvirt/rte_eth_xenvirt.c +1 -1
index 1adeb5b..72861d8 100644
@@ -651,7 +651,7 @@ eth_dev_xenvirt_create(const char *name, const char *params,
 		goto err;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	eth_dev = rte_eth_dev_allocate(name);
 	if (eth_dev == NULL)
 		goto err;
 
examples/ip_pipeline/init.c +0 -22
index 7120bab..0933a5f 100644
@@ -606,29 +606,12 @@ app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
 	}
 }
 
-static int
-app_link_is_virtual(struct app_link_params *p)
-{
-	uint32_t pmd_id = p->pmd_id;
-	struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
-
-	if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
-		return 1;
-
-	return 0;
-}
-
 void
 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
 {
 	uint32_t i;
 	int status;
 
-	if (app_link_is_virtual(cp)) {
-		cp->state = 1;
-		return;
-	}
-
 	/* For each link, add filters for IP of current link */
 	if (cp->ip != 0) {
 		for (i = 0; i < app->n_links; i++) {
@@ -736,11 +719,6 @@ app_link_down_internal(struct app_params *app, struct app_link_params *cp)
 	uint32_t i;
 	int status;
 
-	if (app_link_is_virtual(cp)) {
-		cp->state = 0;
-		return;
-	}
-
 	/* PMD link down */
 	status = rte_eth_dev_set_link_down(cp->pmd_id);
 	if (status < 0)
lib/librte_ether/rte_ethdev.c +2 -3
index 12d24ff..35ec7f3 100644
@@ -185,7 +185,7 @@ rte_eth_dev_find_free_port(void)
 }
 
 struct rte_eth_dev *
-rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
+rte_eth_dev_allocate(const char *name)
 {
 	uint8_t port_id;
 	struct rte_eth_dev *eth_dev;
@@ -210,7 +210,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
 	eth_dev->data->port_id = port_id;
 	eth_dev->attached = DEV_ATTACHED;
-	eth_dev->dev_type = type;
 	eth_dev_last_created_port = port_id;
 	nb_ports++;
 	return eth_dev;
@@ -242,7 +241,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
 			sizeof(ethdev_name));
 
-	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
+	eth_dev = rte_eth_dev_allocate(ethdev_name);
 	if (eth_dev == NULL)
 		return -ENOMEM;
 
lib/librte_ether/rte_ethdev.h +1 -14
index 64d889e..92876e5 100644
@@ -1574,17 +1574,6 @@ struct rte_eth_rxtx_callback {
 };
 
 /**
- * The eth device type.
- */
-enum rte_eth_dev_type {
-	RTE_ETH_DEV_UNKNOWN,	/**< unknown device type */
-	RTE_ETH_DEV_PCI,
-		/**< Physical function and Virtual function of PCI devices */
-	RTE_ETH_DEV_VIRTUAL,	/**< non hardware device */
-	RTE_ETH_DEV_MAX		/**< max value of this enum */
-};
-
-/**
  * @internal
  * The generic data structure associated with each ethernet device.
  *
@@ -1614,7 +1603,6 @@ struct rte_eth_dev {
 	 */
 	struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
 	uint8_t attached; /**< Flag indicating the port is attached */
-	enum rte_eth_dev_type dev_type; /**< Flag indicating the device type */
 };
 
 struct rte_eth_dev_sriov {
@@ -1727,8 +1715,7 @@ struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
  * @return
  *   - Slot in the rte_dev_devices array for a new device;
  */
-struct rte_eth_dev *rte_eth_dev_allocate(const char *name,
-		enum rte_eth_dev_type type);
+struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
 
 /**
  * @internal
Signature · 1 line
2.7.4
#77 lore raw

Re: [PATCH v3 10/17] ethdev: get rid of eth driver register callback

In reply to Shreyansh Jain
Quoted 32 lines · Shreyansh Jain

From: David Marchand <[email protected]>

Now that all pdev are pci drivers, we don't need to register ethdev drivers through a dedicated channel.

---
 lib/librte_ether/rte_ethdev.c          | 22 ----------------------
 lib/librte_ether/rte_ethdev.h          | 12 ------------
 lib/librte_ether/rte_ether_version.map |  1 -
 3 files changed, 35 deletions(-)
lib/librte_ether/rte_ethdev.c +0 -12
index d05eada..7258062 100644
@@ -334,28 +334,6 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-/**
- * Register an Ethernet [Poll Mode] driver.
- *
- * Function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver.
- * Invokes the rte_eal_pci_register() function to register the *pci_drv*
- * structure embedded in the *eth_drv* structure, after having stored the
- * address of the rte_eth_dev_init() function in the *devinit* field of
- * the *pci_drv* structure.
- * During the PCI probing phase, the rte_eth_dev_init() function is
- * invoked for each PCI [Ethernet device] matching the embedded PCI

lib/librte_ether/rte_ethdev.c rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev) · line 358

Quoted 10 lines
lib/librte_ether/rte_ethdev.c +0 -10
- * identifiers provided by the driver.
- */
-void
-rte_eth_driver_register(struct eth_driver *eth_drv)
-{
-	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
-	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
-	rte_eal_pci_register(&eth_drv->pci_drv);
-}
-

Self review (as I rebased this series):

With this applied on master (3901ed99), it would cause issues with qede driver. qede driver uses the rte_eth_driver_register() function. I will update it (qede driver) and post another version.

Quoted 32 lines
lib/librte_ether/rte_ethdev.c +0 -0
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
lib/librte_ether/rte_ethdev.h +0 -12
index 6deafa2..64d889e 100644
@@ -1842,18 +1842,6 @@ struct eth_driver {
 };
 
 /**
- * @internal
- * A function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver (PMD).
- *
- * @param eth_drv
- *   The pointer to the *eth_driver* structure associated with
- *   the Ethernet driver.
- */
-void rte_eth_driver_register(struct eth_driver *eth_drv);
-
-/**
  * Convert a numerical speed in Mbps to a bitmap flag that can be used in
  * the bitmap link_speeds of the struct rte_eth_conf
  *
lib/librte_ether/rte_ether_version.map +0 -0
index 31017d4..d457b21 100644

lib/librte_ether/rte_ether_version.map DPDK_2.2 { · line 85

Quoted 7 lines
lib/librte_ether/rte_ether_version.map +0 -1
@@ -80,7 +80,6 @@ DPDK_2.2 {
 	rte_eth_dev_vlan_filter;
 	rte_eth_dev_wd_timeout_store;
 	rte_eth_dma_zone_reserve;
-	rte_eth_driver_register;
 	rte_eth_led_off;
 	rte_eth_led_on;
 	rte_eth_link;

-
Shreyansh

#85 lore raw

v4 cover prepare for rte_device / rte_driver

In reply to David Marchand

* Original patch series is from David Marchand [1], [2].
* Cover letter text has been modified to make it author agnostic

David created the original patchset based on the discussions on list [3]. Being a large piece of work, this patchset introduces first level of changes for generalizing the driver-device relationship for supporting hotplug.

Pending work, as per discussions in thread [3]:
- Heirarchical relationship between rte_driver/device, pci_*, crypto_*
- Cleaner device init/deinit methods (probably from rte_driver onwards)
- Moving generic flags/fields from pci_* structure to rte_* structure
- Removing dependency on devargs for pdev/vdev distinction
- Device/Driver lists: discussion and decision on separate or unified lists

Changes since v3:
- rebase over HEAD (913154e)
- Update arguments to RTE_EAL_PCI_REGISTER macro as per Jan's suggestion
- modify qede driver to use RTE_EAL_PCI_REGISTER
- Argument check in hotplug functions

Changes since v2:
- rebase over HEAD (d76c193)
- Move SYSFS_PCI_DRIVERS macro to rte_pci.h to avoid compilation issue

Changes since v1:
- rebased on HEAD, new drivers should be okay
- patches have been split into smaller pieces
- RTE_INIT macro has been added, but in the end, I am not sure it is useful
- device type has been removed from ethdev, as it was used only by hotplug
- getting rid of pmd type in eal patch (patch 5 of initial series) has been dropped for now, we can do this once vdev drivers have been converted

[1] http://dpdk.org/ml/archives/dev/2016-January/032387.html
[2] http://dpdk.org/ml/archives/dev/2016-April/037686.html
[3] http://dpdk.org/ml/archives/dev/2016-January/031390.html

David Marchand (17):
pci: no need for dynamic tailq init
crypto: no need for a crypto pmd type
drivers: align pci driver definitions
eal: remove duplicate function declaration
eal: introduce init macros
crypto: export init/uninit common wrappers for pci drivers
ethdev: export init/uninit common wrappers for pci drivers
drivers: convert all pdev drivers as pci drivers
crypto: get rid of crypto driver register callback
ethdev: get rid of eth driver register callback eal/linux: move back interrupt thread init before setting affinity
pci: add a helper for device name
pci: add a helper to update a device
ethdev: do not scan all pci devices on attach
eal: add hotplug operations for pci and vdev
ethdev: convert to eal hotplug
ethdev: get rid of device type

 app/test/virtual_pmd.c                          |   2 +-
 drivers/crypto/qat/rte_qat_cryptodev.c          |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |   2 +-
 drivers/net/bnx2x/bnx2x_ethdev.c                |  35 +---
 drivers/net/bonding/rte_eth_bond_api.c          |   2 +-
 drivers/net/cxgbe/cxgbe_ethdev.c                |  24 +--
 drivers/net/cxgbe/cxgbe_main.c                  |   2 +-
 drivers/net/e1000/em_ethdev.c                   |  16 +-
 drivers/net/e1000/igb_ethdev.c                  |  40 +----
 drivers/net/ena/ena_ethdev.c                    |  20 +--
 drivers/net/enic/enic_ethdev.c                  |  23 +--
 drivers/net/fm10k/fm10k_ethdev.c                |  23 +--
 drivers/net/i40e/i40e_ethdev.c                  |  26 +--
 drivers/net/i40e/i40e_ethdev_vf.c               |  25 +--
 drivers/net/ixgbe/ixgbe_ethdev.c                |  47 +----
 drivers/net/mlx4/mlx4.c                         |  22 +--
 drivers/net/mlx5/mlx5.c                         |  21 +--
 drivers/net/mpipe/mpipe_tilegx.c                |   2 +-
 drivers/net/nfp/nfp_net.c                       |  23 +--
 drivers/net/null/rte_eth_null.c                 |   2 +-
 drivers/net/pcap/rte_eth_pcap.c                 |   2 +-
 drivers/net/qede/qede_ethdev.c                  |  40 +----
 drivers/net/ring/rte_eth_ring.c                 |   2 +-
 drivers/net/szedata2/rte_eth_szedata2.c         |  25 +--
 drivers/net/vhost/rte_eth_vhost.c               |   2 +-
 drivers/net/virtio/virtio_ethdev.c              |  26 +--
 drivers/net/vmxnet3/vmxnet3_ethdev.c            |  23 +--
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   2 +-
 examples/ip_pipeline/init.c                     |  22 ---
 lib/librte_cryptodev/rte_cryptodev.c            |  67 ++-----
 lib/librte_cryptodev/rte_cryptodev.h            |   2 -
 lib/librte_cryptodev/rte_cryptodev_pmd.h        |  45 ++---
 lib/librte_cryptodev/rte_cryptodev_version.map  |   9 +-
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  52 +++++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   2 +
 lib/librte_eal/common/eal_common_dev.c          |  47 +++++
 lib/librte_eal/common/eal_common_pci.c          |  19 +-
 lib/librte_eal/common/eal_private.h             |  20 ++-
 lib/librte_eal/common/include/rte_dev.h         |  29 +++-
 lib/librte_eal/common/include/rte_eal.h         |   3 +
 lib/librte_eal/common/include/rte_pci.h         |  36 ++++
 lib/librte_eal/common/include/rte_tailq.h       |   4 +-
 lib/librte_eal/linuxapp/eal/eal.c               |   7 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c           |  16 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   2 +
 lib/librte_ether/rte_ethdev.c                   | 222 +++++-------------------
 lib/librte_ether/rte_ethdev.h                   |  40 ++---
 lib/librte_ether/rte_ether_version.map          |   4 +-
 48 files changed, 395 insertions(+), 750 deletions(-)
Signature · 1 line
2.7.4
#86 lore raw

PATCH v4 1/17 pci: no need for dynamic tailq init

These lists can be initialized once and for all at build time. With this, those lists are only manipulated in a common place (and we could even make them private).

A nice side effect is that pci drivers can now register in constructors.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c    | 3 ---
 lib/librte_eal/common/eal_common_pci.c | 6 ++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 3 ---
 3 files changed, 4 insertions(+), 8 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +0 -3
index 7fdd6f1..880483d 100644
@@ -623,9 +623,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
lib/librte_eal/common/eal_common_pci.c +4 -2
index ba5283d..fee4aa5 100644
@@ -82,8 +82,10 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list;
-struct pci_device_list pci_device_list;
+struct pci_driver_list pci_driver_list =
+	TAILQ_HEAD_INITIALIZER(pci_driver_list);
+struct pci_device_list pci_device_list =
+	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
lib/librte_eal/linuxapp/eal/eal_pci.c +0 -3
index f9c3efd..bfc410f 100644
@@ -743,9 +743,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 int
 rte_eal_pci_init(void)
 {
-	TAILQ_INIT(&pci_driver_list);
-	TAILQ_INIT(&pci_device_list);
-
 	/* for debug purposes, PCI can be disabled */
 	if (internal_config.no_pci)
 		return 0;
Signature · 1 line
2.7.4
#87 lore raw

PATCH v4 2/17 crypto: no need for a crypto pmd type

In reply to Shreyansh Jain

This information is not used and just adds noise.

---
 lib/librte_cryptodev/rte_cryptodev.c     | 8 +++-----
 lib/librte_cryptodev/rte_cryptodev.h     | 2 --
 lib/librte_cryptodev/rte_cryptodev_pmd.h | 3 +--
 3 files changed, 4 insertions(+), 9 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +3 -5
index 960e2d5..b0d806c 100644
@@ -230,7 +230,7 @@ rte_cryptodev_find_free_device_index(void)
 }
 
 struct rte_cryptodev *
-rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
+rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 {
 	struct rte_cryptodev *cryptodev;
 	uint8_t dev_id;
@@ -269,7 +269,6 @@ rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id)
 		cryptodev->data->dev_started = 0;
 
 		cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
-		cryptodev->pmd_type = type;
 
 		cryptodev_globals.nb_devs++;
 	}
@@ -318,7 +317,7 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	struct rte_cryptodev *cryptodev;
 
 	/* allocate device structure */
-	cryptodev = rte_cryptodev_pmd_allocate(name, PMD_VDEV, socket_id);
+	cryptodev = rte_cryptodev_pmd_allocate(name, socket_id);
 	if (cryptodev == NULL)
 		return NULL;
 
@@ -360,8 +359,7 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	rte_cryptodev_create_unique_device_name(cryptodev_name,
 			sizeof(cryptodev_name), pci_dev);
 
-	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, PMD_PDEV,
-			rte_socket_id());
+	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
 		return -ENOMEM;
 
lib/librte_cryptodev/rte_cryptodev.h +0 -2
index 27cf8ef..f22eb43 100644
@@ -700,8 +700,6 @@ struct rte_cryptodev {
 
 	enum rte_cryptodev_type dev_type;
 	/**< Crypto device type */
-	enum pmd_type pmd_type;
-	/**< PMD type - PDEV / VDEV */
 
 	struct rte_cryptodev_cb_list link_intr_cbs;
 	/**< User application callback for interrupts if present */
lib/librte_cryptodev/rte_cryptodev_pmd.h +1 -2
index 7d049ea..c977c61 100644
@@ -454,13 +454,12 @@ struct rte_cryptodev_ops {
  * to that slot for the driver to use.
  *
  * @param	name		Unique identifier name for each device
- * @param	type		Device type of this Crypto device
  * @param	socket_id	Socket to allocate resources on.
  * @return
  *   - Slot in the rte_dev_devices array for a new device;
  */
 struct rte_cryptodev *
-rte_cryptodev_pmd_allocate(const char *name, enum pmd_type type, int socket_id);
+rte_cryptodev_pmd_allocate(const char *name, int socket_id);
 
 /**
  * Creates a new virtual crypto device and returns the pointer
Signature · 1 line
2.7.4
#88 lore raw

PATCH v4 3/17 drivers: align pci driver definitions

In reply to Shreyansh Jain

Pure coding style, but it might make it easier later if we want to move fields in rte_cryptodev_driver and eth_driver structures.

---
 drivers/crypto/qat/rte_qat_cryptodev.c | 2 +-
 drivers/net/ena/ena_ethdev.c           | 2 +-
 drivers/net/nfp/nfp_net.c              | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +1 -1
index a7912f5..08496ab 100644
@@ -116,7 +116,7 @@ crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_
 }
 
 static struct rte_cryptodev_driver rte_qat_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
drivers/net/ena/ena_ethdev.c +1 -1
index e157587..8d01e9a 100644
@@ -1427,7 +1427,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 }
 
 static struct eth_driver rte_ena_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_ena_pmd",
 		.id_table = pci_id_ena_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
drivers/net/nfp/nfp_net.c +1 -1
index 5c9f350..ef7011e 100644
@@ -2463,7 +2463,7 @@ static struct rte_pci_id pci_id_nfp_net_map[] = {
 };
 
 static struct eth_driver rte_nfp_net_pmd = {
-	{
+	.pci_drv = {
 		.name = "rte_nfp_net_pmd",
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
Signature · 1 line
2.7.4
#89 lore raw

PATCH v4 4/17 eal: remove duplicate function declaration

In reply to Shreyansh Jain

rte_eal_dev_init is declared in both eal_private.h and rte_dev.h since its introduction.
This function has been exported in ABI, so remove it from eal_private.h

Fixes e57f20e05177 ("eal: make vdev init path generic for both virtual and pci devices")
---
 lib/librte_eal/common/eal_private.h | 7 -------
 lib/librte_eal/linuxapp/eal/eal.c   | 1 +
 2 files changed, 1 insertion(+), 7 deletions(-)
lib/librte_eal/common/eal_private.h +0 -7
index 857dc3e..06a68f6 100644
@@ -259,13 +259,6 @@ int rte_eal_intr_init(void);
 int rte_eal_alarm_init(void);
 
 /**
- * This function initialises any virtual devices
- *
- * This function is private to the EAL.
- */
-int rte_eal_dev_init(void);
-
-/**
  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
  * etc.) loaded.
  *
lib/librte_eal/linuxapp/eal/eal.c +1 -0
index 4f22c18..29fba52 100644
@@ -70,6 +70,7 @@
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
+#include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_common.h>
 #include <rte_version.h>
Signature · 1 line
2.7.4
#90 lore raw

PATCH v4 5/17 eal: introduce init macros

In reply to Shreyansh Jain

Introduce a RTE_INIT macro used to mark an init function as a constructor. Current eal macros have been converted to use this (no functional impact). RTE_EAL_PCI_REGISTER is added as a helper for pci drivers.

RTE_EAL_PCI_REGISTER assumes that object expanded contains a pci_drv member.

---
 lib/librte_eal/common/include/rte_dev.h   | 4 ++--
 lib/librte_eal/common/include/rte_eal.h   | 3 +++
 lib/librte_eal/common/include/rte_pci.h   | 8 ++++++++
 lib/librte_eal/common/include/rte_tailq.h | 4 ++--
 4 files changed, 15 insertions(+), 4 deletions(-)
lib/librte_eal/common/include/rte_dev.h +2 -2
index f1b5507..85e48f2 100644
@@ -179,8 +179,8 @@ int rte_eal_vdev_init(const char *name, const char *args);
 int rte_eal_vdev_uninit(const char *name);
 
 #define PMD_REGISTER_DRIVER(d)\
-void devinitfn_ ##d(void);\
-void __attribute__((constructor, used)) devinitfn_ ##d(void)\
+RTE_INIT(devinitfn_ ##d);\
+static void devinitfn_ ##d(void)\
 {\
 	rte_eal_driver_register(&d);\
 }
lib/librte_eal/common/include/rte_eal.h +3 -0
index a71d6f5..186f3c6 100644
@@ -252,6 +252,9 @@ static inline int rte_gettid(void)
 	return RTE_PER_LCORE(_thread_id);
 }
 
+#define RTE_INIT(func) \
+static void __attribute__((constructor, used)) func(void)
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/common/include/rte_pci.h +8 -0
index fa74962..ac890fc 100644
@@ -470,6 +470,14 @@ void rte_eal_pci_dump(FILE *f);
  */
 void rte_eal_pci_register(struct rte_pci_driver *driver);
 
+/** Helper for PCI device registeration from driver (eth, crypto) instance */
+#define RTE_EAL_PCI_REGISTER(name) \
+RTE_INIT(pciinitfn_ ##name); \
+static void pciinitfn_ ##name(void) \
+{ \
+	rte_eal_pci_register(&(name).pci_drv); \
+}
+
 /**
  * Unregister a PCI driver.
  *
lib/librte_eal/common/include/rte_tailq.h +2 -2
index 4a686e6..71ed3bb 100644
@@ -148,8 +148,8 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
 int rte_eal_tailq_register(struct rte_tailq_elem *t);
 
 #define EAL_REGISTER_TAILQ(t) \
-void tailqinitfn_ ##t(void); \
-void __attribute__((constructor, used)) tailqinitfn_ ##t(void) \
+RTE_INIT(tailqinitfn_ ##t); \
+static void tailqinitfn_ ##t(void) \
 { \
 	if (rte_eal_tailq_register(&t) < 0) \
 		rte_panic("Cannot initialize tailq: %s\n", t.name); \
Signature · 1 line
2.7.4
#91 lore raw

PATCH v4 6/17 crypto: export init/uninit common wrappers for pci drivers

In reply to Shreyansh Jain

Preparing for getting rid of rte_cryptodev_driver, here are two wrappers that can be used by pci drivers that assume a 1 to 1 association between pci resource and upper interface.

---
 lib/librte_cryptodev/rte_cryptodev.c           | 16 ++++++++--------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 12 ++++++++++++
 lib/librte_cryptodev/rte_cryptodev_version.map |  8 ++++++++
 3 files changed, 28 insertions(+), 8 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +8 -8
index b0d806c..65a2e29 100644
@@ -340,9 +340,9 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 	return cryptodev;
 }
 
-static int
-rte_cryptodev_init(struct rte_pci_driver *pci_drv,
-		struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			struct rte_pci_device *pci_dev)
 {
 	struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -401,8 +401,8 @@ rte_cryptodev_init(struct rte_pci_driver *pci_drv,
 	return -ENXIO;
 }
 
-static int
-rte_cryptodev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct rte_cryptodev_driver *cryptodrv;
 	struct rte_cryptodev *cryptodev;
@@ -450,15 +450,15 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
 {
 	/* Call crypto device initialization directly if device is virtual */
 	if (type == PMD_VDEV)
-		return rte_cryptodev_init((struct rte_pci_driver *)cryptodrv,
+		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
 				NULL);
 
 	/*
 	 * Register PCI driver for physical device intialisation during
 	 * PCI probing
 	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_init;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_uninit;
+	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
+	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
 
 	rte_eal_pci_register(&cryptodrv->pci_drv);
 
lib/librte_cryptodev/rte_cryptodev_pmd.h +12 -0
index c977c61..3fb7c7c 100644
@@ -534,6 +534,18 @@ rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
 				enum rte_cryptodev_event_type event);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
+			    struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a crypto
+ * interface.
+ */
+int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
 
 #ifdef __cplusplus
 }
lib/librte_cryptodev/rte_cryptodev_version.map +8 -0
index 41004e1..8d0edfb 100644
@@ -32,3 +32,11 @@ DPDK_16.04 {
 
 	local: *;
 };
+
+DPDK_16.07 {
+	global:
+
+	rte_cryptodev_pci_probe;
+	rte_cryptodev_pci_remove;
+
+} DPDK_16.04;
Signature · 1 line
2.7.4
#92 lore raw

PATCH v4 7/17 ethdev: export init/uninit common wrappers for pci drivers

In reply to Shreyansh Jain

Preparing for getting rid of eth_drv, here are two wrappers that can be used by pci drivers that assume a 1 to 1 association between pci resource and upper interface.

---
 lib/librte_ether/rte_ethdev.c          | 14 +++++++-------
 lib/librte_ether/rte_ethdev.h          | 13 +++++++++++++
 lib/librte_ether/rte_ether_version.map |  3 +++
 3 files changed, 23 insertions(+), 7 deletions(-)
lib/librte_ether/rte_ethdev.c +7 -7
index 42aaef7..312c42c 100644
@@ -245,9 +245,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 	return 0;
 }
 
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-		 struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+		      struct rte_pci_device *pci_dev)
 {
 	struct eth_driver    *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -299,8 +299,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	return diag;
 }
 
-static int
-rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 {
 	const struct eth_driver *eth_drv;
 	struct rte_eth_dev *eth_dev;
@@ -357,8 +357,8 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 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;
+	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
+	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
 
lib/librte_ether/rte_ethdev.h +13 -0
index bd93bf6..2249466 100644
@@ -4354,6 +4354,19 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id);
 int
 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name);
 
+/**
+ * Wrapper for use by pci drivers as a .devinit function to attach to a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+			  struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .devuninit function to detach a ethdev
+ * interface.
+ */
+int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_ether/rte_ether_version.map +3 -0
index 97ed0b0..cf4581c 100644
@@ -140,4 +140,7 @@ DPDK_16.07 {
 	rte_eth_dev_get_name_by_port;
 	rte_eth_dev_get_port_by_name;
 	rte_eth_xstats_get_names;
+	rte_eth_dev_pci_probe;
+	rte_eth_dev_pci_remove;
+
 } DPDK_16.04;
Signature · 1 line
2.7.4
#93 lore raw

PATCH v4 8/17 drivers: convert all pdev drivers as pci drivers

In reply to Shreyansh Jain

Simplify crypto and ethdev pci drivers init by using newly introduced init macros and helpers.
Those drivers then don't need to register as "rte_driver"s anymore.

virtio and mlx* drivers use the general purpose RTE_INIT macro, as they both need some special stuff to be done before registering a pci driver.

---
 drivers/crypto/qat/rte_qat_cryptodev.c  | 16 +++--------
 drivers/net/bnx2x/bnx2x_ethdev.c        | 35 +++++-------------------
 drivers/net/cxgbe/cxgbe_ethdev.c        | 24 +++--------------
 drivers/net/e1000/em_ethdev.c           | 16 +++--------
 drivers/net/e1000/igb_ethdev.c          | 40 +++++-----------------------
 drivers/net/ena/ena_ethdev.c            | 18 +++----------
 drivers/net/enic/enic_ethdev.c          | 23 +++-------------
 drivers/net/fm10k/fm10k_ethdev.c        | 23 +++-------------
 drivers/net/i40e/i40e_ethdev.c          | 26 +++---------------
 drivers/net/i40e/i40e_ethdev_vf.c       | 25 +++---------------
 drivers/net/ixgbe/ixgbe_ethdev.c        | 47 +++++----------------------------
 drivers/net/mlx4/mlx4.c                 | 20 +++-----------
 drivers/net/mlx5/mlx5.c                 | 19 +++----------
 drivers/net/nfp/nfp_net.c               | 21 +++------------
 drivers/net/qede/qede_ethdev.c          | 40 ++++++----------------------
 drivers/net/szedata2/rte_eth_szedata2.c | 25 +++---------------
 drivers/net/virtio/virtio_ethdev.c      | 26 +++++-------------
 drivers/net/vmxnet3/vmxnet3_ethdev.c    | 23 +++-------------
 18 files changed, 76 insertions(+), 391 deletions(-)
drivers/crypto/qat/rte_qat_cryptodev.c +3 -13
index 08496ab..43bccdc 100644
@@ -120,21 +120,11 @@ static struct rte_cryptodev_driver rte_qat_pmd = {
 		.name = "rte_qat_pmd",
 		.id_table = pci_id_qat_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_cryptodev_pci_probe,
+		.devuninit = rte_cryptodev_pci_remove,
 	},
 	.cryptodev_init = crypto_qat_dev_init,
 	.dev_private_size = sizeof(struct qat_pmd_private),
 };
 
-static int
-rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
-}
-
-static struct rte_driver pmd_qat_drv = {
-	.type = PMD_PDEV,
-	.init = rte_qat_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(pmd_qat_drv);
+RTE_EAL_PCI_REGISTER(rte_qat_pmd);
drivers/net/bnx2x/bnx2x_ethdev.c +7 -28
index 071b44f..5ab3c75 100644
@@ -506,11 +506,15 @@ static struct eth_driver rte_bnx2x_pmd = {
 		.name = "rte_bnx2x_pmd",
 		.id_table = pci_id_bnx2x_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2x_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
+RTE_EAL_PCI_REGISTER(rte_bnx2x_pmd);
+
 /*
  * virtual function driver struct
  */
@@ -519,36 +523,11 @@ static struct eth_driver rte_bnx2xvf_pmd = {
 		.name = "rte_bnx2xvf_pmd",
 		.id_table = pci_id_bnx2xvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_bnx2xvf_dev_init,
 	.dev_private_size = sizeof(struct bnx2x_softc),
 };
 
-static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2x_pmd);
-
-	return 0;
-}
-
-static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_bnx2xvf_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_bnx2x_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2x_pmd_init,
-};
-
-static struct rte_driver rte_bnx2xvf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_bnx2xvf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_bnx2x_driver);
-PMD_REGISTER_DRIVER(rte_bnx2xvf_driver);
+RTE_EAL_PCI_REGISTER(rte_bnx2xvf_pmd);
drivers/net/cxgbe/cxgbe_ethdev.c +3 -21
index 04eddaf..1389371 100644
@@ -869,29 +869,11 @@ static struct eth_driver rte_cxgbe_pmd = {
 		.name = "rte_cxgbe_pmd",
 		.id_table = cxgb4_pci_tbl,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_cxgbe_dev_init,
 	.dev_private_size = sizeof(struct port_info),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI CXGBE devices.
- */
-static int rte_cxgbe_pmd_init(const char *name __rte_unused,
-			      const char *params __rte_unused)
-{
-	CXGBE_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_cxgbe_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_cxgbe_driver = {
-	.name = "cxgbe_driver",
-	.type = PMD_PDEV,
-	.init = rte_cxgbe_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_cxgbe_driver);
+RTE_EAL_PCI_REGISTER(rte_cxgbe_pmd);
drivers/net/e1000/em_ethdev.c +3 -13
index 653be09..1f80c05 100644
@@ -368,18 +368,15 @@ static struct eth_driver rte_em_pmd = {
 		.id_table = pci_id_em_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_em_dev_init,
 	.eth_dev_uninit = eth_em_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_em_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_em_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(em, rte_em_pmd.pci_drv);
 
 static int
 em_hw_init(struct e1000_hw *hw)
@@ -1771,10 +1768,3 @@ eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
 	e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
 	return 0;
 }
-
-struct rte_driver em_pmd_drv = {
-	.type = PMD_PDEV,
-	.init = rte_em_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(em_pmd_drv);
drivers/net/e1000/igb_ethdev.c +7 -33
index b822992..a523944 100644
@@ -983,12 +983,16 @@ static struct eth_driver rte_igb_pmd = {
 		.id_table = pci_id_igb_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igb_dev_init,
 	.eth_dev_uninit = eth_igb_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
+RTE_EAL_PCI_REGISTER(rte_igb_pmd);
+
 /*
  * virtual function driver struct
  */
@@ -997,18 +1001,15 @@ static struct eth_driver rte_igbvf_pmd = {
 		.name = "rte_igbvf_pmd",
 		.id_table = pci_id_igbvf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_igbvf_dev_init,
 	.eth_dev_uninit = eth_igbvf_dev_uninit,
 	.dev_private_size = sizeof(struct e1000_adapter),
 };
 
-static int
-rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_igb_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(rte_igbvf_pmd);
 
 static void
 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
@@ -1021,20 +1022,6 @@ igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
 }
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
- */
-static int
-rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_igbvf_pmd);
-	return 0;
-}
-
 static int
 igb_check_mq_mode(struct rte_eth_dev *dev)
 {
@@ -4844,16 +4831,6 @@ eth_igb_set_eeprom(struct rte_eth_dev *dev,
 	return nvm->ops.write(hw,  first, length, data);
 }
 
-static struct rte_driver pmd_igb_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igb_pmd_init,
-};
-
-static struct rte_driver pmd_igbvf_drv = {
-	.type = PMD_PDEV,
-	.init = rte_igbvf_pmd_init,
-};
-
 static int
 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
@@ -5014,6 +4991,3 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 
 	E1000_WRITE_FLUSH(hw);
 }
-
-PMD_REGISTER_DRIVER(pmd_igb_drv);
-PMD_REGISTER_DRIVER(pmd_igbvf_drv);
drivers/net/ena/ena_ethdev.c +3 -15
index 8d01e9a..dc32435 100644
@@ -1431,23 +1431,11 @@ static struct eth_driver rte_ena_pmd = {
 		.name = "rte_ena_pmd",
 		.id_table = pci_id_ena_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_ena_dev_init,
 	.dev_private_size = sizeof(struct ena_adapter),
 };
 
-static int
-rte_ena_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_ena_pmd);
-	return 0;
-};
-
-struct rte_driver ena_pmd_drv = {
-	.name = "ena_driver",
-	.type = PMD_PDEV,
-	.init = rte_ena_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(ena_pmd_drv);
+RTE_EAL_PCI_REGISTER(rte_ena_pmd);
drivers/net/enic/enic_ethdev.c +3 -20
index 6bea940..d5e395d 100644
@@ -660,28 +660,11 @@ static struct eth_driver rte_enic_pmd = {
 		.name = "rte_enic_pmd",
 		.id_table = pci_id_enic_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_enicpmd_dev_init,
 	.dev_private_size = sizeof(struct enic),
 };
 
-/* Driver initialization routine.
- * Invoked once at EAL init time.
- * Register as the [Poll Mode] Driver of Cisco ENIC device.
- */
-static int
-rte_enic_pmd_init(__rte_unused const char *name,
-	 __rte_unused const char *params)
-{
-	ENICPMD_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_enic_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_enic_driver = {
-	.type = PMD_PDEV,
-	.init = rte_enic_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_enic_driver);
+RTE_EAL_PCI_REGISTER(rte_enic_pmd);
drivers/net/fm10k/fm10k_ethdev.c +3 -20
index ce053b0..8ec8f5e 100644
@@ -3064,29 +3064,12 @@ static struct eth_driver rte_pmd_fm10k = {
 		.id_table = pci_id_fm10k_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_fm10k_dev_init,
 	.eth_dev_uninit = eth_fm10k_dev_uninit,
 	.dev_private_size = sizeof(struct fm10k_adapter),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI FM10K devices.
- */
-static int
-rte_pmd_fm10k_init(__rte_unused const char *name,
-	__rte_unused const char *params)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_pmd_fm10k);
-	return 0;
-}
-
-static struct rte_driver rte_fm10k_driver = {
-	.type = PMD_PDEV,
-	.init = rte_pmd_fm10k_init,
-};
-
-PMD_REGISTER_DRIVER(rte_fm10k_driver);
+RTE_EAL_PCI_REGISTER(rte_pmd_fm10k);
drivers/net/i40e/i40e_ethdev.c +4 -22
index f94ad87..f2712ab 100644
@@ -645,12 +645,16 @@ static struct eth_driver rte_i40e_pmd = {
 		.id_table = pci_id_i40e_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_i40e_dev_init,
 	.eth_dev_uninit = eth_i40e_dev_uninit,
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
+RTE_EAL_PCI_REGISTER(rte_i40e_pmd);
+
 static inline int
 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
 				     struct rte_eth_link *link)
@@ -680,28 +684,6 @@ rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
 }
 
 /*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
- */
-static int
-rte_i40e_pmd_init(const char *name __rte_unused,
-		  const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	rte_eth_driver_register(&rte_i40e_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_i40e_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40e_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40e_driver);
-
-/*
  * Initialize registers for flexible payload, which should be set by NVM.
  * This should be removed from code once it is fixed in NVM.
  */
drivers/net/i40e/i40e_ethdev_vf.c +3 -22
index 37af399..3411831 100644
@@ -1555,34 +1555,15 @@ static struct eth_driver rte_i40evf_pmd = {
 		.name = "rte_i40evf_pmd",
 		.id_table = pci_id_i40evf_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = i40evf_dev_init,
 	.eth_dev_uninit = i40evf_dev_uninit,
 	.dev_private_size = sizeof(struct i40e_adapter),
 };
 
-/*
- * VF Driver initialization routine.
- * Invoked one at EAL init time.
- * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
- */
-static int
-rte_i40evf_pmd_init(const char *name __rte_unused,
-		    const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_i40evf_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_i40evf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_i40evf_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40evf_driver);
+RTE_EAL_PCI_REGISTER(rte_i40evf_pmd);
 
 static int
 i40evf_dev_configure(struct rte_eth_dev *dev)
drivers/net/ixgbe/ixgbe_ethdev.c +7 -40

74 lines not on this page · raw message

drivers/net/mlx4/mlx4.c +3 -17
index 9ed1491..b594433 100644
@@ -5837,15 +5837,10 @@ static struct eth_driver mlx4_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx4_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx4_pmd_init);
+static void
+rte_mlx4_pmd_init(void)
 {
-	(void)name;
-	(void)args;
-
 	RTE_BUILD_BUG_ON(sizeof(wr_id_t) != sizeof(uint64_t));
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
@@ -5856,13 +5851,4 @@ rte_mlx4_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx4_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx4_driver = {
-	.type = PMD_PDEV,
-	.name = MLX4_DRIVER_NAME,
-	.init = rte_mlx4_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx4_driver)
drivers/net/mlx5/mlx5.c +3 -16
index 041cfc3..1989a37 100644
@@ -646,14 +646,10 @@ static struct eth_driver mlx5_driver = {
 	.dev_private_size = sizeof(struct priv)
 };
 
-/**
- * Driver initialization routine.
- */
-static int
-rte_mlx5_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx5_pmd_init);
+static void
+rte_mlx5_pmd_init(void)
 {
-	(void)name;
-	(void)args;
 	/*
 	 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
 	 * huge pages. Calling ibv_fork_init() during init allows
@@ -663,13 +659,4 @@ rte_mlx5_pmd_init(const char *name, const char *args)
 	setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
 	ibv_fork_init();
 	rte_eal_pci_register(&mlx5_driver.pci_drv);
-	return 0;
 }
-
-static struct rte_driver rte_mlx5_driver = {
-	.type = PMD_PDEV,
-	.name = MLX5_DRIVER_NAME,
-	.init = rte_mlx5_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx5_driver)
drivers/net/nfp/nfp_net.c +3 -18
index ef7011e..951c8b4 100644
@@ -2468,29 +2468,14 @@ static struct eth_driver rte_nfp_net_pmd = {
 		.id_table = pci_id_nfp_net_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
 			     RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = nfp_net_init,
 	.dev_private_size = sizeof(struct nfp_net_adapter),
 };
 
-static int
-nfp_net_pmd_init(const char *name __rte_unused,
-		 const char *params __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-	PMD_INIT_LOG(INFO, "librte_pmd_nfp_net version %s\n",
-		     NFP_NET_PMD_VERSION);
-
-	rte_eth_driver_register(&rte_nfp_net_pmd);
-	return 0;
-}
-
-static struct rte_driver rte_nfp_net_driver = {
-	.type = PMD_PDEV,
-	.init = nfp_net_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_nfp_net_driver);
+RTE_EAL_PCI_REGISTER(rte_nfp_net_pmd);
 
 /*
  * Local variables:
drivers/net/qede/qede_ethdev.c +8 -32
index 1273fd3..4fcb54c 100644
@@ -1056,7 +1056,9 @@ static struct eth_driver rte_qedevf_pmd = {
 		    .id_table = pci_id_qedevf_map,
 		    .drv_flags =
 		    RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
-		    },
+		    .devinit = rte_eth_dev_pci_probe,
+		    .devuninit = rte_eth_dev_pci_remove,
+		   },
 	.eth_dev_init = qedevf_eth_dev_init,
 	.eth_dev_uninit = qedevf_eth_dev_uninit,
 	.dev_private_size = sizeof(struct qede_dev),
@@ -1068,39 +1070,13 @@ static struct eth_driver rte_qede_pmd = {
 		    .id_table = pci_id_qede_map,
 		    .drv_flags =
 		    RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
-		    },
+		    .devinit = rte_eth_dev_pci_probe,
+		    .devuninit = rte_eth_dev_pci_remove,
+		   },
 	.eth_dev_init = qede_eth_dev_init,
 	.eth_dev_uninit = qede_eth_dev_uninit,
 	.dev_private_size = sizeof(struct qede_dev),
 };
 
-static int
-rte_qedevf_pmd_init(const char *name __rte_unused,
-		    const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_qedevf_pmd);
-
-	return 0;
-}
-
-static int
-rte_qede_pmd_init(const char *name __rte_unused,
-		  const char *params __rte_unused)
-{
-	rte_eth_driver_register(&rte_qede_pmd);
-
-	return 0;
-}
-
-static struct rte_driver rte_qedevf_driver = {
-	.type = PMD_PDEV,
-	.init = rte_qede_pmd_init
-};
-
-static struct rte_driver rte_qede_driver = {
-	.type = PMD_PDEV,
-	.init = rte_qedevf_pmd_init
-};
-
-PMD_REGISTER_DRIVER(rte_qede_driver);
-PMD_REGISTER_DRIVER(rte_qedevf_driver);
+RTE_EAL_PCI_REGISTER(rte_qede_pmd);
+RTE_EAL_PCI_REGISTER(rte_qedevf_pmd);
drivers/net/szedata2/rte_eth_szedata2.c +3 -22
index 985a8d6..6815dbb 100644
@@ -1574,31 +1574,12 @@ static struct eth_driver szedata2_eth_driver = {
 	.pci_drv = {
 		.name     = RTE_SZEDATA2_PCI_DRIVER_NAME,
 		.id_table = rte_szedata2_pci_id_table,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init     = rte_szedata2_eth_dev_init,
 	.eth_dev_uninit   = rte_szedata2_eth_dev_uninit,
 	.dev_private_size = sizeof(struct pmd_internals),
 };
 
-static int
-rte_szedata2_init(const char *name __rte_unused,
-		const char *args __rte_unused)
-{
-	rte_eth_driver_register(&szedata2_eth_driver);
-	return 0;
-}
-
-static int
-rte_szedata2_uninit(const char *name __rte_unused)
-{
-	return 0;
-}
-
-static struct rte_driver rte_szedata2_driver = {
-	.type = PMD_PDEV,
-	.name = RTE_SZEDATA2_DRIVER_NAME,
-	.init = rte_szedata2_init,
-	.uninit = rte_szedata2_uninit,
-};
-
-PMD_REGISTER_DRIVER(rte_szedata2_driver);
+RTE_EAL_PCI_REGISTER(szedata2_eth_driver);
drivers/net/virtio/virtio_ethdev.c +7 -19
index a833740..9f5faf1 100644
@@ -1255,29 +1255,24 @@ static struct eth_driver rte_virtio_pmd = {
 		.name = "rte_virtio_pmd",
 		.id_table = pci_id_virtio_map,
 		.drv_flags = RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_virtio_dev_init,
 	.eth_dev_uninit = eth_virtio_dev_uninit,
 	.dev_private_size = sizeof(struct virtio_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI virtio devices.
- * Returns 0 on success.
- */
-static int
-rte_virtio_pmd_init(const char *name __rte_unused,
-		    const char *param __rte_unused)
+RTE_INIT(rte_virtio_pmd_init);
+static void
+rte_virtio_pmd_init(void)
 {
 	if (rte_eal_iopl_init() != 0) {
 		PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
-		return -1;
+		return;
 	}
 
-	rte_eth_driver_register(&rte_virtio_pmd);
-	return 0;
+	rte_eal_pci_register(&rte_virtio_pmd.pci_drv);
 }
 
 /*
@@ -1499,10 +1494,3 @@ __rte_unused uint8_t is_rx)
 {
 	return 0;
 }
-
-static struct rte_driver rte_virtio_driver = {
-	.type = PMD_PDEV,
-	.init = rte_virtio_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_virtio_driver);
drivers/net/vmxnet3/vmxnet3_ethdev.c +3 -20
index 29b469c..55d8776 100644
@@ -332,25 +332,15 @@ static struct eth_driver rte_vmxnet3_pmd = {
 		.name = "rte_vmxnet3_pmd",
 		.id_table = pci_id_vmxnet3_map,
 		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
+		.devinit = rte_eth_dev_pci_probe,
+		.devuninit = rte_eth_dev_pci_remove,
 	},
 	.eth_dev_init = eth_vmxnet3_dev_init,
 	.eth_dev_uninit = eth_vmxnet3_dev_uninit,
 	.dev_private_size = sizeof(struct vmxnet3_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of Virtual PCI VMXNET3 devices.
- */
-static int
-rte_vmxnet3_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
-{
-	PMD_INIT_FUNC_TRACE();
-
-	rte_eth_driver_register(&rte_vmxnet3_pmd);
-	return 0;
-}
+RTE_EAL_PCI_REGISTER(rte_vmxnet3);
 
 static int
 vmxnet3_dev_configure(struct rte_eth_dev *dev)
@@ -948,10 +938,3 @@ vmxnet3_process_events(struct vmxnet3_hw *hw)
 
 }
 #endif
-
-static struct rte_driver rte_vmxnet3_driver = {
-	.type = PMD_PDEV,
-	.init = rte_vmxnet3_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_vmxnet3_driver);
Signature · 1 line
2.7.4
#94 lore raw

PATCH v4 9/17 crypto: get rid of crypto driver register callback

In reply to Shreyansh Jain

Now that all pdev are pci drivers, we don't need to register crypto drivers through a dedicated channel.

---
 lib/librte_cryptodev/rte_cryptodev.c           | 22 -------------------
 lib/librte_cryptodev/rte_cryptodev_pmd.h       | 30 --------------------------
 lib/librte_cryptodev/rte_cryptodev_version.map |  1 -
 3 files changed, 53 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +0 -22
index 65a2e29..a7cb33a 100644
@@ -444,28 +444,6 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-int
-rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *cryptodrv,
-		enum pmd_type type)
-{
-	/* Call crypto device initialization directly if device is virtual */
-	if (type == PMD_VDEV)
-		return rte_cryptodev_pci_probe((struct rte_pci_driver *)cryptodrv,
-				NULL);
-
-	/*
-	 * Register PCI driver for physical device intialisation during
-	 * PCI probing
-	 */
-	cryptodrv->pci_drv.devinit = rte_cryptodev_pci_probe;
-	cryptodrv->pci_drv.devuninit = rte_cryptodev_pci_remove;
-
-	rte_eal_pci_register(&cryptodrv->pci_drv);
-
-	return 0;
-}
-
-
 uint16_t
 rte_cryptodev_queue_pair_count(uint8_t dev_id)
 {
lib/librte_cryptodev/rte_cryptodev_pmd.h +0 -30
index 3fb7c7c..99fd69e 100644
@@ -491,36 +491,6 @@ rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
 extern int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
 
-
-/**
- * Register a Crypto [Poll Mode] driver.
- *
- * Function invoked by the initialization function of a Crypto driver
- * to simultaneously register itself as Crypto Poll Mode Driver and to either:
- *
- *	a - register itself as PCI driver if the crypto device is a physical
- *		device, by invoking the rte_eal_pci_register() function to
- *		register the *pci_drv* structure embedded in the *crypto_drv*
- *		structure, after having stored the address of the
- *		rte_cryptodev_init() function in the *devinit* field of the
- *		*pci_drv* structure.
- *
- *		During the PCI probing phase, the rte_cryptodev_init()
- *		function is invoked for each PCI [device] matching the
- *		embedded PCI identifiers provided by the driver.
- *
- *	b, complete the initialization sequence if the device is a virtual
- *		device by calling the rte_cryptodev_init() directly passing a
- *		NULL parameter for the rte_pci_device structure.
- *
- *   @param crypto_drv	crypto_driver structure associated with the crypto
- *					driver.
- *   @param type		pmd type
- */
-extern int
-rte_cryptodev_pmd_driver_register(struct rte_cryptodev_driver *crypto_drv,
-		enum pmd_type type);
-
 /**
  * Executes all the user application registered callbacks for the specific
  * device.
lib/librte_cryptodev/rte_cryptodev_version.map +0 -1
index 8d0edfb..e0a9620 100644
@@ -14,7 +14,6 @@ DPDK_16.04 {
 	rte_cryptodev_info_get;
 	rte_cryptodev_pmd_allocate;
 	rte_cryptodev_pmd_callback_process;
-	rte_cryptodev_pmd_driver_register;
 	rte_cryptodev_pmd_release_device;
 	rte_cryptodev_pmd_virtual_dev_init;
 	rte_cryptodev_sym_session_create;
Signature · 1 line
2.7.4
#95 lore raw

PATCH v4 10/17 ethdev: get rid of eth driver register callback

In reply to Shreyansh Jain

Now that all pdev are pci drivers, we don't need to register ethdev drivers through a dedicated channel.

---
 lib/librte_ether/rte_ethdev.c          | 22 ----------------------
 lib/librte_ether/rte_ethdev.h          | 12 ------------
 lib/librte_ether/rte_ether_version.map |  1 -
 3 files changed, 35 deletions(-)
lib/librte_ether/rte_ethdev.c +0 -22
index 312c42c..06065fe 100644
@@ -340,28 +340,6 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	return 0;
 }
 
-/**
- * Register an Ethernet [Poll Mode] driver.
- *
- * Function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver.
- * Invokes the rte_eal_pci_register() function to register the *pci_drv*
- * structure embedded in the *eth_drv* structure, after having stored the
- * address of the rte_eth_dev_init() function in the *devinit* field of
- * the *pci_drv* structure.
- * During the PCI probing phase, the rte_eth_dev_init() function is
- * invoked for each PCI [Ethernet device] matching the embedded PCI
- * identifiers provided by the driver.
- */
-void
-rte_eth_driver_register(struct eth_driver *eth_drv)
-{
-	eth_drv->pci_drv.devinit = rte_eth_dev_pci_probe;
-	eth_drv->pci_drv.devuninit = rte_eth_dev_pci_remove;
-	rte_eal_pci_register(&eth_drv->pci_drv);
-}
-
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
lib/librte_ether/rte_ethdev.h +0 -12
index 2249466..ffd24e4 100644
@@ -1862,18 +1862,6 @@ struct eth_driver {
 };
 
 /**
- * @internal
- * A function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver (PMD).
- *
- * @param eth_drv
- *   The pointer to the *eth_driver* structure associated with
- *   the Ethernet driver.
- */
-void rte_eth_driver_register(struct eth_driver *eth_drv);
-
-/**
  * Convert a numerical speed in Mbps to a bitmap flag that can be used in
  * the bitmap link_speeds of the struct rte_eth_conf
  *
lib/librte_ether/rte_ether_version.map +0 -1
index cf4581c..8151007 100644
@@ -80,7 +80,6 @@ DPDK_2.2 {
 	rte_eth_dev_vlan_filter;
 	rte_eth_dev_wd_timeout_store;
 	rte_eth_dma_zone_reserve;
-	rte_eth_driver_register;
 	rte_eth_led_off;
 	rte_eth_led_on;
 	rte_eth_link;
Signature · 1 line
2.7.4
#96 lore raw

PATCH v4 11/17 eal/linux: move back interrupt thread init before setting affinity

In reply to Shreyansh Jain

Now that virtio pci driver is initialized in a constructor, iopl() stuff happens early enough so that interrupt thread can be created right after plugin loading.
This way, chelsio driver should be happy again [1].

[1] http://dpdk.org/ml/archives/dev/2015-November/028289.html

---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal.c +3 -3
index 29fba52..748daca 100644
@@ -821,6 +821,9 @@ rte_eal_init(int argc, char **argv)
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
+	if (rte_eal_intr_init() < 0)
+		rte_panic("Cannot init interrupt-handling thread\n");
+
 	eal_thread_init_master(rte_config.master_lcore);
 
 	ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
@@ -832,9 +835,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-	if (rte_eal_intr_init() < 0)
-		rte_panic("Cannot init interrupt-handling thread\n");
-
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
 		/*
Signature · 1 line
2.7.4
#97 lore raw

PATCH v4 12/17 pci: add a helper for device name

In reply to Shreyansh Jain

eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev.

---
 lib/librte_cryptodev/rte_cryptodev.c    | 27 ++++-----------------------
 lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c           | 24 ++++--------------------
 3 files changed, 33 insertions(+), 43 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +4 -23
index a7cb33a..3b587e4 100644
@@ -276,23 +276,6 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 	return cryptodev;
 }
 
-static inline int
-rte_cryptodev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	if ((name == NULL) || (pci_dev == NULL))
-		return -EINVAL;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
 {
@@ -355,9 +338,8 @@ rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
 	if (cryptodrv == NULL)
 		return -ENODEV;
 
-	/* Create unique Crypto device name using PCI address */
-	rte_cryptodev_create_unique_device_name(cryptodev_name,
-			sizeof(cryptodev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+			sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
@@ -412,9 +394,8 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique device name using PCI address */
-	rte_cryptodev_create_unique_device_name(cryptodev_name,
-			sizeof(cryptodev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+			sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
 	if (cryptodev == NULL)
lib/librte_eal/common/include/rte_pci.h +25 -0
index ac890fc..1666a55 100644
@@ -82,6 +82,7 @@ extern "C" {
 #include <stdint.h>
 #include <inttypes.h>
 
+#include <rte_debug.h>
 #include <rte_interrupts.h>
 
 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
@@ -95,6 +96,7 @@ const char *pci_get_sysfs_path(void);
 
 /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
 #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
+#define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X")
 
 /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
@@ -308,6 +310,29 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using above functions.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address
+ * @param output
+ *	The output buffer string
+ * @param size
+ *	The output buffer size
+ * @return
+ *  0 on success, negative on error.
+ */
+static inline void
+rte_eal_pci_device_name(const struct rte_pci_addr *addr,
+		    char *output, size_t size)
+{
+	RTE_VERIFY(size >= PCI_PRI_STR_SIZE);
+	RTE_VERIFY(snprintf(output, size, PCI_PRI_FMT,
+			    addr->domain, addr->bus,
+			    addr->devid, addr->function) >= 0);
+}
+
 /* Compare two PCI device addresses. */
 /**
  * Utility function to compare two PCI device addresses.
lib/librte_ether/rte_ethdev.c +4 -20
index 06065fe..ace8353 100644
@@ -220,20 +220,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	return eth_dev;
 }
 
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
-		struct rte_pci_device *pci_dev)
-{
-	int ret;
-
-	ret = snprintf(name, size, "%d:%d.%d",
-			pci_dev->addr.bus, pci_dev->addr.devid,
-			pci_dev->addr.function);
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -257,9 +243,8 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 
 	eth_drv = (struct eth_driver *)pci_drv;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+			sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
 	if (eth_dev == NULL)
@@ -310,9 +295,8 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (pci_dev == NULL)
 		return -EINVAL;
 
-	/* Create unique Ethernet device name using PCI address */
-	rte_eth_dev_create_unique_device_name(ethdev_name,
-			sizeof(ethdev_name), pci_dev);
+	rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+			sizeof(ethdev_name));
 
 	eth_dev = rte_eth_dev_allocated(ethdev_name);
 	if (eth_dev == NULL)
Signature · 1 line
2.7.4
#98 lore raw

PATCH v4 13/17 pci: add a helper to update a device

In reply to Shreyansh Jain

This helper updates a pci device object with latest information it can find.
It will be used mainly for hotplug code.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c     | 49 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c  |  2 --
 lib/librte_eal/common/eal_private.h     | 13 +++++++++
 lib/librte_eal/common/include/rte_pci.h |  3 ++
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 13 +++++++++
 5 files changed, 78 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +49 -0
index 880483d..013c953 100644
@@ -406,6 +406,55 @@ error:
 	return -1;
 }
 
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+	int fd;
+	struct pci_conf matches[2];
+	struct pci_match_conf match = {
+		.pc_sel = {
+			.pc_domain = addr->domain,
+			.pc_bus = addr->bus,
+			.pc_dev = addr->devid,
+			.pc_func = addr->function,
+		},
+	};
+	struct pci_conf_io conf_io = {
+		.pat_buf_len = 0,
+		.num_patterns = 1,
+		.patterns = &match,
+		.match_buf_len = sizeof(matches),
+		.matches = &matches[0],
+	};
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+				__func__, strerror(errno));
+		goto error;
+	}
+
+	if (conf_io.num_matches != 1)
+		goto error;
+
+	if (pci_scan_one(fd, &matches[0]) < 0)
+		goto error;
+
+	close(fd);
+
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
 /* Read PCI config space. */
 int rte_eal_pci_read_config(const struct rte_pci_device *dev,
 			    void *buf, size_t len, off_t offset)
lib/librte_eal/common/eal_common_pci.c +0 -2
index fee4aa5..dfd0a8c 100644
@@ -87,8 +87,6 @@ struct pci_driver_list pci_driver_list =
 struct pci_device_list pci_device_list =
 	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
-#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
-
 const char *pci_get_sysfs_path(void)
 {
 	const char *path = NULL;
lib/librte_eal/common/eal_private.h +13 -0
index 06a68f6..b8ff9c5 100644
@@ -152,6 +152,19 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Update a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ *	The PCI Bus-Device-Function address to look for
+ * @return
+ *   - 0 on success.
+ *   - negative on error.
+ */
+int pci_update_device(const struct rte_pci_addr *addr);
+
+/**
  * Unbind kernel driver for this device
  *
  * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +3 -0
index 1666a55..eed6b56 100644
@@ -107,6 +107,9 @@ const char *pci_get_sysfs_path(void);
 /** Nb. of values in PCI resource format. */
 #define PCI_RESOURCE_FMT_NVAL 3
 
+/** Default sysfs path for PCI device search. */
+#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
+
 /**
  * A structure describing a PCI resource.
  */
lib/librte_eal/linuxapp/eal/eal_pci.c +13 -0
index bfc410f..0a368c5 100644
@@ -417,6 +417,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 	return 0;
 }
 
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+	char filename[PATH_MAX];
+
+	snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
+		 SYSFS_PCI_DEVICES, addr->domain, addr->bus, addr->devid,
+		 addr->function);
+
+	return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
+			    addr->function);
+}
+
 /*
  * split up a pci address into its constituent parts.
  */
Signature · 1 line
2.7.4
#99 lore raw

PATCH v4 14/17 ethdev: do not scan all pci devices on attach

In reply to Shreyansh Jain

No need to scan all devices, we only need to update the device being attached.

---
 lib/librte_eal/common/eal_common_pci.c | 11 ++++++++---
 lib/librte_ether/rte_ethdev.c          |  3 ---
 2 files changed, 8 insertions(+), 6 deletions(-)
lib/librte_eal/common/eal_common_pci.c +8 -3
index dfd0a8c..d05dda4 100644
@@ -339,6 +339,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
+	/* update current pci device in global list, kernel bindings might have
+	 * changed since last time we looked at it */
+	if (pci_update_device(addr) < 0)
+		goto err_return;
+
 	TAILQ_FOREACH(dev, &pci_device_list, next) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
@@ -351,9 +356,9 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	return -1;
 
 err_return:
-	RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
-			" cannot be used\n", dev->addr.domain, dev->addr.bus,
-			dev->addr.devid, dev->addr.function);
+	RTE_LOG(WARNING, EAL,
+		"Requested device " PCI_PRI_FMT " cannot be used\n",
+		addr->domain, addr->bus, addr->devid, addr->function);
 	return -1;
 }
 
lib/librte_ether/rte_ethdev.c +0 -3
index ace8353..6f2b169 100644
@@ -469,9 +469,6 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 static int
 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
 {
-	/* re-construct pci_device_list */
-	if (rte_eal_pci_scan())
-		goto err;
 	/* Invoke probe func of the driver can handle the new device. */
 	if (rte_eal_pci_probe_one(addr))
 		goto err;
Signature · 1 line
2.7.4
#100 lore raw

PATCH v4 15/17 eal: add hotplug operations for pci and vdev

In reply to Shreyansh Jain

hotplug which deals with resources should come from the layer that already handles them, i.e. eal.

For both attach and detach operations, 'name' is used to select the bus that will handle the request.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 ++
 lib/librte_eal/common/eal_common_dev.c          | 47 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 25 +++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 ++
 4 files changed, 76 insertions(+)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
index 1852c4a..6f9324f 100644
@@ -159,5 +159,7 @@ DPDK_16.07 {
 	rte_keepalive_mark_sleep;
 	rte_keepalive_register_relay_callback;
 	rte_thread_setname;
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
 
 } DPDK_16.04;
lib/librte_eal/common/eal_common_dev.c +47 -0

50 lines not on this page · raw message

lib/librte_eal/common/include/rte_dev.h +25 -0
index 85e48f2..b1c0520 100644
@@ -178,6 +178,31 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * Attach a resource to a registered driver.
+ *
+ * @param name
+ *   The resource name, that refers to a pci resource or some private
+ *   way of designating a resource for vdev drivers. Based on this
+ *   resource name, eal will identify a driver capable of handling
+ *   this resource and pass this resource to the driver probing
+ *   function.
+ * @param devargs
+ *   Device arguments to be passed to the driver.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_attach(const char *name, const char *devargs);
+
+/**
+ * Detach a resource from its driver.
+ *
+ * @param name
+ *   Same description as for rte_eal_dev_attach().
+ *   Here, eal will call the driver detaching function.
+ */
+int rte_eal_dev_detach(const char *name);
+
 #define PMD_REGISTER_DRIVER(d)\
 RTE_INIT(devinitfn_ ##d);\
 static void devinitfn_ ##d(void)\
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
index 0513467..6c6163e 100644
@@ -162,5 +162,7 @@ DPDK_16.07 {
 	rte_keepalive_mark_sleep;
 	rte_keepalive_register_relay_callback;
 	rte_thread_setname;
+	rte_eal_dev_attach;
+	rte_eal_dev_detach;
 
 } DPDK_16.04;
Signature · 1 line
2.7.4
#101 lore raw

PATCH v4 16/17 ethdev: convert to eal hotplug

In reply to Shreyansh Jain

Remove bus logic from ethdev hotplug by using eal for this.

Current api is preserved:
- the last port that has been created is tracked to return it to the application when attaching,
- the internal device name is reused when detaching.

We can not get rid of ethdev hotplug yet since we still need some mechanism to inform applications of port creation/removal to substitute for ethdev hotplug api.

dev_type field in struct rte_eth_dev and rte_eth_dev_allocate are kept as is, but this information is not needed anymore and is removed in the following commit.

---
 lib/librte_ether/rte_ethdev.c | 158 +++++++++---------------------------------
 1 file changed, 33 insertions(+), 125 deletions(-)
lib/librte_ether/rte_ethdev.c +33 -125
index 6f2b169..28604ca 100644
@@ -72,6 +72,7 @@
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
 static struct rte_eth_dev_data *rte_eth_dev_data;
+static uint8_t eth_dev_last_created_port;
 static uint8_t nb_ports;
 
 /* spinlock for eth device callbacks */
@@ -216,6 +217,7 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 	eth_dev->data->port_id = port_id;
 	eth_dev->attached = DEV_ATTACHED;
 	eth_dev->dev_type = type;
+	eth_dev_last_created_port = port_id;
 	nb_ports++;
 	return eth_dev;
 }
@@ -465,124 +467,45 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		return 1;
 }
 
-/* attach the new physical device, then store port_id of the device */
-static int
-rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
-{
-	/* Invoke probe func of the driver can handle the new device. */
-	if (rte_eal_pci_probe_one(addr))
-		goto err;
-
-	if (rte_eth_dev_get_port_by_addr(addr, port_id))
-		goto err;
-
-	return 0;
-err:
-	return -1;
-}
-
-/* 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)
-{
-	struct rte_pci_addr freed_addr;
-	struct rte_pci_addr vp;
-
-	/* get pci address by port id */
-	if (rte_eth_dev_get_addr_by_port(port_id, &freed_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)
-		goto err;
-
-	/* invoke devuninit func of the pci driver,
-	 * also remove the device from pci_device_list */
-	if (rte_eal_pci_detach(&freed_addr))
-		goto err;
-
-	*addr = freed_addr;
-	return 0;
-err:
-	return -1;
-}
-
-/* attach the new virtual device, then store port_id of the device */
-static int
-rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
-{
-	char *name = NULL, *args = NULL;
-	int ret = -1;
-
-	/* parse vdevargs, then retrieve device name and args */
-	if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
-		goto end;
-
-	/* walk around dev_driver_list to find the driver of the device,
-	 * then invoke probe function of the driver.
-	 * rte_eal_vdev_init() updates port_id allocated after
-	 * initialization.
-	 */
-	if (rte_eal_vdev_init(name, args))
-		goto end;
-
-	if (rte_eth_dev_get_port_by_name(name, port_id))
-		goto end;
-
-	ret = 0;
-end:
-	free(name);
-	free(args);
-
-	return ret;
-}
-
-/* detach the new virtual device, then store the name of the device */
-static int
-rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
-{
-	char name[RTE_ETH_NAME_MAX_LEN];
-
-	/* get device name by port id */
-	if (rte_eth_dev_get_name_by_port(port_id, name))
-		goto err;
-	/* walk around dev_driver_list to find the driver of the device,
-	 * then invoke uninit function of the driver */
-	if (rte_eal_vdev_uninit(name))
-		goto err;
-
-	strncpy(vdevname, name, sizeof(name));
-	return 0;
-err:
-	return -1;
-}
-
 /* attach the new device, then store port_id of the device */
 int
 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
-	struct rte_pci_addr addr;
 	int ret = -1;
+	int current = eth_dev_last_created_port;
+	char *name = NULL;
+	char *args = NULL;
 
 	if ((devargs == NULL) || (port_id == NULL)) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
-		ret = rte_eth_dev_attach_pdev(&addr, port_id);
-		if (ret < 0)
-			goto err;
-	} else {
-		ret = rte_eth_dev_attach_vdev(devargs, port_id);
-		if (ret < 0)
-			goto err;
+	/* parse devargs, then retrieve device name and args */
+	if (rte_eal_parse_devargs_str(devargs, &name, &args))
+		goto err;
+
+	ret = rte_eal_dev_attach(name, args);
+	if (ret < 0)
+		goto err;
+
+	/* no point looking at eth_dev_last_created_port if no port exists */
+	if (!nb_ports) {
+		ret = -1;
+		goto err;
 	}
+	/* if nothing happened, there is a bug here, since some driver told us
+	 * it did attach a device, but did not create a port */
+	if (current == eth_dev_last_created_port) {
+		ret = -1;
+		goto err;
+	}
+	*port_id = eth_dev_last_created_port;
+	ret = 0;
 
-	return 0;
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	free(name);
+	free(args);
 	return ret;
 }
 
@@ -590,7 +513,6 @@ err:
 int
 rte_eth_dev_detach(uint8_t port_id, char *name)
 {
-	struct rte_pci_addr addr;
 	int ret = -1;
 
 	if (name == NULL) {
@@ -598,33 +520,19 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 		goto err;
 	}
 
-	/* check whether the driver supports detach feature, or not */
+	/* FIXME: move this to eal, once device flags are relocated there */
 	if (rte_eth_dev_is_detachable(port_id))
 		goto err;
 
-	if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
-		ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
-		if (ret < 0)
-			goto err;
-
-		ret = rte_eth_dev_detach_pdev(port_id, &addr);
-		if (ret < 0)
-			goto err;
-
-		snprintf(name, RTE_ETH_NAME_MAX_LEN,
-			"%04x:%02x:%02x.%d",
-			addr.domain, addr.bus,
-			addr.devid, addr.function);
-	} else {
-		ret = rte_eth_dev_detach_vdev(port_id, name);
-		if (ret < 0)
-			goto err;
-	}
+	snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
+		 "%s", rte_eth_devices[port_id].data->name);
+	ret = rte_eal_dev_detach(name);
+	if (ret < 0)
+		goto err;
 
 	return 0;
 
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
 	return ret;
 }
 
Signature · 1 line
2.7.4