ixgbe_x540.c 22 KB

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