Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include "txgbe_type.h"
7 : : #include "txgbe_mbx.h"
8 : : #include "txgbe_phy.h"
9 : : #include "txgbe_dcb.h"
10 : : #include "txgbe_vf.h"
11 : : #include "txgbe_eeprom.h"
12 : : #include "txgbe_mng.h"
13 : : #include "txgbe_hw.h"
14 : :
15 : : #define TXGBE_RAPTOR_MAX_TX_QUEUES 128
16 : : #define TXGBE_RAPTOR_MAX_RX_QUEUES 128
17 : : #define TXGBE_RAPTOR_RAR_ENTRIES 128
18 : : #define TXGBE_RAPTOR_MC_TBL_SIZE 128
19 : : #define TXGBE_RAPTOR_VFT_TBL_SIZE 128
20 : : #define TXGBE_RAPTOR_RX_PB_SIZE 512 /*KB*/
21 : :
22 : : static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
23 : : u32 speed,
24 : : bool autoneg_wait_to_complete);
25 : :
26 : : static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr);
27 : : static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
28 : : u16 *san_mac_offset);
29 : :
30 : 0 : static s32 txgbe_is_lldp(struct txgbe_hw *hw)
31 : : {
32 : 0 : u32 tmp = 0, lldp_flash_data = 0, i;
33 : : s32 err = 0;
34 : :
35 [ # # ]: 0 : if ((hw->fw_version & TXGBE_FW_MASK) >= TXGBE_FW_GET_LLDP) {
36 : 0 : err = txgbe_hic_get_lldp(hw);
37 [ # # ]: 0 : if (err == 0)
38 : : return 0;
39 : : }
40 : :
41 [ # # ]: 0 : for (i = 0; i < 1024; i++) {
42 : 0 : err = txgbe_flash_read_dword(hw, TXGBE_LLDP_REG + i * 4, &tmp);
43 [ # # ]: 0 : if (err)
44 : 0 : return err;
45 : :
46 [ # # ]: 0 : if (tmp == BIT_MASK32)
47 : : break;
48 : : lldp_flash_data = tmp;
49 : : }
50 : :
51 [ # # ]: 0 : if (lldp_flash_data & MS(hw->bus.lan_id, 1))
52 : 0 : hw->lldp_enabled = true;
53 : : else
54 : 0 : hw->lldp_enabled = false;
55 : :
56 : : return 0;
57 : : }
58 : :
59 : 0 : static void txgbe_disable_lldp(struct txgbe_hw *hw)
60 : : {
61 : : s32 status = 0;
62 : :
63 [ # # ]: 0 : if ((hw->fw_version & TXGBE_FW_MASK) < TXGBE_FW_SUPPORT_LLDP)
64 : : return;
65 : :
66 : 0 : status = txgbe_is_lldp(hw);
67 [ # # ]: 0 : if (status) {
68 : 0 : PMD_INIT_LOG(INFO, "Can not get LLDP status.");
69 [ # # ]: 0 : } else if (hw->lldp_enabled) {
70 : 0 : status = txgbe_hic_set_lldp(hw, false);
71 [ # # ]: 0 : if (!status)
72 : 0 : PMD_INIT_LOG(INFO,
73 : : "LLDP detected on port %d, turn it off by default.",
74 : : hw->port_id);
75 : : else
76 : 0 : PMD_INIT_LOG(INFO, "Can not set LLDP status.");
77 : : }
78 : : }
79 : :
80 : : /**
81 : : * txgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
82 : : * of flow control
83 : : * @hw: pointer to hardware structure
84 : : *
85 : : * This function returns true if the device supports flow control
86 : : * autonegotiation, and false if it does not.
87 : : *
88 : : **/
89 : 0 : bool txgbe_device_supports_autoneg_fc(struct txgbe_hw *hw)
90 : : {
91 : : bool supported = false;
92 : : u32 speed;
93 : : bool link_up;
94 : :
95 [ # # # # ]: 0 : switch (hw->phy.media_type) {
96 : 0 : case txgbe_media_type_fiber_qsfp:
97 : : case txgbe_media_type_fiber:
98 : 0 : hw->mac.check_link(hw, &speed, &link_up, false);
99 : : /* if link is down, assume supported */
100 [ # # ]: 0 : if (link_up)
101 : 0 : supported = speed == TXGBE_LINK_SPEED_1GB_FULL ?
102 : 0 : true : false;
103 : : else
104 : : supported = true;
105 : :
106 : : break;
107 : : case txgbe_media_type_backplane:
108 : : supported = true;
109 : : break;
110 : 0 : case txgbe_media_type_copper:
111 : : /* only some copper devices support flow control autoneg */
112 [ # # ]: 0 : switch (hw->subsystem_device_id & 0xFF) {
113 : : case TXGBE_DEV_ID_XAUI:
114 : : case TXGBE_DEV_ID_SGMII:
115 : : supported = true;
116 : : break;
117 : : default:
118 : : supported = false;
119 : : }
120 : : default:
121 : : break;
122 : : }
123 : :
124 [ # # ]: 0 : if (!supported)
125 : 0 : DEBUGOUT("Device %x does not support flow control autoneg",
126 : : hw->device_id);
127 : 0 : return supported;
128 : : }
129 : :
130 : : /**
131 : : * txgbe_setup_fc - Set up flow control
132 : : * @hw: pointer to hardware structure
133 : : *
134 : : * Called at init time to set up flow control.
135 : : **/
136 : 0 : s32 txgbe_setup_fc(struct txgbe_hw *hw)
137 : : {
138 : : s32 err = 0;
139 : : u32 reg = 0;
140 : : u16 reg_cu = 0;
141 : : u32 value = 0;
142 : : u64 reg_bp = 0;
143 : :
144 : : /* Validate the requested mode */
145 [ # # # # ]: 0 : if (hw->fc.strict_ieee && hw->fc.requested_mode == txgbe_fc_rx_pause) {
146 : 0 : DEBUGOUT("txgbe_fc_rx_pause not valid in strict IEEE mode");
147 : : err = TXGBE_ERR_INVALID_LINK_SETTINGS;
148 : 0 : goto out;
149 : : }
150 : :
151 : : /*
152 : : * 10gig parts do not have a word in the EEPROM to determine the
153 : : * default flow control setting, so we explicitly set it to full.
154 : : */
155 [ # # ]: 0 : if (hw->fc.requested_mode == txgbe_fc_default)
156 : 0 : hw->fc.requested_mode = txgbe_fc_full;
157 : :
158 : : /*
159 : : * The possible values of fc.requested_mode are:
160 : : * 0: Flow control is completely disabled
161 : : * 1: Rx flow control is enabled (we can receive pause frames,
162 : : * but not send pause frames).
163 : : * 2: Tx flow control is enabled (we can send pause frames but
164 : : * we do not support receiving pause frames).
165 : : * 3: Both Rx and Tx flow control (symmetric) are enabled.
166 : : * other: Invalid.
167 : : */
168 [ # # ]: 0 : switch (hw->fc.requested_mode) {
169 : : case txgbe_fc_none:
170 : : /* Flow control completely disabled by software override. */
171 : : break;
172 : : case txgbe_fc_tx_pause:
173 : : /*
174 : : * Tx Flow control is enabled, and Rx Flow control is
175 : : * disabled by software override.
176 : : */
177 : : reg |= SR_MII_MMD_AN_ADV_PAUSE_ASM;
178 : : reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_ASM;
179 : : break;
180 : : case txgbe_fc_rx_pause:
181 : : /*
182 : : * Rx Flow control is enabled and Tx Flow control is
183 : : * disabled by software override. Since there really
184 : : * isn't a way to advertise that we are capable of RX
185 : : * Pause ONLY, we will advertise that we support both
186 : : * symmetric and asymmetric Rx PAUSE, as such we fall
187 : : * through to the fc_full statement. Later, we will
188 : : * disable the adapter's ability to send PAUSE frames.
189 : : */
190 : : case txgbe_fc_full:
191 : : /* Flow control (both Rx and Tx) is enabled by SW override. */
192 : : reg |= SR_MII_MMD_AN_ADV_PAUSE_SYM |
193 : : SR_MII_MMD_AN_ADV_PAUSE_ASM;
194 : : reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_SYM |
195 : : SR_AN_MMD_ADV_REG1_PAUSE_ASM;
196 : : break;
197 : 0 : default:
198 : 0 : DEBUGOUT("Flow control param set incorrectly");
199 : : err = TXGBE_ERR_CONFIG;
200 : 0 : goto out;
201 : : }
202 : :
203 : : /*
204 : : * Enable auto-negotiation between the MAC & PHY;
205 : : * the MAC will advertise clause 37 flow control.
206 : : */
207 : : value = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
208 : 0 : value = (value & ~(SR_MII_MMD_AN_ADV_PAUSE_ASM |
209 : : SR_MII_MMD_AN_ADV_PAUSE_SYM)) | reg;
210 : : wr32_epcs(hw, SR_MII_MMD_AN_ADV, value);
211 : :
212 : : /*
213 : : * AUTOC restart handles negotiation of 1G and 10G on backplane
214 : : * and copper. There is no need to set the PCS1GCTL register.
215 : : *
216 : : */
217 [ # # ]: 0 : if (hw->phy.media_type == txgbe_media_type_backplane) {
218 : : value = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
219 : 0 : value = (value & ~(SR_AN_MMD_ADV_REG1_PAUSE_ASM |
220 : 0 : SR_AN_MMD_ADV_REG1_PAUSE_SYM)) |
221 : : reg_bp;
222 : : wr32_epcs(hw, SR_AN_MMD_ADV_REG1, value);
223 [ # # # # ]: 0 : } else if ((hw->phy.media_type == txgbe_media_type_copper) &&
224 : 0 : (txgbe_device_supports_autoneg_fc(hw))) {
225 : 0 : hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
226 : : TXGBE_MD_DEV_AUTO_NEG, reg_cu);
227 : : }
228 : :
229 : 0 : DEBUGOUT("Set up FC; reg = 0x%08X", reg);
230 : 0 : out:
231 : 0 : return err;
232 : : }
233 : :
234 : : /**
235 : : * txgbe_start_hw - Prepare hardware for Tx/Rx
236 : : * @hw: pointer to hardware structure
237 : : *
238 : : * Starts the hardware by filling the bus info structure and media type, clears
239 : : * all on chip counters, initializes receive address registers, multicast
240 : : * table, VLAN filter table, calls routine to set up link and flow control
241 : : * settings, and leaves transmit and receive units disabled and uninitialized
242 : : **/
243 : 0 : s32 txgbe_start_hw(struct txgbe_hw *hw)
244 : : {
245 : : s32 err;
246 : : u16 device_caps;
247 : :
248 : : /* Set the media type */
249 : 0 : hw->phy.media_type = hw->phy.get_media_type(hw);
250 : :
251 : : /* Clear the VLAN filter table */
252 : 0 : hw->mac.clear_vfta(hw);
253 : :
254 : : /* Clear statistics registers */
255 : 0 : hw->mac.clear_hw_cntrs(hw);
256 : :
257 : : /* Setup flow control */
258 : 0 : err = txgbe_setup_fc(hw);
259 [ # # ]: 0 : if (err != 0 && err != TXGBE_NOT_IMPLEMENTED) {
260 : 0 : DEBUGOUT("Flow control setup failed, returning %d", err);
261 : 0 : return err;
262 : : }
263 : :
264 : : /* Cache bit indicating need for crosstalk fix */
265 [ # # ]: 0 : switch (hw->mac.type) {
266 : 0 : case txgbe_mac_raptor:
267 : 0 : hw->mac.get_device_caps(hw, &device_caps);
268 [ # # ]: 0 : if (device_caps & TXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
269 : 0 : hw->need_crosstalk_fix = false;
270 : : else
271 : 0 : hw->need_crosstalk_fix = true;
272 : : break;
273 : 0 : default:
274 : 0 : hw->need_crosstalk_fix = false;
275 : 0 : break;
276 : : }
277 : :
278 : : /* Clear adapter stopped flag */
279 : 0 : hw->adapter_stopped = false;
280 : :
281 : 0 : return 0;
282 : : }
283 : :
284 : : /**
285 : : * txgbe_start_hw_gen2 - Init sequence for common device family
286 : : * @hw: pointer to hw structure
287 : : *
288 : : * Performs the init sequence common to the second generation
289 : : * of 10 GbE devices.
290 : : **/
291 : 0 : s32 txgbe_start_hw_gen2(struct txgbe_hw *hw)
292 : : {
293 : : u32 i;
294 : :
295 : : /* Clear the rate limiters */
296 [ # # ]: 0 : for (i = 0; i < hw->mac.max_tx_queues; i++) {
297 : : wr32(hw, TXGBE_ARBPOOLIDX, i);
298 : : wr32(hw, TXGBE_ARBTXRATE, 0);
299 : : }
300 : : txgbe_flush(hw);
301 : :
302 : : /* We need to run link autotry after the driver loads */
303 : 0 : hw->mac.autotry_restart = true;
304 : :
305 : 0 : return 0;
306 : : }
307 : :
308 : : /**
309 : : * txgbe_init_hw - Generic hardware initialization
310 : : * @hw: pointer to hardware structure
311 : : *
312 : : * Initialize the hardware by resetting the hardware, filling the bus info
313 : : * structure and media type, clears all on chip counters, initializes receive
314 : : * address registers, multicast table, VLAN filter table, calls routine to set
315 : : * up link and flow control settings, and leaves transmit and receive units
316 : : * disabled and uninitialized
317 : : **/
318 : 0 : s32 txgbe_init_hw(struct txgbe_hw *hw)
319 : : {
320 : : s32 status;
321 : :
322 : : /* Get firmware version */
323 : 0 : hw->phy.get_fw_version(hw, &hw->fw_version);
324 : :
325 : 0 : txgbe_disable_lldp(hw);
326 : :
327 : : /* Reset the hardware */
328 : 0 : status = hw->mac.reset_hw(hw);
329 [ # # ]: 0 : if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
330 : : /* Start the HW */
331 : 0 : status = hw->mac.start_hw(hw);
332 : : }
333 : :
334 [ # # ]: 0 : if (status != 0)
335 : 0 : DEBUGOUT("Failed to initialize HW, STATUS = %d", status);
336 : :
337 : 0 : return status;
338 : : }
339 : :
340 : : /**
341 : : * txgbe_clear_hw_cntrs - Generic clear hardware counters
342 : : * @hw: pointer to hardware structure
343 : : *
344 : : * Clears all hardware statistics counters by reading them from the hardware
345 : : * Statistics counters are clear on read.
346 : : **/
347 : 0 : s32 txgbe_clear_hw_cntrs(struct txgbe_hw *hw)
348 : : {
349 : : u16 i = 0;
350 : :
351 : : /* QP Stats */
352 : : /* don't write clear queue stats */
353 [ # # ]: 0 : for (i = 0; i < TXGBE_MAX_QP; i++) {
354 : 0 : hw->qp_last[i].rx_qp_packets = 0;
355 : 0 : hw->qp_last[i].tx_qp_packets = 0;
356 : 0 : hw->qp_last[i].rx_qp_bytes = 0;
357 : 0 : hw->qp_last[i].tx_qp_bytes = 0;
358 : 0 : hw->qp_last[i].rx_qp_mc_packets = 0;
359 : : }
360 : :
361 : : /* PB Stats */
362 [ # # ]: 0 : for (i = 0; i < TXGBE_MAX_UP; i++) {
363 : 0 : rd32(hw, TXGBE_PBRXUPXON(i));
364 : 0 : rd32(hw, TXGBE_PBRXUPXOFF(i));
365 : 0 : rd32(hw, TXGBE_PBTXUPXON(i));
366 : 0 : rd32(hw, TXGBE_PBTXUPXOFF(i));
367 : 0 : rd32(hw, TXGBE_PBTXUPOFF(i));
368 : :
369 : 0 : rd32(hw, TXGBE_PBRXMISS(i));
370 : : }
371 : : rd32(hw, TXGBE_PBRXLNKXON);
372 : : rd32(hw, TXGBE_PBRXLNKXOFF);
373 : : rd32(hw, TXGBE_PBTXLNKXON);
374 : : rd32(hw, TXGBE_PBTXLNKXOFF);
375 : :
376 : : /* DMA Stats */
377 : : rd32(hw, TXGBE_DMARXPKT);
378 : : rd32(hw, TXGBE_DMATXPKT);
379 : :
380 : : rd64(hw, TXGBE_DMARXOCTL);
381 : : rd64(hw, TXGBE_DMATXOCTL);
382 : :
383 : : /* MAC Stats */
384 : : rd64(hw, TXGBE_MACRXERRCRCL);
385 : : rd64(hw, TXGBE_MACRXMPKTL);
386 : : rd64(hw, TXGBE_MACTXMPKTL);
387 : :
388 : : rd64(hw, TXGBE_MACRXPKTL);
389 : : rd64(hw, TXGBE_MACTXPKTL);
390 : : rd64(hw, TXGBE_MACRXGBOCTL);
391 : :
392 : : rd64(hw, TXGBE_MACRXOCTL);
393 : : rd32(hw, TXGBE_MACTXOCTL);
394 : :
395 : : rd64(hw, TXGBE_MACRX1TO64L);
396 : : rd64(hw, TXGBE_MACRX65TO127L);
397 : : rd64(hw, TXGBE_MACRX128TO255L);
398 : : rd64(hw, TXGBE_MACRX256TO511L);
399 : : rd64(hw, TXGBE_MACRX512TO1023L);
400 : : rd64(hw, TXGBE_MACRX1024TOMAXL);
401 : : rd64(hw, TXGBE_MACTX1TO64L);
402 : : rd64(hw, TXGBE_MACTX65TO127L);
403 : : rd64(hw, TXGBE_MACTX128TO255L);
404 : : rd64(hw, TXGBE_MACTX256TO511L);
405 : : rd64(hw, TXGBE_MACTX512TO1023L);
406 : : rd64(hw, TXGBE_MACTX1024TOMAXL);
407 : :
408 : : rd64(hw, TXGBE_MACRXERRLENL);
409 : : rd32(hw, TXGBE_MACRXOVERSIZE);
410 : : rd32(hw, TXGBE_MACRXJABBER);
411 : :
412 : : /* FCoE Stats */
413 : : rd32(hw, TXGBE_FCOECRC);
414 : : rd32(hw, TXGBE_FCOELAST);
415 : : rd32(hw, TXGBE_FCOERPDC);
416 : : rd32(hw, TXGBE_FCOEPRC);
417 : : rd32(hw, TXGBE_FCOEPTC);
418 : : rd32(hw, TXGBE_FCOEDWRC);
419 : : rd32(hw, TXGBE_FCOEDWTC);
420 : :
421 : : /* Flow Director Stats */
422 : : rd32(hw, TXGBE_FDIRMATCH);
423 : : rd32(hw, TXGBE_FDIRMISS);
424 : : rd32(hw, TXGBE_FDIRUSED);
425 : : rd32(hw, TXGBE_FDIRUSED);
426 : : rd32(hw, TXGBE_FDIRFAIL);
427 : : rd32(hw, TXGBE_FDIRFAIL);
428 : :
429 : : /* MACsec Stats */
430 : : rd32(hw, TXGBE_LSECTX_UTPKT);
431 : : rd32(hw, TXGBE_LSECTX_ENCPKT);
432 : : rd32(hw, TXGBE_LSECTX_PROTPKT);
433 : : rd32(hw, TXGBE_LSECTX_ENCOCT);
434 : : rd32(hw, TXGBE_LSECTX_PROTOCT);
435 : : rd32(hw, TXGBE_LSECRX_UTPKT);
436 : : rd32(hw, TXGBE_LSECRX_BTPKT);
437 : : rd32(hw, TXGBE_LSECRX_NOSCIPKT);
438 : : rd32(hw, TXGBE_LSECRX_UNSCIPKT);
439 : : rd32(hw, TXGBE_LSECRX_DECOCT);
440 : : rd32(hw, TXGBE_LSECRX_VLDOCT);
441 : : rd32(hw, TXGBE_LSECRX_UNCHKPKT);
442 : : rd32(hw, TXGBE_LSECRX_DLYPKT);
443 : : rd32(hw, TXGBE_LSECRX_LATEPKT);
444 [ # # ]: 0 : for (i = 0; i < 2; i++) {
445 : 0 : rd32(hw, TXGBE_LSECRX_OKPKT(i));
446 : 0 : rd32(hw, TXGBE_LSECRX_INVPKT(i));
447 : 0 : rd32(hw, TXGBE_LSECRX_BADPKT(i));
448 : : }
449 : : rd32(hw, TXGBE_LSECRX_INVSAPKT);
450 : : rd32(hw, TXGBE_LSECRX_BADSAPKT);
451 : :
452 : 0 : return 0;
453 : : }
454 : :
455 : : /**
456 : : * txgbe_get_mac_addr - Generic get MAC address
457 : : * @hw: pointer to hardware structure
458 : : * @mac_addr: Adapter MAC address
459 : : *
460 : : * Reads the adapter's MAC address from first Receive Address Register (RAR0)
461 : : * A reset of the adapter must be performed prior to calling this function
462 : : * in order for the MAC address to have been loaded from the EEPROM into RAR0
463 : : **/
464 : 0 : s32 txgbe_get_mac_addr(struct txgbe_hw *hw, u8 *mac_addr)
465 : : {
466 : : u32 rar_high;
467 : : u32 rar_low;
468 : : u16 i;
469 : :
470 : : wr32(hw, TXGBE_ETHADDRIDX, 0);
471 : : rar_high = rd32(hw, TXGBE_ETHADDRH);
472 : : rar_low = rd32(hw, TXGBE_ETHADDRL);
473 : :
474 [ # # ]: 0 : for (i = 0; i < 2; i++)
475 : 0 : mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
476 : :
477 [ # # ]: 0 : for (i = 0; i < 4; i++)
478 : 0 : mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
479 : :
480 : 0 : return 0;
481 : : }
482 : :
483 : : /**
484 : : * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
485 : : * @hw: pointer to the HW structure
486 : : *
487 : : * Determines the LAN function id by reading memory-mapped registers and swaps
488 : : * the port value if requested, and set MAC instance for devices.
489 : : **/
490 : 0 : void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
491 : : {
492 : : struct txgbe_bus_info *bus = &hw->bus;
493 : : u32 reg;
494 : :
495 : : reg = rd32(hw, TXGBE_PORTSTAT);
496 : 0 : bus->lan_id = TXGBE_PORTSTAT_ID(reg);
497 : :
498 : : /* check for single port */
499 : : reg = rd32(hw, TXGBE_PWR);
500 : : if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
501 : : bus->func = 0;
502 : : else
503 : 0 : bus->func = bus->lan_id;
504 : 0 : }
505 : :
506 : : /**
507 : : * txgbe_stop_hw - Generic stop Tx/Rx units
508 : : * @hw: pointer to hardware structure
509 : : *
510 : : * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
511 : : * disables transmit and receive units. The adapter_stopped flag is used by
512 : : * the shared code and drivers to determine if the adapter is in a stopped
513 : : * state and should not touch the hardware.
514 : : **/
515 : 0 : s32 txgbe_stop_hw(struct txgbe_hw *hw)
516 : : {
517 : : s32 status = 0;
518 : : u16 i;
519 : :
520 : : /*
521 : : * Set the adapter_stopped flag so other driver functions stop touching
522 : : * the hardware
523 : : */
524 : 0 : hw->adapter_stopped = true;
525 : :
526 : : /* Disable the receive unit */
527 : 0 : txgbe_disable_rx(hw);
528 : :
529 : : /* Clear interrupt mask to stop interrupts from being generated */
530 : : wr32(hw, TXGBE_IENMISC, 0);
531 : : wr32(hw, TXGBE_IMS(0), TXGBE_IMS_MASK);
532 : : wr32(hw, TXGBE_IMS(1), TXGBE_IMS_MASK);
533 : :
534 : : /* Clear any pending interrupts, flush previous writes */
535 : : wr32(hw, TXGBE_ICRMISC, TXGBE_ICRMISC_MASK);
536 : : wr32(hw, TXGBE_ICR(0), TXGBE_ICR_MASK);
537 : : wr32(hw, TXGBE_ICR(1), TXGBE_ICR_MASK);
538 : :
539 : : wr32(hw, TXGBE_BMECTL, 0x3);
540 : :
541 : : /* Disable the receive unit by stopping each queue */
542 [ # # ]: 0 : for (i = 0; i < hw->mac.max_rx_queues; i++)
543 : 0 : wr32(hw, TXGBE_RXCFG(i), 0);
544 : :
545 : : /* flush all queues disables */
546 : : txgbe_flush(hw);
547 : : msec_delay(2);
548 : :
549 : : /* Prevent the PCI-E bus from hanging by disabling PCI-E master
550 : : * access and verify no pending requests
551 : : */
552 : 0 : status = txgbe_set_pcie_master(hw, false);
553 [ # # ]: 0 : if (status)
554 : : return status;
555 : :
556 : : /* Disable the transmit unit. Each queue must be disabled. */
557 [ # # ]: 0 : for (i = 0; i < hw->mac.max_tx_queues; i++)
558 : 0 : wr32(hw, TXGBE_TXCFG(i), 0);
559 : :
560 : : /* flush all queues disables */
561 : : txgbe_flush(hw);
562 : : msec_delay(2);
563 : :
564 : 0 : return 0;
565 : : }
566 : :
567 : : /**
568 : : * txgbe_led_on - Turns on the software controllable LEDs.
569 : : * @hw: pointer to hardware structure
570 : : * @index: led number to turn on
571 : : **/
572 : 0 : s32 txgbe_led_on(struct txgbe_hw *hw, u32 index)
573 : : {
574 : : u32 led_reg = rd32(hw, TXGBE_LEDCTL);
575 : :
576 : : /* To turn on the LED, set mode to ON. */
577 : 0 : led_reg |= index << TXGBE_LEDCTL_ORD_SHIFT;
578 : 0 : led_reg |= index;
579 : : wr32(hw, TXGBE_LEDCTL, led_reg);
580 : : txgbe_flush(hw);
581 : :
582 : 0 : return 0;
583 : : }
584 : :
585 : : /**
586 : : * txgbe_led_off - Turns off the software controllable LEDs.
587 : : * @hw: pointer to hardware structure
588 : : * @index: led number to turn off
589 : : **/
590 : 0 : s32 txgbe_led_off(struct txgbe_hw *hw, u32 index)
591 : : {
592 : : u32 led_reg = rd32(hw, TXGBE_LEDCTL);
593 : :
594 : : /* To turn off the LED, set mode to OFF. */
595 : 0 : led_reg &= ~(index << TXGBE_LEDCTL_ORD_SHIFT);
596 : 0 : led_reg |= index;
597 : : wr32(hw, TXGBE_LEDCTL, led_reg);
598 : : txgbe_flush(hw);
599 : :
600 : 0 : return 0;
601 : : }
602 : :
603 : : /**
604 : : * txgbe_validate_mac_addr - Validate MAC address
605 : : * @mac_addr: pointer to MAC address.
606 : : *
607 : : * Tests a MAC address to ensure it is a valid Individual Address.
608 : : **/
609 : 0 : s32 txgbe_validate_mac_addr(u8 *mac_addr)
610 : : {
611 : : s32 status = 0;
612 : :
613 : : /* Make sure it is not a multicast address */
614 [ # # ]: 0 : if (TXGBE_IS_MULTICAST(mac_addr)) {
615 : : status = TXGBE_ERR_INVALID_MAC_ADDR;
616 : : /* Not a broadcast address */
617 : : } else if (TXGBE_IS_BROADCAST(mac_addr)) {
618 : : status = TXGBE_ERR_INVALID_MAC_ADDR;
619 : : /* Reject the zero address */
620 [ # # # # : 0 : } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
# # ]
621 [ # # # # : 0 : mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
# # ]
622 : : status = TXGBE_ERR_INVALID_MAC_ADDR;
623 : : }
624 : 0 : return status;
625 : : }
626 : :
627 : : /**
628 : : * txgbe_set_rar - Set Rx address register
629 : : * @hw: pointer to hardware structure
630 : : * @index: Receive address register to write
631 : : * @addr: Address to put into receive address register
632 : : * @vmdq: VMDq "set" or "pool" index
633 : : * @enable_addr: set flag that address is active
634 : : *
635 : : * Puts an ethernet address into a receive address register.
636 : : **/
637 : 0 : s32 txgbe_set_rar(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
638 : : u32 enable_addr)
639 : : {
640 : : u32 rar_low, rar_high;
641 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
642 : :
643 : : /* Make sure we are using a valid rar index range */
644 [ # # ]: 0 : if (index >= rar_entries) {
645 : 0 : DEBUGOUT("RAR index %d is out of range.", index);
646 : 0 : return TXGBE_ERR_INVALID_ARGUMENT;
647 : : }
648 : :
649 : : /* setup VMDq pool selection before this RAR gets enabled */
650 : 0 : hw->mac.set_vmdq(hw, index, vmdq);
651 : :
652 : : /*
653 : : * HW expects these in little endian so we reverse the byte
654 : : * order from network order (big endian) to little endian
655 : : */
656 : 0 : rar_low = TXGBE_ETHADDRL_AD0(addr[5]) |
657 : 0 : TXGBE_ETHADDRL_AD1(addr[4]) |
658 : 0 : TXGBE_ETHADDRL_AD2(addr[3]) |
659 : 0 : TXGBE_ETHADDRL_AD3(addr[2]);
660 : : /*
661 : : * Some parts put the VMDq setting in the extra RAH bits,
662 : : * so save everything except the lower 16 bits that hold part
663 : : * of the address and the address valid bit.
664 : : */
665 : : rar_high = rd32(hw, TXGBE_ETHADDRH);
666 : 0 : rar_high &= ~TXGBE_ETHADDRH_AD_MASK;
667 : 0 : rar_high |= (TXGBE_ETHADDRH_AD4(addr[1]) |
668 : 0 : TXGBE_ETHADDRH_AD5(addr[0]));
669 : :
670 : 0 : rar_high &= ~TXGBE_ETHADDRH_VLD;
671 [ # # ]: 0 : if (enable_addr != 0)
672 : 0 : rar_high |= TXGBE_ETHADDRH_VLD;
673 : :
674 : : wr32(hw, TXGBE_ETHADDRIDX, index);
675 : : wr32(hw, TXGBE_ETHADDRL, rar_low);
676 : : wr32(hw, TXGBE_ETHADDRH, rar_high);
677 : :
678 : 0 : return 0;
679 : : }
680 : :
681 : : /**
682 : : * txgbe_clear_rar - Remove Rx address register
683 : : * @hw: pointer to hardware structure
684 : : * @index: Receive address register to write
685 : : *
686 : : * Clears an ethernet address from a receive address register.
687 : : **/
688 : 0 : s32 txgbe_clear_rar(struct txgbe_hw *hw, u32 index)
689 : : {
690 : : u32 rar_high;
691 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
692 : :
693 : : /* Make sure we are using a valid rar index range */
694 [ # # ]: 0 : if (index >= rar_entries) {
695 : 0 : DEBUGOUT("RAR index %d is out of range.", index);
696 : 0 : return TXGBE_ERR_INVALID_ARGUMENT;
697 : : }
698 : :
699 : : /*
700 : : * Some parts put the VMDq setting in the extra RAH bits,
701 : : * so save everything except the lower 16 bits that hold part
702 : : * of the address and the address valid bit.
703 : : */
704 : : wr32(hw, TXGBE_ETHADDRIDX, index);
705 : : rar_high = rd32(hw, TXGBE_ETHADDRH);
706 : 0 : rar_high &= ~(TXGBE_ETHADDRH_AD_MASK | TXGBE_ETHADDRH_VLD);
707 : :
708 : : wr32(hw, TXGBE_ETHADDRL, 0);
709 : : wr32(hw, TXGBE_ETHADDRH, rar_high);
710 : :
711 : : /* clear VMDq pool/queue selection for this RAR */
712 : 0 : hw->mac.clear_vmdq(hw, index, BIT_MASK32);
713 : :
714 : 0 : return 0;
715 : : }
716 : :
717 : : /**
718 : : * txgbe_init_rx_addrs - Initializes receive address filters.
719 : : * @hw: pointer to hardware structure
720 : : *
721 : : * Places the MAC address in receive address register 0 and clears the rest
722 : : * of the receive address registers. Clears the multicast table. Assumes
723 : : * the receiver is in reset when the routine is called.
724 : : **/
725 : 0 : s32 txgbe_init_rx_addrs(struct txgbe_hw *hw)
726 : : {
727 : : u32 i;
728 : : u32 psrctl;
729 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
730 : :
731 : : /*
732 : : * If the current mac address is valid, assume it is a software override
733 : : * to the permanent address.
734 : : * Otherwise, use the permanent address from the eeprom.
735 : : */
736 [ # # ]: 0 : if (txgbe_validate_mac_addr(hw->mac.addr) ==
737 : : TXGBE_ERR_INVALID_MAC_ADDR) {
738 : : /* Get the MAC address from the RAR0 for later reference */
739 : 0 : hw->mac.get_mac_addr(hw, hw->mac.addr);
740 : :
741 : 0 : DEBUGOUT(" Keeping Current RAR0 Addr = "
742 : : RTE_ETHER_ADDR_PRT_FMT,
743 : : hw->mac.addr[0], hw->mac.addr[1],
744 : : hw->mac.addr[2], hw->mac.addr[3],
745 : : hw->mac.addr[4], hw->mac.addr[5]);
746 : : } else {
747 : : /* Setup the receive address. */
748 : 0 : DEBUGOUT("Overriding MAC Address in RAR[0]");
749 : 0 : DEBUGOUT(" New MAC Addr = "
750 : : RTE_ETHER_ADDR_PRT_FMT,
751 : : hw->mac.addr[0], hw->mac.addr[1],
752 : : hw->mac.addr[2], hw->mac.addr[3],
753 : : hw->mac.addr[4], hw->mac.addr[5]);
754 : :
755 : 0 : hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
756 : : }
757 : :
758 : : /* clear VMDq pool/queue selection for RAR 0 */
759 : 0 : hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
760 : :
761 : 0 : hw->addr_ctrl.overflow_promisc = 0;
762 : :
763 : 0 : hw->addr_ctrl.rar_used_count = 1;
764 : :
765 : : /* Zero out the other receive addresses. */
766 : 0 : DEBUGOUT("Clearing RAR[1-%d]", rar_entries - 1);
767 [ # # ]: 0 : for (i = 1; i < rar_entries; i++) {
768 : : wr32(hw, TXGBE_ETHADDRIDX, i);
769 : : wr32(hw, TXGBE_ETHADDRL, 0);
770 : : wr32(hw, TXGBE_ETHADDRH, 0);
771 : : }
772 : :
773 : : /* Clear the MTA */
774 : 0 : hw->addr_ctrl.mta_in_use = 0;
775 : : psrctl = rd32(hw, TXGBE_PSRCTL);
776 : 0 : psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
777 : 0 : psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
778 : : wr32(hw, TXGBE_PSRCTL, psrctl);
779 : :
780 : 0 : DEBUGOUT(" Clearing MTA");
781 [ # # ]: 0 : for (i = 0; i < hw->mac.mcft_size; i++)
782 : 0 : wr32(hw, TXGBE_MCADDRTBL(i), 0);
783 : :
784 : 0 : txgbe_init_uta_tables(hw);
785 : :
786 : 0 : return 0;
787 : : }
788 : :
789 : : /**
790 : : * txgbe_mta_vector - Determines bit-vector in multicast table to set
791 : : * @hw: pointer to hardware structure
792 : : * @mc_addr: the multicast address
793 : : *
794 : : * Extracts the 12 bits, from a multicast address, to determine which
795 : : * bit-vector to set in the multicast table. The hardware uses 12 bits, from
796 : : * incoming rx multicast addresses, to determine the bit-vector to check in
797 : : * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
798 : : * by the MO field of the PSRCTRL. The MO field is set during initialization
799 : : * to mc_filter_type.
800 : : **/
801 : 0 : static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
802 : : {
803 : : u32 vector = 0;
804 : :
805 [ # # # # : 0 : switch (hw->mac.mc_filter_type) {
# ]
806 : 0 : case 0: /* use bits [47:36] of the address */
807 : 0 : vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
808 : 0 : break;
809 : 0 : case 1: /* use bits [46:35] of the address */
810 : 0 : vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
811 : 0 : break;
812 : 0 : case 2: /* use bits [45:34] of the address */
813 : 0 : vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
814 : 0 : break;
815 : 0 : case 3: /* use bits [43:32] of the address */
816 : 0 : vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
817 : 0 : break;
818 : 0 : default: /* Invalid mc_filter_type */
819 : 0 : DEBUGOUT("MC filter type param set incorrectly");
820 : 0 : ASSERT(0);
821 : : break;
822 : : }
823 : :
824 : : /* vector can only be 12-bits or boundary will be exceeded */
825 : 0 : vector &= 0xFFF;
826 : 0 : return vector;
827 : : }
828 : :
829 : : /**
830 : : * txgbe_set_mta - Set bit-vector in multicast table
831 : : * @hw: pointer to hardware structure
832 : : * @mc_addr: Multicast address
833 : : *
834 : : * Sets the bit-vector in the multicast table.
835 : : **/
836 : 0 : void txgbe_set_mta(struct txgbe_hw *hw, u8 *mc_addr)
837 : : {
838 : : u32 vector;
839 : : u32 vector_bit;
840 : : u32 vector_reg;
841 : :
842 : 0 : hw->addr_ctrl.mta_in_use++;
843 : :
844 : 0 : vector = txgbe_mta_vector(hw, mc_addr);
845 : 0 : DEBUGOUT(" bit-vector = 0x%03X", vector);
846 : :
847 : : /*
848 : : * The MTA is a register array of 128 32-bit registers. It is treated
849 : : * like an array of 4096 bits. We want to set bit
850 : : * BitArray[vector_value]. So we figure out what register the bit is
851 : : * in, read it, OR in the new bit, then write back the new value. The
852 : : * register is determined by the upper 7 bits of the vector value and
853 : : * the bit within that register are determined by the lower 5 bits of
854 : : * the value.
855 : : */
856 : 0 : vector_reg = (vector >> 5) & 0x7F;
857 : 0 : vector_bit = vector & 0x1F;
858 : 0 : hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
859 : 0 : }
860 : :
861 : : /**
862 : : * txgbe_update_mc_addr_list - Updates MAC list of multicast addresses
863 : : * @hw: pointer to hardware structure
864 : : * @mc_addr_list: the list of new multicast addresses
865 : : * @mc_addr_count: number of addresses
866 : : * @next: iterator function to walk the multicast address list
867 : : * @clear: flag, when set clears the table beforehand
868 : : *
869 : : * When the clear flag is set, the given list replaces any existing list.
870 : : * Hashes the given addresses into the multicast table.
871 : : **/
872 : 0 : s32 txgbe_update_mc_addr_list(struct txgbe_hw *hw, u8 *mc_addr_list,
873 : : u32 mc_addr_count, txgbe_mc_addr_itr next,
874 : : bool clear)
875 : : {
876 : : u32 i;
877 : : u32 vmdq;
878 : :
879 : : /*
880 : : * Set the new number of MC addresses that we are being requested to
881 : : * use.
882 : : */
883 : 0 : hw->addr_ctrl.num_mc_addrs = mc_addr_count;
884 : 0 : hw->addr_ctrl.mta_in_use = 0;
885 : :
886 : : /* Clear mta_shadow */
887 [ # # ]: 0 : if (clear) {
888 : 0 : DEBUGOUT(" Clearing MTA");
889 : 0 : memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
890 : : }
891 : :
892 : : /* Update mta_shadow */
893 [ # # ]: 0 : for (i = 0; i < mc_addr_count; i++) {
894 : 0 : DEBUGOUT(" Adding the multicast addresses:");
895 : 0 : txgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
896 : : }
897 : :
898 : : /* Enable mta */
899 [ # # ]: 0 : for (i = 0; i < hw->mac.mcft_size; i++)
900 : 0 : wr32a(hw, TXGBE_MCADDRTBL(0), i,
901 : : hw->mac.mta_shadow[i]);
902 : :
903 [ # # ]: 0 : if (hw->addr_ctrl.mta_in_use > 0) {
904 : : u32 psrctl = rd32(hw, TXGBE_PSRCTL);
905 : 0 : psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
906 : 0 : psrctl |= TXGBE_PSRCTL_MCHFENA |
907 : 0 : TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
908 : : wr32(hw, TXGBE_PSRCTL, psrctl);
909 : : }
910 : :
911 : 0 : DEBUGOUT("txgbe update mc addr list complete");
912 : 0 : return 0;
913 : : }
914 : :
915 : : /**
916 : : * txgbe_fc_enable - Enable flow control
917 : : * @hw: pointer to hardware structure
918 : : *
919 : : * Enable flow control according to the current settings.
920 : : **/
921 : 0 : s32 txgbe_fc_enable(struct txgbe_hw *hw)
922 : : {
923 : : s32 err = 0;
924 : : u32 mflcn_reg, fccfg_reg;
925 : : u32 pause_time;
926 : : u32 fcrtl, fcrth;
927 : : int i;
928 : :
929 : : /* Validate the water mark configuration */
930 [ # # ]: 0 : if (!hw->fc.pause_time) {
931 : : err = TXGBE_ERR_INVALID_LINK_SETTINGS;
932 : 0 : goto out;
933 : : }
934 : :
935 : : /* Low water mark of zero causes XOFF floods */
936 [ # # ]: 0 : for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
937 [ # # ]: 0 : if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
938 [ # # ]: 0 : hw->fc.high_water[i]) {
939 [ # # # # ]: 0 : if (!hw->fc.low_water[i] ||
940 : : hw->fc.low_water[i] >= hw->fc.high_water[i]) {
941 : 0 : DEBUGOUT("Invalid water mark configuration");
942 : : err = TXGBE_ERR_INVALID_LINK_SETTINGS;
943 : 0 : goto out;
944 : : }
945 : : }
946 : : }
947 : :
948 : : /* Negotiate the fc mode to use */
949 : 0 : hw->mac.fc_autoneg(hw);
950 : :
951 : : /* Disable any previous flow control settings */
952 : : mflcn_reg = rd32(hw, TXGBE_RXFCCFG);
953 : 0 : mflcn_reg &= ~(TXGBE_RXFCCFG_FC | TXGBE_RXFCCFG_PFC);
954 : :
955 : : fccfg_reg = rd32(hw, TXGBE_TXFCCFG);
956 : 0 : fccfg_reg &= ~(TXGBE_TXFCCFG_FC | TXGBE_TXFCCFG_PFC);
957 : :
958 : : /*
959 : : * The possible values of fc.current_mode are:
960 : : * 0: Flow control is completely disabled
961 : : * 1: Rx flow control is enabled (we can receive pause frames,
962 : : * but not send pause frames).
963 : : * 2: Tx flow control is enabled (we can send pause frames but
964 : : * we do not support receiving pause frames).
965 : : * 3: Both Rx and Tx flow control (symmetric) are enabled.
966 : : * other: Invalid.
967 : : */
968 [ # # # # : 0 : switch (hw->fc.current_mode) {
# ]
969 : : case txgbe_fc_none:
970 : : /*
971 : : * Flow control is disabled by software override or autoneg.
972 : : * The code below will actually disable it in the HW.
973 : : */
974 : : break;
975 : 0 : case txgbe_fc_rx_pause:
976 : : /*
977 : : * Rx Flow control is enabled and Tx Flow control is
978 : : * disabled by software override. Since there really
979 : : * isn't a way to advertise that we are capable of RX
980 : : * Pause ONLY, we will advertise that we support both
981 : : * symmetric and asymmetric Rx PAUSE. Later, we will
982 : : * disable the adapter's ability to send PAUSE frames.
983 : : */
984 : 0 : mflcn_reg |= TXGBE_RXFCCFG_FC;
985 : 0 : break;
986 : 0 : case txgbe_fc_tx_pause:
987 : : /*
988 : : * Tx Flow control is enabled, and Rx Flow control is
989 : : * disabled by software override.
990 : : */
991 : 0 : fccfg_reg |= TXGBE_TXFCCFG_FC;
992 : 0 : break;
993 : 0 : case txgbe_fc_full:
994 : : /* Flow control (both Rx and Tx) is enabled by SW override. */
995 : 0 : mflcn_reg |= TXGBE_RXFCCFG_FC;
996 : 0 : fccfg_reg |= TXGBE_TXFCCFG_FC;
997 : 0 : break;
998 : 0 : default:
999 : 0 : DEBUGOUT("Flow control param set incorrectly");
1000 : : err = TXGBE_ERR_CONFIG;
1001 : 0 : goto out;
1002 : : }
1003 : :
1004 : : /* Set 802.3x based flow control settings. */
1005 : : wr32(hw, TXGBE_RXFCCFG, mflcn_reg);
1006 : : wr32(hw, TXGBE_TXFCCFG, fccfg_reg);
1007 : :
1008 : : /* Set up and enable Rx high/low water mark thresholds, enable XON. */
1009 [ # # ]: 0 : for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
1010 [ # # ]: 0 : if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
1011 [ # # ]: 0 : hw->fc.high_water[i]) {
1012 : 0 : fcrtl = TXGBE_FCWTRLO_TH(hw->fc.low_water[i]) |
1013 : : TXGBE_FCWTRLO_XON;
1014 : 0 : fcrth = TXGBE_FCWTRHI_TH(hw->fc.high_water[i]) |
1015 : : TXGBE_FCWTRHI_XOFF;
1016 : : } else {
1017 : : /*
1018 : : * In order to prevent Tx hangs when the internal Tx
1019 : : * switch is enabled we must set the high water mark
1020 : : * to the Rx packet buffer size - 24KB. This allows
1021 : : * the Tx switch to function even under heavy Rx
1022 : : * workloads.
1023 : : */
1024 : : fcrtl = 0;
1025 : 0 : fcrth = rd32(hw, TXGBE_PBRXSIZE(i)) - 24576;
1026 : : }
1027 : 0 : wr32(hw, TXGBE_FCWTRLO(i), fcrtl);
1028 : 0 : wr32(hw, TXGBE_FCWTRHI(i), fcrth);
1029 : : }
1030 : :
1031 : : /* Configure pause time (2 TCs per register) */
1032 : 0 : pause_time = TXGBE_RXFCFSH_TIME(hw->fc.pause_time);
1033 [ # # ]: 0 : for (i = 0; i < (TXGBE_DCB_TC_MAX / 2); i++)
1034 : 0 : wr32(hw, TXGBE_FCXOFFTM(i), pause_time * 0x00010001);
1035 : :
1036 : : /* Configure flow control refresh threshold value */
1037 : 0 : wr32(hw, TXGBE_RXFCRFSH, hw->fc.pause_time / 2);
1038 : :
1039 : 0 : out:
1040 : 0 : return err;
1041 : : }
1042 : :
1043 : : /**
1044 : : * txgbe_negotiate_fc - Negotiate flow control
1045 : : * @hw: pointer to hardware structure
1046 : : * @adv_reg: flow control advertised settings
1047 : : * @lp_reg: link partner's flow control settings
1048 : : * @adv_sym: symmetric pause bit in advertisement
1049 : : * @adv_asm: asymmetric pause bit in advertisement
1050 : : * @lp_sym: symmetric pause bit in link partner advertisement
1051 : : * @lp_asm: asymmetric pause bit in link partner advertisement
1052 : : *
1053 : : * Find the intersection between advertised settings and link partner's
1054 : : * advertised settings
1055 : : **/
1056 : 0 : s32 txgbe_negotiate_fc(struct txgbe_hw *hw, u32 adv_reg, u32 lp_reg,
1057 : : u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
1058 : : {
1059 [ # # ]: 0 : if ((!(adv_reg)) || (!(lp_reg))) {
1060 : 0 : DEBUGOUT("Local or link partner's advertised flow control settings are NULL. Local: %x, link partner: %x",
1061 : : adv_reg, lp_reg);
1062 : 0 : return TXGBE_ERR_FC_NOT_NEGOTIATED;
1063 : : }
1064 : :
1065 [ # # # # ]: 0 : if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
1066 : : /*
1067 : : * Now we need to check if the user selected Rx ONLY
1068 : : * of pause frames. In this case, we had to advertise
1069 : : * FULL flow control because we could not advertise RX
1070 : : * ONLY. Hence, we must now check to see if we need to
1071 : : * turn OFF the TRANSMISSION of PAUSE frames.
1072 : : */
1073 [ # # ]: 0 : if (hw->fc.requested_mode == txgbe_fc_full) {
1074 : 0 : hw->fc.current_mode = txgbe_fc_full;
1075 : 0 : DEBUGOUT("Flow Control = FULL.");
1076 : : } else {
1077 : 0 : hw->fc.current_mode = txgbe_fc_rx_pause;
1078 : 0 : DEBUGOUT("Flow Control=RX PAUSE frames only");
1079 : : }
1080 [ # # # # ]: 0 : } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1081 [ # # # # ]: 0 : (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1082 : 0 : hw->fc.current_mode = txgbe_fc_tx_pause;
1083 : 0 : DEBUGOUT("Flow Control = TX PAUSE frames only.");
1084 [ # # # # ]: 0 : } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1085 [ # # # # ]: 0 : !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1086 : 0 : hw->fc.current_mode = txgbe_fc_rx_pause;
1087 : 0 : DEBUGOUT("Flow Control = RX PAUSE frames only.");
1088 : : } else {
1089 : 0 : hw->fc.current_mode = txgbe_fc_none;
1090 : 0 : DEBUGOUT("Flow Control = NONE.");
1091 : : }
1092 : : return 0;
1093 : : }
1094 : :
1095 : : /**
1096 : : * txgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
1097 : : * @hw: pointer to hardware structure
1098 : : *
1099 : : * Enable flow control according on 1 gig fiber.
1100 : : **/
1101 : 0 : STATIC s32 txgbe_fc_autoneg_fiber(struct txgbe_hw *hw)
1102 : : {
1103 : : u32 pcs_anadv_reg, pcs_lpab_reg;
1104 : : s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
1105 : :
1106 : : /*
1107 : : * On multispeed fiber at 1g, bail out if
1108 : : * - link is up but AN did not complete, or if
1109 : : * - link is up and AN completed but timed out
1110 : : */
1111 : :
1112 : : pcs_anadv_reg = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
1113 : : pcs_lpab_reg = rd32_epcs(hw, SR_MII_MMD_LP_BABL);
1114 : :
1115 : 0 : err = txgbe_negotiate_fc(hw, pcs_anadv_reg,
1116 : : pcs_lpab_reg,
1117 : : SR_MII_MMD_AN_ADV_PAUSE_SYM,
1118 : : SR_MII_MMD_AN_ADV_PAUSE_ASM,
1119 : : SR_MII_MMD_AN_ADV_PAUSE_SYM,
1120 : : SR_MII_MMD_AN_ADV_PAUSE_ASM);
1121 : :
1122 : 0 : return err;
1123 : : }
1124 : :
1125 : : /**
1126 : : * txgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
1127 : : * @hw: pointer to hardware structure
1128 : : *
1129 : : * Enable flow control according to IEEE clause 37.
1130 : : **/
1131 : 0 : STATIC s32 txgbe_fc_autoneg_backplane(struct txgbe_hw *hw)
1132 : : {
1133 : : u32 anlp1_reg, autoc_reg;
1134 : : s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
1135 : :
1136 : : /*
1137 : : * Read the 10g AN autoc and LP ability registers and resolve
1138 : : * local flow control settings accordingly
1139 : : */
1140 : : autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
1141 : : anlp1_reg = rd32_epcs(hw, SR_AN_MMD_LP_ABL1);
1142 : :
1143 : 0 : err = txgbe_negotiate_fc(hw, autoc_reg,
1144 : : anlp1_reg,
1145 : : SR_AN_MMD_ADV_REG1_PAUSE_SYM,
1146 : : SR_AN_MMD_ADV_REG1_PAUSE_ASM,
1147 : : SR_AN_MMD_ADV_REG1_PAUSE_SYM,
1148 : : SR_AN_MMD_ADV_REG1_PAUSE_ASM);
1149 : :
1150 : 0 : return err;
1151 : : }
1152 : :
1153 : : /**
1154 : : * txgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
1155 : : * @hw: pointer to hardware structure
1156 : : *
1157 : : * Enable flow control according to IEEE clause 37.
1158 : : **/
1159 : 0 : STATIC s32 txgbe_fc_autoneg_copper(struct txgbe_hw *hw)
1160 : : {
1161 : 0 : u16 technology_ability_reg = 0;
1162 : 0 : u16 lp_technology_ability_reg = 0;
1163 : :
1164 : 0 : hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
1165 : : TXGBE_MD_DEV_AUTO_NEG,
1166 : : &technology_ability_reg);
1167 : 0 : hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_LP,
1168 : : TXGBE_MD_DEV_AUTO_NEG,
1169 : : &lp_technology_ability_reg);
1170 : :
1171 : 0 : return txgbe_negotiate_fc(hw, (u32)technology_ability_reg,
1172 : : (u32)lp_technology_ability_reg,
1173 : : TXGBE_TAF_SYM_PAUSE, TXGBE_TAF_ASM_PAUSE,
1174 : : TXGBE_TAF_SYM_PAUSE, TXGBE_TAF_ASM_PAUSE);
1175 : : }
1176 : :
1177 : : /**
1178 : : * txgbe_fc_autoneg - Configure flow control
1179 : : * @hw: pointer to hardware structure
1180 : : *
1181 : : * Compares our advertised flow control capabilities to those advertised by
1182 : : * our link partner, and determines the proper flow control mode to use.
1183 : : **/
1184 : 0 : void txgbe_fc_autoneg(struct txgbe_hw *hw)
1185 : : {
1186 : : s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
1187 : : u32 speed;
1188 : : bool link_up;
1189 : :
1190 : : /*
1191 : : * AN should have completed when the cable was plugged in.
1192 : : * Look for reasons to bail out. Bail out if:
1193 : : * - FC autoneg is disabled, or if
1194 : : * - link is not up.
1195 : : */
1196 [ # # ]: 0 : if (hw->fc.disable_fc_autoneg) {
1197 : 0 : DEBUGOUT("Flow control autoneg is disabled");
1198 : 0 : goto out;
1199 : : }
1200 : :
1201 : 0 : hw->mac.check_link(hw, &speed, &link_up, false);
1202 [ # # ]: 0 : if (!link_up) {
1203 : 0 : DEBUGOUT("The link is down");
1204 : 0 : goto out;
1205 : : }
1206 : :
1207 [ # # # # ]: 0 : switch (hw->phy.media_type) {
1208 : : /* Autoneg flow control on fiber adapters */
1209 : 0 : case txgbe_media_type_fiber_qsfp:
1210 : : case txgbe_media_type_fiber:
1211 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_1GB_FULL)
1212 : 0 : err = txgbe_fc_autoneg_fiber(hw);
1213 : : break;
1214 : :
1215 : : /* Autoneg flow control on backplane adapters */
1216 : 0 : case txgbe_media_type_backplane:
1217 : 0 : err = txgbe_fc_autoneg_backplane(hw);
1218 : 0 : break;
1219 : :
1220 : : /* Autoneg flow control on copper adapters */
1221 : 0 : case txgbe_media_type_copper:
1222 [ # # ]: 0 : if (txgbe_device_supports_autoneg_fc(hw))
1223 : 0 : err = txgbe_fc_autoneg_copper(hw);
1224 : : break;
1225 : :
1226 : : default:
1227 : : break;
1228 : : }
1229 : :
1230 : 0 : out:
1231 [ # # ]: 0 : if (err == 0) {
1232 : 0 : hw->fc.fc_was_autonegged = true;
1233 : : } else {
1234 : 0 : hw->fc.fc_was_autonegged = false;
1235 : 0 : hw->fc.current_mode = hw->fc.requested_mode;
1236 : : }
1237 : 0 : }
1238 : :
1239 : 0 : s32 txgbe_set_pcie_master(struct txgbe_hw *hw, bool enable)
1240 : : {
1241 : 0 : struct rte_pci_device *pci_dev = (struct rte_pci_device *)hw->back;
1242 : : s32 status = 0;
1243 : : u32 i;
1244 : :
1245 [ # # ]: 0 : if (rte_pci_set_bus_master(pci_dev, enable) < 0) {
1246 : 0 : DEBUGOUT("Cannot configure PCI bus master.");
1247 : 0 : return -1;
1248 : : }
1249 : :
1250 [ # # ]: 0 : if (enable)
1251 : 0 : goto out;
1252 : :
1253 : : /* Exit if master requests are blocked */
1254 [ # # ]: 0 : if (!(rd32(hw, TXGBE_BMEPEND)))
1255 : 0 : goto out;
1256 : :
1257 : : /* Poll for master request bit to clear */
1258 [ # # ]: 0 : for (i = 0; i < TXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
1259 : 0 : usec_delay(100);
1260 [ # # ]: 0 : if (!(rd32(hw, TXGBE_BMEPEND)))
1261 : 0 : goto out;
1262 : : }
1263 : :
1264 : 0 : DEBUGOUT("PCIe transaction pending bit also did not clear.");
1265 : : status = TXGBE_ERR_MASTER_REQUESTS_PENDING;
1266 : :
1267 : : out:
1268 : : return status;
1269 : : }
1270 : :
1271 : : /**
1272 : : * txgbe_acquire_swfw_sync - Acquire SWFW semaphore
1273 : : * @hw: pointer to hardware structure
1274 : : * @mask: Mask to specify which semaphore to acquire
1275 : : *
1276 : : * Acquires the SWFW semaphore through the MNGSEM register for the specified
1277 : : * function (CSR, PHY0, PHY1, EEPROM, Flash)
1278 : : **/
1279 : 0 : s32 txgbe_acquire_swfw_sync(struct txgbe_hw *hw, u32 mask)
1280 : : {
1281 : : u32 mngsem = 0;
1282 : 0 : u32 swmask = TXGBE_MNGSEM_SW(mask);
1283 : 0 : u32 fwmask = TXGBE_MNGSEM_FW(mask);
1284 : : u32 timeout = 200;
1285 : : u32 i;
1286 : :
1287 [ # # ]: 0 : for (i = 0; i < timeout; i++) {
1288 : : /*
1289 : : * SW NVM semaphore bit is used for access to all
1290 : : * SW_FW_SYNC bits (not just NVM)
1291 : : */
1292 [ # # ]: 0 : if (txgbe_get_eeprom_semaphore(hw))
1293 : : return TXGBE_ERR_SWFW_SYNC;
1294 : :
1295 : : mngsem = rd32(hw, TXGBE_MNGSEM);
1296 [ # # ]: 0 : if (mngsem & (fwmask | swmask)) {
1297 : : /* Resource is currently in use by FW or SW */
1298 : 0 : txgbe_release_eeprom_semaphore(hw);
1299 : : msec_delay(5);
1300 : : } else {
1301 : 0 : mngsem |= swmask;
1302 : : wr32(hw, TXGBE_MNGSEM, mngsem);
1303 : 0 : txgbe_release_eeprom_semaphore(hw);
1304 : 0 : return 0;
1305 : : }
1306 : : }
1307 : :
1308 : : /* If time expired clear the bits holding the lock and retry */
1309 [ # # ]: 0 : if (mngsem & (fwmask | swmask))
1310 : 0 : txgbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
1311 : :
1312 : : msec_delay(5);
1313 : 0 : return TXGBE_ERR_SWFW_SYNC;
1314 : : }
1315 : :
1316 : : /**
1317 : : * txgbe_release_swfw_sync - Release SWFW semaphore
1318 : : * @hw: pointer to hardware structure
1319 : : * @mask: Mask to specify which semaphore to release
1320 : : *
1321 : : * Releases the SWFW semaphore through the MNGSEM register for the specified
1322 : : * function (CSR, PHY0, PHY1, EEPROM, Flash)
1323 : : **/
1324 : 0 : void txgbe_release_swfw_sync(struct txgbe_hw *hw, u32 mask)
1325 : : {
1326 : : u32 mngsem;
1327 : : u32 swmask = mask;
1328 : :
1329 : 0 : txgbe_get_eeprom_semaphore(hw);
1330 : :
1331 : : mngsem = rd32(hw, TXGBE_MNGSEM);
1332 : 0 : mngsem &= ~swmask;
1333 : : wr32(hw, TXGBE_MNGSEM, mngsem);
1334 : :
1335 : 0 : txgbe_release_eeprom_semaphore(hw);
1336 : 0 : }
1337 : :
1338 : : /**
1339 : : * txgbe_disable_sec_rx_path - Stops the receive data path
1340 : : * @hw: pointer to hardware structure
1341 : : *
1342 : : * Stops the receive data path and waits for the HW to internally empty
1343 : : * the Rx security block
1344 : : **/
1345 : 0 : s32 txgbe_disable_sec_rx_path(struct txgbe_hw *hw)
1346 : : {
1347 : : #define TXGBE_MAX_SECRX_POLL 4000
1348 : :
1349 : : int i;
1350 : : u32 secrxreg;
1351 : :
1352 : : secrxreg = rd32(hw, TXGBE_SECRXCTL);
1353 : 0 : secrxreg |= TXGBE_SECRXCTL_XDSA;
1354 : : wr32(hw, TXGBE_SECRXCTL, secrxreg);
1355 [ # # ]: 0 : for (i = 0; i < TXGBE_MAX_SECRX_POLL; i++) {
1356 : : secrxreg = rd32(hw, TXGBE_SECRXSTAT);
1357 [ # # ]: 0 : if (!(secrxreg & TXGBE_SECRXSTAT_RDY))
1358 : : /* Use interrupt-safe sleep just in case */
1359 : 0 : usec_delay(10);
1360 : : else
1361 : : break;
1362 : : }
1363 : :
1364 : : /* For informational purposes only */
1365 [ # # ]: 0 : if (i >= TXGBE_MAX_SECRX_POLL)
1366 : 0 : DEBUGOUT("Rx unit being enabled before security path fully disabled. Continuing with init.");
1367 : :
1368 : 0 : return 0;
1369 : : }
1370 : :
1371 : : /**
1372 : : * txgbe_enable_sec_rx_path - Enables the receive data path
1373 : : * @hw: pointer to hardware structure
1374 : : *
1375 : : * Enables the receive data path.
1376 : : **/
1377 : 0 : s32 txgbe_enable_sec_rx_path(struct txgbe_hw *hw)
1378 : : {
1379 : : u32 secrxreg;
1380 : :
1381 : : secrxreg = rd32(hw, TXGBE_SECRXCTL);
1382 : 0 : secrxreg &= ~TXGBE_SECRXCTL_XDSA;
1383 : : wr32(hw, TXGBE_SECRXCTL, secrxreg);
1384 : : txgbe_flush(hw);
1385 : :
1386 : 0 : return 0;
1387 : : }
1388 : :
1389 : : /**
1390 : : * txgbe_disable_sec_tx_path - Stops the transmit data path
1391 : : * @hw: pointer to hardware structure
1392 : : *
1393 : : * Stops the transmit data path and waits for the HW to internally empty
1394 : : * the Tx security block
1395 : : **/
1396 : 0 : int txgbe_disable_sec_tx_path(struct txgbe_hw *hw)
1397 : : {
1398 : : #define TXGBE_MAX_SECTX_POLL 40
1399 : :
1400 : : int i;
1401 : : u32 sectxreg;
1402 : :
1403 : : sectxreg = rd32(hw, TXGBE_SECTXCTL);
1404 : 0 : sectxreg |= TXGBE_SECTXCTL_XDSA;
1405 : : wr32(hw, TXGBE_SECTXCTL, sectxreg);
1406 [ # # ]: 0 : for (i = 0; i < TXGBE_MAX_SECTX_POLL; i++) {
1407 : : sectxreg = rd32(hw, TXGBE_SECTXSTAT);
1408 [ # # ]: 0 : if (sectxreg & TXGBE_SECTXSTAT_RDY)
1409 : : break;
1410 : : /* Use interrupt-safe sleep just in case */
1411 : 0 : usec_delay(1000);
1412 : : }
1413 : :
1414 : : /* For informational purposes only */
1415 [ # # ]: 0 : if (i >= TXGBE_MAX_SECTX_POLL)
1416 : 0 : DEBUGOUT("Tx unit being enabled before security path fully disabled. Continuing with init.");
1417 : :
1418 : 0 : return 0;
1419 : : }
1420 : :
1421 : : /**
1422 : : * txgbe_enable_sec_tx_path - Enables the transmit data path
1423 : : * @hw: pointer to hardware structure
1424 : : *
1425 : : * Enables the transmit data path.
1426 : : **/
1427 : 0 : int txgbe_enable_sec_tx_path(struct txgbe_hw *hw)
1428 : : {
1429 : : uint32_t sectxreg;
1430 : :
1431 : : sectxreg = rd32(hw, TXGBE_SECTXCTL);
1432 : 0 : sectxreg &= ~TXGBE_SECTXCTL_XDSA;
1433 : : wr32(hw, TXGBE_SECTXCTL, sectxreg);
1434 : : txgbe_flush(hw);
1435 : :
1436 : 0 : return 0;
1437 : : }
1438 : :
1439 : : /**
1440 : : * txgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
1441 : : * @hw: pointer to hardware structure
1442 : : * @san_mac_offset: SAN MAC address offset
1443 : : *
1444 : : * This function will read the EEPROM location for the SAN MAC address
1445 : : * pointer, and returns the value at that location. This is used in both
1446 : : * get and set mac_addr routines.
1447 : : **/
1448 : 0 : static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
1449 : : u16 *san_mac_offset)
1450 : : {
1451 : : s32 err;
1452 : :
1453 : : /*
1454 : : * First read the EEPROM pointer to see if the MAC addresses are
1455 : : * available.
1456 : : */
1457 : 0 : err = hw->rom.readw_sw(hw, TXGBE_SAN_MAC_ADDR_PTR,
1458 : : san_mac_offset);
1459 [ # # ]: 0 : if (err) {
1460 : 0 : DEBUGOUT("eeprom at offset %d failed",
1461 : : TXGBE_SAN_MAC_ADDR_PTR);
1462 : : }
1463 : :
1464 : 0 : return err;
1465 : : }
1466 : :
1467 : : /**
1468 : : * txgbe_get_san_mac_addr - SAN MAC address retrieval from the EEPROM
1469 : : * @hw: pointer to hardware structure
1470 : : * @san_mac_addr: SAN MAC address
1471 : : *
1472 : : * Reads the SAN MAC address from the EEPROM, if it's available. This is
1473 : : * per-port, so set_lan_id() must be called before reading the addresses.
1474 : : * set_lan_id() is called by identify_sfp(), but this cannot be relied
1475 : : * upon for non-SFP connections, so we must call it here.
1476 : : **/
1477 : 0 : s32 txgbe_get_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
1478 : : {
1479 : : u16 san_mac_data, san_mac_offset;
1480 : : u8 i;
1481 : : s32 err;
1482 : :
1483 : : /*
1484 : : * First read the EEPROM pointer to see if the MAC addresses are
1485 : : * available. If they're not, no point in calling set_lan_id() here.
1486 : : */
1487 : 0 : err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
1488 [ # # # # : 0 : if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
# # ]
1489 : 0 : goto san_mac_addr_out;
1490 : :
1491 : : /* apply the port offset to the address offset */
1492 [ # # ]: 0 : (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
1493 : : (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
1494 [ # # ]: 0 : for (i = 0; i < 3; i++) {
1495 : 0 : err = hw->rom.read16(hw, san_mac_offset,
1496 : : &san_mac_data);
1497 [ # # ]: 0 : if (err) {
1498 : 0 : DEBUGOUT("eeprom read at offset %d failed",
1499 : : san_mac_offset);
1500 : 0 : goto san_mac_addr_out;
1501 : : }
1502 : 0 : san_mac_addr[i * 2] = (u8)(san_mac_data);
1503 : 0 : san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
1504 : 0 : san_mac_offset++;
1505 : : }
1506 : : return 0;
1507 : :
1508 : : san_mac_addr_out:
1509 : : /*
1510 : : * No addresses available in this EEPROM. It's not an
1511 : : * error though, so just wipe the local address and return.
1512 : : */
1513 [ # # ]: 0 : for (i = 0; i < 6; i++)
1514 : 0 : san_mac_addr[i] = 0xFF;
1515 : : return 0;
1516 : : }
1517 : :
1518 : : /**
1519 : : * txgbe_set_san_mac_addr - Write the SAN MAC address to the EEPROM
1520 : : * @hw: pointer to hardware structure
1521 : : * @san_mac_addr: SAN MAC address
1522 : : *
1523 : : * Write a SAN MAC address to the EEPROM.
1524 : : **/
1525 : 0 : s32 txgbe_set_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
1526 : : {
1527 : : s32 err;
1528 : : u16 san_mac_data, san_mac_offset;
1529 : : u8 i;
1530 : :
1531 : : /* Look for SAN mac address pointer. If not defined, return */
1532 : 0 : err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
1533 [ # # # # : 0 : if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
# # ]
1534 : : return TXGBE_ERR_NO_SAN_ADDR_PTR;
1535 : :
1536 : : /* Apply the port offset to the address offset */
1537 [ # # ]: 0 : (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
1538 : : (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
1539 : :
1540 [ # # ]: 0 : for (i = 0; i < 3; i++) {
1541 : 0 : san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
1542 : 0 : san_mac_data |= (u16)(san_mac_addr[i * 2]);
1543 : 0 : hw->rom.write16(hw, san_mac_offset, san_mac_data);
1544 : 0 : san_mac_offset++;
1545 : : }
1546 : :
1547 : : return 0;
1548 : : }
1549 : :
1550 : : /**
1551 : : * txgbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
1552 : : * @hw: pointer to hardware struct
1553 : : * @rar: receive address register index to disassociate
1554 : : * @vmdq: VMDq pool index to remove from the rar
1555 : : **/
1556 : 0 : s32 txgbe_clear_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
1557 : : {
1558 : : u32 mpsar_lo, mpsar_hi;
1559 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
1560 : :
1561 : : /* Make sure we are using a valid rar index range */
1562 [ # # ]: 0 : if (rar >= rar_entries) {
1563 : 0 : DEBUGOUT("RAR index %d is out of range.", rar);
1564 : 0 : return TXGBE_ERR_INVALID_ARGUMENT;
1565 : : }
1566 : :
1567 : : wr32(hw, TXGBE_ETHADDRIDX, rar);
1568 : : mpsar_lo = rd32(hw, TXGBE_ETHADDRASSL);
1569 : : mpsar_hi = rd32(hw, TXGBE_ETHADDRASSH);
1570 : :
1571 : : if (TXGBE_REMOVED(hw->hw_addr))
1572 : : goto done;
1573 : :
1574 [ # # ]: 0 : if (!mpsar_lo && !mpsar_hi)
1575 : 0 : goto done;
1576 : :
1577 [ # # ]: 0 : if (vmdq == BIT_MASK32) {
1578 [ # # ]: 0 : if (mpsar_lo) {
1579 : : wr32(hw, TXGBE_ETHADDRASSL, 0);
1580 : : mpsar_lo = 0;
1581 : : }
1582 [ # # ]: 0 : if (mpsar_hi) {
1583 : : wr32(hw, TXGBE_ETHADDRASSH, 0);
1584 : : mpsar_hi = 0;
1585 : : }
1586 [ # # ]: 0 : } else if (vmdq < 32) {
1587 : 0 : mpsar_lo &= ~(1 << vmdq);
1588 : : wr32(hw, TXGBE_ETHADDRASSL, mpsar_lo);
1589 : : } else {
1590 : 0 : mpsar_hi &= ~(1 << (vmdq - 32));
1591 : : wr32(hw, TXGBE_ETHADDRASSH, mpsar_hi);
1592 : : }
1593 : :
1594 : : /* was that the last pool using this rar? */
1595 [ # # # # ]: 0 : if (mpsar_lo == 0 && mpsar_hi == 0 &&
1596 [ # # ]: 0 : rar != 0 && rar != hw->mac.san_mac_rar_index)
1597 : 0 : hw->mac.clear_rar(hw, rar);
1598 : 0 : done:
1599 : : return 0;
1600 : : }
1601 : :
1602 : : /**
1603 : : * txgbe_set_vmdq - Associate a VMDq pool index with a rx address
1604 : : * @hw: pointer to hardware struct
1605 : : * @rar: receive address register index to associate with a VMDq index
1606 : : * @vmdq: VMDq pool index
1607 : : **/
1608 : 0 : s32 txgbe_set_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
1609 : : {
1610 : : u32 mpsar;
1611 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
1612 : :
1613 : : /* Make sure we are using a valid rar index range */
1614 [ # # ]: 0 : if (rar >= rar_entries) {
1615 : 0 : DEBUGOUT("RAR index %d is out of range.", rar);
1616 : 0 : return TXGBE_ERR_INVALID_ARGUMENT;
1617 : : }
1618 : :
1619 : : wr32(hw, TXGBE_ETHADDRIDX, rar);
1620 [ # # ]: 0 : if (vmdq < 32) {
1621 : : mpsar = rd32(hw, TXGBE_ETHADDRASSL);
1622 : 0 : mpsar |= 1 << vmdq;
1623 : : wr32(hw, TXGBE_ETHADDRASSL, mpsar);
1624 : : } else {
1625 : : mpsar = rd32(hw, TXGBE_ETHADDRASSH);
1626 : 0 : mpsar |= 1 << (vmdq - 32);
1627 : : wr32(hw, TXGBE_ETHADDRASSH, mpsar);
1628 : : }
1629 : : return 0;
1630 : : }
1631 : :
1632 : : /**
1633 : : * txgbe_init_uta_tables - Initialize the Unicast Table Array
1634 : : * @hw: pointer to hardware structure
1635 : : **/
1636 : 0 : s32 txgbe_init_uta_tables(struct txgbe_hw *hw)
1637 : : {
1638 : : int i;
1639 : :
1640 : 0 : DEBUGOUT(" Clearing UTA");
1641 : :
1642 [ # # ]: 0 : for (i = 0; i < 128; i++)
1643 : 0 : wr32(hw, TXGBE_UCADDRTBL(i), 0);
1644 : :
1645 : 0 : return 0;
1646 : : }
1647 : :
1648 : : /**
1649 : : * txgbe_find_vlvf_slot - find the vlanid or the first empty slot
1650 : : * @hw: pointer to hardware structure
1651 : : * @vlan: VLAN id to write to VLAN filter
1652 : : * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
1653 : : * vlanid not found
1654 : : *
1655 : : *
1656 : : * return the VLVF index where this VLAN id should be placed
1657 : : *
1658 : : **/
1659 : 0 : s32 txgbe_find_vlvf_slot(struct txgbe_hw *hw, u32 vlan, bool vlvf_bypass)
1660 : : {
1661 : : s32 regindex, first_empty_slot;
1662 : : u32 bits;
1663 : :
1664 : : /* short cut the special case */
1665 [ # # ]: 0 : if (vlan == 0)
1666 : : return 0;
1667 : :
1668 : : /* if vlvf_bypass is set we don't want to use an empty slot, we
1669 : : * will simply bypass the VLVF if there are no entries present in the
1670 : : * VLVF that contain our VLAN
1671 : : */
1672 [ # # ]: 0 : first_empty_slot = vlvf_bypass ? TXGBE_ERR_NO_SPACE : 0;
1673 : :
1674 : : /* add VLAN enable bit for comparison */
1675 : 0 : vlan |= TXGBE_PSRVLAN_EA;
1676 : :
1677 : : /* Search for the vlan id in the VLVF entries. Save off the first empty
1678 : : * slot found along the way.
1679 : : *
1680 : : * pre-decrement loop covering (TXGBE_NUM_POOL - 1) .. 1
1681 : : */
1682 [ # # ]: 0 : for (regindex = TXGBE_NUM_POOL; --regindex;) {
1683 : 0 : wr32(hw, TXGBE_PSRVLANIDX, regindex);
1684 : : bits = rd32(hw, TXGBE_PSRVLAN);
1685 [ # # ]: 0 : if (bits == vlan)
1686 : 0 : return regindex;
1687 [ # # ]: 0 : if (!first_empty_slot && !bits)
1688 : : first_empty_slot = regindex;
1689 : : }
1690 : :
1691 : : /* If we are here then we didn't find the VLAN. Return first empty
1692 : : * slot we found during our search, else error.
1693 : : */
1694 [ # # ]: 0 : if (!first_empty_slot)
1695 : 0 : DEBUGOUT("No space in VLVF.");
1696 : :
1697 [ # # ]: 0 : return first_empty_slot ? first_empty_slot : TXGBE_ERR_NO_SPACE;
1698 : : }
1699 : :
1700 : : /**
1701 : : * txgbe_set_vfta - Set VLAN filter table
1702 : : * @hw: pointer to hardware structure
1703 : : * @vlan: VLAN id to write to VLAN filter
1704 : : * @vind: VMDq output index that maps queue to VLAN id in VLVFB
1705 : : * @vlan_on: boolean flag to turn on/off VLAN
1706 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
1707 : : *
1708 : : * Turn on/off specified VLAN in the VLAN filter table.
1709 : : **/
1710 : 0 : s32 txgbe_set_vfta(struct txgbe_hw *hw, u32 vlan, u32 vind,
1711 : : bool vlan_on, bool vlvf_bypass)
1712 : : {
1713 : : u32 regidx, vfta_delta, vfta;
1714 : : s32 err;
1715 : :
1716 [ # # ]: 0 : if (vlan > 4095 || vind > 63)
1717 : : return TXGBE_ERR_PARAM;
1718 : :
1719 : : /*
1720 : : * this is a 2 part operation - first the VFTA, then the
1721 : : * VLVF and VLVFB if VT Mode is set
1722 : : * We don't write the VFTA until we know the VLVF part succeeded.
1723 : : */
1724 : :
1725 : : /* Part 1
1726 : : * The VFTA is a bitstring made up of 128 32-bit registers
1727 : : * that enable the particular VLAN id, much like the MTA:
1728 : : * bits[11-5]: which register
1729 : : * bits[4-0]: which bit in the register
1730 : : */
1731 : 0 : regidx = vlan / 32;
1732 : 0 : vfta_delta = 1 << (vlan % 32);
1733 : 0 : vfta = rd32(hw, TXGBE_VLANTBL(regidx));
1734 : :
1735 : : /*
1736 : : * vfta_delta represents the difference between the current value
1737 : : * of vfta and the value we want in the register. Since the diff
1738 : : * is an XOR mask we can just update the vfta using an XOR
1739 : : */
1740 [ # # ]: 0 : vfta_delta &= vlan_on ? ~vfta : vfta;
1741 : 0 : vfta ^= vfta_delta;
1742 : :
1743 : : /* Part 2
1744 : : * Call txgbe_set_vlvf to set VLVFB and VLVF
1745 : : */
1746 : 0 : err = txgbe_set_vlvf(hw, vlan, vind, vlan_on, &vfta_delta,
1747 : : vfta, vlvf_bypass);
1748 [ # # ]: 0 : if (err != 0) {
1749 [ # # ]: 0 : if (vlvf_bypass)
1750 : 0 : goto vfta_update;
1751 : : return err;
1752 : : }
1753 : :
1754 : 0 : vfta_update:
1755 : : /* Update VFTA now that we are ready for traffic */
1756 [ # # ]: 0 : if (vfta_delta)
1757 : : wr32(hw, TXGBE_VLANTBL(regidx), vfta);
1758 : :
1759 : : return 0;
1760 : : }
1761 : :
1762 : : /**
1763 : : * txgbe_set_vlvf - Set VLAN Pool Filter
1764 : : * @hw: pointer to hardware structure
1765 : : * @vlan: VLAN id to write to VLAN filter
1766 : : * @vind: VMDq output index that maps queue to VLAN id in PSRVLANPLM
1767 : : * @vlan_on: boolean flag to turn on/off VLAN in PSRVLAN
1768 : : * @vfta_delta: pointer to the difference between the current value
1769 : : * of PSRVLANPLM and the desired value
1770 : : * @vfta: the desired value of the VFTA
1771 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
1772 : : *
1773 : : * Turn on/off specified bit in VLVF table.
1774 : : **/
1775 : 0 : s32 txgbe_set_vlvf(struct txgbe_hw *hw, u32 vlan, u32 vind,
1776 : : bool vlan_on, u32 *vfta_delta, u32 vfta,
1777 : : bool vlvf_bypass)
1778 : : {
1779 : : u32 bits;
1780 : : u32 portctl;
1781 : : s32 vlvf_index;
1782 : :
1783 [ # # ]: 0 : if (vlan > 4095 || vind > 63)
1784 : : return TXGBE_ERR_PARAM;
1785 : :
1786 : : /* If VT Mode is set
1787 : : * Either vlan_on
1788 : : * make sure the vlan is in PSRVLAN
1789 : : * set the vind bit in the matching PSRVLANPLM
1790 : : * Or !vlan_on
1791 : : * clear the pool bit and possibly the vind
1792 : : */
1793 : : portctl = rd32(hw, TXGBE_PORTCTL);
1794 [ # # ]: 0 : if (!(portctl & TXGBE_PORTCTL_NUMVT_MASK))
1795 : : return 0;
1796 : :
1797 : 0 : vlvf_index = txgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
1798 [ # # ]: 0 : if (vlvf_index < 0)
1799 : : return vlvf_index;
1800 : :
1801 : 0 : wr32(hw, TXGBE_PSRVLANIDX, vlvf_index);
1802 : 0 : bits = rd32(hw, TXGBE_PSRVLANPLM(vind / 32));
1803 : :
1804 : : /* set the pool bit */
1805 : 0 : bits |= 1 << (vind % 32);
1806 [ # # ]: 0 : if (vlan_on)
1807 : 0 : goto vlvf_update;
1808 : :
1809 : : /* clear the pool bit */
1810 : 0 : bits ^= 1 << (vind % 32);
1811 : :
1812 [ # # # # ]: 0 : if (!bits &&
1813 : : !rd32(hw, TXGBE_PSRVLANPLM(vind / 32))) {
1814 : : /* Clear PSRVLANPLM first, then disable PSRVLAN. Otherwise
1815 : : * we run the risk of stray packets leaking into
1816 : : * the PF via the default pool
1817 : : */
1818 [ # # ]: 0 : if (*vfta_delta)
1819 : 0 : wr32(hw, TXGBE_PSRVLANPLM(vlan / 32), vfta);
1820 : :
1821 : : /* disable VLVF and clear remaining bit from pool */
1822 : : wr32(hw, TXGBE_PSRVLAN, 0);
1823 : : wr32(hw, TXGBE_PSRVLANPLM(vind / 32), 0);
1824 : :
1825 : 0 : return 0;
1826 : : }
1827 : :
1828 : : /* If there are still bits set in the PSRVLANPLM registers
1829 : : * for the VLAN ID indicated we need to see if the
1830 : : * caller is requesting that we clear the PSRVLANPLM entry bit.
1831 : : * If the caller has requested that we clear the PSRVLANPLM
1832 : : * entry bit but there are still pools/VFs using this VLAN
1833 : : * ID entry then ignore the request. We're not worried
1834 : : * about the case where we're turning the PSRVLANPLM VLAN ID
1835 : : * entry bit on, only when requested to turn it off as
1836 : : * there may be multiple pools and/or VFs using the
1837 : : * VLAN ID entry. In that case we cannot clear the
1838 : : * PSRVLANPLM bit until all pools/VFs using that VLAN ID have also
1839 : : * been cleared. This will be indicated by "bits" being
1840 : : * zero.
1841 : : */
1842 : 0 : *vfta_delta = 0;
1843 : :
1844 : 0 : vlvf_update:
1845 : : /* record pool change and enable VLAN ID if not already enabled */
1846 : : wr32(hw, TXGBE_PSRVLANPLM(vind / 32), bits);
1847 : 0 : wr32(hw, TXGBE_PSRVLAN, TXGBE_PSRVLAN_EA | vlan);
1848 : :
1849 : 0 : return 0;
1850 : : }
1851 : :
1852 : : /**
1853 : : * txgbe_clear_vfta - Clear VLAN filter table
1854 : : * @hw: pointer to hardware structure
1855 : : *
1856 : : * Clears the VLAN filer table, and the VMDq index associated with the filter
1857 : : **/
1858 : 0 : s32 txgbe_clear_vfta(struct txgbe_hw *hw)
1859 : : {
1860 : : u32 offset;
1861 : :
1862 [ # # ]: 0 : for (offset = 0; offset < hw->mac.vft_size; offset++)
1863 : 0 : wr32(hw, TXGBE_VLANTBL(offset), 0);
1864 : :
1865 [ # # ]: 0 : for (offset = 0; offset < TXGBE_NUM_POOL; offset++) {
1866 : : wr32(hw, TXGBE_PSRVLANIDX, offset);
1867 : : wr32(hw, TXGBE_PSRVLAN, 0);
1868 : : wr32(hw, TXGBE_PSRVLANPLM(0), 0);
1869 : : wr32(hw, TXGBE_PSRVLANPLM(1), 0);
1870 : : }
1871 : :
1872 : 0 : return 0;
1873 : : }
1874 : :
1875 : : /**
1876 : : * txgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
1877 : : * @hw: pointer to hardware structure
1878 : : *
1879 : : * Contains the logic to identify if we need to verify link for the
1880 : : * crosstalk fix
1881 : : **/
1882 : : static bool txgbe_need_crosstalk_fix(struct txgbe_hw *hw)
1883 : : {
1884 : : /* Does FW say we need the fix */
1885 : 0 : if (!hw->need_crosstalk_fix)
1886 : : return false;
1887 : :
1888 : : /* Only consider SFP+ PHYs i.e. media type fiber */
1889 [ # # ]: 0 : switch (hw->phy.media_type) {
1890 : : case txgbe_media_type_fiber:
1891 : : case txgbe_media_type_fiber_qsfp:
1892 : : break;
1893 : : default:
1894 : : return false;
1895 : : }
1896 : :
1897 : : return true;
1898 : : }
1899 : :
1900 : : /**
1901 : : * txgbe_check_mac_link - Determine link and speed status
1902 : : * @hw: pointer to hardware structure
1903 : : * @speed: pointer to link speed
1904 : : * @link_up: true when link is up
1905 : : * @link_up_wait_to_complete: bool used to wait for link up or not
1906 : : *
1907 : : * Reads the links register to determine if link is up and the current speed
1908 : : **/
1909 [ # # ]: 0 : s32 txgbe_check_mac_link(struct txgbe_hw *hw, u32 *speed,
1910 : : bool *link_up, bool link_up_wait_to_complete)
1911 : : {
1912 : : u32 links_reg, links_orig;
1913 : : u32 i;
1914 : :
1915 : : /* If Crosstalk fix enabled do the sanity check of making sure
1916 : : * the SFP+ cage is full.
1917 : : */
1918 : : if (txgbe_need_crosstalk_fix(hw)) {
1919 : : u32 sfp_cage_full;
1920 : :
1921 [ # # ]: 0 : switch (hw->mac.type) {
1922 : : case txgbe_mac_raptor:
1923 : 0 : sfp_cage_full = !rd32m(hw, TXGBE_GPIODATA,
1924 : : TXGBE_GPIOBIT_2);
1925 : : break;
1926 : : default:
1927 : : /* sanity check - No SFP+ devices here */
1928 : : sfp_cage_full = false;
1929 : : break;
1930 : : }
1931 : :
1932 [ # # ]: 0 : if (!sfp_cage_full) {
1933 : 0 : *link_up = false;
1934 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
1935 : 0 : return 0;
1936 : : }
1937 : : }
1938 : :
1939 : : /* clear the old state */
1940 : : links_orig = rd32(hw, TXGBE_PORTSTAT);
1941 : :
1942 : : links_reg = rd32(hw, TXGBE_PORTSTAT);
1943 : :
1944 [ # # ]: 0 : if (links_orig != links_reg) {
1945 : 0 : DEBUGOUT("LINKS changed from %08X to %08X",
1946 : : links_orig, links_reg);
1947 : : }
1948 : :
1949 [ # # ]: 0 : if (link_up_wait_to_complete) {
1950 [ # # ]: 0 : for (i = 0; i < hw->mac.max_link_up_time; i++) {
1951 [ # # ]: 0 : if (!(links_reg & TXGBE_PORTSTAT_UP)) {
1952 : 0 : *link_up = false;
1953 : : } else {
1954 : 0 : *link_up = true;
1955 : 0 : break;
1956 : : }
1957 : : msec_delay(100);
1958 : : links_reg = rd32(hw, TXGBE_PORTSTAT);
1959 : : }
1960 : : } else {
1961 [ # # ]: 0 : if (links_reg & TXGBE_PORTSTAT_UP)
1962 : 0 : *link_up = true;
1963 : : else
1964 : 0 : *link_up = false;
1965 : : }
1966 : :
1967 [ # # # # ]: 0 : switch (links_reg & TXGBE_PORTSTAT_BW_MASK) {
1968 : 0 : case TXGBE_PORTSTAT_BW_10G:
1969 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL;
1970 : 0 : break;
1971 : 0 : case TXGBE_PORTSTAT_BW_1G:
1972 : 0 : *speed = TXGBE_LINK_SPEED_1GB_FULL;
1973 : 0 : break;
1974 : 0 : case TXGBE_PORTSTAT_BW_100M:
1975 : 0 : *speed = TXGBE_LINK_SPEED_100M_FULL;
1976 : 0 : break;
1977 : 0 : default:
1978 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
1979 : : }
1980 : :
1981 : : return 0;
1982 : : }
1983 : :
1984 : : /**
1985 : : * txgbe_get_wwn_prefix - Get alternative WWNN/WWPN prefix from
1986 : : * the EEPROM
1987 : : * @hw: pointer to hardware structure
1988 : : * @wwnn_prefix: the alternative WWNN prefix
1989 : : * @wwpn_prefix: the alternative WWPN prefix
1990 : : *
1991 : : * This function will read the EEPROM from the alternative SAN MAC address
1992 : : * block to check the support for the alternative WWNN/WWPN prefix support.
1993 : : **/
1994 : 0 : s32 txgbe_get_wwn_prefix(struct txgbe_hw *hw, u16 *wwnn_prefix,
1995 : : u16 *wwpn_prefix)
1996 : : {
1997 : : u16 offset, caps;
1998 : : u16 alt_san_mac_blk_offset;
1999 : :
2000 : : /* clear output first */
2001 : 0 : *wwnn_prefix = 0xFFFF;
2002 : 0 : *wwpn_prefix = 0xFFFF;
2003 : :
2004 : : /* check if alternative SAN MAC is supported */
2005 : : offset = TXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
2006 [ # # ]: 0 : if (hw->rom.readw_sw(hw, offset, &alt_san_mac_blk_offset))
2007 : 0 : goto wwn_prefix_err;
2008 : :
2009 [ # # ]: 0 : if (alt_san_mac_blk_offset == 0 || alt_san_mac_blk_offset == 0xFFFF)
2010 : 0 : goto wwn_prefix_out;
2011 : :
2012 : : /* check capability in alternative san mac address block */
2013 : : offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2014 [ # # ]: 0 : if (hw->rom.read16(hw, offset, &caps))
2015 : 0 : goto wwn_prefix_err;
2016 [ # # ]: 0 : if (!(caps & TXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2017 : 0 : goto wwn_prefix_out;
2018 : :
2019 : : /* get the corresponding prefix for WWNN/WWPN */
2020 : 0 : offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2021 [ # # ]: 0 : if (hw->rom.read16(hw, offset, wwnn_prefix))
2022 : 0 : DEBUGOUT("eeprom read at offset %d failed", offset);
2023 : :
2024 : 0 : offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2025 [ # # ]: 0 : if (hw->rom.read16(hw, offset, wwpn_prefix))
2026 : 0 : goto wwn_prefix_err;
2027 : :
2028 : 0 : wwn_prefix_out:
2029 : : return 0;
2030 : :
2031 : 0 : wwn_prefix_err:
2032 : 0 : DEBUGOUT("eeprom read at offset %d failed", offset);
2033 : 0 : return 0;
2034 : : }
2035 : :
2036 : : /**
2037 : : * txgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2038 : : * @hw: pointer to hardware structure
2039 : : * @enable: enable or disable switch for MAC anti-spoofing
2040 : : * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
2041 : : *
2042 : : **/
2043 : 0 : void txgbe_set_mac_anti_spoofing(struct txgbe_hw *hw, bool enable, int vf)
2044 : : {
2045 : 0 : int vf_target_reg = vf >> 3;
2046 : : int vf_target_shift = vf % 8;
2047 : : u32 pfvfspoof;
2048 : :
2049 : 0 : pfvfspoof = rd32(hw, TXGBE_POOLTXASMAC(vf_target_reg));
2050 [ # # ]: 0 : if (enable)
2051 : 0 : pfvfspoof |= (1 << vf_target_shift);
2052 : : else
2053 : 0 : pfvfspoof &= ~(1 << vf_target_shift);
2054 : : wr32(hw, TXGBE_POOLTXASMAC(vf_target_reg), pfvfspoof);
2055 : 0 : }
2056 : :
2057 : : /**
2058 : : * txgbe_set_ethertype_anti_spoofing - Configure Ethertype anti-spoofing
2059 : : * @hw: pointer to hardware structure
2060 : : * @enable: enable or disable switch for Ethertype anti-spoofing
2061 : : * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
2062 : : *
2063 : : **/
2064 : 0 : void txgbe_set_ethertype_anti_spoofing(struct txgbe_hw *hw,
2065 : : bool enable, int vf)
2066 : : {
2067 : 0 : int vf_target_reg = vf >> 3;
2068 : : int vf_target_shift = vf % 8;
2069 : : u32 pfvfspoof;
2070 : :
2071 : 0 : pfvfspoof = rd32(hw, TXGBE_POOLTXASET(vf_target_reg));
2072 [ # # ]: 0 : if (enable)
2073 : 0 : pfvfspoof |= (1 << vf_target_shift);
2074 : : else
2075 : 0 : pfvfspoof &= ~(1 << vf_target_shift);
2076 : : wr32(hw, TXGBE_POOLTXASET(vf_target_reg), pfvfspoof);
2077 : 0 : }
2078 : :
2079 : : /**
2080 : : * txgbe_get_device_caps - Get additional device capabilities
2081 : : * @hw: pointer to hardware structure
2082 : : * @device_caps: the EEPROM word with the extra device capabilities
2083 : : *
2084 : : * This function will read the EEPROM location for the device capabilities,
2085 : : * and return the word through device_caps.
2086 : : **/
2087 : 0 : s32 txgbe_get_device_caps(struct txgbe_hw *hw, u16 *device_caps)
2088 : : {
2089 : 0 : hw->rom.readw_sw(hw, TXGBE_DEVICE_CAPS, device_caps);
2090 : :
2091 : 0 : return 0;
2092 : : }
2093 : :
2094 : : /**
2095 : : * txgbe_set_pba - Initialize Rx packet buffer
2096 : : * @hw: pointer to hardware structure
2097 : : * @num_pb: number of packet buffers to allocate
2098 : : * @headroom: reserve n KB of headroom
2099 : : * @strategy: packet buffer allocation strategy
2100 : : **/
2101 : 0 : void txgbe_set_pba(struct txgbe_hw *hw, int num_pb, u32 headroom,
2102 : : int strategy)
2103 : : {
2104 : 0 : u32 pbsize = hw->mac.rx_pb_size;
2105 : : int i = 0;
2106 : : u32 rxpktsize, txpktsize, txpbthresh;
2107 : :
2108 : : UNREFERENCED_PARAMETER(hw);
2109 : :
2110 : : /* Reserve headroom */
2111 : 0 : pbsize -= headroom;
2112 : :
2113 [ # # ]: 0 : if (!num_pb)
2114 : : num_pb = 1;
2115 : :
2116 : : /* Divide remaining packet buffer space amongst the number of packet
2117 : : * buffers requested using supplied strategy.
2118 : : */
2119 [ # # # ]: 0 : switch (strategy) {
2120 : 0 : case PBA_STRATEGY_WEIGHTED:
2121 : : /* txgbe_dcb_pba_80_48 strategy weight first half of packet
2122 : : * buffer with 5/8 of the packet buffer space.
2123 : : */
2124 : 0 : rxpktsize = (pbsize * 5) / (num_pb * 4);
2125 : 0 : pbsize -= rxpktsize * (num_pb / 2);
2126 : 0 : rxpktsize <<= 10;
2127 [ # # ]: 0 : for (; i < (num_pb / 2); i++)
2128 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
2129 : : /* fall through - configure remaining packet buffers */
2130 : : case PBA_STRATEGY_EQUAL:
2131 : 0 : rxpktsize = (pbsize / (num_pb - i));
2132 : 0 : rxpktsize <<= 10;
2133 [ # # ]: 0 : for (; i < num_pb; i++)
2134 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
2135 : : break;
2136 : : default:
2137 : : break;
2138 : : }
2139 : :
2140 : : /* Only support an equally distributed Tx packet buffer strategy. */
2141 : 0 : txpktsize = TXGBE_PBTXSIZE_MAX / num_pb;
2142 : 0 : txpbthresh = (txpktsize / 1024) - TXGBE_TXPKT_SIZE_MAX;
2143 [ # # ]: 0 : for (i = 0; i < num_pb; i++) {
2144 : 0 : wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
2145 : 0 : wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
2146 : : }
2147 : :
2148 : : /* Clear unused TCs, if any, to zero buffer size*/
2149 [ # # ]: 0 : for (; i < TXGBE_MAX_UP; i++) {
2150 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), 0);
2151 : 0 : wr32(hw, TXGBE_PBTXSIZE(i), 0);
2152 : 0 : wr32(hw, TXGBE_PBTXDMATH(i), 0);
2153 : : }
2154 : 0 : }
2155 : :
2156 : : /**
2157 : : * txgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
2158 : : * @hw: pointer to the hardware structure
2159 : : *
2160 : : * The MACs can experience issues if TX work is still pending
2161 : : * when a reset occurs. This function prevents this by flushing the PCIe
2162 : : * buffers on the system.
2163 : : **/
2164 : 0 : void txgbe_clear_tx_pending(struct txgbe_hw *hw)
2165 : : {
2166 : : u32 hlreg0, i, poll;
2167 : :
2168 : : /*
2169 : : * If double reset is not requested then all transactions should
2170 : : * already be clear and as such there is no work to do
2171 : : */
2172 [ # # ]: 0 : if (!(hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
2173 : : return;
2174 : :
2175 : : hlreg0 = rd32(hw, TXGBE_PSRCTL);
2176 : 0 : wr32(hw, TXGBE_PSRCTL, hlreg0 | TXGBE_PSRCTL_LBENA);
2177 : :
2178 : : /* Wait for a last completion before clearing buffers */
2179 : : txgbe_flush(hw);
2180 : : msec_delay(3);
2181 : :
2182 : : /*
2183 : : * Before proceeding, make sure that the PCIe block does not have
2184 : : * transactions pending.
2185 : : */
2186 : : poll = (800 * 11) / 10;
2187 [ # # ]: 0 : for (i = 0; i < poll; i++)
2188 : 0 : usec_delay(100);
2189 : :
2190 : : /* Flush all writes and allow 20usec for all transactions to clear */
2191 : : txgbe_flush(hw);
2192 : 0 : usec_delay(20);
2193 : :
2194 : : /* restore previous register values */
2195 : : wr32(hw, TXGBE_PSRCTL, hlreg0);
2196 : : }
2197 : :
2198 : : /**
2199 : : * txgbe_get_thermal_sensor_data - Gathers thermal sensor data
2200 : : * @hw: pointer to hardware structure
2201 : : *
2202 : : * Returns the thermal sensor data structure
2203 : : **/
2204 : 0 : s32 txgbe_get_thermal_sensor_data(struct txgbe_hw *hw)
2205 : : {
2206 : : struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2207 : : s64 tsv;
2208 : : u32 ts_stat;
2209 : :
2210 : : /* Only support thermal sensors attached to physical port 0 */
2211 [ # # ]: 0 : if (hw->bus.lan_id != 0)
2212 : : return TXGBE_NOT_IMPLEMENTED;
2213 : :
2214 : : ts_stat = rd32(hw, TXGBE_TSSTAT);
2215 : : tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
2216 : : tsv = tsv > 1200 ? tsv : 1200;
2217 : : tsv = -(48380 << 8) / 1000
2218 : : + tsv * (31020 << 8) / 100000
2219 : : - tsv * tsv * (18201 << 8) / 100000000
2220 : : + tsv * tsv * tsv * (81542 << 8) / 1000000000000
2221 : : - tsv * tsv * tsv * tsv * (16743 << 8) / 1000000000000000;
2222 : : tsv >>= 8;
2223 : :
2224 : 0 : data->sensor[0].temp = (s16)tsv;
2225 : :
2226 : 0 : return 0;
2227 : : }
2228 : :
2229 : : /**
2230 : : * txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
2231 : : * @hw: pointer to hardware structure
2232 : : *
2233 : : * Inits the thermal sensor thresholds according to the NVM map
2234 : : * and save off the threshold and location values into mac.thermal_sensor_data
2235 : : **/
2236 : 0 : s32 txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw)
2237 : : {
2238 [ # # ]: 0 : struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2239 : :
2240 : : memset(data, 0, sizeof(struct txgbe_thermal_sensor_data));
2241 : :
2242 [ # # ]: 0 : if (hw->bus.lan_id != 0)
2243 : : return TXGBE_NOT_IMPLEMENTED;
2244 : :
2245 : : wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
2246 : : wr32(hw, TXGBE_TSINTR,
2247 : : TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
2248 : : wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
2249 : :
2250 : :
2251 : 0 : data->sensor[0].alarm_thresh = 100;
2252 : : wr32(hw, TXGBE_TSATHRE, 677);
2253 : 0 : data->sensor[0].dalarm_thresh = 90;
2254 : : wr32(hw, TXGBE_TSDTHRE, 614);
2255 : :
2256 : 0 : return 0;
2257 : : }
2258 : :
2259 : 0 : void txgbe_disable_rx(struct txgbe_hw *hw)
2260 : : {
2261 : : u32 pfdtxgswc;
2262 : :
2263 : : pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
2264 [ # # ]: 0 : if (pfdtxgswc & TXGBE_PSRCTL_LBENA) {
2265 : 0 : pfdtxgswc &= ~TXGBE_PSRCTL_LBENA;
2266 : : wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
2267 : 0 : hw->mac.set_lben = true;
2268 : : } else {
2269 : 0 : hw->mac.set_lben = false;
2270 : : }
2271 : :
2272 : : wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
2273 : : wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
2274 : 0 : }
2275 : :
2276 : 0 : void txgbe_enable_rx(struct txgbe_hw *hw)
2277 : : {
2278 : : u32 pfdtxgswc;
2279 : :
2280 : : wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, TXGBE_MACRXCFG_ENA);
2281 : : wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, TXGBE_PBRXCTL_ENA);
2282 : :
2283 [ # # ]: 0 : if (hw->mac.set_lben) {
2284 : : pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
2285 : 0 : pfdtxgswc |= TXGBE_PSRCTL_LBENA;
2286 : : wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
2287 : 0 : hw->mac.set_lben = false;
2288 : : }
2289 : 0 : }
2290 : :
2291 : : /**
2292 : : * txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
2293 : : * @hw: pointer to hardware structure
2294 : : * @speed: new link speed
2295 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
2296 : : *
2297 : : * Set the link speed in the MAC and/or PHY register and restarts link.
2298 : : **/
2299 : 0 : s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
2300 : : u32 speed,
2301 : : bool autoneg_wait_to_complete)
2302 : : {
2303 : 0 : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2304 : : u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2305 : : s32 status = 0;
2306 : : u32 speedcnt = 0;
2307 : : u32 i = 0;
2308 : 0 : bool autoneg, link_up = false;
2309 : :
2310 : : /* Mask off requested but non-supported speeds */
2311 : 0 : status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
2312 [ # # ]: 0 : if (status != 0)
2313 : : return status;
2314 : :
2315 : 0 : speed &= link_speed;
2316 : :
2317 : : /* Try each speed one by one, highest priority first. We do this in
2318 : : * software because 10Gb fiber doesn't support speed autonegotiation.
2319 : : */
2320 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
2321 : : speedcnt++;
2322 : : highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
2323 : :
2324 : : /* Set the module link speed */
2325 [ # # # ]: 0 : switch (hw->phy.media_type) {
2326 : 0 : case txgbe_media_type_fiber:
2327 : 0 : hw->mac.set_rate_select_speed(hw,
2328 : : TXGBE_LINK_SPEED_10GB_FULL);
2329 : 0 : break;
2330 : : case txgbe_media_type_fiber_qsfp:
2331 : : /* QSFP module automatically detects MAC link speed */
2332 : : break;
2333 : 0 : default:
2334 : 0 : DEBUGOUT("Unexpected media type.");
2335 : 0 : break;
2336 : : }
2337 : :
2338 : : /* Allow module to change analog characteristics (1G->10G) */
2339 : : msec_delay(40);
2340 : :
2341 : 0 : status = hw->mac.setup_mac_link(hw,
2342 : : TXGBE_LINK_SPEED_10GB_FULL,
2343 : : autoneg_wait_to_complete);
2344 [ # # ]: 0 : if (status != 0)
2345 : : return status;
2346 : :
2347 : : /* Flap the Tx laser if it has not already been done */
2348 : 0 : hw->mac.flap_tx_laser(hw);
2349 : :
2350 : : /* Wait for the controller to acquire link. Per IEEE 802.3ap,
2351 : : * Section 73.10.2, we may have to wait up to 500ms if KR is
2352 : : * attempted. uses the same timing for 10g SFI.
2353 : : */
2354 [ # # ]: 0 : for (i = 0; i < 5; i++) {
2355 : : /* Wait for the link partner to also set speed */
2356 : : msec_delay(100);
2357 : :
2358 : : /* If we have link, just jump out */
2359 : 0 : status = hw->mac.check_link(hw, &link_speed,
2360 : : &link_up, false);
2361 [ # # ]: 0 : if (status != 0)
2362 : 0 : return status;
2363 : :
2364 [ # # ]: 0 : if (link_up)
2365 : 0 : goto out;
2366 : : }
2367 : : }
2368 : :
2369 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
2370 : : u32 curr_autoneg;
2371 : :
2372 : 0 : speedcnt++;
2373 [ # # ]: 0 : if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
2374 : : highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
2375 : :
2376 : 0 : status = hw->mac.check_link(hw, &link_speed, &link_up, false);
2377 [ # # ]: 0 : if (status != 0)
2378 : : return status;
2379 : :
2380 : : /* If we already have link at this speed, just jump out */
2381 [ # # ]: 0 : if (link_speed == TXGBE_LINK_SPEED_1GB_FULL) {
2382 : : curr_autoneg = rd32_epcs(hw, SR_MII_MMD_CTL);
2383 [ # # ]: 0 : if (link_up && (hw->autoneg ==
2384 [ # # ]: 0 : !!(curr_autoneg & SR_MII_MMD_CTL_AN_EN)))
2385 : 0 : goto out;
2386 : : }
2387 : :
2388 : : /* Set the module link speed */
2389 [ # # # ]: 0 : switch (hw->phy.media_type) {
2390 : 0 : case txgbe_media_type_fiber:
2391 : 0 : hw->mac.set_rate_select_speed(hw,
2392 : : TXGBE_LINK_SPEED_1GB_FULL);
2393 : 0 : break;
2394 : : case txgbe_media_type_fiber_qsfp:
2395 : : /* QSFP module automatically detects link speed */
2396 : : break;
2397 : 0 : default:
2398 : 0 : DEBUGOUT("Unexpected media type.");
2399 : 0 : break;
2400 : : }
2401 : :
2402 : : /* Allow module to change analog characteristics (10G->1G) */
2403 : : msec_delay(40);
2404 : :
2405 : 0 : status = hw->mac.setup_mac_link(hw,
2406 : : TXGBE_LINK_SPEED_1GB_FULL,
2407 : : autoneg_wait_to_complete);
2408 [ # # ]: 0 : if (status != 0)
2409 : : return status;
2410 : :
2411 : : /* Flap the Tx laser if it has not already been done */
2412 : 0 : hw->mac.flap_tx_laser(hw);
2413 : :
2414 : : /* Wait for the link partner to also set speed */
2415 : : msec_delay(100);
2416 : :
2417 : : /* If we have link, just jump out */
2418 : 0 : status = hw->mac.check_link(hw, &link_speed, &link_up, false);
2419 [ # # ]: 0 : if (status != 0)
2420 : : return status;
2421 : :
2422 [ # # ]: 0 : if (link_up)
2423 : 0 : goto out;
2424 : : }
2425 : :
2426 : : /* We didn't get link. Configure back to the highest speed we tried,
2427 : : * (if there was more than one). We call ourselves back with just the
2428 : : * single highest speed that the user requested.
2429 : : */
2430 [ # # ]: 0 : if (speedcnt > 1)
2431 : 0 : status = txgbe_setup_mac_link_multispeed_fiber(hw,
2432 : : highest_link_speed,
2433 : : autoneg_wait_to_complete);
2434 : :
2435 : 0 : out:
2436 : : /* Set autoneg_advertised value based on input link speed */
2437 : 0 : hw->phy.autoneg_advertised = 0;
2438 : :
2439 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_10GB_FULL)
2440 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
2441 : :
2442 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_1GB_FULL)
2443 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
2444 : :
2445 : : return status;
2446 : : }
2447 : :
2448 : : /**
2449 : : * txgbe_init_shared_code - Initialize the shared code
2450 : : * @hw: pointer to hardware structure
2451 : : *
2452 : : * This will assign function pointers and assign the MAC type and PHY code.
2453 : : * Does not touch the hardware. This function must be called prior to any
2454 : : * other function in the shared code. The txgbe_hw structure should be
2455 : : * memset to 0 prior to calling this function. The following fields in
2456 : : * hw structure should be filled in prior to calling this function:
2457 : : * hw_addr, back, device_id, vendor_id, subsystem_device_id,
2458 : : * subsystem_vendor_id, and revision_id
2459 : : **/
2460 : 0 : s32 txgbe_init_shared_code(struct txgbe_hw *hw)
2461 : : {
2462 : : s32 status;
2463 : :
2464 : : /*
2465 : : * Set the mac type
2466 : : */
2467 : 0 : txgbe_set_mac_type(hw);
2468 : :
2469 : 0 : txgbe_init_ops_dummy(hw);
2470 [ # # # ]: 0 : switch (hw->mac.type) {
2471 : 0 : case txgbe_mac_raptor:
2472 : 0 : status = txgbe_init_ops_pf(hw);
2473 : 0 : break;
2474 : 0 : case txgbe_mac_raptor_vf:
2475 : 0 : status = txgbe_init_ops_vf(hw);
2476 : 0 : break;
2477 : : default:
2478 : : status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2479 : : break;
2480 : : }
2481 : 0 : hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
2482 : :
2483 : 0 : hw->bus.set_lan_id(hw);
2484 : :
2485 : 0 : return status;
2486 : : }
2487 : :
2488 : : /**
2489 : : * txgbe_set_mac_type - Sets MAC type
2490 : : * @hw: pointer to the HW structure
2491 : : *
2492 : : * This function sets the mac type of the adapter based on the
2493 : : * vendor ID and device ID stored in the hw structure.
2494 : : **/
2495 : 0 : s32 txgbe_set_mac_type(struct txgbe_hw *hw)
2496 : : {
2497 : : s32 err = 0;
2498 : :
2499 [ # # ]: 0 : if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
2500 : 0 : DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
2501 : 0 : return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2502 : : }
2503 : :
2504 [ # # # ]: 0 : switch (hw->device_id) {
2505 : 0 : case TXGBE_DEV_ID_SP1000:
2506 : : case TXGBE_DEV_ID_WX1820:
2507 : 0 : hw->mac.type = txgbe_mac_raptor;
2508 : 0 : break;
2509 : 0 : case TXGBE_DEV_ID_SP1000_VF:
2510 : : case TXGBE_DEV_ID_WX1820_VF:
2511 : 0 : hw->phy.media_type = txgbe_media_type_virtual;
2512 : 0 : hw->mac.type = txgbe_mac_raptor_vf;
2513 : 0 : break;
2514 : 0 : default:
2515 : : err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2516 : 0 : DEBUGOUT("Unsupported device id: %x", hw->device_id);
2517 : 0 : break;
2518 : : }
2519 : :
2520 : 0 : DEBUGOUT("found mac: %d, returns: %d",
2521 : : hw->mac.type, err);
2522 : 0 : return err;
2523 : : }
2524 : :
2525 : 0 : void txgbe_init_mac_link_ops(struct txgbe_hw *hw)
2526 : : {
2527 : : struct txgbe_mac_info *mac = &hw->mac;
2528 : :
2529 : : /*
2530 : : * enable the laser control functions for SFP+ fiber
2531 : : * and MNG not enabled
2532 : : */
2533 [ # # # # ]: 0 : if (hw->phy.media_type == txgbe_media_type_fiber &&
2534 : 0 : !txgbe_mng_enabled(hw)) {
2535 : 0 : mac->disable_tx_laser =
2536 : : txgbe_disable_tx_laser_multispeed_fiber;
2537 : 0 : mac->enable_tx_laser =
2538 : : txgbe_enable_tx_laser_multispeed_fiber;
2539 : 0 : mac->flap_tx_laser =
2540 : : txgbe_flap_tx_laser_multispeed_fiber;
2541 : : }
2542 : :
2543 [ # # ]: 0 : if ((hw->phy.media_type == txgbe_media_type_fiber ||
2544 : 0 : hw->phy.media_type == txgbe_media_type_fiber_qsfp) &&
2545 [ # # ]: 0 : hw->phy.multispeed_fiber) {
2546 : : /* Set up dual speed SFP+ support */
2547 : 0 : mac->setup_link = txgbe_setup_mac_link_multispeed_fiber;
2548 : 0 : mac->setup_mac_link = txgbe_setup_mac_link;
2549 : 0 : mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
2550 : : } else {
2551 : 0 : mac->setup_link = txgbe_setup_mac_link;
2552 : 0 : mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
2553 : : }
2554 : 0 : }
2555 : :
2556 : : /**
2557 : : * txgbe_init_phy_raptor - PHY/SFP specific init
2558 : : * @hw: pointer to hardware structure
2559 : : *
2560 : : * Initialize any function pointers that were not able to be
2561 : : * set during init_shared_code because the PHY/SFP type was
2562 : : * not known. Perform the SFP init if necessary.
2563 : : *
2564 : : **/
2565 : 0 : s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
2566 : : {
2567 : : struct txgbe_mac_info *mac = &hw->mac;
2568 : : struct txgbe_phy_info *phy = &hw->phy;
2569 : : s32 err = 0;
2570 : :
2571 [ # # ]: 0 : if ((hw->device_id & 0xFF) == TXGBE_DEV_ID_QSFP) {
2572 : : /* Store flag indicating I2C bus access control unit. */
2573 [ # # # ]: 0 : hw->phy.qsfp_shared_i2c_bus = TRUE;
2574 : :
2575 : : /* Initialize access to QSFP+ I2C bus */
2576 : : txgbe_flush(hw);
2577 : : }
2578 : :
2579 : : /* Identify the PHY or SFP module */
2580 : 0 : err = phy->identify(hw);
2581 [ # # ]: 0 : if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
2582 : 0 : goto init_phy_ops_out;
2583 : :
2584 : : /* Setup function pointers based on detected SFP module and speeds */
2585 : 0 : txgbe_init_mac_link_ops(hw);
2586 : :
2587 : : /* If copper media, overwrite with copper function pointers */
2588 [ # # ]: 0 : if (phy->media_type == txgbe_media_type_copper) {
2589 : 0 : mac->setup_link = txgbe_setup_copper_link_raptor;
2590 : 0 : mac->get_link_capabilities =
2591 : : txgbe_get_copper_link_capabilities;
2592 : : }
2593 : :
2594 [ # # ]: 0 : if (phy->media_type == txgbe_media_type_backplane) {
2595 : 0 : mac->kr_handle = txgbe_kr_handle;
2596 : 0 : mac->bp_down_event = txgbe_bp_down_event;
2597 : : }
2598 : :
2599 : : /* Set necessary function pointers based on PHY type */
2600 [ # # ]: 0 : switch (hw->phy.type) {
2601 : 0 : case txgbe_phy_tn:
2602 : 0 : phy->setup_link = txgbe_setup_phy_link_tnx;
2603 : 0 : phy->check_link = txgbe_check_phy_link_tnx;
2604 : 0 : break;
2605 : : default:
2606 : : break;
2607 : : }
2608 : :
2609 : 0 : init_phy_ops_out:
2610 : 0 : return err;
2611 : : }
2612 : :
2613 : 0 : s32 txgbe_setup_sfp_modules(struct txgbe_hw *hw)
2614 : : {
2615 : : s32 err = 0;
2616 : :
2617 [ # # ]: 0 : if (hw->phy.sfp_type == txgbe_sfp_type_unknown)
2618 : : return 0;
2619 : :
2620 : 0 : txgbe_init_mac_link_ops(hw);
2621 : :
2622 : : /* PHY config will finish before releasing the semaphore */
2623 : 0 : err = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2624 [ # # ]: 0 : if (err != 0)
2625 : : return TXGBE_ERR_SWFW_SYNC;
2626 : :
2627 : : /* Release the semaphore */
2628 : 0 : hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2629 : :
2630 : : /* Delay obtaining semaphore again to allow FW access
2631 : : * prot_autoc_write uses the semaphore too.
2632 : : */
2633 : 0 : msec_delay(hw->rom.semaphore_delay);
2634 : :
2635 : : if (err) {
2636 : : DEBUGOUT("sfp module setup not complete");
2637 : : return TXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
2638 : : }
2639 : :
2640 : : return err;
2641 : : }
2642 : :
2643 : : /**
2644 : : * txgbe_prot_autoc_read_raptor - Hides MAC differences needed for AUTOC read
2645 : : * @hw: pointer to hardware structure
2646 : : * @locked: Return the if we locked for this read.
2647 : : * @value: Value we read from AUTOC
2648 : : *
2649 : : * For this part we need to wrap read-modify-writes with a possible
2650 : : * FW/SW lock. It is assumed this lock will be freed with the next
2651 : : * prot_autoc_write_raptor().
2652 : : */
2653 : 0 : s32 txgbe_prot_autoc_read_raptor(struct txgbe_hw *hw, bool *locked, u64 *value)
2654 : : {
2655 : : s32 err;
2656 : : bool lock_state = false;
2657 : :
2658 : : /* If LESM is on then we need to hold the SW/FW semaphore. */
2659 [ # # ]: 0 : if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2660 : 0 : err = hw->mac.acquire_swfw_sync(hw,
2661 : : TXGBE_MNGSEM_SWPHY);
2662 [ # # ]: 0 : if (err != 0)
2663 : : return TXGBE_ERR_SWFW_SYNC;
2664 : :
2665 : : lock_state = true;
2666 : : }
2667 : :
2668 [ # # ]: 0 : if (locked)
2669 : 0 : *locked = lock_state;
2670 : :
2671 : 0 : *value = txgbe_autoc_read(hw);
2672 : 0 : return 0;
2673 : : }
2674 : :
2675 : : /**
2676 : : * txgbe_prot_autoc_write_raptor - Hides MAC differences needed for AUTOC write
2677 : : * @hw: pointer to hardware structure
2678 : : * @autoc: value to write to AUTOC
2679 : : * @locked: bool to indicate whether the SW/FW lock was already taken by
2680 : : * previous prot_autoc_read_raptor.
2681 : : *
2682 : : * This part may need to hold the SW/FW lock around all writes to
2683 : : * AUTOC. Likewise after a write we need to do a pipeline reset.
2684 : : */
2685 : 0 : s32 txgbe_prot_autoc_write_raptor(struct txgbe_hw *hw, bool locked, u64 autoc)
2686 : : {
2687 : : int err = 0;
2688 : :
2689 : : /* Blocked by MNG FW so bail */
2690 [ # # ]: 0 : if (txgbe_check_reset_blocked(hw))
2691 : 0 : goto out;
2692 : :
2693 : : /* We only need to get the lock if:
2694 : : * - We didn't do it already (in the read part of a read-modify-write)
2695 : : * - LESM is enabled.
2696 : : */
2697 [ # # # # ]: 0 : if (!locked && txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2698 : 0 : err = hw->mac.acquire_swfw_sync(hw,
2699 : : TXGBE_MNGSEM_SWPHY);
2700 [ # # ]: 0 : if (err != 0)
2701 : : return TXGBE_ERR_SWFW_SYNC;
2702 : :
2703 : : locked = true;
2704 : : }
2705 : :
2706 : 0 : txgbe_autoc_write(hw, autoc);
2707 : 0 : err = txgbe_reset_pipeline_raptor(hw);
2708 : :
2709 : 0 : out:
2710 : : /* Free the SW/FW semaphore as we either grabbed it here or
2711 : : * already had it when this function was called.
2712 : : */
2713 [ # # ]: 0 : if (locked)
2714 : 0 : hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2715 : :
2716 : : return err;
2717 : : }
2718 : :
2719 : : /* cmd_addr is used for some special command:
2720 : : * 1. to be sector address, when implemented erase sector command
2721 : : * 2. to be flash address when implemented read, write flash address
2722 : : *
2723 : : * Return 0 on success, return TXGBE_ERR_TIMEOUT on failure.
2724 : : */
2725 : 0 : s32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr)
2726 : : {
2727 : : u32 cmd_val, i;
2728 : :
2729 : 0 : cmd_val = TXGBE_SPICMD_CMD(cmd) | TXGBE_SPICMD_CLK(3) | cmd_addr;
2730 : : wr32(hw, TXGBE_SPICMD, cmd_val);
2731 : :
2732 [ # # ]: 0 : for (i = 0; i < TXGBE_SPI_TIMEOUT; i++) {
2733 [ # # ]: 0 : if (rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_OPDONE)
2734 : : break;
2735 : :
2736 : 0 : usec_delay(10);
2737 : : }
2738 : :
2739 [ # # ]: 0 : if (i == TXGBE_SPI_TIMEOUT)
2740 : 0 : return TXGBE_ERR_TIMEOUT;
2741 : :
2742 : : return 0;
2743 : : }
2744 : :
2745 : 0 : s32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr, u32 *data)
2746 : : {
2747 : : s32 status;
2748 : :
2749 : 0 : status = txgbe_fmgr_cmd_op(hw, 1, addr);
2750 [ # # ]: 0 : if (status < 0) {
2751 : 0 : DEBUGOUT("Read flash timeout.");
2752 : 0 : return status;
2753 : : }
2754 : :
2755 : 0 : *data = rd32(hw, TXGBE_SPIDAT);
2756 : :
2757 : 0 : return 0;
2758 : : }
2759 : :
2760 : : /**
2761 : : * txgbe_init_ops_pf - Inits func ptrs and MAC type
2762 : : * @hw: pointer to hardware structure
2763 : : *
2764 : : * Initialize the function pointers and assign the MAC type.
2765 : : * Does not touch the hardware.
2766 : : **/
2767 : 0 : s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
2768 : : {
2769 : : struct txgbe_bus_info *bus = &hw->bus;
2770 : : struct txgbe_mac_info *mac = &hw->mac;
2771 : : struct txgbe_phy_info *phy = &hw->phy;
2772 : : struct txgbe_rom_info *rom = &hw->rom;
2773 : : struct txgbe_mbx_info *mbx = &hw->mbx;
2774 : :
2775 : : /* BUS */
2776 : 0 : bus->set_lan_id = txgbe_set_lan_id_multi_port;
2777 : :
2778 : : /* PHY */
2779 : 0 : phy->get_media_type = txgbe_get_media_type_raptor;
2780 : 0 : phy->identify = txgbe_identify_phy;
2781 : 0 : phy->init = txgbe_init_phy_raptor;
2782 : 0 : phy->read_reg = txgbe_read_phy_reg;
2783 : 0 : phy->write_reg = txgbe_write_phy_reg;
2784 : 0 : phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
2785 : 0 : phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
2786 : 0 : phy->setup_link = txgbe_setup_phy_link;
2787 : 0 : phy->setup_link_speed = txgbe_setup_phy_link_speed;
2788 : 0 : phy->get_fw_version = txgbe_get_phy_fw_version;
2789 : 0 : phy->read_i2c_byte = txgbe_read_i2c_byte;
2790 : 0 : phy->write_i2c_byte = txgbe_write_i2c_byte;
2791 : 0 : phy->read_i2c_sff8472 = txgbe_read_i2c_sff8472;
2792 : 0 : phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
2793 : 0 : phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
2794 : 0 : phy->identify_sfp = txgbe_identify_module;
2795 : 0 : phy->read_i2c_byte_unlocked = txgbe_read_i2c_byte_unlocked;
2796 : 0 : phy->write_i2c_byte_unlocked = txgbe_write_i2c_byte_unlocked;
2797 : 0 : phy->check_overtemp = txgbe_check_overtemp;
2798 : 0 : phy->reset = txgbe_reset_phy;
2799 : :
2800 : : /* MAC */
2801 : 0 : mac->init_hw = txgbe_init_hw;
2802 : 0 : mac->start_hw = txgbe_start_hw_raptor;
2803 : 0 : mac->clear_hw_cntrs = txgbe_clear_hw_cntrs;
2804 : 0 : mac->enable_rx_dma = txgbe_enable_rx_dma_raptor;
2805 : 0 : mac->get_mac_addr = txgbe_get_mac_addr;
2806 : 0 : mac->stop_hw = txgbe_stop_hw;
2807 : 0 : mac->acquire_swfw_sync = txgbe_acquire_swfw_sync;
2808 : 0 : mac->release_swfw_sync = txgbe_release_swfw_sync;
2809 : 0 : mac->reset_hw = txgbe_reset_hw;
2810 : 0 : mac->update_mc_addr_list = txgbe_update_mc_addr_list;
2811 : :
2812 : 0 : mac->disable_sec_rx_path = txgbe_disable_sec_rx_path;
2813 : 0 : mac->enable_sec_rx_path = txgbe_enable_sec_rx_path;
2814 : 0 : mac->disable_sec_tx_path = txgbe_disable_sec_tx_path;
2815 : 0 : mac->enable_sec_tx_path = txgbe_enable_sec_tx_path;
2816 : 0 : mac->get_san_mac_addr = txgbe_get_san_mac_addr;
2817 : 0 : mac->set_san_mac_addr = txgbe_set_san_mac_addr;
2818 : 0 : mac->get_device_caps = txgbe_get_device_caps;
2819 : 0 : mac->get_wwn_prefix = txgbe_get_wwn_prefix;
2820 : 0 : mac->autoc_read = txgbe_autoc_read;
2821 : 0 : mac->autoc_write = txgbe_autoc_write;
2822 : 0 : mac->prot_autoc_read = txgbe_prot_autoc_read_raptor;
2823 : 0 : mac->prot_autoc_write = txgbe_prot_autoc_write_raptor;
2824 : :
2825 : : /* RAR, Multicast, VLAN */
2826 : 0 : mac->set_rar = txgbe_set_rar;
2827 : 0 : mac->clear_rar = txgbe_clear_rar;
2828 : 0 : mac->init_rx_addrs = txgbe_init_rx_addrs;
2829 : 0 : mac->enable_rx = txgbe_enable_rx;
2830 : 0 : mac->disable_rx = txgbe_disable_rx;
2831 : 0 : mac->set_vmdq = txgbe_set_vmdq;
2832 : 0 : mac->clear_vmdq = txgbe_clear_vmdq;
2833 : 0 : mac->set_vfta = txgbe_set_vfta;
2834 : 0 : mac->set_vlvf = txgbe_set_vlvf;
2835 : 0 : mac->clear_vfta = txgbe_clear_vfta;
2836 : 0 : mac->init_uta_tables = txgbe_init_uta_tables;
2837 : 0 : mac->setup_sfp = txgbe_setup_sfp_modules;
2838 : 0 : mac->set_mac_anti_spoofing = txgbe_set_mac_anti_spoofing;
2839 : 0 : mac->set_ethertype_anti_spoofing = txgbe_set_ethertype_anti_spoofing;
2840 : :
2841 : : /* Flow Control */
2842 : 0 : mac->fc_enable = txgbe_fc_enable;
2843 : 0 : mac->setup_fc = txgbe_setup_fc;
2844 : 0 : mac->fc_autoneg = txgbe_fc_autoneg;
2845 : :
2846 : : /* Link */
2847 : 0 : mac->get_link_capabilities = txgbe_get_link_capabilities_raptor;
2848 : 0 : mac->check_link = txgbe_check_mac_link;
2849 : 0 : mac->setup_pba = txgbe_set_pba;
2850 : :
2851 : : /* Manageability interface */
2852 : 0 : mac->set_fw_drv_ver = txgbe_hic_set_drv_ver;
2853 : 0 : mac->get_thermal_sensor_data = txgbe_get_thermal_sensor_data;
2854 : 0 : mac->init_thermal_sensor_thresh = txgbe_init_thermal_sensor_thresh;
2855 : :
2856 : 0 : mbx->init_params = txgbe_init_mbx_params_pf;
2857 : 0 : mbx->read = txgbe_read_mbx_pf;
2858 : 0 : mbx->write = txgbe_write_mbx_pf;
2859 : 0 : mbx->check_for_msg = txgbe_check_for_msg_pf;
2860 : 0 : mbx->check_for_ack = txgbe_check_for_ack_pf;
2861 : 0 : mbx->check_for_rst = txgbe_check_for_rst_pf;
2862 : :
2863 : : /* EEPROM */
2864 : 0 : rom->init_params = txgbe_init_eeprom_params;
2865 : 0 : rom->read16 = txgbe_ee_read16;
2866 : 0 : rom->readw_buffer = txgbe_ee_readw_buffer;
2867 : 0 : rom->readw_sw = txgbe_ee_readw_sw;
2868 : 0 : rom->read32 = txgbe_ee_read32;
2869 : 0 : rom->write16 = txgbe_ee_write16;
2870 : 0 : rom->writew_buffer = txgbe_ee_writew_buffer;
2871 : 0 : rom->writew_sw = txgbe_ee_writew_sw;
2872 : 0 : rom->write32 = txgbe_ee_write32;
2873 : 0 : rom->validate_checksum = txgbe_validate_eeprom_checksum;
2874 : 0 : rom->update_checksum = txgbe_update_eeprom_checksum;
2875 : 0 : rom->calc_checksum = txgbe_calc_eeprom_checksum;
2876 : :
2877 : 0 : mac->mcft_size = TXGBE_RAPTOR_MC_TBL_SIZE;
2878 : 0 : mac->vft_size = TXGBE_RAPTOR_VFT_TBL_SIZE;
2879 : 0 : mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
2880 : 0 : mac->rx_pb_size = TXGBE_RAPTOR_RX_PB_SIZE;
2881 : 0 : mac->max_rx_queues = TXGBE_RAPTOR_MAX_RX_QUEUES;
2882 : 0 : mac->max_tx_queues = TXGBE_RAPTOR_MAX_TX_QUEUES;
2883 : :
2884 : 0 : return 0;
2885 : : }
2886 : :
2887 : : /**
2888 : : * txgbe_get_link_capabilities_raptor - Determines link capabilities
2889 : : * @hw: pointer to hardware structure
2890 : : * @speed: pointer to link speed
2891 : : * @autoneg: true when autoneg or autotry is enabled
2892 : : *
2893 : : * Determines the link capabilities by reading the AUTOC register.
2894 : : **/
2895 : 0 : s32 txgbe_get_link_capabilities_raptor(struct txgbe_hw *hw,
2896 : : u32 *speed,
2897 : : bool *autoneg)
2898 : : {
2899 : : s32 status = 0;
2900 : : u32 autoc = 0;
2901 : :
2902 : : /* Check if 1G SFP module. */
2903 : 0 : if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
2904 [ # # ]: 0 : hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
2905 [ # # ]: 0 : hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
2906 [ # # ]: 0 : hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
2907 [ # # ]: 0 : hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
2908 : : hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
2909 : 0 : *speed = TXGBE_LINK_SPEED_1GB_FULL;
2910 : 0 : *autoneg = true;
2911 : 0 : return 0;
2912 : : }
2913 : :
2914 : : /*
2915 : : * Determine link capabilities based on the stored value of AUTOC,
2916 : : * which represents EEPROM defaults. If AUTOC value has not
2917 : : * been stored, use the current register values.
2918 : : */
2919 [ # # ]: 0 : if (hw->mac.orig_link_settings_stored)
2920 : 0 : autoc = hw->mac.orig_autoc;
2921 : : else
2922 : 0 : autoc = hw->mac.autoc_read(hw);
2923 : :
2924 [ # # # # : 0 : switch (autoc & TXGBE_AUTOC_LMS_MASK) {
# # # # ]
2925 : 0 : case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
2926 : 0 : *speed = TXGBE_LINK_SPEED_1GB_FULL;
2927 : 0 : *autoneg = false;
2928 : 0 : break;
2929 : :
2930 : 0 : case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
2931 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL;
2932 : 0 : *autoneg = false;
2933 : 0 : break;
2934 : :
2935 : 0 : case TXGBE_AUTOC_LMS_1G_AN:
2936 : 0 : *speed = TXGBE_LINK_SPEED_1GB_FULL;
2937 : 0 : *autoneg = true;
2938 : 0 : break;
2939 : :
2940 : 0 : case TXGBE_AUTOC_LMS_10G:
2941 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL;
2942 : 0 : *autoneg = false;
2943 : 0 : break;
2944 : :
2945 : 0 : case TXGBE_AUTOC_LMS_KX4_KX_KR:
2946 : : case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
2947 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
2948 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_KR_SUPP)
2949 : 0 : *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2950 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_KX4_SUPP)
2951 : 0 : *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2952 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_KX_SUPP)
2953 : 0 : *speed |= TXGBE_LINK_SPEED_1GB_FULL;
2954 : 0 : *autoneg = true;
2955 : 0 : break;
2956 : :
2957 : 0 : case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
2958 : 0 : *speed = TXGBE_LINK_SPEED_100M_FULL;
2959 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_KR_SUPP)
2960 : 0 : *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2961 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_KX4_SUPP)
2962 : 0 : *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2963 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_KX_SUPP)
2964 : 0 : *speed |= TXGBE_LINK_SPEED_1GB_FULL;
2965 : 0 : *autoneg = true;
2966 : 0 : break;
2967 : :
2968 : 0 : case TXGBE_AUTOC_LMS_SGMII_1G_100M:
2969 : 0 : *speed = TXGBE_LINK_SPEED_1GB_FULL |
2970 : : TXGBE_LINK_SPEED_100M_FULL |
2971 : : TXGBE_LINK_SPEED_10M_FULL;
2972 : 0 : *autoneg = false;
2973 : 0 : break;
2974 : :
2975 : : default:
2976 : : return TXGBE_ERR_LINK_SETUP;
2977 : : }
2978 : :
2979 [ # # ]: 0 : if (hw->phy.multispeed_fiber) {
2980 : 0 : *speed |= TXGBE_LINK_SPEED_10GB_FULL |
2981 : : TXGBE_LINK_SPEED_1GB_FULL;
2982 : :
2983 : : /* QSFP must not enable full auto-negotiation
2984 : : * Limited autoneg is enabled at 1G
2985 : : */
2986 [ # # ]: 0 : if (hw->phy.media_type == txgbe_media_type_fiber_qsfp)
2987 : 0 : *autoneg = false;
2988 : : else
2989 : 0 : *autoneg = true;
2990 : : }
2991 : :
2992 : : return status;
2993 : : }
2994 : :
2995 : : /**
2996 : : * txgbe_get_media_type_raptor - Get media type
2997 : : * @hw: pointer to hardware structure
2998 : : *
2999 : : * Returns the media type (fiber, copper, backplane)
3000 : : **/
3001 : 0 : u32 txgbe_get_media_type_raptor(struct txgbe_hw *hw)
3002 : : {
3003 : : u32 media_type;
3004 : :
3005 [ # # ]: 0 : if (hw->phy.ffe_set)
3006 : 0 : txgbe_bp_mode_set(hw);
3007 : :
3008 : : /* Detect if there is a copper PHY attached. */
3009 [ # # ]: 0 : switch (hw->phy.type) {
3010 : : case txgbe_phy_cu_unknown:
3011 : : case txgbe_phy_tn:
3012 : : media_type = txgbe_media_type_copper;
3013 : : return media_type;
3014 : : default:
3015 : : break;
3016 : : }
3017 : :
3018 [ # # # # : 0 : switch (hw->subsystem_device_id & 0xFF) {
# # ]
3019 : : case TXGBE_DEV_ID_KR_KX_KX4:
3020 : : case TXGBE_DEV_ID_MAC_SGMII:
3021 : : case TXGBE_DEV_ID_MAC_XAUI:
3022 : : /* Default device ID is mezzanine card KX/KX4 */
3023 : : media_type = txgbe_media_type_backplane;
3024 : : break;
3025 : 0 : case TXGBE_DEV_ID_SFP:
3026 : : media_type = txgbe_media_type_fiber;
3027 : 0 : break;
3028 : 0 : case TXGBE_DEV_ID_QSFP:
3029 : : media_type = txgbe_media_type_fiber_qsfp;
3030 : 0 : break;
3031 : 0 : case TXGBE_DEV_ID_XAUI:
3032 : : case TXGBE_DEV_ID_SGMII:
3033 : : media_type = txgbe_media_type_copper;
3034 : 0 : break;
3035 : 0 : case TXGBE_DEV_ID_SFI_XAUI:
3036 [ # # ]: 0 : if (hw->bus.lan_id == 0)
3037 : : media_type = txgbe_media_type_fiber;
3038 : : else
3039 : : media_type = txgbe_media_type_copper;
3040 : : break;
3041 : 0 : default:
3042 : : media_type = txgbe_media_type_unknown;
3043 : 0 : break;
3044 : : }
3045 : :
3046 : : return media_type;
3047 : : }
3048 : :
3049 : : /**
3050 : : * txgbe_start_mac_link_raptor - Setup MAC link settings
3051 : : * @hw: pointer to hardware structure
3052 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
3053 : : *
3054 : : * Configures link settings based on values in the txgbe_hw struct.
3055 : : * Restarts the link. Performs autonegotiation if needed.
3056 : : **/
3057 : 0 : s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
3058 : : bool autoneg_wait_to_complete)
3059 : : {
3060 : : s32 status = 0;
3061 : : bool got_lock = false;
3062 : :
3063 : : UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
3064 : :
3065 : : /* reset_pipeline requires us to hold this lock as it writes to
3066 : : * AUTOC.
3067 : : */
3068 [ # # ]: 0 : if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
3069 : 0 : status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
3070 [ # # ]: 0 : if (status != 0)
3071 : 0 : goto out;
3072 : :
3073 : : got_lock = true;
3074 : : }
3075 : :
3076 : : /* Restart link */
3077 : 0 : txgbe_reset_pipeline_raptor(hw);
3078 : :
3079 [ # # ]: 0 : if (got_lock)
3080 : 0 : hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
3081 : :
3082 : : /* Add delay to filter out noises during initial link setup */
3083 : : msec_delay(50);
3084 : :
3085 : 0 : out:
3086 : 0 : return status;
3087 : : }
3088 : :
3089 : : /**
3090 : : * txgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
3091 : : * @hw: pointer to hardware structure
3092 : : *
3093 : : * The base drivers may require better control over SFP+ module
3094 : : * PHY states. This includes selectively shutting down the Tx
3095 : : * laser on the PHY, effectively halting physical link.
3096 : : **/
3097 : 0 : void txgbe_disable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
3098 : : {
3099 : : u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
3100 : :
3101 [ # # ]: 0 : if (txgbe_close_notify(hw))
3102 : 0 : txgbe_led_off(hw, TXGBE_LEDCTL_UP | TXGBE_LEDCTL_10G |
3103 : : TXGBE_LEDCTL_1G | TXGBE_LEDCTL_ACTIVE);
3104 : :
3105 : : /* Disable Tx laser; allow 100us to go dark per spec */
3106 : 0 : esdp_reg |= (TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
3107 : : wr32(hw, TXGBE_GPIODATA, esdp_reg);
3108 : : txgbe_flush(hw);
3109 : 0 : usec_delay(100);
3110 : 0 : }
3111 : :
3112 : : /**
3113 : : * txgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
3114 : : * @hw: pointer to hardware structure
3115 : : *
3116 : : * The base drivers may require better control over SFP+ module
3117 : : * PHY states. This includes selectively turning on the Tx
3118 : : * laser on the PHY, effectively starting physical link.
3119 : : **/
3120 : 0 : void txgbe_enable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
3121 : : {
3122 : : u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
3123 : :
3124 [ # # ]: 0 : if (txgbe_open_notify(hw))
3125 : : wr32(hw, TXGBE_LEDCTL, 0);
3126 : :
3127 : : /* Enable Tx laser; allow 100ms to light up */
3128 : 0 : esdp_reg &= ~(TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
3129 : : wr32(hw, TXGBE_GPIODATA, esdp_reg);
3130 : : txgbe_flush(hw);
3131 : : msec_delay(100);
3132 : 0 : }
3133 : :
3134 : : /**
3135 : : * txgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
3136 : : * @hw: pointer to hardware structure
3137 : : *
3138 : : * When the driver changes the link speeds that it can support,
3139 : : * it sets autotry_restart to true to indicate that we need to
3140 : : * initiate a new autotry session with the link partner. To do
3141 : : * so, we set the speed then disable and re-enable the Tx laser, to
3142 : : * alert the link partner that it also needs to restart autotry on its
3143 : : * end. This is consistent with true clause 37 autoneg, which also
3144 : : * involves a loss of signal.
3145 : : **/
3146 : 0 : void txgbe_flap_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
3147 : : {
3148 [ # # ]: 0 : if (hw->mac.autotry_restart) {
3149 : 0 : txgbe_disable_tx_laser_multispeed_fiber(hw);
3150 : 0 : txgbe_enable_tx_laser_multispeed_fiber(hw);
3151 : 0 : hw->mac.autotry_restart = false;
3152 : : }
3153 : 0 : }
3154 : :
3155 : : /**
3156 : : * txgbe_set_hard_rate_select_speed - Set module link speed
3157 : : * @hw: pointer to hardware structure
3158 : : * @speed: link speed to set
3159 : : *
3160 : : * Set module link speed via RS0/RS1 rate select pins.
3161 : : */
3162 : 0 : void txgbe_set_hard_rate_select_speed(struct txgbe_hw *hw,
3163 : : u32 speed)
3164 : : {
3165 : : u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
3166 : :
3167 [ # # # ]: 0 : switch (speed) {
3168 : 0 : case TXGBE_LINK_SPEED_10GB_FULL:
3169 : 0 : esdp_reg |= (TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
3170 : 0 : break;
3171 : 0 : case TXGBE_LINK_SPEED_1GB_FULL:
3172 : 0 : esdp_reg &= ~(TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
3173 : 0 : break;
3174 : 0 : default:
3175 : 0 : DEBUGOUT("Invalid fixed module speed");
3176 : 0 : return;
3177 : : }
3178 : :
3179 : : wr32(hw, TXGBE_GPIODATA, esdp_reg);
3180 : : txgbe_flush(hw);
3181 : : }
3182 : :
3183 : : /**
3184 : : * txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
3185 : : * @hw: pointer to hardware structure
3186 : : * @speed: new link speed
3187 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
3188 : : *
3189 : : * Implements the Intel SmartSpeed algorithm.
3190 : : **/
3191 : 0 : s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
3192 : : u32 speed,
3193 : : bool autoneg_wait_to_complete)
3194 : : {
3195 : : s32 status = 0;
3196 : 0 : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
3197 : : s32 i, j;
3198 : 0 : bool link_up = false;
3199 : : u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
3200 : :
3201 : : /* Set autoneg_advertised value based on input link speed */
3202 : 0 : hw->phy.autoneg_advertised = 0;
3203 : :
3204 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_10GB_FULL)
3205 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
3206 : :
3207 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_1GB_FULL)
3208 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
3209 : :
3210 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_100M_FULL)
3211 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
3212 : :
3213 : : /*
3214 : : * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
3215 : : * autoneg advertisement if link is unable to be established at the
3216 : : * highest negotiated rate. This can sometimes happen due to integrity
3217 : : * issues with the physical media connection.
3218 : : */
3219 : :
3220 : : /* First, try to get link with full advertisement */
3221 : 0 : hw->phy.smart_speed_active = false;
3222 [ # # ]: 0 : for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
3223 : 0 : status = txgbe_setup_mac_link(hw, speed,
3224 : : autoneg_wait_to_complete);
3225 [ # # ]: 0 : if (status != 0)
3226 : 0 : goto out;
3227 : :
3228 : : /*
3229 : : * Wait for the controller to acquire link. Per IEEE 802.3ap,
3230 : : * Section 73.10.2, we may have to wait up to 500ms if KR is
3231 : : * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
3232 : : * Table 9 in the AN MAS.
3233 : : */
3234 [ # # ]: 0 : for (i = 0; i < 5; i++) {
3235 : : msec_delay(100);
3236 : :
3237 : : /* If we have link, just jump out */
3238 : 0 : status = hw->mac.check_link(hw, &link_speed, &link_up,
3239 : : false);
3240 [ # # ]: 0 : if (status != 0)
3241 : 0 : goto out;
3242 : :
3243 [ # # ]: 0 : if (link_up)
3244 : 0 : goto out;
3245 : : }
3246 : : }
3247 : :
3248 : : /*
3249 : : * We didn't get link. If we advertised KR plus one of KX4/KX
3250 : : * (or BX4/BX), then disable KR and try again.
3251 : : */
3252 [ # # # # ]: 0 : if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
3253 : 0 : ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
3254 [ # # ]: 0 : (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
3255 : 0 : goto out;
3256 : :
3257 : : /* Turn SmartSpeed on to disable KR support */
3258 : 0 : hw->phy.smart_speed_active = true;
3259 : 0 : status = txgbe_setup_mac_link(hw, speed,
3260 : : autoneg_wait_to_complete);
3261 [ # # ]: 0 : if (status != 0)
3262 : 0 : goto out;
3263 : :
3264 : : /*
3265 : : * Wait for the controller to acquire link. 600ms will allow for
3266 : : * the AN link_fail_inhibit_timer as well for multiple cycles of
3267 : : * parallel detect, both 10g and 1g. This allows for the maximum
3268 : : * connect attempts as defined in the AN MAS table 73-7.
3269 : : */
3270 [ # # ]: 0 : for (i = 0; i < 6; i++) {
3271 : : msec_delay(100);
3272 : :
3273 : : /* If we have link, just jump out */
3274 : 0 : status = hw->mac.check_link(hw, &link_speed, &link_up, false);
3275 [ # # ]: 0 : if (status != 0)
3276 : 0 : goto out;
3277 : :
3278 [ # # ]: 0 : if (link_up)
3279 : 0 : goto out;
3280 : : }
3281 : :
3282 : : /* We didn't get link. Turn SmartSpeed back off. */
3283 : 0 : hw->phy.smart_speed_active = false;
3284 : 0 : status = txgbe_setup_mac_link(hw, speed,
3285 : : autoneg_wait_to_complete);
3286 : :
3287 : 0 : out:
3288 [ # # # # ]: 0 : if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
3289 : 0 : DEBUGOUT("Smartspeed has downgraded the link speed from the maximum advertised");
3290 : 0 : return status;
3291 : : }
3292 : :
3293 : : /**
3294 : : * txgbe_setup_mac_link - Set MAC link speed
3295 : : * @hw: pointer to hardware structure
3296 : : * @speed: new link speed
3297 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
3298 : : *
3299 : : * Set the link speed in the AUTOC register and restarts link.
3300 : : **/
3301 : 0 : s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
3302 : : u32 speed,
3303 : : bool autoneg_wait_to_complete)
3304 : : {
3305 : 0 : bool autoneg = false;
3306 : : s32 status = 0;
3307 : :
3308 : 0 : u64 autoc = hw->mac.autoc_read(hw);
3309 : 0 : u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
3310 : 0 : u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
3311 : 0 : u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
3312 : : u64 orig_autoc = 0;
3313 : 0 : u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
3314 : :
3315 : : UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
3316 : :
3317 : : /* Check to see if speed passed in is supported. */
3318 : 0 : status = hw->mac.get_link_capabilities(hw,
3319 : : &link_capabilities, &autoneg);
3320 [ # # ]: 0 : if (status)
3321 : : return status;
3322 : :
3323 : 0 : speed &= link_capabilities;
3324 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_UNKNOWN)
3325 : : return TXGBE_ERR_LINK_SETUP;
3326 : :
3327 : : /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
3328 [ # # ]: 0 : if (hw->mac.orig_link_settings_stored)
3329 : 0 : orig_autoc = hw->mac.orig_autoc;
3330 : : else
3331 : : orig_autoc = autoc;
3332 : :
3333 : : link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
3334 : : pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
3335 : :
3336 : 0 : if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
3337 [ # # # # ]: 0 : link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
3338 : : link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
3339 : : /* Set KX4/KX/KR support according to speed requested */
3340 : 0 : autoc &= ~(TXGBE_AUTOC_KX_SUPP |
3341 : : TXGBE_AUTOC_KX4_SUPP |
3342 : : TXGBE_AUTOC_KR_SUPP);
3343 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
3344 [ # # ]: 0 : if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
3345 : 0 : autoc |= TXGBE_AUTOC_KX4_SUPP;
3346 [ # # ]: 0 : if (orig_autoc & TXGBE_AUTOC_KR_SUPP)
3347 : 0 : autoc |= TXGBE_AUTOC_KR_SUPP;
3348 : : }
3349 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_1GB_FULL)
3350 : 0 : autoc |= TXGBE_AUTOC_KX_SUPP;
3351 [ # # ]: 0 : } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
3352 : 0 : (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
3353 [ # # ]: 0 : link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
3354 : : /* Switch from 1G SFI to 10G SFI if requested */
3355 : 0 : if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
3356 [ # # ]: 0 : pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
3357 : 0 : autoc &= ~TXGBE_AUTOC_LMS_MASK;
3358 : 0 : autoc |= TXGBE_AUTOC_LMS_10G;
3359 : : }
3360 : 0 : } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
3361 [ # # ]: 0 : (link_mode == TXGBE_AUTOC_LMS_10G)) {
3362 : : /* Switch from 10G SFI to 1G SFI if requested */
3363 : 0 : if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
3364 [ # # ]: 0 : pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
3365 : 0 : autoc &= ~TXGBE_AUTOC_LMS_MASK;
3366 [ # # # # ]: 0 : if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
3367 : 0 : autoc |= TXGBE_AUTOC_LMS_1G_AN;
3368 : : else
3369 : : autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
3370 : : }
3371 : : }
3372 : :
3373 : 0 : autoc &= ~TXGBE_AUTOC_SPEED_MASK;
3374 : 0 : autoc |= TXGBE_AUTOC_SPEED(speed);
3375 : 0 : autoc &= ~TXGBE_AUTOC_AUTONEG;
3376 [ # # ]: 0 : autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
3377 : :
3378 : : /* Restart link */
3379 : 0 : hw->mac.autoc_write(hw, autoc);
3380 : :
3381 : : /* Add delay to filter out noises during initial link setup */
3382 : : msec_delay(50);
3383 : :
3384 : 0 : return status;
3385 : : }
3386 : :
3387 : : /**
3388 : : * txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
3389 : : * @hw: pointer to hardware structure
3390 : : * @speed: new link speed
3391 : : * @autoneg_wait_to_complete: true if waiting is needed to complete
3392 : : *
3393 : : * Restarts link on PHY and MAC based on settings passed in.
3394 : : **/
3395 : 0 : static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
3396 : : u32 speed,
3397 : : bool autoneg_wait_to_complete)
3398 : : {
3399 : : s32 status;
3400 : :
3401 : : /* Setup the PHY according to input speed */
3402 : 0 : status = hw->phy.setup_link_speed(hw, speed,
3403 : : autoneg_wait_to_complete);
3404 : : /* Set up MAC */
3405 : 0 : txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
3406 : :
3407 : 0 : return status;
3408 : : }
3409 : :
3410 : : static int
3411 : 0 : txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
3412 : : {
3413 : : u32 reg = 0;
3414 : : u32 i;
3415 : : int err = 0;
3416 : : /* if there's flash existing */
3417 [ # # ]: 0 : if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
3418 : : /* wait hw load flash done */
3419 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3420 : : reg = rd32(hw, TXGBE_ILDRSTAT);
3421 [ # # ]: 0 : if (!(reg & check_bit)) {
3422 : : /* done */
3423 : : break;
3424 : : }
3425 : : msleep(100);
3426 : : }
3427 [ # # ]: 0 : if (i == 10)
3428 : : err = TXGBE_ERR_FLASH_LOADING_FAILED;
3429 : : }
3430 : 0 : return err;
3431 : : }
3432 : :
3433 : : static void
3434 : 0 : txgbe_reset_misc(struct txgbe_hw *hw)
3435 : : {
3436 : : int i;
3437 : : u32 value;
3438 : :
3439 : 0 : wr32(hw, TXGBE_ISBADDRL, hw->isb_dma & 0x00000000FFFFFFFF);
3440 : 0 : wr32(hw, TXGBE_ISBADDRH, hw->isb_dma >> 32);
3441 : :
3442 : : value = rd32_epcs(hw, SR_XS_PCS_CTRL2);
3443 [ # # ]: 0 : if ((value & 0x3) != SR_PCS_CTRL2_TYPE_SEL_X)
3444 : 0 : hw->link_status = TXGBE_LINK_STATUS_NONE;
3445 : :
3446 : : /* receive packets that size > 2048 */
3447 : : wr32m(hw, TXGBE_MACRXCFG,
3448 : : TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
3449 : :
3450 : : wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
3451 : : TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
3452 : :
3453 : : /* clear counters on read */
3454 : : wr32m(hw, TXGBE_MACCNTCTL,
3455 : : TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
3456 : :
3457 : : wr32m(hw, TXGBE_RXFCCFG,
3458 : : TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
3459 : : wr32m(hw, TXGBE_TXFCCFG,
3460 : : TXGBE_TXFCCFG_FC, TXGBE_TXFCCFG_FC);
3461 : :
3462 : : wr32m(hw, TXGBE_MACRXFLT,
3463 : : TXGBE_MACRXFLT_PROMISC, TXGBE_MACRXFLT_PROMISC);
3464 : :
3465 : : wr32m(hw, TXGBE_RSTSTAT,
3466 : : TXGBE_RSTSTAT_TMRINIT_MASK, TXGBE_RSTSTAT_TMRINIT(30));
3467 : :
3468 : : /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
3469 : : wr32(hw, TXGBE_MNGFLEXSEL, 0);
3470 [ # # ]: 0 : for (i = 0; i < 16; i++) {
3471 : 0 : wr32(hw, TXGBE_MNGFLEXDWL(i), 0);
3472 : 0 : wr32(hw, TXGBE_MNGFLEXDWH(i), 0);
3473 : 0 : wr32(hw, TXGBE_MNGFLEXMSK(i), 0);
3474 : : }
3475 : : wr32(hw, TXGBE_LANFLEXSEL, 0);
3476 [ # # ]: 0 : for (i = 0; i < 16; i++) {
3477 : 0 : wr32(hw, TXGBE_LANFLEXDWL(i), 0);
3478 : 0 : wr32(hw, TXGBE_LANFLEXDWH(i), 0);
3479 : 0 : wr32(hw, TXGBE_LANFLEXMSK(i), 0);
3480 : : }
3481 : :
3482 : : /* set pause frame dst mac addr */
3483 : : wr32(hw, TXGBE_RXPBPFCDMACL, 0xC2000001);
3484 : : wr32(hw, TXGBE_RXPBPFCDMACH, 0x0180);
3485 : :
3486 : 0 : hw->mac.init_thermal_sensor_thresh(hw);
3487 : :
3488 : : /* enable mac transmitter */
3489 : : wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE, TXGBE_MACTXCFG_TXE);
3490 : :
3491 : 0 : hw->mac.autoc = hw->mac.orig_autoc;
3492 [ # # ]: 0 : for (i = 0; i < 4; i++)
3493 : 0 : wr32m(hw, TXGBE_IVAR(i), 0x80808080, 0);
3494 : 0 : }
3495 : :
3496 : : /**
3497 : : * txgbe_reset_hw - Perform hardware reset
3498 : : * @hw: pointer to hardware structure
3499 : : *
3500 : : * Resets the hardware by resetting the transmit and receive units, masks
3501 : : * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
3502 : : * reset.
3503 : : **/
3504 : 0 : s32 txgbe_reset_hw(struct txgbe_hw *hw)
3505 : : {
3506 : : s32 status;
3507 : : u32 autoc;
3508 : :
3509 : : /* Call adapter stop to disable tx/rx and clear interrupts */
3510 : 0 : status = hw->mac.stop_hw(hw);
3511 [ # # ]: 0 : if (status != 0)
3512 : : return status;
3513 : :
3514 : : /* flush pending Tx transactions */
3515 : 0 : txgbe_clear_tx_pending(hw);
3516 : :
3517 : : /* Identify PHY and related function pointers */
3518 : 0 : status = hw->phy.init(hw);
3519 [ # # ]: 0 : if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
3520 : : return status;
3521 : :
3522 : : /* Setup SFP module if there is one present. */
3523 [ # # ]: 0 : if (hw->phy.sfp_setup_needed) {
3524 : 0 : status = hw->mac.setup_sfp(hw);
3525 : 0 : hw->phy.sfp_setup_needed = false;
3526 : : }
3527 [ # # ]: 0 : if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
3528 : : return status;
3529 : :
3530 : : /* Reset PHY */
3531 [ # # ]: 0 : if (!hw->phy.reset_disable)
3532 : 0 : hw->phy.reset(hw);
3533 : :
3534 : : /* remember AUTOC from before we reset */
3535 : 0 : autoc = hw->mac.autoc_read(hw);
3536 : :
3537 : 0 : mac_reset_top:
3538 : : /* Do LAN reset, the MNG domain will not be reset. */
3539 : 0 : wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
3540 : : txgbe_flush(hw);
3541 : 0 : usec_delay(10);
3542 : :
3543 : 0 : txgbe_reset_misc(hw);
3544 : :
3545 [ # # ]: 0 : if (hw->bus.lan_id == 0) {
3546 : 0 : status = txgbe_check_flash_load(hw,
3547 : : TXGBE_ILDRSTAT_SWRST_LAN0);
3548 : : } else {
3549 : 0 : status = txgbe_check_flash_load(hw,
3550 : : TXGBE_ILDRSTAT_SWRST_LAN1);
3551 : : }
3552 [ # # ]: 0 : if (status != 0)
3553 : 0 : return status;
3554 : :
3555 : : msec_delay(50);
3556 : :
3557 : : /*
3558 : : * Double resets are required for recovery from certain error
3559 : : * conditions. Between resets, it is necessary to stall to
3560 : : * allow time for any pending HW events to complete.
3561 : : */
3562 [ # # ]: 0 : if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
3563 : 0 : hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3564 : 0 : goto mac_reset_top;
3565 : : }
3566 : :
3567 : : /*
3568 : : * Store the original AUTOC/AUTOC2 values if they have not been
3569 : : * stored off yet. Otherwise restore the stored original
3570 : : * values since the reset operation sets back to defaults.
3571 : : */
3572 [ # # ]: 0 : if (!hw->mac.orig_link_settings_stored) {
3573 : 0 : hw->mac.orig_autoc = hw->mac.autoc_read(hw);
3574 : 0 : hw->mac.orig_link_settings_stored = true;
3575 : : } else {
3576 : 0 : hw->mac.orig_autoc = autoc;
3577 : : }
3578 : :
3579 [ # # ]: 0 : if (hw->phy.ffe_set) {
3580 : : /* Make sure phy power is up */
3581 : : msec_delay(50);
3582 : :
3583 : : /* A temporary solution to set phy */
3584 : 0 : txgbe_set_phy_temp(hw);
3585 : : }
3586 : :
3587 : : /* Store the permanent mac address */
3588 : 0 : hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
3589 : :
3590 : : /*
3591 : : * Store MAC address from RAR0, clear receive address registers, and
3592 : : * clear the multicast table. Also reset num_rar_entries to 128,
3593 : : * since we modify this value when programming the SAN MAC address.
3594 : : */
3595 : 0 : hw->mac.num_rar_entries = 128;
3596 : 0 : hw->mac.init_rx_addrs(hw);
3597 : :
3598 : : /* Store the permanent SAN mac address */
3599 : 0 : hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
3600 : :
3601 : : /* Add the SAN MAC address to the RAR only if it's a valid address */
3602 [ # # ]: 0 : if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
3603 : : /* Save the SAN MAC RAR index */
3604 : 0 : hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
3605 : :
3606 : 0 : hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
3607 : : hw->mac.san_addr, 0, true);
3608 : :
3609 : : /* clear VMDq pool/queue selection for this RAR */
3610 : 0 : hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
3611 : : BIT_MASK32);
3612 : :
3613 : : /* Reserve the last RAR for the SAN MAC address */
3614 : 0 : hw->mac.num_rar_entries--;
3615 : : }
3616 : :
3617 : : /* Store the alternative WWNN/WWPN prefix */
3618 : 0 : hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
3619 : : &hw->mac.wwpn_prefix);
3620 : :
3621 : 0 : return status;
3622 : : }
3623 : :
3624 : : /**
3625 : : * txgbe_fdir_check_cmd_complete - poll to check whether FDIRPICMD is complete
3626 : : * @hw: pointer to hardware structure
3627 : : * @fdircmd: current value of FDIRCMD register
3628 : : */
3629 : : static s32 txgbe_fdir_check_cmd_complete(struct txgbe_hw *hw, u32 *fdircmd)
3630 : : {
3631 : : int i;
3632 : :
3633 [ # # ]: 0 : for (i = 0; i < TXGBE_FDIRCMD_CMD_POLL; i++) {
3634 : : *fdircmd = rd32(hw, TXGBE_FDIRPICMD);
3635 [ # # ]: 0 : if (!(*fdircmd & TXGBE_FDIRPICMD_OP_MASK))
3636 : : return 0;
3637 : 0 : usec_delay(10);
3638 : : }
3639 : :
3640 : : return TXGBE_ERR_FDIR_CMD_INCOMPLETE;
3641 : : }
3642 : :
3643 : : /**
3644 : : * txgbe_reinit_fdir_tables - Reinitialize Flow Director tables.
3645 : : * @hw: pointer to hardware structure
3646 : : **/
3647 : 0 : s32 txgbe_reinit_fdir_tables(struct txgbe_hw *hw)
3648 : : {
3649 : : s32 err;
3650 : : int i;
3651 : : u32 fdirctrl = rd32(hw, TXGBE_FDIRCTL);
3652 : : u32 fdircmd;
3653 : 0 : fdirctrl &= ~TXGBE_FDIRCTL_INITDONE;
3654 : :
3655 : : /*
3656 : : * Before starting reinitialization process,
3657 : : * FDIRPICMD.OP must be zero.
3658 : : */
3659 : : err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
3660 [ # # ]: 0 : if (err) {
3661 : 0 : DEBUGOUT("Flow Director previous command did not complete, aborting table re-initialization.");
3662 : 0 : return err;
3663 : : }
3664 : :
3665 : : wr32(hw, TXGBE_FDIRFREE, 0);
3666 : : txgbe_flush(hw);
3667 : : /*
3668 : : * adapters flow director init flow cannot be restarted,
3669 : : * Workaround silicon errata by performing the following steps
3670 : : * before re-writing the FDIRCTL control register with the same value.
3671 : : * - write 1 to bit 8 of FDIRPICMD register &
3672 : : * - write 0 to bit 8 of FDIRPICMD register
3673 : : */
3674 : : wr32m(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_CLR, TXGBE_FDIRPICMD_CLR);
3675 : : txgbe_flush(hw);
3676 : : wr32m(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_CLR, 0);
3677 : : txgbe_flush(hw);
3678 : : /*
3679 : : * Clear FDIR Hash register to clear any leftover hashes
3680 : : * waiting to be programmed.
3681 : : */
3682 : : wr32(hw, TXGBE_FDIRPIHASH, 0x00);
3683 : : txgbe_flush(hw);
3684 : :
3685 : : wr32(hw, TXGBE_FDIRCTL, fdirctrl);
3686 : : txgbe_flush(hw);
3687 : :
3688 : : /* Poll init-done after we write FDIRCTL register */
3689 [ # # ]: 0 : for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
3690 [ # # ]: 0 : if (rd32m(hw, TXGBE_FDIRCTL, TXGBE_FDIRCTL_INITDONE))
3691 : : break;
3692 : : msec_delay(1);
3693 : : }
3694 [ # # ]: 0 : if (i >= TXGBE_FDIR_INIT_DONE_POLL) {
3695 : 0 : DEBUGOUT("Flow Director Signature poll time exceeded!");
3696 : 0 : return TXGBE_ERR_FDIR_REINIT_FAILED;
3697 : : }
3698 : :
3699 : : /* Clear FDIR statistics registers (read to clear) */
3700 : : rd32(hw, TXGBE_FDIRUSED);
3701 : : rd32(hw, TXGBE_FDIRFAIL);
3702 : : rd32(hw, TXGBE_FDIRMATCH);
3703 : : rd32(hw, TXGBE_FDIRMISS);
3704 : : rd32(hw, TXGBE_FDIRLEN);
3705 : :
3706 : 0 : return 0;
3707 : : }
3708 : :
3709 : : /**
3710 : : * txgbe_start_hw_raptor - Prepare hardware for Tx/Rx
3711 : : * @hw: pointer to hardware structure
3712 : : *
3713 : : * Starts the hardware using the generic start_hw function
3714 : : * and the generation start_hw function.
3715 : : * Then performs revision-specific operations, if any.
3716 : : **/
3717 : 0 : s32 txgbe_start_hw_raptor(struct txgbe_hw *hw)
3718 : : {
3719 : : s32 err = 0;
3720 : :
3721 : 0 : err = txgbe_start_hw(hw);
3722 [ # # ]: 0 : if (err != 0)
3723 : 0 : goto out;
3724 : :
3725 : 0 : err = txgbe_start_hw_gen2(hw);
3726 [ # # ]: 0 : if (err != 0)
3727 : 0 : goto out;
3728 : :
3729 : : /* We need to run link autotry after the driver loads */
3730 : 0 : hw->mac.autotry_restart = true;
3731 : :
3732 : 0 : out:
3733 : 0 : return err;
3734 : : }
3735 : :
3736 : : /**
3737 : : * txgbe_enable_rx_dma_raptor - Enable the Rx DMA unit
3738 : : * @hw: pointer to hardware structure
3739 : : * @regval: register value to write to RXCTRL
3740 : : *
3741 : : * Enables the Rx DMA unit
3742 : : **/
3743 : 0 : s32 txgbe_enable_rx_dma_raptor(struct txgbe_hw *hw, u32 regval)
3744 : : {
3745 : : /*
3746 : : * Workaround silicon errata when enabling the Rx datapath.
3747 : : * If traffic is incoming before we enable the Rx unit, it could hang
3748 : : * the Rx DMA unit. Therefore, make sure the security engine is
3749 : : * completely disabled prior to enabling the Rx unit.
3750 : : */
3751 : :
3752 : 0 : hw->mac.disable_sec_rx_path(hw);
3753 : :
3754 [ # # ]: 0 : if (regval & TXGBE_PBRXCTL_ENA)
3755 : 0 : txgbe_enable_rx(hw);
3756 : : else
3757 : 0 : txgbe_disable_rx(hw);
3758 : :
3759 : 0 : hw->mac.enable_sec_rx_path(hw);
3760 : :
3761 : 0 : return 0;
3762 : : }
3763 : :
3764 : : /**
3765 : : * txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
3766 : : * @hw: pointer to hardware structure
3767 : : *
3768 : : * Returns true if the LESM FW module is present and enabled. Otherwise
3769 : : * returns false. Smart Speed must be disabled if LESM FW module is enabled.
3770 : : **/
3771 : 0 : bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
3772 : : {
3773 : : bool lesm_enabled = false;
3774 : : u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
3775 : : s32 status;
3776 : :
3777 : : /* get the offset to the Firmware Module block */
3778 : 0 : status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
3779 : :
3780 [ # # # # : 0 : if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
# # ]
3781 : 0 : goto out;
3782 : :
3783 : : /* get the offset to the LESM Parameters block */
3784 : 0 : status = hw->rom.read16(hw, (fw_offset +
3785 : : TXGBE_FW_LESM_PARAMETERS_PTR),
3786 : : &fw_lesm_param_offset);
3787 : :
3788 [ # # ]: 0 : if (status != 0 ||
3789 [ # # # # ]: 0 : fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
3790 : 0 : goto out;
3791 : :
3792 : : /* get the LESM state word */
3793 : 0 : status = hw->rom.read16(hw, (fw_lesm_param_offset +
3794 : : TXGBE_FW_LESM_STATE_1),
3795 : : &fw_lesm_state);
3796 : :
3797 : : if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
3798 : : lesm_enabled = true;
3799 : :
3800 : 0 : out:
3801 : : lesm_enabled = false;
3802 : 0 : return lesm_enabled;
3803 : : }
3804 : :
3805 : : /**
3806 : : * txgbe_reset_pipeline_raptor - perform pipeline reset
3807 : : *
3808 : : * @hw: pointer to hardware structure
3809 : : *
3810 : : * Reset pipeline by asserting Restart_AN together with LMS change to ensure
3811 : : * full pipeline reset. This function assumes the SW/FW lock is held.
3812 : : **/
3813 : 0 : s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
3814 : : {
3815 : : s32 err = 0;
3816 : : u64 autoc;
3817 : :
3818 : 0 : autoc = hw->mac.autoc_read(hw);
3819 : :
3820 : : /* Enable link if disabled in NVM */
3821 [ # # ]: 0 : if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
3822 : 0 : autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
3823 : :
3824 : 0 : autoc |= TXGBE_AUTOC_AN_RESTART;
3825 : : /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
3826 : 0 : hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
3827 : :
3828 : : /* Write AUTOC register with original LMS field and Restart_AN */
3829 : 0 : hw->mac.autoc_write(hw, autoc);
3830 : : txgbe_flush(hw);
3831 : :
3832 : 0 : return err;
3833 : : }
3834 : :
|