igc_base.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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_set_pcie_completion_timeout - set pci-e completion timeout
  11. * @hw: pointer to the HW structure
  12. */
  13. static s32 igc_set_pcie_completion_timeout(struct igc_hw *hw)
  14. {
  15. u32 gcr = rd32(IGC_GCR);
  16. u16 pcie_devctl2;
  17. s32 ret_val = 0;
  18. /* only take action if timeout value is defaulted to 0 */
  19. if (gcr & IGC_GCR_CMPL_TMOUT_MASK)
  20. goto out;
  21. /* if capabilities version is type 1 we can write the
  22. * timeout of 10ms to 200ms through the GCR register
  23. */
  24. if (!(gcr & IGC_GCR_CAP_VER2)) {
  25. gcr |= IGC_GCR_CMPL_TMOUT_10ms;
  26. goto out;
  27. }
  28. /* for version 2 capabilities we need to write the config space
  29. * directly in order to set the completion timeout value for
  30. * 16ms to 55ms
  31. */
  32. ret_val = igc_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  33. &pcie_devctl2);
  34. if (ret_val)
  35. goto out;
  36. pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
  37. ret_val = igc_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  38. &pcie_devctl2);
  39. out:
  40. /* disable completion timeout resend */
  41. gcr &= ~IGC_GCR_CMPL_TMOUT_RESEND;
  42. wr32(IGC_GCR, gcr);
  43. return ret_val;
  44. }
  45. /**
  46. * igc_check_for_link_base - Check for link
  47. * @hw: pointer to the HW structure
  48. *
  49. * If sgmii is enabled, then use the pcs register to determine link, otherwise
  50. * use the generic interface for determining link.
  51. */
  52. static s32 igc_check_for_link_base(struct igc_hw *hw)
  53. {
  54. s32 ret_val = 0;
  55. ret_val = igc_check_for_copper_link(hw);
  56. return ret_val;
  57. }
  58. /**
  59. * igc_reset_hw_base - Reset hardware
  60. * @hw: pointer to the HW structure
  61. *
  62. * This resets the hardware into a known state. This is a
  63. * function pointer entry point called by the api module.
  64. */
  65. static s32 igc_reset_hw_base(struct igc_hw *hw)
  66. {
  67. s32 ret_val;
  68. u32 ctrl;
  69. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  70. * on the last TLP read/write transaction when MAC is reset.
  71. */
  72. ret_val = igc_disable_pcie_master(hw);
  73. if (ret_val)
  74. hw_dbg("PCI-E Master disable polling has failed.\n");
  75. /* set the completion timeout for interface */
  76. ret_val = igc_set_pcie_completion_timeout(hw);
  77. if (ret_val)
  78. hw_dbg("PCI-E Set completion timeout has failed.\n");
  79. hw_dbg("Masking off all interrupts\n");
  80. wr32(IGC_IMC, 0xffffffff);
  81. wr32(IGC_RCTL, 0);
  82. wr32(IGC_TCTL, IGC_TCTL_PSP);
  83. wrfl();
  84. usleep_range(10000, 20000);
  85. ctrl = rd32(IGC_CTRL);
  86. hw_dbg("Issuing a global reset to MAC\n");
  87. wr32(IGC_CTRL, ctrl | IGC_CTRL_RST);
  88. ret_val = igc_get_auto_rd_done(hw);
  89. if (ret_val) {
  90. /* When auto config read does not complete, do not
  91. * return with an error. This can happen in situations
  92. * where there is no eeprom and prevents getting link.
  93. */
  94. hw_dbg("Auto Read Done did not complete\n");
  95. }
  96. /* Clear any pending interrupt events. */
  97. wr32(IGC_IMC, 0xffffffff);
  98. rd32(IGC_ICR);
  99. return ret_val;
  100. }
  101. /**
  102. * igc_init_nvm_params_base - Init NVM func ptrs.
  103. * @hw: pointer to the HW structure
  104. */
  105. static s32 igc_init_nvm_params_base(struct igc_hw *hw)
  106. {
  107. struct igc_nvm_info *nvm = &hw->nvm;
  108. u32 eecd = rd32(IGC_EECD);
  109. u16 size;
  110. size = (u16)((eecd & IGC_EECD_SIZE_EX_MASK) >>
  111. IGC_EECD_SIZE_EX_SHIFT);
  112. /* Added to a constant, "size" becomes the left-shift value
  113. * for setting word_size.
  114. */
  115. size += NVM_WORD_SIZE_BASE_SHIFT;
  116. /* Just in case size is out of range, cap it to the largest
  117. * EEPROM size supported
  118. */
  119. if (size > 15)
  120. size = 15;
  121. nvm->word_size = BIT(size);
  122. nvm->opcode_bits = 8;
  123. nvm->delay_usec = 1;
  124. nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
  125. nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ?
  126. 16 : 8;
  127. if (nvm->word_size == BIT(15))
  128. nvm->page_size = 128;
  129. return 0;
  130. }
  131. /**
  132. * igc_init_mac_params_base - Init MAC func ptrs.
  133. * @hw: pointer to the HW structure
  134. */
  135. static s32 igc_init_mac_params_base(struct igc_hw *hw)
  136. {
  137. struct igc_dev_spec_base *dev_spec = &hw->dev_spec._base;
  138. struct igc_mac_info *mac = &hw->mac;
  139. /* Set mta register count */
  140. mac->mta_reg_count = 128;
  141. mac->rar_entry_count = IGC_RAR_ENTRIES;
  142. /* reset */
  143. mac->ops.reset_hw = igc_reset_hw_base;
  144. mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
  145. mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
  146. /* Allow a single clear of the SW semaphore on I225 */
  147. if (mac->type == igc_i225)
  148. dev_spec->clear_semaphore_once = true;
  149. return 0;
  150. }
  151. static s32 igc_get_invariants_base(struct igc_hw *hw)
  152. {
  153. u32 link_mode = 0;
  154. u32 ctrl_ext = 0;
  155. s32 ret_val = 0;
  156. ctrl_ext = rd32(IGC_CTRL_EXT);
  157. link_mode = ctrl_ext & IGC_CTRL_EXT_LINK_MODE_MASK;
  158. /* mac initialization and operations */
  159. ret_val = igc_init_mac_params_base(hw);
  160. if (ret_val)
  161. goto out;
  162. /* NVM initialization */
  163. ret_val = igc_init_nvm_params_base(hw);
  164. switch (hw->mac.type) {
  165. case igc_i225:
  166. ret_val = igc_init_nvm_params_i225(hw);
  167. break;
  168. default:
  169. break;
  170. }
  171. if (ret_val)
  172. goto out;
  173. out:
  174. return ret_val;
  175. }
  176. /**
  177. * igc_get_link_up_info_base - Get link speed/duplex info
  178. * @hw: pointer to the HW structure
  179. * @speed: stores the current speed
  180. * @duplex: stores the current duplex
  181. *
  182. * This is a wrapper function, if using the serial gigabit media independent
  183. * interface, use PCS to retrieve the link speed and duplex information.
  184. * Otherwise, use the generic function to get the link speed and duplex info.
  185. */
  186. static s32 igc_get_link_up_info_base(struct igc_hw *hw, u16 *speed,
  187. u16 *duplex)
  188. {
  189. s32 ret_val;
  190. ret_val = igc_get_speed_and_duplex_copper(hw, speed, duplex);
  191. return ret_val;
  192. }
  193. /**
  194. * igc_init_hw_base - Initialize hardware
  195. * @hw: pointer to the HW structure
  196. *
  197. * This inits the hardware readying it for operation.
  198. */
  199. static s32 igc_init_hw_base(struct igc_hw *hw)
  200. {
  201. struct igc_mac_info *mac = &hw->mac;
  202. u16 i, rar_count = mac->rar_entry_count;
  203. s32 ret_val = 0;
  204. /* Setup the receive address */
  205. igc_init_rx_addrs(hw, rar_count);
  206. /* Zero out the Multicast HASH table */
  207. hw_dbg("Zeroing the MTA\n");
  208. for (i = 0; i < mac->mta_reg_count; i++)
  209. array_wr32(IGC_MTA, i, 0);
  210. /* Zero out the Unicast HASH table */
  211. hw_dbg("Zeroing the UTA\n");
  212. for (i = 0; i < mac->uta_reg_count; i++)
  213. array_wr32(IGC_UTA, i, 0);
  214. /* Setup link and flow control */
  215. ret_val = igc_setup_link(hw);
  216. /* Clear all of the statistics registers (clear on read). It is
  217. * important that we do this after we have tried to establish link
  218. * because the symbol error count will increment wildly if there
  219. * is no link.
  220. */
  221. igc_clear_hw_cntrs_base(hw);
  222. return ret_val;
  223. }
  224. /**
  225. * igc_read_mac_addr_base - Read device MAC address
  226. * @hw: pointer to the HW structure
  227. */
  228. static s32 igc_read_mac_addr_base(struct igc_hw *hw)
  229. {
  230. s32 ret_val = 0;
  231. ret_val = igc_read_mac_addr(hw);
  232. return ret_val;
  233. }
  234. /**
  235. * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
  236. * @hw: pointer to the HW structure
  237. *
  238. * After Rx enable, if manageability is enabled then there is likely some
  239. * bad data at the start of the fifo and possibly in the DMA fifo. This
  240. * function clears the fifos and flushes any packets that came in as rx was
  241. * being enabled.
  242. */
  243. void igc_rx_fifo_flush_base(struct igc_hw *hw)
  244. {
  245. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  246. int i, ms_wait;
  247. /* disable IPv6 options as per hardware errata */
  248. rfctl = rd32(IGC_RFCTL);
  249. rfctl |= IGC_RFCTL_IPV6_EX_DIS;
  250. wr32(IGC_RFCTL, rfctl);
  251. if (!(rd32(IGC_MANC) & IGC_MANC_RCV_TCO_EN))
  252. return;
  253. /* Disable all Rx queues */
  254. for (i = 0; i < 4; i++) {
  255. rxdctl[i] = rd32(IGC_RXDCTL(i));
  256. wr32(IGC_RXDCTL(i),
  257. rxdctl[i] & ~IGC_RXDCTL_QUEUE_ENABLE);
  258. }
  259. /* Poll all queues to verify they have shut down */
  260. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  261. usleep_range(1000, 2000);
  262. rx_enabled = 0;
  263. for (i = 0; i < 4; i++)
  264. rx_enabled |= rd32(IGC_RXDCTL(i));
  265. if (!(rx_enabled & IGC_RXDCTL_QUEUE_ENABLE))
  266. break;
  267. }
  268. if (ms_wait == 10)
  269. pr_debug("Queue disable timed out after 10ms\n");
  270. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  271. * incoming packets are rejected. Set enable and wait 2ms so that
  272. * any packet that was coming in as RCTL.EN was set is flushed
  273. */
  274. wr32(IGC_RFCTL, rfctl & ~IGC_RFCTL_LEF);
  275. rlpml = rd32(IGC_RLPML);
  276. wr32(IGC_RLPML, 0);
  277. rctl = rd32(IGC_RCTL);
  278. temp_rctl = rctl & ~(IGC_RCTL_EN | IGC_RCTL_SBP);
  279. temp_rctl |= IGC_RCTL_LPE;
  280. wr32(IGC_RCTL, temp_rctl);
  281. wr32(IGC_RCTL, temp_rctl | IGC_RCTL_EN);
  282. wrfl();
  283. usleep_range(2000, 3000);
  284. /* Enable Rx queues that were previously enabled and restore our
  285. * previous state
  286. */
  287. for (i = 0; i < 4; i++)
  288. wr32(IGC_RXDCTL(i), rxdctl[i]);
  289. wr32(IGC_RCTL, rctl);
  290. wrfl();
  291. wr32(IGC_RLPML, rlpml);
  292. wr32(IGC_RFCTL, rfctl);
  293. /* Flush receive errors generated by workaround */
  294. rd32(IGC_ROC);
  295. rd32(IGC_RNBC);
  296. rd32(IGC_MPC);
  297. }
  298. static struct igc_mac_operations igc_mac_ops_base = {
  299. .init_hw = igc_init_hw_base,
  300. .check_for_link = igc_check_for_link_base,
  301. .rar_set = igc_rar_set,
  302. .read_mac_addr = igc_read_mac_addr_base,
  303. .get_speed_and_duplex = igc_get_link_up_info_base,
  304. };
  305. const struct igc_info igc_base_info = {
  306. .get_invariants = igc_get_invariants_base,
  307. .mac_ops = &igc_mac_ops_base,
  308. };