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