ixgbe_x540.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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 EEPROM
  261. *
  262. * Reads a 16 bit word from the EEPROM using the EERD register.
  263. **/
  264. static s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
  265. {
  266. s32 status = 0;
  267. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
  268. 0)
  269. status = ixgbe_read_eerd_generic(hw, offset, data);
  270. else
  271. status = IXGBE_ERR_SWFW_SYNC;
  272. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  273. return status;
  274. }
  275. /**
  276. * ixgbe_read_eerd_buffer_X540 - Read EEPROM word(s) using EERD
  277. * @hw: pointer to hardware structure
  278. * @offset: offset of word in the EEPROM to read
  279. * @words: number of words
  280. * @data: word(s) read from the EEPROM
  281. *
  282. * Reads a 16 bit word(s) from the EEPROM using the EERD register.
  283. **/
  284. static s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw,
  285. u16 offset, u16 words, u16 *data)
  286. {
  287. s32 status = 0;
  288. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
  289. 0)
  290. status = ixgbe_read_eerd_buffer_generic(hw, offset,
  291. words, data);
  292. else
  293. status = IXGBE_ERR_SWFW_SYNC;
  294. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  295. return status;
  296. }
  297. /**
  298. * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
  299. * @hw: pointer to hardware structure
  300. * @offset: offset of word in the EEPROM to write
  301. * @data: word write to the EEPROM
  302. *
  303. * Write a 16 bit word to the EEPROM using the EEWR register.
  304. **/
  305. static s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
  306. {
  307. s32 status = 0;
  308. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0)
  309. status = ixgbe_write_eewr_generic(hw, offset, data);
  310. else
  311. status = IXGBE_ERR_SWFW_SYNC;
  312. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  313. return status;
  314. }
  315. /**
  316. * ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR
  317. * @hw: pointer to hardware structure
  318. * @offset: offset of word in the EEPROM to write
  319. * @words: number of words
  320. * @data: word(s) write to the EEPROM
  321. *
  322. * Write a 16 bit word(s) to the EEPROM using the EEWR register.
  323. **/
  324. static s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
  325. u16 offset, u16 words, u16 *data)
  326. {
  327. s32 status = 0;
  328. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
  329. 0)
  330. status = ixgbe_write_eewr_buffer_generic(hw, offset,
  331. words, data);
  332. else
  333. status = IXGBE_ERR_SWFW_SYNC;
  334. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  335. return status;
  336. }
  337. /**
  338. * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
  339. *
  340. * This function does not use synchronization for EERD and EEWR. It can
  341. * be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
  342. *
  343. * @hw: pointer to hardware structure
  344. **/
  345. static u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
  346. {
  347. u16 i;
  348. u16 j;
  349. u16 checksum = 0;
  350. u16 length = 0;
  351. u16 pointer = 0;
  352. u16 word = 0;
  353. /*
  354. * Do not use hw->eeprom.ops.read because we do not want to take
  355. * the synchronization semaphores here. Instead use
  356. * ixgbe_read_eerd_generic
  357. */
  358. /* Include 0x0-0x3F in the checksum */
  359. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  360. if (ixgbe_read_eerd_generic(hw, i, &word) != 0) {
  361. hw_dbg(hw, "EEPROM read failed\n");
  362. break;
  363. }
  364. checksum += word;
  365. }
  366. /*
  367. * Include all data from pointers 0x3, 0x6-0xE. This excludes the
  368. * FW, PHY module, and PCIe Expansion/Option ROM pointers.
  369. */
  370. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  371. if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
  372. continue;
  373. if (ixgbe_read_eerd_generic(hw, i, &pointer) != 0) {
  374. hw_dbg(hw, "EEPROM read failed\n");
  375. break;
  376. }
  377. /* Skip pointer section if the pointer is invalid. */
  378. if (pointer == 0xFFFF || pointer == 0 ||
  379. pointer >= hw->eeprom.word_size)
  380. continue;
  381. if (ixgbe_read_eerd_generic(hw, pointer, &length) != 0) {
  382. hw_dbg(hw, "EEPROM read failed\n");
  383. break;
  384. }
  385. /* Skip pointer section if length is invalid. */
  386. if (length == 0xFFFF || length == 0 ||
  387. (pointer + length) >= hw->eeprom.word_size)
  388. continue;
  389. for (j = pointer+1; j <= pointer+length; j++) {
  390. if (ixgbe_read_eerd_generic(hw, j, &word) != 0) {
  391. hw_dbg(hw, "EEPROM read failed\n");
  392. break;
  393. }
  394. checksum += word;
  395. }
  396. }
  397. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  398. return checksum;
  399. }
  400. /**
  401. * ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum
  402. * @hw: pointer to hardware structure
  403. * @checksum_val: calculated checksum
  404. *
  405. * Performs checksum calculation and validates the EEPROM checksum. If the
  406. * caller does not need checksum_val, the value can be NULL.
  407. **/
  408. static s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw,
  409. u16 *checksum_val)
  410. {
  411. s32 status;
  412. u16 checksum;
  413. u16 read_checksum = 0;
  414. /*
  415. * Read the first word from the EEPROM. If this times out or fails, do
  416. * not continue or we could be in for a very long wait while every
  417. * EEPROM read fails
  418. */
  419. status = hw->eeprom.ops.read(hw, 0, &checksum);
  420. if (status != 0) {
  421. hw_dbg(hw, "EEPROM read failed\n");
  422. goto out;
  423. }
  424. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  425. checksum = hw->eeprom.ops.calc_checksum(hw);
  426. /*
  427. * Do not use hw->eeprom.ops.read because we do not want to take
  428. * the synchronization semaphores twice here.
  429. */
  430. ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
  431. &read_checksum);
  432. /*
  433. * Verify read checksum from EEPROM is the same as
  434. * calculated checksum
  435. */
  436. if (read_checksum != checksum)
  437. status = IXGBE_ERR_EEPROM_CHECKSUM;
  438. /* If the user cares, return the calculated checksum */
  439. if (checksum_val)
  440. *checksum_val = checksum;
  441. } else {
  442. status = IXGBE_ERR_SWFW_SYNC;
  443. }
  444. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  445. out:
  446. return status;
  447. }
  448. /**
  449. * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
  450. * @hw: pointer to hardware structure
  451. *
  452. * After writing EEPROM to shadow RAM using EEWR register, software calculates
  453. * checksum and updates the EEPROM and instructs the hardware to update
  454. * the flash.
  455. **/
  456. static s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
  457. {
  458. s32 status;
  459. u16 checksum;
  460. /*
  461. * Read the first word from the EEPROM. If this times out or fails, do
  462. * not continue or we could be in for a very long wait while every
  463. * EEPROM read fails
  464. */
  465. status = hw->eeprom.ops.read(hw, 0, &checksum);
  466. if (status != 0)
  467. hw_dbg(hw, "EEPROM read failed\n");
  468. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  469. checksum = hw->eeprom.ops.calc_checksum(hw);
  470. /*
  471. * Do not use hw->eeprom.ops.write because we do not want to
  472. * take the synchronization semaphores twice here.
  473. */
  474. status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM,
  475. checksum);
  476. if (status == 0)
  477. status = ixgbe_update_flash_X540(hw);
  478. else
  479. status = IXGBE_ERR_SWFW_SYNC;
  480. }
  481. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  482. return status;
  483. }
  484. /**
  485. * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
  486. * @hw: pointer to hardware structure
  487. *
  488. * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
  489. * EEPROM from shadow RAM to the flash device.
  490. **/
  491. static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
  492. {
  493. u32 flup;
  494. s32 status = IXGBE_ERR_EEPROM;
  495. status = ixgbe_poll_flash_update_done_X540(hw);
  496. if (status == IXGBE_ERR_EEPROM) {
  497. hw_dbg(hw, "Flash update time out\n");
  498. goto out;
  499. }
  500. flup = IXGBE_READ_REG(hw, IXGBE_EEC) | IXGBE_EEC_FLUP;
  501. IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
  502. status = ixgbe_poll_flash_update_done_X540(hw);
  503. if (status == 0)
  504. hw_dbg(hw, "Flash update complete\n");
  505. else
  506. hw_dbg(hw, "Flash update time out\n");
  507. if (hw->revision_id == 0) {
  508. flup = IXGBE_READ_REG(hw, IXGBE_EEC);
  509. if (flup & IXGBE_EEC_SEC1VAL) {
  510. flup |= IXGBE_EEC_FLUP;
  511. IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
  512. }
  513. status = ixgbe_poll_flash_update_done_X540(hw);
  514. if (status == 0)
  515. hw_dbg(hw, "Flash update complete\n");
  516. else
  517. hw_dbg(hw, "Flash update time out\n");
  518. }
  519. out:
  520. return status;
  521. }
  522. /**
  523. * ixgbe_poll_flash_update_done_X540 - Poll flash update status
  524. * @hw: pointer to hardware structure
  525. *
  526. * Polls the FLUDONE (bit 26) of the EEC Register to determine when the
  527. * flash update is done.
  528. **/
  529. static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
  530. {
  531. u32 i;
  532. u32 reg;
  533. s32 status = IXGBE_ERR_EEPROM;
  534. for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
  535. reg = IXGBE_READ_REG(hw, IXGBE_EEC);
  536. if (reg & IXGBE_EEC_FLUDONE) {
  537. status = 0;
  538. break;
  539. }
  540. udelay(5);
  541. }
  542. return status;
  543. }
  544. /**
  545. * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
  546. * @hw: pointer to hardware structure
  547. * @mask: Mask to specify which semaphore to acquire
  548. *
  549. * Acquires the SWFW semaphore thought the SW_FW_SYNC register for
  550. * the specified function (CSR, PHY0, PHY1, NVM, Flash)
  551. **/
  552. static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
  553. {
  554. u32 swfw_sync;
  555. u32 swmask = mask;
  556. u32 fwmask = mask << 5;
  557. u32 hwmask = 0;
  558. u32 timeout = 200;
  559. u32 i;
  560. if (swmask == IXGBE_GSSR_EEP_SM)
  561. hwmask = IXGBE_GSSR_FLASH_SM;
  562. for (i = 0; i < timeout; i++) {
  563. /*
  564. * SW NVM semaphore bit is used for access to all
  565. * SW_FW_SYNC bits (not just NVM)
  566. */
  567. if (ixgbe_get_swfw_sync_semaphore(hw))
  568. return IXGBE_ERR_SWFW_SYNC;
  569. swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  570. if (!(swfw_sync & (fwmask | swmask | hwmask))) {
  571. swfw_sync |= swmask;
  572. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
  573. ixgbe_release_swfw_sync_semaphore(hw);
  574. break;
  575. } else {
  576. /*
  577. * Firmware currently using resource (fwmask),
  578. * hardware currently using resource (hwmask),
  579. * or other software thread currently using
  580. * resource (swmask)
  581. */
  582. ixgbe_release_swfw_sync_semaphore(hw);
  583. usleep_range(5000, 10000);
  584. }
  585. }
  586. /*
  587. * If the resource is not released by the FW/HW the SW can assume that
  588. * the FW/HW malfunctions. In that case the SW should sets the
  589. * SW bit(s) of the requested resource(s) while ignoring the
  590. * corresponding FW/HW bits in the SW_FW_SYNC register.
  591. */
  592. if (i >= timeout) {
  593. swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  594. if (swfw_sync & (fwmask | hwmask)) {
  595. if (ixgbe_get_swfw_sync_semaphore(hw))
  596. return IXGBE_ERR_SWFW_SYNC;
  597. swfw_sync |= swmask;
  598. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
  599. ixgbe_release_swfw_sync_semaphore(hw);
  600. }
  601. }
  602. usleep_range(5000, 10000);
  603. return 0;
  604. }
  605. /**
  606. * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
  607. * @hw: pointer to hardware structure
  608. * @mask: Mask to specify which semaphore to release
  609. *
  610. * Releases the SWFW semaphore through the SW_FW_SYNC register
  611. * for the specified function (CSR, PHY0, PHY1, EVM, Flash)
  612. **/
  613. static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
  614. {
  615. u32 swfw_sync;
  616. u32 swmask = mask;
  617. ixgbe_get_swfw_sync_semaphore(hw);
  618. swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  619. swfw_sync &= ~swmask;
  620. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
  621. ixgbe_release_swfw_sync_semaphore(hw);
  622. usleep_range(5000, 10000);
  623. }
  624. /**
  625. * ixgbe_get_nvm_semaphore - Get hardware semaphore
  626. * @hw: pointer to hardware structure
  627. *
  628. * Sets the hardware semaphores so SW/FW can gain control of shared resources
  629. **/
  630. static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
  631. {
  632. s32 status = IXGBE_ERR_EEPROM;
  633. u32 timeout = 2000;
  634. u32 i;
  635. u32 swsm;
  636. /* Get SMBI software semaphore between device drivers first */
  637. for (i = 0; i < timeout; i++) {
  638. /*
  639. * If the SMBI bit is 0 when we read it, then the bit will be
  640. * set and we have the semaphore
  641. */
  642. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  643. if (!(swsm & IXGBE_SWSM_SMBI)) {
  644. status = 0;
  645. break;
  646. }
  647. udelay(50);
  648. }
  649. /* Now get the semaphore between SW/FW through the REGSMP bit */
  650. if (status) {
  651. for (i = 0; i < timeout; i++) {
  652. swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  653. if (!(swsm & IXGBE_SWFW_REGSMP))
  654. break;
  655. udelay(50);
  656. }
  657. } else {
  658. hw_dbg(hw, "Software semaphore SMBI between device drivers "
  659. "not granted.\n");
  660. }
  661. return status;
  662. }
  663. /**
  664. * ixgbe_release_nvm_semaphore - Release hardware semaphore
  665. * @hw: pointer to hardware structure
  666. *
  667. * This function clears hardware semaphore bits.
  668. **/
  669. static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
  670. {
  671. u32 swsm;
  672. /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
  673. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  674. swsm &= ~IXGBE_SWSM_SMBI;
  675. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  676. swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
  677. swsm &= ~IXGBE_SWFW_REGSMP;
  678. IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swsm);
  679. IXGBE_WRITE_FLUSH(hw);
  680. }
  681. /**
  682. * ixgbe_blink_led_start_X540 - Blink LED based on index.
  683. * @hw: pointer to hardware structure
  684. * @index: led number to blink
  685. *
  686. * Devices that implement the version 2 interface:
  687. * X540
  688. **/
  689. static s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index)
  690. {
  691. u32 macc_reg;
  692. u32 ledctl_reg;
  693. /*
  694. * In order for the blink bit in the LED control register
  695. * to work, link and speed must be forced in the MAC. We
  696. * will reverse this when we stop the blinking.
  697. */
  698. macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
  699. macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS;
  700. IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
  701. /* Set the LED to LINK_UP + BLINK. */
  702. ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  703. ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
  704. ledctl_reg |= IXGBE_LED_BLINK(index);
  705. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
  706. IXGBE_WRITE_FLUSH(hw);
  707. return 0;
  708. }
  709. /**
  710. * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index.
  711. * @hw: pointer to hardware structure
  712. * @index: led number to stop blinking
  713. *
  714. * Devices that implement the version 2 interface:
  715. * X540
  716. **/
  717. static s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index)
  718. {
  719. u32 macc_reg;
  720. u32 ledctl_reg;
  721. /* Restore the LED to its default value. */
  722. ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  723. ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
  724. ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  725. ledctl_reg &= ~IXGBE_LED_BLINK(index);
  726. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
  727. /* Unforce link and speed in the MAC. */
  728. macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
  729. macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS);
  730. IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
  731. IXGBE_WRITE_FLUSH(hw);
  732. return 0;
  733. }
  734. static struct ixgbe_mac_operations mac_ops_X540 = {
  735. .init_hw = &ixgbe_init_hw_generic,
  736. .reset_hw = &ixgbe_reset_hw_X540,
  737. .start_hw = &ixgbe_start_hw_X540,
  738. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  739. .get_media_type = &ixgbe_get_media_type_X540,
  740. .get_supported_physical_layer =
  741. &ixgbe_get_supported_physical_layer_X540,
  742. .enable_rx_dma = &ixgbe_enable_rx_dma_generic,
  743. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  744. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  745. .get_device_caps = &ixgbe_get_device_caps_generic,
  746. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  747. .stop_adapter = &ixgbe_stop_adapter_generic,
  748. .get_bus_info = &ixgbe_get_bus_info_generic,
  749. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  750. .read_analog_reg8 = NULL,
  751. .write_analog_reg8 = NULL,
  752. .setup_link = &ixgbe_setup_mac_link_X540,
  753. .check_link = &ixgbe_check_mac_link_generic,
  754. .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
  755. .led_on = &ixgbe_led_on_generic,
  756. .led_off = &ixgbe_led_off_generic,
  757. .blink_led_start = &ixgbe_blink_led_start_X540,
  758. .blink_led_stop = &ixgbe_blink_led_stop_X540,
  759. .set_rar = &ixgbe_set_rar_generic,
  760. .clear_rar = &ixgbe_clear_rar_generic,
  761. .set_vmdq = &ixgbe_set_vmdq_generic,
  762. .clear_vmdq = &ixgbe_clear_vmdq_generic,
  763. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  764. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  765. .enable_mc = &ixgbe_enable_mc_generic,
  766. .disable_mc = &ixgbe_disable_mc_generic,
  767. .clear_vfta = &ixgbe_clear_vfta_generic,
  768. .set_vfta = &ixgbe_set_vfta_generic,
  769. .fc_enable = &ixgbe_fc_enable_generic,
  770. .init_uta_tables = &ixgbe_init_uta_tables_generic,
  771. .setup_sfp = NULL,
  772. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
  773. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
  774. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
  775. .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
  776. };
  777. static struct ixgbe_eeprom_operations eeprom_ops_X540 = {
  778. .init_params = &ixgbe_init_eeprom_params_X540,
  779. .read = &ixgbe_read_eerd_X540,
  780. .read_buffer = &ixgbe_read_eerd_buffer_X540,
  781. .write = &ixgbe_write_eewr_X540,
  782. .write_buffer = &ixgbe_write_eewr_buffer_X540,
  783. .calc_checksum = &ixgbe_calc_eeprom_checksum_X540,
  784. .validate_checksum = &ixgbe_validate_eeprom_checksum_X540,
  785. .update_checksum = &ixgbe_update_eeprom_checksum_X540,
  786. };
  787. static struct ixgbe_phy_operations phy_ops_X540 = {
  788. .identify = &ixgbe_identify_phy_generic,
  789. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  790. .init = NULL,
  791. .reset = NULL,
  792. .read_reg = &ixgbe_read_phy_reg_generic,
  793. .write_reg = &ixgbe_write_phy_reg_generic,
  794. .setup_link = &ixgbe_setup_phy_link_generic,
  795. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  796. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  797. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  798. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  799. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  800. .check_overtemp = &ixgbe_tn_check_overtemp,
  801. };
  802. struct ixgbe_info ixgbe_X540_info = {
  803. .mac = ixgbe_mac_X540,
  804. .get_invariants = &ixgbe_get_invariants_X540,
  805. .mac_ops = &mac_ops_X540,
  806. .eeprom_ops = &eeprom_ops_X540,
  807. .phy_ops = &phy_ops_X540,
  808. .mbx_ops = &mbx_ops_generic,
  809. };