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