e1000_i210.c 21 KB

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