ixgbe_x540.c 26 KB

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