All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
@ 2021-08-24 14:20 Prabhakar Kushwaha
  2021-08-24 14:30 ` Heiner Kallweit
  0 siblings, 1 reply; 5+ messages in thread
From: Prabhakar Kushwaha @ 2021-08-24 14:20 UTC (permalink / raw)
  To: Heiner Kallweit, Bjorn Helgaas, Ariel Elior,
	Sudarsana Reddy Kalluru, GR-everest-linux-l2, Jakub Kicinski,
	David Härdeman
  Cc: linux-pci, netdev, Shai Malin

Hi Heiner,

> -----Original Message-----
> From: Heiner Kallweit <hkallweit1@gmail.com>
> Sent: Sunday, August 22, 2021 7:23 PM
> To: Bjorn Helgaas <bhelgaas@google.com>; Ariel Elior <aelior@marvell.com>;
> Sudarsana Reddy Kalluru <skalluru@marvell.com>; GR-everest-linux-l2 <GR-
> everest-linux-l2@marvell.com>; Jakub Kicinski <kuba@kernel.org>; David
> Härdeman <david@hardeman.nu>
> Cc: linux-pci@vger.kernel.org; netdev@vger.kernel.org
> Subject: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
> 
> External Email
> 
> ----------------------------------------------------------------------
> Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and
> read the full VPD data into it.
> 
> This simplifies the code, and we no longer have to make assumptions about
> VPD size.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x.h   |  1 -
>  .../net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 44 +++++--------------
>  2 files changed, 10 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
> index d04994840..e789430f4 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
> @@ -2407,7 +2407,6 @@ void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8
> func, u8 idu_sb_id,
>  #define ETH_MAX_RX_CLIENTS_E2		ETH_MAX_RX_CLIENTS_E1H
>  #endif
> 
> -#define BNX2X_VPD_LEN			128
>  #define VENDOR_ID_LEN			4
> 
>  #define VF_ACQUIRE_THRESH		3
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> index 6d9813491..0466adf8d 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> @@ -12189,50 +12189,29 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
> 
>  static void bnx2x_read_fwinfo(struct bnx2x *bp)
>  {
> -	int cnt, i, block_end, rodi;
> -	char vpd_start[BNX2X_VPD_LEN+1];
> +	int i, block_end, rodi;
>  	char str_id_reg[VENDOR_ID_LEN+1];
>  	char str_id_cap[VENDOR_ID_LEN+1];
> -	char *vpd_data;
> -	char *vpd_extended_data = NULL;
> -	u8 len;
> +	unsigned int vpd_len;
> +	u8 *vpd_data, len;
> 
> -	cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
>  	memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
> 
> -	if (cnt < BNX2X_VPD_LEN)
> -		goto out_not_found;
> +	vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);

Definition of pci_vpd_alloc() is below as per repo "git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git" and   branch wip/heiner-vpd-api
void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size)
{
        unsigned int len = dev->vpd.len;
        void *buf;
--
--
        if (size)
                *size = len;
}
Here is len is already part of pci_dev.  

So why cannot same be set in caller function i.e. vpd_len = pb->pdev->vpd.len


> +	if (IS_ERR(vpd_data))
> +		return;
> 
>  	/* VPD RO tag should be first tag after identifier string, hence
>  	 * we should be able to find it in first BNX2X_VPD_LEN chars
>  	 */
> -	i = pci_vpd_find_tag(vpd_start, BNX2X_VPD_LEN,
> PCI_VPD_LRDT_RO_DATA);
> +	i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
>  	if (i < 0)
>  		goto out_not_found;
> 
>  	block_end = i + PCI_VPD_LRDT_TAG_SIZE +
> -		    pci_vpd_lrdt_size(&vpd_start[i]);
> -
> +		    pci_vpd_lrdt_size(&vpd_data[i]);
>  	i += PCI_VPD_LRDT_TAG_SIZE;
> 
> -	if (block_end > BNX2X_VPD_LEN) {
> -		vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
> -		if (vpd_extended_data  == NULL)
> -			goto out_not_found;
> -
> -		/* read rest of vpd image into vpd_extended_data */
> -		memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
> -		cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
> -				   block_end - BNX2X_VPD_LEN,
> -				   vpd_extended_data + BNX2X_VPD_LEN);
> -		if (cnt < (block_end - BNX2X_VPD_LEN))
> -			goto out_not_found;
> -		vpd_data = vpd_extended_data;
> -	} else
> -		vpd_data = vpd_start;
> -
> -	/* now vpd_data holds full vpd content in both cases */
> -
>  	rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
>  				   PCI_VPD_RO_KEYWORD_MFR_ID);
>  	if (rodi < 0)
> @@ -12258,17 +12237,14 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp)
> 
>  			rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
> 
> -			if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
> +			if (len < 32 && (len + rodi) <= vpd_len) {
>  				memcpy(bp->fw_ver, &vpd_data[rodi], len);
>  				bp->fw_ver[len] = ' ';
>  			}
>  		}
> -		kfree(vpd_extended_data);
> -		return;
>  	}
>  out_not_found:
> -	kfree(vpd_extended_data);
> -	return;
> +	kfree(vpd_data);

As vpd_data allocation done in PCI layer. 
It will be logical to also free vpd_data in PCI layer.

--pk

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
  2021-08-24 14:20 [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() Prabhakar Kushwaha
@ 2021-08-24 14:30 ` Heiner Kallweit
  0 siblings, 0 replies; 5+ messages in thread
From: Heiner Kallweit @ 2021-08-24 14:30 UTC (permalink / raw)
  To: Prabhakar Kushwaha, Bjorn Helgaas, Ariel Elior,
	Sudarsana Reddy Kalluru, GR-everest-linux-l2, Jakub Kicinski,
	David Härdeman
  Cc: linux-pci, netdev, Shai Malin

On 24.08.2021 16:20, Prabhakar Kushwaha wrote:
> Hi Heiner,
> 
>> -----Original Message-----
>> From: Heiner Kallweit <hkallweit1@gmail.com>
>> Sent: Sunday, August 22, 2021 7:23 PM
>> To: Bjorn Helgaas <bhelgaas@google.com>; Ariel Elior <aelior@marvell.com>;
>> Sudarsana Reddy Kalluru <skalluru@marvell.com>; GR-everest-linux-l2 <GR-
>> everest-linux-l2@marvell.com>; Jakub Kicinski <kuba@kernel.org>; David
>> Härdeman <david@hardeman.nu>
>> Cc: linux-pci@vger.kernel.org; netdev@vger.kernel.org
>> Subject: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
>>
>> External Email
>>
>> ----------------------------------------------------------------------
>> Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and
>> read the full VPD data into it.
>>
>> This simplifies the code, and we no longer have to make assumptions about
>> VPD size.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>  drivers/net/ethernet/broadcom/bnx2x/bnx2x.h   |  1 -
>>  .../net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 44 +++++--------------
>>  2 files changed, 10 insertions(+), 35 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
>> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
>> index d04994840..e789430f4 100644
>> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
>> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
>> @@ -2407,7 +2407,6 @@ void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8
>> func, u8 idu_sb_id,
>>  #define ETH_MAX_RX_CLIENTS_E2		ETH_MAX_RX_CLIENTS_E1H
>>  #endif
>>
>> -#define BNX2X_VPD_LEN			128
>>  #define VENDOR_ID_LEN			4
>>
>>  #define VF_ACQUIRE_THRESH		3
>> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> index 6d9813491..0466adf8d 100644
>> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> @@ -12189,50 +12189,29 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
>>
>>  static void bnx2x_read_fwinfo(struct bnx2x *bp)
>>  {
>> -	int cnt, i, block_end, rodi;
>> -	char vpd_start[BNX2X_VPD_LEN+1];
>> +	int i, block_end, rodi;
>>  	char str_id_reg[VENDOR_ID_LEN+1];
>>  	char str_id_cap[VENDOR_ID_LEN+1];
>> -	char *vpd_data;
>> -	char *vpd_extended_data = NULL;
>> -	u8 len;
>> +	unsigned int vpd_len;
>> +	u8 *vpd_data, len;
>>
>> -	cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
>>  	memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
>>
>> -	if (cnt < BNX2X_VPD_LEN)
>> -		goto out_not_found;
>> +	vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
> 
> Definition of pci_vpd_alloc() is below as per repo "git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git" and   branch wip/heiner-vpd-api
> void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size)
> {
>         unsigned int len = dev->vpd.len;
>         void *buf;
> --
> --
>         if (size)
>                 *size = len;
> }
> Here is len is already part of pci_dev.  
> 
> So why cannot same be set in caller function i.e. vpd_len = pb->pdev->vpd.len
> 
Internals of struct pci_vpd shouldn't be referenced outside PCI core.
Also you can't use vpd.len w/o checking vpd.cap.
pci_vpd_alloc() encapsulates these internals.

> 
>> +	if (IS_ERR(vpd_data))
>> +		return;
>>
>>  	/* VPD RO tag should be first tag after identifier string, hence
>>  	 * we should be able to find it in first BNX2X_VPD_LEN chars
>>  	 */
>> -	i = pci_vpd_find_tag(vpd_start, BNX2X_VPD_LEN,
>> PCI_VPD_LRDT_RO_DATA);
>> +	i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
>>  	if (i < 0)
>>  		goto out_not_found;
>>
>>  	block_end = i + PCI_VPD_LRDT_TAG_SIZE +
>> -		    pci_vpd_lrdt_size(&vpd_start[i]);
>> -
>> +		    pci_vpd_lrdt_size(&vpd_data[i]);
>>  	i += PCI_VPD_LRDT_TAG_SIZE;
>>
>> -	if (block_end > BNX2X_VPD_LEN) {
>> -		vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
>> -		if (vpd_extended_data  == NULL)
>> -			goto out_not_found;
>> -
>> -		/* read rest of vpd image into vpd_extended_data */
>> -		memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
>> -		cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
>> -				   block_end - BNX2X_VPD_LEN,
>> -				   vpd_extended_data + BNX2X_VPD_LEN);
>> -		if (cnt < (block_end - BNX2X_VPD_LEN))
>> -			goto out_not_found;
>> -		vpd_data = vpd_extended_data;
>> -	} else
>> -		vpd_data = vpd_start;
>> -
>> -	/* now vpd_data holds full vpd content in both cases */
>> -
>>  	rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
>>  				   PCI_VPD_RO_KEYWORD_MFR_ID);
>>  	if (rodi < 0)
>> @@ -12258,17 +12237,14 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp)
>>
>>  			rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
>>
>> -			if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
>> +			if (len < 32 && (len + rodi) <= vpd_len) {
>>  				memcpy(bp->fw_ver, &vpd_data[rodi], len);
>>  				bp->fw_ver[len] = ' ';
>>  			}
>>  		}
>> -		kfree(vpd_extended_data);
>> -		return;
>>  	}
>>  out_not_found:
>> -	kfree(vpd_extended_data);
>> -	return;
>> +	kfree(vpd_data);
> 
> As vpd_data allocation done in PCI layer. 
> It will be logical to also free vpd_data in PCI layer.
> 
The idea is right, however a call like pci_vpd_free() would be a one-liner
calling kfree(), and I doubt it's really worth it.

> --pk
> 
Heiner

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
  2021-08-22 13:53 ` [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() Heiner Kallweit
@ 2021-08-22 17:42     ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-08-22 17:42 UTC (permalink / raw)
  To: Heiner Kallweit, Bjorn Helgaas, Ariel Elior, Sudarsana Kalluru,
	GR-everest-linux-l2, Jakub Kicinski, David Härdeman
  Cc: kbuild-all, linux-pci, netdev

[-- Attachment #1: Type: text/plain, Size: 4459 bytes --]

Hi Heiner,

I love your patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on pci/next mkp-scsi/for-next linus/master v5.14-rc6 next-20210820]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Heiner-Kallweit/PCI-VPD-Convert-more-users-to-the-new-VPD-API-functions/20210822-220229
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/11d3b0532e225fec84b84c082ff913ab35cecd29
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Heiner-Kallweit/PCI-VPD-Convert-more-users-to-the-new-VPD-API-functions/20210822-220229
        git checkout 11d3b0532e225fec84b84c082ff913ab35cecd29
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=xtensa 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c: In function 'bnx2x_read_fwinfo':
   drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c:12200:20: error: implicit declaration of function 'pci_vpd_alloc'; did you mean 'pci_pool_alloc'? [-Werror=implicit-function-declaration]
   12200 |         vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
         |                    ^~~~~~~~~~~~~
         |                    pci_pool_alloc
>> drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c:12200:18: warning: assignment to 'u8 *' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
   12200 |         vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
         |                  ^
   cc1: some warnings being treated as errors


vim +12200 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

 12189	
 12190	static void bnx2x_read_fwinfo(struct bnx2x *bp)
 12191	{
 12192		int i, block_end, rodi;
 12193		char str_id_reg[VENDOR_ID_LEN+1];
 12194		char str_id_cap[VENDOR_ID_LEN+1];
 12195		unsigned int vpd_len;
 12196		u8 *vpd_data, len;
 12197	
 12198		memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
 12199	
 12200		vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
 12201		if (IS_ERR(vpd_data))
 12202			return;
 12203	
 12204		/* VPD RO tag should be first tag after identifier string, hence
 12205		 * we should be able to find it in first BNX2X_VPD_LEN chars
 12206		 */
 12207		i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
 12208		if (i < 0)
 12209			goto out_not_found;
 12210	
 12211		block_end = i + PCI_VPD_LRDT_TAG_SIZE +
 12212			    pci_vpd_lrdt_size(&vpd_data[i]);
 12213		i += PCI_VPD_LRDT_TAG_SIZE;
 12214	
 12215		rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
 12216					   PCI_VPD_RO_KEYWORD_MFR_ID);
 12217		if (rodi < 0)
 12218			goto out_not_found;
 12219	
 12220		len = pci_vpd_info_field_size(&vpd_data[rodi]);
 12221	
 12222		if (len != VENDOR_ID_LEN)
 12223			goto out_not_found;
 12224	
 12225		rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
 12226	
 12227		/* vendor specific info */
 12228		snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
 12229		snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
 12230		if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
 12231		    !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
 12232	
 12233			rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
 12234							PCI_VPD_RO_KEYWORD_VENDOR0);
 12235			if (rodi >= 0) {
 12236				len = pci_vpd_info_field_size(&vpd_data[rodi]);
 12237	
 12238				rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
 12239	
 12240				if (len < 32 && (len + rodi) <= vpd_len) {
 12241					memcpy(bp->fw_ver, &vpd_data[rodi], len);
 12242					bp->fw_ver[len] = ' ';
 12243				}
 12244			}
 12245		}
 12246	out_not_found:
 12247		kfree(vpd_data);
 12248	}
 12249	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 68217 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
@ 2021-08-22 17:42     ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-08-22 17:42 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4568 bytes --]

Hi Heiner,

I love your patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on pci/next mkp-scsi/for-next linus/master v5.14-rc6 next-20210820]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Heiner-Kallweit/PCI-VPD-Convert-more-users-to-the-new-VPD-API-functions/20210822-220229
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/11d3b0532e225fec84b84c082ff913ab35cecd29
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Heiner-Kallweit/PCI-VPD-Convert-more-users-to-the-new-VPD-API-functions/20210822-220229
        git checkout 11d3b0532e225fec84b84c082ff913ab35cecd29
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=xtensa 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c: In function 'bnx2x_read_fwinfo':
   drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c:12200:20: error: implicit declaration of function 'pci_vpd_alloc'; did you mean 'pci_pool_alloc'? [-Werror=implicit-function-declaration]
   12200 |         vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
         |                    ^~~~~~~~~~~~~
         |                    pci_pool_alloc
>> drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c:12200:18: warning: assignment to 'u8 *' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
   12200 |         vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
         |                  ^
   cc1: some warnings being treated as errors


vim +12200 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

 12189	
 12190	static void bnx2x_read_fwinfo(struct bnx2x *bp)
 12191	{
 12192		int i, block_end, rodi;
 12193		char str_id_reg[VENDOR_ID_LEN+1];
 12194		char str_id_cap[VENDOR_ID_LEN+1];
 12195		unsigned int vpd_len;
 12196		u8 *vpd_data, len;
 12197	
 12198		memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
 12199	
 12200		vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
 12201		if (IS_ERR(vpd_data))
 12202			return;
 12203	
 12204		/* VPD RO tag should be first tag after identifier string, hence
 12205		 * we should be able to find it in first BNX2X_VPD_LEN chars
 12206		 */
 12207		i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
 12208		if (i < 0)
 12209			goto out_not_found;
 12210	
 12211		block_end = i + PCI_VPD_LRDT_TAG_SIZE +
 12212			    pci_vpd_lrdt_size(&vpd_data[i]);
 12213		i += PCI_VPD_LRDT_TAG_SIZE;
 12214	
 12215		rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
 12216					   PCI_VPD_RO_KEYWORD_MFR_ID);
 12217		if (rodi < 0)
 12218			goto out_not_found;
 12219	
 12220		len = pci_vpd_info_field_size(&vpd_data[rodi]);
 12221	
 12222		if (len != VENDOR_ID_LEN)
 12223			goto out_not_found;
 12224	
 12225		rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
 12226	
 12227		/* vendor specific info */
 12228		snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
 12229		snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
 12230		if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
 12231		    !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
 12232	
 12233			rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
 12234							PCI_VPD_RO_KEYWORD_VENDOR0);
 12235			if (rodi >= 0) {
 12236				len = pci_vpd_info_field_size(&vpd_data[rodi]);
 12237	
 12238				rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
 12239	
 12240				if (len < 32 && (len + rodi) <= vpd_len) {
 12241					memcpy(bp->fw_ver, &vpd_data[rodi], len);
 12242					bp->fw_ver[len] = ' ';
 12243				}
 12244			}
 12245		}
 12246	out_not_found:
 12247		kfree(vpd_data);
 12248	}
 12249	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 68217 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc()
  2021-08-22 13:46 [PATCH 00/12] PCI/VPD: Convert more users to the new VPD API functions Heiner Kallweit
@ 2021-08-22 13:53 ` Heiner Kallweit
  2021-08-22 17:42     ` kernel test robot
  0 siblings, 1 reply; 5+ messages in thread
From: Heiner Kallweit @ 2021-08-22 13:53 UTC (permalink / raw)
  To: Bjorn Helgaas, Ariel Elior, Sudarsana Kalluru,
	GR-everest-linux-l2, Jakub Kicinski, David Härdeman
  Cc: linux-pci, netdev

Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and
read the full VPD data into it.

This simplifies the code, and we no longer have to make assumptions about
VPD size.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h   |  1 -
 .../net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 44 +++++--------------
 2 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index d04994840..e789430f4 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -2407,7 +2407,6 @@ void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id,
 #define ETH_MAX_RX_CLIENTS_E2		ETH_MAX_RX_CLIENTS_E1H
 #endif
 
-#define BNX2X_VPD_LEN			128
 #define VENDOR_ID_LEN			4
 
 #define VF_ACQUIRE_THRESH		3
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 6d9813491..0466adf8d 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -12189,50 +12189,29 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
 
 static void bnx2x_read_fwinfo(struct bnx2x *bp)
 {
-	int cnt, i, block_end, rodi;
-	char vpd_start[BNX2X_VPD_LEN+1];
+	int i, block_end, rodi;
 	char str_id_reg[VENDOR_ID_LEN+1];
 	char str_id_cap[VENDOR_ID_LEN+1];
-	char *vpd_data;
-	char *vpd_extended_data = NULL;
-	u8 len;
+	unsigned int vpd_len;
+	u8 *vpd_data, len;
 
-	cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
 	memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
 
-	if (cnt < BNX2X_VPD_LEN)
-		goto out_not_found;
+	vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
+	if (IS_ERR(vpd_data))
+		return;
 
 	/* VPD RO tag should be first tag after identifier string, hence
 	 * we should be able to find it in first BNX2X_VPD_LEN chars
 	 */
-	i = pci_vpd_find_tag(vpd_start, BNX2X_VPD_LEN, PCI_VPD_LRDT_RO_DATA);
+	i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
 	if (i < 0)
 		goto out_not_found;
 
 	block_end = i + PCI_VPD_LRDT_TAG_SIZE +
-		    pci_vpd_lrdt_size(&vpd_start[i]);
-
+		    pci_vpd_lrdt_size(&vpd_data[i]);
 	i += PCI_VPD_LRDT_TAG_SIZE;
 
-	if (block_end > BNX2X_VPD_LEN) {
-		vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
-		if (vpd_extended_data  == NULL)
-			goto out_not_found;
-
-		/* read rest of vpd image into vpd_extended_data */
-		memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
-		cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
-				   block_end - BNX2X_VPD_LEN,
-				   vpd_extended_data + BNX2X_VPD_LEN);
-		if (cnt < (block_end - BNX2X_VPD_LEN))
-			goto out_not_found;
-		vpd_data = vpd_extended_data;
-	} else
-		vpd_data = vpd_start;
-
-	/* now vpd_data holds full vpd content in both cases */
-
 	rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
 				   PCI_VPD_RO_KEYWORD_MFR_ID);
 	if (rodi < 0)
@@ -12258,17 +12237,14 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp)
 
 			rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
 
-			if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
+			if (len < 32 && (len + rodi) <= vpd_len) {
 				memcpy(bp->fw_ver, &vpd_data[rodi], len);
 				bp->fw_ver[len] = ' ';
 			}
 		}
-		kfree(vpd_extended_data);
-		return;
 	}
 out_not_found:
-	kfree(vpd_extended_data);
-	return;
+	kfree(vpd_data);
 }
 
 static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-24 14:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 14:20 [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() Prabhakar Kushwaha
2021-08-24 14:30 ` Heiner Kallweit
  -- strict thread matches above, loose matches on Subject: below --
2021-08-22 13:46 [PATCH 00/12] PCI/VPD: Convert more users to the new VPD API functions Heiner Kallweit
2021-08-22 13:53 ` [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 17:42   ` kernel test robot
2021-08-22 17:42     ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.