ixgbe_x540.c 24 KB

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