ixgbe_x540.c 26 KB

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