ixgbe_x540.c 27 KB

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