ixgbe_x540.c 28 KB

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