cxgb4: remove bogus CHELSIO_VPD_UNIQUE_ID constant
Subsystems (3)
PATCH 1/1 cxgb4: remove bogus CHELSIO_VPD_UNIQUE_ID constant
The comment is quite weird, there is no such thing as a vendor-specific VPD id. 0x82 is the value of PCI_VPD_LRDT_ID_STRING. So what we are doing here is simply checking whether the byte at VPD address VPD_BASE is a valid string LRDT, same as what is done a few lines later in the code.
LRDT = Large Resource Data Tag, see PCI 2.2 spec, VPD chapter
--- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +5 -11
@@ -2689,7 +2689,6 @@ void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)#define VPD_BASE 0x400#define VPD_BASE_OLD 0#define VPD_LEN 1024 -#define CHELSIO_VPD_UNIQUE_ID 0x82/** * t4_eeprom_ptov - translate a physical EEPROM address to virtual
@@ -2743,9 +2742,9 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable)*/ int t4_get_raw_vpd_params (struct adapter *adapter,struct vpd_params *p) { -int i, ret =0 , addr; +int i, ret =0 , addr =VPD_BASE ;int ec, sn, pn, na; -u8 *vpd, csum; +u8 *vpd, csum, base_val =0 ;unsigned int vpdr_len, kw_offset, id_len; vpd =vmalloc (VPD_LEN );
@@ -2755,17 +2754,12 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)/* Card information normally starts at VPD_BASE but early cards had * it at 0. */ - ret =pci_read_vpd (adapter->pdev,VPD_BASE ,sizeof (u32), vpd); + ret =pci_read_vpd (adapter->pdev,VPD_BASE ,1 , &base_val);if (ret <0 ) goto out; -/* The VPD shall have a unique identifier specified by the PCI SIG. -* For chelsio adapters, the identifier is 0x82. The first byte of a VPD -* shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software -* is expected to automatically put this entry at the -* beginning of the VPD. -*/ - addr = *vpd ==CHELSIO_VPD_UNIQUE_ID ?VPD_BASE :VPD_BASE_OLD ; +if (base_val !=PCI_VPD_LRDT_ID_STRING ) + addr =VPD_BASE_OLD ; ret =pci_read_vpd (adapter->pdev, addr,VPD_LEN , vpd);if (ret <0 )
Signature · 1 line
2.30.0
Jakub Kicinski
maintainerQuoted 8 lines · On Sat, 16 Jan 2021 14:45:25 +0100 Heiner Kallweit wrote:
The comment is quite weird, there is no such thing as a vendor-specific VPD id.
0x82is the value ofPCI_VPD_LRDT_ID_STRING. So what we are doing here is simply checking whether the byte at VPD addressVPD_BASEis a valid string LRDT, same as what is done a few lines later in the code.
LRDT = Large Resource Data Tag, see PCI 2.2 spec, VPD chapterSigned-off-by Heiner Kallweit <[email protected]>
Did you find this by code inspection?
Quoted 13 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +0
-1@@ -2689,7 +2689,6 @@ void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)#define VPD_BASE 0x400#define VPD_BASE_OLD 0#define VPD_LEN 1024 -#define CHELSIO_VPD_UNIQUE_ID 0x82/** * t4_eeprom_ptov - translate a physical EEPROM address to virtual
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c int t4_seeprom_wp(struct adapter *adapter, bool enable) · line 2745
Quoted 5 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +1
-1@@ -2743,9 +2742,9 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable)*/ int t4_get_raw_vpd_params (struct adapter *adapter,struct vpd_params *p) { -int i, ret =0 , addr; +int i, ret =0 , addr =VPD_BASE ;
IMHO it's more readable if the addr is set to BASE or BASE_OLD in one place rather than having a default value at variable init which may be overwritten.
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) · line 2757
Quoted 12 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +2
-2int ec, sn, pn, na; -u8 *vpd, csum; +u8 *vpd, csum, base_val =0 ;unsigned int vpdr_len, kw_offset, id_len; vpd =vmalloc (VPD_LEN );@@ -2755,17 +2754,12 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)/* Card information normally starts at VPD_BASE but early cards had * it at 0. */ - ret =pci_read_vpd (adapter->pdev,VPD_BASE ,sizeof (u32), vpd); + ret =pci_read_vpd (adapter->pdev,VPD_BASE ,1 , &base_val);
Are we sure this works? I've seen silicon out there which has problems with small PCI accesses (granted those were not VPD accesses).
Quoted 15 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +2
-7if (ret <0 ) goto out; -/* The VPD shall have a unique identifier specified by the PCI SIG. -* For chelsio adapters, the identifier is 0x82. The first byte of a VPD -* shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software -* is expected to automatically put this entry at the -* beginning of the VPD. -*/ - addr = *vpd ==CHELSIO_VPD_UNIQUE_ID ?VPD_BASE :VPD_BASE_OLD ; +if (base_val !=PCI_VPD_LRDT_ID_STRING ) + addr =VPD_BASE_OLD ; ret =pci_read_vpd (adapter->pdev, addr,VPD_LEN , vpd);if (ret <0 )
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Sat, 16 Jan 2021 14:45:25 +0100 Heiner Kallweit wrote:
The comment is quite weird, there is no such thing as a vendor-specific VPD id.
0x82is the value ofPCI_VPD_LRDT_ID_STRING. So what we are doing here is simply checking whether the byte at VPD addressVPD_BASEis a valid string LRDT, same as what is done a few lines later in the code.
LRDT = Large Resource Data Tag, see PCI 2.2 spec, VPD chapter
Quoted 4 lines
Quoted 1 line
Signed-off-by Heiner Kallweit <[email protected]>Did you find this by code inspection?
Well, more or less ..
RTL8168 indicates it has VPD but in all cases I've seen there is no VPD EEPROM. Result is that the VPD code throws an "invalid VPD tag" error. When checking the VPD code (+ VPD spec) and its (few) users I came across the chelsio driver.
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +0
-1@@ -2689,7 +2689,6 @@ void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)#define VPD_BASE 0x400#define VPD_BASE_OLD 0#define VPD_LEN 1024 -#define CHELSIO_VPD_UNIQUE_ID 0x82
Quoted 13 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c int t4_seeprom_wp(struct adapter *adapter, bool enable) · line 2745
Quoted 8 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +1
-1/** * t4_eeprom_ptov - translate a physical EEPROM address to virtual @@ -2743,9 +2742,9 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable)*/ int t4_get_raw_vpd_params (struct adapter *adapter,struct vpd_params *p) { -int i, ret =0 , addr; +int i, ret =0 , addr =VPD_BASE ;IMHO it's more readable if the addr is set to BASE or
BASE_OLDin one place rather than having a default value at variable init which may be overwritten.
OK. Thought was just that VPD_BASE is the more common case. I'll change this in a v2.
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +1
-1int ec, sn, pn, na; -u8 *vpd, csum; +u8 *vpd, csum, base_val =0 ;unsigned int vpdr_len, kw_offset, id_len;
Quoted 11 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p) · line 2757
Quoted 7 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +1
-1vpd =vmalloc (VPD_LEN );@@ -2755,17 +2754,12 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)/* Card information normally starts at VPD_BASE but early cards had * it at 0. */ - ret =pci_read_vpd (adapter->pdev,VPD_BASE ,sizeof (u32), vpd); + ret =pci_read_vpd (adapter->pdev,VPD_BASE ,1 , &base_val);Are we sure this works? I've seen silicon out there which has problems with small PCI accesses (granted those were not VPD accesses).
The underlying PCI register access reads 4 bytes, the VPD code will ignore the higher three bytes here.
Quoted 16 lines
Quoted 15 lines
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +2
-7if (ret <0 ) goto out; -/* The VPD shall have a unique identifier specified by the PCI SIG. -* For chelsio adapters, the identifier is 0x82. The first byte of a VPD -* shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software -* is expected to automatically put this entry at the -* beginning of the VPD. -*/ - addr = *vpd ==CHELSIO_VPD_UNIQUE_ID ?VPD_BASE :VPD_BASE_OLD ; +if (base_val !=PCI_VPD_LRDT_ID_STRING ) + addr =VPD_BASE_OLD ; ret =pci_read_vpd (adapter->pdev, addr,VPD_LEN , vpd);if (ret <0 )