Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

csiostor:T5 Firmware fix and cleanup.

This patch fix is to use default firmware configuration files
present in the adapter incase if not available in standard
/lib/firmware/* dir. Additional cleanup is done to reuse flash
related defines from cxgb4 header file.

Please apply over net-next since it depends on previous commit.

Signed-off-by: Praveen Madhavan <praveenm@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Praveen Madhavan and committed by
David S. Miller
216ce69c 5cce1cf7

+128 -257
+127 -217
drivers/scsi/csiostor/csio_hw.c
··· 636 636 static int 637 637 csio_hw_get_fw_version(struct csio_hw *hw, uint32_t *vers) 638 638 { 639 - return csio_hw_read_flash(hw, FW_IMG_START + 639 + return csio_hw_read_flash(hw, FLASH_FW_START + 640 640 offsetof(struct fw_hdr, fw_ver), 1, 641 641 vers, 0); 642 642 } ··· 696 696 return -EINVAL; 697 697 } 698 698 699 - if (size > FW_MAX_SIZE) { 699 + if (size > FLASH_FW_MAX_SIZE) { 700 700 csio_err(hw, "FW image too large, max is %u bytes\n", 701 - FW_MAX_SIZE); 701 + FLASH_FW_MAX_SIZE); 702 702 return -EINVAL; 703 703 } 704 704 ··· 714 714 i = DIV_ROUND_UP(size, sf_sec_size); /* # of sectors spanned */ 715 715 716 716 csio_dbg(hw, "Erasing sectors... start:%d end:%d\n", 717 - FW_START_SEC, FW_START_SEC + i - 1); 717 + FLASH_FW_START_SEC, FLASH_FW_START_SEC + i - 1); 718 718 719 - ret = csio_hw_flash_erase_sectors(hw, FW_START_SEC, 720 - FW_START_SEC + i - 1); 719 + ret = csio_hw_flash_erase_sectors(hw, FLASH_FW_START_SEC, 720 + FLASH_FW_START_SEC + i - 1); 721 721 if (ret) { 722 722 csio_err(hw, "Flash Erase failed\n"); 723 723 goto out; ··· 730 730 */ 731 731 memcpy(first_page, fw_data, SF_PAGE_SIZE); 732 732 ((struct fw_hdr *)first_page)->fw_ver = htonl(0xffffffff); 733 - ret = csio_hw_write_flash(hw, FW_IMG_START, SF_PAGE_SIZE, first_page); 733 + ret = csio_hw_write_flash(hw, FLASH_FW_START, SF_PAGE_SIZE, first_page); 734 734 if (ret) 735 735 goto out; 736 736 737 737 csio_dbg(hw, "Writing Flash .. start:%d end:%d\n", 738 738 FW_IMG_START, FW_IMG_START + size); 739 739 740 - addr = FW_IMG_START; 740 + addr = FLASH_FW_START; 741 741 for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) { 742 742 addr += SF_PAGE_SIZE; 743 743 fw_data += SF_PAGE_SIZE; ··· 747 747 } 748 748 749 749 ret = csio_hw_write_flash(hw, 750 - FW_IMG_START + 750 + FLASH_FW_START + 751 751 offsetof(struct fw_hdr, fw_ver), 752 752 sizeof(hdr->fw_ver), 753 753 (const uint8_t *)&hdr->fw_ver); ··· 1250 1250 return csio_hw_fw_restart(hw, mbox, reset); 1251 1251 } 1252 1252 1253 - 1254 - /* 1255 - * csio_hw_fw_config_file - setup an adapter via a Configuration File 1256 - * @hw: the HW module 1257 - * @mbox: mailbox to use for the FW command 1258 - * @mtype: the memory type where the Configuration File is located 1259 - * @maddr: the memory address where the Configuration File is located 1260 - * @finiver: return value for CF [fini] version 1261 - * @finicsum: return value for CF [fini] checksum 1262 - * @cfcsum: return value for CF computed checksum 1263 - * 1264 - * Issue a command to get the firmware to process the Configuration 1265 - * File located at the specified mtype/maddress. If the Configuration 1266 - * File is processed successfully and return value pointers are 1267 - * provided, the Configuration File "[fini] section version and 1268 - * checksum values will be returned along with the computed checksum. 1269 - * It's up to the caller to decide how it wants to respond to the 1270 - * checksums not matching but it recommended that a prominant warning 1271 - * be emitted in order to help people rapidly identify changed or 1272 - * corrupted Configuration Files. 1273 - * 1274 - * Also note that it's possible to modify things like "niccaps", 1275 - * "toecaps",etc. between processing the Configuration File and telling 1276 - * the firmware to use the new configuration. Callers which want to 1277 - * do this will need to "hand-roll" their own CAPS_CONFIGS commands for 1278 - * Configuration Files if they want to do this. 1279 - */ 1280 - static int 1281 - csio_hw_fw_config_file(struct csio_hw *hw, 1282 - unsigned int mtype, unsigned int maddr, 1283 - uint32_t *finiver, uint32_t *finicsum, uint32_t *cfcsum) 1284 - { 1285 - struct csio_mb *mbp; 1286 - struct fw_caps_config_cmd *caps_cmd; 1287 - int rv = -EINVAL; 1288 - enum fw_retval ret; 1289 - 1290 - mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC); 1291 - if (!mbp) { 1292 - CSIO_INC_STATS(hw, n_err_nomem); 1293 - return -ENOMEM; 1294 - } 1295 - /* 1296 - * Tell the firmware to process the indicated Configuration File. 1297 - * If there are no errors and the caller has provided return value 1298 - * pointers for the [fini] section version, checksum and computed 1299 - * checksum, pass those back to the caller. 1300 - */ 1301 - caps_cmd = (struct fw_caps_config_cmd *)(mbp->mb); 1302 - CSIO_INIT_MBP(mbp, caps_cmd, CSIO_MB_DEFAULT_TMO, hw, NULL, 1); 1303 - caps_cmd->op_to_write = 1304 - htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) | 1305 - FW_CMD_REQUEST_F | 1306 - FW_CMD_READ_F); 1307 - caps_cmd->cfvalid_to_len16 = 1308 - htonl(FW_CAPS_CONFIG_CMD_CFVALID_F | 1309 - FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) | 1310 - FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) | 1311 - FW_LEN16(*caps_cmd)); 1312 - 1313 - if (csio_mb_issue(hw, mbp)) { 1314 - csio_err(hw, "Issue of FW_CAPS_CONFIG_CMD failed!\n"); 1315 - goto out; 1316 - } 1317 - 1318 - ret = csio_mb_fw_retval(mbp); 1319 - if (ret != FW_SUCCESS) { 1320 - csio_dbg(hw, "FW_CAPS_CONFIG_CMD returned %d!\n", rv); 1321 - goto out; 1322 - } 1323 - 1324 - if (finiver) 1325 - *finiver = ntohl(caps_cmd->finiver); 1326 - if (finicsum) 1327 - *finicsum = ntohl(caps_cmd->finicsum); 1328 - if (cfcsum) 1329 - *cfcsum = ntohl(caps_cmd->cfcsum); 1330 - 1331 - /* Validate device capabilities */ 1332 - if (csio_hw_validate_caps(hw, mbp)) { 1333 - rv = -ENOENT; 1334 - goto out; 1335 - } 1336 - 1337 - /* 1338 - * And now tell the firmware to use the configuration we just loaded. 1339 - */ 1340 - caps_cmd->op_to_write = 1341 - htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) | 1342 - FW_CMD_REQUEST_F | 1343 - FW_CMD_WRITE_F); 1344 - caps_cmd->cfvalid_to_len16 = htonl(FW_LEN16(*caps_cmd)); 1345 - 1346 - if (csio_mb_issue(hw, mbp)) { 1347 - csio_err(hw, "Issue of FW_CAPS_CONFIG_CMD failed!\n"); 1348 - goto out; 1349 - } 1350 - 1351 - ret = csio_mb_fw_retval(mbp); 1352 - if (ret != FW_SUCCESS) { 1353 - csio_dbg(hw, "FW_CAPS_CONFIG_CMD returned %d!\n", rv); 1354 - goto out; 1355 - } 1356 - 1357 - rv = 0; 1358 - out: 1359 - mempool_free(mbp, hw->mb_mempool); 1360 - return rv; 1361 - } 1362 - 1363 1253 /* 1364 1254 * csio_get_device_params - Get device parameters. 1365 1255 * @hw: HW module ··· 1652 1762 static int 1653 1763 csio_hw_use_fwconfig(struct csio_hw *hw, int reset, u32 *fw_cfg_param) 1654 1764 { 1765 + struct csio_mb *mbp = NULL; 1766 + struct fw_caps_config_cmd *caps_cmd; 1655 1767 unsigned int mtype, maddr; 1656 - int rv; 1768 + int rv = -EINVAL; 1657 1769 uint32_t finiver = 0, finicsum = 0, cfcsum = 0; 1658 - int using_flash; 1659 1770 char path[64]; 1771 + char *config_name = NULL; 1660 1772 1661 1773 /* 1662 1774 * Reset device if necessary ··· 1678 1786 rv = csio_hw_flash_config(hw, fw_cfg_param, path); 1679 1787 spin_lock_irq(&hw->lock); 1680 1788 if (rv != 0) { 1681 - if (rv == -ENOENT) { 1682 - /* 1683 - * config file was not found. Use default 1684 - * config file from flash. 1685 - */ 1686 - mtype = FW_MEMTYPE_CF_FLASH; 1687 - maddr = hw->chip_ops->chip_flash_cfg_addr(hw); 1688 - using_flash = 1; 1689 - } else { 1690 - /* 1691 - * we revert back to the hardwired config if 1692 - * flashing failed. 1693 - */ 1694 - goto bye; 1695 - } 1789 + /* 1790 + * config file was not found. Use default 1791 + * config file from flash. 1792 + */ 1793 + config_name = "On FLASH"; 1794 + mtype = FW_MEMTYPE_CF_FLASH; 1795 + maddr = hw->chip_ops->chip_flash_cfg_addr(hw); 1696 1796 } else { 1797 + config_name = path; 1697 1798 mtype = FW_PARAMS_PARAM_Y_G(*fw_cfg_param); 1698 1799 maddr = FW_PARAMS_PARAM_Z_G(*fw_cfg_param) << 16; 1699 - using_flash = 0; 1700 1800 } 1701 1801 1702 - hw->cfg_store = (uint8_t)mtype; 1703 - 1802 + mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC); 1803 + if (!mbp) { 1804 + CSIO_INC_STATS(hw, n_err_nomem); 1805 + return -ENOMEM; 1806 + } 1704 1807 /* 1705 - * Issue a Capability Configuration command to the firmware to get it 1706 - * to parse the Configuration File. 1808 + * Tell the firmware to process the indicated Configuration File. 1809 + * If there are no errors and the caller has provided return value 1810 + * pointers for the [fini] section version, checksum and computed 1811 + * checksum, pass those back to the caller. 1707 1812 */ 1708 - rv = csio_hw_fw_config_file(hw, mtype, maddr, &finiver, 1709 - &finicsum, &cfcsum); 1710 - if (rv != 0) 1813 + caps_cmd = (struct fw_caps_config_cmd *)(mbp->mb); 1814 + CSIO_INIT_MBP(mbp, caps_cmd, CSIO_MB_DEFAULT_TMO, hw, NULL, 1); 1815 + caps_cmd->op_to_write = 1816 + htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) | 1817 + FW_CMD_REQUEST_F | 1818 + FW_CMD_READ_F); 1819 + caps_cmd->cfvalid_to_len16 = 1820 + htonl(FW_CAPS_CONFIG_CMD_CFVALID_F | 1821 + FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) | 1822 + FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) | 1823 + FW_LEN16(*caps_cmd)); 1824 + 1825 + if (csio_mb_issue(hw, mbp)) { 1826 + rv = -EINVAL; 1827 + goto bye; 1828 + } 1829 + 1830 + rv = csio_mb_fw_retval(mbp); 1831 + /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware 1832 + * Configuration File in FLASH), our last gasp effort is to use the 1833 + * Firmware Configuration File which is embedded in the 1834 + * firmware. A very few early versions of the firmware didn't 1835 + * have one embedded but we can ignore those. 1836 + */ 1837 + if (rv == ENOENT) { 1838 + CSIO_INIT_MBP(mbp, caps_cmd, CSIO_MB_DEFAULT_TMO, hw, NULL, 1); 1839 + caps_cmd->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) | 1840 + FW_CMD_REQUEST_F | 1841 + FW_CMD_READ_F); 1842 + caps_cmd->cfvalid_to_len16 = htonl(FW_LEN16(*caps_cmd)); 1843 + 1844 + if (csio_mb_issue(hw, mbp)) { 1845 + rv = -EINVAL; 1846 + goto bye; 1847 + } 1848 + 1849 + rv = csio_mb_fw_retval(mbp); 1850 + config_name = "Firmware Default"; 1851 + } 1852 + if (rv != FW_SUCCESS) 1711 1853 goto bye; 1712 1854 1713 - hw->cfg_finiver = finiver; 1714 - hw->cfg_finicsum = finicsum; 1715 - hw->cfg_cfcsum = cfcsum; 1716 - hw->cfg_csum_status = true; 1855 + finiver = ntohl(caps_cmd->finiver); 1856 + finicsum = ntohl(caps_cmd->finicsum); 1857 + cfcsum = ntohl(caps_cmd->cfcsum); 1717 1858 1859 + /* 1860 + * And now tell the firmware to use the configuration we just loaded. 1861 + */ 1862 + caps_cmd->op_to_write = 1863 + htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) | 1864 + FW_CMD_REQUEST_F | 1865 + FW_CMD_WRITE_F); 1866 + caps_cmd->cfvalid_to_len16 = htonl(FW_LEN16(*caps_cmd)); 1867 + 1868 + if (csio_mb_issue(hw, mbp)) { 1869 + rv = -EINVAL; 1870 + goto bye; 1871 + } 1872 + 1873 + rv = csio_mb_fw_retval(mbp); 1874 + if (rv != FW_SUCCESS) { 1875 + csio_dbg(hw, "FW_CAPS_CONFIG_CMD returned %d!\n", rv); 1876 + goto bye; 1877 + } 1878 + 1879 + mempool_free(mbp, hw->mb_mempool); 1718 1880 if (finicsum != cfcsum) { 1719 1881 csio_warn(hw, 1720 1882 "Config File checksum mismatch: csum=%#x, computed=%#x\n", 1721 1883 finicsum, cfcsum); 1722 - 1723 - hw->cfg_csum_status = false; 1724 1884 } 1725 1885 1886 + /* Validate device capabilities */ 1887 + if (csio_hw_validate_caps(hw, mbp)) 1888 + goto bye; 1726 1889 /* 1727 1890 * Note that we're operating with parameters 1728 1891 * not supplied by the driver, rather than from hard-wired ··· 1800 1853 /* Post event to notify completion of configuration */ 1801 1854 csio_post_event(&hw->sm, CSIO_HWE_INIT); 1802 1855 1803 - csio_info(hw, 1804 - "Firmware Configuration File %s, version %#x, computed checksum %#x\n", 1805 - (using_flash ? "in device FLASH" : path), finiver, cfcsum); 1806 - 1856 + csio_info(hw, "Successfully configure using Firmware " 1857 + "Configuration File %s, version %#x, computed checksum %#x\n", 1858 + config_name, finiver, cfcsum); 1807 1859 return 0; 1808 1860 1809 1861 /* 1810 1862 * Something bad happened. Return the error ... 1811 1863 */ 1812 1864 bye: 1865 + if (mbp) 1866 + mempool_free(mbp, hw->mb_mempool); 1813 1867 hw->flags &= ~CSIO_HWF_USING_SOFT_PARAMS; 1814 - csio_dbg(hw, "Configuration file error %d\n", rv); 1815 - return rv; 1816 - } 1817 - 1818 - /* 1819 - * Attempt to initialize the adapter via hard-coded, driver supplied 1820 - * parameters ... 1821 - */ 1822 - static int 1823 - csio_hw_no_fwconfig(struct csio_hw *hw, int reset) 1824 - { 1825 - int rv; 1826 - /* 1827 - * Reset device if necessary 1828 - */ 1829 - if (reset) { 1830 - rv = csio_do_reset(hw, true); 1831 - if (rv != 0) 1832 - goto out; 1833 - } 1834 - 1835 - /* Get and set device capabilities */ 1836 - rv = csio_config_device_caps(hw); 1837 - if (rv != 0) 1838 - goto out; 1839 - 1840 - /* device parameters */ 1841 - rv = csio_get_device_params(hw); 1842 - if (rv != 0) 1843 - goto out; 1844 - 1845 - /* Configure SGE */ 1846 - csio_wr_sge_init(hw); 1847 - 1848 - /* Post event to notify completion of configuration */ 1849 - csio_post_event(&hw->sm, CSIO_HWE_INIT); 1850 - 1851 - out: 1868 + csio_warn(hw, "Configuration file error %d\n", rv); 1852 1869 return rv; 1853 1870 } 1854 1871 ··· 2012 2101 if (request_firmware(&fw, FW_FNAME_T5, dev) < 0) { 2013 2102 csio_err(hw, "could not find firmware image %s, err: %d\n", 2014 2103 FW_FNAME_T5, ret); 2015 - return -EINVAL; 2104 + } else { 2105 + fw_data = fw->data; 2106 + fw_size = fw->size; 2016 2107 } 2017 2108 2018 2109 /* allocate memory to read the header of the firmware on the 2019 2110 * card 2020 2111 */ 2021 2112 card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL); 2022 - 2023 - fw_data = fw->data; 2024 - fw_size = fw->size; 2025 2113 2026 2114 /* upgrade FW logic */ 2027 2115 ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw, ··· 2100 2190 if (rv != 0) 2101 2191 goto out; 2102 2192 2103 - /* 2104 - * If the firmware doesn't support Configuration 2105 - * Files, use the old Driver-based, hard-wired 2106 - * initialization. Otherwise, try using the 2107 - * Configuration File support and fall back to the 2108 - * Driver-based initialization if there's no 2109 - * Configuration File found. 2193 + /* If the firmware doesn't support Configuration Files, 2194 + * return an error. 2110 2195 */ 2111 - if (csio_hw_check_fwconfig(hw, param) == 0) { 2112 - rv = csio_hw_use_fwconfig(hw, reset, param); 2113 - if (rv == -ENOENT) 2114 - goto out; 2115 - if (rv != 0) { 2116 - csio_info(hw, 2117 - "No Configuration File present " 2118 - "on adapter. Using hard-wired " 2119 - "configuration parameters.\n"); 2120 - rv = csio_hw_no_fwconfig(hw, reset); 2121 - } 2122 - } else { 2123 - rv = csio_hw_no_fwconfig(hw, reset); 2196 + rv = csio_hw_check_fwconfig(hw, param); 2197 + if (rv != 0) { 2198 + csio_info(hw, "Firmware doesn't support " 2199 + "Firmware Configuration files\n"); 2200 + goto out; 2124 2201 } 2125 2202 2126 - if (rv != 0) 2203 + /* The firmware provides us with a memory buffer where we can 2204 + * load a Configuration File from the host if we want to 2205 + * override the Configuration File in flash. 2206 + */ 2207 + rv = csio_hw_use_fwconfig(hw, reset, param); 2208 + if (rv == -ENOENT) { 2209 + csio_info(hw, "Could not initialize " 2210 + "adapter, error%d\n", rv); 2127 2211 goto out; 2212 + } 2213 + if (rv != 0) { 2214 + csio_info(hw, "Could not initialize " 2215 + "adapter, error%d\n", rv); 2216 + goto out; 2217 + } 2128 2218 2129 2219 } else { 2130 2220 if (hw->fw_state == CSIO_DEV_STATE_INIT) {
+1 -39
drivers/scsi/csiostor/csio_hw.h
··· 48 48 #include <scsi/scsi_device.h> 49 49 #include <scsi/scsi_transport_fc.h> 50 50 51 + #include "t4_hw.h" 51 52 #include "csio_hw_chip.h" 52 53 #include "csio_wr.h" 53 54 #include "csio_mb.h" ··· 175 174 }; 176 175 177 176 enum { 178 - EEPROMVSIZE = 32768, /* Serial EEPROM virtual address space size */ 179 177 SERNUM_LEN = 16, /* Serial # length */ 180 178 EC_LEN = 16, /* E/C length */ 181 179 ID_LEN = 16, /* ID length */ 182 - TRACE_LEN = 112, /* length of trace data and mask */ 183 180 }; 184 181 185 182 enum { 186 - SF_PAGE_SIZE = 256, /* serial flash page size */ 187 - SF_SEC_SIZE = 64 * 1024, /* serial flash sector size */ 188 183 SF_SIZE = SF_SEC_SIZE * 16, /* serial flash size */ 189 184 }; 190 185 ··· 196 199 SF_RD_DATA_FAST = 0xb, /* read flash */ 197 200 SF_RD_ID = 0x9f, /* read ID */ 198 201 SF_ERASE_SECTOR = 0xd8, /* erase sector */ 199 - 200 - FW_START_SEC = 8, /* first flash sector for FW */ 201 - FW_IMG_START = FW_START_SEC * SF_SEC_SIZE, 202 - FW_MAX_SIZE = 16 * SF_SEC_SIZE, 203 - 204 - FLASH_CFG_MAX_SIZE = 0x10000 , /* max size of the flash config file*/ 205 - FLASH_CFG_OFFSET = 0x1f0000, 206 - FLASH_CFG_START_SEC = FLASH_CFG_OFFSET / SF_SEC_SIZE, 207 202 }; 208 - 209 - /* 210 - * Flash layout. 211 - */ 212 - #define FLASH_START(start) ((start) * SF_SEC_SIZE) 213 - #define FLASH_MAX_SIZE(nsecs) ((nsecs) * SF_SEC_SIZE) 214 - 215 - enum { 216 - /* 217 - * Location of firmware image in FLASH. 218 - */ 219 - FLASH_FW_START_SEC = 8, 220 - FLASH_FW_NSECS = 16, 221 - FLASH_FW_START = FLASH_START(FLASH_FW_START_SEC), 222 - FLASH_FW_MAX_SIZE = FLASH_MAX_SIZE(FLASH_FW_NSECS), 223 - 224 - /* Location of Firmware Configuration File in FLASH. */ 225 - FLASH_CFG_START = FLASH_START(FLASH_CFG_START_SEC), 226 - }; 227 - 228 - #undef FLASH_START 229 - #undef FLASH_MAX_SIZE 230 203 231 204 /* Management module */ 232 205 enum { ··· 448 481 uint32_t tp_vers; 449 482 char chip_ver; 450 483 uint16_t chip_id; /* Tells T4/T5 chip */ 451 - uint32_t cfg_finiver; 452 - uint32_t cfg_finicsum; 453 - uint32_t cfg_cfcsum; 454 - uint8_t cfg_csum_status; 455 - uint8_t cfg_store; 456 484 enum csio_dev_state fw_state; 457 485 struct csio_vpd vpd; 458 486
-1
drivers/scsi/csiostor/csio_hw_chip.h
··· 95 95 enum { 96 96 MEMWIN_APERTURE = 2048, 97 97 MEMWIN_BASE = 0x1b800, 98 - MEMWIN_CSIOSTOR = 6, /* PCI-e Memory Window access */ 99 98 }; 100 99 101 100 /* Slow path handlers */