ixgbe_x540.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2012 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. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include "ixgbe.h"
  24. #include "ixgbe_phy.h"
  25. #define IXGBE_X540_MAX_TX_QUEUES 128
  26. #define IXGBE_X540_MAX_RX_QUEUES 128
  27. #define IXGBE_X540_RAR_ENTRIES 128
  28. #define IXGBE_X540_MC_TBL_SIZE 128
  29. #define IXGBE_X540_VFT_TBL_SIZE 128
  30. #define IXGBE_X540_RX_PB_SIZE 384
  31. static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw);
  32. static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
  33. static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
  34. static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
  35. static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
  36. static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
  37. static enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
  38. {
  39. return ixgbe_media_type_copper;
  40. }
  41. static s32 ixgbe_get_invariants_X540(struct ixgbe_hw *hw)
  42. {
  43. struct ixgbe_mac_info *mac = &hw->mac;
  44. /* Call PHY identify routine to get the phy type */
  45. ixgbe_identify_phy_generic(hw);
  46. mac->mcft_size = IXGBE_X540_MC_TBL_SIZE;
  47. mac->vft_size = IXGBE_X540_VFT_TBL_SIZE;
  48. mac->num_rar_entries = IXGBE_X540_RAR_ENTRIES;
  49. mac->max_rx_queues = IXGBE_X540_MAX_RX_QUEUES;
  50. mac->max_tx_queues = IXGBE_X540_MAX_TX_QUEUES;
  51. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
  52. return 0;
  53. }
  54. /**
  55. * ixgbe_setup_mac_link_X540 - Set the auto advertised capabilitires
  56. * @hw: pointer to hardware structure
  57. * @speed: new link speed
  58. * @autoneg: true if autonegotiation enabled
  59. * @autoneg_wait_to_complete: true when waiting for completion is needed
  60. **/
  61. static s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw,
  62. ixgbe_link_speed speed, bool autoneg,
  63. bool autoneg_wait_to_complete)
  64. {
  65. return hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  66. autoneg_wait_to_complete);
  67. }
  68. /**
  69. * ixgbe_reset_hw_X540 - Perform hardware reset
  70. * @hw: pointer to hardware structure
  71. *
  72. * Resets the hardware by resetting the transmit and receive units, masks
  73. * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  74. * reset.
  75. **/
  76. static s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw)
  77. {
  78. s32 status;
  79. u32 ctrl, i;
  80. /* Call adapter stop to disable tx/rx and clear interrupts */
  81. status = hw->mac.ops.stop_adapter(hw);
  82. if (status != 0)
  83. goto reset_hw_out;
  84. /* flush pending Tx transactions */
  85. ixgbe_clear_tx_pending(hw);
  86. mac_reset_top:
  87. ctrl = IXGBE_CTRL_RST;
  88. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  89. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  90. IXGBE_WRITE_FLUSH(hw);
  91. /* Poll for reset bit to self-clear indicating reset is complete */
  92. for (i = 0; i < 10; i++) {
  93. udelay(1);
  94. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  95. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  96. break;
  97. }
  98. if (ctrl & IXGBE_CTRL_RST_MASK) {
  99. status = IXGBE_ERR_RESET_FAILED;
  100. hw_dbg(hw, "Reset polling failed to complete.\n");
  101. }
  102. msleep(100);
  103. /*
  104. * Double resets are required for recovery from certain error
  105. * conditions. Between resets, it is necessary to stall to allow time
  106. * for any pending HW events to complete.
  107. */
  108. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  109. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  110. goto mac_reset_top;
  111. }
  112. /* Set the Rx packet buffer size. */
  113. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT);
  114. /* Store the permanent mac address */
  115. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  116. /*
  117. * Store MAC address from RAR0, clear receive address registers, and
  118. * clear the multicast table. Also reset num_rar_entries to 128,
  119. * since we modify this value when programming the SAN MAC address.
  120. */
  121. hw->mac.num_rar_entries = IXGBE_X540_MAX_TX_QUEUES;
  122. hw->mac.ops.init_rx_addrs(hw);
  123. /* Store the permanent SAN mac address */
  124. hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
  125. /* Add the SAN MAC address to the RAR only if it's a valid address */
  126. if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
  127. hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
  128. hw->mac.san_addr, 0, IXGBE_RAH_AV);
  129. /* Reserve the last RAR for the SAN MAC address */
  130. hw->mac.num_rar_entries--;
  131. }
  132. /* Store the alternative WWNN/WWPN prefix */
  133. hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
  134. &hw->mac.wwpn_prefix);
  135. reset_hw_out:
  136. return status;
  137. }
  138. /**
  139. * ixgbe_start_hw_X540 - Prepare hardware for Tx/Rx
  140. * @hw: pointer to hardware structure
  141. *
  142. * Starts the hardware using the generic start_hw function
  143. * and the generation start_hw function.
  144. * Then performs revision-specific operations, if any.
  145. **/
  146. static s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw)
  147. {
  148. s32 ret_val = 0;
  149. ret_val = ixgbe_start_hw_generic(hw);
  150. if (ret_val != 0)
  151. goto out;
  152. ret_val = ixgbe_start_hw_gen2(hw);
  153. hw->mac.rx_pb_size = IXGBE_X540_RX_PB_SIZE;
  154. out:
  155. return ret_val;
  156. }
  157. /**
  158. * ixgbe_get_supported_physical_layer_X540 - Returns physical layer type
  159. * @hw: pointer to hardware structure
  160. *
  161. * Determines physical layer capabilities of the current configuration.
  162. **/
  163. static u32 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw)
  164. {
  165. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  166. u16 ext_ability = 0;
  167. hw->phy.ops.identify(hw);
  168. hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
  169. &ext_ability);
  170. if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
  171. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
  172. if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
  173. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
  174. if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
  175. physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
  176. return physical_layer;
  177. }
  178. /**
  179. * ixgbe_init_eeprom_params_X540 - Initialize EEPROM params
  180. * @hw: pointer to hardware structure
  181. *
  182. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  183. * ixgbe_hw struct in order to set up EEPROM access.
  184. **/
  185. static s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
  186. {
  187. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  188. u32 eec;
  189. u16 eeprom_size;
  190. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  191. eeprom->semaphore_delay = 10;
  192. eeprom->type = ixgbe_flash;
  193. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  194. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  195. IXGBE_EEC_SIZE_SHIFT);
  196. eeprom->word_size = 1 << (eeprom_size +
  197. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  198. hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
  199. eeprom->type, eeprom->word_size);
  200. }
  201. return 0;
  202. }
  203. /**
  204. * ixgbe_read_eerd_X540- Read EEPROM word using EERD
  205. * @hw: pointer to hardware structure
  206. * @offset: offset of word in the EEPROM to read
  207. * @data: word read from the EEPROM
  208. *
  209. * Reads a 16 bit word from the EEPROM using the EERD register.
  210. **/
  211. static s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
  212. {
  213. s32 status = 0;
  214. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
  215. 0)
  216. status = ixgbe_read_eerd_generic(hw, offset, data);
  217. else
  218. status = IXGBE_ERR_SWFW_SYNC;
  219. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  220. return status;
  221. }
  222. /**
  223. * ixgbe_read_eerd_buffer_X540 - Read EEPROM word(s) using EERD
  224. * @hw: pointer to hardware structure
  225. * @offset: offset of word in the EEPROM to read
  226. * @words: number of words
  227. * @data: word(s) read from the EEPROM
  228. *
  229. * Reads a 16 bit word(s) from the EEPROM using the EERD register.
  230. **/
  231. static s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw,
  232. u16 offset, u16 words, u16 *data)
  233. {
  234. s32 status = 0;
  235. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
  236. 0)
  237. status = ixgbe_read_eerd_buffer_generic(hw, offset,
  238. words, data);
  239. else
  240. status = IXGBE_ERR_SWFW_SYNC;
  241. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  242. return status;
  243. }
  244. /**
  245. * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
  246. * @hw: pointer to hardware structure
  247. * @offset: offset of word in the EEPROM to write
  248. * @data: word write to the EEPROM
  249. *
  250. * Write a 16 bit word to the EEPROM using the EEWR register.
  251. **/
  252. static s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
  253. {
  254. s32 status = 0;
  255. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0)
  256. status = ixgbe_write_eewr_generic(hw, offset, data);
  257. else
  258. status = IXGBE_ERR_SWFW_SYNC;
  259. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  260. return status;
  261. }
  262. /**
  263. * ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR
  264. * @hw: pointer to hardware structure
  265. * @offset: offset of word in the EEPROM to write
  266. * @words: number of words
  267. * @data: word(s) write to the EEPROM
  268. *
  269. * Write a 16 bit word(s) to the EEPROM using the EEWR register.
  270. **/
  271. static s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
  272. u16 offset, u16 words, u16 *data)
  273. {
  274. s32 status = 0;
  275. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
  276. 0)
  277. status = ixgbe_write_eewr_buffer_generic(hw, offset,
  278. words, data);
  279. else
  280. status = IXGBE_ERR_SWFW_SYNC;
  281. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  282. return status;
  283. }
  284. /**
  285. * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
  286. *
  287. * This function does not use synchronization for EERD and EEWR. It can
  288. * be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
  289. *
  290. * @hw: pointer to hardware structure
  291. **/
  292. static u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
  293. {
  294. u16 i;
  295. u16 j;
  296. u16 checksum = 0;
  297. u16 length = 0;
  298. u16 pointer = 0;
  299. u16 word = 0;
  300. /*
  301. * Do not use hw->eeprom.ops.read because we do not want to take
  302. * the synchronization semaphores here. Instead use
  303. * ixgbe_read_eerd_generic
  304. */
  305. /* Include 0x0-0x3F in the checksum */
  306. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  307. if (ixgbe_read_eerd_generic(hw, i, &word) != 0) {
  308. hw_dbg(hw, "EEPROM read failed\n");
  309. break;
  310. }
  311. checksum += word;
  312. }
  313. /*
  314. * Include all data from pointers 0x3, 0x6-0xE. This excludes the
  315. * FW, PHY module, and PCIe Expansion/Option ROM pointers.
  316. */
  317. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  318. if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
  319. continue;
  320. if (ixgbe_read_eerd_generic(hw, i, &pointer) != 0) {
  321. hw_dbg(hw, "EEPROM read failed\n");
  322. break;
  323. }
  324. /* Skip pointer section if the pointer is invalid. */
  325. if (pointer == 0xFFFF || pointer == 0 ||
  326. pointer >= hw->eeprom.word_size)
  327. continue;
  328. if (ixgbe_read_eerd_generic(hw, pointer, &length) != 0) {
  329. hw_dbg(hw, "EEPROM read failed\n");
  330. break;
  331. }
  332. /* Skip pointer section if length is invalid. */
  333. if (length == 0xFFFF || length == 0 ||
  334. (pointer + length) >= hw->eeprom.word_size)
  335. continue;
  336. for (j = pointer+1; j <= pointer+length; j++) {
  337. if (ixgbe_read_eerd_generic(hw, j, &word) != 0) {
  338. hw_dbg(hw, "EEPROM read failed\n");
  339. break;
  340. }
  341. checksum += word;
  342. }
  343. }
  344. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  345. return checksum;
  346. }
  347. /**
  348. * ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum
  349. * @hw: pointer to hardware structure
  350. * @checksum_val: calculated checksum
  351. *
  352. * Performs checksum calculation and validates the EEPROM checksum. If the
  353. * caller does not need checksum_val, the value can be NULL.
  354. **/
  355. static s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw,
  356. u16 *checksum_val)
  357. {
  358. s32 status;
  359. u16 checksum;
  360. u16 read_checksum = 0;
  361. /*
  362. * Read the first word from the EEPROM. If this times out or fails, do
  363. * not continue or we could be in for a very long wait while every
  364. * EEPROM read fails
  365. */
  366. status = hw->eeprom.ops.read(hw, 0, &checksum);
  367. if (status != 0) {
  368. hw_dbg(hw, "EEPROM read failed\n");
  369. goto out;
  370. }
  371. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  372. checksum = hw->eeprom.ops.calc_checksum(hw);
  373. /*
  374. * Do not use hw->eeprom.ops.read because we do not want to take
  375. * the synchronization semaphores twice here.
  376. */
  377. ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
  378. &read_checksum);
  379. /*
  380. * Verify read checksum from EEPROM is the same as
  381. * calculated checksum
  382. */
  383. if (read_checksum != checksum)
  384. status = IXGBE_ERR_EEPROM_CHECKSUM;
  385. /* If the user cares, return the calculated checksum */
  386. if (checksum_val)
  387. *checksum_val = checksum;
  388. } else {
  389. status = IXGBE_ERR_SWFW_SYNC;
  390. }
  391. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  392. out:
  393. return status;
  394. }
  395. /**
  396. * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
  397. * @hw: pointer to hardware structure
  398. *
  399. * After writing EEPROM to shadow RAM using EEWR register, software calculates
  400. * checksum and updates the EEPROM and instructs the hardware to update
  401. * the flash.
  402. **/
  403. static s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
  404. {
  405. s32 status;
  406. u16 checksum;
  407. /*
  408. * Read the first word from the EEPROM. If this times out or fails, do
  409. * not continue or we could be in for a very long wait while every
  410. * EEPROM read fails
  411. */
  412. status = hw->eeprom.ops.read(hw, 0, &checksum);
  413. if (status != 0)
  414. hw_dbg(hw, "EEPROM read failed\n");
  415. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  416. checksum = hw->eeprom.ops.calc_checksum(hw);
  417. /*
  418. * Do not use hw->eeprom.ops.write because we do not want to
  419. * take the synchronization semaphores twice here.
  420. */
  421. status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM,
  422. checksum);
  423. if (status == 0)
  424. status = ixgbe_update_flash_X540(hw);
  425. else
  426. status = IXGBE_ERR_SWFW_SYNC;
  427. }
  428. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  429. return status;
  430. }
  431. /**
  432. * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
  433. * @hw: pointer to hardware structure
  434. *
  435. * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
  436. * EEPROM from shadow RAM to the flash device.
  437. **/
  438. static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
  439. {
  440. u32 flup;
  441. s32 status = IXGBE_ERR_EEPROM;
  442. status = ixgbe_poll_flash_update_done_X540(hw);
  443. if (status == IXGBE_ERR_EEPROM) {
  444. hw_dbg(hw, "Flash update time out\n");
  445. goto out;
  446. }
  447. flup = IXGBE_READ_REG(hw, IXGBE_EEC) | IXGBE_EEC_FLUP;
  448. IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
  449. status = ixgbe_poll_flash_update_done_X540(hw);
  450. if (status == 0)
  451. hw_dbg(hw, "Flash update complete\n");
  452. else
  453. hw_dbg(hw, "Flash update time out\n");
  454. if (hw->revision_id == 0) {
  455. flup = IXGBE_READ_REG(hw, IXGBE_EEC);
  456. if (flup & IXGBE_EEC_SEC1VAL) {
  457. flup |= IXGBE_EEC_FLUP;
  458. IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
  459. }
  460. status = ixgbe_poll_flash_update_done_X540(hw);
  461. if (status == 0)
  462. hw_dbg(hw, "Flash update complete\n");
  463. else
  464. hw_dbg(hw, "Flash update time out\n");
  465. }
  466. out:
  467. return status;
  468. }
  469. /**
  470. * ixgbe_poll_flash_update_done_X540 - Poll flash update status
  471. * @hw: pointer to hardware structure
  472. *
  473. * Polls the FLUDONE (bit 26) of the EEC Register to determine when the
  474. * flash update is done.
  475. **/
  476. static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
  477. {
  478. u32 i;
  479. u32 reg;
  480. s32 status = IXGBE_ERR_EEPROM;
  481. for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
  482. reg = IXGBE_READ_REG(hw, IXGBE_EEC);
  483. if (reg & IXGBE_EEC_FLUDONE) {
  484. status = 0;
  485. break;
  486. }
  487. udelay(5);
  488. }
  489. return status;
  490. }
  491. /**
  492. * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
  493. * @hw: pointer to hardware structure
  494. * @mask: Mask to specify which semaphore to acquire
  495. *
  496. * Acquires the SWFW semaphore thought the SW_FW_SYNC register for
  497. * the specified function (CSR, PHY0, PHY1, NVM, Flash)
  498. **/
  499. static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
  500. {
  501. u32 swfw_sync;
  502. u32 swmask = mask;
  503. u32 fwmask = mask << 5;
  504. u32 hwmask = 0;
  505. u32 timeout = 200;
  506. u32 i;
  507. if (swmask == IXGBE_GSSR_EEP_SM)
  508. hwmask = IXGBE_GSSR_FLASH_SM;
  509. for (i = 0; i < timeout; i++) {
  510. /*
  511. * SW NVM semaphore bit is used for access to all
  512. * SW_FW_SYNC bits (not just NVM)
  513. */
  514. if (ixgbe_get_swfw_sync_semaphore(hw))
  515. return IXGBE_ERR_SWFW_SYNC;
  516. swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  517. if (!(swfw_sync & (fwmask | swmask | hwmask))) {
  518. swfw_sync |= swmask;
  519. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
  520. ixgbe_release_swfw_sync_semaphore(hw);
  521. break;
  522. } else {
  523. /*
  524. * Firmware currently using resource (fwmask),
  525. * hardware currently using resource (hwmask),
  526. * or other software thread currently using
  527. * resource (swmask)
  528. */
  529. ixgbe_release_swfw_sync_semaphore(hw);
  530. usleep_range(5000, 10000);
  531. }
  532. }
  533. /*
  534. * If the resource is not released by the FW/HW the SW can assume that
  535. * the FW/HW malfunctions. In that case the SW should sets the
  536. * SW bit(s) of the requested resource(s) while ignoring the
  537. * corresponding FW/HW bits in the SW_FW_SYNC register.
  538. */
  539. if (i >= timeout) {
  540. swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  541. if (swfw_sync & (fwmask | hwmask)) {
  542. if (ixgbe_get_swfw_sync_semaphore(hw))
  543. return IXGBE_ERR_SWFW_SYNC;
  544. swfw_sync |= swmask;
  545. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
  546. ixgbe_release_swfw_sync_semaphore(hw);
  547. }
  548. }
  549. usleep_range(5000, 10000);
  550. return 0;
  551. }
  552. /**
  553. * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
  554. * @hw: pointer to hardware structure
  555. * @mask: Mask to specify which semaphore to release
  556. *
  557. * Releases the SWFW semaphore through the SW_FW_SYNC register
  558. * for the specified function (CSR, PHY0, PHY1, EVM, Flash)
  559. **/
  560. static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
  561. {
  562. u32 swfw_sync;
  563. u32 swmask = mask;
  564. ixgbe_get_swfw_sync_semaphore(hw);
  565. swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  566. swfw_sync &= ~swmask;
  567. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
  568. ixgbe_release_swfw_sync_semaphore(hw);
  569. usleep_range(5000, 10000);
  570. }
  571. /**
  572. * ixgbe_get_nvm_semaphore - Get hardware semaphore
  573. * @hw: pointer to hardware structure
  574. *
  575. * Sets the hardware semaphores so SW/FW can gain control of shared resources
  576. **/
  577. static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
  578. {
  579. s32 status = IXGBE_ERR_EEPROM;
  580. u32 timeout = 2000;
  581. u32 i;
  582. u32 swsm;
  583. /* Get SMBI software semaphore between device drivers first */
  584. for (i = 0; i < timeout; i++) {
  585. /*
  586. * If the SMBI bit is 0 when we read it, then the bit will be
  587. * set and we have the semaphore
  588. */
  589. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  590. if (!(swsm & IXGBE_SWSM_SMBI)) {
  591. status = 0;
  592. break;
  593. }
  594. udelay(50);
  595. }
  596. /* Now get the semaphore between SW/FW through the REGSMP bit */
  597. if (status) {
  598. for (i = 0; i < timeout; i++) {
  599. swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  600. if (!(swsm & IXGBE_SWFW_REGSMP))
  601. break;
  602. udelay(50);
  603. }
  604. } else {
  605. hw_dbg(hw, "Software semaphore SMBI between device drivers "
  606. "not granted.\n");
  607. }
  608. return status;
  609. }
  610. /**
  611. * ixgbe_release_nvm_semaphore - Release hardware semaphore
  612. * @hw: pointer to hardware structure
  613. *
  614. * This function clears hardware semaphore bits.
  615. **/
  616. static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
  617. {
  618. u32 swsm;
  619. /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
  620. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  621. swsm &= ~IXGBE_SWSM_SMBI;
  622. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  623. swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  624. swsm &= ~IXGBE_SWFW_REGSMP;
  625. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swsm);
  626. IXGBE_WRITE_FLUSH(hw);
  627. }
  628. /**
  629. * ixgbe_blink_led_start_X540 - Blink LED based on index.
  630. * @hw: pointer to hardware structure
  631. * @index: led number to blink
  632. *
  633. * Devices that implement the version 2 interface:
  634. * X540
  635. **/
  636. static s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index)
  637. {
  638. u32 macc_reg;
  639. u32 ledctl_reg;
  640. ixgbe_link_speed speed;
  641. bool link_up;
  642. /*
  643. * Link should be up in order for the blink bit in the LED control
  644. * register to work. Force link and speed in the MAC if link is down.
  645. * This will be reversed when we stop the blinking.
  646. */
  647. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  648. if (link_up == false) {
  649. macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
  650. macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS;
  651. IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
  652. }
  653. /* Set the LED to LINK_UP + BLINK. */
  654. ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  655. ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
  656. ledctl_reg |= IXGBE_LED_BLINK(index);
  657. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
  658. IXGBE_WRITE_FLUSH(hw);
  659. return 0;
  660. }
  661. /**
  662. * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index.
  663. * @hw: pointer to hardware structure
  664. * @index: led number to stop blinking
  665. *
  666. * Devices that implement the version 2 interface:
  667. * X540
  668. **/
  669. static s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index)
  670. {
  671. u32 macc_reg;
  672. u32 ledctl_reg;
  673. /* Restore the LED to its default value. */
  674. ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  675. ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
  676. ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  677. ledctl_reg &= ~IXGBE_LED_BLINK(index);
  678. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
  679. /* Unforce link and speed in the MAC. */
  680. macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
  681. macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS);
  682. IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
  683. IXGBE_WRITE_FLUSH(hw);
  684. return 0;
  685. }
  686. static struct ixgbe_mac_operations mac_ops_X540 = {
  687. .init_hw = &ixgbe_init_hw_generic,
  688. .reset_hw = &ixgbe_reset_hw_X540,
  689. .start_hw = &ixgbe_start_hw_X540,
  690. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  691. .get_media_type = &ixgbe_get_media_type_X540,
  692. .get_supported_physical_layer =
  693. &ixgbe_get_supported_physical_layer_X540,
  694. .enable_rx_dma = &ixgbe_enable_rx_dma_generic,
  695. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  696. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  697. .get_device_caps = &ixgbe_get_device_caps_generic,
  698. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  699. .stop_adapter = &ixgbe_stop_adapter_generic,
  700. .get_bus_info = &ixgbe_get_bus_info_generic,
  701. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  702. .read_analog_reg8 = NULL,
  703. .write_analog_reg8 = NULL,
  704. .setup_link = &ixgbe_setup_mac_link_X540,
  705. .set_rxpba = &ixgbe_set_rxpba_generic,
  706. .check_link = &ixgbe_check_mac_link_generic,
  707. .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
  708. .led_on = &ixgbe_led_on_generic,
  709. .led_off = &ixgbe_led_off_generic,
  710. .blink_led_start = &ixgbe_blink_led_start_X540,
  711. .blink_led_stop = &ixgbe_blink_led_stop_X540,
  712. .set_rar = &ixgbe_set_rar_generic,
  713. .clear_rar = &ixgbe_clear_rar_generic,
  714. .set_vmdq = &ixgbe_set_vmdq_generic,
  715. .clear_vmdq = &ixgbe_clear_vmdq_generic,
  716. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  717. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  718. .enable_mc = &ixgbe_enable_mc_generic,
  719. .disable_mc = &ixgbe_disable_mc_generic,
  720. .clear_vfta = &ixgbe_clear_vfta_generic,
  721. .set_vfta = &ixgbe_set_vfta_generic,
  722. .fc_enable = &ixgbe_fc_enable_generic,
  723. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic,
  724. .init_uta_tables = &ixgbe_init_uta_tables_generic,
  725. .setup_sfp = NULL,
  726. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
  727. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
  728. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
  729. .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
  730. };
  731. static struct ixgbe_eeprom_operations eeprom_ops_X540 = {
  732. .init_params = &ixgbe_init_eeprom_params_X540,
  733. .read = &ixgbe_read_eerd_X540,
  734. .read_buffer = &ixgbe_read_eerd_buffer_X540,
  735. .write = &ixgbe_write_eewr_X540,
  736. .write_buffer = &ixgbe_write_eewr_buffer_X540,
  737. .calc_checksum = &ixgbe_calc_eeprom_checksum_X540,
  738. .validate_checksum = &ixgbe_validate_eeprom_checksum_X540,
  739. .update_checksum = &ixgbe_update_eeprom_checksum_X540,
  740. };
  741. static struct ixgbe_phy_operations phy_ops_X540 = {
  742. .identify = &ixgbe_identify_phy_generic,
  743. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  744. .init = NULL,
  745. .reset = NULL,
  746. .read_reg = &ixgbe_read_phy_reg_generic,
  747. .write_reg = &ixgbe_write_phy_reg_generic,
  748. .setup_link = &ixgbe_setup_phy_link_generic,
  749. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  750. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  751. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  752. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  753. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  754. .check_overtemp = &ixgbe_tn_check_overtemp,
  755. .get_firmware_version = &ixgbe_get_phy_firmware_version_generic,
  756. };
  757. struct ixgbe_info ixgbe_X540_info = {
  758. .mac = ixgbe_mac_X540,
  759. .get_invariants = &ixgbe_get_invariants_X540,
  760. .mac_ops = &mac_ops_X540,
  761. .eeprom_ops = &eeprom_ops_X540,
  762. .phy_ops = &phy_ops_X540,
  763. .mbx_ops = &mbx_ops_generic,
  764. };