ixgbe_x540.c 26 KB

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