igc_mac.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018 Intel Corporation */
  3. #include <linux/pci.h>
  4. #include <linux/delay.h>
  5. #include "igc_mac.h"
  6. #include "igc_hw.h"
  7. /* forward declaration */
  8. static s32 igc_set_default_fc(struct igc_hw *hw);
  9. static s32 igc_set_fc_watermarks(struct igc_hw *hw);
  10. /**
  11. * igc_disable_pcie_master - Disables PCI-express master access
  12. * @hw: pointer to the HW structure
  13. *
  14. * Returns 0 (0) if successful, else returns -10
  15. * (-IGC_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
  16. * the master requests to be disabled.
  17. *
  18. * Disables PCI-Express master access and verifies there are no pending
  19. * requests.
  20. */
  21. s32 igc_disable_pcie_master(struct igc_hw *hw)
  22. {
  23. s32 timeout = MASTER_DISABLE_TIMEOUT;
  24. s32 ret_val = 0;
  25. u32 ctrl;
  26. ctrl = rd32(IGC_CTRL);
  27. ctrl |= IGC_CTRL_GIO_MASTER_DISABLE;
  28. wr32(IGC_CTRL, ctrl);
  29. while (timeout) {
  30. if (!(rd32(IGC_STATUS) &
  31. IGC_STATUS_GIO_MASTER_ENABLE))
  32. break;
  33. usleep_range(2000, 3000);
  34. timeout--;
  35. }
  36. if (!timeout) {
  37. hw_dbg("Master requests are pending.\n");
  38. ret_val = -IGC_ERR_MASTER_REQUESTS_PENDING;
  39. goto out;
  40. }
  41. out:
  42. return ret_val;
  43. }
  44. /**
  45. * igc_init_rx_addrs - Initialize receive addresses
  46. * @hw: pointer to the HW structure
  47. * @rar_count: receive address registers
  48. *
  49. * Setup the receive address registers by setting the base receive address
  50. * register to the devices MAC address and clearing all the other receive
  51. * address registers to 0.
  52. */
  53. void igc_init_rx_addrs(struct igc_hw *hw, u16 rar_count)
  54. {
  55. u8 mac_addr[ETH_ALEN] = {0};
  56. u32 i;
  57. /* Setup the receive address */
  58. hw_dbg("Programming MAC Address into RAR[0]\n");
  59. hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
  60. /* Zero out the other (rar_entry_count - 1) receive addresses */
  61. hw_dbg("Clearing RAR[1-%u]\n", rar_count - 1);
  62. for (i = 1; i < rar_count; i++)
  63. hw->mac.ops.rar_set(hw, mac_addr, i);
  64. }
  65. /**
  66. * igc_setup_link - Setup flow control and link settings
  67. * @hw: pointer to the HW structure
  68. *
  69. * Determines which flow control settings to use, then configures flow
  70. * control. Calls the appropriate media-specific link configuration
  71. * function. Assuming the adapter has a valid link partner, a valid link
  72. * should be established. Assumes the hardware has previously been reset
  73. * and the transmitter and receiver are not enabled.
  74. */
  75. s32 igc_setup_link(struct igc_hw *hw)
  76. {
  77. s32 ret_val = 0;
  78. /* In the case of the phy reset being blocked, we already have a link.
  79. * We do not need to set it up again.
  80. */
  81. /* If requested flow control is set to default, set flow control
  82. * based on the EEPROM flow control settings.
  83. */
  84. if (hw->fc.requested_mode == igc_fc_default) {
  85. ret_val = igc_set_default_fc(hw);
  86. if (ret_val)
  87. goto out;
  88. }
  89. /* We want to save off the original Flow Control configuration just
  90. * in case we get disconnected and then reconnected into a different
  91. * hub or switch with different Flow Control capabilities.
  92. */
  93. hw->fc.current_mode = hw->fc.requested_mode;
  94. hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
  95. /* Call the necessary media_type subroutine to configure the link. */
  96. ret_val = hw->mac.ops.setup_physical_interface(hw);
  97. if (ret_val)
  98. goto out;
  99. /* Initialize the flow control address, type, and PAUSE timer
  100. * registers to their default values. This is done even if flow
  101. * control is disabled, because it does not hurt anything to
  102. * initialize these registers.
  103. */
  104. hw_dbg("Initializing the Flow Control address, type and timer regs\n");
  105. wr32(IGC_FCT, FLOW_CONTROL_TYPE);
  106. wr32(IGC_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  107. wr32(IGC_FCAL, FLOW_CONTROL_ADDRESS_LOW);
  108. wr32(IGC_FCTTV, hw->fc.pause_time);
  109. ret_val = igc_set_fc_watermarks(hw);
  110. out:
  111. return ret_val;
  112. }
  113. /**
  114. * igc_set_default_fc - Set flow control default values
  115. * @hw: pointer to the HW structure
  116. *
  117. * Read the EEPROM for the default values for flow control and store the
  118. * values.
  119. */
  120. static s32 igc_set_default_fc(struct igc_hw *hw)
  121. {
  122. return 0;
  123. }
  124. /**
  125. * igc_set_fc_watermarks - Set flow control high/low watermarks
  126. * @hw: pointer to the HW structure
  127. *
  128. * Sets the flow control high/low threshold (watermark) registers. If
  129. * flow control XON frame transmission is enabled, then set XON frame
  130. * transmission as well.
  131. */
  132. static s32 igc_set_fc_watermarks(struct igc_hw *hw)
  133. {
  134. u32 fcrtl = 0, fcrth = 0;
  135. /* Set the flow control receive threshold registers. Normally,
  136. * these registers will be set to a default threshold that may be
  137. * adjusted later by the driver's runtime code. However, if the
  138. * ability to transmit pause frames is not enabled, then these
  139. * registers will be set to 0.
  140. */
  141. if (hw->fc.current_mode & igc_fc_tx_pause) {
  142. /* We need to set up the Receive Threshold high and low water
  143. * marks as well as (optionally) enabling the transmission of
  144. * XON frames.
  145. */
  146. fcrtl = hw->fc.low_water;
  147. if (hw->fc.send_xon)
  148. fcrtl |= IGC_FCRTL_XONE;
  149. fcrth = hw->fc.high_water;
  150. }
  151. wr32(IGC_FCRTL, fcrtl);
  152. wr32(IGC_FCRTH, fcrth);
  153. return 0;
  154. }
  155. /**
  156. * igc_clear_hw_cntrs_base - Clear base hardware counters
  157. * @hw: pointer to the HW structure
  158. *
  159. * Clears the base hardware counters by reading the counter registers.
  160. */
  161. void igc_clear_hw_cntrs_base(struct igc_hw *hw)
  162. {
  163. rd32(IGC_CRCERRS);
  164. rd32(IGC_SYMERRS);
  165. rd32(IGC_MPC);
  166. rd32(IGC_SCC);
  167. rd32(IGC_ECOL);
  168. rd32(IGC_MCC);
  169. rd32(IGC_LATECOL);
  170. rd32(IGC_COLC);
  171. rd32(IGC_DC);
  172. rd32(IGC_SEC);
  173. rd32(IGC_RLEC);
  174. rd32(IGC_XONRXC);
  175. rd32(IGC_XONTXC);
  176. rd32(IGC_XOFFRXC);
  177. rd32(IGC_XOFFTXC);
  178. rd32(IGC_FCRUC);
  179. rd32(IGC_GPRC);
  180. rd32(IGC_BPRC);
  181. rd32(IGC_MPRC);
  182. rd32(IGC_GPTC);
  183. rd32(IGC_GORCL);
  184. rd32(IGC_GORCH);
  185. rd32(IGC_GOTCL);
  186. rd32(IGC_GOTCH);
  187. rd32(IGC_RNBC);
  188. rd32(IGC_RUC);
  189. rd32(IGC_RFC);
  190. rd32(IGC_ROC);
  191. rd32(IGC_RJC);
  192. rd32(IGC_TORL);
  193. rd32(IGC_TORH);
  194. rd32(IGC_TOTL);
  195. rd32(IGC_TOTH);
  196. rd32(IGC_TPR);
  197. rd32(IGC_TPT);
  198. rd32(IGC_MPTC);
  199. rd32(IGC_BPTC);
  200. rd32(IGC_PRC64);
  201. rd32(IGC_PRC127);
  202. rd32(IGC_PRC255);
  203. rd32(IGC_PRC511);
  204. rd32(IGC_PRC1023);
  205. rd32(IGC_PRC1522);
  206. rd32(IGC_PTC64);
  207. rd32(IGC_PTC127);
  208. rd32(IGC_PTC255);
  209. rd32(IGC_PTC511);
  210. rd32(IGC_PTC1023);
  211. rd32(IGC_PTC1522);
  212. rd32(IGC_ALGNERRC);
  213. rd32(IGC_RXERRC);
  214. rd32(IGC_TNCRS);
  215. rd32(IGC_CEXTERR);
  216. rd32(IGC_TSCTC);
  217. rd32(IGC_TSCTFC);
  218. rd32(IGC_MGTPRC);
  219. rd32(IGC_MGTPDC);
  220. rd32(IGC_MGTPTC);
  221. rd32(IGC_IAC);
  222. rd32(IGC_ICRXOC);
  223. rd32(IGC_ICRXPTC);
  224. rd32(IGC_ICRXATC);
  225. rd32(IGC_ICTXPTC);
  226. rd32(IGC_ICTXATC);
  227. rd32(IGC_ICTXQEC);
  228. rd32(IGC_ICTXQMTC);
  229. rd32(IGC_ICRXDMTC);
  230. rd32(IGC_CBTMPC);
  231. rd32(IGC_HTDPMC);
  232. rd32(IGC_CBRMPC);
  233. rd32(IGC_RPTHC);
  234. rd32(IGC_HGPTC);
  235. rd32(IGC_HTCBDPC);
  236. rd32(IGC_HGORCL);
  237. rd32(IGC_HGORCH);
  238. rd32(IGC_HGOTCL);
  239. rd32(IGC_HGOTCH);
  240. rd32(IGC_LENERRS);
  241. }
  242. /**
  243. * igc_get_auto_rd_done - Check for auto read completion
  244. * @hw: pointer to the HW structure
  245. *
  246. * Check EEPROM for Auto Read done bit.
  247. */
  248. s32 igc_get_auto_rd_done(struct igc_hw *hw)
  249. {
  250. s32 ret_val = 0;
  251. s32 i = 0;
  252. while (i < AUTO_READ_DONE_TIMEOUT) {
  253. if (rd32(IGC_EECD) & IGC_EECD_AUTO_RD)
  254. break;
  255. usleep_range(1000, 2000);
  256. i++;
  257. }
  258. if (i == AUTO_READ_DONE_TIMEOUT) {
  259. hw_dbg("Auto read by HW from NVM has not completed.\n");
  260. ret_val = -IGC_ERR_RESET;
  261. goto out;
  262. }
  263. out:
  264. return ret_val;
  265. }
  266. /**
  267. * igc_put_hw_semaphore - Release hardware semaphore
  268. * @hw: pointer to the HW structure
  269. *
  270. * Release hardware semaphore used to access the PHY or NVM
  271. */
  272. void igc_put_hw_semaphore(struct igc_hw *hw)
  273. {
  274. u32 swsm;
  275. swsm = rd32(IGC_SWSM);
  276. swsm &= ~(IGC_SWSM_SMBI | IGC_SWSM_SWESMBI);
  277. wr32(IGC_SWSM, swsm);
  278. }