ixgbe_x540.c 27 KB

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