ixgbe_x540.c 25 KB

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