Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include "ngbe_type.h"
7 : : #include "ngbe_mbx.h"
8 : : #include "ngbe_phy.h"
9 : : #include "ngbe_eeprom.h"
10 : : #include "ngbe_mng.h"
11 : : #include "ngbe_hw.h"
12 : : #include "ngbe_vf.h"
13 : :
14 : 0 : static s32 ngbe_is_lldp(struct ngbe_hw *hw)
15 : : {
16 : 0 : u32 tmp = 0, lldp_flash_data = 0, i;
17 : : s32 err = 0;
18 : :
19 [ # # ]: 0 : if ((hw->eeprom_id & NGBE_FW_MASK) >= NGBE_FW_GET_LLDP) {
20 : 0 : err = ngbe_hic_get_lldp(hw);
21 [ # # ]: 0 : if (err == 0)
22 : : return 0;
23 : : }
24 : :
25 [ # # ]: 0 : for (i = 0; i < 1024; i++) {
26 : 0 : err = ngbe_flash_read_dword(hw, NGBE_LLDP_REG + i * 4, &tmp);
27 [ # # ]: 0 : if (err)
28 : 0 : return err;
29 : :
30 [ # # ]: 0 : if (tmp == BIT_MASK32)
31 : : break;
32 : : lldp_flash_data = tmp;
33 : : }
34 : :
35 [ # # ]: 0 : if (lldp_flash_data & MS(hw->bus.lan_id, 1))
36 : 0 : hw->lldp_enabled = true;
37 : : else
38 : 0 : hw->lldp_enabled = false;
39 : :
40 : : return 0;
41 : : }
42 : :
43 : 0 : static void ngbe_disable_lldp(struct ngbe_hw *hw)
44 : : {
45 : : s32 err = 0;
46 : :
47 [ # # ]: 0 : if ((hw->eeprom_id & NGBE_FW_MASK) < NGBE_FW_SUPPORT_LLDP)
48 : : return;
49 : :
50 : 0 : err = ngbe_is_lldp(hw);
51 [ # # ]: 0 : if (err) {
52 : 0 : PMD_INIT_LOG(INFO, "Can not get LLDP status.");
53 [ # # ]: 0 : } else if (hw->lldp_enabled) {
54 : 0 : err = ngbe_hic_set_lldp(hw, false);
55 [ # # ]: 0 : if (!err)
56 : 0 : PMD_INIT_LOG(INFO,
57 : : "LLDP detected on port %d, turn it off by default.",
58 : : hw->port_id);
59 : : else
60 : 0 : PMD_INIT_LOG(INFO, "Can not set LLDP status.");
61 : : }
62 : : }
63 : :
64 : : /**
65 : : * ngbe_start_hw - Prepare hardware for Tx/Rx
66 : : * @hw: pointer to hardware structure
67 : : *
68 : : * Starts the hardware.
69 : : **/
70 : 0 : s32 ngbe_start_hw(struct ngbe_hw *hw)
71 : : {
72 : : s32 err;
73 : :
74 : : /* Clear the VLAN filter table */
75 : 0 : hw->mac.clear_vfta(hw);
76 : :
77 : : /* Clear statistics registers */
78 : 0 : hw->mac.clear_hw_cntrs(hw);
79 : :
80 : : /* Setup flow control */
81 : 0 : err = hw->mac.setup_fc(hw);
82 [ # # ]: 0 : if (err != 0 && err != NGBE_NOT_IMPLEMENTED) {
83 : 0 : DEBUGOUT("Flow control setup failed, returning %d", err);
84 : 0 : return err;
85 : : }
86 : :
87 : : /* Clear adapter stopped flag */
88 : 0 : hw->adapter_stopped = false;
89 : :
90 : 0 : return 0;
91 : : }
92 : :
93 : : /**
94 : : * ngbe_init_hw - Generic hardware initialization
95 : : * @hw: pointer to hardware structure
96 : : *
97 : : * Initialize the hardware by resetting the hardware, filling the bus info
98 : : * structure and media type, clears all on chip counters, initializes receive
99 : : * address registers, multicast table, VLAN filter table, calls routine to set
100 : : * up link and flow control settings, and leaves transmit and receive units
101 : : * disabled and uninitialized
102 : : **/
103 : 0 : s32 ngbe_init_hw(struct ngbe_hw *hw)
104 : : {
105 : : s32 status;
106 : :
107 : 0 : ngbe_read_efuse(hw);
108 : 0 : ngbe_save_eeprom_version(hw);
109 : 0 : ngbe_disable_lldp(hw);
110 : :
111 : : /* Reset the hardware */
112 : 0 : status = hw->mac.reset_hw(hw);
113 [ # # ]: 0 : if (status == 0) {
114 : : /* Start the HW */
115 : 0 : status = hw->mac.start_hw(hw);
116 : : }
117 : :
118 [ # # ]: 0 : if (status != 0)
119 : 0 : DEBUGOUT("Failed to initialize HW, STATUS = %d", status);
120 : :
121 : 0 : return status;
122 : : }
123 : :
124 : : static void
125 : 0 : ngbe_reset_misc_em(struct ngbe_hw *hw)
126 : : {
127 : : int i;
128 : :
129 : 0 : wr32(hw, NGBE_ISBADDRL, hw->isb_dma & 0xFFFFFFFF);
130 : 0 : wr32(hw, NGBE_ISBADDRH, hw->isb_dma >> 32);
131 : :
132 : : /* receive packets that size > 2048 */
133 : : wr32m(hw, NGBE_MACRXCFG,
134 : : NGBE_MACRXCFG_JUMBO, NGBE_MACRXCFG_JUMBO);
135 : :
136 : : wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
137 : : NGBE_FRMSZ_MAX(NGBE_FRAME_SIZE_DFT));
138 : :
139 : : /* clear counters on read */
140 : : wr32m(hw, NGBE_MACCNTCTL,
141 : : NGBE_MACCNTCTL_RC, NGBE_MACCNTCTL_RC);
142 : :
143 : : wr32m(hw, NGBE_RXFCCFG,
144 : : NGBE_RXFCCFG_FC, NGBE_RXFCCFG_FC);
145 : : wr32m(hw, NGBE_TXFCCFG,
146 : : NGBE_TXFCCFG_FC, NGBE_TXFCCFG_FC);
147 : :
148 : : wr32m(hw, NGBE_MACRXFLT,
149 : : NGBE_MACRXFLT_PROMISC, NGBE_MACRXFLT_PROMISC);
150 : :
151 : : wr32m(hw, NGBE_RSTSTAT,
152 : : NGBE_RSTSTAT_TMRINIT_MASK, NGBE_RSTSTAT_TMRINIT(30));
153 : :
154 : : /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
155 : : wr32(hw, NGBE_MNGFLEXSEL, 0);
156 [ # # ]: 0 : for (i = 0; i < 16; i++) {
157 : 0 : wr32(hw, NGBE_MNGFLEXDWL(i), 0);
158 : 0 : wr32(hw, NGBE_MNGFLEXDWH(i), 0);
159 : 0 : wr32(hw, NGBE_MNGFLEXMSK(i), 0);
160 : : }
161 : : wr32(hw, NGBE_LANFLEXSEL, 0);
162 [ # # ]: 0 : for (i = 0; i < 16; i++) {
163 : 0 : wr32(hw, NGBE_LANFLEXDWL(i), 0);
164 : 0 : wr32(hw, NGBE_LANFLEXDWH(i), 0);
165 : 0 : wr32(hw, NGBE_LANFLEXMSK(i), 0);
166 : : }
167 : :
168 : : /* set pause frame dst mac addr */
169 : : wr32(hw, NGBE_RXPBPFCDMACL, 0xC2000001);
170 : : wr32(hw, NGBE_RXPBPFCDMACH, 0x0180);
171 : :
172 : : wr32(hw, NGBE_MDIOMODE, 0xF);
173 : :
174 : : wr32m(hw, NGBE_GPIE, NGBE_GPIE_MSIX, NGBE_GPIE_MSIX);
175 : :
176 [ # # ]: 0 : if (hw->gpio_ctl) {
177 : : /* gpio0 is used to power on/off control*/
178 : : wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
179 : : wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
180 : : }
181 : :
182 : 0 : hw->mac.init_thermal_sensor_thresh(hw);
183 : :
184 : : /* enable mac transmitter */
185 : : wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_TE, NGBE_MACTXCFG_TE);
186 : :
187 : : /* sellect GMII */
188 : : wr32m(hw, NGBE_MACTXCFG,
189 : : NGBE_MACTXCFG_SPEED_MASK, NGBE_MACTXCFG_SPEED_1G);
190 : :
191 [ # # ]: 0 : for (i = 0; i < 4; i++)
192 : 0 : wr32m(hw, NGBE_IVAR(i), 0x80808080, 0);
193 : 0 : }
194 : :
195 : : /**
196 : : * ngbe_reset_hw_em - Perform hardware reset
197 : : * @hw: pointer to hardware structure
198 : : *
199 : : * Resets the hardware by resetting the transmit and receive units, masks
200 : : * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
201 : : * reset.
202 : : **/
203 : 0 : s32 ngbe_reset_hw_em(struct ngbe_hw *hw)
204 : : {
205 : : s32 status;
206 : :
207 : : /* Call adapter stop to disable tx/rx and clear interrupts */
208 : 0 : status = hw->mac.stop_hw(hw);
209 [ # # ]: 0 : if (status != 0)
210 : : return status;
211 : :
212 : : /* Identify PHY and related function pointers */
213 : 0 : status = ngbe_init_phy(hw);
214 [ # # ]: 0 : if (status)
215 : : return status;
216 : :
217 : : /* Reset PHY */
218 [ # # ]: 0 : if (!hw->phy.reset_disable)
219 : 0 : hw->phy.reset_hw(hw);
220 : :
221 : 0 : wr32(hw, NGBE_RST, NGBE_RST_LAN(hw->bus.lan_id));
222 : : ngbe_flush(hw);
223 : : msec_delay(50);
224 : :
225 : 0 : ngbe_reset_misc_em(hw);
226 : 0 : hw->mac.clear_hw_cntrs(hw);
227 : :
228 [ # # ]: 0 : if (!(((hw->sub_device_id & NGBE_OEM_MASK) == NGBE_RGMII_FPGA) ||
229 [ # # # # ]: 0 : hw->ncsi_enabled || hw->wol_enabled))
230 : 0 : hw->phy.set_phy_power(hw, false);
231 : :
232 : : msec_delay(50);
233 : :
234 : : /* Store the permanent mac address */
235 : 0 : hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
236 : :
237 : : /*
238 : : * Store MAC address from RAR0, clear receive address registers, and
239 : : * clear the multicast table.
240 : : */
241 : 0 : hw->mac.num_rar_entries = NGBE_EM_RAR_ENTRIES;
242 : 0 : hw->mac.init_rx_addrs(hw);
243 : :
244 : 0 : return status;
245 : : }
246 : :
247 : : /**
248 : : * ngbe_clear_hw_cntrs - Generic clear hardware counters
249 : : * @hw: pointer to hardware structure
250 : : *
251 : : * Clears all hardware statistics counters by reading them from the hardware
252 : : * Statistics counters are clear on read.
253 : : **/
254 : 0 : s32 ngbe_clear_hw_cntrs(struct ngbe_hw *hw)
255 : : {
256 : : u16 i = 0;
257 : :
258 : : /* QP Stats */
259 : : /* don't write clear queue stats */
260 [ # # ]: 0 : for (i = 0; i < NGBE_MAX_QP; i++) {
261 : 0 : hw->qp_last[i].rx_qp_packets = 0;
262 : 0 : hw->qp_last[i].tx_qp_packets = 0;
263 : 0 : hw->qp_last[i].rx_qp_bytes = 0;
264 : 0 : hw->qp_last[i].tx_qp_bytes = 0;
265 : 0 : hw->qp_last[i].rx_qp_mc_packets = 0;
266 : 0 : hw->qp_last[i].tx_qp_mc_packets = 0;
267 : 0 : hw->qp_last[i].rx_qp_bc_packets = 0;
268 : 0 : hw->qp_last[i].tx_qp_bc_packets = 0;
269 : : }
270 : :
271 : : /* PB Stats */
272 : : rd32(hw, NGBE_PBRXLNKXON);
273 : : rd32(hw, NGBE_PBRXLNKXOFF);
274 : : rd32(hw, NGBE_PBTXLNKXON);
275 : : rd32(hw, NGBE_PBTXLNKXOFF);
276 : :
277 : : /* DMA Stats */
278 : : rd32(hw, NGBE_DMARXPKT);
279 : : rd32(hw, NGBE_DMATXPKT);
280 : :
281 : : rd64(hw, NGBE_DMARXOCTL);
282 : : rd64(hw, NGBE_DMATXOCTL);
283 : :
284 : : /* MAC Stats */
285 : : rd64(hw, NGBE_MACRXERRCRCL);
286 : : rd64(hw, NGBE_MACRXMPKTL);
287 : : rd64(hw, NGBE_MACTXMPKTL);
288 : :
289 : : rd64(hw, NGBE_MACRXPKTL);
290 : : rd64(hw, NGBE_MACTXPKTL);
291 : : rd64(hw, NGBE_MACRXGBOCTL);
292 : :
293 : : rd64(hw, NGBE_MACRXOCTL);
294 : : rd32(hw, NGBE_MACTXOCTL);
295 : :
296 : : rd64(hw, NGBE_MACRX1TO64L);
297 : : rd64(hw, NGBE_MACRX65TO127L);
298 : : rd64(hw, NGBE_MACRX128TO255L);
299 : : rd64(hw, NGBE_MACRX256TO511L);
300 : : rd64(hw, NGBE_MACRX512TO1023L);
301 : : rd64(hw, NGBE_MACRX1024TOMAXL);
302 : : rd64(hw, NGBE_MACTX1TO64L);
303 : : rd64(hw, NGBE_MACTX65TO127L);
304 : : rd64(hw, NGBE_MACTX128TO255L);
305 : : rd64(hw, NGBE_MACTX256TO511L);
306 : : rd64(hw, NGBE_MACTX512TO1023L);
307 : : rd64(hw, NGBE_MACTX1024TOMAXL);
308 : :
309 : : rd64(hw, NGBE_MACRXERRLENL);
310 : : rd32(hw, NGBE_MACRXOVERSIZE);
311 : : rd32(hw, NGBE_MACRXJABBER);
312 : :
313 : : /* MACsec Stats */
314 : : rd32(hw, NGBE_LSECTX_UTPKT);
315 : : rd32(hw, NGBE_LSECTX_ENCPKT);
316 : : rd32(hw, NGBE_LSECTX_PROTPKT);
317 : : rd32(hw, NGBE_LSECTX_ENCOCT);
318 : : rd32(hw, NGBE_LSECTX_PROTOCT);
319 : : rd32(hw, NGBE_LSECRX_UTPKT);
320 : : rd32(hw, NGBE_LSECRX_BTPKT);
321 : : rd32(hw, NGBE_LSECRX_NOSCIPKT);
322 : : rd32(hw, NGBE_LSECRX_UNSCIPKT);
323 : : rd32(hw, NGBE_LSECRX_DECOCT);
324 : : rd32(hw, NGBE_LSECRX_VLDOCT);
325 : : rd32(hw, NGBE_LSECRX_UNCHKPKT);
326 : : rd32(hw, NGBE_LSECRX_DLYPKT);
327 : : rd32(hw, NGBE_LSECRX_LATEPKT);
328 [ # # ]: 0 : for (i = 0; i < 2; i++) {
329 : 0 : rd32(hw, NGBE_LSECRX_OKPKT(i));
330 : 0 : rd32(hw, NGBE_LSECRX_INVPKT(i));
331 : 0 : rd32(hw, NGBE_LSECRX_BADPKT(i));
332 : : }
333 [ # # ]: 0 : for (i = 0; i < 4; i++) {
334 : 0 : rd32(hw, NGBE_LSECRX_INVSAPKT(i));
335 : 0 : rd32(hw, NGBE_LSECRX_BADSAPKT(i));
336 : : }
337 : :
338 : 0 : return 0;
339 : : }
340 : :
341 : : /**
342 : : * ngbe_get_mac_addr - Generic get MAC address
343 : : * @hw: pointer to hardware structure
344 : : * @mac_addr: Adapter MAC address
345 : : *
346 : : * Reads the adapter's MAC address from first Receive Address Register (RAR0)
347 : : * A reset of the adapter must be performed prior to calling this function
348 : : * in order for the MAC address to have been loaded from the EEPROM into RAR0
349 : : **/
350 : 0 : s32 ngbe_get_mac_addr(struct ngbe_hw *hw, u8 *mac_addr)
351 : : {
352 : : u32 rar_high;
353 : : u32 rar_low;
354 : : u16 i;
355 : :
356 : : wr32(hw, NGBE_ETHADDRIDX, 0);
357 : : rar_high = rd32(hw, NGBE_ETHADDRH);
358 : : rar_low = rd32(hw, NGBE_ETHADDRL);
359 : :
360 [ # # ]: 0 : for (i = 0; i < 2; i++)
361 : 0 : mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
362 : :
363 [ # # ]: 0 : for (i = 0; i < 4; i++)
364 : 0 : mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
365 : :
366 : 0 : return 0;
367 : : }
368 : :
369 : : /**
370 : : * ngbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
371 : : * @hw: pointer to the HW structure
372 : : *
373 : : * Determines the LAN function id by reading memory-mapped registers and swaps
374 : : * the port value if requested, and set MAC instance for devices.
375 : : **/
376 : 0 : void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
377 : : {
378 : : struct ngbe_bus_info *bus = &hw->bus;
379 : : u32 reg = 0;
380 : :
381 : : reg = rd32(hw, NGBE_PORTSTAT);
382 : 0 : bus->lan_id = NGBE_PORTSTAT_ID(reg);
383 : 0 : bus->func = bus->lan_id;
384 : 0 : }
385 : :
386 : : /**
387 : : * ngbe_stop_hw - Generic stop Tx/Rx units
388 : : * @hw: pointer to hardware structure
389 : : *
390 : : * Sets the adapter_stopped flag within ngbe_hw struct. Clears interrupts,
391 : : * disables transmit and receive units. The adapter_stopped flag is used by
392 : : * the shared code and drivers to determine if the adapter is in a stopped
393 : : * state and should not touch the hardware.
394 : : **/
395 : 0 : s32 ngbe_stop_hw(struct ngbe_hw *hw)
396 : : {
397 : : u16 i;
398 : : s32 status = 0;
399 : :
400 : : /*
401 : : * Set the adapter_stopped flag so other driver functions stop touching
402 : : * the hardware
403 : : */
404 : 0 : hw->adapter_stopped = true;
405 : :
406 : : /* Disable the receive unit */
407 : 0 : ngbe_disable_rx(hw);
408 : :
409 : : /* Clear interrupt mask to stop interrupts from being generated */
410 : : wr32(hw, NGBE_IENMISC, 0);
411 : : wr32(hw, NGBE_IMS(0), NGBE_IMS_MASK);
412 : :
413 : : /* Clear any pending interrupts, flush previous writes */
414 : : wr32(hw, NGBE_ICRMISC, NGBE_ICRMISC_MASK);
415 : : wr32(hw, NGBE_ICR(0), NGBE_ICR_MASK);
416 : :
417 : : wr32(hw, NGBE_BMECTL, 0x3);
418 : :
419 : : /* Disable the receive unit by stopping each queue */
420 [ # # ]: 0 : for (i = 0; i < hw->mac.max_rx_queues; i++)
421 : 0 : wr32(hw, NGBE_RXCFG(i), 0);
422 : :
423 : : /* flush all queues disables */
424 : : ngbe_flush(hw);
425 : : msec_delay(2);
426 : :
427 : : /*
428 : : * Prevent the PCI-E bus from hanging by disabling PCI-E master
429 : : * access and verify no pending requests
430 : : */
431 : 0 : status = ngbe_set_pcie_master(hw, false);
432 [ # # ]: 0 : if (status)
433 : : return status;
434 : :
435 : : /* Disable the transmit unit. Each queue must be disabled. */
436 [ # # ]: 0 : for (i = 0; i < hw->mac.max_tx_queues; i++)
437 : 0 : wr32(hw, NGBE_TXCFG(i), 0);
438 : :
439 : : /* flush all queues disables */
440 : : ngbe_flush(hw);
441 : : msec_delay(2);
442 : :
443 : 0 : return 0;
444 : : }
445 : :
446 : : /**
447 : : * ngbe_led_on - Turns on the software controllable LEDs.
448 : : * @hw: pointer to hardware structure
449 : : * @index: led number to turn on
450 : : **/
451 : 0 : s32 ngbe_led_on(struct ngbe_hw *hw, u32 index)
452 : : {
453 : : u32 led_reg = rd32(hw, NGBE_LEDCTL);
454 : :
455 [ # # ]: 0 : if (index > 3)
456 : : return NGBE_ERR_PARAM;
457 : :
458 : : /* To turn on the LED, set mode to ON. */
459 : 0 : led_reg |= NGBE_LEDCTL_100M;
460 : : wr32(hw, NGBE_LEDCTL, led_reg);
461 : : ngbe_flush(hw);
462 : :
463 : 0 : return 0;
464 : : }
465 : :
466 : : /**
467 : : * ngbe_led_off - Turns off the software controllable LEDs.
468 : : * @hw: pointer to hardware structure
469 : : * @index: led number to turn off
470 : : **/
471 : 0 : s32 ngbe_led_off(struct ngbe_hw *hw, u32 index)
472 : : {
473 : : u32 led_reg = rd32(hw, NGBE_LEDCTL);
474 : :
475 [ # # ]: 0 : if (index > 3)
476 : : return NGBE_ERR_PARAM;
477 : :
478 : : /* To turn off the LED, set mode to OFF. */
479 : 0 : led_reg &= ~NGBE_LEDCTL_100M;
480 : : wr32(hw, NGBE_LEDCTL, led_reg);
481 : : ngbe_flush(hw);
482 : :
483 : 0 : return 0;
484 : : }
485 : :
486 : : /**
487 : : * ngbe_validate_mac_addr - Validate MAC address
488 : : * @mac_addr: pointer to MAC address.
489 : : *
490 : : * Tests a MAC address to ensure it is a valid Individual Address.
491 : : **/
492 [ # # ]: 0 : s32 ngbe_validate_mac_addr(u8 *mac_addr)
493 : : {
494 : : s32 status = 0;
495 : :
496 : : /* Make sure it is not a multicast address */
497 [ # # ]: 0 : if (NGBE_IS_MULTICAST((struct rte_ether_addr *)mac_addr)) {
498 : : status = NGBE_ERR_INVALID_MAC_ADDR;
499 : : /* Not a broadcast address */
500 [ # # ]: 0 : } else if (NGBE_IS_BROADCAST((struct rte_ether_addr *)mac_addr)) {
501 : : status = NGBE_ERR_INVALID_MAC_ADDR;
502 : : /* Reject the zero address */
503 [ # # # # : 0 : } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
# # ]
504 [ # # # # : 0 : mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
# # ]
505 : : status = NGBE_ERR_INVALID_MAC_ADDR;
506 : : }
507 : 0 : return status;
508 : : }
509 : :
510 : : /**
511 : : * ngbe_set_rar - Set Rx address register
512 : : * @hw: pointer to hardware structure
513 : : * @index: Receive address register to write
514 : : * @addr: Address to put into receive address register
515 : : * @vmdq: VMDq "set" or "pool" index
516 : : * @enable_addr: set flag that address is active
517 : : *
518 : : * Puts an ethernet address into a receive address register.
519 : : **/
520 : 0 : s32 ngbe_set_rar(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
521 : : u32 enable_addr)
522 : : {
523 : : u32 rar_low, rar_high;
524 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
525 : :
526 : : /* Make sure we are using a valid rar index range */
527 [ # # ]: 0 : if (index >= rar_entries) {
528 : 0 : DEBUGOUT("RAR index %d is out of range.", index);
529 : 0 : return NGBE_ERR_INVALID_ARGUMENT;
530 : : }
531 : :
532 : : /* setup VMDq pool selection before this RAR gets enabled */
533 : 0 : hw->mac.set_vmdq(hw, index, vmdq);
534 : :
535 : : /*
536 : : * HW expects these in little endian so we reverse the byte
537 : : * order from network order (big endian) to little endian
538 : : */
539 : 0 : rar_low = NGBE_ETHADDRL_AD0(addr[5]) |
540 : 0 : NGBE_ETHADDRL_AD1(addr[4]) |
541 : 0 : NGBE_ETHADDRL_AD2(addr[3]) |
542 : 0 : NGBE_ETHADDRL_AD3(addr[2]);
543 : : /*
544 : : * Some parts put the VMDq setting in the extra RAH bits,
545 : : * so save everything except the lower 16 bits that hold part
546 : : * of the address and the address valid bit.
547 : : */
548 : : rar_high = rd32(hw, NGBE_ETHADDRH);
549 : 0 : rar_high &= ~NGBE_ETHADDRH_AD_MASK;
550 : 0 : rar_high |= (NGBE_ETHADDRH_AD4(addr[1]) |
551 : 0 : NGBE_ETHADDRH_AD5(addr[0]));
552 : :
553 : 0 : rar_high &= ~NGBE_ETHADDRH_VLD;
554 [ # # ]: 0 : if (enable_addr != 0)
555 : 0 : rar_high |= NGBE_ETHADDRH_VLD;
556 : :
557 : : wr32(hw, NGBE_ETHADDRIDX, index);
558 : : wr32(hw, NGBE_ETHADDRL, rar_low);
559 : : wr32(hw, NGBE_ETHADDRH, rar_high);
560 : :
561 : 0 : return 0;
562 : : }
563 : :
564 : : /**
565 : : * ngbe_clear_rar - Remove Rx address register
566 : : * @hw: pointer to hardware structure
567 : : * @index: Receive address register to write
568 : : *
569 : : * Clears an ethernet address from a receive address register.
570 : : **/
571 : 0 : s32 ngbe_clear_rar(struct ngbe_hw *hw, u32 index)
572 : : {
573 : : u32 rar_high;
574 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
575 : :
576 : : /* Make sure we are using a valid rar index range */
577 [ # # ]: 0 : if (index >= rar_entries) {
578 : 0 : DEBUGOUT("RAR index %d is out of range.", index);
579 : 0 : return NGBE_ERR_INVALID_ARGUMENT;
580 : : }
581 : :
582 : : /*
583 : : * Some parts put the VMDq setting in the extra RAH bits,
584 : : * so save everything except the lower 16 bits that hold part
585 : : * of the address and the address valid bit.
586 : : */
587 : : wr32(hw, NGBE_ETHADDRIDX, index);
588 : : rar_high = rd32(hw, NGBE_ETHADDRH);
589 : 0 : rar_high &= ~(NGBE_ETHADDRH_AD_MASK | NGBE_ETHADDRH_VLD);
590 : :
591 : : wr32(hw, NGBE_ETHADDRL, 0);
592 : : wr32(hw, NGBE_ETHADDRH, rar_high);
593 : :
594 : : /* clear VMDq pool/queue selection for this RAR */
595 : 0 : hw->mac.clear_vmdq(hw, index, BIT_MASK32);
596 : :
597 : 0 : return 0;
598 : : }
599 : :
600 : : /**
601 : : * ngbe_init_rx_addrs - Initializes receive address filters.
602 : : * @hw: pointer to hardware structure
603 : : *
604 : : * Places the MAC address in receive address register 0 and clears the rest
605 : : * of the receive address registers. Clears the multicast table. Assumes
606 : : * the receiver is in reset when the routine is called.
607 : : **/
608 : 0 : s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
609 : : {
610 : : u32 i;
611 : : u32 psrctl;
612 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
613 : :
614 : : /*
615 : : * If the current mac address is valid, assume it is a software override
616 : : * to the permanent address.
617 : : * Otherwise, use the permanent address from the eeprom.
618 : : */
619 [ # # ]: 0 : if (ngbe_validate_mac_addr(hw->mac.addr) ==
620 : : NGBE_ERR_INVALID_MAC_ADDR) {
621 : : /* Get the MAC address from the RAR0 for later reference */
622 : 0 : hw->mac.get_mac_addr(hw, hw->mac.addr);
623 : :
624 : 0 : DEBUGOUT(" Keeping Current RAR0 Addr = "
625 : : RTE_ETHER_ADDR_PRT_FMT,
626 : : hw->mac.addr[0], hw->mac.addr[1],
627 : : hw->mac.addr[2], hw->mac.addr[3],
628 : : hw->mac.addr[4], hw->mac.addr[5]);
629 : : } else {
630 : : /* Setup the receive address. */
631 : 0 : DEBUGOUT("Overriding MAC Address in RAR[0]");
632 : 0 : DEBUGOUT(" New MAC Addr = "
633 : : RTE_ETHER_ADDR_PRT_FMT,
634 : : hw->mac.addr[0], hw->mac.addr[1],
635 : : hw->mac.addr[2], hw->mac.addr[3],
636 : : hw->mac.addr[4], hw->mac.addr[5]);
637 : :
638 : 0 : hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
639 : : }
640 : :
641 : : /* clear VMDq pool/queue selection for RAR 0 */
642 : 0 : hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
643 : :
644 : : /* Zero out the other receive addresses. */
645 : 0 : DEBUGOUT("Clearing RAR[1-%d]", rar_entries - 1);
646 [ # # ]: 0 : for (i = 1; i < rar_entries; i++) {
647 : : wr32(hw, NGBE_ETHADDRIDX, i);
648 : : wr32(hw, NGBE_ETHADDRL, 0);
649 : : wr32(hw, NGBE_ETHADDRH, 0);
650 : : }
651 : :
652 : : /* Clear the MTA */
653 : 0 : hw->addr_ctrl.mta_in_use = 0;
654 : : psrctl = rd32(hw, NGBE_PSRCTL);
655 : 0 : psrctl &= ~(NGBE_PSRCTL_ADHF12_MASK | NGBE_PSRCTL_MCHFENA);
656 : 0 : psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
657 : : wr32(hw, NGBE_PSRCTL, psrctl);
658 : :
659 : 0 : DEBUGOUT(" Clearing MTA");
660 [ # # ]: 0 : for (i = 0; i < hw->mac.mcft_size; i++)
661 : 0 : wr32(hw, NGBE_MCADDRTBL(i), 0);
662 : :
663 : 0 : ngbe_init_uta_tables(hw);
664 : :
665 : 0 : return 0;
666 : : }
667 : :
668 : : /**
669 : : * ngbe_mta_vector - Determines bit-vector in multicast table to set
670 : : * @hw: pointer to hardware structure
671 : : * @mc_addr: the multicast address
672 : : *
673 : : * Extracts the 12 bits, from a multicast address, to determine which
674 : : * bit-vector to set in the multicast table. The hardware uses 12 bits, from
675 : : * incoming rx multicast addresses, to determine the bit-vector to check in
676 : : * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
677 : : * by the MO field of the PSRCTRL. The MO field is set during initialization
678 : : * to mc_filter_type.
679 : : **/
680 : 0 : static s32 ngbe_mta_vector(struct ngbe_hw *hw, u8 *mc_addr)
681 : : {
682 : : u32 vector = 0;
683 : :
684 [ # # # # : 0 : switch (hw->mac.mc_filter_type) {
# ]
685 : 0 : case 0: /* use bits [47:36] of the address */
686 : 0 : vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
687 : 0 : break;
688 : 0 : case 1: /* use bits [46:35] of the address */
689 : 0 : vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
690 : 0 : break;
691 : 0 : case 2: /* use bits [45:34] of the address */
692 : 0 : vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
693 : 0 : break;
694 : 0 : case 3: /* use bits [43:32] of the address */
695 : 0 : vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
696 : 0 : break;
697 : 0 : default: /* Invalid mc_filter_type */
698 : 0 : DEBUGOUT("MC filter type param set incorrectly");
699 : 0 : ASSERT(0);
700 : : break;
701 : : }
702 : :
703 : : /* vector can only be 12-bits or boundary will be exceeded */
704 : 0 : vector &= 0xFFF;
705 : 0 : return vector;
706 : : }
707 : :
708 : : /**
709 : : * ngbe_set_mta - Set bit-vector in multicast table
710 : : * @hw: pointer to hardware structure
711 : : * @mc_addr: Multicast address
712 : : *
713 : : * Sets the bit-vector in the multicast table.
714 : : **/
715 : 0 : void ngbe_set_mta(struct ngbe_hw *hw, u8 *mc_addr)
716 : : {
717 : : u32 vector;
718 : : u32 vector_bit;
719 : : u32 vector_reg;
720 : :
721 : 0 : hw->addr_ctrl.mta_in_use++;
722 : :
723 : 0 : vector = ngbe_mta_vector(hw, mc_addr);
724 : 0 : DEBUGOUT(" bit-vector = 0x%03X", vector);
725 : :
726 : : /*
727 : : * The MTA is a register array of 128 32-bit registers. It is treated
728 : : * like an array of 4096 bits. We want to set bit
729 : : * BitArray[vector_value]. So we figure out what register the bit is
730 : : * in, read it, OR in the new bit, then write back the new value. The
731 : : * register is determined by the upper 7 bits of the vector value and
732 : : * the bit within that register are determined by the lower 5 bits of
733 : : * the value.
734 : : */
735 : 0 : vector_reg = (vector >> 5) & 0x7F;
736 : 0 : vector_bit = vector & 0x1F;
737 : 0 : hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
738 : 0 : }
739 : :
740 : : /**
741 : : * ngbe_update_mc_addr_list - Updates MAC list of multicast addresses
742 : : * @hw: pointer to hardware structure
743 : : * @mc_addr_list: the list of new multicast addresses
744 : : * @mc_addr_count: number of addresses
745 : : * @next: iterator function to walk the multicast address list
746 : : * @clear: flag, when set clears the table beforehand
747 : : *
748 : : * When the clear flag is set, the given list replaces any existing list.
749 : : * Hashes the given addresses into the multicast table.
750 : : **/
751 : 0 : s32 ngbe_update_mc_addr_list(struct ngbe_hw *hw, u8 *mc_addr_list,
752 : : u32 mc_addr_count, ngbe_mc_addr_itr next,
753 : : bool clear)
754 : : {
755 : : u32 i;
756 : : u32 vmdq;
757 : :
758 : : /*
759 : : * Set the new number of MC addresses that we are being requested to
760 : : * use.
761 : : */
762 : 0 : hw->addr_ctrl.num_mc_addrs = mc_addr_count;
763 : 0 : hw->addr_ctrl.mta_in_use = 0;
764 : :
765 : : /* Clear mta_shadow */
766 [ # # ]: 0 : if (clear) {
767 : 0 : DEBUGOUT(" Clearing MTA");
768 : 0 : memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
769 : : }
770 : :
771 : : /* Update mta_shadow */
772 [ # # ]: 0 : for (i = 0; i < mc_addr_count; i++) {
773 : 0 : DEBUGOUT(" Adding the multicast addresses:");
774 : 0 : ngbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
775 : : }
776 : :
777 : : /* Enable mta */
778 [ # # ]: 0 : for (i = 0; i < hw->mac.mcft_size; i++)
779 : 0 : wr32a(hw, NGBE_MCADDRTBL(0), i,
780 : : hw->mac.mta_shadow[i]);
781 : :
782 [ # # ]: 0 : if (hw->addr_ctrl.mta_in_use > 0) {
783 : : u32 psrctl = rd32(hw, NGBE_PSRCTL);
784 : 0 : psrctl &= ~(NGBE_PSRCTL_ADHF12_MASK | NGBE_PSRCTL_MCHFENA);
785 : 0 : psrctl |= NGBE_PSRCTL_MCHFENA |
786 : 0 : NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
787 : : wr32(hw, NGBE_PSRCTL, psrctl);
788 : : }
789 : :
790 : 0 : DEBUGOUT("ngbe update mc addr list complete");
791 : 0 : return 0;
792 : : }
793 : :
794 : : /**
795 : : * ngbe_setup_fc_em - Set up flow control
796 : : * @hw: pointer to hardware structure
797 : : *
798 : : * Called at init time to set up flow control.
799 : : **/
800 : 0 : s32 ngbe_setup_fc_em(struct ngbe_hw *hw)
801 : : {
802 : : s32 err = 0;
803 : : u16 reg_cu = 0;
804 : :
805 : : /* Validate the requested mode */
806 [ # # # # ]: 0 : if (hw->fc.strict_ieee && hw->fc.requested_mode == ngbe_fc_rx_pause) {
807 : 0 : DEBUGOUT("ngbe_fc_rx_pause not valid in strict IEEE mode");
808 : : err = NGBE_ERR_INVALID_LINK_SETTINGS;
809 : 0 : goto out;
810 : : }
811 : :
812 : : /*
813 : : * 1gig parts do not have a word in the EEPROM to determine the
814 : : * default flow control setting, so we explicitly set it to full.
815 : : */
816 [ # # ]: 0 : if (hw->fc.requested_mode == ngbe_fc_default)
817 : 0 : hw->fc.requested_mode = ngbe_fc_full;
818 : :
819 : : /*
820 : : * The possible values of fc.requested_mode are:
821 : : * 0: Flow control is completely disabled
822 : : * 1: Rx flow control is enabled (we can receive pause frames,
823 : : * but not send pause frames).
824 : : * 2: Tx flow control is enabled (we can send pause frames but
825 : : * we do not support receiving pause frames).
826 : : * 3: Both Rx and Tx flow control (symmetric) are enabled.
827 : : * other: Invalid.
828 : : */
829 [ # # # # ]: 0 : switch (hw->fc.requested_mode) {
830 : : case ngbe_fc_none:
831 : : /* Flow control completely disabled by software override. */
832 : : break;
833 : 0 : case ngbe_fc_tx_pause:
834 : : /*
835 : : * Tx Flow control is enabled, and Rx Flow control is
836 : : * disabled by software override.
837 : : */
838 [ # # ]: 0 : if (hw->phy.type == ngbe_phy_mvl_sfi ||
839 : : hw->phy.type == ngbe_phy_yt8521s_sfi)
840 : : reg_cu |= MVL_FANA_ASM_PAUSE;
841 : : else
842 : : reg_cu |= 0x800; /*need to merge rtl and mvl on page 0*/
843 : : break;
844 : 0 : case ngbe_fc_rx_pause:
845 : : /*
846 : : * Rx Flow control is enabled and Tx Flow control is
847 : : * disabled by software override. Since there really
848 : : * isn't a way to advertise that we are capable of RX
849 : : * Pause ONLY, we will advertise that we support both
850 : : * symmetric and asymmetric Rx PAUSE, as such we fall
851 : : * through to the fc_full statement. Later, we will
852 : : * disable the adapter's ability to send PAUSE frames.
853 : : */
854 : : case ngbe_fc_full:
855 : : /* Flow control (both Rx and Tx) is enabled by SW override. */
856 [ # # ]: 0 : if (hw->phy.type == ngbe_phy_mvl_sfi ||
857 : : hw->phy.type == ngbe_phy_yt8521s_sfi)
858 : : reg_cu |= MVL_FANA_SYM_PAUSE;
859 : : else
860 : : reg_cu |= 0xC00; /*need to merge rtl and mvl on page 0*/
861 : : break;
862 : 0 : default:
863 : 0 : DEBUGOUT("Flow control param set incorrectly");
864 : : err = NGBE_ERR_CONFIG;
865 : 0 : goto out;
866 : : }
867 : :
868 : : /*
869 : : * Reconfig mac ctrl frame fwd rule to make sure it still
870 : : * working after port stop/start.
871 : : */
872 : 0 : wr32m(hw, NGBE_MACRXFLT, NGBE_MACRXFLT_CTL_MASK,
873 [ # # ]: 0 : (hw->fc.mac_ctrl_frame_fwd ?
874 : : NGBE_MACRXFLT_CTL_NOPS : NGBE_MACRXFLT_CTL_DROP));
875 : : ngbe_flush(hw);
876 : :
877 : 0 : err = hw->phy.set_pause_adv(hw, reg_cu);
878 : :
879 : 0 : out:
880 : 0 : return err;
881 : : }
882 : :
883 : : /**
884 : : * ngbe_fc_enable - Enable flow control
885 : : * @hw: pointer to hardware structure
886 : : *
887 : : * Enable flow control according to the current settings.
888 : : **/
889 : 0 : s32 ngbe_fc_enable(struct ngbe_hw *hw)
890 : : {
891 : : s32 err = 0;
892 : : u32 mflcn_reg, fccfg_reg;
893 : : u32 pause_time;
894 : : u32 fcrtl, fcrth;
895 : :
896 : : /* Validate the water mark configuration */
897 [ # # ]: 0 : if (!hw->fc.pause_time) {
898 : : err = NGBE_ERR_INVALID_LINK_SETTINGS;
899 : 0 : goto out;
900 : : }
901 : :
902 : : /* Low water mark of zero causes XOFF floods */
903 [ # # # # ]: 0 : if ((hw->fc.current_mode & ngbe_fc_tx_pause) && hw->fc.high_water) {
904 [ # # # # ]: 0 : if (!hw->fc.low_water ||
905 : : hw->fc.low_water >= hw->fc.high_water) {
906 : 0 : DEBUGOUT("Invalid water mark configuration");
907 : : err = NGBE_ERR_INVALID_LINK_SETTINGS;
908 : 0 : goto out;
909 : : }
910 : : }
911 : :
912 : : /* Negotiate the fc mode to use */
913 : 0 : hw->mac.fc_autoneg(hw);
914 : :
915 : : /* Disable any previous flow control settings */
916 : : mflcn_reg = rd32(hw, NGBE_RXFCCFG);
917 : 0 : mflcn_reg &= ~NGBE_RXFCCFG_FC;
918 : :
919 : : fccfg_reg = rd32(hw, NGBE_TXFCCFG);
920 : 0 : fccfg_reg &= ~NGBE_TXFCCFG_FC;
921 : : /*
922 : : * The possible values of fc.current_mode are:
923 : : * 0: Flow control is completely disabled
924 : : * 1: Rx flow control is enabled (we can receive pause frames,
925 : : * but not send pause frames).
926 : : * 2: Tx flow control is enabled (we can send pause frames but
927 : : * we do not support receiving pause frames).
928 : : * 3: Both Rx and Tx flow control (symmetric) are enabled.
929 : : * other: Invalid.
930 : : */
931 [ # # # # : 0 : switch (hw->fc.current_mode) {
# ]
932 : : case ngbe_fc_none:
933 : : /*
934 : : * Flow control is disabled by software override or autoneg.
935 : : * The code below will actually disable it in the HW.
936 : : */
937 : : break;
938 : 0 : case ngbe_fc_rx_pause:
939 : : /*
940 : : * Rx Flow control is enabled and Tx Flow control is
941 : : * disabled by software override. Since there really
942 : : * isn't a way to advertise that we are capable of RX
943 : : * Pause ONLY, we will advertise that we support both
944 : : * symmetric and asymmetric Rx PAUSE. Later, we will
945 : : * disable the adapter's ability to send PAUSE frames.
946 : : */
947 : 0 : mflcn_reg |= NGBE_RXFCCFG_FC;
948 : 0 : break;
949 : 0 : case ngbe_fc_tx_pause:
950 : : /*
951 : : * Tx Flow control is enabled, and Rx Flow control is
952 : : * disabled by software override.
953 : : */
954 : 0 : fccfg_reg |= NGBE_TXFCCFG_FC;
955 : 0 : break;
956 : 0 : case ngbe_fc_full:
957 : : /* Flow control (both Rx and Tx) is enabled by SW override. */
958 : 0 : mflcn_reg |= NGBE_RXFCCFG_FC;
959 : 0 : fccfg_reg |= NGBE_TXFCCFG_FC;
960 : 0 : break;
961 : 0 : default:
962 : 0 : DEBUGOUT("Flow control param set incorrectly");
963 : : err = NGBE_ERR_CONFIG;
964 : 0 : goto out;
965 : : }
966 : :
967 : : /* Set 802.3x based flow control settings. */
968 : : wr32(hw, NGBE_RXFCCFG, mflcn_reg);
969 : : wr32(hw, NGBE_TXFCCFG, fccfg_reg);
970 : :
971 : : /* Set up and enable Rx high/low water mark thresholds, enable XON. */
972 [ # # ]: 0 : if ((hw->fc.current_mode & ngbe_fc_tx_pause) &&
973 [ # # ]: 0 : hw->fc.high_water) {
974 : 0 : fcrtl = NGBE_FCWTRLO_TH(hw->fc.low_water) |
975 : : NGBE_FCWTRLO_XON;
976 : 0 : fcrth = NGBE_FCWTRHI_TH(hw->fc.high_water) |
977 : : NGBE_FCWTRHI_XOFF;
978 : : } else {
979 : : /*
980 : : * In order to prevent Tx hangs when the internal Tx
981 : : * switch is enabled we must set the high water mark
982 : : * to the Rx packet buffer size - 24KB. This allows
983 : : * the Tx switch to function even under heavy Rx
984 : : * workloads.
985 : : */
986 : : fcrtl = 0;
987 : 0 : fcrth = rd32(hw, NGBE_PBRXSIZE) - 24576;
988 : : }
989 : : wr32(hw, NGBE_FCWTRLO, fcrtl);
990 : : wr32(hw, NGBE_FCWTRHI, fcrth);
991 : :
992 : : /* Configure pause time */
993 : 0 : pause_time = NGBE_RXFCFSH_TIME(hw->fc.pause_time);
994 : 0 : wr32(hw, NGBE_FCXOFFTM, pause_time * 0x00010000);
995 : :
996 : : /* Configure flow control refresh threshold value */
997 : 0 : wr32(hw, NGBE_RXFCRFSH, hw->fc.pause_time / 2);
998 : :
999 : 0 : out:
1000 : 0 : return err;
1001 : : }
1002 : :
1003 : : /**
1004 : : * ngbe_negotiate_fc - Negotiate flow control
1005 : : * @hw: pointer to hardware structure
1006 : : * @adv_reg: flow control advertised settings
1007 : : * @lp_reg: link partner's flow control settings
1008 : : * @adv_sym: symmetric pause bit in advertisement
1009 : : * @adv_asm: asymmetric pause bit in advertisement
1010 : : * @lp_sym: symmetric pause bit in link partner advertisement
1011 : : * @lp_asm: asymmetric pause bit in link partner advertisement
1012 : : *
1013 : : * Find the intersection between advertised settings and link partner's
1014 : : * advertised settings
1015 : : **/
1016 : 0 : s32 ngbe_negotiate_fc(struct ngbe_hw *hw, u32 adv_reg, u32 lp_reg,
1017 : : u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
1018 : : {
1019 [ # # ]: 0 : if ((!(adv_reg)) || (!(lp_reg))) {
1020 : 0 : DEBUGOUT("Local or link partner's advertised flow control settings are NULL. Local: %x, link partner: %x",
1021 : : adv_reg, lp_reg);
1022 : 0 : return NGBE_ERR_FC_NOT_NEGOTIATED;
1023 : : }
1024 : :
1025 [ # # # # ]: 0 : if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
1026 : : /*
1027 : : * Now we need to check if the user selected Rx ONLY
1028 : : * of pause frames. In this case, we had to advertise
1029 : : * FULL flow control because we could not advertise RX
1030 : : * ONLY. Hence, we must now check to see if we need to
1031 : : * turn OFF the TRANSMISSION of PAUSE frames.
1032 : : */
1033 [ # # ]: 0 : if (hw->fc.requested_mode == ngbe_fc_full) {
1034 : 0 : hw->fc.current_mode = ngbe_fc_full;
1035 : 0 : DEBUGOUT("Flow Control = FULL.");
1036 : : } else {
1037 : 0 : hw->fc.current_mode = ngbe_fc_rx_pause;
1038 : 0 : DEBUGOUT("Flow Control=RX PAUSE frames only");
1039 : : }
1040 [ # # # # ]: 0 : } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1041 [ # # # # ]: 0 : (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1042 : 0 : hw->fc.current_mode = ngbe_fc_tx_pause;
1043 : 0 : DEBUGOUT("Flow Control = TX PAUSE frames only.");
1044 [ # # # # ]: 0 : } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1045 [ # # # # ]: 0 : !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1046 : 0 : hw->fc.current_mode = ngbe_fc_rx_pause;
1047 : 0 : DEBUGOUT("Flow Control = RX PAUSE frames only.");
1048 : : } else {
1049 : 0 : hw->fc.current_mode = ngbe_fc_none;
1050 : 0 : DEBUGOUT("Flow Control = NONE.");
1051 : : }
1052 : : return 0;
1053 : : }
1054 : :
1055 : : /**
1056 : : * ngbe_fc_autoneg_em - Enable flow control IEEE clause 37
1057 : : * @hw: pointer to hardware structure
1058 : : *
1059 : : * Enable flow control according to IEEE clause 37.
1060 : : **/
1061 : 0 : STATIC s32 ngbe_fc_autoneg_em(struct ngbe_hw *hw)
1062 : : {
1063 : 0 : u8 technology_ability_reg = 0;
1064 : 0 : u8 lp_technology_ability_reg = 0;
1065 : :
1066 : 0 : hw->phy.get_adv_pause(hw, &technology_ability_reg);
1067 : 0 : hw->phy.get_lp_adv_pause(hw, &lp_technology_ability_reg);
1068 : :
1069 : 0 : return ngbe_negotiate_fc(hw, (u32)technology_ability_reg,
1070 : : (u32)lp_technology_ability_reg,
1071 : : NGBE_TAF_SYM_PAUSE, NGBE_TAF_ASM_PAUSE,
1072 : : NGBE_TAF_SYM_PAUSE, NGBE_TAF_ASM_PAUSE);
1073 : : }
1074 : :
1075 : : /**
1076 : : * ngbe_fc_autoneg - Configure flow control
1077 : : * @hw: pointer to hardware structure
1078 : : *
1079 : : * Compares our advertised flow control capabilities to those advertised by
1080 : : * our link partner, and determines the proper flow control mode to use.
1081 : : **/
1082 : 0 : void ngbe_fc_autoneg(struct ngbe_hw *hw)
1083 : : {
1084 : : s32 err = NGBE_ERR_FC_NOT_NEGOTIATED;
1085 : : u32 speed;
1086 : : bool link_up;
1087 : :
1088 : : /*
1089 : : * AN should have completed when the cable was plugged in.
1090 : : * Look for reasons to bail out. Bail out if:
1091 : : * - FC autoneg is disabled, or if
1092 : : * - link is not up.
1093 : : */
1094 [ # # ]: 0 : if (hw->fc.disable_fc_autoneg) {
1095 : 0 : DEBUGOUT("Flow control autoneg is disabled");
1096 : 0 : goto out;
1097 : : }
1098 : :
1099 : 0 : hw->mac.check_link(hw, &speed, &link_up, false);
1100 [ # # ]: 0 : if (!link_up) {
1101 : 0 : DEBUGOUT("The link is down");
1102 : 0 : goto out;
1103 : : }
1104 : :
1105 : 0 : err = ngbe_fc_autoneg_em(hw);
1106 : :
1107 : : out:
1108 [ # # ]: 0 : if (err == 0) {
1109 : 0 : hw->fc.fc_was_autonegged = true;
1110 : : } else {
1111 : 0 : hw->fc.fc_was_autonegged = false;
1112 : 0 : hw->fc.current_mode = hw->fc.requested_mode;
1113 : : }
1114 : 0 : }
1115 : :
1116 : : /**
1117 : : * ngbe_set_pcie_master - Disable or Enable PCI-express master access
1118 : : * @hw: pointer to hardware structure
1119 : : *
1120 : : * Disables PCI-Express master access and verifies there are no pending
1121 : : * requests. NGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
1122 : : * bit hasn't caused the master requests to be disabled, else 0
1123 : : * is returned signifying master requests disabled.
1124 : : **/
1125 : 0 : s32 ngbe_set_pcie_master(struct ngbe_hw *hw, bool enable)
1126 : : {
1127 : 0 : struct rte_pci_device *pci_dev = (struct rte_pci_device *)hw->back;
1128 : : s32 status = 0;
1129 : : u32 i;
1130 : :
1131 [ # # ]: 0 : if (rte_pci_set_bus_master(pci_dev, enable) < 0) {
1132 : 0 : DEBUGOUT("Cannot configure PCI bus master");
1133 : 0 : return -1;
1134 : : }
1135 : :
1136 [ # # ]: 0 : if (enable)
1137 : 0 : goto out;
1138 : :
1139 : : /* Exit if master requests are blocked */
1140 [ # # ]: 0 : if (!(rd32(hw, NGBE_BMEPEND)) ||
1141 : : NGBE_REMOVED(hw->hw_addr))
1142 : 0 : goto out;
1143 : :
1144 : : /* Poll for master request bit to clear */
1145 [ # # ]: 0 : for (i = 0; i < NGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
1146 : 0 : usec_delay(100);
1147 [ # # ]: 0 : if (!(rd32(hw, NGBE_BMEPEND)))
1148 : 0 : goto out;
1149 : : }
1150 : :
1151 : 0 : DEBUGOUT("PCIe transaction pending bit also did not clear.");
1152 : : status = NGBE_ERR_MASTER_REQUESTS_PENDING;
1153 : :
1154 : : out:
1155 : : return status;
1156 : : }
1157 : :
1158 : : /**
1159 : : * ngbe_acquire_swfw_sync - Acquire SWFW semaphore
1160 : : * @hw: pointer to hardware structure
1161 : : * @mask: Mask to specify which semaphore to acquire
1162 : : *
1163 : : * Acquires the SWFW semaphore through the MNGSEM register for the specified
1164 : : * function (CSR, PHY0, PHY1, EEPROM, Flash)
1165 : : **/
1166 : 0 : s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask)
1167 : : {
1168 : : u32 mngsem = 0;
1169 : : u32 fwsm = 0;
1170 : 0 : u32 swmask = NGBE_MNGSEM_SW(mask);
1171 : 0 : u32 fwmask = NGBE_MNGSEM_FW(mask);
1172 : : u32 timeout = 200;
1173 : : u32 i;
1174 : :
1175 [ # # ]: 0 : for (i = 0; i < timeout; i++) {
1176 : : /*
1177 : : * SW NVM semaphore bit is used for access to all
1178 : : * SW_FW_SYNC bits (not just NVM)
1179 : : */
1180 [ # # ]: 0 : if (ngbe_get_eeprom_semaphore(hw))
1181 : : return NGBE_ERR_SWFW_SYNC;
1182 : :
1183 : : mngsem = rd32(hw, NGBE_MNGSEM);
1184 [ # # ]: 0 : if (mngsem & (fwmask | swmask)) {
1185 : : /* Resource is currently in use by FW or SW */
1186 : 0 : ngbe_release_eeprom_semaphore(hw);
1187 : : msec_delay(5);
1188 : : } else {
1189 : 0 : mngsem |= swmask;
1190 : : wr32(hw, NGBE_MNGSEM, mngsem);
1191 : 0 : ngbe_release_eeprom_semaphore(hw);
1192 : 0 : return 0;
1193 : : }
1194 : : }
1195 : :
1196 : : fwsm = rd32(hw, NGBE_MNGFWSYNC);
1197 : 0 : DEBUGOUT("SWFW semaphore not granted: MNG_SWFW_SYNC = 0x%x, MNG_FW_SM = 0x%x",
1198 : : mngsem, fwsm);
1199 : :
1200 : : msec_delay(5);
1201 : 0 : return NGBE_ERR_SWFW_SYNC;
1202 : : }
1203 : :
1204 : : /**
1205 : : * ngbe_release_swfw_sync - Release SWFW semaphore
1206 : : * @hw: pointer to hardware structure
1207 : : * @mask: Mask to specify which semaphore to release
1208 : : *
1209 : : * Releases the SWFW semaphore through the MNGSEM register for the specified
1210 : : * function (CSR, PHY0, PHY1, EEPROM, Flash)
1211 : : **/
1212 : 0 : void ngbe_release_swfw_sync(struct ngbe_hw *hw, u32 mask)
1213 : : {
1214 : : u32 mngsem;
1215 : : u32 swmask = mask;
1216 : :
1217 : 0 : ngbe_get_eeprom_semaphore(hw);
1218 : :
1219 : : mngsem = rd32(hw, NGBE_MNGSEM);
1220 : 0 : mngsem &= ~swmask;
1221 : : wr32(hw, NGBE_MNGSEM, mngsem);
1222 : :
1223 : 0 : ngbe_release_eeprom_semaphore(hw);
1224 : 0 : }
1225 : :
1226 : : /**
1227 : : * ngbe_disable_sec_rx_path - Stops the receive data path
1228 : : * @hw: pointer to hardware structure
1229 : : *
1230 : : * Stops the receive data path and waits for the HW to internally empty
1231 : : * the Rx security block
1232 : : **/
1233 : 0 : s32 ngbe_disable_sec_rx_path(struct ngbe_hw *hw)
1234 : : {
1235 : : #define NGBE_MAX_SECRX_POLL 4000
1236 : :
1237 : : int i;
1238 : : u32 secrxreg;
1239 : :
1240 : : secrxreg = rd32(hw, NGBE_SECRXCTL);
1241 : 0 : secrxreg |= NGBE_SECRXCTL_XDSA;
1242 : : wr32(hw, NGBE_SECRXCTL, secrxreg);
1243 [ # # ]: 0 : for (i = 0; i < NGBE_MAX_SECRX_POLL; i++) {
1244 : : secrxreg = rd32(hw, NGBE_SECRXSTAT);
1245 [ # # ]: 0 : if (!(secrxreg & NGBE_SECRXSTAT_RDY))
1246 : : /* Use interrupt-safe sleep just in case */
1247 : 0 : usec_delay(10);
1248 : : else
1249 : : break;
1250 : : }
1251 : :
1252 : : /* For informational purposes only */
1253 [ # # ]: 0 : if (i >= NGBE_MAX_SECRX_POLL)
1254 : 0 : DEBUGOUT("Rx unit being enabled before security path fully disabled. Continuing with init.");
1255 : :
1256 : 0 : return 0;
1257 : : }
1258 : :
1259 : : /**
1260 : : * ngbe_enable_sec_rx_path - Enables the receive data path
1261 : : * @hw: pointer to hardware structure
1262 : : *
1263 : : * Enables the receive data path.
1264 : : **/
1265 : 0 : s32 ngbe_enable_sec_rx_path(struct ngbe_hw *hw)
1266 : : {
1267 : : u32 secrxreg;
1268 : :
1269 : : secrxreg = rd32(hw, NGBE_SECRXCTL);
1270 : 0 : secrxreg &= ~NGBE_SECRXCTL_XDSA;
1271 : : wr32(hw, NGBE_SECRXCTL, secrxreg);
1272 : : ngbe_flush(hw);
1273 : :
1274 : 0 : return 0;
1275 : : }
1276 : :
1277 : : /**
1278 : : * ngbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
1279 : : * @hw: pointer to hardware struct
1280 : : * @rar: receive address register index to disassociate
1281 : : * @vmdq: VMDq pool index to remove from the rar
1282 : : **/
1283 : 0 : s32 ngbe_clear_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
1284 : : {
1285 : : u32 mpsar;
1286 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
1287 : :
1288 : : /* Make sure we are using a valid rar index range */
1289 [ # # ]: 0 : if (rar >= rar_entries) {
1290 : 0 : DEBUGOUT("RAR index %d is out of range.", rar);
1291 : 0 : return NGBE_ERR_INVALID_ARGUMENT;
1292 : : }
1293 : :
1294 : : wr32(hw, NGBE_ETHADDRIDX, rar);
1295 : : mpsar = rd32(hw, NGBE_ETHADDRASS);
1296 : :
1297 : : if (NGBE_REMOVED(hw->hw_addr))
1298 : : goto done;
1299 : :
1300 [ # # ]: 0 : if (!mpsar)
1301 : 0 : goto done;
1302 : :
1303 : 0 : mpsar &= ~(1 << vmdq);
1304 : : wr32(hw, NGBE_ETHADDRASS, mpsar);
1305 : :
1306 : : /* was that the last pool using this rar? */
1307 [ # # ]: 0 : if (mpsar == 0 && rar != 0)
1308 : 0 : hw->mac.clear_rar(hw, rar);
1309 : 0 : done:
1310 : : return 0;
1311 : : }
1312 : :
1313 : : /**
1314 : : * ngbe_set_vmdq - Associate a VMDq pool index with a rx address
1315 : : * @hw: pointer to hardware struct
1316 : : * @rar: receive address register index to associate with a VMDq index
1317 : : * @vmdq: VMDq pool index
1318 : : **/
1319 : 0 : s32 ngbe_set_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
1320 : : {
1321 : : u32 mpsar;
1322 : 0 : u32 rar_entries = hw->mac.num_rar_entries;
1323 : :
1324 : : /* Make sure we are using a valid rar index range */
1325 [ # # ]: 0 : if (rar >= rar_entries) {
1326 : 0 : DEBUGOUT("RAR index %d is out of range.", rar);
1327 : 0 : return NGBE_ERR_INVALID_ARGUMENT;
1328 : : }
1329 : :
1330 : : wr32(hw, NGBE_ETHADDRIDX, rar);
1331 : :
1332 : : mpsar = rd32(hw, NGBE_ETHADDRASS);
1333 : 0 : mpsar |= 1 << vmdq;
1334 : : wr32(hw, NGBE_ETHADDRASS, mpsar);
1335 : :
1336 : 0 : return 0;
1337 : : }
1338 : :
1339 : : /**
1340 : : * ngbe_init_uta_tables - Initialize the Unicast Table Array
1341 : : * @hw: pointer to hardware structure
1342 : : **/
1343 : 0 : s32 ngbe_init_uta_tables(struct ngbe_hw *hw)
1344 : : {
1345 : : int i;
1346 : :
1347 : 0 : DEBUGOUT(" Clearing UTA");
1348 : :
1349 [ # # ]: 0 : for (i = 0; i < 128; i++)
1350 : 0 : wr32(hw, NGBE_UCADDRTBL(i), 0);
1351 : :
1352 : 0 : return 0;
1353 : : }
1354 : :
1355 : : /**
1356 : : * ngbe_find_vlvf_slot - find the vlanid or the first empty slot
1357 : : * @hw: pointer to hardware structure
1358 : : * @vlan: VLAN id to write to VLAN filter
1359 : : * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
1360 : : * vlanid not found
1361 : : *
1362 : : *
1363 : : * return the VLVF index where this VLAN id should be placed
1364 : : *
1365 : : **/
1366 : 0 : s32 ngbe_find_vlvf_slot(struct ngbe_hw *hw, u32 vlan, bool vlvf_bypass)
1367 : : {
1368 : : s32 regindex, first_empty_slot;
1369 : : u32 bits;
1370 : :
1371 : : /* short cut the special case */
1372 [ # # ]: 0 : if (vlan == 0)
1373 : : return 0;
1374 : :
1375 : : /* if vlvf_bypass is set we don't want to use an empty slot, we
1376 : : * will simply bypass the VLVF if there are no entries present in the
1377 : : * VLVF that contain our VLAN
1378 : : */
1379 [ # # ]: 0 : first_empty_slot = vlvf_bypass ? NGBE_ERR_NO_SPACE : 0;
1380 : :
1381 : : /* add VLAN enable bit for comparison */
1382 : 0 : vlan |= NGBE_PSRVLAN_EA;
1383 : :
1384 : : /* Search for the vlan id in the VLVF entries. Save off the first empty
1385 : : * slot found along the way.
1386 : : *
1387 : : * pre-decrement loop covering (NGBE_NUM_POOL - 1) .. 1
1388 : : */
1389 [ # # ]: 0 : for (regindex = NGBE_NUM_POOL; --regindex;) {
1390 : 0 : wr32(hw, NGBE_PSRVLANIDX, regindex);
1391 : : bits = rd32(hw, NGBE_PSRVLAN);
1392 [ # # ]: 0 : if (bits == vlan)
1393 : 0 : return regindex;
1394 [ # # ]: 0 : if (!first_empty_slot && !bits)
1395 : : first_empty_slot = regindex;
1396 : : }
1397 : :
1398 : : /* If we are here then we didn't find the VLAN. Return first empty
1399 : : * slot we found during our search, else error.
1400 : : */
1401 [ # # ]: 0 : if (!first_empty_slot)
1402 : 0 : DEBUGOUT("No space in VLVF.");
1403 : :
1404 [ # # ]: 0 : return first_empty_slot ? first_empty_slot : NGBE_ERR_NO_SPACE;
1405 : : }
1406 : :
1407 : : /**
1408 : : * ngbe_set_vfta - Set VLAN filter table
1409 : : * @hw: pointer to hardware structure
1410 : : * @vlan: VLAN id to write to VLAN filter
1411 : : * @vind: VMDq output index that maps queue to VLAN id in VLVFB
1412 : : * @vlan_on: boolean flag to turn on/off VLAN
1413 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
1414 : : *
1415 : : * Turn on/off specified VLAN in the VLAN filter table.
1416 : : **/
1417 : 0 : s32 ngbe_set_vfta(struct ngbe_hw *hw, u32 vlan, u32 vind,
1418 : : bool vlan_on, bool vlvf_bypass)
1419 : : {
1420 : : u32 regidx, vfta_delta, vfta;
1421 : : s32 err;
1422 : :
1423 [ # # ]: 0 : if (vlan > 4095 || vind > 63)
1424 : : return NGBE_ERR_PARAM;
1425 : :
1426 : : /*
1427 : : * this is a 2 part operation - first the VFTA, then the
1428 : : * VLVF and VLVFB if VT Mode is set
1429 : : * We don't write the VFTA until we know the VLVF part succeeded.
1430 : : */
1431 : :
1432 : : /* Part 1
1433 : : * The VFTA is a bitstring made up of 128 32-bit registers
1434 : : * that enable the particular VLAN id, much like the MTA:
1435 : : * bits[11-5]: which register
1436 : : * bits[4-0]: which bit in the register
1437 : : */
1438 : 0 : regidx = vlan / 32;
1439 : 0 : vfta_delta = 1 << (vlan % 32);
1440 : 0 : vfta = rd32(hw, NGBE_VLANTBL(regidx));
1441 : :
1442 : : /*
1443 : : * vfta_delta represents the difference between the current value
1444 : : * of vfta and the value we want in the register. Since the diff
1445 : : * is an XOR mask we can just update the vfta using an XOR
1446 : : */
1447 [ # # ]: 0 : vfta_delta &= vlan_on ? ~vfta : vfta;
1448 : 0 : vfta ^= vfta_delta;
1449 : :
1450 : : /* Part 2
1451 : : * Call ngbe_set_vlvf to set VLVFB and VLVF
1452 : : */
1453 : 0 : err = ngbe_set_vlvf(hw, vlan, vind, vlan_on, &vfta_delta,
1454 : : vfta, vlvf_bypass);
1455 [ # # ]: 0 : if (err != 0) {
1456 [ # # ]: 0 : if (vlvf_bypass)
1457 : 0 : goto vfta_update;
1458 : : return err;
1459 : : }
1460 : :
1461 : 0 : vfta_update:
1462 : : /* Update VFTA now that we are ready for traffic */
1463 [ # # ]: 0 : if (vfta_delta)
1464 : : wr32(hw, NGBE_VLANTBL(regidx), vfta);
1465 : :
1466 : : return 0;
1467 : : }
1468 : :
1469 : : /**
1470 : : * ngbe_set_vlvf - Set VLAN Pool Filter
1471 : : * @hw: pointer to hardware structure
1472 : : * @vlan: VLAN id to write to VLAN filter
1473 : : * @vind: VMDq output index that maps queue to VLAN id in PSRVLANPLM
1474 : : * @vlan_on: boolean flag to turn on/off VLAN in PSRVLAN
1475 : : * @vfta_delta: pointer to the difference between the current value
1476 : : * of PSRVLANPLM and the desired value
1477 : : * @vfta: the desired value of the VFTA
1478 : : * @vlvf_bypass: boolean flag indicating updating default pool is okay
1479 : : *
1480 : : * Turn on/off specified bit in VLVF table.
1481 : : **/
1482 : 0 : s32 ngbe_set_vlvf(struct ngbe_hw *hw, u32 vlan, u32 vind,
1483 : : bool vlan_on, u32 *vfta_delta, u32 vfta,
1484 : : bool vlvf_bypass)
1485 : : {
1486 : : u32 bits;
1487 : : u32 portctl;
1488 : : s32 vlvf_index;
1489 : :
1490 [ # # ]: 0 : if (vlan > 4095 || vind > 63)
1491 : : return NGBE_ERR_PARAM;
1492 : :
1493 : : /* If VT Mode is set
1494 : : * Either vlan_on
1495 : : * make sure the vlan is in PSRVLAN
1496 : : * set the vind bit in the matching PSRVLANPLM
1497 : : * Or !vlan_on
1498 : : * clear the pool bit and possibly the vind
1499 : : */
1500 : : portctl = rd32(hw, NGBE_PORTCTL);
1501 [ # # ]: 0 : if (!(portctl & NGBE_PORTCTL_NUMVT_MASK))
1502 : : return 0;
1503 : :
1504 : 0 : vlvf_index = ngbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
1505 [ # # ]: 0 : if (vlvf_index < 0)
1506 : : return vlvf_index;
1507 : :
1508 : 0 : wr32(hw, NGBE_PSRVLANIDX, vlvf_index);
1509 : 0 : bits = rd32(hw, NGBE_PSRVLANPLM(vind / 32));
1510 : :
1511 : : /* set the pool bit */
1512 : 0 : bits |= 1 << (vind % 32);
1513 [ # # ]: 0 : if (vlan_on)
1514 : 0 : goto vlvf_update;
1515 : :
1516 : : /* clear the pool bit */
1517 : 0 : bits ^= 1 << (vind % 32);
1518 : :
1519 [ # # # # ]: 0 : if (!bits &&
1520 : : !rd32(hw, NGBE_PSRVLANPLM(vind / 32))) {
1521 : : /* Clear PSRVLANPLM first, then disable PSRVLAN. Otherwise
1522 : : * we run the risk of stray packets leaking into
1523 : : * the PF via the default pool
1524 : : */
1525 [ # # ]: 0 : if (*vfta_delta)
1526 : 0 : wr32(hw, NGBE_PSRVLANPLM(vlan / 32), vfta);
1527 : :
1528 : : /* disable VLVF and clear remaining bit from pool */
1529 : : wr32(hw, NGBE_PSRVLAN, 0);
1530 : : wr32(hw, NGBE_PSRVLANPLM(vind / 32), 0);
1531 : :
1532 : 0 : return 0;
1533 : : }
1534 : :
1535 : : /* If there are still bits set in the PSRVLANPLM registers
1536 : : * for the VLAN ID indicated we need to see if the
1537 : : * caller is requesting that we clear the PSRVLANPLM entry bit.
1538 : : * If the caller has requested that we clear the PSRVLANPLM
1539 : : * entry bit but there are still pools/VFs using this VLAN
1540 : : * ID entry then ignore the request. We're not worried
1541 : : * about the case where we're turning the PSRVLANPLM VLAN ID
1542 : : * entry bit on, only when requested to turn it off as
1543 : : * there may be multiple pools and/or VFs using the
1544 : : * VLAN ID entry. In that case we cannot clear the
1545 : : * PSRVLANPLM bit until all pools/VFs using that VLAN ID have also
1546 : : * been cleared. This will be indicated by "bits" being
1547 : : * zero.
1548 : : */
1549 : 0 : *vfta_delta = 0;
1550 : :
1551 : 0 : vlvf_update:
1552 : : /* record pool change and enable VLAN ID if not already enabled */
1553 : : wr32(hw, NGBE_PSRVLANPLM(vind / 32), bits);
1554 : 0 : wr32(hw, NGBE_PSRVLAN, NGBE_PSRVLAN_EA | vlan);
1555 : :
1556 : 0 : return 0;
1557 : : }
1558 : :
1559 : : /**
1560 : : * ngbe_clear_vfta - Clear VLAN filter table
1561 : : * @hw: pointer to hardware structure
1562 : : *
1563 : : * Clears the VLAN filer table, and the VMDq index associated with the filter
1564 : : **/
1565 : 0 : s32 ngbe_clear_vfta(struct ngbe_hw *hw)
1566 : : {
1567 : : u32 offset;
1568 : :
1569 [ # # ]: 0 : for (offset = 0; offset < hw->mac.vft_size; offset++)
1570 : 0 : wr32(hw, NGBE_VLANTBL(offset), 0);
1571 : :
1572 [ # # ]: 0 : for (offset = 0; offset < NGBE_NUM_POOL; offset++) {
1573 : : wr32(hw, NGBE_PSRVLANIDX, offset);
1574 : : wr32(hw, NGBE_PSRVLAN, 0);
1575 : : wr32(hw, NGBE_PSRVLANPLM(0), 0);
1576 : : }
1577 : :
1578 : 0 : return 0;
1579 : : }
1580 : :
1581 : : /**
1582 : : * ngbe_check_mac_link_em - Determine link and speed status
1583 : : * @hw: pointer to hardware structure
1584 : : * @speed: pointer to link speed
1585 : : * @link_up: true when link is up
1586 : : * @link_up_wait_to_complete: bool used to wait for link up or not
1587 : : *
1588 : : * Reads the links register to determine if link is up and the current speed
1589 : : **/
1590 : 0 : s32 ngbe_check_mac_link_em(struct ngbe_hw *hw, u32 *speed,
1591 : : bool *link_up, bool link_up_wait_to_complete)
1592 : : {
1593 : : u32 i;
1594 : : s32 status = 0;
1595 : :
1596 [ # # ]: 0 : if (hw->lsc) {
1597 : : u32 reg;
1598 : :
1599 : : reg = rd32(hw, NGBE_GPIOINTSTAT);
1600 : : wr32(hw, NGBE_GPIOEOI, reg);
1601 : : }
1602 : :
1603 [ # # ]: 0 : if (link_up_wait_to_complete) {
1604 [ # # ]: 0 : for (i = 0; i < hw->mac.max_link_up_time; i++) {
1605 : 0 : status = hw->phy.check_link(hw, speed, link_up);
1606 [ # # ]: 0 : if (*link_up)
1607 : : break;
1608 : : msec_delay(100);
1609 : : }
1610 : : } else {
1611 : 0 : status = hw->phy.check_link(hw, speed, link_up);
1612 : : }
1613 : :
1614 : 0 : return status;
1615 : : }
1616 : :
1617 : 0 : s32 ngbe_get_link_capabilities_em(struct ngbe_hw *hw,
1618 : : u32 *speed,
1619 : : bool *autoneg)
1620 : : {
1621 : : s32 status = 0;
1622 : 0 : u16 value = 0;
1623 : :
1624 : 0 : hw->mac.autoneg = *autoneg;
1625 : :
1626 [ # # ]: 0 : if (hw->phy.type == ngbe_phy_rtl) {
1627 : 0 : *speed = NGBE_LINK_SPEED_1GB_FULL |
1628 : : NGBE_LINK_SPEED_100M_FULL |
1629 : : NGBE_LINK_SPEED_10M_FULL;
1630 : : }
1631 : :
1632 [ # # ]: 0 : if (hw->phy.type == ngbe_phy_yt8521s_sfi) {
1633 : 0 : ngbe_read_phy_reg_ext_yt(hw, YT_CHIP, 0, &value);
1634 [ # # ]: 0 : if ((value & YT_CHIP_MODE_MASK) == YT_CHIP_MODE_SEL(1))
1635 : 0 : *speed = NGBE_LINK_SPEED_1GB_FULL;
1636 : : }
1637 : :
1638 : 0 : return status;
1639 : : }
1640 : :
1641 : 0 : s32 ngbe_setup_mac_link_em(struct ngbe_hw *hw,
1642 : : u32 speed,
1643 : : bool autoneg_wait_to_complete)
1644 : : {
1645 : : s32 status;
1646 : :
1647 : : /* Setup the PHY according to input speed */
1648 : 0 : status = hw->phy.setup_link(hw, speed, autoneg_wait_to_complete);
1649 : :
1650 : 0 : return status;
1651 : : }
1652 : :
1653 : : /**
1654 : : * ngbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
1655 : : * @hw: pointer to hardware structure
1656 : : * @enable: enable or disable switch for MAC anti-spoofing
1657 : : * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
1658 : : *
1659 : : **/
1660 : 0 : void ngbe_set_mac_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)
1661 : : {
1662 : : u32 pfvfspoof;
1663 : :
1664 : : pfvfspoof = rd32(hw, NGBE_POOLTXASMAC);
1665 [ # # ]: 0 : if (enable)
1666 : 0 : pfvfspoof |= (1 << vf);
1667 : : else
1668 : 0 : pfvfspoof &= ~(1 << vf);
1669 : : wr32(hw, NGBE_POOLTXASMAC, pfvfspoof);
1670 : 0 : }
1671 : :
1672 : : /**
1673 : : * ngbe_set_pba - Initialize Rx packet buffer
1674 : : * @hw: pointer to hardware structure
1675 : : * @headroom: reserve n KB of headroom
1676 : : **/
1677 : 0 : void ngbe_set_pba(struct ngbe_hw *hw)
1678 : : {
1679 : 0 : u32 rxpktsize = hw->mac.rx_pb_size;
1680 : : u32 txpktsize, txpbthresh;
1681 : :
1682 : : /* Reserve 256 KB of headroom */
1683 : 0 : rxpktsize -= 256;
1684 : :
1685 : 0 : rxpktsize <<= 10;
1686 : : wr32(hw, NGBE_PBRXSIZE, rxpktsize);
1687 : :
1688 : : /* Only support an equally distributed Tx packet buffer strategy. */
1689 : : txpktsize = NGBE_PBTXSIZE_MAX;
1690 : : txpbthresh = (txpktsize / 1024) - NGBE_TXPKT_SIZE_MAX;
1691 : :
1692 : : wr32(hw, NGBE_PBTXSIZE, txpktsize);
1693 : : wr32(hw, NGBE_PBTXDMATH, txpbthresh);
1694 : 0 : }
1695 : :
1696 : : /**
1697 : : * ngbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
1698 : : * @hw: pointer to hardware structure
1699 : : * @enable: enable or disable switch for VLAN anti-spoofing
1700 : : * @vf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
1701 : : *
1702 : : **/
1703 : 0 : void ngbe_set_vlan_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)
1704 : : {
1705 : : u32 pfvfspoof;
1706 : :
1707 : : pfvfspoof = rd32(hw, NGBE_POOLTXASVLAN);
1708 [ # # ]: 0 : if (enable)
1709 : 0 : pfvfspoof |= (1 << vf);
1710 : : else
1711 : 0 : pfvfspoof &= ~(1 << vf);
1712 : : wr32(hw, NGBE_POOLTXASVLAN, pfvfspoof);
1713 : 0 : }
1714 : :
1715 : : /**
1716 : : * ngbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
1717 : : * @hw: pointer to hardware structure
1718 : : *
1719 : : * Inits the thermal sensor thresholds according to the NVM map
1720 : : * and save off the threshold and location values into mac.thermal_sensor_data
1721 : : **/
1722 : 0 : s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw)
1723 : : {
1724 [ # # ]: 0 : struct ngbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
1725 : :
1726 : : memset(data, 0, sizeof(struct ngbe_thermal_sensor_data));
1727 : :
1728 [ # # ]: 0 : if (hw->bus.lan_id != 0)
1729 : : return NGBE_NOT_IMPLEMENTED;
1730 : :
1731 : : wr32(hw, NGBE_TSINTR,
1732 : : NGBE_TSINTR_AEN | NGBE_TSINTR_DEN);
1733 : : wr32(hw, NGBE_TSEN, NGBE_TSEN_ENA);
1734 : :
1735 : :
1736 : 0 : data->sensor[0].alarm_thresh = 115;
1737 : : wr32(hw, NGBE_TSATHRE, 0x344);
1738 : 0 : data->sensor[0].dalarm_thresh = 110;
1739 : : wr32(hw, NGBE_TSDTHRE, 0x330);
1740 : :
1741 : 0 : return 0;
1742 : : }
1743 : :
1744 : 0 : s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw)
1745 : : {
1746 : : s32 status = 0;
1747 : : u32 ts_state;
1748 : :
1749 : : /* Check that the LASI temp alarm status was triggered */
1750 : : ts_state = rd32(hw, NGBE_TSALM);
1751 : :
1752 [ # # ]: 0 : if (ts_state & NGBE_TSALM_HI)
1753 : : status = NGBE_ERR_UNDERTEMP;
1754 [ # # ]: 0 : else if (ts_state & NGBE_TSALM_LO)
1755 : : status = NGBE_ERR_OVERTEMP;
1756 : :
1757 : 0 : return status;
1758 : : }
1759 : :
1760 : 0 : void ngbe_disable_rx(struct ngbe_hw *hw)
1761 : : {
1762 : : u32 pfdtxgswc;
1763 : :
1764 : : pfdtxgswc = rd32(hw, NGBE_PSRCTL);
1765 [ # # ]: 0 : if (pfdtxgswc & NGBE_PSRCTL_LBENA) {
1766 : 0 : pfdtxgswc &= ~NGBE_PSRCTL_LBENA;
1767 : : wr32(hw, NGBE_PSRCTL, pfdtxgswc);
1768 : 0 : hw->mac.set_lben = true;
1769 : : } else {
1770 : 0 : hw->mac.set_lben = false;
1771 : : }
1772 : :
1773 : : wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, 0);
1774 [ # # # # ]: 0 : if (!(hw->ncsi_enabled || hw->wol_enabled))
1775 : : wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, 0);
1776 : 0 : }
1777 : :
1778 : 0 : void ngbe_enable_rx(struct ngbe_hw *hw)
1779 : : {
1780 : : u32 pfdtxgswc;
1781 : :
1782 : : wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, NGBE_MACRXCFG_ENA);
1783 : : wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, NGBE_PBRXCTL_ENA);
1784 : :
1785 [ # # ]: 0 : if (hw->mac.set_lben) {
1786 : : pfdtxgswc = rd32(hw, NGBE_PSRCTL);
1787 : 0 : pfdtxgswc |= NGBE_PSRCTL_LBENA;
1788 : : wr32(hw, NGBE_PSRCTL, pfdtxgswc);
1789 : 0 : hw->mac.set_lben = false;
1790 : : }
1791 : 0 : }
1792 : :
1793 : : /**
1794 : : * ngbe_set_mac_type - Sets MAC type
1795 : : * @hw: pointer to the HW structure
1796 : : *
1797 : : * This function sets the mac type of the adapter based on the
1798 : : * vendor ID and device ID stored in the hw structure.
1799 : : **/
1800 : 0 : s32 ngbe_set_mac_type(struct ngbe_hw *hw)
1801 : : {
1802 : : s32 err = 0;
1803 : :
1804 [ # # ]: 0 : if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
1805 : 0 : DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
1806 : 0 : return NGBE_ERR_DEVICE_NOT_SUPPORTED;
1807 : : }
1808 : :
1809 [ # # # # : 0 : switch (hw->sub_device_id) {
# # ]
1810 : 0 : case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
1811 : : case NGBE_SUB_DEV_ID_EM_MVL_RGMII:
1812 : 0 : hw->phy.media_type = ngbe_media_type_copper;
1813 : 0 : hw->mac.type = ngbe_mac_em;
1814 : 0 : hw->mac.link_type = ngbe_link_copper;
1815 : 0 : break;
1816 : 0 : case NGBE_SUB_DEV_ID_EM_RTL_YT8521S_SFP:
1817 : 0 : hw->phy.media_type = ngbe_media_type_copper;
1818 : 0 : hw->mac.type = ngbe_mac_em;
1819 : 0 : hw->mac.link_type = ngbe_link_fiber;
1820 : 0 : break;
1821 : 0 : case NGBE_SUB_DEV_ID_EM_MVL_SFP:
1822 : : case NGBE_SUB_DEV_ID_EM_YT8521S_SFP:
1823 : 0 : hw->phy.media_type = ngbe_media_type_fiber;
1824 : 0 : hw->mac.type = ngbe_mac_em;
1825 : 0 : hw->mac.link_type = ngbe_link_fiber;
1826 : 0 : break;
1827 : 0 : case NGBE_SUB_DEV_ID_EM_MVL_MIX:
1828 : 0 : hw->phy.media_type = ngbe_media_type_unknown;
1829 : 0 : hw->mac.type = ngbe_mac_em;
1830 : 0 : hw->mac.link_type = ngbe_link_type_unknown;
1831 : 0 : break;
1832 : 0 : case NGBE_SUB_DEV_ID_EM_VF:
1833 : 0 : hw->phy.media_type = ngbe_media_type_virtual;
1834 : 0 : hw->mac.type = ngbe_mac_em_vf;
1835 : 0 : break;
1836 : 0 : default:
1837 : : err = NGBE_ERR_DEVICE_NOT_SUPPORTED;
1838 : 0 : hw->phy.media_type = ngbe_media_type_unknown;
1839 : 0 : hw->mac.type = ngbe_mac_unknown;
1840 : 0 : DEBUGOUT("Unsupported device id: %x", hw->device_id);
1841 : 0 : break;
1842 : : }
1843 : :
1844 : 0 : DEBUGOUT("found mac: %d media: %d, returns: %d",
1845 : : hw->mac.type, hw->phy.media_type, err);
1846 : 0 : return err;
1847 : : }
1848 : :
1849 : : /**
1850 : : * ngbe_enable_rx_dma - Enable the Rx DMA unit
1851 : : * @hw: pointer to hardware structure
1852 : : * @regval: register value to write to RXCTRL
1853 : : *
1854 : : * Enables the Rx DMA unit
1855 : : **/
1856 : 0 : s32 ngbe_enable_rx_dma(struct ngbe_hw *hw, u32 regval)
1857 : : {
1858 : : /*
1859 : : * Workaround silicon errata when enabling the Rx datapath.
1860 : : * If traffic is incoming before we enable the Rx unit, it could hang
1861 : : * the Rx DMA unit. Therefore, make sure the security engine is
1862 : : * completely disabled prior to enabling the Rx unit.
1863 : : */
1864 : 0 : hw->mac.disable_sec_rx_path(hw);
1865 : :
1866 [ # # ]: 0 : if (regval & NGBE_PBRXCTL_ENA)
1867 : 0 : ngbe_enable_rx(hw);
1868 : : else
1869 : 0 : ngbe_disable_rx(hw);
1870 : :
1871 : 0 : hw->mac.enable_sec_rx_path(hw);
1872 : :
1873 : 0 : return 0;
1874 : : }
1875 : :
1876 : : /* cmd_addr is used for some special command:
1877 : : * 1. to be sector address, when implemented erase sector command
1878 : : * 2. to be flash address when implemented read, write flash address
1879 : : *
1880 : : * Return 0 on success, return NGBE_ERR_TIMEOUT on failure.
1881 : : */
1882 : 0 : s32 ngbe_fmgr_cmd_op(struct ngbe_hw *hw, u32 cmd, u32 cmd_addr)
1883 : : {
1884 : : u32 cmd_val, i;
1885 : :
1886 : 0 : cmd_val = NGBE_SPICMD_CMD(cmd) | NGBE_SPICMD_CLK(3) | cmd_addr;
1887 : : wr32(hw, NGBE_SPICMD, cmd_val);
1888 : :
1889 [ # # ]: 0 : for (i = 0; i < NGBE_SPI_TIMEOUT; i++) {
1890 [ # # ]: 0 : if (rd32(hw, NGBE_SPISTAT) & NGBE_SPISTAT_OPDONE)
1891 : : break;
1892 : :
1893 : 0 : usec_delay(10);
1894 : : }
1895 [ # # ]: 0 : if (i == NGBE_SPI_TIMEOUT)
1896 : 0 : return NGBE_ERR_TIMEOUT;
1897 : :
1898 : : return 0;
1899 : : }
1900 : :
1901 : 0 : s32 ngbe_flash_read_dword(struct ngbe_hw *hw, u32 addr, u32 *data)
1902 : : {
1903 : : s32 status;
1904 : :
1905 : 0 : status = ngbe_fmgr_cmd_op(hw, 1, addr);
1906 [ # # ]: 0 : if (status < 0) {
1907 : 0 : DEBUGOUT("Read flash timeout.");
1908 : 0 : return status;
1909 : : }
1910 : :
1911 : 0 : *data = rd32(hw, NGBE_SPIDAT);
1912 : :
1913 : 0 : return 0;
1914 : : }
1915 : :
1916 : 0 : void ngbe_read_efuse(struct ngbe_hw *hw)
1917 : : {
1918 : 0 : u32 efuse[2] = {0, 0};
1919 : 0 : u8 lan_id = hw->bus.lan_id;
1920 : :
1921 : 0 : ngbe_flash_read_dword(hw, 0xfe010 + lan_id * 8, &efuse[0]);
1922 : 0 : ngbe_flash_read_dword(hw, 0xfe010 + lan_id * 8 + 4, &efuse[1]);
1923 : :
1924 : 0 : DEBUGOUT("port %d efuse[0] = %08x, efuse[1] = %08x",
1925 : : lan_id, efuse[0], efuse[1]);
1926 : :
1927 : 0 : hw->gphy_efuse[0] = efuse[0];
1928 : 0 : hw->gphy_efuse[1] = efuse[1];
1929 : 0 : }
1930 : :
1931 : 0 : void ngbe_map_device_id(struct ngbe_hw *hw)
1932 : : {
1933 : 0 : u16 oem = hw->sub_system_id & NGBE_OEM_MASK;
1934 : : u16 ncsi = hw->sub_system_id & NGBE_NCSI_SUP_MASK;
1935 : 0 : u16 wol = hw->sub_system_id & NGBE_WOL_SUP_MASK;
1936 : :
1937 : 0 : hw->is_pf = true;
1938 : :
1939 : : /* move subsystem_device_id to device_id */
1940 [ # # # ]: 0 : switch (hw->device_id) {
1941 : 0 : case NGBE_DEV_ID_EM_WX1860AL_W_VF:
1942 : : case NGBE_DEV_ID_EM_WX1860A2_VF:
1943 : : case NGBE_DEV_ID_EM_WX1860A2S_VF:
1944 : : case NGBE_DEV_ID_EM_WX1860A4_VF:
1945 : : case NGBE_DEV_ID_EM_WX1860A4S_VF:
1946 : : case NGBE_DEV_ID_EM_WX1860AL2_VF:
1947 : : case NGBE_DEV_ID_EM_WX1860AL2S_VF:
1948 : : case NGBE_DEV_ID_EM_WX1860AL4_VF:
1949 : : case NGBE_DEV_ID_EM_WX1860AL4S_VF:
1950 : : case NGBE_DEV_ID_EM_WX1860NCSI_VF:
1951 : : case NGBE_DEV_ID_EM_WX1860A1_VF:
1952 : : case NGBE_DEV_ID_EM_WX1860A1L_VF:
1953 : 0 : hw->device_id = NGBE_DEV_ID_EM_VF;
1954 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_VF;
1955 : 0 : hw->is_pf = false;
1956 : 0 : break;
1957 : 0 : case NGBE_DEV_ID_EM_WX1860AL_W:
1958 : : case NGBE_DEV_ID_EM_WX1860A2:
1959 : : case NGBE_DEV_ID_EM_WX1860A2S:
1960 : : case NGBE_DEV_ID_EM_WX1860A4:
1961 : : case NGBE_DEV_ID_EM_WX1860A4S:
1962 : : case NGBE_DEV_ID_EM_WX1860AL2:
1963 : : case NGBE_DEV_ID_EM_WX1860AL2S:
1964 : : case NGBE_DEV_ID_EM_WX1860AL4:
1965 : : case NGBE_DEV_ID_EM_WX1860AL4S:
1966 : : case NGBE_DEV_ID_EM_WX1860NCSI:
1967 : : case NGBE_DEV_ID_EM_WX1860A1:
1968 : : case NGBE_DEV_ID_EM_WX1860A1L:
1969 : 0 : hw->device_id = NGBE_DEV_ID_EM;
1970 [ # # ]: 0 : if (oem == NGBE_M88E1512_SFP || oem == NGBE_LY_M88E1512_SFP)
1971 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_SFP;
1972 [ # # # # ]: 0 : else if (oem == NGBE_M88E1512_RJ45 ||
1973 : : (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45))
1974 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_RGMII;
1975 : : else if (oem == NGBE_M88E1512_MIX)
1976 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_MIX;
1977 : : else if (oem == NGBE_YT8521S_SFP ||
1978 : : oem == NGBE_YT8521S_SFP_GPIO ||
1979 : : oem == NGBE_LY_YT8521S_SFP)
1980 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_YT8521S_SFP;
1981 : : else if (oem == NGBE_INTERNAL_YT8521S_SFP ||
1982 : : oem == NGBE_INTERNAL_YT8521S_SFP_GPIO)
1983 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_YT8521S_SFP;
1984 : : else
1985 : 0 : hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_SGMII;
1986 : : break;
1987 : : default:
1988 : : break;
1989 : : }
1990 : :
1991 [ # # ]: 0 : if (oem == NGBE_LY_M88E1512_SFP || oem == NGBE_YT8521S_SFP_GPIO ||
1992 : 0 : oem == NGBE_INTERNAL_YT8521S_SFP_GPIO ||
1993 [ # # ]: 0 : oem == NGBE_LY_YT8521S_SFP)
1994 : 0 : hw->gpio_ctl = true;
1995 : :
1996 : 0 : hw->wol_enabled = (wol == NGBE_WOL_SUP_MASK) ? true : false;
1997 : 0 : hw->ncsi_enabled = (ncsi == NGBE_NCSI_SUP_MASK ||
1998 : 0 : oem == NGBE_OCP_CARD) ? true : false;
1999 : 0 : }
2000 : :
2001 : : /**
2002 : : * ngbe_init_ops_pf - Inits func ptrs and MAC type
2003 : : * @hw: pointer to hardware structure
2004 : : *
2005 : : * Initialize the function pointers and assign the MAC type.
2006 : : * Does not touch the hardware.
2007 : : **/
2008 : 0 : s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
2009 : : {
2010 : : struct ngbe_bus_info *bus = &hw->bus;
2011 : : struct ngbe_mac_info *mac = &hw->mac;
2012 : : struct ngbe_phy_info *phy = &hw->phy;
2013 : : struct ngbe_rom_info *rom = &hw->rom;
2014 : : struct ngbe_mbx_info *mbx = &hw->mbx;
2015 : :
2016 : : /* BUS */
2017 : 0 : bus->set_lan_id = ngbe_set_lan_id_multi_port;
2018 : :
2019 : : /* PHY */
2020 : 0 : phy->identify = ngbe_identify_phy;
2021 : 0 : phy->read_reg = ngbe_read_phy_reg;
2022 : 0 : phy->write_reg = ngbe_write_phy_reg;
2023 : 0 : phy->read_reg_unlocked = ngbe_read_phy_reg_mdi;
2024 : 0 : phy->write_reg_unlocked = ngbe_write_phy_reg_mdi;
2025 : 0 : phy->reset_hw = ngbe_reset_phy;
2026 : 0 : phy->led_oem_chk = ngbe_phy_led_oem_chk;
2027 : :
2028 : : /* MAC */
2029 : 0 : mac->init_hw = ngbe_init_hw;
2030 : 0 : mac->reset_hw = ngbe_reset_hw_em;
2031 : 0 : mac->start_hw = ngbe_start_hw;
2032 : 0 : mac->clear_hw_cntrs = ngbe_clear_hw_cntrs;
2033 : 0 : mac->enable_rx_dma = ngbe_enable_rx_dma;
2034 : 0 : mac->get_mac_addr = ngbe_get_mac_addr;
2035 : 0 : mac->stop_hw = ngbe_stop_hw;
2036 : 0 : mac->acquire_swfw_sync = ngbe_acquire_swfw_sync;
2037 : 0 : mac->release_swfw_sync = ngbe_release_swfw_sync;
2038 : :
2039 : 0 : mac->disable_sec_rx_path = ngbe_disable_sec_rx_path;
2040 : 0 : mac->enable_sec_rx_path = ngbe_enable_sec_rx_path;
2041 : :
2042 : : /* LEDs */
2043 : 0 : mac->led_on = ngbe_led_on;
2044 : 0 : mac->led_off = ngbe_led_off;
2045 : :
2046 : : /* RAR, VLAN, Multicast */
2047 : 0 : mac->set_rar = ngbe_set_rar;
2048 : 0 : mac->clear_rar = ngbe_clear_rar;
2049 : 0 : mac->init_rx_addrs = ngbe_init_rx_addrs;
2050 : 0 : mac->update_mc_addr_list = ngbe_update_mc_addr_list;
2051 : 0 : mac->set_vmdq = ngbe_set_vmdq;
2052 : 0 : mac->clear_vmdq = ngbe_clear_vmdq;
2053 : 0 : mac->set_vfta = ngbe_set_vfta;
2054 : 0 : mac->set_vlvf = ngbe_set_vlvf;
2055 : 0 : mac->clear_vfta = ngbe_clear_vfta;
2056 : 0 : mac->set_mac_anti_spoofing = ngbe_set_mac_anti_spoofing;
2057 : 0 : mac->set_vlan_anti_spoofing = ngbe_set_vlan_anti_spoofing;
2058 : :
2059 : : /* Flow Control */
2060 : 0 : mac->fc_enable = ngbe_fc_enable;
2061 : 0 : mac->fc_autoneg = ngbe_fc_autoneg;
2062 : 0 : mac->setup_fc = ngbe_setup_fc_em;
2063 : :
2064 : : /* Link */
2065 : 0 : mac->get_link_capabilities = ngbe_get_link_capabilities_em;
2066 : 0 : mac->check_link = ngbe_check_mac_link_em;
2067 : 0 : mac->setup_link = ngbe_setup_mac_link_em;
2068 : :
2069 : 0 : mac->setup_pba = ngbe_set_pba;
2070 : :
2071 : : /* Manageability interface */
2072 : 0 : mac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;
2073 : 0 : mac->check_overtemp = ngbe_mac_check_overtemp;
2074 : :
2075 : 0 : mbx->init_params = ngbe_init_mbx_params_pf;
2076 : 0 : mbx->read = ngbe_read_mbx_pf;
2077 : 0 : mbx->write = ngbe_write_mbx_pf;
2078 : 0 : mbx->check_for_msg = ngbe_check_for_msg_pf;
2079 : 0 : mbx->check_for_ack = ngbe_check_for_ack_pf;
2080 : 0 : mbx->check_for_rst = ngbe_check_for_rst_pf;
2081 : :
2082 : : /* EEPROM */
2083 : 0 : rom->init_params = ngbe_init_eeprom_params;
2084 : 0 : rom->readw_buffer = ngbe_ee_readw_buffer;
2085 : 0 : rom->read32 = ngbe_ee_read32;
2086 : 0 : rom->writew_buffer = ngbe_ee_writew_buffer;
2087 : 0 : rom->validate_checksum = ngbe_validate_eeprom_checksum_em;
2088 : :
2089 : 0 : mac->mcft_size = NGBE_EM_MC_TBL_SIZE;
2090 : 0 : mac->vft_size = NGBE_EM_VFT_TBL_SIZE;
2091 : 0 : mac->num_rar_entries = NGBE_EM_RAR_ENTRIES;
2092 : 0 : mac->rx_pb_size = NGBE_EM_RX_PB_SIZE;
2093 : 0 : mac->max_rx_queues = NGBE_EM_MAX_RX_QUEUES;
2094 : 0 : mac->max_tx_queues = NGBE_EM_MAX_TX_QUEUES;
2095 : :
2096 : 0 : mac->default_speeds = NGBE_LINK_SPEED_10M_FULL |
2097 : : NGBE_LINK_SPEED_100M_FULL |
2098 : : NGBE_LINK_SPEED_1GB_FULL;
2099 : :
2100 : 0 : return 0;
2101 : : }
2102 : :
2103 : : /**
2104 : : * ngbe_init_shared_code - Initialize the shared code
2105 : : * @hw: pointer to hardware structure
2106 : : *
2107 : : * This will assign function pointers and assign the MAC type and PHY code.
2108 : : * Does not touch the hardware. This function must be called prior to any
2109 : : * other function in the shared code. The ngbe_hw structure should be
2110 : : * memset to 0 prior to calling this function. The following fields in
2111 : : * hw structure should be filled in prior to calling this function:
2112 : : * hw_addr, back, device_id, vendor_id, subsystem_device_id
2113 : : **/
2114 : 0 : s32 ngbe_init_shared_code(struct ngbe_hw *hw)
2115 : : {
2116 : : s32 status = 0;
2117 : :
2118 : : /*
2119 : : * Set the mac type
2120 : : */
2121 : 0 : ngbe_set_mac_type(hw);
2122 : :
2123 : 0 : ngbe_init_ops_dummy(hw);
2124 [ # # # ]: 0 : switch (hw->mac.type) {
2125 : 0 : case ngbe_mac_em:
2126 : 0 : ngbe_init_ops_pf(hw);
2127 : 0 : break;
2128 : 0 : case ngbe_mac_em_vf:
2129 : 0 : ngbe_init_ops_vf(hw);
2130 : 0 : break;
2131 : : default:
2132 : : status = NGBE_ERR_DEVICE_NOT_SUPPORTED;
2133 : : break;
2134 : : }
2135 : 0 : hw->mac.max_link_up_time = NGBE_LINK_UP_TIME;
2136 : :
2137 : 0 : hw->bus.set_lan_id(hw);
2138 : :
2139 : 0 : return status;
2140 : : }
2141 : :
2142 : 0 : void ngbe_set_ncsi_status(struct ngbe_hw *hw)
2143 : : {
2144 : 0 : u16 ncsi_pin = 0;
2145 : : s32 err = 0;
2146 : :
2147 : : /* need to check ncsi pin status for oem ncsi card */
2148 [ # # ]: 0 : if (hw->ncsi_enabled || hw->wol_enabled)
2149 : 0 : return;
2150 : :
2151 : 0 : err = hw->rom.readw_buffer(hw, FW_READ_SHADOW_RAM_GPIO, 1, &ncsi_pin);
2152 [ # # ]: 0 : if (err) {
2153 : 0 : DEBUGOUT("get ncsi pin status failed");
2154 : 0 : return;
2155 : : }
2156 : :
2157 [ # # ]: 0 : if (ncsi_pin == 1) {
2158 : 0 : hw->ncsi_enabled = true;
2159 : 0 : hw->wol_enabled = true;
2160 : : }
2161 : : }
|