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