ixgbe_x540.c 27 KB

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