62 #include <linux/types.h>
63 #include <linux/slab.h>
64 #include <linux/export.h>
80 #define IWL_EEPROM_ACCESS_TIMEOUT 5000
82 #define IWL_EEPROM_SEM_TIMEOUT 10
83 #define IWL_EEPROM_SEM_RETRY_LIMIT 1000
93 #define EEPROM_SEM_TIMEOUT 10
94 #define EEPROM_SEM_RETRY_LIMIT 1000
113 "Acquired semaphore after %d tries.\n",
128 static int iwl_eeprom_verify_signature(
struct iwl_trans *
trans,
bool nvm_is_otp)
137 IWL_ERR(trans,
"EEPROM with bad signature: 0x%08x\n",
145 IWL_ERR(trans,
"OTP with bad signature: 0x%08x\n", gp);
152 "bad EEPROM/OTP signature, type=%s, EEPROM_GP=0x%08x\n",
153 nvm_is_otp ?
"OTP" :
"EEPROM", gp);
164 static void iwl_set_otp_access_absolute(
struct iwl_trans *trans)
172 static int iwl_nvm_is_otp(
struct iwl_trans *trans)
179 IWL_ERR(trans,
"Unknown hardware type\n");
194 static int iwl_init_otp_access(
struct iwl_trans *trans)
209 IWL_ERR(trans,
"Time out access OTP\n");
221 if (trans->
cfg->base_params->shadow_ram_support)
242 IWL_ERR(trans,
"Time out reading OTP[%d]\n", addr);
252 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
253 IWL_ERR(trans,
"Uncorrectable OTP ECC error, abort OTP read\n");
260 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
261 IWL_ERR(trans,
"Correctable OTP ECC error, continue read\n");
270 static bool iwl_is_otp_empty(
struct iwl_trans *trans)
272 u16 next_link_addr = 0;
274 bool is_empty =
false;
277 if (!iwl_read_otp_word(trans, next_link_addr, &link_value)) {
279 IWL_ERR(trans,
"OTP is empty\n");
283 IWL_ERR(trans,
"Unable to read first block of OTP list.\n");
300 static int iwl_find_otp_image(
struct iwl_trans *trans,
303 u16 next_link_addr = 0, valid_addr;
308 iwl_set_otp_access_absolute(trans);
311 if (iwl_is_otp_empty(trans))
323 valid_addr = next_link_addr;
326 usedblocks, next_link_addr);
327 if (iwl_read_otp_word(trans, next_link_addr, &link_value))
335 *validblockaddr = valid_addr;
337 *validblockaddr += 2;
342 }
while (usedblocks <= trans->
cfg->base_params->max_ll_items);
364 u16 validblockaddr = 0;
368 if (!eeprom || !eeprom_size)
371 nvm_is_otp = iwl_nvm_is_otp(trans);
375 sz = trans->
cfg->base_params->eeprom_size;
382 ret = iwl_eeprom_verify_signature(trans, nvm_is_otp);
384 IWL_ERR(trans,
"EEPROM not found, EEPROM_GP=0x%08x\n", gp);
389 ret = iwl_eeprom_acquire_semaphore(trans);
391 IWL_ERR(trans,
"Failed to acquire EEPROM semaphore.\n");
396 ret = iwl_init_otp_access(trans);
398 IWL_ERR(trans,
"Failed to initialize OTP access.\n");
408 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
410 if (!trans->
cfg->base_params->shadow_ram_support) {
411 ret = iwl_find_otp_image(trans, &validblockaddr);
415 for (addr = validblockaddr; addr < validblockaddr + sz;
416 addr +=
sizeof(
u16)) {
419 ret = iwl_read_otp_word(trans, addr, &eeprom_data);
422 e[cache_addr / 2] = eeprom_data;
423 cache_addr +=
sizeof(
u16);
427 for (addr = 0; addr < sz; addr +=
sizeof(
u16)) {
439 "Time out reading EEPROM[%d]\n", addr);
448 nvm_is_otp ?
"OTP" :
"EEPROM");
450 iwl_eeprom_release_semaphore(trans);
457 iwl_eeprom_release_semaphore(trans);