e1000_i210.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. /* Firmware currently using resource (fwmask) */
  119. igb_put_hw_semaphore_i210(hw);
  120. mdelay(5);
  121. i++;
  122. }
  123. if (i == timeout) {
  124. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  125. ret_val = -E1000_ERR_SWFW_SYNC;
  126. goto out;
  127. }
  128. swfw_sync |= swmask;
  129. wr32(E1000_SW_FW_SYNC, swfw_sync);
  130. igb_put_hw_semaphore_i210(hw);
  131. out:
  132. return ret_val;
  133. }
  134. /**
  135. * igb_release_swfw_sync_i210 - Release SW/FW semaphore
  136. * @hw: pointer to the HW structure
  137. * @mask: specifies which semaphore to acquire
  138. *
  139. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  140. * will also specify which port we're releasing the lock for.
  141. **/
  142. void igb_release_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
  143. {
  144. u32 swfw_sync;
  145. while (igb_get_hw_semaphore_i210(hw) != E1000_SUCCESS)
  146. ; /* Empty */
  147. swfw_sync = rd32(E1000_SW_FW_SYNC);
  148. swfw_sync &= ~mask;
  149. wr32(E1000_SW_FW_SYNC, swfw_sync);
  150. igb_put_hw_semaphore_i210(hw);
  151. }
  152. /**
  153. * igb_read_nvm_srrd_i210 - Reads Shadow Ram using EERD register
  154. * @hw: pointer to the HW structure
  155. * @offset: offset of word in the Shadow Ram to read
  156. * @words: number of words to read
  157. * @data: word read from the Shadow Ram
  158. *
  159. * Reads a 16 bit word from the Shadow Ram using the EERD register.
  160. * Uses necessary synchronization semaphores.
  161. **/
  162. s32 igb_read_nvm_srrd_i210(struct e1000_hw *hw, u16 offset, u16 words,
  163. u16 *data)
  164. {
  165. s32 status = E1000_SUCCESS;
  166. u16 i, count;
  167. /* We cannot hold synchronization semaphores for too long,
  168. * because of forceful takeover procedure. However it is more efficient
  169. * to read in bursts than synchronizing access for each word.
  170. */
  171. for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
  172. count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
  173. E1000_EERD_EEWR_MAX_COUNT : (words - i);
  174. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  175. status = igb_read_nvm_eerd(hw, offset, count,
  176. data + i);
  177. hw->nvm.ops.release(hw);
  178. } else {
  179. status = E1000_ERR_SWFW_SYNC;
  180. }
  181. if (status != E1000_SUCCESS)
  182. break;
  183. }
  184. return status;
  185. }
  186. /**
  187. * igb_write_nvm_srwr - Write to Shadow Ram using EEWR
  188. * @hw: pointer to the HW structure
  189. * @offset: offset within the Shadow Ram to be written to
  190. * @words: number of words to write
  191. * @data: 16 bit word(s) to be written to the Shadow Ram
  192. *
  193. * Writes data to Shadow Ram at offset using EEWR register.
  194. *
  195. * If igb_update_nvm_checksum is not called after this function , the
  196. * Shadow Ram will most likely contain an invalid checksum.
  197. **/
  198. static s32 igb_write_nvm_srwr(struct e1000_hw *hw, u16 offset, u16 words,
  199. u16 *data)
  200. {
  201. struct e1000_nvm_info *nvm = &hw->nvm;
  202. u32 i, k, eewr = 0;
  203. u32 attempts = 100000;
  204. s32 ret_val = E1000_SUCCESS;
  205. /* A check for invalid values: offset too large, too many words,
  206. * too many words for the offset, and not enough words.
  207. */
  208. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  209. (words == 0)) {
  210. hw_dbg("nvm parameter(s) out of bounds\n");
  211. ret_val = -E1000_ERR_NVM;
  212. goto out;
  213. }
  214. for (i = 0; i < words; i++) {
  215. eewr = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
  216. (data[i] << E1000_NVM_RW_REG_DATA) |
  217. E1000_NVM_RW_REG_START;
  218. wr32(E1000_SRWR, eewr);
  219. for (k = 0; k < attempts; k++) {
  220. if (E1000_NVM_RW_REG_DONE &
  221. rd32(E1000_SRWR)) {
  222. ret_val = E1000_SUCCESS;
  223. break;
  224. }
  225. udelay(5);
  226. }
  227. if (ret_val != E1000_SUCCESS) {
  228. hw_dbg("Shadow RAM write EEWR timed out\n");
  229. break;
  230. }
  231. }
  232. out:
  233. return ret_val;
  234. }
  235. /**
  236. * igb_write_nvm_srwr_i210 - Write to Shadow RAM using EEWR
  237. * @hw: pointer to the HW structure
  238. * @offset: offset within the Shadow RAM to be written to
  239. * @words: number of words to write
  240. * @data: 16 bit word(s) to be written to the Shadow RAM
  241. *
  242. * Writes data to Shadow RAM at offset using EEWR register.
  243. *
  244. * If e1000_update_nvm_checksum is not called after this function , the
  245. * data will not be committed to FLASH and also Shadow RAM will most likely
  246. * contain an invalid checksum.
  247. *
  248. * If error code is returned, data and Shadow RAM may be inconsistent - buffer
  249. * partially written.
  250. **/
  251. s32 igb_write_nvm_srwr_i210(struct e1000_hw *hw, u16 offset, u16 words,
  252. u16 *data)
  253. {
  254. s32 status = E1000_SUCCESS;
  255. u16 i, count;
  256. /* We cannot hold synchronization semaphores for too long,
  257. * because of forceful takeover procedure. However it is more efficient
  258. * to write in bursts than synchronizing access for each word.
  259. */
  260. for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
  261. count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
  262. E1000_EERD_EEWR_MAX_COUNT : (words - i);
  263. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  264. status = igb_write_nvm_srwr(hw, offset, count,
  265. data + i);
  266. hw->nvm.ops.release(hw);
  267. } else {
  268. status = E1000_ERR_SWFW_SYNC;
  269. }
  270. if (status != E1000_SUCCESS)
  271. break;
  272. }
  273. return status;
  274. }
  275. /**
  276. * igb_read_nvm_i211 - Read NVM wrapper function for I211
  277. * @hw: pointer to the HW structure
  278. * @words: number of words to read
  279. * @data: pointer to the data read
  280. *
  281. * Wrapper function to return data formerly found in the NVM.
  282. **/
  283. s32 igb_read_nvm_i211(struct e1000_hw *hw, u16 offset, u16 words,
  284. u16 *data)
  285. {
  286. s32 ret_val = E1000_SUCCESS;
  287. /* Only the MAC addr is required to be present in the iNVM */
  288. switch (offset) {
  289. case NVM_MAC_ADDR:
  290. ret_val = igb_read_invm_i211(hw, offset, &data[0]);
  291. ret_val |= igb_read_invm_i211(hw, offset+1, &data[1]);
  292. ret_val |= igb_read_invm_i211(hw, offset+2, &data[2]);
  293. if (ret_val != E1000_SUCCESS)
  294. hw_dbg("MAC Addr not found in iNVM\n");
  295. break;
  296. case NVM_INIT_CTRL_2:
  297. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  298. if (ret_val != E1000_SUCCESS) {
  299. *data = NVM_INIT_CTRL_2_DEFAULT_I211;
  300. ret_val = E1000_SUCCESS;
  301. }
  302. break;
  303. case NVM_INIT_CTRL_4:
  304. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  305. if (ret_val != E1000_SUCCESS) {
  306. *data = NVM_INIT_CTRL_4_DEFAULT_I211;
  307. ret_val = E1000_SUCCESS;
  308. }
  309. break;
  310. case NVM_LED_1_CFG:
  311. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  312. if (ret_val != E1000_SUCCESS) {
  313. *data = NVM_LED_1_CFG_DEFAULT_I211;
  314. ret_val = E1000_SUCCESS;
  315. }
  316. break;
  317. case NVM_LED_0_2_CFG:
  318. igb_read_invm_i211(hw, offset, data);
  319. if (ret_val != E1000_SUCCESS) {
  320. *data = NVM_LED_0_2_CFG_DEFAULT_I211;
  321. ret_val = E1000_SUCCESS;
  322. }
  323. break;
  324. case NVM_ID_LED_SETTINGS:
  325. ret_val = igb_read_invm_i211(hw, (u8)offset, data);
  326. if (ret_val != E1000_SUCCESS) {
  327. *data = ID_LED_RESERVED_FFFF;
  328. ret_val = E1000_SUCCESS;
  329. }
  330. case NVM_SUB_DEV_ID:
  331. *data = hw->subsystem_device_id;
  332. break;
  333. case NVM_SUB_VEN_ID:
  334. *data = hw->subsystem_vendor_id;
  335. break;
  336. case NVM_DEV_ID:
  337. *data = hw->device_id;
  338. break;
  339. case NVM_VEN_ID:
  340. *data = hw->vendor_id;
  341. break;
  342. default:
  343. hw_dbg("NVM word 0x%02x is not mapped.\n", offset);
  344. *data = NVM_RESERVED_WORD;
  345. break;
  346. }
  347. return ret_val;
  348. }
  349. /**
  350. * igb_read_invm_i211 - Reads OTP
  351. * @hw: pointer to the HW structure
  352. * @address: the word address (aka eeprom offset) to read
  353. * @data: pointer to the data read
  354. *
  355. * Reads 16-bit words from the OTP. Return error when the word is not
  356. * stored in OTP.
  357. **/
  358. s32 igb_read_invm_i211(struct e1000_hw *hw, u16 address, u16 *data)
  359. {
  360. s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
  361. u32 invm_dword;
  362. u16 i;
  363. u8 record_type, word_address;
  364. for (i = 0; i < E1000_INVM_SIZE; i++) {
  365. invm_dword = rd32(E1000_INVM_DATA_REG(i));
  366. /* Get record type */
  367. record_type = INVM_DWORD_TO_RECORD_TYPE(invm_dword);
  368. if (record_type == E1000_INVM_UNINITIALIZED_STRUCTURE)
  369. break;
  370. if (record_type == E1000_INVM_CSR_AUTOLOAD_STRUCTURE)
  371. i += E1000_INVM_CSR_AUTOLOAD_DATA_SIZE_IN_DWORDS;
  372. if (record_type == E1000_INVM_RSA_KEY_SHA256_STRUCTURE)
  373. i += E1000_INVM_RSA_KEY_SHA256_DATA_SIZE_IN_DWORDS;
  374. if (record_type == E1000_INVM_WORD_AUTOLOAD_STRUCTURE) {
  375. word_address = INVM_DWORD_TO_WORD_ADDRESS(invm_dword);
  376. if (word_address == (u8)address) {
  377. *data = INVM_DWORD_TO_WORD_DATA(invm_dword);
  378. hw_dbg("Read INVM Word 0x%02x = %x",
  379. address, *data);
  380. status = E1000_SUCCESS;
  381. break;
  382. }
  383. }
  384. }
  385. if (status != E1000_SUCCESS)
  386. hw_dbg("Requested word 0x%02x not found in OTP\n", address);
  387. return status;
  388. }
  389. /**
  390. * igb_read_invm_version - Reads iNVM version and image type
  391. * @hw: pointer to the HW structure
  392. * @invm_ver: version structure for the version read
  393. *
  394. * Reads iNVM version and image type.
  395. **/
  396. s32 igb_read_invm_version(struct e1000_hw *hw,
  397. struct e1000_fw_version *invm_ver) {
  398. u32 *record = NULL;
  399. u32 *next_record = NULL;
  400. u32 i = 0;
  401. u32 invm_dword = 0;
  402. u32 invm_blocks = E1000_INVM_SIZE - (E1000_INVM_ULT_BYTES_SIZE /
  403. E1000_INVM_RECORD_SIZE_IN_BYTES);
  404. u32 buffer[E1000_INVM_SIZE];
  405. s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
  406. u16 version = 0;
  407. /* Read iNVM memory */
  408. for (i = 0; i < E1000_INVM_SIZE; i++) {
  409. invm_dword = rd32(E1000_INVM_DATA_REG(i));
  410. buffer[i] = invm_dword;
  411. }
  412. /* Read version number */
  413. for (i = 1; i < invm_blocks; i++) {
  414. record = &buffer[invm_blocks - i];
  415. next_record = &buffer[invm_blocks - i + 1];
  416. /* Check if we have first version location used */
  417. if ((i == 1) && ((*record & E1000_INVM_VER_FIELD_ONE) == 0)) {
  418. version = 0;
  419. status = E1000_SUCCESS;
  420. break;
  421. }
  422. /* Check if we have second version location used */
  423. else if ((i == 1) &&
  424. ((*record & E1000_INVM_VER_FIELD_TWO) == 0)) {
  425. version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
  426. status = E1000_SUCCESS;
  427. break;
  428. }
  429. /* Check if we have odd version location
  430. * used and it is the last one used
  431. */
  432. else if ((((*record & E1000_INVM_VER_FIELD_ONE) == 0) &&
  433. ((*record & 0x3) == 0)) || (((*record & 0x3) != 0) &&
  434. (i != 1))) {
  435. version = (*next_record & E1000_INVM_VER_FIELD_TWO)
  436. >> 13;
  437. status = E1000_SUCCESS;
  438. break;
  439. }
  440. /* Check if we have even version location
  441. * used and it is the last one used
  442. */
  443. else if (((*record & E1000_INVM_VER_FIELD_TWO) == 0) &&
  444. ((*record & 0x3) == 0)) {
  445. version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
  446. status = E1000_SUCCESS;
  447. break;
  448. }
  449. }
  450. if (status == E1000_SUCCESS) {
  451. invm_ver->invm_major = (version & E1000_INVM_MAJOR_MASK)
  452. >> E1000_INVM_MAJOR_SHIFT;
  453. invm_ver->invm_minor = version & E1000_INVM_MINOR_MASK;
  454. }
  455. /* Read Image Type */
  456. for (i = 1; i < invm_blocks; i++) {
  457. record = &buffer[invm_blocks - i];
  458. next_record = &buffer[invm_blocks - i + 1];
  459. /* Check if we have image type in first location used */
  460. if ((i == 1) && ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) {
  461. invm_ver->invm_img_type = 0;
  462. status = E1000_SUCCESS;
  463. break;
  464. }
  465. /* Check if we have image type in first location used */
  466. else if ((((*record & 0x3) == 0) &&
  467. ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) ||
  468. ((((*record & 0x3) != 0) && (i != 1)))) {
  469. invm_ver->invm_img_type =
  470. (*next_record & E1000_INVM_IMGTYPE_FIELD) >> 23;
  471. status = E1000_SUCCESS;
  472. break;
  473. }
  474. }
  475. return status;
  476. }
  477. /**
  478. * igb_validate_nvm_checksum_i210 - Validate EEPROM checksum
  479. * @hw: pointer to the HW structure
  480. *
  481. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  482. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  483. **/
  484. s32 igb_validate_nvm_checksum_i210(struct e1000_hw *hw)
  485. {
  486. s32 status = E1000_SUCCESS;
  487. s32 (*read_op_ptr)(struct e1000_hw *, u16, u16, u16 *);
  488. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  489. /* Replace the read function with semaphore grabbing with
  490. * the one that skips this for a while.
  491. * We have semaphore taken already here.
  492. */
  493. read_op_ptr = hw->nvm.ops.read;
  494. hw->nvm.ops.read = igb_read_nvm_eerd;
  495. status = igb_validate_nvm_checksum(hw);
  496. /* Revert original read operation. */
  497. hw->nvm.ops.read = read_op_ptr;
  498. hw->nvm.ops.release(hw);
  499. } else {
  500. status = E1000_ERR_SWFW_SYNC;
  501. }
  502. return status;
  503. }
  504. /**
  505. * igb_update_nvm_checksum_i210 - Update EEPROM checksum
  506. * @hw: pointer to the HW structure
  507. *
  508. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  509. * up to the checksum. Then calculates the EEPROM checksum and writes the
  510. * value to the EEPROM. Next commit EEPROM data onto the Flash.
  511. **/
  512. s32 igb_update_nvm_checksum_i210(struct e1000_hw *hw)
  513. {
  514. s32 ret_val = E1000_SUCCESS;
  515. u16 checksum = 0;
  516. u16 i, nvm_data;
  517. /* Read the first word from the EEPROM. If this times out or fails, do
  518. * not continue or we could be in for a very long wait while every
  519. * EEPROM read fails
  520. */
  521. ret_val = igb_read_nvm_eerd(hw, 0, 1, &nvm_data);
  522. if (ret_val != E1000_SUCCESS) {
  523. hw_dbg("EEPROM read failed\n");
  524. goto out;
  525. }
  526. if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
  527. /* Do not use hw->nvm.ops.write, hw->nvm.ops.read
  528. * because we do not want to take the synchronization
  529. * semaphores twice here.
  530. */
  531. for (i = 0; i < NVM_CHECKSUM_REG; i++) {
  532. ret_val = igb_read_nvm_eerd(hw, i, 1, &nvm_data);
  533. if (ret_val) {
  534. hw->nvm.ops.release(hw);
  535. hw_dbg("NVM Read Error while updating checksum.\n");
  536. goto out;
  537. }
  538. checksum += nvm_data;
  539. }
  540. checksum = (u16) NVM_SUM - checksum;
  541. ret_val = igb_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
  542. &checksum);
  543. if (ret_val != E1000_SUCCESS) {
  544. hw->nvm.ops.release(hw);
  545. hw_dbg("NVM Write Error while updating checksum.\n");
  546. goto out;
  547. }
  548. hw->nvm.ops.release(hw);
  549. ret_val = igb_update_flash_i210(hw);
  550. } else {
  551. ret_val = -E1000_ERR_SWFW_SYNC;
  552. }
  553. out:
  554. return ret_val;
  555. }
  556. /**
  557. * igb_pool_flash_update_done_i210 - Pool FLUDONE status.
  558. * @hw: pointer to the HW structure
  559. *
  560. **/
  561. static s32 igb_pool_flash_update_done_i210(struct e1000_hw *hw)
  562. {
  563. s32 ret_val = -E1000_ERR_NVM;
  564. u32 i, reg;
  565. for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
  566. reg = rd32(E1000_EECD);
  567. if (reg & E1000_EECD_FLUDONE_I210) {
  568. ret_val = E1000_SUCCESS;
  569. break;
  570. }
  571. udelay(5);
  572. }
  573. return ret_val;
  574. }
  575. /**
  576. * igb_update_flash_i210 - Commit EEPROM to the flash
  577. * @hw: pointer to the HW structure
  578. *
  579. **/
  580. s32 igb_update_flash_i210(struct e1000_hw *hw)
  581. {
  582. s32 ret_val = E1000_SUCCESS;
  583. u32 flup;
  584. ret_val = igb_pool_flash_update_done_i210(hw);
  585. if (ret_val == -E1000_ERR_NVM) {
  586. hw_dbg("Flash update time out\n");
  587. goto out;
  588. }
  589. flup = rd32(E1000_EECD) | E1000_EECD_FLUPD_I210;
  590. wr32(E1000_EECD, flup);
  591. ret_val = igb_pool_flash_update_done_i210(hw);
  592. if (ret_val == E1000_SUCCESS)
  593. hw_dbg("Flash update complete\n");
  594. else
  595. hw_dbg("Flash update time out\n");
  596. out:
  597. return ret_val;
  598. }
  599. /**
  600. * igb_valid_led_default_i210 - Verify a valid default LED config
  601. * @hw: pointer to the HW structure
  602. * @data: pointer to the NVM (EEPROM)
  603. *
  604. * Read the EEPROM for the current default LED configuration. If the
  605. * LED configuration is not valid, set to a valid LED configuration.
  606. **/
  607. s32 igb_valid_led_default_i210(struct e1000_hw *hw, u16 *data)
  608. {
  609. s32 ret_val;
  610. ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
  611. if (ret_val) {
  612. hw_dbg("NVM Read Error\n");
  613. goto out;
  614. }
  615. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
  616. switch (hw->phy.media_type) {
  617. case e1000_media_type_internal_serdes:
  618. *data = ID_LED_DEFAULT_I210_SERDES;
  619. break;
  620. case e1000_media_type_copper:
  621. default:
  622. *data = ID_LED_DEFAULT_I210;
  623. break;
  624. }
  625. }
  626. out:
  627. return ret_val;
  628. }
  629. /**
  630. * __igb_access_xmdio_reg - Read/write XMDIO register
  631. * @hw: pointer to the HW structure
  632. * @address: XMDIO address to program
  633. * @dev_addr: device address to program
  634. * @data: pointer to value to read/write from/to the XMDIO address
  635. * @read: boolean flag to indicate read or write
  636. **/
  637. static s32 __igb_access_xmdio_reg(struct e1000_hw *hw, u16 address,
  638. u8 dev_addr, u16 *data, bool read)
  639. {
  640. s32 ret_val = E1000_SUCCESS;
  641. ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, dev_addr);
  642. if (ret_val)
  643. return ret_val;
  644. ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAAD, address);
  645. if (ret_val)
  646. return ret_val;
  647. ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, E1000_MMDAC_FUNC_DATA |
  648. dev_addr);
  649. if (ret_val)
  650. return ret_val;
  651. if (read)
  652. ret_val = hw->phy.ops.read_reg(hw, E1000_MMDAAD, data);
  653. else
  654. ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAAD, *data);
  655. if (ret_val)
  656. return ret_val;
  657. /* Recalibrate the device back to 0 */
  658. ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, 0);
  659. if (ret_val)
  660. return ret_val;
  661. return ret_val;
  662. }
  663. /**
  664. * igb_read_xmdio_reg - Read XMDIO register
  665. * @hw: pointer to the HW structure
  666. * @addr: XMDIO address to program
  667. * @dev_addr: device address to program
  668. * @data: value to be read from the EMI address
  669. **/
  670. s32 igb_read_xmdio_reg(struct e1000_hw *hw, u16 addr, u8 dev_addr, u16 *data)
  671. {
  672. return __igb_access_xmdio_reg(hw, addr, dev_addr, data, true);
  673. }
  674. /**
  675. * igb_write_xmdio_reg - Write XMDIO register
  676. * @hw: pointer to the HW structure
  677. * @addr: XMDIO address to program
  678. * @dev_addr: device address to program
  679. * @data: value to be written to the XMDIO address
  680. **/
  681. s32 igb_write_xmdio_reg(struct e1000_hw *hw, u16 addr, u8 dev_addr, u16 data)
  682. {
  683. return __igb_access_xmdio_reg(hw, addr, dev_addr, &data, false);
  684. }