cxgb4: add support to read/write flash
Subsystems (3)
v2 cover cxgb4: add support to read/write flash
This series of patches adds support to read/write different binary images of serial flash present in Chelsio terminator.
V2 changes:
Patch 1: No change
Patch 2: No change
Patch 3: Fix 4 compilation warnings reported by C=1, W=1 flags Patch 4: No change
Patch 5: No change
Vishal Kulkarni (5):
cxgb4: update set_flash to flash different images
cxgb4: add support to flash PHY image
cxgb4: add support to flash boot image
cxgb4: add support to flash boot cfg image
cxgb4: add support to read serial flash
drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h | 3 +- .../net/ethernet/chelsio/cxgb4/cudbg_lib.c | 38 +++ .../net/ethernet/chelsio/cxgb4/cudbg_lib.h | 4 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 67 +++++ .../net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c | 14 + .../net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h | 1 + .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 244 ++++++++++++++- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 277 ++++++++++++++++++ drivers/net/ethernet/chelsio/cxgb4/t4_regs.h | 6 + 9 files changed, 638 insertions(+), 16 deletions(-)
Signature · 1 line
2.21.1
PATCH v2 1/5 cxgb4: update set_flash to flash different images
Chelsio adapter contains different flash regions and each region is used by different binary files. This patch adds support to flash images like PHY firmware, boot and boot config using ethtool -f N.
The N value mapping is as follows.
N = 0 : Parse image and decide which region to flash N = 1 : Firmware
N = 2 : PHY firmware
N = 3 : boot image
N = 4 : boot cfg
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 9 ++ .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 121 +++++++++++++++--- 2 files changed, 115 insertions(+), 15 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +9 -0
@@ -139,6 +139,10 @@ enum cc_fec {FEC_BASER_RS =1 <<2 /* BaseR/Reed-Solomon */ }; +enum { +CXGB4_ETHTOOL_FLASH_FW =1 , +}; +struct port_stats {u64 tx_octets;/* total # of octets in good frames */ u64 tx_frames;/* all good frames */
@@ -492,6 +496,11 @@ struct trace_params {unsigned char port; }; +struct cxgb4_fw_data { +__be32 signature; +__u8 reserved[4 ]; +}; +/* Firmware Port Capabilities types. */ typedef u16 fw_port_cap16_t ;/* 16-bit Port Capabilities integral value */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +106 -15
146 lines not on this page · raw message
Signature · 1 line
2.21.1
PATCH v2 2/5 cxgb4: add support to flash PHY image
In reply to Vishal KulkarniUpdate set_flash to flash PHY image to flash region
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 1 + .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +1 -0
@@ -141,6 +141,7 @@ enum cc_fec {enum {CXGB4_ETHTOOL_FLASH_FW =1 , +CXGB4_ETHTOOL_FLASH_PHY =2 , };struct port_stats {
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +39 -0
@@ -26,6 +26,7 @@ static void set_msglevel(struct net_device *dev, u32 val)static const char *const flash_region_strings[] = {"All" ,"Firmware" , +"PHY Firmware" , };static const char stats_strings[][ETH_GSTRING_LEN ] = {
@@ -1240,6 +1241,39 @@ static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,return err; } +#define CXGB4_PHY_SIG 0x130000ea + +static int cxgb4_validate_phy_image (const u8 *data,u32 *size) +{ +struct cxgb4_fw_data *header; + + header = (struct cxgb4_fw_data *)data; +if (be32_to_cpu (header->signature) !=CXGB4_PHY_SIG ) +return -EINVAL ; + +return 0 ; +} + +static int cxgb4_ethtool_flash_phy (struct net_device *netdev, +const u8 *data,u32 size) +{ +struct adapter *adap =netdev2adap (netdev); +int ret; + + ret =cxgb4_validate_phy_image (data,NULL ); +if (ret) { +dev_err (adap->pdev_dev,"PHY signature mismatch\n" ); +return ret; + } + + ret =t4_load_phy_fw (adap,MEMWIN_NIC , &adap->win0_lock, +NULL , data, size); +if (ret) +dev_err (adap->pdev_dev,"Failed to load PHY FW\n" ); + +return ret; +} +static int cxgb4_ethtool_flash_fw (struct net_device *netdev,const u8 *data,u32 size) {
@@ -1273,6 +1307,9 @@ static int cxgb4_ethtool_flash_region(struct net_device *netdev,case CXGB4_ETHTOOL_FLASH_FW : ret =cxgb4_ethtool_flash_fw (netdev, data, size);break ; +case CXGB4_ETHTOOL_FLASH_PHY : + ret =cxgb4_ethtool_flash_phy (netdev, data, size); +break ;default : ret = -EOPNOTSUPP ;break ;
@@ -1306,6 +1343,8 @@ static int cxgb4_ethtool_get_flash_region(const u8 *data, u32 *size) {if (!cxgb4_validate_fw_image (data, size))return CXGB4_ETHTOOL_FLASH_FW ; +if (!cxgb4_validate_phy_image (data, size)) +return CXGB4_ETHTOOL_FLASH_PHY ;return -EOPNOTSUPP ; }
Signature · 1 line
2.21.1
PATCH v2 3/5 cxgb4: add support to flash boot image
In reply to Vishal KulkarniUpdate set_flash to flash boot image to flash region
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 48 +++++ .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 56 ++++++ drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 187 ++++++++++++++++++ drivers/net/ethernet/chelsio/cxgb4/t4_regs.h | 6 + 4 files changed, 297 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +48 -0
@@ -142,6 +142,52 @@ enum cc_fec {enum {CXGB4_ETHTOOL_FLASH_FW =1 ,CXGB4_ETHTOOL_FLASH_PHY =2 , +CXGB4_ETHTOOL_FLASH_BOOT =3 , +}; + +struct cxgb4_pcir_data { +__le32 signature;/* Signature. The string "PCIR" */ +__le16 vendor_id;/* Vendor Identification */ +__le16 device_id;/* Device Identification */ +__u8 vital_product[2 ];/* Pointer to Vital Product Data */ +__u8 length[2 ];/* PCIR Data Structure Length */ +__u8 revision;/* PCIR Data Structure Revision */ +__u8 class_code[3 ];/* Class Code */ +__u8 image_length[2 ];/* Image Length. Multiple of 512B */ +__u8 code_revision[2 ];/* Revision Level of Code/Data */ +__u8 code_type; +__u8 indicator; +__u8 reserved[2 ]; +}; + +/* BIOS boot headers */ +struct cxgb4_pci_exp_rom_header { +__le16 signature;/* ROM Signature. Should be 0xaa55 */ +__u8 reserved[22 ];/* Reserved per processor Architecture data */ +__le16 pcir_offset;/* Offset to PCI Data Structure */ +}; + +/* Legacy PCI Expansion ROM Header */ +struct legacy_pci_rom_hdr { +__u8 signature[2 ];/* ROM Signature. Should be 0xaa55 */ +__u8 size512;/* Current Image Size in units of 512 bytes */ +__u8 initentry_point[4 ]; +__u8 cksum;/* Checksum computed on the entire Image */ +__u8 reserved[16 ];/* Reserved */ +__le16 pcir_offset;/* Offset to PCI Data Struture */ +}; + +#define CXGB4_HDR_CODE1 0x00 +#define CXGB4_HDR_CODE2 0x03 +#define CXGB4_HDR_INDI 0x80 + +/* BOOT constants */ +enum { +BOOT_SIZE_INC =512 , +BOOT_SIGNATURE =0xaa55 , +BOOT_MIN_SIZE =sizeof (struct cxgb4_pci_exp_rom_header ), +BOOT_MAX_SIZE =1024 *BOOT_SIZE_INC , +PCIR_SIGNATURE =0x52494350 };struct port_stats {
@@ -1998,6 +2044,8 @@ void t4_register_netevent_notifier(void);int t4_i2c_rd (struct adapter *adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 *buf); +int t4_load_boot (struct adapter *adap,u8 *boot_data, +unsigned int boot_addr,unsigned int size);void free_rspq_fl (struct adapter *adap,struct sge_rspq *rq,struct sge_fl *fl);void free_tx_desc (struct adapter *adap,struct sge_txq *q,unsigned int n,bool unmap);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +56 -0
84 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +187 -0
190 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/t4_regs.h +6 -0
@@ -563,6 +563,12 @@#define AIVEC_V (x) ((x) << AIVEC_S)#define PCIE_PF_CLI_A 0x44 + +#define PCIE_PF_EXPROM_OFST_A 0x4c +#define OFFSET_S 10 +#define OFFSET_M 0x3fffU +#define OFFSET_G (x) (((x) >> OFFSET_S) & OFFSET_M) +#define PCIE_INT_CAUSE_A 0x3004#define UNXSPLCPLERR_S 29
Signature · 1 line
2.21.1
PATCH v2 4/5 cxgb4: add support to flash boot cfg image
In reply to Vishal KulkarniUpdate set_flash to flash boot cfg image to flash region
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 9 ++ .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 30 +++++++ drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 90 +++++++++++++++++++ 3 files changed, 129 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +9 -0
@@ -143,6 +143,12 @@ enum {CXGB4_ETHTOOL_FLASH_FW =1 ,CXGB4_ETHTOOL_FLASH_PHY =2 ,CXGB4_ETHTOOL_FLASH_BOOT =3 , +CXGB4_ETHTOOL_FLASH_BOOTCFG =4 +}; + +struct cxgb4_bootcfg_data { +__le16 signature; +__u8 reserved[2 ]; }; struct cxgb4_pcir_data {
@@ -183,6 +189,7 @@ struct legacy_pci_rom_hdr {/* BOOT constants */ enum { +BOOT_CFG_SIG =0x4243 ,BOOT_SIZE_INC =512 ,BOOT_SIGNATURE =0xaa55 ,BOOT_MIN_SIZE =sizeof (struct cxgb4_pci_exp_rom_header ),
@@ -2046,6 +2053,8 @@ int t4_i2c_rd(struct adapter *adap, unsigned int mbox, int port, unsigned int len, u8 *buf);int t4_load_boot (struct adapter *adap,u8 *boot_data,unsigned int boot_addr,unsigned int size); +int t4_load_bootcfg (struct adapter *adap, +const u8 *cfg_data,unsigned int size);void free_rspq_fl (struct adapter *adap,struct sge_rspq *rq,struct sge_fl *fl);void free_tx_desc (struct adapter *adap,struct sge_txq *q,unsigned int n,bool unmap);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +30 -0
@@ -28,6 +28,7 @@ static const char * const flash_region_strings[] = {"Firmware" ,"PHY Firmware" ,"Boot" , + "Boot CFG", }; static const char stats_strings[][ETH_GSTRING_LEN] = {
@@ -1242,6 +1243,19 @@ static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,return err; } +static int cxgb4_ethtool_flash_bootcfg (struct net_device *netdev, +const u8 *data,u32 size) +{ +struct adapter *adap =netdev2adap (netdev); +int ret; + + ret =t4_load_bootcfg (adap, data, size); +if (ret) +dev_err (adap->pdev_dev,"Failed to load boot cfg image\n" ); + +return ret; +} +static int cxgb4_ethtool_flash_boot (struct net_device *netdev,const u8 *bdata,u32 size) {
@@ -1336,6 +1350,9 @@ static int cxgb4_ethtool_flash_region(struct net_device *netdev,case CXGB4_ETHTOOL_FLASH_BOOT : ret =cxgb4_ethtool_flash_boot (netdev, data, size);break ; +case CXGB4_ETHTOOL_FLASH_BOOTCFG : + ret =cxgb4_ethtool_flash_bootcfg (netdev, data, size); +break ;default : ret = -EOPNOTSUPP ;break ;
@@ -1365,6 +1382,17 @@ static int cxgb4_validate_fw_image(const u8 *data, u32 *size)return 0 ; } +static int cxgb4_validate_bootcfg_image (const u8 *data,u32 *size) +{ +struct cxgb4_bootcfg_data *header; + + header = (struct cxgb4_bootcfg_data *)data; +if (le16_to_cpu (header->signature) !=BOOT_CFG_SIG ) +return -EINVAL ; + +return 0 ; +} +static int cxgb4_validate_boot_image (const u8 *data,u32 *size) {struct cxgb4_pci_exp_rom_header *exp_header;
@@ -1401,6 +1429,8 @@ static int cxgb4_ethtool_get_flash_region(const u8 *data, u32 *size)return CXGB4_ETHTOOL_FLASH_BOOT ;if (!cxgb4_validate_phy_image (data, size))return CXGB4_ETHTOOL_FLASH_PHY ; +if (!cxgb4_validate_bootcfg_image (data, size)) +return CXGB4_ETHTOOL_FLASH_BOOTCFG ;return -EOPNOTSUPP ; }
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +90 -0
93 lines not on this page · raw message
Signature · 1 line
2.21.1
PATCH v2 5/5 cxgb4: add support to read serial flash
In reply to Vishal KulkarniThis patch adds support to dump flash memory via
ethtool --get-dump
--- drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h | 3 +- .../net/ethernet/chelsio/cxgb4/cudbg_lib.c | 38 +++++++++++++++++++ .../net/ethernet/chelsio/cxgb4/cudbg_lib.h | 4 +- .../net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c | 14 +++++++ .../net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h | 1 + 5 files changed, 58 insertions(+), 2 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h +2 -1
@@ -70,7 +70,8 @@ enum cudbg_dbg_entity_type {CUDBG_HMA_INDIRECT =67 ,CUDBG_HMA =68 ,CUDBG_QDESC =70 , - CUDBG_MAX_ENTITY = 71, +CUDBG_FLASH =71 , + CUDBG_MAX_ENTITY = 72, }; struct cudbg_init {
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +38 -0
@@ -3156,3 +3156,41 @@ int cudbg_collect_qdesc(struct cudbg_init *pdbg_init,return rc; } + +int cudbg_collect_flash (struct cudbg_init *pdbg_init, +struct cudbg_buffer *dbg_buff, +struct cudbg_error *cudbg_err) +{ +struct adapter *padap = pdbg_init->adap; +u32 count = padap->params.sf_size, n; +struct cudbg_buffer temp_buff = {0 }; +u32 addr, i; +int rc; + + addr =FLASH_EXP_ROM_START ; + +for (i =0 ; i < count; i +=SF_PAGE_SIZE ) { + n =min_t (u32, count - i,SF_PAGE_SIZE ); + + rc =cudbg_get_buff (pdbg_init, dbg_buff, n, &temp_buff); +if (rc) { + cudbg_err->sys_warn =CUDBG_STATUS_PARTIAL_DATA ; + goto out; + } + rc =t4_read_flash (padap, addr, n, (u32 *)temp_buff.data,0 ); +if (rc) + goto out; + + addr += (n *4 ); + rc =cudbg_write_and_release_buff (pdbg_init, &temp_buff, + dbg_buff); +if (rc) { + cudbg_err->sys_warn =CUDBG_STATUS_PARTIAL_DATA ; + goto out; + } + } + +out: +return rc; +} +
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.h +3 -1
@@ -162,7 +162,9 @@ int cudbg_collect_hma_meminfo(struct cudbg_init *pdbg_init,int cudbg_collect_qdesc (struct cudbg_init *pdbg_init,struct cudbg_buffer *dbg_buff,struct cudbg_error *cudbg_err); - +int cudbg_collect_flash (struct cudbg_init *pdbg_init, +struct cudbg_buffer *dbg_buff, +struct cudbg_error *cudbg_err);struct cudbg_entity_hdr *cudbg_get_entity_hdr (void *outbuf,int i);void cudbg_align_debug_buffer (struct cudbg_buffer *dbg_buff,struct cudbg_entity_hdr *entity_hdr);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c +14 -0
@@ -66,6 +66,10 @@ static const struct cxgb4_collect_entity cxgb4_collect_hw_dump[] = { { CUDBG_HMA_INDIRECT, cudbg_collect_hma_indirect }, }; +static const struct cxgb4_collect_entity cxgb4_collect_flash_dump[] = { + {CUDBG_FLASH , cudbg_collect_flash }, +}; +static u32 cxgb4_get_entity_length (struct adapter *adap,u32 entity) {struct cudbg_tcam tcam_region = {0 };
@@ -330,6 +334,9 @@ u32 cxgb4_get_dump_length(struct adapter *adap, u32 flag) } } +if (flag &CXGB4_ETH_DUMP_FLASH ) + len += adap->params.sf_size; +/* If compression is enabled, a smaller destination buffer is enough */ wsize =cudbg_get_workspace_size ();if (wsize && len >CUDBG_DUMP_BUFF_SIZE )
@@ -468,6 +475,13 @@ int cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size, buf, &total_size); +if (flag &CXGB4_ETH_DUMP_FLASH ) +cxgb4_cudbg_collect_entity (&cudbg_init, &dbg_buff, + cxgb4_collect_flash_dump, +ARRAY_SIZE (cxgb4_collect_flash_dump), + buf, + &total_size); +cudbg_free_compress_buff (&cudbg_init); cudbg_hdr->data_len = total_size;if (cudbg_init.compress_type !=CUDBG_COMPRESSION_NONE )
drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h +1 -0
@@ -27,6 +27,7 @@ enum CXGB4_ETHTOOL_DUMP_FLAGS {CXGB4_ETH_DUMP_NONE =ETH_FW_DUMP_DISABLE ,CXGB4_ETH_DUMP_MEM = (1 <<0 ),/* On-Chip Memory Dumps */ CXGB4_ETH_DUMP_HW = (1 <<1 ),/* various FW and HW dumps */ + CXGB4_ETH_DUMP_FLASH = (1 << 2), /* Dump flash memory */ };#define CXGB4_ETH_DUMP_ALL (CXGB4_ETH_DUMP_MEM | CXGB4_ETH_DUMP_HW)
Signature · 1 line
2.21.1
David Miller
maintainerFrom: Vishal Kulkarni <[email protected]>
Date: Thu, 18 Jun 2020 11:35:51 +0530
Quoted 9 lines
This series of patches adds support to read/write different binary images of serial flash present in Chelsio terminator.
V2 changes:
Patch 1: No change
Patch 2: No change
Patch 3: Fix 4 compilation warnings reported by C=1, W=1 flags Patch 4: No change
Patch 5: No change
Series applied, thank you.