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