1f31e4b6fSAnirudh Venkataramanan // SPDX-License-Identifier: GPL-2.0 2f31e4b6fSAnirudh Venkataramanan /* Copyright (c) 2018, Intel Corporation. */ 3f31e4b6fSAnirudh Venkataramanan 4f31e4b6fSAnirudh Venkataramanan #include "ice_common.h" 5f31e4b6fSAnirudh Venkataramanan 6f31e4b6fSAnirudh Venkataramanan /** 7f31e4b6fSAnirudh Venkataramanan * ice_aq_read_nvm 8f9867df6SAnirudh Venkataramanan * @hw: pointer to the HW struct 9f31e4b6fSAnirudh Venkataramanan * @module_typeid: module pointer location in words from the NVM beginning 10f31e4b6fSAnirudh Venkataramanan * @offset: byte offset from the module beginning 11f31e4b6fSAnirudh Venkataramanan * @length: length of the section to be read (in bytes from the offset) 12f31e4b6fSAnirudh Venkataramanan * @data: command buffer (size [bytes] = length) 13f31e4b6fSAnirudh Venkataramanan * @last_command: tells if this is the last command in a series 14e9450990SJacob Keller * @read_shadow_ram: tell if this is a shadow RAM read 15f31e4b6fSAnirudh Venkataramanan * @cd: pointer to command details structure or NULL 16f31e4b6fSAnirudh Venkataramanan * 17f31e4b6fSAnirudh Venkataramanan * Read the NVM using the admin queue commands (0x0701) 18f31e4b6fSAnirudh Venkataramanan */ 19f31e4b6fSAnirudh Venkataramanan static enum ice_status 2043c89b16SAnirudh Venkataramanan ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, u16 length, 21e9450990SJacob Keller void *data, bool last_command, bool read_shadow_ram, 22e9450990SJacob Keller struct ice_sq_cd *cd) 23f31e4b6fSAnirudh Venkataramanan { 24f31e4b6fSAnirudh Venkataramanan struct ice_aq_desc desc; 25f31e4b6fSAnirudh Venkataramanan struct ice_aqc_nvm *cmd; 26f31e4b6fSAnirudh Venkataramanan 27f31e4b6fSAnirudh Venkataramanan cmd = &desc.params.nvm; 28f31e4b6fSAnirudh Venkataramanan 2981f07491SJacob Keller if (offset > ICE_AQC_NVM_MAX_OFFSET) 30f31e4b6fSAnirudh Venkataramanan return ICE_ERR_PARAM; 31f31e4b6fSAnirudh Venkataramanan 32f31e4b6fSAnirudh Venkataramanan ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_read); 33f31e4b6fSAnirudh Venkataramanan 34e9450990SJacob Keller if (!read_shadow_ram && module_typeid == ICE_AQC_NVM_START_POINT) 35e9450990SJacob Keller cmd->cmd_flags |= ICE_AQC_NVM_FLASH_ONLY; 36e9450990SJacob Keller 37f31e4b6fSAnirudh Venkataramanan /* If this is the last command in a series, set the proper flag. */ 38f31e4b6fSAnirudh Venkataramanan if (last_command) 39f31e4b6fSAnirudh Venkataramanan cmd->cmd_flags |= ICE_AQC_NVM_LAST_CMD; 4043c89b16SAnirudh Venkataramanan cmd->module_typeid = cpu_to_le16(module_typeid); 4143c89b16SAnirudh Venkataramanan cmd->offset_low = cpu_to_le16(offset & 0xFFFF); 4243c89b16SAnirudh Venkataramanan cmd->offset_high = (offset >> 16) & 0xFF; 43f31e4b6fSAnirudh Venkataramanan cmd->length = cpu_to_le16(length); 44f31e4b6fSAnirudh Venkataramanan 45f31e4b6fSAnirudh Venkataramanan return ice_aq_send_cmd(hw, &desc, data, length, cd); 46f31e4b6fSAnirudh Venkataramanan } 47f31e4b6fSAnirudh Venkataramanan 48f31e4b6fSAnirudh Venkataramanan /** 49e9450990SJacob Keller * ice_read_flat_nvm - Read portion of NVM by flat offset 50e9450990SJacob Keller * @hw: pointer to the HW struct 51e9450990SJacob Keller * @offset: offset from beginning of NVM 52e9450990SJacob Keller * @length: (in) number of bytes to read; (out) number of bytes actually read 53e9450990SJacob Keller * @data: buffer to return data in (sized to fit the specified length) 54e9450990SJacob Keller * @read_shadow_ram: if true, read from shadow RAM instead of NVM 55e9450990SJacob Keller * 56e9450990SJacob Keller * Reads a portion of the NVM, as a flat memory space. This function correctly 57e9450990SJacob Keller * breaks read requests across Shadow RAM sectors and ensures that no single 5832e6deb2SBruce Allan * read request exceeds the maximum 4KB read for a single AdminQ command. 59e9450990SJacob Keller * 60e9450990SJacob Keller * Returns a status code on failure. Note that the data pointer may be 61e9450990SJacob Keller * partially updated if some reads succeed before a failure. 62e9450990SJacob Keller */ 63e9450990SJacob Keller enum ice_status 64e9450990SJacob Keller ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data, 65e9450990SJacob Keller bool read_shadow_ram) 66e9450990SJacob Keller { 67e9450990SJacob Keller enum ice_status status; 68e9450990SJacob Keller u32 inlen = *length; 69e9450990SJacob Keller u32 bytes_read = 0; 70e9450990SJacob Keller bool last_cmd; 71e9450990SJacob Keller 72e9450990SJacob Keller *length = 0; 73e9450990SJacob Keller 74e9450990SJacob Keller /* Verify the length of the read if this is for the Shadow RAM */ 759af368faSJacob Keller if (read_shadow_ram && ((offset + inlen) > (hw->flash.sr_words * 2u))) { 769228d8b2SJacob Keller ice_debug(hw, ICE_DBG_NVM, "NVM error: requested offset is beyond Shadow RAM limit\n"); 77e9450990SJacob Keller return ICE_ERR_PARAM; 78e9450990SJacob Keller } 79e9450990SJacob Keller 80e9450990SJacob Keller do { 81e9450990SJacob Keller u32 read_size, sector_offset; 82e9450990SJacob Keller 8332e6deb2SBruce Allan /* ice_aq_read_nvm cannot read more than 4KB at a time. 84e9450990SJacob Keller * Additionally, a read from the Shadow RAM may not cross over 85e9450990SJacob Keller * a sector boundary. Conveniently, the sector size is also 8632e6deb2SBruce Allan * 4KB. 87e9450990SJacob Keller */ 88e9450990SJacob Keller sector_offset = offset % ICE_AQ_MAX_BUF_LEN; 89e9450990SJacob Keller read_size = min_t(u32, ICE_AQ_MAX_BUF_LEN - sector_offset, 90e9450990SJacob Keller inlen - bytes_read); 91e9450990SJacob Keller 92e9450990SJacob Keller last_cmd = !(bytes_read + read_size < inlen); 93e9450990SJacob Keller 94e9450990SJacob Keller status = ice_aq_read_nvm(hw, ICE_AQC_NVM_START_POINT, 95e9450990SJacob Keller offset, read_size, 96e9450990SJacob Keller data + bytes_read, last_cmd, 97e9450990SJacob Keller read_shadow_ram, NULL); 98e9450990SJacob Keller if (status) 99e9450990SJacob Keller break; 100e9450990SJacob Keller 101e9450990SJacob Keller bytes_read += read_size; 102e9450990SJacob Keller offset += read_size; 103e9450990SJacob Keller } while (!last_cmd); 104e9450990SJacob Keller 105e9450990SJacob Keller *length = bytes_read; 106e9450990SJacob Keller return status; 107e9450990SJacob Keller } 108e9450990SJacob Keller 109e9450990SJacob Keller /** 110544cd2acSCudzilo, Szymon T * ice_aq_update_nvm 111544cd2acSCudzilo, Szymon T * @hw: pointer to the HW struct 112544cd2acSCudzilo, Szymon T * @module_typeid: module pointer location in words from the NVM beginning 113544cd2acSCudzilo, Szymon T * @offset: byte offset from the module beginning 114544cd2acSCudzilo, Szymon T * @length: length of the section to be written (in bytes from the offset) 115544cd2acSCudzilo, Szymon T * @data: command buffer (size [bytes] = length) 116544cd2acSCudzilo, Szymon T * @last_command: tells if this is the last command in a series 117544cd2acSCudzilo, Szymon T * @command_flags: command parameters 118544cd2acSCudzilo, Szymon T * @cd: pointer to command details structure or NULL 119544cd2acSCudzilo, Szymon T * 120544cd2acSCudzilo, Szymon T * Update the NVM using the admin queue commands (0x0703) 121544cd2acSCudzilo, Szymon T */ 122544cd2acSCudzilo, Szymon T enum ice_status 123544cd2acSCudzilo, Szymon T ice_aq_update_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, 124544cd2acSCudzilo, Szymon T u16 length, void *data, bool last_command, u8 command_flags, 125544cd2acSCudzilo, Szymon T struct ice_sq_cd *cd) 126544cd2acSCudzilo, Szymon T { 127544cd2acSCudzilo, Szymon T struct ice_aq_desc desc; 128544cd2acSCudzilo, Szymon T struct ice_aqc_nvm *cmd; 129544cd2acSCudzilo, Szymon T 130544cd2acSCudzilo, Szymon T cmd = &desc.params.nvm; 131544cd2acSCudzilo, Szymon T 132544cd2acSCudzilo, Szymon T /* In offset the highest byte must be zeroed. */ 133544cd2acSCudzilo, Szymon T if (offset & 0xFF000000) 134544cd2acSCudzilo, Szymon T return ICE_ERR_PARAM; 135544cd2acSCudzilo, Szymon T 136544cd2acSCudzilo, Szymon T ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_write); 137544cd2acSCudzilo, Szymon T 138544cd2acSCudzilo, Szymon T cmd->cmd_flags |= command_flags; 139544cd2acSCudzilo, Szymon T 140544cd2acSCudzilo, Szymon T /* If this is the last command in a series, set the proper flag. */ 141544cd2acSCudzilo, Szymon T if (last_command) 142544cd2acSCudzilo, Szymon T cmd->cmd_flags |= ICE_AQC_NVM_LAST_CMD; 143544cd2acSCudzilo, Szymon T cmd->module_typeid = cpu_to_le16(module_typeid); 144544cd2acSCudzilo, Szymon T cmd->offset_low = cpu_to_le16(offset & 0xFFFF); 145544cd2acSCudzilo, Szymon T cmd->offset_high = (offset >> 16) & 0xFF; 146544cd2acSCudzilo, Szymon T cmd->length = cpu_to_le16(length); 147544cd2acSCudzilo, Szymon T 148544cd2acSCudzilo, Szymon T desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); 149544cd2acSCudzilo, Szymon T 150544cd2acSCudzilo, Szymon T return ice_aq_send_cmd(hw, &desc, data, length, cd); 151544cd2acSCudzilo, Szymon T } 152544cd2acSCudzilo, Szymon T 153544cd2acSCudzilo, Szymon T /** 154544cd2acSCudzilo, Szymon T * ice_aq_erase_nvm 155544cd2acSCudzilo, Szymon T * @hw: pointer to the HW struct 156544cd2acSCudzilo, Szymon T * @module_typeid: module pointer location in words from the NVM beginning 157544cd2acSCudzilo, Szymon T * @cd: pointer to command details structure or NULL 158544cd2acSCudzilo, Szymon T * 159544cd2acSCudzilo, Szymon T * Erase the NVM sector using the admin queue commands (0x0702) 160544cd2acSCudzilo, Szymon T */ 161544cd2acSCudzilo, Szymon T enum ice_status 162544cd2acSCudzilo, Szymon T ice_aq_erase_nvm(struct ice_hw *hw, u16 module_typeid, struct ice_sq_cd *cd) 163544cd2acSCudzilo, Szymon T { 164544cd2acSCudzilo, Szymon T struct ice_aq_desc desc; 165544cd2acSCudzilo, Szymon T struct ice_aqc_nvm *cmd; 166544cd2acSCudzilo, Szymon T 167544cd2acSCudzilo, Szymon T cmd = &desc.params.nvm; 168544cd2acSCudzilo, Szymon T 169544cd2acSCudzilo, Szymon T ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_erase); 170544cd2acSCudzilo, Szymon T 171544cd2acSCudzilo, Szymon T cmd->module_typeid = cpu_to_le16(module_typeid); 172544cd2acSCudzilo, Szymon T cmd->length = cpu_to_le16(ICE_AQC_NVM_ERASE_LEN); 173544cd2acSCudzilo, Szymon T cmd->offset_low = 0; 174544cd2acSCudzilo, Szymon T cmd->offset_high = 0; 175544cd2acSCudzilo, Szymon T 176544cd2acSCudzilo, Szymon T return ice_aq_send_cmd(hw, &desc, NULL, 0, cd); 177544cd2acSCudzilo, Szymon T } 178544cd2acSCudzilo, Szymon T 179544cd2acSCudzilo, Szymon T /** 180f31e4b6fSAnirudh Venkataramanan * ice_read_sr_word_aq - Reads Shadow RAM via AQ 181f31e4b6fSAnirudh Venkataramanan * @hw: pointer to the HW structure 182f31e4b6fSAnirudh Venkataramanan * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF) 183f31e4b6fSAnirudh Venkataramanan * @data: word read from the Shadow RAM 184f31e4b6fSAnirudh Venkataramanan * 185e9450990SJacob Keller * Reads one 16 bit word from the Shadow RAM using ice_read_flat_nvm. 186f31e4b6fSAnirudh Venkataramanan */ 187f31e4b6fSAnirudh Venkataramanan static enum ice_status 188f31e4b6fSAnirudh Venkataramanan ice_read_sr_word_aq(struct ice_hw *hw, u16 offset, u16 *data) 189f31e4b6fSAnirudh Venkataramanan { 190e9450990SJacob Keller u32 bytes = sizeof(u16); 191f31e4b6fSAnirudh Venkataramanan enum ice_status status; 1922efefb56SJacob Keller __le16 data_local; 193f31e4b6fSAnirudh Venkataramanan 194e9450990SJacob Keller /* Note that ice_read_flat_nvm takes into account the 4Kb AdminQ and 195e9450990SJacob Keller * Shadow RAM sector restrictions necessary when reading from the NVM. 196e9450990SJacob Keller */ 197e9450990SJacob Keller status = ice_read_flat_nvm(hw, offset * sizeof(u16), &bytes, 19834d8461aSBruce Allan (__force u8 *)&data_local, true); 199e9450990SJacob Keller if (status) 200f31e4b6fSAnirudh Venkataramanan return status; 201e9450990SJacob Keller 202e9450990SJacob Keller *data = le16_to_cpu(data_local); 203e9450990SJacob Keller return 0; 204f31e4b6fSAnirudh Venkataramanan } 205f31e4b6fSAnirudh Venkataramanan 206f31e4b6fSAnirudh Venkataramanan /** 207f31e4b6fSAnirudh Venkataramanan * ice_acquire_nvm - Generic request for acquiring the NVM ownership 208f31e4b6fSAnirudh Venkataramanan * @hw: pointer to the HW structure 209f31e4b6fSAnirudh Venkataramanan * @access: NVM access type (read or write) 210f31e4b6fSAnirudh Venkataramanan * 211f31e4b6fSAnirudh Venkataramanan * This function will request NVM ownership. 212f31e4b6fSAnirudh Venkataramanan */ 21384a24798SJesse Brandeburg enum ice_status 2143968540bSAnirudh Venkataramanan ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access) 215f31e4b6fSAnirudh Venkataramanan { 2169af368faSJacob Keller if (hw->flash.blank_nvm_mode) 217f31e4b6fSAnirudh Venkataramanan return 0; 218f31e4b6fSAnirudh Venkataramanan 219ff2b1321SDan Nowlin return ice_acquire_res(hw, ICE_NVM_RES_ID, access, ICE_NVM_TIMEOUT); 220f31e4b6fSAnirudh Venkataramanan } 221f31e4b6fSAnirudh Venkataramanan 222f31e4b6fSAnirudh Venkataramanan /** 223f31e4b6fSAnirudh Venkataramanan * ice_release_nvm - Generic request for releasing the NVM ownership 224f31e4b6fSAnirudh Venkataramanan * @hw: pointer to the HW structure 225f31e4b6fSAnirudh Venkataramanan * 226f31e4b6fSAnirudh Venkataramanan * This function will release NVM ownership. 227f31e4b6fSAnirudh Venkataramanan */ 22884a24798SJesse Brandeburg void ice_release_nvm(struct ice_hw *hw) 229f31e4b6fSAnirudh Venkataramanan { 2309af368faSJacob Keller if (hw->flash.blank_nvm_mode) 231f31e4b6fSAnirudh Venkataramanan return; 232f31e4b6fSAnirudh Venkataramanan 233f31e4b6fSAnirudh Venkataramanan ice_release_res(hw, ICE_NVM_RES_ID); 234f31e4b6fSAnirudh Venkataramanan } 235f31e4b6fSAnirudh Venkataramanan 236f31e4b6fSAnirudh Venkataramanan /** 2370ce50c70SJacob Keller * ice_get_flash_bank_offset - Get offset into requested flash bank 2380ce50c70SJacob Keller * @hw: pointer to the HW structure 2390ce50c70SJacob Keller * @bank: whether to read from the active or inactive flash bank 2400ce50c70SJacob Keller * @module: the module to read from 2410ce50c70SJacob Keller * 2420ce50c70SJacob Keller * Based on the module, lookup the module offset from the beginning of the 2430ce50c70SJacob Keller * flash. 2440ce50c70SJacob Keller * 2450ce50c70SJacob Keller * Returns the flash offset. Note that a value of zero is invalid and must be 2460ce50c70SJacob Keller * treated as an error. 2470ce50c70SJacob Keller */ 2480ce50c70SJacob Keller static u32 ice_get_flash_bank_offset(struct ice_hw *hw, enum ice_bank_select bank, u16 module) 2490ce50c70SJacob Keller { 2500ce50c70SJacob Keller struct ice_bank_info *banks = &hw->flash.banks; 2510ce50c70SJacob Keller enum ice_flash_bank active_bank; 2520ce50c70SJacob Keller bool second_bank_active; 2530ce50c70SJacob Keller u32 offset, size; 2540ce50c70SJacob Keller 2550ce50c70SJacob Keller switch (module) { 2560ce50c70SJacob Keller case ICE_SR_1ST_NVM_BANK_PTR: 2570ce50c70SJacob Keller offset = banks->nvm_ptr; 2580ce50c70SJacob Keller size = banks->nvm_size; 2590ce50c70SJacob Keller active_bank = banks->nvm_bank; 2600ce50c70SJacob Keller break; 2610ce50c70SJacob Keller case ICE_SR_1ST_OROM_BANK_PTR: 2620ce50c70SJacob Keller offset = banks->orom_ptr; 2630ce50c70SJacob Keller size = banks->orom_size; 2640ce50c70SJacob Keller active_bank = banks->orom_bank; 2650ce50c70SJacob Keller break; 2660ce50c70SJacob Keller case ICE_SR_NETLIST_BANK_PTR: 2670ce50c70SJacob Keller offset = banks->netlist_ptr; 2680ce50c70SJacob Keller size = banks->netlist_size; 2690ce50c70SJacob Keller active_bank = banks->netlist_bank; 2700ce50c70SJacob Keller break; 2710ce50c70SJacob Keller default: 2720ce50c70SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Unexpected value for flash module: 0x%04x\n", module); 2730ce50c70SJacob Keller return 0; 2740ce50c70SJacob Keller } 2750ce50c70SJacob Keller 2760ce50c70SJacob Keller switch (active_bank) { 2770ce50c70SJacob Keller case ICE_1ST_FLASH_BANK: 2780ce50c70SJacob Keller second_bank_active = false; 2790ce50c70SJacob Keller break; 2800ce50c70SJacob Keller case ICE_2ND_FLASH_BANK: 2810ce50c70SJacob Keller second_bank_active = true; 2820ce50c70SJacob Keller break; 2830ce50c70SJacob Keller default: 2840ce50c70SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Unexpected value for active flash bank: %u\n", 2850ce50c70SJacob Keller active_bank); 2860ce50c70SJacob Keller return 0; 2870ce50c70SJacob Keller } 2880ce50c70SJacob Keller 2890ce50c70SJacob Keller /* The second flash bank is stored immediately following the first 2900ce50c70SJacob Keller * bank. Based on whether the 1st or 2nd bank is active, and whether 2910ce50c70SJacob Keller * we want the active or inactive bank, calculate the desired offset. 2920ce50c70SJacob Keller */ 2930ce50c70SJacob Keller switch (bank) { 2940ce50c70SJacob Keller case ICE_ACTIVE_FLASH_BANK: 2950ce50c70SJacob Keller return offset + (second_bank_active ? size : 0); 2960ce50c70SJacob Keller case ICE_INACTIVE_FLASH_BANK: 2970ce50c70SJacob Keller return offset + (second_bank_active ? 0 : size); 2980ce50c70SJacob Keller } 2990ce50c70SJacob Keller 3000ce50c70SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Unexpected value for flash bank selection: %u\n", bank); 3010ce50c70SJacob Keller return 0; 3020ce50c70SJacob Keller } 3030ce50c70SJacob Keller 3040ce50c70SJacob Keller /** 3050ce50c70SJacob Keller * ice_read_flash_module - Read a word from one of the main NVM modules 3060ce50c70SJacob Keller * @hw: pointer to the HW structure 3070ce50c70SJacob Keller * @bank: which bank of the module to read 3080ce50c70SJacob Keller * @module: the module to read 3090ce50c70SJacob Keller * @offset: the offset into the module in bytes 3100ce50c70SJacob Keller * @data: storage for the word read from the flash 3110ce50c70SJacob Keller * @length: bytes of data to read 3120ce50c70SJacob Keller * 3130ce50c70SJacob Keller * Read data from the specified flash module. The bank parameter indicates 3140ce50c70SJacob Keller * whether or not to read from the active bank or the inactive bank of that 3150ce50c70SJacob Keller * module. 3160ce50c70SJacob Keller * 3170ce50c70SJacob Keller * The word will be read using flat NVM access, and relies on the 3180ce50c70SJacob Keller * hw->flash.banks data being setup by ice_determine_active_flash_banks() 3190ce50c70SJacob Keller * during initialization. 3200ce50c70SJacob Keller */ 3210ce50c70SJacob Keller static enum ice_status 3220ce50c70SJacob Keller ice_read_flash_module(struct ice_hw *hw, enum ice_bank_select bank, u16 module, 3230ce50c70SJacob Keller u32 offset, u8 *data, u32 length) 3240ce50c70SJacob Keller { 3250ce50c70SJacob Keller enum ice_status status; 3260ce50c70SJacob Keller u32 start; 3270ce50c70SJacob Keller 3280ce50c70SJacob Keller start = ice_get_flash_bank_offset(hw, bank, module); 3290ce50c70SJacob Keller if (!start) { 3300ce50c70SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Unable to calculate flash bank offset for module 0x%04x\n", 3310ce50c70SJacob Keller module); 3320ce50c70SJacob Keller return ICE_ERR_PARAM; 3330ce50c70SJacob Keller } 3340ce50c70SJacob Keller 3350ce50c70SJacob Keller status = ice_acquire_nvm(hw, ICE_RES_READ); 3360ce50c70SJacob Keller if (status) 3370ce50c70SJacob Keller return status; 3380ce50c70SJacob Keller 3390ce50c70SJacob Keller status = ice_read_flat_nvm(hw, start + offset, &length, data, false); 3400ce50c70SJacob Keller 3410ce50c70SJacob Keller ice_release_nvm(hw); 3420ce50c70SJacob Keller 3430ce50c70SJacob Keller return status; 3440ce50c70SJacob Keller } 3450ce50c70SJacob Keller 3460ce50c70SJacob Keller /** 3470ce50c70SJacob Keller * ice_read_nvm_module - Read from the active main NVM module 3480ce50c70SJacob Keller * @hw: pointer to the HW structure 3490ce50c70SJacob Keller * @bank: whether to read from active or inactive NVM module 3500ce50c70SJacob Keller * @offset: offset into the NVM module to read, in words 3510ce50c70SJacob Keller * @data: storage for returned word value 3520ce50c70SJacob Keller * 3530ce50c70SJacob Keller * Read the specified word from the active NVM module. This includes the CSS 3540ce50c70SJacob Keller * header at the start of the NVM module. 3550ce50c70SJacob Keller */ 3560ce50c70SJacob Keller static enum ice_status 3570ce50c70SJacob Keller ice_read_nvm_module(struct ice_hw *hw, enum ice_bank_select bank, u32 offset, u16 *data) 3580ce50c70SJacob Keller { 3590ce50c70SJacob Keller enum ice_status status; 3600ce50c70SJacob Keller __le16 data_local; 3610ce50c70SJacob Keller 3620ce50c70SJacob Keller status = ice_read_flash_module(hw, bank, ICE_SR_1ST_NVM_BANK_PTR, offset * sizeof(u16), 3630ce50c70SJacob Keller (__force u8 *)&data_local, sizeof(u16)); 3640ce50c70SJacob Keller if (!status) 3650ce50c70SJacob Keller *data = le16_to_cpu(data_local); 3660ce50c70SJacob Keller 3670ce50c70SJacob Keller return status; 3680ce50c70SJacob Keller } 3690ce50c70SJacob Keller 3700ce50c70SJacob Keller /** 3710ce50c70SJacob Keller * ice_read_nvm_sr_copy - Read a word from the Shadow RAM copy in the NVM bank 3720ce50c70SJacob Keller * @hw: pointer to the HW structure 3730ce50c70SJacob Keller * @bank: whether to read from the active or inactive NVM module 3740ce50c70SJacob Keller * @offset: offset into the Shadow RAM copy to read, in words 3750ce50c70SJacob Keller * @data: storage for returned word value 3760ce50c70SJacob Keller * 3770ce50c70SJacob Keller * Read the specified word from the copy of the Shadow RAM found in the 3780ce50c70SJacob Keller * specified NVM module. 3790ce50c70SJacob Keller */ 3800ce50c70SJacob Keller static enum ice_status 3810ce50c70SJacob Keller ice_read_nvm_sr_copy(struct ice_hw *hw, enum ice_bank_select bank, u32 offset, u16 *data) 3820ce50c70SJacob Keller { 3830ce50c70SJacob Keller return ice_read_nvm_module(hw, bank, ICE_NVM_SR_COPY_WORD_OFFSET + offset, data); 3840ce50c70SJacob Keller } 3850ce50c70SJacob Keller 3860ce50c70SJacob Keller /** 387e120a9abSJacob Keller * ice_read_netlist_module - Read data from the netlist module area 388e120a9abSJacob Keller * @hw: pointer to the HW structure 389e120a9abSJacob Keller * @bank: whether to read from the active or inactive module 390e120a9abSJacob Keller * @offset: offset into the netlist to read from 391e120a9abSJacob Keller * @data: storage for returned word value 392e120a9abSJacob Keller * 393e120a9abSJacob Keller * Read a word from the specified netlist bank. 394e120a9abSJacob Keller */ 395e120a9abSJacob Keller static enum ice_status 396e120a9abSJacob Keller ice_read_netlist_module(struct ice_hw *hw, enum ice_bank_select bank, u32 offset, u16 *data) 397e120a9abSJacob Keller { 398e120a9abSJacob Keller enum ice_status status; 399e120a9abSJacob Keller __le16 data_local; 400e120a9abSJacob Keller 401e120a9abSJacob Keller status = ice_read_flash_module(hw, bank, ICE_SR_NETLIST_BANK_PTR, offset * sizeof(u16), 402e120a9abSJacob Keller (__force u8 *)&data_local, sizeof(u16)); 403e120a9abSJacob Keller if (!status) 404e120a9abSJacob Keller *data = le16_to_cpu(data_local); 405e120a9abSJacob Keller 406e120a9abSJacob Keller return status; 407e120a9abSJacob Keller } 408e120a9abSJacob Keller 409e120a9abSJacob Keller /** 410f31e4b6fSAnirudh Venkataramanan * ice_read_sr_word - Reads Shadow RAM word and acquire NVM if necessary 411f31e4b6fSAnirudh Venkataramanan * @hw: pointer to the HW structure 412f31e4b6fSAnirudh Venkataramanan * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF) 413f31e4b6fSAnirudh Venkataramanan * @data: word read from the Shadow RAM 414f31e4b6fSAnirudh Venkataramanan * 415f31e4b6fSAnirudh Venkataramanan * Reads one 16 bit word from the Shadow RAM using the ice_read_sr_word_aq. 416f31e4b6fSAnirudh Venkataramanan */ 417769c500dSAkeem G Abodunrin enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data) 418f31e4b6fSAnirudh Venkataramanan { 419f31e4b6fSAnirudh Venkataramanan enum ice_status status; 420f31e4b6fSAnirudh Venkataramanan 421f31e4b6fSAnirudh Venkataramanan status = ice_acquire_nvm(hw, ICE_RES_READ); 422f31e4b6fSAnirudh Venkataramanan if (!status) { 423f31e4b6fSAnirudh Venkataramanan status = ice_read_sr_word_aq(hw, offset, data); 424f31e4b6fSAnirudh Venkataramanan ice_release_nvm(hw); 425f31e4b6fSAnirudh Venkataramanan } 426f31e4b6fSAnirudh Venkataramanan 427f31e4b6fSAnirudh Venkataramanan return status; 428f31e4b6fSAnirudh Venkataramanan } 429f31e4b6fSAnirudh Venkataramanan 430f31e4b6fSAnirudh Venkataramanan /** 431e961b679SJacob Keller * ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA 432e961b679SJacob Keller * @hw: pointer to hardware structure 433e961b679SJacob Keller * @module_tlv: pointer to module TLV to return 434e961b679SJacob Keller * @module_tlv_len: pointer to module TLV length to return 435e961b679SJacob Keller * @module_type: module type requested 436e961b679SJacob Keller * 437e961b679SJacob Keller * Finds the requested sub module TLV type from the Preserved Field 438e961b679SJacob Keller * Area (PFA) and returns the TLV pointer and length. The caller can 439e961b679SJacob Keller * use these to read the variable length TLV value. 440e961b679SJacob Keller */ 441ea78ce4dSPaul Greenwalt enum ice_status 442e961b679SJacob Keller ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len, 443e961b679SJacob Keller u16 module_type) 444e961b679SJacob Keller { 445e961b679SJacob Keller enum ice_status status; 446e961b679SJacob Keller u16 pfa_len, pfa_ptr; 447e961b679SJacob Keller u16 next_tlv; 448e961b679SJacob Keller 449e961b679SJacob Keller status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr); 450e961b679SJacob Keller if (status) { 451e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Preserved Field Array pointer.\n"); 452e961b679SJacob Keller return status; 453e961b679SJacob Keller } 454e961b679SJacob Keller status = ice_read_sr_word(hw, pfa_ptr, &pfa_len); 455e961b679SJacob Keller if (status) { 456e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read PFA length.\n"); 457e961b679SJacob Keller return status; 458e961b679SJacob Keller } 459e961b679SJacob Keller /* Starting with first TLV after PFA length, iterate through the list 460e961b679SJacob Keller * of TLVs to find the requested one. 461e961b679SJacob Keller */ 462e961b679SJacob Keller next_tlv = pfa_ptr + 1; 463e961b679SJacob Keller while (next_tlv < pfa_ptr + pfa_len) { 464e961b679SJacob Keller u16 tlv_sub_module_type; 465e961b679SJacob Keller u16 tlv_len; 466e961b679SJacob Keller 467e961b679SJacob Keller /* Read TLV type */ 468e961b679SJacob Keller status = ice_read_sr_word(hw, next_tlv, &tlv_sub_module_type); 469e961b679SJacob Keller if (status) { 470e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV type.\n"); 471e961b679SJacob Keller break; 472e961b679SJacob Keller } 473e961b679SJacob Keller /* Read TLV length */ 474e961b679SJacob Keller status = ice_read_sr_word(hw, next_tlv + 1, &tlv_len); 475e961b679SJacob Keller if (status) { 476e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV length.\n"); 477e961b679SJacob Keller break; 478e961b679SJacob Keller } 479e961b679SJacob Keller if (tlv_sub_module_type == module_type) { 480e961b679SJacob Keller if (tlv_len) { 481e961b679SJacob Keller *module_tlv = next_tlv; 482e961b679SJacob Keller *module_tlv_len = tlv_len; 483e961b679SJacob Keller return 0; 484e961b679SJacob Keller } 485e961b679SJacob Keller return ICE_ERR_INVAL_SIZE; 486e961b679SJacob Keller } 487e961b679SJacob Keller /* Check next TLV, i.e. current TLV pointer + length + 2 words 488e961b679SJacob Keller * (for current TLV's type and length) 489e961b679SJacob Keller */ 490e961b679SJacob Keller next_tlv = next_tlv + tlv_len + 2; 491e961b679SJacob Keller } 492e961b679SJacob Keller /* Module does not exist */ 493e961b679SJacob Keller return ICE_ERR_DOES_NOT_EXIST; 494e961b679SJacob Keller } 495e961b679SJacob Keller 496e961b679SJacob Keller /** 497e961b679SJacob Keller * ice_read_pba_string - Reads part number string from NVM 498e961b679SJacob Keller * @hw: pointer to hardware structure 499e961b679SJacob Keller * @pba_num: stores the part number string from the NVM 500e961b679SJacob Keller * @pba_num_size: part number string buffer length 501e961b679SJacob Keller * 502e961b679SJacob Keller * Reads the part number string from the NVM. 503e961b679SJacob Keller */ 504e961b679SJacob Keller enum ice_status 505e961b679SJacob Keller ice_read_pba_string(struct ice_hw *hw, u8 *pba_num, u32 pba_num_size) 506e961b679SJacob Keller { 507e961b679SJacob Keller u16 pba_tlv, pba_tlv_len; 508e961b679SJacob Keller enum ice_status status; 509e961b679SJacob Keller u16 pba_word, pba_size; 510e961b679SJacob Keller u16 i; 511e961b679SJacob Keller 512e961b679SJacob Keller status = ice_get_pfa_module_tlv(hw, &pba_tlv, &pba_tlv_len, 513e961b679SJacob Keller ICE_SR_PBA_BLOCK_PTR); 514e961b679SJacob Keller if (status) { 515e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block TLV.\n"); 516e961b679SJacob Keller return status; 517e961b679SJacob Keller } 518e961b679SJacob Keller 519e961b679SJacob Keller /* pba_size is the next word */ 520e961b679SJacob Keller status = ice_read_sr_word(hw, (pba_tlv + 2), &pba_size); 521e961b679SJacob Keller if (status) { 522e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Section size.\n"); 523e961b679SJacob Keller return status; 524e961b679SJacob Keller } 525e961b679SJacob Keller 526e961b679SJacob Keller if (pba_tlv_len < pba_size) { 527e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Invalid PBA Block TLV size.\n"); 528e961b679SJacob Keller return ICE_ERR_INVAL_SIZE; 529e961b679SJacob Keller } 530e961b679SJacob Keller 531e961b679SJacob Keller /* Subtract one to get PBA word count (PBA Size word is included in 532e961b679SJacob Keller * total size) 533e961b679SJacob Keller */ 534e961b679SJacob Keller pba_size--; 535e961b679SJacob Keller if (pba_num_size < (((u32)pba_size * 2) + 1)) { 536e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Buffer too small for PBA data.\n"); 537e961b679SJacob Keller return ICE_ERR_PARAM; 538e961b679SJacob Keller } 539e961b679SJacob Keller 540e961b679SJacob Keller for (i = 0; i < pba_size; i++) { 541e961b679SJacob Keller status = ice_read_sr_word(hw, (pba_tlv + 2 + 1) + i, &pba_word); 542e961b679SJacob Keller if (status) { 543e961b679SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block word %d.\n", i); 544e961b679SJacob Keller return status; 545e961b679SJacob Keller } 546e961b679SJacob Keller 547e961b679SJacob Keller pba_num[(i * 2)] = (pba_word >> 8) & 0xFF; 548e961b679SJacob Keller pba_num[(i * 2) + 1] = pba_word & 0xFF; 549e961b679SJacob Keller } 550e961b679SJacob Keller pba_num[(pba_size * 2)] = '\0'; 551e961b679SJacob Keller 552e961b679SJacob Keller return status; 553e961b679SJacob Keller } 554e961b679SJacob Keller 555e961b679SJacob Keller /** 5569af368faSJacob Keller * ice_get_nvm_ver_info - Read NVM version information 5579af368faSJacob Keller * @hw: pointer to the HW struct 5580ce50c70SJacob Keller * @bank: whether to read from the active or inactive flash bank 5599af368faSJacob Keller * @nvm: pointer to NVM info structure 5609af368faSJacob Keller * 5619af368faSJacob Keller * Read the NVM EETRACK ID and map version of the main NVM image bank, filling 5629af368faSJacob Keller * in the NVM info structure. 5639af368faSJacob Keller */ 5649af368faSJacob Keller static enum ice_status 5650ce50c70SJacob Keller ice_get_nvm_ver_info(struct ice_hw *hw, enum ice_bank_select bank, struct ice_nvm_info *nvm) 5669af368faSJacob Keller { 5679af368faSJacob Keller u16 eetrack_lo, eetrack_hi, ver; 5689af368faSJacob Keller enum ice_status status; 5699af368faSJacob Keller 5700ce50c70SJacob Keller status = ice_read_nvm_sr_copy(hw, bank, ICE_SR_NVM_DEV_STARTER_VER, &ver); 5719af368faSJacob Keller if (status) { 5729af368faSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read DEV starter version.\n"); 5739af368faSJacob Keller return status; 5749af368faSJacob Keller } 5750ce50c70SJacob Keller 5769af368faSJacob Keller nvm->major = (ver & ICE_NVM_VER_HI_MASK) >> ICE_NVM_VER_HI_SHIFT; 5779af368faSJacob Keller nvm->minor = (ver & ICE_NVM_VER_LO_MASK) >> ICE_NVM_VER_LO_SHIFT; 5789af368faSJacob Keller 5790ce50c70SJacob Keller status = ice_read_nvm_sr_copy(hw, bank, ICE_SR_NVM_EETRACK_LO, &eetrack_lo); 5809af368faSJacob Keller if (status) { 5819af368faSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read EETRACK lo.\n"); 5829af368faSJacob Keller return status; 5839af368faSJacob Keller } 5840ce50c70SJacob Keller status = ice_read_nvm_sr_copy(hw, bank, ICE_SR_NVM_EETRACK_HI, &eetrack_hi); 5859af368faSJacob Keller if (status) { 5869af368faSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read EETRACK hi.\n"); 5879af368faSJacob Keller return status; 5889af368faSJacob Keller } 5899af368faSJacob Keller 5909af368faSJacob Keller nvm->eetrack = (eetrack_hi << 16) | eetrack_lo; 5919af368faSJacob Keller 5929af368faSJacob Keller return 0; 5939af368faSJacob Keller } 5949af368faSJacob Keller 5959af368faSJacob Keller /** 5962c4fe41dSJacob Keller * ice_get_inactive_nvm_ver - Read Option ROM version from the inactive bank 5972c4fe41dSJacob Keller * @hw: pointer to the HW structure 5982c4fe41dSJacob Keller * @nvm: storage for Option ROM version information 5992c4fe41dSJacob Keller * 6002c4fe41dSJacob Keller * Reads the NVM EETRACK ID, Map version, and security revision of the 6012c4fe41dSJacob Keller * inactive NVM bank. Used to access version data for a pending update that 6022c4fe41dSJacob Keller * has not yet been activated. 6032c4fe41dSJacob Keller */ 6042c4fe41dSJacob Keller enum ice_status ice_get_inactive_nvm_ver(struct ice_hw *hw, struct ice_nvm_info *nvm) 6052c4fe41dSJacob Keller { 6062c4fe41dSJacob Keller return ice_get_nvm_ver_info(hw, ICE_INACTIVE_FLASH_BANK, nvm); 6072c4fe41dSJacob Keller } 6082c4fe41dSJacob Keller 6092c4fe41dSJacob Keller /** 610*e67fbcfbSJacob Keller * ice_get_orom_civd_data - Get the combo version information from Option ROM 611d4e87444SJacob Keller * @hw: pointer to the HW struct 612*e67fbcfbSJacob Keller * @bank: whether to read from the active or inactive flash module 613*e67fbcfbSJacob Keller * @civd: storage for the Option ROM CIVD data. 614d4e87444SJacob Keller * 615*e67fbcfbSJacob Keller * Searches through the Option ROM flash contents to locate the CIVD data for 616*e67fbcfbSJacob Keller * the image. 617d4e87444SJacob Keller */ 6189af368faSJacob Keller static enum ice_status 619*e67fbcfbSJacob Keller ice_get_orom_civd_data(struct ice_hw *hw, enum ice_bank_select bank, 620*e67fbcfbSJacob Keller struct ice_orom_civd_info *civd) 621d4e87444SJacob Keller { 622*e67fbcfbSJacob Keller struct ice_orom_civd_info tmp; 623*e67fbcfbSJacob Keller enum ice_status status; 624*e67fbcfbSJacob Keller u32 offset; 625*e67fbcfbSJacob Keller 626*e67fbcfbSJacob Keller /* The CIVD section is located in the Option ROM aligned to 512 bytes. 627*e67fbcfbSJacob Keller * The first 4 bytes must contain the ASCII characters "$CIV". 628*e67fbcfbSJacob Keller * A simple modulo 256 sum of all of the bytes of the structure must 629*e67fbcfbSJacob Keller * equal 0. 630*e67fbcfbSJacob Keller */ 631*e67fbcfbSJacob Keller for (offset = 0; (offset + 512) <= hw->flash.banks.orom_size; offset += 512) { 632*e67fbcfbSJacob Keller u8 sum = 0, i; 633*e67fbcfbSJacob Keller 634*e67fbcfbSJacob Keller status = ice_read_flash_module(hw, bank, ICE_SR_1ST_OROM_BANK_PTR, 635*e67fbcfbSJacob Keller offset, (u8 *)&tmp, sizeof(tmp)); 636*e67fbcfbSJacob Keller if (status) { 637*e67fbcfbSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Unable to read Option ROM CIVD data\n"); 638*e67fbcfbSJacob Keller return status; 639*e67fbcfbSJacob Keller } 640*e67fbcfbSJacob Keller 641*e67fbcfbSJacob Keller /* Skip forward until we find a matching signature */ 642*e67fbcfbSJacob Keller if (memcmp("$CIV", tmp.signature, sizeof(tmp.signature)) != 0) 643*e67fbcfbSJacob Keller continue; 644*e67fbcfbSJacob Keller 645*e67fbcfbSJacob Keller /* Verify that the simple checksum is zero */ 646*e67fbcfbSJacob Keller for (i = 0; i < sizeof(tmp); i++) 647*e67fbcfbSJacob Keller sum += ((u8 *)&tmp)[i]; 648*e67fbcfbSJacob Keller 649*e67fbcfbSJacob Keller if (sum) { 650*e67fbcfbSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Found CIVD data with invalid checksum of %u\n", 651*e67fbcfbSJacob Keller sum); 652*e67fbcfbSJacob Keller return ICE_ERR_NVM; 653*e67fbcfbSJacob Keller } 654*e67fbcfbSJacob Keller 655*e67fbcfbSJacob Keller *civd = tmp; 656*e67fbcfbSJacob Keller return 0; 657*e67fbcfbSJacob Keller } 658*e67fbcfbSJacob Keller 659*e67fbcfbSJacob Keller return ICE_ERR_NVM; 660*e67fbcfbSJacob Keller } 661*e67fbcfbSJacob Keller 662*e67fbcfbSJacob Keller /** 663*e67fbcfbSJacob Keller * ice_get_orom_ver_info - Read Option ROM version information 664*e67fbcfbSJacob Keller * @hw: pointer to the HW struct 665*e67fbcfbSJacob Keller * @bank: whether to read from the active or inactive flash module 666*e67fbcfbSJacob Keller * @orom: pointer to Option ROM info structure 667*e67fbcfbSJacob Keller * 668*e67fbcfbSJacob Keller * Read Option ROM version and security revision from the Option ROM flash 669*e67fbcfbSJacob Keller * section. 670*e67fbcfbSJacob Keller */ 671*e67fbcfbSJacob Keller static enum ice_status 672*e67fbcfbSJacob Keller ice_get_orom_ver_info(struct ice_hw *hw, enum ice_bank_select bank, struct ice_orom_info *orom) 673*e67fbcfbSJacob Keller { 674*e67fbcfbSJacob Keller struct ice_orom_civd_info civd; 675d4e87444SJacob Keller enum ice_status status; 676d4e87444SJacob Keller u32 combo_ver; 677d4e87444SJacob Keller 678*e67fbcfbSJacob Keller status = ice_get_orom_civd_data(hw, bank, &civd); 679d4e87444SJacob Keller if (status) { 680*e67fbcfbSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to locate valid Option ROM CIVD data\n"); 681d4e87444SJacob Keller return status; 682d4e87444SJacob Keller } 683d4e87444SJacob Keller 684*e67fbcfbSJacob Keller combo_ver = le32_to_cpu(civd.combo_ver); 685d4e87444SJacob Keller 686*e67fbcfbSJacob Keller orom->major = (u8)((combo_ver & ICE_OROM_VER_MASK) >> ICE_OROM_VER_SHIFT); 687d4e87444SJacob Keller orom->patch = (u8)(combo_ver & ICE_OROM_VER_PATCH_MASK); 688*e67fbcfbSJacob Keller orom->build = (u16)((combo_ver & ICE_OROM_VER_BUILD_MASK) >> ICE_OROM_VER_BUILD_SHIFT); 689d4e87444SJacob Keller 690d4e87444SJacob Keller return 0; 691d4e87444SJacob Keller } 692d4e87444SJacob Keller 693d4e87444SJacob Keller /** 694*e67fbcfbSJacob Keller * ice_get_inactive_orom_ver - Read Option ROM version from the inactive bank 695*e67fbcfbSJacob Keller * @hw: pointer to the HW structure 696*e67fbcfbSJacob Keller * @orom: storage for Option ROM version information 697*e67fbcfbSJacob Keller * 698*e67fbcfbSJacob Keller * Reads the Option ROM version and security revision data for the inactive 699*e67fbcfbSJacob Keller * section of flash. Used to access version data for a pending update that has 700*e67fbcfbSJacob Keller * not yet been activated. 701*e67fbcfbSJacob Keller */ 702*e67fbcfbSJacob Keller enum ice_status ice_get_inactive_orom_ver(struct ice_hw *hw, struct ice_orom_info *orom) 703*e67fbcfbSJacob Keller { 704*e67fbcfbSJacob Keller return ice_get_orom_ver_info(hw, ICE_INACTIVE_FLASH_BANK, orom); 705*e67fbcfbSJacob Keller } 706*e67fbcfbSJacob Keller 707*e67fbcfbSJacob Keller /** 708e120a9abSJacob Keller * ice_get_netlist_info 709f45a645fSJacob Keller * @hw: pointer to the HW struct 710e120a9abSJacob Keller * @bank: whether to read from the active or inactive flash bank 711e120a9abSJacob Keller * @netlist: pointer to netlist version info structure 712f45a645fSJacob Keller * 713e120a9abSJacob Keller * Get the netlist version information from the requested bank. Reads the Link 714e120a9abSJacob Keller * Topology section to find the Netlist ID block and extract the relevant 715e120a9abSJacob Keller * information into the netlist version structure. 716f45a645fSJacob Keller */ 7179af368faSJacob Keller static enum ice_status 718e120a9abSJacob Keller ice_get_netlist_info(struct ice_hw *hw, enum ice_bank_select bank, 719e120a9abSJacob Keller struct ice_netlist_info *netlist) 720f45a645fSJacob Keller { 721e120a9abSJacob Keller u16 module_id, length, node_count, i; 722e120a9abSJacob Keller enum ice_status status; 723e120a9abSJacob Keller u16 *id_blk; 724f45a645fSJacob Keller 725e120a9abSJacob Keller status = ice_read_netlist_module(hw, bank, ICE_NETLIST_TYPE_OFFSET, &module_id); 726e120a9abSJacob Keller if (status) 727e120a9abSJacob Keller return status; 728e120a9abSJacob Keller 729e120a9abSJacob Keller if (module_id != ICE_NETLIST_LINK_TOPO_MOD_ID) { 730e120a9abSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Expected netlist module_id ID of 0x%04x, but got 0x%04x\n", 731e120a9abSJacob Keller ICE_NETLIST_LINK_TOPO_MOD_ID, module_id); 732e120a9abSJacob Keller return ICE_ERR_NVM; 733f45a645fSJacob Keller } 734f45a645fSJacob Keller 735e120a9abSJacob Keller status = ice_read_netlist_module(hw, bank, ICE_LINK_TOPO_MODULE_LEN, &length); 736e120a9abSJacob Keller if (status) 737e120a9abSJacob Keller return status; 738e120a9abSJacob Keller 739e120a9abSJacob Keller /* sanity check that we have at least enough words to store the netlist ID block */ 740e120a9abSJacob Keller if (length < ICE_NETLIST_ID_BLK_SIZE) { 741e120a9abSJacob Keller ice_debug(hw, ICE_DBG_NVM, "Netlist Link Topology module too small. Expected at least %u words, but got %u words.\n", 742e120a9abSJacob Keller ICE_NETLIST_ID_BLK_SIZE, length); 743e120a9abSJacob Keller return ICE_ERR_NVM; 744e120a9abSJacob Keller } 745e120a9abSJacob Keller 746e120a9abSJacob Keller status = ice_read_netlist_module(hw, bank, ICE_LINK_TOPO_NODE_COUNT, &node_count); 747e120a9abSJacob Keller if (status) 748e120a9abSJacob Keller return status; 749e120a9abSJacob Keller node_count &= ICE_LINK_TOPO_NODE_COUNT_M; 750e120a9abSJacob Keller 751e120a9abSJacob Keller id_blk = kcalloc(ICE_NETLIST_ID_BLK_SIZE, sizeof(*id_blk), GFP_KERNEL); 752e120a9abSJacob Keller if (!id_blk) 753e120a9abSJacob Keller return ICE_ERR_NO_MEMORY; 754e120a9abSJacob Keller 755e120a9abSJacob Keller /* Read out the entire Netlist ID Block at once. */ 756e120a9abSJacob Keller status = ice_read_flash_module(hw, bank, ICE_SR_NETLIST_BANK_PTR, 757e120a9abSJacob Keller ICE_NETLIST_ID_BLK_OFFSET(node_count) * sizeof(u16), 758e120a9abSJacob Keller (u8 *)id_blk, ICE_NETLIST_ID_BLK_SIZE * sizeof(u16)); 759e120a9abSJacob Keller if (status) 760f45a645fSJacob Keller goto exit_error; 761f45a645fSJacob Keller 762e120a9abSJacob Keller for (i = 0; i < ICE_NETLIST_ID_BLK_SIZE; i++) 763e120a9abSJacob Keller id_blk[i] = le16_to_cpu(((__force __le16 *)id_blk)[i]); 764f45a645fSJacob Keller 765e120a9abSJacob Keller netlist->major = id_blk[ICE_NETLIST_ID_BLK_MAJOR_VER_HIGH] << 16 | 766e120a9abSJacob Keller id_blk[ICE_NETLIST_ID_BLK_MAJOR_VER_LOW]; 767e120a9abSJacob Keller netlist->minor = id_blk[ICE_NETLIST_ID_BLK_MINOR_VER_HIGH] << 16 | 768e120a9abSJacob Keller id_blk[ICE_NETLIST_ID_BLK_MINOR_VER_LOW]; 769e120a9abSJacob Keller netlist->type = id_blk[ICE_NETLIST_ID_BLK_TYPE_HIGH] << 16 | 770e120a9abSJacob Keller id_blk[ICE_NETLIST_ID_BLK_TYPE_LOW]; 771e120a9abSJacob Keller netlist->rev = id_blk[ICE_NETLIST_ID_BLK_REV_HIGH] << 16 | 772e120a9abSJacob Keller id_blk[ICE_NETLIST_ID_BLK_REV_LOW]; 773e120a9abSJacob Keller netlist->cust_ver = id_blk[ICE_NETLIST_ID_BLK_CUST_VER]; 774f45a645fSJacob Keller /* Read the left most 4 bytes of SHA */ 775e120a9abSJacob Keller netlist->hash = id_blk[ICE_NETLIST_ID_BLK_SHA_HASH_WORD(15)] << 16 | 776e120a9abSJacob Keller id_blk[ICE_NETLIST_ID_BLK_SHA_HASH_WORD(14)]; 777f45a645fSJacob Keller 778f45a645fSJacob Keller exit_error: 779e120a9abSJacob Keller kfree(id_blk); 780e120a9abSJacob Keller 781e120a9abSJacob Keller return status; 782e120a9abSJacob Keller } 783e120a9abSJacob Keller 784e120a9abSJacob Keller /** 785e120a9abSJacob Keller * ice_get_inactive_netlist_ver 786e120a9abSJacob Keller * @hw: pointer to the HW struct 787e120a9abSJacob Keller * @netlist: pointer to netlist version info structure 788e120a9abSJacob Keller * 789e120a9abSJacob Keller * Read the netlist version data from the inactive netlist bank. Used to 790e120a9abSJacob Keller * extract version data of a pending flash update in order to display the 791e120a9abSJacob Keller * version data. 792e120a9abSJacob Keller */ 793e120a9abSJacob Keller enum ice_status ice_get_inactive_netlist_ver(struct ice_hw *hw, struct ice_netlist_info *netlist) 794e120a9abSJacob Keller { 795e120a9abSJacob Keller return ice_get_netlist_info(hw, ICE_INACTIVE_FLASH_BANK, netlist); 796f45a645fSJacob Keller } 797f45a645fSJacob Keller 798f45a645fSJacob Keller /** 79981f07491SJacob Keller * ice_discover_flash_size - Discover the available flash size. 80081f07491SJacob Keller * @hw: pointer to the HW struct 80181f07491SJacob Keller * 80281f07491SJacob Keller * The device flash could be up to 16MB in size. However, it is possible that 80381f07491SJacob Keller * the actual size is smaller. Use bisection to determine the accessible size 80481f07491SJacob Keller * of flash memory. 80581f07491SJacob Keller */ 80681f07491SJacob Keller static enum ice_status ice_discover_flash_size(struct ice_hw *hw) 80781f07491SJacob Keller { 80881f07491SJacob Keller u32 min_size = 0, max_size = ICE_AQC_NVM_MAX_OFFSET + 1; 80981f07491SJacob Keller enum ice_status status; 81081f07491SJacob Keller 81181f07491SJacob Keller status = ice_acquire_nvm(hw, ICE_RES_READ); 81281f07491SJacob Keller if (status) 81381f07491SJacob Keller return status; 81481f07491SJacob Keller 81581f07491SJacob Keller while ((max_size - min_size) > 1) { 81681f07491SJacob Keller u32 offset = (max_size + min_size) / 2; 81781f07491SJacob Keller u32 len = 1; 81881f07491SJacob Keller u8 data; 81981f07491SJacob Keller 82081f07491SJacob Keller status = ice_read_flat_nvm(hw, offset, &len, &data, false); 82181f07491SJacob Keller if (status == ICE_ERR_AQ_ERROR && 82281f07491SJacob Keller hw->adminq.sq_last_status == ICE_AQ_RC_EINVAL) { 8239228d8b2SJacob Keller ice_debug(hw, ICE_DBG_NVM, "%s: New upper bound of %u bytes\n", 82481f07491SJacob Keller __func__, offset); 82581f07491SJacob Keller status = 0; 82681f07491SJacob Keller max_size = offset; 82781f07491SJacob Keller } else if (!status) { 8289228d8b2SJacob Keller ice_debug(hw, ICE_DBG_NVM, "%s: New lower bound of %u bytes\n", 82981f07491SJacob Keller __func__, offset); 83081f07491SJacob Keller min_size = offset; 83181f07491SJacob Keller } else { 83281f07491SJacob Keller /* an unexpected error occurred */ 83381f07491SJacob Keller goto err_read_flat_nvm; 83481f07491SJacob Keller } 83581f07491SJacob Keller } 83681f07491SJacob Keller 8379228d8b2SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Predicted flash size is %u bytes\n", max_size); 83881f07491SJacob Keller 8399af368faSJacob Keller hw->flash.flash_size = max_size; 84081f07491SJacob Keller 84181f07491SJacob Keller err_read_flat_nvm: 84281f07491SJacob Keller ice_release_nvm(hw); 84381f07491SJacob Keller 84481f07491SJacob Keller return status; 84581f07491SJacob Keller } 84681f07491SJacob Keller 84781f07491SJacob Keller /** 8481fa95e01SJacob Keller * ice_read_sr_pointer - Read the value of a Shadow RAM pointer word 8491fa95e01SJacob Keller * @hw: pointer to the HW structure 8501fa95e01SJacob Keller * @offset: the word offset of the Shadow RAM word to read 8511fa95e01SJacob Keller * @pointer: pointer value read from Shadow RAM 8521fa95e01SJacob Keller * 8531fa95e01SJacob Keller * Read the given Shadow RAM word, and convert it to a pointer value specified 8541fa95e01SJacob Keller * in bytes. This function assumes the specified offset is a valid pointer 8551fa95e01SJacob Keller * word. 8561fa95e01SJacob Keller * 8571fa95e01SJacob Keller * Each pointer word specifies whether it is stored in word size or 4KB 8581fa95e01SJacob Keller * sector size by using the highest bit. The reported pointer value will be in 8591fa95e01SJacob Keller * bytes, intended for flat NVM reads. 8601fa95e01SJacob Keller */ 8611fa95e01SJacob Keller static enum ice_status 8621fa95e01SJacob Keller ice_read_sr_pointer(struct ice_hw *hw, u16 offset, u32 *pointer) 8631fa95e01SJacob Keller { 8641fa95e01SJacob Keller enum ice_status status; 8651fa95e01SJacob Keller u16 value; 8661fa95e01SJacob Keller 8671fa95e01SJacob Keller status = ice_read_sr_word(hw, offset, &value); 8681fa95e01SJacob Keller if (status) 8691fa95e01SJacob Keller return status; 8701fa95e01SJacob Keller 8711fa95e01SJacob Keller /* Determine if the pointer is in 4KB or word units */ 8721fa95e01SJacob Keller if (value & ICE_SR_NVM_PTR_4KB_UNITS) 8731fa95e01SJacob Keller *pointer = (value & ~ICE_SR_NVM_PTR_4KB_UNITS) * 4 * 1024; 8741fa95e01SJacob Keller else 8751fa95e01SJacob Keller *pointer = value * 2; 8761fa95e01SJacob Keller 8771fa95e01SJacob Keller return 0; 8781fa95e01SJacob Keller } 8791fa95e01SJacob Keller 8801fa95e01SJacob Keller /** 8811fa95e01SJacob Keller * ice_read_sr_area_size - Read an area size from a Shadow RAM word 8821fa95e01SJacob Keller * @hw: pointer to the HW structure 8831fa95e01SJacob Keller * @offset: the word offset of the Shadow RAM to read 8841fa95e01SJacob Keller * @size: size value read from the Shadow RAM 8851fa95e01SJacob Keller * 8861fa95e01SJacob Keller * Read the given Shadow RAM word, and convert it to an area size value 8871fa95e01SJacob Keller * specified in bytes. This function assumes the specified offset is a valid 8881fa95e01SJacob Keller * area size word. 8891fa95e01SJacob Keller * 8901fa95e01SJacob Keller * Each area size word is specified in 4KB sector units. This function reports 8911fa95e01SJacob Keller * the size in bytes, intended for flat NVM reads. 8921fa95e01SJacob Keller */ 8931fa95e01SJacob Keller static enum ice_status 8941fa95e01SJacob Keller ice_read_sr_area_size(struct ice_hw *hw, u16 offset, u32 *size) 8951fa95e01SJacob Keller { 8961fa95e01SJacob Keller enum ice_status status; 8971fa95e01SJacob Keller u16 value; 8981fa95e01SJacob Keller 8991fa95e01SJacob Keller status = ice_read_sr_word(hw, offset, &value); 9001fa95e01SJacob Keller if (status) 9011fa95e01SJacob Keller return status; 9021fa95e01SJacob Keller 9031fa95e01SJacob Keller /* Area sizes are always specified in 4KB units */ 9041fa95e01SJacob Keller *size = value * 4 * 1024; 9051fa95e01SJacob Keller 9061fa95e01SJacob Keller return 0; 9071fa95e01SJacob Keller } 9081fa95e01SJacob Keller 9091fa95e01SJacob Keller /** 9101fa95e01SJacob Keller * ice_determine_active_flash_banks - Discover active bank for each module 9111fa95e01SJacob Keller * @hw: pointer to the HW struct 9121fa95e01SJacob Keller * 9131fa95e01SJacob Keller * Read the Shadow RAM control word and determine which banks are active for 9141fa95e01SJacob Keller * the NVM, OROM, and Netlist modules. Also read and calculate the associated 9151fa95e01SJacob Keller * pointer and size. These values are then cached into the ice_flash_info 9161fa95e01SJacob Keller * structure for later use in order to calculate the correct offset to read 9171fa95e01SJacob Keller * from the active module. 9181fa95e01SJacob Keller */ 9191fa95e01SJacob Keller static enum ice_status 9201fa95e01SJacob Keller ice_determine_active_flash_banks(struct ice_hw *hw) 9211fa95e01SJacob Keller { 9221fa95e01SJacob Keller struct ice_bank_info *banks = &hw->flash.banks; 9231fa95e01SJacob Keller enum ice_status status; 9241fa95e01SJacob Keller u16 ctrl_word; 9251fa95e01SJacob Keller 9261fa95e01SJacob Keller status = ice_read_sr_word(hw, ICE_SR_NVM_CTRL_WORD, &ctrl_word); 9271fa95e01SJacob Keller if (status) { 9281fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read the Shadow RAM control word\n"); 9291fa95e01SJacob Keller return status; 9301fa95e01SJacob Keller } 9311fa95e01SJacob Keller 9321fa95e01SJacob Keller /* Check that the control word indicates validity */ 9331fa95e01SJacob Keller if ((ctrl_word & ICE_SR_CTRL_WORD_1_M) >> ICE_SR_CTRL_WORD_1_S != ICE_SR_CTRL_WORD_VALID) { 9341fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Shadow RAM control word is invalid\n"); 9351fa95e01SJacob Keller return ICE_ERR_CFG; 9361fa95e01SJacob Keller } 9371fa95e01SJacob Keller 9381fa95e01SJacob Keller if (!(ctrl_word & ICE_SR_CTRL_WORD_NVM_BANK)) 9391fa95e01SJacob Keller banks->nvm_bank = ICE_1ST_FLASH_BANK; 9401fa95e01SJacob Keller else 9411fa95e01SJacob Keller banks->nvm_bank = ICE_2ND_FLASH_BANK; 9421fa95e01SJacob Keller 9431fa95e01SJacob Keller if (!(ctrl_word & ICE_SR_CTRL_WORD_OROM_BANK)) 9441fa95e01SJacob Keller banks->orom_bank = ICE_1ST_FLASH_BANK; 9451fa95e01SJacob Keller else 9461fa95e01SJacob Keller banks->orom_bank = ICE_2ND_FLASH_BANK; 9471fa95e01SJacob Keller 9481fa95e01SJacob Keller if (!(ctrl_word & ICE_SR_CTRL_WORD_NETLIST_BANK)) 9491fa95e01SJacob Keller banks->netlist_bank = ICE_1ST_FLASH_BANK; 9501fa95e01SJacob Keller else 9511fa95e01SJacob Keller banks->netlist_bank = ICE_2ND_FLASH_BANK; 9521fa95e01SJacob Keller 9531fa95e01SJacob Keller status = ice_read_sr_pointer(hw, ICE_SR_1ST_NVM_BANK_PTR, &banks->nvm_ptr); 9541fa95e01SJacob Keller if (status) { 9551fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read NVM bank pointer\n"); 9561fa95e01SJacob Keller return status; 9571fa95e01SJacob Keller } 9581fa95e01SJacob Keller 9591fa95e01SJacob Keller status = ice_read_sr_area_size(hw, ICE_SR_NVM_BANK_SIZE, &banks->nvm_size); 9601fa95e01SJacob Keller if (status) { 9611fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read NVM bank area size\n"); 9621fa95e01SJacob Keller return status; 9631fa95e01SJacob Keller } 9641fa95e01SJacob Keller 9651fa95e01SJacob Keller status = ice_read_sr_pointer(hw, ICE_SR_1ST_OROM_BANK_PTR, &banks->orom_ptr); 9661fa95e01SJacob Keller if (status) { 9671fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read OROM bank pointer\n"); 9681fa95e01SJacob Keller return status; 9691fa95e01SJacob Keller } 9701fa95e01SJacob Keller 9711fa95e01SJacob Keller status = ice_read_sr_area_size(hw, ICE_SR_OROM_BANK_SIZE, &banks->orom_size); 9721fa95e01SJacob Keller if (status) { 9731fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read OROM bank area size\n"); 9741fa95e01SJacob Keller return status; 9751fa95e01SJacob Keller } 9761fa95e01SJacob Keller 9771fa95e01SJacob Keller status = ice_read_sr_pointer(hw, ICE_SR_NETLIST_BANK_PTR, &banks->netlist_ptr); 9781fa95e01SJacob Keller if (status) { 9791fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read Netlist bank pointer\n"); 9801fa95e01SJacob Keller return status; 9811fa95e01SJacob Keller } 9821fa95e01SJacob Keller 9831fa95e01SJacob Keller status = ice_read_sr_area_size(hw, ICE_SR_NETLIST_BANK_SIZE, &banks->netlist_size); 9841fa95e01SJacob Keller if (status) { 9851fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to read Netlist bank area size\n"); 9861fa95e01SJacob Keller return status; 9871fa95e01SJacob Keller } 9881fa95e01SJacob Keller 9891fa95e01SJacob Keller return 0; 9901fa95e01SJacob Keller } 9911fa95e01SJacob Keller 9921fa95e01SJacob Keller /** 993f31e4b6fSAnirudh Venkataramanan * ice_init_nvm - initializes NVM setting 994f9867df6SAnirudh Venkataramanan * @hw: pointer to the HW struct 995f31e4b6fSAnirudh Venkataramanan * 996f31e4b6fSAnirudh Venkataramanan * This function reads and populates NVM settings such as Shadow RAM size, 997f31e4b6fSAnirudh Venkataramanan * max_timeout, and blank_nvm_mode 998f31e4b6fSAnirudh Venkataramanan */ 999f31e4b6fSAnirudh Venkataramanan enum ice_status ice_init_nvm(struct ice_hw *hw) 1000f31e4b6fSAnirudh Venkataramanan { 10019af368faSJacob Keller struct ice_flash_info *flash = &hw->flash; 1002031f2147SMd Fahad Iqbal Polash enum ice_status status; 1003f31e4b6fSAnirudh Venkataramanan u32 fla, gens_stat; 1004f31e4b6fSAnirudh Venkataramanan u8 sr_size; 1005f31e4b6fSAnirudh Venkataramanan 1006f9867df6SAnirudh Venkataramanan /* The SR size is stored regardless of the NVM programming mode 1007f31e4b6fSAnirudh Venkataramanan * as the blank mode may be used in the factory line. 1008f31e4b6fSAnirudh Venkataramanan */ 1009f31e4b6fSAnirudh Venkataramanan gens_stat = rd32(hw, GLNVM_GENS); 1010f31e4b6fSAnirudh Venkataramanan sr_size = (gens_stat & GLNVM_GENS_SR_SIZE_M) >> GLNVM_GENS_SR_SIZE_S; 1011f31e4b6fSAnirudh Venkataramanan 1012f31e4b6fSAnirudh Venkataramanan /* Switching to words (sr_size contains power of 2) */ 10139af368faSJacob Keller flash->sr_words = BIT(sr_size) * ICE_SR_WORDS_IN_1KB; 1014f31e4b6fSAnirudh Venkataramanan 1015f31e4b6fSAnirudh Venkataramanan /* Check if we are in the normal or blank NVM programming mode */ 1016f31e4b6fSAnirudh Venkataramanan fla = rd32(hw, GLNVM_FLA); 1017f31e4b6fSAnirudh Venkataramanan if (fla & GLNVM_FLA_LOCKED_M) { /* Normal programming mode */ 10189af368faSJacob Keller flash->blank_nvm_mode = false; 1019031f2147SMd Fahad Iqbal Polash } else { 1020031f2147SMd Fahad Iqbal Polash /* Blank programming mode */ 10219af368faSJacob Keller flash->blank_nvm_mode = true; 10229228d8b2SJacob Keller ice_debug(hw, ICE_DBG_NVM, "NVM init error: unsupported blank mode.\n"); 1023031f2147SMd Fahad Iqbal Polash return ICE_ERR_NVM_BLANK_MODE; 1024f31e4b6fSAnirudh Venkataramanan } 1025f31e4b6fSAnirudh Venkataramanan 102681f07491SJacob Keller status = ice_discover_flash_size(hw); 102781f07491SJacob Keller if (status) { 10289228d8b2SJacob Keller ice_debug(hw, ICE_DBG_NVM, "NVM init error: failed to discover flash size.\n"); 102981f07491SJacob Keller return status; 103081f07491SJacob Keller } 103181f07491SJacob Keller 10321fa95e01SJacob Keller status = ice_determine_active_flash_banks(hw); 10331fa95e01SJacob Keller if (status) { 10341fa95e01SJacob Keller ice_debug(hw, ICE_DBG_NVM, "Failed to determine active flash banks.\n"); 10351fa95e01SJacob Keller return status; 10361fa95e01SJacob Keller } 10371fa95e01SJacob Keller 10380ce50c70SJacob Keller status = ice_get_nvm_ver_info(hw, ICE_ACTIVE_FLASH_BANK, &flash->nvm); 10399af368faSJacob Keller if (status) { 10409af368faSJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read NVM info.\n"); 10419af368faSJacob Keller return status; 10429af368faSJacob Keller } 10439af368faSJacob Keller 1044*e67fbcfbSJacob Keller status = ice_get_orom_ver_info(hw, ICE_ACTIVE_FLASH_BANK, &flash->orom); 1045*e67fbcfbSJacob Keller if (status) 1046d4e87444SJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read Option ROM info.\n"); 10474c98ab55SBruce Allan 1048f45a645fSJacob Keller /* read the netlist version information */ 1049e120a9abSJacob Keller status = ice_get_netlist_info(hw, ICE_ACTIVE_FLASH_BANK, &flash->netlist); 1050f45a645fSJacob Keller if (status) 1051f45a645fSJacob Keller ice_debug(hw, ICE_DBG_INIT, "Failed to read netlist info.\n"); 1052f45a645fSJacob Keller 1053031f2147SMd Fahad Iqbal Polash return 0; 1054031f2147SMd Fahad Iqbal Polash } 1055031f2147SMd Fahad Iqbal Polash 10564c98ab55SBruce Allan /** 10570e674aebSAnirudh Venkataramanan * ice_nvm_validate_checksum 10580e674aebSAnirudh Venkataramanan * @hw: pointer to the HW struct 10590e674aebSAnirudh Venkataramanan * 10600e674aebSAnirudh Venkataramanan * Verify NVM PFA checksum validity (0x0706) 10610e674aebSAnirudh Venkataramanan */ 10620e674aebSAnirudh Venkataramanan enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw) 10630e674aebSAnirudh Venkataramanan { 10640e674aebSAnirudh Venkataramanan struct ice_aqc_nvm_checksum *cmd; 10650e674aebSAnirudh Venkataramanan struct ice_aq_desc desc; 10660e674aebSAnirudh Venkataramanan enum ice_status status; 10670e674aebSAnirudh Venkataramanan 10680e674aebSAnirudh Venkataramanan status = ice_acquire_nvm(hw, ICE_RES_READ); 10690e674aebSAnirudh Venkataramanan if (status) 10700e674aebSAnirudh Venkataramanan return status; 10710e674aebSAnirudh Venkataramanan 10720e674aebSAnirudh Venkataramanan cmd = &desc.params.nvm_checksum; 10730e674aebSAnirudh Venkataramanan 10740e674aebSAnirudh Venkataramanan ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_checksum); 10750e674aebSAnirudh Venkataramanan cmd->flags = ICE_AQC_NVM_CHECKSUM_VERIFY; 10760e674aebSAnirudh Venkataramanan 10770e674aebSAnirudh Venkataramanan status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL); 10780e674aebSAnirudh Venkataramanan ice_release_nvm(hw); 10790e674aebSAnirudh Venkataramanan 10800e674aebSAnirudh Venkataramanan if (!status) 10810e674aebSAnirudh Venkataramanan if (le16_to_cpu(cmd->checksum) != ICE_AQC_NVM_CHECKSUM_CORRECT) 10820e674aebSAnirudh Venkataramanan status = ICE_ERR_NVM_CHECKSUM; 10830e674aebSAnirudh Venkataramanan 10840e674aebSAnirudh Venkataramanan return status; 10850e674aebSAnirudh Venkataramanan } 1086544cd2acSCudzilo, Szymon T 1087544cd2acSCudzilo, Szymon T /** 1088544cd2acSCudzilo, Szymon T * ice_nvm_write_activate 1089544cd2acSCudzilo, Szymon T * @hw: pointer to the HW struct 1090544cd2acSCudzilo, Szymon T * @cmd_flags: NVM activate admin command bits (banks to be validated) 1091544cd2acSCudzilo, Szymon T * 1092544cd2acSCudzilo, Szymon T * Update the control word with the required banks' validity bits 1093544cd2acSCudzilo, Szymon T * and dumps the Shadow RAM to flash (0x0707) 1094544cd2acSCudzilo, Szymon T */ 1095544cd2acSCudzilo, Szymon T enum ice_status ice_nvm_write_activate(struct ice_hw *hw, u8 cmd_flags) 1096544cd2acSCudzilo, Szymon T { 1097544cd2acSCudzilo, Szymon T struct ice_aqc_nvm *cmd; 1098544cd2acSCudzilo, Szymon T struct ice_aq_desc desc; 1099544cd2acSCudzilo, Szymon T 1100544cd2acSCudzilo, Szymon T cmd = &desc.params.nvm; 1101544cd2acSCudzilo, Szymon T ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_write_activate); 1102544cd2acSCudzilo, Szymon T 1103544cd2acSCudzilo, Szymon T cmd->cmd_flags = cmd_flags; 1104544cd2acSCudzilo, Szymon T 1105544cd2acSCudzilo, Szymon T return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL); 1106544cd2acSCudzilo, Szymon T } 1107544cd2acSCudzilo, Szymon T 1108544cd2acSCudzilo, Szymon T /** 1109544cd2acSCudzilo, Szymon T * ice_aq_nvm_update_empr 1110544cd2acSCudzilo, Szymon T * @hw: pointer to the HW struct 1111544cd2acSCudzilo, Szymon T * 1112544cd2acSCudzilo, Szymon T * Update empr (0x0709). This command allows SW to 1113544cd2acSCudzilo, Szymon T * request an EMPR to activate new FW. 1114544cd2acSCudzilo, Szymon T */ 1115544cd2acSCudzilo, Szymon T enum ice_status ice_aq_nvm_update_empr(struct ice_hw *hw) 1116544cd2acSCudzilo, Szymon T { 1117544cd2acSCudzilo, Szymon T struct ice_aq_desc desc; 1118544cd2acSCudzilo, Szymon T 1119544cd2acSCudzilo, Szymon T ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_update_empr); 1120544cd2acSCudzilo, Szymon T 1121544cd2acSCudzilo, Szymon T return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL); 1122544cd2acSCudzilo, Szymon T } 1123544cd2acSCudzilo, Szymon T 1124544cd2acSCudzilo, Szymon T /* ice_nvm_set_pkg_data 1125544cd2acSCudzilo, Szymon T * @hw: pointer to the HW struct 1126544cd2acSCudzilo, Szymon T * @del_pkg_data_flag: If is set then the current pkg_data store by FW 1127544cd2acSCudzilo, Szymon T * is deleted. 1128544cd2acSCudzilo, Szymon T * If bit is set to 1, then buffer should be size 0. 1129544cd2acSCudzilo, Szymon T * @data: pointer to buffer 1130544cd2acSCudzilo, Szymon T * @length: length of the buffer 1131544cd2acSCudzilo, Szymon T * @cd: pointer to command details structure or NULL 1132544cd2acSCudzilo, Szymon T * 1133544cd2acSCudzilo, Szymon T * Set package data (0x070A). This command is equivalent to the reception 1134544cd2acSCudzilo, Szymon T * of a PLDM FW Update GetPackageData cmd. This command should be sent 1135544cd2acSCudzilo, Szymon T * as part of the NVM update as the first cmd in the flow. 1136544cd2acSCudzilo, Szymon T */ 1137544cd2acSCudzilo, Szymon T 1138544cd2acSCudzilo, Szymon T enum ice_status 1139544cd2acSCudzilo, Szymon T ice_nvm_set_pkg_data(struct ice_hw *hw, bool del_pkg_data_flag, u8 *data, 1140544cd2acSCudzilo, Szymon T u16 length, struct ice_sq_cd *cd) 1141544cd2acSCudzilo, Szymon T { 1142544cd2acSCudzilo, Szymon T struct ice_aqc_nvm_pkg_data *cmd; 1143544cd2acSCudzilo, Szymon T struct ice_aq_desc desc; 1144544cd2acSCudzilo, Szymon T 1145544cd2acSCudzilo, Szymon T if (length != 0 && !data) 1146544cd2acSCudzilo, Szymon T return ICE_ERR_PARAM; 1147544cd2acSCudzilo, Szymon T 1148544cd2acSCudzilo, Szymon T cmd = &desc.params.pkg_data; 1149544cd2acSCudzilo, Szymon T 1150544cd2acSCudzilo, Szymon T ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_pkg_data); 1151544cd2acSCudzilo, Szymon T desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); 1152544cd2acSCudzilo, Szymon T 1153544cd2acSCudzilo, Szymon T if (del_pkg_data_flag) 1154544cd2acSCudzilo, Szymon T cmd->cmd_flags |= ICE_AQC_NVM_PKG_DELETE; 1155544cd2acSCudzilo, Szymon T 1156544cd2acSCudzilo, Szymon T return ice_aq_send_cmd(hw, &desc, data, length, cd); 1157544cd2acSCudzilo, Szymon T } 1158544cd2acSCudzilo, Szymon T 1159544cd2acSCudzilo, Szymon T /* ice_nvm_pass_component_tbl 1160544cd2acSCudzilo, Szymon T * @hw: pointer to the HW struct 1161544cd2acSCudzilo, Szymon T * @data: pointer to buffer 1162544cd2acSCudzilo, Szymon T * @length: length of the buffer 1163544cd2acSCudzilo, Szymon T * @transfer_flag: parameter for determining stage of the update 1164544cd2acSCudzilo, Szymon T * @comp_response: a pointer to the response from the 0x070B AQC. 1165544cd2acSCudzilo, Szymon T * @comp_response_code: a pointer to the response code from the 0x070B AQC. 1166544cd2acSCudzilo, Szymon T * @cd: pointer to command details structure or NULL 1167544cd2acSCudzilo, Szymon T * 1168544cd2acSCudzilo, Szymon T * Pass component table (0x070B). This command is equivalent to the reception 1169544cd2acSCudzilo, Szymon T * of a PLDM FW Update PassComponentTable cmd. This command should be sent once 1170544cd2acSCudzilo, Szymon T * per component. It can be only sent after Set Package Data cmd and before 1171544cd2acSCudzilo, Szymon T * actual update. FW will assume these commands are going to be sent until 1172544cd2acSCudzilo, Szymon T * the TransferFlag is set to End or StartAndEnd. 1173544cd2acSCudzilo, Szymon T */ 1174544cd2acSCudzilo, Szymon T 1175544cd2acSCudzilo, Szymon T enum ice_status 1176544cd2acSCudzilo, Szymon T ice_nvm_pass_component_tbl(struct ice_hw *hw, u8 *data, u16 length, 1177544cd2acSCudzilo, Szymon T u8 transfer_flag, u8 *comp_response, 1178544cd2acSCudzilo, Szymon T u8 *comp_response_code, struct ice_sq_cd *cd) 1179544cd2acSCudzilo, Szymon T { 1180544cd2acSCudzilo, Szymon T struct ice_aqc_nvm_pass_comp_tbl *cmd; 1181544cd2acSCudzilo, Szymon T struct ice_aq_desc desc; 1182544cd2acSCudzilo, Szymon T enum ice_status status; 1183544cd2acSCudzilo, Szymon T 1184544cd2acSCudzilo, Szymon T if (!data || !comp_response || !comp_response_code) 1185544cd2acSCudzilo, Szymon T return ICE_ERR_PARAM; 1186544cd2acSCudzilo, Szymon T 1187544cd2acSCudzilo, Szymon T cmd = &desc.params.pass_comp_tbl; 1188544cd2acSCudzilo, Szymon T 1189544cd2acSCudzilo, Szymon T ice_fill_dflt_direct_cmd_desc(&desc, 1190544cd2acSCudzilo, Szymon T ice_aqc_opc_nvm_pass_component_tbl); 1191544cd2acSCudzilo, Szymon T desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); 1192544cd2acSCudzilo, Szymon T 1193544cd2acSCudzilo, Szymon T cmd->transfer_flag = transfer_flag; 1194544cd2acSCudzilo, Szymon T status = ice_aq_send_cmd(hw, &desc, data, length, cd); 1195544cd2acSCudzilo, Szymon T 1196544cd2acSCudzilo, Szymon T if (!status) { 1197544cd2acSCudzilo, Szymon T *comp_response = cmd->component_response; 1198544cd2acSCudzilo, Szymon T *comp_response_code = cmd->component_response_code; 1199544cd2acSCudzilo, Szymon T } 1200544cd2acSCudzilo, Szymon T return status; 1201544cd2acSCudzilo, Szymon T } 1202