diff mbox

[dpdk-dev,v3,21/28] eal/pci: Fix pci_probe_all_drivers to share code with closing function

Message ID 1418106629-22227-22-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Tetsuya Mukawa Dec. 9, 2014, 6:30 a.m. UTC
pci_close_all_drivers() will be implemented after the patch.
To share a part of code between thses 2 functions, The patch fixes
pci_probe_all_drivers() first.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/common/eal_common_pci.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

Comments

Michael Qiu Dec. 11, 2014, 3:50 a.m. UTC | #1
On 12/9/2014 2:34 PM, Tetsuya Mukawa wrote:
> pci_close_all_drivers() will be implemented after the patch.
> To share a part of code between thses 2 functions, The patch fixes
> pci_probe_all_drivers() first.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/common/eal_common_pci.c | 28 ++++++++++++++++++++--------
>  1 file changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
> index f01f258..1e3efea 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -99,19 +99,20 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
>  	return NULL;
>  }
>  
> -/*
> - * If vendor/device ID match, call the devinit() function of all
> - * registered driver for the given device. Return -1 if initialization
> - * failed, return 1 if no driver is found for this device.
> - */
> +#define INVOKE_PROBE	(0)

I see lots of places defined this macros( so does INVOKE_CLOSE ), does
any issue with it?
I'm not sure if you need
#ifndef XXX
#define XXX
#endif

Please make sure of this.

Thanks,
Michael
> +
>  static int
> -pci_probe_all_drivers(struct rte_pci_device *dev)
> +pci_invoke_all_drivers(struct rte_pci_device *dev, int type)
>  {
>  	struct rte_pci_driver *dr = NULL;
> -	int rc;
> +	int rc = 0;
>  
>  	TAILQ_FOREACH(dr, &pci_driver_list, next) {
> -		rc = rte_eal_pci_probe_one_driver(dr, dev);
> +		switch (type) {
> +		case INVOKE_PROBE:
> +			rc = rte_eal_pci_probe_one_driver(dr, dev);
> +			break;
> +		}
>  		if (rc < 0)
>  			/* negative value is an error */
>  			return -1;
> @@ -124,6 +125,17 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
>  }
>  
>  /*
> + * If vendor/device ID match, call the devinit() function of all
> + * registered driver for the given device. Return -1 if initialization
> + * failed, return 1 if no driver is found for this device.
> + */
> +static int
> +pci_probe_all_drivers(struct rte_pci_device *dev)
> +{
> +	return pci_invoke_all_drivers(dev, INVOKE_PROBE);
> +}
> +
> +/*
>   * Scan the content of the PCI bus, and call the devinit() function for
>   * all registered drivers that have a matching entry in its id_table
>   * for discovered devices.
Michael Qiu Dec. 11, 2014, 4:46 a.m. UTC | #2
On 12/11/2014 11:52 AM, Qiu, Michael wrote:
> On 12/9/2014 2:34 PM, Tetsuya Mukawa wrote:
>> pci_close_all_drivers() will be implemented after the patch.
>> To share a part of code between thses 2 functions, The patch fixes
>> pci_probe_all_drivers() first.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/common/eal_common_pci.c | 28 ++++++++++++++++++++--------
>>  1 file changed, 20 insertions(+), 8 deletions(-)
>>
>> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
>> index f01f258..1e3efea 100644
>> --- a/lib/librte_eal/common/eal_common_pci.c
>> +++ b/lib/librte_eal/common/eal_common_pci.c
>> @@ -99,19 +99,20 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
>>  	return NULL;
>>  }
>>  
>> -/*
>> - * If vendor/device ID match, call the devinit() function of all
>> - * registered driver for the given device. Return -1 if initialization
>> - * failed, return 1 if no driver is found for this device.
>> - */
>> +#define INVOKE_PROBE	(0)
> I see lots of places defined this macros( so does INVOKE_CLOSE ), does
> any issue with it?
> I'm not sure if you need
> #ifndef XXX
> #define XXX
> #endif
>
> Please make sure of this.

Another choice is move them to one file like eal_private.h to avoid
defined in so many places.

Thanks,
Michael
>
> Thanks,
> Michael
>> +
>>  static int
>> -pci_probe_all_drivers(struct rte_pci_device *dev)
>> +pci_invoke_all_drivers(struct rte_pci_device *dev, int type)
>>  {
>>  	struct rte_pci_driver *dr = NULL;
>> -	int rc;
>> +	int rc = 0;
>>  
>>  	TAILQ_FOREACH(dr, &pci_driver_list, next) {
>> -		rc = rte_eal_pci_probe_one_driver(dr, dev);
>> +		switch (type) {
>> +		case INVOKE_PROBE:
>> +			rc = rte_eal_pci_probe_one_driver(dr, dev);
>> +			break;
>> +		}
>>  		if (rc < 0)
>>  			/* negative value is an error */
>>  			return -1;
>> @@ -124,6 +125,17 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
>>  }
>>  
>>  /*
>> + * If vendor/device ID match, call the devinit() function of all
>> + * registered driver for the given device. Return -1 if initialization
>> + * failed, return 1 if no driver is found for this device.
>> + */
>> +static int
>> +pci_probe_all_drivers(struct rte_pci_device *dev)
>> +{
>> +	return pci_invoke_all_drivers(dev, INVOKE_PROBE);
>> +}
>> +
>> +/*
>>   * Scan the content of the PCI bus, and call the devinit() function for
>>   * all registered drivers that have a matching entry in its id_table
>>   * for discovered devices.
>
Tetsuya Mukawa Dec. 11, 2014, 4:59 a.m. UTC | #3
(2014/12/11 13:46), Qiu, Michael wrote:
> On 12/11/2014 11:52 AM, Qiu, Michael wrote:
>> On 12/9/2014 2:34 PM, Tetsuya Mukawa wrote:
>>> pci_close_all_drivers() will be implemented after the patch.
>>> To share a part of code between thses 2 functions, The patch fixes
>>> pci_probe_all_drivers() first.
>>>
>>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>>> ---
>>>  lib/librte_eal/common/eal_common_pci.c | 28 ++++++++++++++++++++--------
>>>  1 file changed, 20 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
>>> index f01f258..1e3efea 100644
>>> --- a/lib/librte_eal/common/eal_common_pci.c
>>> +++ b/lib/librte_eal/common/eal_common_pci.c
>>> @@ -99,19 +99,20 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
>>>  	return NULL;
>>>  }
>>>  
>>> -/*
>>> - * If vendor/device ID match, call the devinit() function of all
>>> - * registered driver for the given device. Return -1 if initialization
>>> - * failed, return 1 if no driver is found for this device.
>>> - */
>>> +#define INVOKE_PROBE	(0)
>> I see lots of places defined this macros( so does INVOKE_CLOSE ), does
>> any issue with it?
>> I'm not sure if you need
>> #ifndef XXX
>> #define XXX
>> #endif
>>
>> Please make sure of this.
> Another choice is move them to one file like eal_private.h to avoid
> defined in so many places.

Thanks. I will do like above.

Tetsuya


> Thanks,
> Michael
>> Thanks,
>> Michael
>>> +
>>>  static int
>>> -pci_probe_all_drivers(struct rte_pci_device *dev)
>>> +pci_invoke_all_drivers(struct rte_pci_device *dev, int type)
>>>  {
>>>  	struct rte_pci_driver *dr = NULL;
>>> -	int rc;
>>> +	int rc = 0;
>>>  
>>>  	TAILQ_FOREACH(dr, &pci_driver_list, next) {
>>> -		rc = rte_eal_pci_probe_one_driver(dr, dev);
>>> +		switch (type) {
>>> +		case INVOKE_PROBE:
>>> +			rc = rte_eal_pci_probe_one_driver(dr, dev);
>>> +			break;
>>> +		}
>>>  		if (rc < 0)
>>>  			/* negative value is an error */
>>>  			return -1;
>>> @@ -124,6 +125,17 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
>>>  }
>>>  
>>>  /*
>>> + * If vendor/device ID match, call the devinit() function of all
>>> + * registered driver for the given device. Return -1 if initialization
>>> + * failed, return 1 if no driver is found for this device.
>>> + */
>>> +static int
>>> +pci_probe_all_drivers(struct rte_pci_device *dev)
>>> +{
>>> +	return pci_invoke_all_drivers(dev, INVOKE_PROBE);
>>> +}
>>> +
>>> +/*
>>>   * Scan the content of the PCI bus, and call the devinit() function for
>>>   * all registered drivers that have a matching entry in its id_table
>>>   * for discovered devices.
diff mbox

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index f01f258..1e3efea 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -99,19 +99,20 @@  static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
-/*
- * If vendor/device ID match, call the devinit() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
+#define INVOKE_PROBE	(0)
+
 static int
-pci_probe_all_drivers(struct rte_pci_device *dev)
+pci_invoke_all_drivers(struct rte_pci_device *dev, int type)
 {
 	struct rte_pci_driver *dr = NULL;
-	int rc;
+	int rc = 0;
 
 	TAILQ_FOREACH(dr, &pci_driver_list, next) {
-		rc = rte_eal_pci_probe_one_driver(dr, dev);
+		switch (type) {
+		case INVOKE_PROBE:
+			rc = rte_eal_pci_probe_one_driver(dr, dev);
+			break;
+		}
 		if (rc < 0)
 			/* negative value is an error */
 			return -1;
@@ -124,6 +125,17 @@  pci_probe_all_drivers(struct rte_pci_device *dev)
 }
 
 /*
+ * If vendor/device ID match, call the devinit() function of all
+ * registered driver for the given device. Return -1 if initialization
+ * failed, return 1 if no driver is found for this device.
+ */
+static int
+pci_probe_all_drivers(struct rte_pci_device *dev)
+{
+	return pci_invoke_all_drivers(dev, INVOKE_PROBE);
+}
+
+/*
  * Scan the content of the PCI bus, and call the devinit() function for
  * all registered drivers that have a matching entry in its id_table
  * for discovered devices.