Change rte_eal_vdev_init to update port_id
PATCH 1/1 Change rte_eal_vdev_init to update port_id
Changes include
Quoted 2 lines
Modify
rte_eal_vdev_initto return allocatedport_idModifyrte_eal_probe_oneto return allocatedport_id
2. Removed following functions
Quoted 2 lines
rte_eth_dev_saveandrte_eth_dev_get_changed_port
3. Added 2 new functions
Quoted 2 lines
rte_eth_dev_get_port_by_namerte_eth_dev_get_port_by_addr
4. Fix return error(ENOMEM) in function rte_pmd_mpipe_devinit
Compiled on Linux for following targets
Quoted 3 lines
x86_64-native-linuxapp-gcc
x86_64-native-linuxapp-clang
x86_x32-native-linuxapp-gcc
Compiled on FreeBSD for following targets
Quoted 2 lines
x86_64-native-bsdapp-clang
x86_64-native-bsdapp-gcc
Tested on Linux/FreeBSD:
Quoted 10 lines
port attach
eth_null
port start all
port stop all
port close all
port detach 0
port attacheth_null
port start all
port stop all
port close all
port detach 0
Successful run of checkpatch.pl on the diffs
Successful validate_abi on Linux for following targets
Quoted 2 lines
x86_64-native-linuxapp-gcc
x86_64-native-linuxapp-clang
--- drivers/net/enic/enic_ethdev.c | 2 +- drivers/net/mpipe/mpipe_tilegx.c | 1 + lib/librte_eal/common/eal_common_dev.c | 14 ++-- lib/librte_eal/common/eal_common_pci.c | 6 +- lib/librte_eal/common/include/rte_dev.h | 36 +++++++++- lib/librte_eal/common/include/rte_pci.h | 4 +- lib/librte_ether/rte_ethdev.c | 119 +++++++++++++++++--------------- lib/librte_ether/rte_ether_version.map | 2 + 8 files changed, 118 insertions(+), 66 deletions(-)
drivers/net/enic/enic_ethdev.c +1 -1
@@ -36,8 +36,8 @@#include <stdio.h> #include <stdint.h> -#include <rte_dev.h> #include <rte_pci.h> +#include <rte_dev.h> #include <rte_ethdev.h> #include <rte_string_fns.h>
drivers/net/mpipe/mpipe_tilegx.c +1 -0
@@ -1582,6 +1582,7 @@ rte_pmd_mpipe_devinit(const char *ifname,if (!eth_dev) {RTE_LOG (ERR ,PMD ,"%s: Failed to allocate device.\n" , ifname);rte_free (priv); +return -ENOMEM ; } RTE_LOG(INFO, PMD, "%s: Initialized mpipe device"
lib/librte_eal/common/eal_common_dev.c +10 -4
@@ -37,6 +37,7 @@#include <inttypes.h> #include <sys/queue.h> +#include <rte_pci.h> #include <rte_dev.h> #include <rte_devargs.h> #include <rte_debug.h>
@@ -64,7 +65,7 @@ rte_eal_driver_unregister(struct rte_driver *driver) }int -rte_eal_vdev_init (const char *name,const char *args) +rte_eal_vdev_init (const char *name,const char *args,uint8_t *port_id) {struct rte_driver *driver;
@@ -81,8 +82,12 @@ rte_eal_vdev_init(const char *name, const char *args)* will be "eth_pcap", but "name" will be "eth_pcapN". * So use strncmp to compare. */ -if (!strncmp (driver->name, name,strlen (driver->name))) -return driver->init (name, args); +if (!strncmp (driver->name, name,strlen (driver->name))) { +if (!driver->init (name, args)) +return rte_eth_dev_get_port_by_name ( + name, port_id); + } + }RTE_LOG (ERR ,EAL ,"no driver found for %s\n" , name);
@@ -94,6 +99,7 @@ rte_eal_dev_init(void) {struct rte_devargs *devargs;struct rte_driver *driver; +uint8_t port_id;/* * Note that the dev_driver_list is populated here
@@ -108,7 +114,7 @@ rte_eal_dev_init(void)continue ;if (rte_eal_vdev_init (devargs->virtual.drv_name, - devargs->args)) { + devargs->args, &port_id)) {RTE_LOG (ERR ,EAL ,"failed to initialize %s device\n" , devargs->virtual.drv_name);return -1 ;
lib/librte_eal/common/eal_common_pci.c +4 -2
@@ -79,6 +79,7 @@#include <rte_string_fns.h> #include <rte_common.h> #include <rte_devargs.h> +#include <rte_dev.h> #include "eal_private.h"
@@ -322,7 +323,7 @@ pci_detach_all_drivers(struct rte_pci_device *dev)* the driver of the devive. */ int -rte_eal_pci_probe_one (const struct rte_pci_addr *addr) +rte_eal_pci_probe_one (const struct rte_pci_addr *addr,uint8_t *port_id) {struct rte_pci_device *dev =NULL ;int ret =0 ;
@@ -337,7 +338,8 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr) ret =pci_probe_all_drivers (dev);if (ret <0 ) goto err_return; -return 0 ; + +return rte_eth_dev_get_port_by_addr (addr, port_id); }return -1 ;
lib/librte_eal/common/include/rte_dev.h +35 -1
@@ -110,10 +110,12 @@ int rte_eal_dev_init(void);* The pointer to a driver name to be initialized. * @param args * The pointer to arguments used by driver initialization. +* @param port_id +* The port_id associated with the driver after initialization. * @return * 0 on success, negative on error */ -int rte_eal_vdev_init (const char *name,const char *args); +int rte_eal_vdev_init (const char *name,const char *args,uint8_t *port_id);/** * Uninitalize a driver specified by name.
@@ -125,6 +127,38 @@ int rte_eal_vdev_init(const char *name, const char *args);*/ int rte_eal_vdev_uninit (const char *name); +/** +* Given name, return port_id associated with the device. +* +* @param name +* Name associated with device. +* @param port_id +* The port identifier of the device. +* +* @return +* - 0: Success. +* - -EINVAL: NULL pointer. +* - -ENODEV: No matching device. +*/ +extern int +rte_eth_dev_get_port_by_name (const char *name,uint8_t *port_id); + +/** +* Given pci_addr, return port_id associated with the device. +* +* @param addr +* PCI addr associated with device. +* @param port_id +* The port identifier of the device. +* +* @return +* - 0: Success. +* - -EINVAL: NULL pointer. +* - -ENODEV: No matching device. +*/ +extern int +rte_eth_dev_get_port_by_addr (const struct rte_pci_addr *addr,uint8_t *port_id); +#define PMD_REGISTER_DRIVER (d)\ void devinitfn_ ##d(void);\ void __attribute__((constructor, used)) devinitfn_ ##d(void)\
lib/librte_eal/common/include/rte_pci.h +3 -1
@@ -406,11 +406,13 @@ void pci_unmap_resource(void *requested_addr, size_t size);* * @param addr * The PCI Bus-Device-Function address to probe. +* @param port_id +* Port-id associated with PCI device address * @return * - 0 on success. * - Negative on error. */ -int rte_eal_pci_probe_one (const struct rte_pci_addr *addr); +int rte_eal_pci_probe_one (const struct rte_pci_addr *addr,uint8_t *port_id);/** * Close the single PCI device.
lib/librte_ether/rte_ethdev.c +62 -57
157 lines not on this page · raw message
lib/librte_ether/rte_ether_version.map +2 -0
@@ -125,5 +125,7 @@ DPDK_2.1 { rte_eth_timesync_enable; rte_eth_timesync_read_rx_timestamp; rte_eth_timesync_read_tx_timestamp; + rte_eth_dev_get_port_by_name; + rte_eth_dev_get_port_by_addr; } DPDK_2.0;
Signature · 1 line
1.9.1
drivers/net/enic/enic_ethdev.c line 42
Quoted 13 lines · Ravi Kerur
drivers/net/enic/enic_ethdev.c +1
-1@@ -36,8 +36,8 @@#include <stdio.h> #include <stdint.h> -#include <rte_dev.h> #include <rte_pci.h> +#include <rte_dev.h> #include <rte_ethdev.h> #include <rte_string_fns.h>
Hi Ravi,
Do we need this fixing?
drivers/net/mpipe/mpipe_tilegx.c rte_pmd_mpipe_devinit(const char *ifname, · line 1585
Quoted 10 lines
drivers/net/mpipe/mpipe_tilegx.c +1
-0@@ -1582,6 +1582,7 @@ rte_pmd_mpipe_devinit(const char *ifname,if (!eth_dev) {RTE_LOG (ERR ,PMD ,"%s: Failed to allocate device.\n" , ifname);rte_free (priv); +return -ENOMEM ;
How about separating this fixing from the patch, and put it as an one of cleanup patch series?
Quoted 18 lines
drivers/net/mpipe/mpipe_tilegx.c +0
-0} RTE_LOG(INFO, PMD, "%s: Initialized mpipe device"lib/librte_eal/common/eal_common_dev.c +1
-0RTE_LOG (ERR ,EAL ,"no driver found for %s\n" , name);@@ -94,6 +99,7 @@ rte_eal_dev_init(void) {struct rte_devargs *devargs;struct rte_driver *driver; +uint8_t port_id;/* * Note that the dev_driver_list is populated here
lib/librte_eal/common/eal_common_dev.c rte_eal_dev_init(void) · line 117
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +1
-1@@ -108,7 +114,7 @@ rte_eal_dev_init(void)continue ;if (rte_eal_vdev_init (devargs->virtual.drv_name, - devargs->args)) { + devargs->args, &port_id)) {
After this line, 'port_id' is actually not used by anywhere in this function.
Also, I guess we will not use port_id in this function in the future. How about fixing rte_eal_vdev_init() to handle NULL value correctly to remove port_id from this function?
But I agree your current implementation is also one of choice.
Quoted 16 lines
lib/librte_ether/rte_ethdev.c +12
-0+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 || port_id ==NULL ) { +PMD_DEBUG_TRACE ("Null pointer is specified\n" ); +return -EINVAL ; + } + + *port_id =RTE_MAX_ETHPORTS ;
lib/librte_ether/rte_ethdev.c rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info) · line 3610
Quoted 10 lines
lib/librte_ether/rte_ethdev.c +10
-0+ +for (i =0 ; i <RTE_MAX_ETHPORTS ; i++) { + + pci_dev = rte_eth_devices[i].pci_dev; + +if (pci_dev !=NULL && + pci_dev->addr.domain == addr->domain && + pci_dev->addr.bus == addr->bus && + pci_dev->addr.devid == addr->devid && + pci_dev->addr.function == addr->function) {
You can use rte_eal_compare_pci_addr() here.
Quoted 12 lines
lib/librte_ether/rte_ethdev.c +7
-0+ + *port_id = i; +return 0 ; + } + } +return -ENODEV ; +}lib/librte_ether/rte_ether_version.map +0
-0
lib/librte_ether/rte_ether_version.map DPDK_2.1 { · line 131
Quoted 7 lines
lib/librte_ether/rte_ether_version.map +2
-0@@ -125,5 +125,7 @@ DPDK_2.1 { rte_eth_timesync_enable; rte_eth_timesync_read_rx_timestamp; rte_eth_timesync_read_tx_timestamp; + rte_eth_dev_get_port_by_name; + rte_eth_dev_get_port_by_addr; } DPDK_2.0;
Hi Thomas,
Could you please make sure API consistency?
Is it ok to add above functions to DPDK_2.1 even though we are in RC phase, or need to add to DPDK_2.2?
Thanks,
Tetsuya
Hi Tetsuya,
Quoted 30 lines · Tetsuya Mukawa
Review
Quoted 1 line · Ravi Kerur
(quoted diff) +0
-0
b/drivers/net/enic/enic_ethdev.cdrivers/net/enic/enic_ethdev.c line 42
Quoted 12 lines
index 8280cea..472ef5a 100644
drivers/net/enic/enic_ethdev.c +1
-1@@ -36,8 +36,8 @@#include <stdio.h> #include <stdint.h> -#include <rte_dev.h> #include <rte_pci.h> +#include <rte_dev.h> #include <rte_ethdev.h> #include <rte_string_fns.h> Hi Ravi,
Do we need this fixing?
Review
Quoted 2 lines
(quoted diff) +0
-0
b/drivers/net/mpipe/mpipe_tilegx.cdrivers/net/mpipe/mpipe_tilegx.c rte_pmd_mpipe_devinit(const char *ifname, · line 1583
Quoted 6 lines
index 743feef..6e3e304 100644
drivers/net/mpipe/mpipe_tilegx.c +0
-0@@ -1582,6 +1582,7 @@ rte_pmd_mpipe_devinit(const char *ifname,if (!eth_dev) { RTE_LOG(ERR, PMD, "%s: Failed to allocate device.\n",ifname);
Quoted 7 lines
drivers/net/mpipe/mpipe_tilegx.c rte_pmd_mpipe_devinit(const char *ifname, · line 1585
Quoted 2 lines
drivers/net/mpipe/mpipe_tilegx.c +1
-0rte_free (priv); +return -ENOMEM ;How about separating this fixing from the patch, and put it as an one of cleanup patch series?
rte_pmd_mpipe_devinit is the init func pointer called via rte_eal_vdev_init. Since we were fixing rte_eal_vdev_init thought of taking care of mpipe issue. If you think it's unrelated to this patch I will send a separate one.
Quoted 54 lines
}Review
Quoted 3 lines
drivers/net/mpipe/mpipe_tilegx.c +0
-0RTE_LOG(INFO, PMD, "%s: Initialized mpipe device"(quoted diff) +0
-0
b/lib/librte_eal/common/eal_common_dev.cQuoted 14 lines
index 4089d66..82d5693 100644
lib/librte_eal/common/eal_common_dev.c +1
-0RTE_LOG (ERR ,EAL ,"no driver found for %s\n" , name);@@ -94,6 +99,7 @@ rte_eal_dev_init(void) {struct rte_devargs *devargs;struct rte_driver *driver; +uint8_t port_id;/* * Note that the dev_driver_list is populated here lib/librte_eal/common/eal_common_dev.c rte_eal_dev_init(void) · line 117
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +1
-1@@ -108,7 +114,7 @@ rte_eal_dev_init(void)continue ;if (rte_eal_vdev_init (devargs->virtual.drv_name, - devargs->args)) { + devargs->args, &port_id)) {After this line, '
port_id' is actually not used by anywhere in this function.
Also, I guess we will not useport_idin this function in the future. How about fixingrte_eal_vdev_init()to handle NULL value correctly to removeport_idfrom this function?
But I agree your current implementation is also one of choice.Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/librte_ether/rte_ethdev.clib/librte_ether/rte_ethdev.c
Quoted 5 lines
index 5fe1906..355d709 100644
lib/librte_ether/rte_ethdev.c +2
-0+int +rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t
*port_id)Quoted 14 lines
lib/librte_ether/rte_ethdev.c +14
-0+{ +int i; +struct rte_pci_device *pci_dev =NULL ; + +if (addr ==NULL || port_id ==NULL ) { +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;
Quoted 9 lines
lib/librte_ether/rte_ethdev.c rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info) · line 3610
Quoted 6 lines
lib/librte_ether/rte_ethdev.c +6
-0+ +if (pci_dev !=NULL && + pci_dev->addr.domain == addr->domain && + pci_dev->addr.bus == addr->bus && + pci_dev->addr.devid == addr->devid && + pci_dev->addr.function == addr->function) {You can use
rte_eal_compare_pci_addr()here.
Will fix this.
Quoted 20 lines
Review
Quoted 9 lines
lib/librte_ether/rte_ethdev.c +7
-0+ + *port_id = i; +return 0 ; + } + } +return -ENODEV ; +}(quoted diff) +0
-0b/lib/librte_ether/rte_ether_version.map
Quoted 10 lines
index 8345a6c..3d5cb23 100644
lib/librte_ether/rte_ether_version.map +2
-0@@ -125,5 +125,7 @@ DPDK_2.1 { rte_eth_timesync_enable; rte_eth_timesync_read_rx_timestamp; rte_eth_timesync_read_tx_timestamp; + rte_eth_dev_get_port_by_name; + rte_eth_dev_get_port_by_addr;
Quoted 9 lines
lib/librte_ether/rte_ether_version.map DPDK_2.1 { · line 131
Quoted 1 line
lib/librte_ether/rte_ether_version.map +0
-0} DPDK_2.0;Hi Thomas,
Could you please make sure API consistency?
Is it ok to add above functions to DPDK_2.1 even though we are in RC phase, or need to add to DPDK_2.2?
Same question. If it's targeted for 2.2 then I will modify this.
Thanks,
Ravi
Quoted 5 lines
Thanks,
Tetsuya
2015-08-07 15:06, Ravi Kerur:
Quoted 9 lines · Tetsuya Mukawa
Quoted 7 lines · Ravi Kerur
Hi Thomas,
Could you please make sure API consistency?
Is it ok to add above functions to DPDK_2.1 even though we are in RC phase, or need to add to DPDK_2.2?Same question. If it's targeted for 2.2 then I will modify this.
Why should it be in 2.1?
Is there something I missed which makes it an important fix?
If no, please stop sending this kind of patch until the end of the 2.1 release. Thanks
Quoted 43 lines · Ravi Kerur
Hi Tetsuya,
On Thu, Aug 6, 2015 at 7:25 PM, Tetsuya Mukawa <[email protected] <mailto:[email protected]>> wrote:
On 2015/08/07 3:04, Ravi Kerur wrote: > diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c > index 8280cea..472ef5a 100644 > --- a/drivers/net/enic/enic_ethdev.c > +++ b/drivers/net/enic/enic_ethdev.c > @@ -36,8 +36,8 @@ > #include <stdio.h> > #include <stdint.h> > > -#include <rte_dev.h> > #include <rte_pci.h> > +#include <rte_dev.h> > #include <rte_ethdev.h> > #include <rte_string_fns.h> Hi Ravi, Do we need this fixing? > > diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c > index 743feef..6e3e304 100644 > --- a/drivers/net/mpipe/mpipe_tilegx.c > +++ b/drivers/net/mpipe/mpipe_tilegx.c > @@ -1582,6 +1582,7 @@ rte_pmd_mpipe_devinit(const char *ifname, > if (!eth_dev) { > RTE_LOG(ERR, PMD, "%s: Failed to allocate device.\n", ifname); > rte_free(priv); > + return -ENOMEM; How about separating this fixing from the patch, and put it as an one of cleanup patch series?
Quoted 5 lines
rte_pmd_mpipe_devinitis the init func pointer called viarte_eal_vdev_init. Since we were fixingrte_eal_vdev_initthought of taking care of mpipe issue. If you think it's unrelated to this patch I will send a separate one.
Hi Ravi,
To avoid segmentation fault like above has a point, even if rest of this patch won't be applied.
So I guess it's nice to separate the patch.
Thanks,
Tetsuya