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