[dpdk-dev] [PATCH v2 3/7] pci: Pass rte_pci_addr to functions instead of separate args

Walker, Benjamin benjamin.walker at intel.com
Fri Dec 2 17:16:58 CET 2016


On Thu, 2016-12-01 at 11:56 +0530, Shreyansh Jain wrote:
> Hello Ben,
> 
> On Thursday 24 November 2016 01:37 AM, Ben Walker wrote:
> > 
> > Instead of passing domain, bus, devid, func, just pass
> > an rte_pci_addr.
> > 
> > Signed-off-by: Ben Walker <benjamin.walker at intel.com>
> > ---
> >  lib/librte_eal/linuxapp/eal/eal_pci.c | 32 +++++++++++++-------------------
> >  1 file changed, 13 insertions(+), 19 deletions(-)
> > 
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c
> > b/lib/librte_eal/linuxapp/eal/eal_pci.c
> > index 876ba38..073af5f 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> > @@ -267,8 +267,7 @@ pci_parse_sysfs_resource(const char *filename, struct
> > rte_pci_device *dev)
> > 
> >  /* Scan one pci sysfs entry, and fill the devices list from it. */
> >  static int
> > -pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
> > -	     uint8_t devid, uint8_t function)
> > +pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
> >  {
> >  	char filename[PATH_MAX];
> >  	unsigned long tmp;
> > @@ -281,10 +280,7 @@ pci_scan_one(const char *dirname, uint16_t domain,
> > uint8_t bus,
> >  		return -1;
> > 
> >  	memset(dev, 0, sizeof(*dev));
> > -	dev->addr.domain = domain;
> > -	dev->addr.bus = bus;
> > -	dev->addr.devid = devid;
> > -	dev->addr.function = function;
> > +	dev->addr = *addr;
> > 
> >  	/* get vendor id */
> >  	snprintf(filename, sizeof(filename), "%s/vendor", dirname);
> > @@ -429,16 +425,14 @@ pci_update_device(const struct rte_pci_addr *addr)
> >  		 pci_get_sysfs_path(), addr->domain, addr->bus, addr-
> > >devid,
> >  		 addr->function);
> > 
> > -	return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
> > -				addr->function);
> > +	return pci_scan_one(filename, addr);
> >  }
> > 
> >  /*
> >   * split up a pci address into its constituent parts.
> >   */
> >  static int
> > -parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
> > -		uint8_t *bus, uint8_t *devid, uint8_t *function)
> > +parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr
> > *addr)
> >  {
> >  	/* first split on ':' */
> >  	union splitaddr {
> > @@ -466,10 +460,10 @@ parse_pci_addr_format(const char *buf, int bufsize,
> > uint16_t *domain,
> > 
> >  	/* now convert to int values */
> >  	errno = 0;
> > -	*domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
> > -	*bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
> > -	*devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
> > -	*function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
> > +	addr->domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
> > +	addr->bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
> > +	addr->devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
> > +	addr->function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
> >  	if (errno != 0)
> >  		goto error;
> > 
> > @@ -490,8 +484,7 @@ rte_eal_pci_scan(void)
> >  	struct dirent *e;
> >  	DIR *dir;
> >  	char dirname[PATH_MAX];
> > -	uint16_t domain;
> > -	uint8_t bus, devid, function;
> > +	struct rte_pci_addr addr;
> > 
> >  	dir = opendir(pci_get_sysfs_path());
> >  	if (dir == NULL) {
> > @@ -500,20 +493,21 @@ rte_eal_pci_scan(void)
> >  		return -1;
> >  	}
> > 
> > +
> >  	while ((e = readdir(dir)) != NULL) {
> >  		if (e->d_name[0] == '.')
> >  			continue;
> > 
> > -		if (parse_pci_addr_format(e->d_name, sizeof(e->d_name),
> > &domain,
> > -				&bus, &devid, &function) != 0)
> > +		if (parse_pci_addr_format(e->d_name, sizeof(e->d_name),
> > &addr) != 0)
> >  			continue;
> > 
> >  		snprintf(dirname, sizeof(dirname), "%s/%s",
> >  				pci_get_sysfs_path(), e->d_name);
> > -		if (pci_scan_one(dirname, domain, bus, devid, function) <
> > 0)
> > +		if (pci_scan_one(dirname, &addr) < 0)
> >  			goto error;
> >  	}
> >  	closedir(dir);
> > +
> >  	return 0;
> > 
> >  error:
> > 
> 
> Do you mind if I use this patch directly as part of my patchset for bus 
> Model? I was doing a similar change to make the pci_scan_one simpler 
> (and pass along a new argument)..

Sure, go ahead.

> 
> -
> Shreyansh


More information about the dev mailing list