igc_base.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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_reset_hw_base - Reset hardware
  47. * @hw: pointer to the HW structure
  48. *
  49. * This resets the hardware into a known state. This is a
  50. * function pointer entry point called by the api module.
  51. */
  52. static s32 igc_reset_hw_base(struct igc_hw *hw)
  53. {
  54. s32 ret_val;
  55. u32 ctrl;
  56. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  57. * on the last TLP read/write transaction when MAC is reset.
  58. */
  59. ret_val = igc_disable_pcie_master(hw);
  60. if (ret_val)
  61. hw_dbg("PCI-E Master disable polling has failed.\n");
  62. /* set the completion timeout for interface */
  63. ret_val = igc_set_pcie_completion_timeout(hw);
  64. if (ret_val)
  65. hw_dbg("PCI-E Set completion timeout has failed.\n");
  66. hw_dbg("Masking off all interrupts\n");
  67. wr32(IGC_IMC, 0xffffffff);
  68. wr32(IGC_RCTL, 0);
  69. wr32(IGC_TCTL, IGC_TCTL_PSP);
  70. wrfl();
  71. usleep_range(10000, 20000);
  72. ctrl = rd32(IGC_CTRL);
  73. hw_dbg("Issuing a global reset to MAC\n");
  74. wr32(IGC_CTRL, ctrl | IGC_CTRL_RST);
  75. ret_val = igc_get_auto_rd_done(hw);
  76. if (ret_val) {
  77. /* When auto config read does not complete, do not
  78. * return with an error. This can happen in situations
  79. * where there is no eeprom and prevents getting link.
  80. */
  81. hw_dbg("Auto Read Done did not complete\n");
  82. }
  83. /* Clear any pending interrupt events. */
  84. wr32(IGC_IMC, 0xffffffff);
  85. rd32(IGC_ICR);
  86. return ret_val;
  87. }
  88. /**
  89. * igc_init_mac_params_base - Init MAC func ptrs.
  90. * @hw: pointer to the HW structure
  91. */
  92. static s32 igc_init_mac_params_base(struct igc_hw *hw)
  93. {
  94. struct igc_mac_info *mac = &hw->mac;
  95. /* Set mta register count */
  96. mac->mta_reg_count = 128;
  97. mac->rar_entry_count = IGC_RAR_ENTRIES;
  98. /* reset */
  99. mac->ops.reset_hw = igc_reset_hw_base;
  100. mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
  101. mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
  102. return 0;
  103. }
  104. static s32 igc_get_invariants_base(struct igc_hw *hw)
  105. {
  106. u32 link_mode = 0;
  107. u32 ctrl_ext = 0;
  108. s32 ret_val = 0;
  109. ctrl_ext = rd32(IGC_CTRL_EXT);
  110. link_mode = ctrl_ext & IGC_CTRL_EXT_LINK_MODE_MASK;
  111. /* mac initialization and operations */
  112. ret_val = igc_init_mac_params_base(hw);
  113. if (ret_val)
  114. goto out;
  115. out:
  116. return ret_val;
  117. }
  118. /**
  119. * igc_init_hw_base - Initialize hardware
  120. * @hw: pointer to the HW structure
  121. *
  122. * This inits the hardware readying it for operation.
  123. */
  124. static s32 igc_init_hw_base(struct igc_hw *hw)
  125. {
  126. struct igc_mac_info *mac = &hw->mac;
  127. u16 i, rar_count = mac->rar_entry_count;
  128. s32 ret_val = 0;
  129. /* Setup the receive address */
  130. igc_init_rx_addrs(hw, rar_count);
  131. /* Zero out the Multicast HASH table */
  132. hw_dbg("Zeroing the MTA\n");
  133. for (i = 0; i < mac->mta_reg_count; i++)
  134. array_wr32(IGC_MTA, i, 0);
  135. /* Zero out the Unicast HASH table */
  136. hw_dbg("Zeroing the UTA\n");
  137. for (i = 0; i < mac->uta_reg_count; i++)
  138. array_wr32(IGC_UTA, i, 0);
  139. /* Setup link and flow control */
  140. ret_val = igc_setup_link(hw);
  141. /* Clear all of the statistics registers (clear on read). It is
  142. * important that we do this after we have tried to establish link
  143. * because the symbol error count will increment wildly if there
  144. * is no link.
  145. */
  146. igc_clear_hw_cntrs_base(hw);
  147. return ret_val;
  148. }
  149. /**
  150. * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
  151. * @hw: pointer to the HW structure
  152. *
  153. * After Rx enable, if manageability is enabled then there is likely some
  154. * bad data at the start of the fifo and possibly in the DMA fifo. This
  155. * function clears the fifos and flushes any packets that came in as rx was
  156. * being enabled.
  157. */
  158. void igc_rx_fifo_flush_base(struct igc_hw *hw)
  159. {
  160. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  161. int i, ms_wait;
  162. /* disable IPv6 options as per hardware errata */
  163. rfctl = rd32(IGC_RFCTL);
  164. rfctl |= IGC_RFCTL_IPV6_EX_DIS;
  165. wr32(IGC_RFCTL, rfctl);
  166. if (!(rd32(IGC_MANC) & IGC_MANC_RCV_TCO_EN))
  167. return;
  168. /* Disable all Rx queues */
  169. for (i = 0; i < 4; i++) {
  170. rxdctl[i] = rd32(IGC_RXDCTL(i));
  171. wr32(IGC_RXDCTL(i),
  172. rxdctl[i] & ~IGC_RXDCTL_QUEUE_ENABLE);
  173. }
  174. /* Poll all queues to verify they have shut down */
  175. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  176. usleep_range(1000, 2000);
  177. rx_enabled = 0;
  178. for (i = 0; i < 4; i++)
  179. rx_enabled |= rd32(IGC_RXDCTL(i));
  180. if (!(rx_enabled & IGC_RXDCTL_QUEUE_ENABLE))
  181. break;
  182. }
  183. if (ms_wait == 10)
  184. pr_debug("Queue disable timed out after 10ms\n");
  185. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  186. * incoming packets are rejected. Set enable and wait 2ms so that
  187. * any packet that was coming in as RCTL.EN was set is flushed
  188. */
  189. wr32(IGC_RFCTL, rfctl & ~IGC_RFCTL_LEF);
  190. rlpml = rd32(IGC_RLPML);
  191. wr32(IGC_RLPML, 0);
  192. rctl = rd32(IGC_RCTL);
  193. temp_rctl = rctl & ~(IGC_RCTL_EN | IGC_RCTL_SBP);
  194. temp_rctl |= IGC_RCTL_LPE;
  195. wr32(IGC_RCTL, temp_rctl);
  196. wr32(IGC_RCTL, temp_rctl | IGC_RCTL_EN);
  197. wrfl();
  198. usleep_range(2000, 3000);
  199. /* Enable Rx queues that were previously enabled and restore our
  200. * previous state
  201. */
  202. for (i = 0; i < 4; i++)
  203. wr32(IGC_RXDCTL(i), rxdctl[i]);
  204. wr32(IGC_RCTL, rctl);
  205. wrfl();
  206. wr32(IGC_RLPML, rlpml);
  207. wr32(IGC_RFCTL, rfctl);
  208. /* Flush receive errors generated by workaround */
  209. rd32(IGC_ROC);
  210. rd32(IGC_RNBC);
  211. rd32(IGC_MPC);
  212. }
  213. static struct igc_mac_operations igc_mac_ops_base = {
  214. .init_hw = igc_init_hw_base,
  215. };
  216. const struct igc_info igc_base_info = {
  217. .get_invariants = igc_get_invariants_base,
  218. .mac_ops = &igc_mac_ops_base,
  219. };