igc_base.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018 Intel Corporation */
  3. #include <linux/delay.h>
  4. #include "igc_hw.h"
  5. #include "igc_i225.h"
  6. #include "igc_mac.h"
  7. #include "igc_base.h"
  8. #include "igc.h"
  9. /**
  10. * igc_reset_hw_base - Reset hardware
  11. * @hw: pointer to the HW structure
  12. *
  13. * This resets the hardware into a known state. This is a
  14. * function pointer entry point called by the api module.
  15. */
  16. static s32 igc_reset_hw_base(struct igc_hw *hw)
  17. {
  18. s32 ret_val;
  19. u32 ctrl;
  20. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  21. * on the last TLP read/write transaction when MAC is reset.
  22. */
  23. ret_val = igc_disable_pcie_master(hw);
  24. if (ret_val)
  25. hw_dbg("PCI-E Master disable polling has failed\n");
  26. hw_dbg("Masking off all interrupts\n");
  27. wr32(IGC_IMC, 0xffffffff);
  28. wr32(IGC_RCTL, 0);
  29. wr32(IGC_TCTL, IGC_TCTL_PSP);
  30. wrfl();
  31. usleep_range(10000, 20000);
  32. ctrl = rd32(IGC_CTRL);
  33. hw_dbg("Issuing a global reset to MAC\n");
  34. wr32(IGC_CTRL, ctrl | IGC_CTRL_RST);
  35. ret_val = igc_get_auto_rd_done(hw);
  36. if (ret_val) {
  37. /* When auto config read does not complete, do not
  38. * return with an error. This can happen in situations
  39. * where there is no eeprom and prevents getting link.
  40. */
  41. hw_dbg("Auto Read Done did not complete\n");
  42. }
  43. /* Clear any pending interrupt events. */
  44. wr32(IGC_IMC, 0xffffffff);
  45. rd32(IGC_ICR);
  46. return ret_val;
  47. }
  48. /**
  49. * igc_init_nvm_params_base - Init NVM func ptrs.
  50. * @hw: pointer to the HW structure
  51. */
  52. static s32 igc_init_nvm_params_base(struct igc_hw *hw)
  53. {
  54. struct igc_nvm_info *nvm = &hw->nvm;
  55. u32 eecd = rd32(IGC_EECD);
  56. u16 size;
  57. /* failed to read reg and got all F's */
  58. if (!(~eecd))
  59. return -ENXIO;
  60. size = FIELD_GET(IGC_EECD_SIZE_EX_MASK, eecd);
  61. /* Added to a constant, "size" becomes the left-shift value
  62. * for setting word_size.
  63. */
  64. size += NVM_WORD_SIZE_BASE_SHIFT;
  65. /* Just in case size is out of range, cap it to the largest
  66. * EEPROM size supported
  67. */
  68. if (size > 15)
  69. size = 15;
  70. nvm->type = igc_nvm_eeprom_spi;
  71. nvm->word_size = BIT(size);
  72. nvm->opcode_bits = 8;
  73. nvm->delay_usec = 1;
  74. nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
  75. nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ?
  76. 16 : 8;
  77. if (nvm->word_size == BIT(15))
  78. nvm->page_size = 128;
  79. return 0;
  80. }
  81. /**
  82. * igc_setup_copper_link_base - Configure copper link settings
  83. * @hw: pointer to the HW structure
  84. *
  85. * Configures the link for auto-neg or forced speed and duplex. Then we check
  86. * for link, once link is established calls to configure collision distance
  87. * and flow control are called.
  88. */
  89. static s32 igc_setup_copper_link_base(struct igc_hw *hw)
  90. {
  91. s32 ret_val = 0;
  92. u32 ctrl;
  93. ctrl = rd32(IGC_CTRL);
  94. ctrl |= IGC_CTRL_SLU;
  95. ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
  96. wr32(IGC_CTRL, ctrl);
  97. ret_val = igc_setup_copper_link(hw);
  98. return ret_val;
  99. }
  100. /**
  101. * igc_init_mac_params_base - Init MAC func ptrs.
  102. * @hw: pointer to the HW structure
  103. */
  104. static s32 igc_init_mac_params_base(struct igc_hw *hw)
  105. {
  106. struct igc_dev_spec_base *dev_spec = &hw->dev_spec._base;
  107. struct igc_mac_info *mac = &hw->mac;
  108. /* Set mta register count */
  109. mac->mta_reg_count = 128;
  110. mac->rar_entry_count = IGC_RAR_ENTRIES;
  111. /* reset */
  112. mac->ops.reset_hw = igc_reset_hw_base;
  113. mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
  114. mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
  115. /* Allow a single clear of the SW semaphore on I225 */
  116. if (mac->type == igc_i225)
  117. dev_spec->clear_semaphore_once = true;
  118. /* physical interface link setup */
  119. mac->ops.setup_physical_interface = igc_setup_copper_link_base;
  120. return 0;
  121. }
  122. /**
  123. * igc_init_phy_params_base - Init PHY func ptrs.
  124. * @hw: pointer to the HW structure
  125. */
  126. static s32 igc_init_phy_params_base(struct igc_hw *hw)
  127. {
  128. struct igc_phy_info *phy = &hw->phy;
  129. s32 ret_val = 0;
  130. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT_2500;
  131. phy->reset_delay_us = 100;
  132. /* set lan id */
  133. hw->bus.func = FIELD_GET(IGC_STATUS_FUNC_MASK, rd32(IGC_STATUS));
  134. /* Make sure the PHY is in a good state. Several people have reported
  135. * firmware leaving the PHY's page select register set to something
  136. * other than the default of zero, which causes the PHY ID read to
  137. * access something other than the intended register.
  138. */
  139. ret_val = hw->phy.ops.reset(hw);
  140. if (ret_val) {
  141. hw_dbg("Error resetting the PHY\n");
  142. goto out;
  143. }
  144. ret_val = igc_get_phy_id(hw);
  145. if (ret_val)
  146. return ret_val;
  147. igc_check_for_copper_link(hw);
  148. out:
  149. return ret_val;
  150. }
  151. static s32 igc_get_invariants_base(struct igc_hw *hw)
  152. {
  153. struct igc_mac_info *mac = &hw->mac;
  154. s32 ret_val = 0;
  155. switch (hw->device_id) {
  156. case IGC_DEV_ID_I225_LM:
  157. case IGC_DEV_ID_I225_V:
  158. case IGC_DEV_ID_I225_I:
  159. case IGC_DEV_ID_I220_V:
  160. case IGC_DEV_ID_I225_K:
  161. case IGC_DEV_ID_I225_K2:
  162. case IGC_DEV_ID_I226_K:
  163. case IGC_DEV_ID_I225_LMVP:
  164. case IGC_DEV_ID_I226_LMVP:
  165. case IGC_DEV_ID_I225_IT:
  166. case IGC_DEV_ID_I226_LM:
  167. case IGC_DEV_ID_I226_V:
  168. case IGC_DEV_ID_I226_IT:
  169. case IGC_DEV_ID_I221_V:
  170. case IGC_DEV_ID_I226_BLANK_NVM:
  171. case IGC_DEV_ID_I225_BLANK_NVM:
  172. mac->type = igc_i225;
  173. break;
  174. default:
  175. return -IGC_ERR_MAC_INIT;
  176. }
  177. hw->phy.media_type = igc_media_type_copper;
  178. /* mac initialization and operations */
  179. ret_val = igc_init_mac_params_base(hw);
  180. if (ret_val)
  181. goto out;
  182. /* NVM initialization */
  183. ret_val = igc_init_nvm_params_base(hw);
  184. if (ret_val)
  185. goto out;
  186. switch (hw->mac.type) {
  187. case igc_i225:
  188. ret_val = igc_init_nvm_params_i225(hw);
  189. break;
  190. default:
  191. break;
  192. }
  193. /* setup PHY parameters */
  194. ret_val = igc_init_phy_params_base(hw);
  195. if (ret_val)
  196. goto out;
  197. out:
  198. return ret_val;
  199. }
  200. /**
  201. * igc_acquire_phy_base - Acquire rights to access PHY
  202. * @hw: pointer to the HW structure
  203. *
  204. * Acquire access rights to the correct PHY. This is a
  205. * function pointer entry point called by the api module.
  206. */
  207. static s32 igc_acquire_phy_base(struct igc_hw *hw)
  208. {
  209. u16 mask = IGC_SWFW_PHY0_SM;
  210. return hw->mac.ops.acquire_swfw_sync(hw, mask);
  211. }
  212. /**
  213. * igc_release_phy_base - Release rights to access PHY
  214. * @hw: pointer to the HW structure
  215. *
  216. * A wrapper to release access rights to the correct PHY. This is a
  217. * function pointer entry point called by the api module.
  218. */
  219. static void igc_release_phy_base(struct igc_hw *hw)
  220. {
  221. u16 mask = IGC_SWFW_PHY0_SM;
  222. hw->mac.ops.release_swfw_sync(hw, mask);
  223. }
  224. /**
  225. * igc_init_hw_base - Initialize hardware
  226. * @hw: pointer to the HW structure
  227. *
  228. * This inits the hardware readying it for operation.
  229. */
  230. static s32 igc_init_hw_base(struct igc_hw *hw)
  231. {
  232. struct igc_mac_info *mac = &hw->mac;
  233. u16 i, rar_count = mac->rar_entry_count;
  234. s32 ret_val = 0;
  235. /* Setup the receive address */
  236. igc_init_rx_addrs(hw, rar_count);
  237. /* Zero out the Multicast HASH table */
  238. hw_dbg("Zeroing the MTA\n");
  239. for (i = 0; i < mac->mta_reg_count; i++)
  240. array_wr32(IGC_MTA, i, 0);
  241. /* Zero out the Unicast HASH table */
  242. hw_dbg("Zeroing the UTA\n");
  243. for (i = 0; i < mac->uta_reg_count; i++)
  244. array_wr32(IGC_UTA, i, 0);
  245. /* Setup link and flow control */
  246. ret_val = igc_setup_link(hw);
  247. /* Clear all of the statistics registers (clear on read). It is
  248. * important that we do this after we have tried to establish link
  249. * because the symbol error count will increment wildly if there
  250. * is no link.
  251. */
  252. igc_clear_hw_cntrs_base(hw);
  253. return ret_val;
  254. }
  255. /**
  256. * igc_power_down_phy_copper_base - Remove link during PHY power down
  257. * @hw: pointer to the HW structure
  258. *
  259. * In the case of a PHY power down to save power, or to turn off link during a
  260. * driver unload, or wake on lan is not enabled, remove the link.
  261. */
  262. void igc_power_down_phy_copper_base(struct igc_hw *hw)
  263. {
  264. /* If the management interface is not enabled, then power down */
  265. if (!(igc_enable_mng_pass_thru(hw) || igc_check_reset_block(hw)))
  266. igc_power_down_phy_copper(hw);
  267. }
  268. /**
  269. * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
  270. * @hw: pointer to the HW structure
  271. *
  272. * After Rx enable, if manageability is enabled then there is likely some
  273. * bad data at the start of the fifo and possibly in the DMA fifo. This
  274. * function clears the fifos and flushes any packets that came in as rx was
  275. * being enabled.
  276. */
  277. void igc_rx_fifo_flush_base(struct igc_hw *hw)
  278. {
  279. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  280. int i, ms_wait;
  281. /* disable IPv6 options as per hardware errata */
  282. rfctl = rd32(IGC_RFCTL);
  283. rfctl |= IGC_RFCTL_IPV6_EX_DIS;
  284. wr32(IGC_RFCTL, rfctl);
  285. if (!(rd32(IGC_MANC) & IGC_MANC_RCV_TCO_EN))
  286. return;
  287. /* Disable all Rx queues */
  288. for (i = 0; i < 4; i++) {
  289. rxdctl[i] = rd32(IGC_RXDCTL(i));
  290. wr32(IGC_RXDCTL(i),
  291. rxdctl[i] & ~IGC_RXDCTL_QUEUE_ENABLE);
  292. }
  293. /* Poll all queues to verify they have shut down */
  294. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  295. usleep_range(1000, 2000);
  296. rx_enabled = 0;
  297. for (i = 0; i < 4; i++)
  298. rx_enabled |= rd32(IGC_RXDCTL(i));
  299. if (!(rx_enabled & IGC_RXDCTL_QUEUE_ENABLE))
  300. break;
  301. }
  302. if (ms_wait == 10)
  303. hw_dbg("Queue disable timed out after 10ms\n");
  304. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  305. * incoming packets are rejected. Set enable and wait 2ms so that
  306. * any packet that was coming in as RCTL.EN was set is flushed
  307. */
  308. wr32(IGC_RFCTL, rfctl & ~IGC_RFCTL_LEF);
  309. rlpml = rd32(IGC_RLPML);
  310. wr32(IGC_RLPML, 0);
  311. rctl = rd32(IGC_RCTL);
  312. temp_rctl = rctl & ~(IGC_RCTL_EN | IGC_RCTL_SBP);
  313. temp_rctl |= IGC_RCTL_LPE;
  314. wr32(IGC_RCTL, temp_rctl);
  315. wr32(IGC_RCTL, temp_rctl | IGC_RCTL_EN);
  316. wrfl();
  317. usleep_range(2000, 3000);
  318. /* Enable Rx queues that were previously enabled and restore our
  319. * previous state
  320. */
  321. for (i = 0; i < 4; i++)
  322. wr32(IGC_RXDCTL(i), rxdctl[i]);
  323. wr32(IGC_RCTL, rctl);
  324. wrfl();
  325. wr32(IGC_RLPML, rlpml);
  326. wr32(IGC_RFCTL, rfctl);
  327. /* Flush receive errors generated by workaround */
  328. rd32(IGC_ROC);
  329. rd32(IGC_RNBC);
  330. rd32(IGC_MPC);
  331. }
  332. bool igc_is_device_id_i225(struct igc_hw *hw)
  333. {
  334. switch (hw->device_id) {
  335. case IGC_DEV_ID_I225_LM:
  336. case IGC_DEV_ID_I225_V:
  337. case IGC_DEV_ID_I225_I:
  338. case IGC_DEV_ID_I225_K:
  339. case IGC_DEV_ID_I225_K2:
  340. case IGC_DEV_ID_I225_LMVP:
  341. case IGC_DEV_ID_I225_IT:
  342. return true;
  343. default:
  344. return false;
  345. }
  346. }
  347. bool igc_is_device_id_i226(struct igc_hw *hw)
  348. {
  349. switch (hw->device_id) {
  350. case IGC_DEV_ID_I226_LM:
  351. case IGC_DEV_ID_I226_V:
  352. case IGC_DEV_ID_I226_K:
  353. case IGC_DEV_ID_I226_IT:
  354. return true;
  355. default:
  356. return false;
  357. }
  358. }
  359. static struct igc_mac_operations igc_mac_ops_base = {
  360. .init_hw = igc_init_hw_base,
  361. .check_for_link = igc_check_for_copper_link,
  362. .rar_set = igc_rar_set,
  363. .read_mac_addr = igc_read_mac_addr,
  364. .get_speed_and_duplex = igc_get_speed_and_duplex_copper,
  365. };
  366. static const struct igc_phy_operations igc_phy_ops_base = {
  367. .acquire = igc_acquire_phy_base,
  368. .release = igc_release_phy_base,
  369. .reset = igc_phy_hw_reset,
  370. .read_reg = igc_read_phy_reg_gpy,
  371. .write_reg = igc_write_phy_reg_gpy,
  372. };
  373. const struct igc_info igc_base_info = {
  374. .get_invariants = igc_get_invariants_base,
  375. .mac_ops = &igc_mac_ops_base,
  376. .phy_ops = &igc_phy_ops_base,
  377. };