e1000_i210.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-2013 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. ******************************************************************************/
  20. /* e1000_i210
  21. * e1000_i211
  22. */
  23. #include <linux/types.h>
  24. #include <linux/if_ether.h>
  25. #include "e1000_hw.h"
  26. #include "e1000_i210.h"
  27. /**
  28. * igb_get_hw_semaphore_i210 - Acquire hardware semaphore
  29. * @hw: pointer to the HW structure
  30. *
  31. * Acquire the HW semaphore to access the PHY or NVM
  32. */
  33. static s32 igb_get_hw_semaphore_i210(struct e1000_hw *hw)
  34. {
  35. u32 swsm;
  36. s32 ret_val = E1000_SUCCESS;
  37. s32 timeout = hw->nvm.word_size + 1;
  38. s32 i = 0;
  39. /* Get the FW semaphore. */
  40. for (i = 0; i < timeout; i++) {
  41. swsm = rd32(E1000_SWSM);
  42. wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
  43. /* Semaphore acquired if bit latched */
  44. if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
  45. break;
  46. udelay(50);
  47. }
  48. if (i == timeout) {
  49. /* Release semaphores */
  50. igb_put_hw_semaphore(hw);
  51. hw_dbg("Driver can't access the NVM\n");
  52. ret_val = -E1000_ERR_NVM;
  53. goto out;
  54. }
  55. out:
  56. return ret_val;
  57. }
  58. /**
  59. * igb_acquire_nvm_i210 - Request for access to EEPROM
  60. * @hw: pointer to the HW structure
  61. *
  62. * Acquire the necessary semaphores for exclusive access to the EEPROM.
  63. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  64. * Return successful if access grant bit set, else clear the request for
  65. * EEPROM access and return -E1000_ERR_NVM (-1).
  66. **/
  67. s32 igb_acquire_nvm_i210(struct e1000_hw *hw)
  68. {
  69. return igb_acquire_swfw_sync_i210(hw, E1000_SWFW_EEP_SM);
  70. }
  71. /**
  72. * igb_release_nvm_i210 - Release exclusive access to EEPROM
  73. * @hw: pointer to the HW structure
  74. *
  75. * Stop any current commands to the EEPROM and clear the EEPROM request bit,
  76. * then release the semaphores acquired.
  77. **/
  78. void igb_release_nvm_i210(struct e1000_hw *hw)
  79. {
  80. igb_release_swfw_sync_i210(hw, E1000_SWFW_EEP_SM);
  81. }
  82. /**
  83. * igb_put_hw_semaphore_i210 - Release hardware semaphore
  84. * @hw: pointer to the HW structure
  85. *
  86. * Release hardware semaphore used to access the PHY or NVM
  87. */
  88. static void igb_put_hw_semaphore_i210(struct e1000_hw *hw)
  89. {
  90. u32 swsm;
  91. swsm = rd32(E1000_SWSM);
  92. swsm &= ~E1000_SWSM_SWESMBI;
  93. wr32(E1000_SWSM, swsm);
  94. }
  95. /**
  96. * igb_acquire_swfw_sync_i210 - Acquire SW/FW semaphore
  97. * @hw: pointer to the HW structure
  98. * @mask: specifies which semaphore to acquire
  99. *
  100. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  101. * will also specify which port we're acquiring the lock for.
  102. **/
  103. s32 igb_acquire_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
  104. {
  105. u32 swfw_sync;
  106. u32 swmask = mask;
  107. u32 fwmask = mask << 16;
  108. s32 ret_val = E1000_SUCCESS;
  109. s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
  110. while (i < timeout) {
  111. if (igb_get_hw_semaphore_i210(hw)) {
  112. ret_val = -E1000_ERR_SWFW_SYNC;
  113. goto out;
  114. }
  115. swfw_sync = rd32(E1000_SW_FW_SYNC);
  116. if (!(swfw_sync & fwmask))
  117. break;
  118. /*
  119. * Firmware currently using resource (fwmask)
  120. */
  121. igb_put_hw_semaphore_i210(hw);
  122. mdelay(5);
  123. i++;
  124. }
  125. if (i == timeout) {
  126. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  127. ret_val = -E1000_ERR_SWFW_SYNC;
  128. goto out;
  129. }
  130. swfw_sync |= swmask;
  131. wr32(E1000_SW_FW_SYNC, swfw_sync);
  132. igb_put_hw_semaphore_i210(hw);
  133. out:
  134. return ret_val;
  135. }
  136. /**
  137. * igb_release_swfw_sync_i210 - Release SW/FW semaphore
  138. * @hw: pointer to the HW structure
  139. * @mask: specifies which semaphore to acquire
  140. *
  141. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  142. * will also specify which port we're releasing the lock for.
  143. **/
  144. void igb_release_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
  145. {
  146. u32 swfw_sync;
  147. while (igb_get_hw_semaphore_i210(hw) != E1000_SUCCESS)
  148. ; /* Empty */
  149. swfw_sync = rd32(E1000_SW_FW_SYNC);
  150. swfw_sync &= ~mask;
  151. wr32(E1000_SW_FW_SYNC, swfw_sync);
  152. igb_put_hw_semaphore_i210(hw);
  153. }
  154. /**
  155. * igb_read_nvm_srrd_i210 - Reads Shadow Ram using EERD register
  156. * @hw: pointer to the HW structure
  157. * @offset: offset of word in the Shadow Ram to read
  158. * @words: number of words to read
  159. * @data: word read from the Shadow Ram
  160. *
  161. * Reads a 16 bit word from the Shadow Ram using the EERD register.
  162. * Uses necessary synchronization semaphores.
  163. **/
  164. s32 igb_read_nvm_srrd_i210(struct e1000_hw *hw, u16 offset, u16 words,
  165. u16 *data)
  166. {
  167. s32 status = E1000_SUCCESS;
  168. u16 i, count;
  169. /* We cannot hold synchronization semaphores for too long,
  170. * because of forceful takeover procedure. However it is more efficient
  171. * to read in bursts than synchronizing access for each word. */
  172. for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
  173. count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
  174. E1000_EERD_EEWR_MAX_COUNT : (words - i);
  175. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  176. status = igb_read_nvm_eerd(hw, offset, count,
  177. data + i);
  178. hw->nvm.ops.release(hw);
  179. } else {
  180. status = E1000_ERR_SWFW_SYNC;
  181. }
  182. if (status != E1000_SUCCESS)
  183. break;
  184. }
  185. return status;
  186. }
  187. /**
  188. * igb_write_nvm_srwr - Write to Shadow Ram using EEWR
  189. * @hw: pointer to the HW structure
  190. * @offset: offset within the Shadow Ram to be written to
  191. * @words: number of words to write
  192. * @data: 16 bit word(s) to be written to the Shadow Ram
  193. *
  194. * Writes data to Shadow Ram at offset using EEWR register.
  195. *
  196. * If igb_update_nvm_checksum is not called after this function , the
  197. * Shadow Ram will most likely contain an invalid checksum.
  198. **/
  199. static s32 igb_write_nvm_srwr(struct e1000_hw *hw, u16 offset, u16 words,
  200. u16 *data)
  201. {
  202. struct e1000_nvm_info *nvm = &hw->nvm;
  203. u32 i, k, eewr = 0;
  204. u32 attempts = 100000;
  205. s32 ret_val = E1000_SUCCESS;
  206. /*
  207. * A check for invalid values: offset too large, too many words,
  208. * too many words for the offset, and not enough words.
  209. */
  210. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  211. (words == 0)) {
  212. hw_dbg("nvm parameter(s) out of bounds\n");
  213. ret_val = -E1000_ERR_NVM;
  214. goto out;
  215. }
  216. for (i = 0; i < words; i++) {
  217. eewr = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
  218. (data[i] << E1000_NVM_RW_REG_DATA) |
  219. E1000_NVM_RW_REG_START;
  220. wr32(E1000_SRWR, eewr);
  221. for (k = 0; k < attempts; k++) {
  222. if (E1000_NVM_RW_REG_DONE &
  223. rd32(E1000_SRWR)) {
  224. ret_val = E1000_SUCCESS;
  225. break;
  226. }
  227. udelay(5);
  228. }
  229. if (ret_val != E1000_SUCCESS) {
  230. hw_dbg("Shadow RAM write EEWR timed out\n");
  231. break;
  232. }
  233. }
  234. out:
  235. return ret_val;
  236. }
  237. /**
  238. * igb_write_nvm_srwr_i210 - Write to Shadow RAM using EEWR
  239. * @hw: pointer to the HW structure
  240. * @offset: offset within the Shadow RAM to be written to
  241. * @words: number of words to write
  242. * @data: 16 bit word(s) to be written to the Shadow RAM
  243. *
  244. * Writes data to Shadow RAM at offset using EEWR register.
  245. *
  246. * If e1000_update_nvm_checksum is not called after this function , the
  247. * data will not be committed to FLASH and also Shadow RAM will most likely
  248. * contain an invalid checksum.
  249. *
  250. * If error code is returned, data and Shadow RAM may be inconsistent - buffer
  251. * partially written.
  252. */
  253. s32 igb_write_nvm_srwr_i210(struct e1000_hw *hw, u16 offset, u16 words,
  254. u16 *data)
  255. {
  256. s32 status = E1000_SUCCESS;
  257. u16 i, count;
  258. /* We cannot hold synchronization semaphores for too long,
  259. * because of forceful takeover procedure. However it is more efficient
  260. * to write in bursts than synchronizing access for each word.
  261. */
  262. for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
  263. count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
  264. E1000_EERD_EEWR_MAX_COUNT : (words - i);
  265. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  266. status = igb_write_nvm_srwr(hw, offset, count,
  267. data + i);
  268. hw->nvm.ops.release(hw);
  269. } else {
  270. status = E1000_ERR_SWFW_SYNC;
  271. }
  272. if (status != E1000_SUCCESS)
  273. break;
  274. }
  275. return status;
  276. }
  277. /**
  278. * igb_read_nvm_i211 - Read NVM wrapper function for I211
  279. * @hw: pointer to the HW structure
  280. * @address: the word address (aka eeprom offset) to read
  281. * @data: pointer to the data read
  282. *
  283. * Wrapper function to return data formerly found in the NVM.
  284. **/
  285. s32 igb_read_nvm_i211(struct e1000_hw *hw, u16 offset, u16 words,
  286. u16 *data)
  287. {
  288. s32 ret_val = E1000_SUCCESS;
  289. /* Only the MAC addr is required to be present in the iNVM */
  290. switch (offset) {
  291. case NVM_MAC_ADDR:
  292. ret_val = igb_read_invm_i211(hw, offset, &data[0]);
  293. ret_val |= igb_read_invm_i211(hw, offset+1, &data[1]);
  294. ret_val |= igb_read_invm_i211(hw, offset+2, &data[2]);
  295. if (ret_val != E1000_SUCCESS)
  296. hw_dbg("MAC Addr not found in iNVM\n");
  297. break;
  298. case NVM_INIT_CTRL_2:
  299. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  300. if (ret_val != E1000_SUCCESS) {
  301. *data = NVM_INIT_CTRL_2_DEFAULT_I211;
  302. ret_val = E1000_SUCCESS;
  303. }
  304. break;
  305. case NVM_INIT_CTRL_4:
  306. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  307. if (ret_val != E1000_SUCCESS) {
  308. *data = NVM_INIT_CTRL_4_DEFAULT_I211;
  309. ret_val = E1000_SUCCESS;
  310. }
  311. break;
  312. case NVM_LED_1_CFG:
  313. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  314. if (ret_val != E1000_SUCCESS) {
  315. *data = NVM_LED_1_CFG_DEFAULT_I211;
  316. ret_val = E1000_SUCCESS;
  317. }
  318. break;
  319. case NVM_LED_0_2_CFG:
  320. igb_read_invm_i211(hw, offset, data);
  321. if (ret_val != E1000_SUCCESS) {
  322. *data = NVM_LED_0_2_CFG_DEFAULT_I211;
  323. ret_val = E1000_SUCCESS;
  324. }
  325. break;
  326. case NVM_ID_LED_SETTINGS:
  327. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  328. if (ret_val != E1000_SUCCESS) {
  329. *data = ID_LED_RESERVED_FFFF;
  330. ret_val = E1000_SUCCESS;
  331. }
  332. case NVM_SUB_DEV_ID:
  333. *data = hw->subsystem_device_id;
  334. break;
  335. case NVM_SUB_VEN_ID:
  336. *data = hw->subsystem_vendor_id;
  337. break;
  338. case NVM_DEV_ID:
  339. *data = hw->device_id;
  340. break;
  341. case NVM_VEN_ID:
  342. *data = hw->vendor_id;
  343. break;
  344. default:
  345. hw_dbg("NVM word 0x%02x is not mapped.\n", offset);
  346. *data = NVM_RESERVED_WORD;
  347. break;
  348. }
  349. return ret_val;
  350. }
  351. /**
  352. * igb_read_invm_i211 - Reads OTP
  353. * @hw: pointer to the HW structure
  354. * @address: the word address (aka eeprom offset) to read
  355. * @data: pointer to the data read
  356. *
  357. * Reads 16-bit words from the OTP. Return error when the word is not
  358. * stored in OTP.
  359. **/
  360. s32 igb_read_invm_i211(struct e1000_hw *hw, u16 address, u16 *data)
  361. {
  362. s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
  363. u32 invm_dword;
  364. u16 i;
  365. u8 record_type, word_address;
  366. for (i = 0; i < E1000_INVM_SIZE; i++) {
  367. invm_dword = rd32(E1000_INVM_DATA_REG(i));
  368. /* Get record type */
  369. record_type = INVM_DWORD_TO_RECORD_TYPE(invm_dword);
  370. if (record_type == E1000_INVM_UNINITIALIZED_STRUCTURE)
  371. break;
  372. if (record_type == E1000_INVM_CSR_AUTOLOAD_STRUCTURE)
  373. i += E1000_INVM_CSR_AUTOLOAD_DATA_SIZE_IN_DWORDS;
  374. if (record_type == E1000_INVM_RSA_KEY_SHA256_STRUCTURE)
  375. i += E1000_INVM_RSA_KEY_SHA256_DATA_SIZE_IN_DWORDS;
  376. if (record_type == E1000_INVM_WORD_AUTOLOAD_STRUCTURE) {
  377. word_address = INVM_DWORD_TO_WORD_ADDRESS(invm_dword);
  378. if (word_address == (u8)address) {
  379. *data = INVM_DWORD_TO_WORD_DATA(invm_dword);
  380. hw_dbg("Read INVM Word 0x%02x = %x",
  381. address, *data);
  382. status = E1000_SUCCESS;
  383. break;
  384. }
  385. }
  386. }
  387. if (status != E1000_SUCCESS)
  388. hw_dbg("Requested word 0x%02x not found in OTP\n", address);
  389. return status;
  390. }
  391. /**
  392. * igb_read_invm_version - Reads iNVM version and image type
  393. * @hw: pointer to the HW structure
  394. * @invm_ver: version structure for the version read
  395. *
  396. * Reads iNVM version and image type.
  397. **/
  398. s32 igb_read_invm_version(struct e1000_hw *hw,
  399. struct e1000_fw_version *invm_ver) {
  400. u32 *record = NULL;
  401. u32 *next_record = NULL;
  402. u32 i = 0;
  403. u32 invm_dword = 0;
  404. u32 invm_blocks = E1000_INVM_SIZE - (E1000_INVM_ULT_BYTES_SIZE /
  405. E1000_INVM_RECORD_SIZE_IN_BYTES);
  406. u32 buffer[E1000_INVM_SIZE];
  407. s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
  408. u16 version = 0;
  409. /* Read iNVM memory */
  410. for (i = 0; i < E1000_INVM_SIZE; i++) {
  411. invm_dword = rd32(E1000_INVM_DATA_REG(i));
  412. buffer[i] = invm_dword;
  413. }
  414. /* Read version number */
  415. for (i = 1; i < invm_blocks; i++) {
  416. record = &buffer[invm_blocks - i];
  417. next_record = &buffer[invm_blocks - i + 1];
  418. /* Check if we have first version location used */
  419. if ((i == 1) && ((*record & E1000_INVM_VER_FIELD_ONE) == 0)) {
  420. version = 0;
  421. status = E1000_SUCCESS;
  422. break;
  423. }
  424. /* Check if we have second version location used */
  425. else if ((i == 1) &&
  426. ((*record & E1000_INVM_VER_FIELD_TWO) == 0)) {
  427. version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
  428. status = E1000_SUCCESS;
  429. break;
  430. }
  431. /* Check if we have odd version location
  432. * used and it is the last one used
  433. */
  434. else if ((((*record & E1000_INVM_VER_FIELD_ONE) == 0) &&
  435. ((*record & 0x3) == 0)) || (((*record & 0x3) != 0) &&
  436. (i != 1))) {
  437. version = (*next_record & E1000_INVM_VER_FIELD_TWO)
  438. >> 13;
  439. status = E1000_SUCCESS;
  440. break;
  441. }
  442. /* Check if we have even version location
  443. * used and it is the last one used
  444. */
  445. else if (((*record & E1000_INVM_VER_FIELD_TWO) == 0) &&
  446. ((*record & 0x3) == 0)) {
  447. version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
  448. status = E1000_SUCCESS;
  449. break;
  450. }
  451. }
  452. if (status == E1000_SUCCESS) {
  453. invm_ver->invm_major = (version & E1000_INVM_MAJOR_MASK)
  454. >> E1000_INVM_MAJOR_SHIFT;
  455. invm_ver->invm_minor = version & E1000_INVM_MINOR_MASK;
  456. }
  457. /* Read Image Type */
  458. for (i = 1; i < invm_blocks; i++) {
  459. record = &buffer[invm_blocks - i];
  460. next_record = &buffer[invm_blocks - i + 1];
  461. /* Check if we have image type in first location used */
  462. if ((i == 1) && ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) {
  463. invm_ver->invm_img_type = 0;
  464. status = E1000_SUCCESS;
  465. break;
  466. }
  467. /* Check if we have image type in first location used */
  468. else if ((((*record & 0x3) == 0) &&
  469. ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) ||
  470. ((((*record & 0x3) != 0) && (i != 1)))) {
  471. invm_ver->invm_img_type =
  472. (*next_record & E1000_INVM_IMGTYPE_FIELD) >> 23;
  473. status = E1000_SUCCESS;
  474. break;
  475. }
  476. }
  477. return status;
  478. }
  479. /**
  480. * igb_validate_nvm_checksum_i210 - Validate EEPROM checksum
  481. * @hw: pointer to the HW structure
  482. *
  483. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  484. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  485. **/
  486. s32 igb_validate_nvm_checksum_i210(struct e1000_hw *hw)
  487. {
  488. s32 status = E1000_SUCCESS;
  489. s32 (*read_op_ptr)(struct e1000_hw *, u16, u16, u16 *);
  490. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  491. /*
  492. * Replace the read function with semaphore grabbing with
  493. * the one that skips this for a while.
  494. * We have semaphore taken already here.
  495. */
  496. read_op_ptr = hw->nvm.ops.read;
  497. hw->nvm.ops.read = igb_read_nvm_eerd;
  498. status = igb_validate_nvm_checksum(hw);
  499. /* Revert original read operation. */
  500. hw->nvm.ops.read = read_op_ptr;
  501. hw->nvm.ops.release(hw);
  502. } else {
  503. status = E1000_ERR_SWFW_SYNC;
  504. }
  505. return status;
  506. }
  507. /**
  508. * igb_update_nvm_checksum_i210 - Update EEPROM checksum
  509. * @hw: pointer to the HW structure
  510. *
  511. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  512. * up to the checksum. Then calculates the EEPROM checksum and writes the
  513. * value to the EEPROM. Next commit EEPROM data onto the Flash.
  514. **/
  515. s32 igb_update_nvm_checksum_i210(struct e1000_hw *hw)
  516. {
  517. s32 ret_val = E1000_SUCCESS;
  518. u16 checksum = 0;
  519. u16 i, nvm_data;
  520. /*
  521. * Read the first word from the EEPROM. If this times out or fails, do
  522. * not continue or we could be in for a very long wait while every
  523. * EEPROM read fails
  524. */
  525. ret_val = igb_read_nvm_eerd(hw, 0, 1, &nvm_data);
  526. if (ret_val != E1000_SUCCESS) {
  527. hw_dbg("EEPROM read failed\n");
  528. goto out;
  529. }
  530. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  531. /*
  532. * Do not use hw->nvm.ops.write, hw->nvm.ops.read
  533. * because we do not want to take the synchronization
  534. * semaphores twice here.
  535. */
  536. for (i = 0; i < NVM_CHECKSUM_REG; i++) {
  537. ret_val = igb_read_nvm_eerd(hw, i, 1, &nvm_data);
  538. if (ret_val) {
  539. hw->nvm.ops.release(hw);
  540. hw_dbg("NVM Read Error while updating checksum.\n");
  541. goto out;
  542. }
  543. checksum += nvm_data;
  544. }
  545. checksum = (u16) NVM_SUM - checksum;
  546. ret_val = igb_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
  547. &checksum);
  548. if (ret_val != E1000_SUCCESS) {
  549. hw->nvm.ops.release(hw);
  550. hw_dbg("NVM Write Error while updating checksum.\n");
  551. goto out;
  552. }
  553. hw->nvm.ops.release(hw);
  554. ret_val = igb_update_flash_i210(hw);
  555. } else {
  556. ret_val = -E1000_ERR_SWFW_SYNC;
  557. }
  558. out:
  559. return ret_val;
  560. }
  561. /**
  562. * igb_pool_flash_update_done_i210 - Pool FLUDONE status.
  563. * @hw: pointer to the HW structure
  564. *
  565. */
  566. static s32 igb_pool_flash_update_done_i210(struct e1000_hw *hw)
  567. {
  568. s32 ret_val = -E1000_ERR_NVM;
  569. u32 i, reg;
  570. for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
  571. reg = rd32(E1000_EECD);
  572. if (reg & E1000_EECD_FLUDONE_I210) {
  573. ret_val = E1000_SUCCESS;
  574. break;
  575. }
  576. udelay(5);
  577. }
  578. return ret_val;
  579. }
  580. /**
  581. * igb_update_flash_i210 - Commit EEPROM to the flash
  582. * @hw: pointer to the HW structure
  583. *
  584. **/
  585. s32 igb_update_flash_i210(struct e1000_hw *hw)
  586. {
  587. s32 ret_val = E1000_SUCCESS;
  588. u32 flup;
  589. ret_val = igb_pool_flash_update_done_i210(hw);
  590. if (ret_val == -E1000_ERR_NVM) {
  591. hw_dbg("Flash update time out\n");
  592. goto out;
  593. }
  594. flup = rd32(E1000_EECD) | E1000_EECD_FLUPD_I210;
  595. wr32(E1000_EECD, flup);
  596. ret_val = igb_pool_flash_update_done_i210(hw);
  597. if (ret_val == E1000_SUCCESS)
  598. hw_dbg("Flash update complete\n");
  599. else
  600. hw_dbg("Flash update time out\n");
  601. out:
  602. return ret_val;
  603. }
  604. /**
  605. * igb_valid_led_default_i210 - Verify a valid default LED config
  606. * @hw: pointer to the HW structure
  607. * @data: pointer to the NVM (EEPROM)
  608. *
  609. * Read the EEPROM for the current default LED configuration. If the
  610. * LED configuration is not valid, set to a valid LED configuration.
  611. **/
  612. s32 igb_valid_led_default_i210(struct e1000_hw *hw, u16 *data)
  613. {
  614. s32 ret_val;
  615. ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
  616. if (ret_val) {
  617. hw_dbg("NVM Read Error\n");
  618. goto out;
  619. }
  620. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
  621. switch (hw->phy.media_type) {
  622. case e1000_media_type_internal_serdes:
  623. *data = ID_LED_DEFAULT_I210_SERDES;
  624. break;
  625. case e1000_media_type_copper:
  626. default:
  627. *data = ID_LED_DEFAULT_I210;
  628. break;
  629. }
  630. }
  631. out:
  632. return ret_val;
  633. }