[dpdk-dev,v6,12/17] pci: add a helper for device name

Message ID 1468303282-2806-13-git-send-email-shreyansh.jain@nxp.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Shreyansh Jain July 12, 2016, 6:01 a.m. UTC
  eal is a better place than crypto / ethdev for naming resources.
Add a helper in eal and make use of it in crypto / ethdev.

Signed-off-by: David Marchand <david.marchand@6wind.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 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(-)
  

Comments

Jan Viktorin July 14, 2016, 4:55 p.m. UTC | #1
On Tue, 12 Jul 2016 11:31:17 +0530
Shreyansh Jain <shreyansh.jain@nxp.com> wrote:

> eal is a better place than crypto / ethdev for naming resources.

s/for naming/to name/

What is meant by "resources" here?

> Add a helper in eal and make use of it in crypto / ethdev.
> 
> Signed-off-by: David Marchand <david.marchand@6wind.com>
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> ---
>  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(-)
> 
> diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
> index d7be111..60c6384 100644
> --- a/lib/librte_cryptodev/rte_cryptodev.c
> +++ b/lib/librte_cryptodev/rte_cryptodev.c
> @@ -367,23 +367,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)
>  {
> @@ -446,9 +429,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)
> @@ -503,9 +485,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)
> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
> index 3027adf..06508fa 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -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.

What about saying "using functions eal_parse_pci_*BDF"? The
specification "above" is quite uncertain...

> + *
> + * @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. */
>  /**

[...]
  
Shreyansh Jain July 15, 2016, 9:39 a.m. UTC | #2
On Thursday 14 July 2016 10:25 PM, Jan Viktorin wrote:
> On Tue, 12 Jul 2016 11:31:17 +0530
> Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> 
>> eal is a better place than crypto / ethdev for naming resources.
> 
> s/for naming/to name/

OK.

> 
> What is meant by "resources" here?

This has historic context (from earlier version of this patch). 
But I could relate the word 'resources' to EAL representation of devices - whether PCI or Crypto.
Or, Resource == Device.

> 
>> Add a helper in eal and make use of it in crypto / ethdev.
>>
>> Signed-off-by: David Marchand <david.marchand@6wind.com>
>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>> ---
>>  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(-)
>>
>> diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
>> index d7be111..60c6384 100644
>> --- a/lib/librte_cryptodev/rte_cryptodev.c
>> +++ b/lib/librte_cryptodev/rte_cryptodev.c
>> @@ -367,23 +367,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)
>>  {
>> @@ -446,9 +429,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)
>> @@ -503,9 +485,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)
>> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
>> index 3027adf..06508fa 100644
>> --- a/lib/librte_eal/common/include/rte_pci.h
>> +++ b/lib/librte_eal/common/include/rte_pci.h
>> @@ -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.
> 
> What about saying "using functions eal_parse_pci_*BDF"? The
> specification "above" is quite uncertain...

Agree that 'above' is positional word and should be avoided.
I will change that to "... using eal_parse_pci_* BDF helpers". OK?

> 
>> + *
>> + * @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. */
>>  /**
> 
> [...]
> 
>
  
Thomas Monjalon July 15, 2016, 9:56 a.m. UTC | #3
2016-07-15 15:09, Shreyansh jain:
> On Thursday 14 July 2016 10:25 PM, Jan Viktorin wrote:
> > What is meant by "resources" here?
> 
> This has historic context (from earlier version of this patch). 
> But I could relate the word 'resources' to EAL representation of devices - whether PCI or Crypto.
> Or, Resource == Device.

We need to define a precise wording, especially for the words
	- interface
	- resource
	- device
	- driver
	- module
Following are my thoughts:

An interface is a view of a resource through an API (e.g. an ethdev port).
A resource is a well identified hardware (e.g. a PCI device id).
A device is a hardware function (e.g. a networking port).
Note that some PCI NICs have only one PCI device id for several ports
(Chelsio and Mellanox cases). That's why we need to distinguish device
and resource.

A driver is the code handling a device.
I have read the word module in some patch proposals but I don't really know
what it refers to. Is it a group of drivers in the same file/directory?
  
Jan Viktorin July 15, 2016, 9:56 a.m. UTC | #4
On Fri, 15 Jul 2016 15:09:58 +0530
Shreyansh jain <shreyansh.jain@nxp.com> wrote:

> On Thursday 14 July 2016 10:25 PM, Jan Viktorin wrote:
> > On Tue, 12 Jul 2016 11:31:17 +0530
> > Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> >   
> >> eal is a better place than crypto / ethdev for naming resources.  
> > 
> > s/for naming/to name/  
> 
> OK.
> 
> > 
> > What is meant by "resources" here?  
> 
> This has historic context (from earlier version of this patch). 
> But I could relate the word 'resources' to EAL representation of devices - whether PCI or Crypto.
> Or, Resource == Device.

If it is possible I'd like more "device". But I think it's not that critical thing...

> 
> >   
> >> Add a helper in eal and make use of it in crypto / ethdev.

[...]

> >>  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.  
> > 
> > What about saying "using functions eal_parse_pci_*BDF"? The
> > specification "above" is quite uncertain...  
> 
> Agree that 'above' is positional word and should be avoided.
> I will change that to "... using eal_parse_pci_* BDF helpers". OK?

OK.

[...]
  
Jan Viktorin July 15, 2016, 11:32 a.m. UTC | #5
On Fri, 15 Jul 2016 11:56:38 +0200
Thomas Monjalon <thomas.monjalon@6wind.com> wrote:

> 2016-07-15 15:09, Shreyansh jain:
> > On Thursday 14 July 2016 10:25 PM, Jan Viktorin wrote:  
> > > What is meant by "resources" here?  
> > 
> > This has historic context (from earlier version of this patch). 
> > But I could relate the word 'resources' to EAL representation of devices - whether PCI or Crypto.
> > Or, Resource == Device.  
> 
> We need to define a precise wording, especially for the words
> 	- interface
> 	- resource
> 	- device
> 	- driver
> 	- module
> Following are my thoughts:
> 
> An interface is a view of a resource through an API (e.g. an ethdev port).
> A resource is a well identified hardware (e.g. a PCI device id).
> A device is a hardware function (e.g. a networking port).
> Note that some PCI NICs have only one PCI device id for several ports
> (Chelsio and Mellanox cases). That's why we need to distinguish device
> and resource.
> 
> A driver is the code handling a device.
> I have read the word module in some patch proposals but I don't really know
> what it refers to. Is it a group of drivers in the same file/directory?

Well, yes, initially there was proposed a kind of module. However, after David
as sent the patchset prepare for rte_device/driver, you can see that there
is no need for such object (probably). A module might be helpful when thinking
about the metadata (as done by Neil Horman). But as far as I know there was no
need for this... So a module has no data abstraction now and I am not going to
make any.

Jan
  
Shreyansh Jain July 15, 2016, 1:14 p.m. UTC | #6
On Friday 15 July 2016 03:09 PM, Shreyansh jain wrote:
> On Thursday 14 July 2016 10:25 PM, Jan Viktorin wrote:
>> On Tue, 12 Jul 2016 11:31:17 +0530
>> Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>
>>> eal is a better place than crypto / ethdev for naming resources.
>>
>> s/for naming/to name/
> 
> OK.
> 
>>
>> What is meant by "resources" here?
> 
> This has historic context (from earlier version of this patch). 
> But I could relate the word 'resources' to EAL representation of devices - whether PCI or Crypto.
> Or, Resource == Device.
> 

If I go by what Thomas is proposing for meaning of 'resource' [1], and the fact that all methods in this patchset refer to 'devices', I will change the patch context to 'EAL is a better place than crypto / ethdev to name devices'.

[1] http://dpdk.org/ml/archives/dev/2016-July/044056.html

>>
>>> Add a helper in eal and make use of it in crypto / ethdev.
>>>
>>> Signed-off-by: David Marchand <david.marchand@6wind.com>
>>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>> ---
>>>  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(-)
>>>
>>> diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
>>> index d7be111..60c6384 100644
>>> --- a/lib/librte_cryptodev/rte_cryptodev.c
>>> +++ b/lib/librte_cryptodev/rte_cryptodev.c
>>> @@ -367,23 +367,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)
>>>  {
>>> @@ -446,9 +429,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)
>>> @@ -503,9 +485,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)
>>> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
>>> index 3027adf..06508fa 100644
>>> --- a/lib/librte_eal/common/include/rte_pci.h
>>> +++ b/lib/librte_eal/common/include/rte_pci.h
>>> @@ -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.
>>
>> What about saying "using functions eal_parse_pci_*BDF"? The
>> specification "above" is quite uncertain...
> 
> Agree that 'above' is positional word and should be avoided.
> I will change that to "... using eal_parse_pci_* BDF helpers". OK?
> 
>>
>>> + *
>>> + * @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. */
>>>  /**
>>
>> [...]
>>
>>
> 
>
  

Patch

diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index d7be111..60c6384 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -367,23 +367,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)
 {
@@ -446,9 +429,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)
@@ -503,9 +485,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)
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 3027adf..06508fa 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -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.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 89c7b31..147b26f 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -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)