if (!read_shadow_ram && module_typeid == ICE_AQC_NVM_START_POINT)
cmd->cmd_flags |= ICE_AQC_NVM_FLASH_ONLY;
/* If this is the last command in a series, set the proper flag. */ if (last_command)
cmd->cmd_flags |= ICE_AQC_NVM_LAST_CMD;
cmd->module_typeid = cpu_to_le16(module_typeid);
cmd->offset_low = cpu_to_le16(offset & 0xFFFF);
cmd->offset_high = (offset >> 16) & 0xFF;
cmd->length = cpu_to_le16(length);
/* Verify the length of the read if this is for the Shadow RAM */ if (read_shadow_ram && ((offset + inlen) > (hw->flash.sr_words * 2u))) {
ice_debug(hw, ICE_DBG_NVM, "NVM error: requested offset is beyond Shadow RAM limit\n"); return -EINVAL;
}
do {
u32 read_size, sector_offset;
/* ice_aq_read_nvm cannot read more than 4KB at a time. *Additionally,areadfromtheShadowRAMmaynotcrossover *asectorboundary.Conveniently,thesectorsizeisalso *4KB.
*/
sector_offset = offset % ICE_AQ_MAX_BUF_LEN;
read_size = min_t(u32, ICE_AQ_MAX_BUF_LEN - sector_offset,
inlen - bytes_read);
last_cmd = !(bytes_read + read_size < inlen);
status = ice_aq_read_nvm(hw, ICE_AQC_NVM_START_POINT,
offset, read_size,
data + bytes_read, last_cmd,
read_shadow_ram, NULL); if (status) break;
bytes_read += read_size;
offset += read_size;
} while (!last_cmd);
/* If this is the last command in a series, set the proper flag. */ if (last_command)
cmd->cmd_flags |= ICE_AQC_NVM_LAST_CMD;
cmd->module_typeid = cpu_to_le16(module_typeid);
cmd->offset_low = cpu_to_le16(offset & 0xFFFF);
cmd->offset_high = (offset >> 16) & 0xFF;
cmd->length = cpu_to_le16(length);
/* Note that ice_read_flat_nvm takes into account the 4Kb AdminQ and *ShadowRAMsectorrestrictionsnecessarywhenreadingfromtheNVM.
*/
status = ice_read_flat_nvm(hw, offset * sizeof(u16), &bytes,
(__force u8 *)&data_local, true); if (status) return status;
*data = le16_to_cpu(data_local); return0;
}
/** *ice_acquire_nvm-GenericrequestforacquiringtheNVMownership *@hw:pointertotheHWstructure *@access:NVMaccesstype(readorwrite) * *ThisfunctionwillrequestNVMownership.
*/ int ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access)
{ if (hw->flash.blank_nvm_mode) return0;
switch (active_bank) { case ICE_1ST_FLASH_BANK:
second_bank_active = false; break; case ICE_2ND_FLASH_BANK:
second_bank_active = true; break; default:
ice_debug(hw, ICE_DBG_NVM, "Unexpected value for active flash bank: %u\n",
active_bank); return0;
}
/* The second flash bank is stored immediately following the first *bank.Basedonwhetherthe1stor2ndbankisactive,andwhether *wewanttheactiveorinactivebank,calculatethedesiredoffset.
*/ switch (bank) { case ICE_ACTIVE_FLASH_BANK: return offset + (second_bank_active ? size : 0); case ICE_INACTIVE_FLASH_BANK: return offset + (second_bank_active ? 0 : size);
}
ice_debug(hw, ICE_DBG_NVM, "Unexpected value for flash bank selection: %u\n", bank); return0;
}
start = ice_get_flash_bank_offset(hw, bank, module); if (!start) {
ice_debug(hw, ICE_DBG_NVM, "Unable to calculate flash bank offset for module 0x%04x\n",
module); return -EINVAL;
}
status = ice_acquire_nvm(hw, ICE_RES_READ); if (status) return status;
status = ice_read_flat_nvm(hw, start + offset, &length, data, false);
status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Preserved Field Array pointer.\n"); return status;
}
status = ice_read_sr_word(hw, pfa_ptr, &pfa_len); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read PFA length.\n"); return status;
}
/* The Preserved Fields Area contains a sequence of Type-Length-Value *structureswhichdefineitscontents.ThePFAlengthincludesall *oftheTLVs,plustheinitiallengthworditself,*and*onefinal *wordattheendafteralloftheTLVs.
*/ if (check_add_overflow(pfa_ptr, pfa_len - 1, &max_tlv)) {
dev_warn(ice_hw_to_dev(hw), "PFA starts at offset %u. PFA length of %u caused 16-bit arithmetic overflow.\n",
pfa_ptr, pfa_len); return -EINVAL;
}
/* Starting with first TLV after PFA length, iterate through the list *ofTLVstofindtherequestedone.
*/
next_tlv = pfa_ptr + 1; while (next_tlv < max_tlv) {
u16 tlv_sub_module_type;
u16 tlv_len;
/* Read TLV type */
status = ice_read_sr_word(hw, next_tlv, &tlv_sub_module_type); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV type.\n"); break;
} /* Read TLV length */
status = ice_read_sr_word(hw, next_tlv + 1, &tlv_len); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV length.\n"); break;
} if (tlv_sub_module_type == module_type) { if (tlv_len) {
*module_tlv = next_tlv;
*module_tlv_len = tlv_len; return0;
} return -EINVAL;
}
if (check_add_overflow(next_tlv, 2, &next_tlv) ||
check_add_overflow(next_tlv, tlv_len, &next_tlv)) {
dev_warn(ice_hw_to_dev(hw), "TLV of type %u and length 0x%04x caused 16-bit arithmetic overflow. The PFA starts at 0x%04x and has length of 0x%04x\n",
tlv_sub_module_type, tlv_len, pfa_ptr, pfa_len); return -EINVAL;
}
} /* Module does not exist */ return -ENOENT;
}
status = ice_get_pfa_module_tlv(hw, &pba_tlv, &pba_tlv_len,
ICE_SR_PBA_BLOCK_PTR); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block TLV.\n"); return status;
}
/* pba_size is the next word */
status = ice_read_sr_word(hw, (pba_tlv + 2), &pba_size); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Section size.\n"); return status;
}
/* Subtract one to get PBA word count (PBA Size word is included in *totalsize)
*/
pba_size--; if (pba_num_size < (((u32)pba_size * 2) + 1)) {
ice_debug(hw, ICE_DBG_INIT, "Buffer too small for PBA data.\n"); return -EINVAL;
}
for (i = 0; i < pba_size; i++) {
status = ice_read_sr_word(hw, (pba_tlv + 2 + 1) + i, &pba_word); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block word %d.\n", i); return status;
}
status = ice_read_nvm_sr_copy(hw, bank, ICE_SR_NVM_DEV_STARTER_VER, &ver); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read DEV starter version.\n"); return status;
}
status = ice_read_nvm_sr_copy(hw, bank, ICE_SR_NVM_EETRACK_LO, &eetrack_lo); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read EETRACK lo.\n"); return status;
}
status = ice_read_nvm_sr_copy(hw, bank, ICE_SR_NVM_EETRACK_HI, &eetrack_hi); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read EETRACK hi.\n"); return status;
}
/* The CIVD section is located in the Option ROM aligned to 512 bytes. *Thefirst4bytesmustcontaintheASCIIcharacters"$CIV". *Asimplemodulo256sumofallofthebytesofthestructuremust *equal0. * *Theexactlocationisunknownandvariesbetweenimagesbutis *usuallysomewhereinthemiddleofthebank.Weneedtoscanthe *OptionROMbanktolocateit. * *It'ssignificantlyfastertoreadtheentireOptionROMupfront *usingthemaximumpagesize,thantoreadeachpossiblelocation *withaseparatefirmwarecommand.
*/
orom_data = vzalloc(hw->flash.banks.orom_size); if (!orom_data) return -ENOMEM;
status = ice_read_flash_module(hw, bank, ICE_SR_1ST_OROM_BANK_PTR, 0,
orom_data, hw->flash.banks.orom_size); if (status) {
vfree(orom_data);
ice_debug(hw, ICE_DBG_NVM, "Unable to read Option ROM data\n"); return status;
}
/* Scan the memory buffer to locate the CIVD data section */ for (offset = 0; (offset + 512) <= hw->flash.banks.orom_size; offset += 512) { struct ice_orom_civd_info *tmp;
u8 sum = 0, i;
status = ice_get_orom_civd_data(hw, bank, &civd); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to locate valid Option ROM CIVD data\n"); return status;
}
status = ice_read_netlist_module(hw, bank, ICE_NETLIST_TYPE_OFFSET, &module_id); if (status) return status;
if (module_id != ICE_NETLIST_LINK_TOPO_MOD_ID) {
ice_debug(hw, ICE_DBG_NVM, "Expected netlist module_id ID of 0x%04x, but got 0x%04x\n",
ICE_NETLIST_LINK_TOPO_MOD_ID, module_id); return -EIO;
}
status = ice_read_netlist_module(hw, bank, ICE_LINK_TOPO_MODULE_LEN, &length); if (status) return status;
/* sanity check that we have at least enough words to store the netlist ID block */ if (length < ICE_NETLIST_ID_BLK_SIZE) {
ice_debug(hw, ICE_DBG_NVM, "Netlist Link Topology module too small. Expected at least %u words, but got %u words.\n",
ICE_NETLIST_ID_BLK_SIZE, length); return -EIO;
}
status = ice_read_netlist_module(hw, bank, ICE_LINK_TOPO_NODE_COUNT, &node_count); if (status) return status;
node_count &= ICE_LINK_TOPO_NODE_COUNT_M;
id_blk = kcalloc(ICE_NETLIST_ID_BLK_SIZE, sizeof(*id_blk), GFP_KERNEL); if (!id_blk) return -ENOMEM;
/* Read out the entire Netlist ID Block at once. */
status = ice_read_flash_module(hw, bank, ICE_SR_NETLIST_BANK_PTR,
ICE_NETLIST_ID_BLK_OFFSET(node_count) * sizeof(u16),
(u8 *)id_blk, ICE_NETLIST_ID_BLK_SIZE * sizeof(u16)); if (status) goto exit_error;
for (i = 0; i < ICE_NETLIST_ID_BLK_SIZE; i++)
id_blk[i] = le16_to_cpu(((__force __le16 *)id_blk)[i]);
status = ice_read_sr_word(hw, offset, &value); if (status) return status;
/* Determine if the pointer is in 4KB or word units */ if (value & ICE_SR_NVM_PTR_4KB_UNITS)
*pointer = (value & ~ICE_SR_NVM_PTR_4KB_UNITS) * 4 * 1024; else
*pointer = value * 2;
status = ice_read_sr_word(hw, ICE_SR_NVM_CTRL_WORD, &ctrl_word); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read the Shadow RAM control word\n"); return status;
}
/* Check that the control word indicates validity */ if (FIELD_GET(ICE_SR_CTRL_WORD_1_M, ctrl_word) !=
ICE_SR_CTRL_WORD_VALID) {
ice_debug(hw, ICE_DBG_NVM, "Shadow RAM control word is invalid\n"); return -EIO;
}
status = ice_read_sr_pointer(hw, ICE_SR_1ST_NVM_BANK_PTR, &banks->nvm_ptr); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read NVM bank pointer\n"); return status;
}
status = ice_read_sr_area_size(hw, ICE_SR_NVM_BANK_SIZE, &banks->nvm_size); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read NVM bank area size\n"); return status;
}
status = ice_read_sr_pointer(hw, ICE_SR_1ST_OROM_BANK_PTR, &banks->orom_ptr); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read OROM bank pointer\n"); return status;
}
status = ice_read_sr_area_size(hw, ICE_SR_OROM_BANK_SIZE, &banks->orom_size); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read OROM bank area size\n"); return status;
}
status = ice_read_sr_pointer(hw, ICE_SR_NETLIST_BANK_PTR, &banks->netlist_ptr); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read Netlist bank pointer\n"); return status;
}
status = ice_read_sr_area_size(hw, ICE_SR_NETLIST_BANK_SIZE, &banks->netlist_size); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to read Netlist bank area size\n"); return status;
}
status = ice_read_nvm_module(hw, bank, ICE_NVM_CSS_HDR_LEN_L,
&hdr_len_l); if (status) return status;
status = ice_read_nvm_module(hw, bank, ICE_NVM_CSS_HDR_LEN_H,
&hdr_len_h); if (status) return status;
/* CSS header length is in DWORD, so convert to words and add *authenticationheadersize
*/
hdr_len_dword = hdr_len_h << 16 | hdr_len_l;
*hdr_len = (hdr_len_dword * 2) + ICE_NVM_AUTH_HEADER_LEN;
/* The SR size is stored regardless of the NVM programming mode *astheblankmodemaybeusedinthefactoryline.
*/
gens_stat = rd32(hw, GLNVM_GENS);
sr_size = FIELD_GET(GLNVM_GENS_SR_SIZE_M, gens_stat);
/* Switching to words (sr_size contains power of 2) */
flash->sr_words = BIT(sr_size) * ICE_SR_WORDS_IN_1KB;
/* Check if we are in the normal or blank NVM programming mode */
fla = rd32(hw, GLNVM_FLA); if (fla & GLNVM_FLA_LOCKED_M) { /* Normal programming mode */
flash->blank_nvm_mode = false;
} else { /* Blank programming mode */
flash->blank_nvm_mode = true;
ice_debug(hw, ICE_DBG_NVM, "NVM init error: unsupported blank mode.\n"); return -EIO;
}
status = ice_discover_flash_size(hw); if (status) {
ice_debug(hw, ICE_DBG_NVM, "NVM init error: failed to discover flash size.\n"); return status;
}
status = ice_determine_active_flash_banks(hw); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to determine active flash banks.\n"); return status;
}
status = ice_determine_css_hdr_len(hw); if (status) {
ice_debug(hw, ICE_DBG_NVM, "Failed to determine Shadow RAM copy offsets.\n"); return status;
}
status = ice_get_nvm_ver_info(hw, ICE_ACTIVE_FLASH_BANK, &flash->nvm); if (status) {
ice_debug(hw, ICE_DBG_INIT, "Failed to read NVM info.\n"); return status;
}
status = ice_get_orom_ver_info(hw, ICE_ACTIVE_FLASH_BANK, &flash->orom); if (status)
ice_debug(hw, ICE_DBG_INIT, "Failed to read Option ROM info.\n");
/* read the netlist version information */
status = ice_get_netlist_info(hw, ICE_ACTIVE_FLASH_BANK, &flash->netlist); if (status)
ice_debug(hw, ICE_DBG_INIT, "Failed to read netlist info.\n");
return0;
}
/** *ice_nvm_validate_checksum *@hw:pointertotheHWstruct * *VerifyNVMPFAchecksumvalidity(0x0706)
*/ int ice_nvm_validate_checksum(struct ice_hw *hw)
{ struct ice_aqc_nvm_checksum *cmd; struct libie_aq_desc desc; int status;
status = ice_acquire_nvm(hw, ICE_RES_READ); if (status) return status;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.