1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
8 #include "ngbe_eeprom.h"
13 * ngbe_start_hw - Prepare hardware for Tx/Rx
14 * @hw: pointer to hardware structure
16 * Starts the hardware.
18 s32 ngbe_start_hw(struct ngbe_hw *hw)
20 DEBUGFUNC("ngbe_start_hw");
22 /* Clear adapter stopped flag */
23 hw->adapter_stopped = false;
29 * ngbe_init_hw - Generic hardware initialization
30 * @hw: pointer to hardware structure
32 * Initialize the hardware by resetting the hardware, filling the bus info
33 * structure and media type, clears all on chip counters, initializes receive
34 * address registers, multicast table, VLAN filter table, calls routine to set
35 * up link and flow control settings, and leaves transmit and receive units
36 * disabled and uninitialized
38 s32 ngbe_init_hw(struct ngbe_hw *hw)
42 DEBUGFUNC("ngbe_init_hw");
44 /* Reset the hardware */
45 status = hw->mac.reset_hw(hw);
48 status = hw->mac.start_hw(hw);
52 DEBUGOUT("Failed to initialize HW, STATUS = %d\n", status);
58 ngbe_reset_misc_em(struct ngbe_hw *hw)
62 wr32(hw, NGBE_ISBADDRL, hw->isb_dma & 0xFFFFFFFF);
63 wr32(hw, NGBE_ISBADDRH, hw->isb_dma >> 32);
65 /* receive packets that size > 2048 */
66 wr32m(hw, NGBE_MACRXCFG,
67 NGBE_MACRXCFG_JUMBO, NGBE_MACRXCFG_JUMBO);
69 wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
70 NGBE_FRMSZ_MAX(NGBE_FRAME_SIZE_DFT));
72 /* clear counters on read */
73 wr32m(hw, NGBE_MACCNTCTL,
74 NGBE_MACCNTCTL_RC, NGBE_MACCNTCTL_RC);
76 wr32m(hw, NGBE_RXFCCFG,
77 NGBE_RXFCCFG_FC, NGBE_RXFCCFG_FC);
78 wr32m(hw, NGBE_TXFCCFG,
79 NGBE_TXFCCFG_FC, NGBE_TXFCCFG_FC);
81 wr32m(hw, NGBE_MACRXFLT,
82 NGBE_MACRXFLT_PROMISC, NGBE_MACRXFLT_PROMISC);
84 wr32m(hw, NGBE_RSTSTAT,
85 NGBE_RSTSTAT_TMRINIT_MASK, NGBE_RSTSTAT_TMRINIT(30));
87 /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
88 wr32(hw, NGBE_MNGFLEXSEL, 0);
89 for (i = 0; i < 16; i++) {
90 wr32(hw, NGBE_MNGFLEXDWL(i), 0);
91 wr32(hw, NGBE_MNGFLEXDWH(i), 0);
92 wr32(hw, NGBE_MNGFLEXMSK(i), 0);
94 wr32(hw, NGBE_LANFLEXSEL, 0);
95 for (i = 0; i < 16; i++) {
96 wr32(hw, NGBE_LANFLEXDWL(i), 0);
97 wr32(hw, NGBE_LANFLEXDWH(i), 0);
98 wr32(hw, NGBE_LANFLEXMSK(i), 0);
101 /* set pause frame dst mac addr */
102 wr32(hw, NGBE_RXPBPFCDMACL, 0xC2000001);
103 wr32(hw, NGBE_RXPBPFCDMACH, 0x0180);
105 wr32(hw, NGBE_MDIOMODE, 0xF);
107 wr32m(hw, NGBE_GPIE, NGBE_GPIE_MSIX, NGBE_GPIE_MSIX);
109 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
110 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
111 /* gpio0 is used to power on/off control*/
112 wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
113 wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
116 hw->mac.init_thermal_sensor_thresh(hw);
118 /* enable mac transmitter */
119 wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_TE, NGBE_MACTXCFG_TE);
122 wr32m(hw, NGBE_MACTXCFG,
123 NGBE_MACTXCFG_SPEED_MASK, NGBE_MACTXCFG_SPEED_1G);
125 for (i = 0; i < 4; i++)
126 wr32m(hw, NGBE_IVAR(i), 0x80808080, 0);
130 * ngbe_reset_hw_em - Perform hardware reset
131 * @hw: pointer to hardware structure
133 * Resets the hardware by resetting the transmit and receive units, masks
134 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
137 s32 ngbe_reset_hw_em(struct ngbe_hw *hw)
141 DEBUGFUNC("ngbe_reset_hw_em");
143 /* Call adapter stop to disable tx/rx and clear interrupts */
144 status = hw->mac.stop_hw(hw);
148 /* Identify PHY and related function pointers */
149 status = ngbe_init_phy(hw);
154 if (!hw->phy.reset_disable)
155 hw->phy.reset_hw(hw);
157 wr32(hw, NGBE_RST, NGBE_RST_LAN(hw->bus.lan_id));
161 ngbe_reset_misc_em(hw);
165 /* Store the permanent mac address */
166 hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
169 * Store MAC address from RAR0, clear receive address registers, and
170 * clear the multicast table.
172 hw->mac.num_rar_entries = NGBE_EM_RAR_ENTRIES;
173 hw->mac.init_rx_addrs(hw);
179 * ngbe_get_mac_addr - Generic get MAC address
180 * @hw: pointer to hardware structure
181 * @mac_addr: Adapter MAC address
183 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
184 * A reset of the adapter must be performed prior to calling this function
185 * in order for the MAC address to have been loaded from the EEPROM into RAR0
187 s32 ngbe_get_mac_addr(struct ngbe_hw *hw, u8 *mac_addr)
193 DEBUGFUNC("ngbe_get_mac_addr");
195 wr32(hw, NGBE_ETHADDRIDX, 0);
196 rar_high = rd32(hw, NGBE_ETHADDRH);
197 rar_low = rd32(hw, NGBE_ETHADDRL);
199 for (i = 0; i < 2; i++)
200 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
202 for (i = 0; i < 4; i++)
203 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
209 * ngbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
210 * @hw: pointer to the HW structure
212 * Determines the LAN function id by reading memory-mapped registers and swaps
213 * the port value if requested, and set MAC instance for devices.
215 void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
217 struct ngbe_bus_info *bus = &hw->bus;
220 DEBUGFUNC("ngbe_set_lan_id_multi_port");
222 reg = rd32(hw, NGBE_PORTSTAT);
223 bus->lan_id = NGBE_PORTSTAT_ID(reg);
224 bus->func = bus->lan_id;
228 * ngbe_stop_hw - Generic stop Tx/Rx units
229 * @hw: pointer to hardware structure
231 * Sets the adapter_stopped flag within ngbe_hw struct. Clears interrupts,
232 * disables transmit and receive units. The adapter_stopped flag is used by
233 * the shared code and drivers to determine if the adapter is in a stopped
234 * state and should not touch the hardware.
236 s32 ngbe_stop_hw(struct ngbe_hw *hw)
241 DEBUGFUNC("ngbe_stop_hw");
244 * Set the adapter_stopped flag so other driver functions stop touching
247 hw->adapter_stopped = true;
249 /* Disable the receive unit */
252 /* Clear interrupt mask to stop interrupts from being generated */
253 wr32(hw, NGBE_IENMISC, 0);
254 wr32(hw, NGBE_IMS(0), NGBE_IMS_MASK);
256 /* Clear any pending interrupts, flush previous writes */
257 wr32(hw, NGBE_ICRMISC, NGBE_ICRMISC_MASK);
258 wr32(hw, NGBE_ICR(0), NGBE_ICR_MASK);
260 /* Disable the transmit unit. Each queue must be disabled. */
261 for (i = 0; i < hw->mac.max_tx_queues; i++)
262 wr32(hw, NGBE_TXCFG(i), NGBE_TXCFG_FLUSH);
264 /* Disable the receive unit by stopping each queue */
265 for (i = 0; i < hw->mac.max_rx_queues; i++) {
266 reg_val = rd32(hw, NGBE_RXCFG(i));
267 reg_val &= ~NGBE_RXCFG_ENA;
268 wr32(hw, NGBE_RXCFG(i), reg_val);
271 /* flush all queues disables */
279 * ngbe_validate_mac_addr - Validate MAC address
280 * @mac_addr: pointer to MAC address.
282 * Tests a MAC address to ensure it is a valid Individual Address.
284 s32 ngbe_validate_mac_addr(u8 *mac_addr)
288 DEBUGFUNC("ngbe_validate_mac_addr");
290 /* Make sure it is not a multicast address */
291 if (NGBE_IS_MULTICAST((struct rte_ether_addr *)mac_addr)) {
292 status = NGBE_ERR_INVALID_MAC_ADDR;
293 /* Not a broadcast address */
294 } else if (NGBE_IS_BROADCAST((struct rte_ether_addr *)mac_addr)) {
295 status = NGBE_ERR_INVALID_MAC_ADDR;
296 /* Reject the zero address */
297 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
298 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
299 status = NGBE_ERR_INVALID_MAC_ADDR;
305 * ngbe_set_rar - Set Rx address register
306 * @hw: pointer to hardware structure
307 * @index: Receive address register to write
308 * @addr: Address to put into receive address register
309 * @vmdq: VMDq "set" or "pool" index
310 * @enable_addr: set flag that address is active
312 * Puts an ethernet address into a receive address register.
314 s32 ngbe_set_rar(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
317 u32 rar_low, rar_high;
318 u32 rar_entries = hw->mac.num_rar_entries;
320 DEBUGFUNC("ngbe_set_rar");
322 /* Make sure we are using a valid rar index range */
323 if (index >= rar_entries) {
324 DEBUGOUT("RAR index %d is out of range.\n", index);
325 return NGBE_ERR_INVALID_ARGUMENT;
328 /* setup VMDq pool selection before this RAR gets enabled */
329 hw->mac.set_vmdq(hw, index, vmdq);
332 * HW expects these in little endian so we reverse the byte
333 * order from network order (big endian) to little endian
335 rar_low = NGBE_ETHADDRL_AD0(addr[5]) |
336 NGBE_ETHADDRL_AD1(addr[4]) |
337 NGBE_ETHADDRL_AD2(addr[3]) |
338 NGBE_ETHADDRL_AD3(addr[2]);
340 * Some parts put the VMDq setting in the extra RAH bits,
341 * so save everything except the lower 16 bits that hold part
342 * of the address and the address valid bit.
344 rar_high = rd32(hw, NGBE_ETHADDRH);
345 rar_high &= ~NGBE_ETHADDRH_AD_MASK;
346 rar_high |= (NGBE_ETHADDRH_AD4(addr[1]) |
347 NGBE_ETHADDRH_AD5(addr[0]));
349 rar_high &= ~NGBE_ETHADDRH_VLD;
350 if (enable_addr != 0)
351 rar_high |= NGBE_ETHADDRH_VLD;
353 wr32(hw, NGBE_ETHADDRIDX, index);
354 wr32(hw, NGBE_ETHADDRL, rar_low);
355 wr32(hw, NGBE_ETHADDRH, rar_high);
361 * ngbe_clear_rar - Remove Rx address register
362 * @hw: pointer to hardware structure
363 * @index: Receive address register to write
365 * Clears an ethernet address from a receive address register.
367 s32 ngbe_clear_rar(struct ngbe_hw *hw, u32 index)
370 u32 rar_entries = hw->mac.num_rar_entries;
372 DEBUGFUNC("ngbe_clear_rar");
374 /* Make sure we are using a valid rar index range */
375 if (index >= rar_entries) {
376 DEBUGOUT("RAR index %d is out of range.\n", index);
377 return NGBE_ERR_INVALID_ARGUMENT;
381 * Some parts put the VMDq setting in the extra RAH bits,
382 * so save everything except the lower 16 bits that hold part
383 * of the address and the address valid bit.
385 wr32(hw, NGBE_ETHADDRIDX, index);
386 rar_high = rd32(hw, NGBE_ETHADDRH);
387 rar_high &= ~(NGBE_ETHADDRH_AD_MASK | NGBE_ETHADDRH_VLD);
389 wr32(hw, NGBE_ETHADDRL, 0);
390 wr32(hw, NGBE_ETHADDRH, rar_high);
392 /* clear VMDq pool/queue selection for this RAR */
393 hw->mac.clear_vmdq(hw, index, BIT_MASK32);
399 * ngbe_init_rx_addrs - Initializes receive address filters.
400 * @hw: pointer to hardware structure
402 * Places the MAC address in receive address register 0 and clears the rest
403 * of the receive address registers. Clears the multicast table. Assumes
404 * the receiver is in reset when the routine is called.
406 s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
410 u32 rar_entries = hw->mac.num_rar_entries;
412 DEBUGFUNC("ngbe_init_rx_addrs");
415 * If the current mac address is valid, assume it is a software override
416 * to the permanent address.
417 * Otherwise, use the permanent address from the eeprom.
419 if (ngbe_validate_mac_addr(hw->mac.addr) ==
420 NGBE_ERR_INVALID_MAC_ADDR) {
421 /* Get the MAC address from the RAR0 for later reference */
422 hw->mac.get_mac_addr(hw, hw->mac.addr);
424 DEBUGOUT(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
425 hw->mac.addr[0], hw->mac.addr[1],
427 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
428 hw->mac.addr[4], hw->mac.addr[5]);
430 /* Setup the receive address. */
431 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
432 DEBUGOUT(" New MAC Addr =%.2X %.2X %.2X ",
433 hw->mac.addr[0], hw->mac.addr[1],
435 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
436 hw->mac.addr[4], hw->mac.addr[5]);
438 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
441 /* clear VMDq pool/queue selection for RAR 0 */
442 hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
444 /* Zero out the other receive addresses. */
445 DEBUGOUT("Clearing RAR[1-%d]\n", rar_entries - 1);
446 for (i = 1; i < rar_entries; i++) {
447 wr32(hw, NGBE_ETHADDRIDX, i);
448 wr32(hw, NGBE_ETHADDRL, 0);
449 wr32(hw, NGBE_ETHADDRH, 0);
453 hw->addr_ctrl.mta_in_use = 0;
454 psrctl = rd32(hw, NGBE_PSRCTL);
455 psrctl &= ~(NGBE_PSRCTL_ADHF12_MASK | NGBE_PSRCTL_MCHFENA);
456 psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
457 wr32(hw, NGBE_PSRCTL, psrctl);
459 DEBUGOUT(" Clearing MTA\n");
460 for (i = 0; i < hw->mac.mcft_size; i++)
461 wr32(hw, NGBE_MCADDRTBL(i), 0);
463 ngbe_init_uta_tables(hw);
469 * ngbe_acquire_swfw_sync - Acquire SWFW semaphore
470 * @hw: pointer to hardware structure
471 * @mask: Mask to specify which semaphore to acquire
473 * Acquires the SWFW semaphore through the MNGSEM register for the specified
474 * function (CSR, PHY0, PHY1, EEPROM, Flash)
476 s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask)
479 u32 swmask = NGBE_MNGSEM_SW(mask);
480 u32 fwmask = NGBE_MNGSEM_FW(mask);
484 DEBUGFUNC("ngbe_acquire_swfw_sync");
486 for (i = 0; i < timeout; i++) {
488 * SW NVM semaphore bit is used for access to all
489 * SW_FW_SYNC bits (not just NVM)
491 if (ngbe_get_eeprom_semaphore(hw))
492 return NGBE_ERR_SWFW_SYNC;
494 mngsem = rd32(hw, NGBE_MNGSEM);
495 if (mngsem & (fwmask | swmask)) {
496 /* Resource is currently in use by FW or SW */
497 ngbe_release_eeprom_semaphore(hw);
501 wr32(hw, NGBE_MNGSEM, mngsem);
502 ngbe_release_eeprom_semaphore(hw);
507 /* If time expired clear the bits holding the lock and retry */
508 if (mngsem & (fwmask | swmask))
509 ngbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
512 return NGBE_ERR_SWFW_SYNC;
516 * ngbe_release_swfw_sync - Release SWFW semaphore
517 * @hw: pointer to hardware structure
518 * @mask: Mask to specify which semaphore to release
520 * Releases the SWFW semaphore through the MNGSEM register for the specified
521 * function (CSR, PHY0, PHY1, EEPROM, Flash)
523 void ngbe_release_swfw_sync(struct ngbe_hw *hw, u32 mask)
528 DEBUGFUNC("ngbe_release_swfw_sync");
530 ngbe_get_eeprom_semaphore(hw);
532 mngsem = rd32(hw, NGBE_MNGSEM);
534 wr32(hw, NGBE_MNGSEM, mngsem);
536 ngbe_release_eeprom_semaphore(hw);
540 * ngbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
541 * @hw: pointer to hardware struct
542 * @rar: receive address register index to disassociate
543 * @vmdq: VMDq pool index to remove from the rar
545 s32 ngbe_clear_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
548 u32 rar_entries = hw->mac.num_rar_entries;
550 DEBUGFUNC("ngbe_clear_vmdq");
552 /* Make sure we are using a valid rar index range */
553 if (rar >= rar_entries) {
554 DEBUGOUT("RAR index %d is out of range.\n", rar);
555 return NGBE_ERR_INVALID_ARGUMENT;
558 wr32(hw, NGBE_ETHADDRIDX, rar);
559 mpsar = rd32(hw, NGBE_ETHADDRASS);
561 if (NGBE_REMOVED(hw->hw_addr))
567 mpsar &= ~(1 << vmdq);
568 wr32(hw, NGBE_ETHADDRASS, mpsar);
570 /* was that the last pool using this rar? */
571 if (mpsar == 0 && rar != 0)
572 hw->mac.clear_rar(hw, rar);
578 * ngbe_set_vmdq - Associate a VMDq pool index with a rx address
579 * @hw: pointer to hardware struct
580 * @rar: receive address register index to associate with a VMDq index
581 * @vmdq: VMDq pool index
583 s32 ngbe_set_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
586 u32 rar_entries = hw->mac.num_rar_entries;
588 DEBUGFUNC("ngbe_set_vmdq");
590 /* Make sure we are using a valid rar index range */
591 if (rar >= rar_entries) {
592 DEBUGOUT("RAR index %d is out of range.\n", rar);
593 return NGBE_ERR_INVALID_ARGUMENT;
596 wr32(hw, NGBE_ETHADDRIDX, rar);
598 mpsar = rd32(hw, NGBE_ETHADDRASS);
600 wr32(hw, NGBE_ETHADDRASS, mpsar);
606 * ngbe_init_uta_tables - Initialize the Unicast Table Array
607 * @hw: pointer to hardware structure
609 s32 ngbe_init_uta_tables(struct ngbe_hw *hw)
613 DEBUGFUNC("ngbe_init_uta_tables");
614 DEBUGOUT(" Clearing UTA\n");
616 for (i = 0; i < 128; i++)
617 wr32(hw, NGBE_UCADDRTBL(i), 0);
623 * ngbe_check_mac_link_em - Determine link and speed status
624 * @hw: pointer to hardware structure
625 * @speed: pointer to link speed
626 * @link_up: true when link is up
627 * @link_up_wait_to_complete: bool used to wait for link up or not
629 * Reads the links register to determine if link is up and the current speed
631 s32 ngbe_check_mac_link_em(struct ngbe_hw *hw, u32 *speed,
632 bool *link_up, bool link_up_wait_to_complete)
637 DEBUGFUNC("ngbe_check_mac_link_em");
639 reg = rd32(hw, NGBE_GPIOINTSTAT);
640 wr32(hw, NGBE_GPIOEOI, reg);
642 if (link_up_wait_to_complete) {
643 for (i = 0; i < hw->mac.max_link_up_time; i++) {
644 status = hw->phy.check_link(hw, speed, link_up);
650 status = hw->phy.check_link(hw, speed, link_up);
656 s32 ngbe_get_link_capabilities_em(struct ngbe_hw *hw,
664 hw->mac.autoneg = *autoneg;
666 switch (hw->sub_device_id) {
667 case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
668 *speed = NGBE_LINK_SPEED_1GB_FULL |
669 NGBE_LINK_SPEED_100M_FULL |
670 NGBE_LINK_SPEED_10M_FULL;
679 s32 ngbe_setup_mac_link_em(struct ngbe_hw *hw,
681 bool autoneg_wait_to_complete)
687 /* Setup the PHY according to input speed */
688 status = hw->phy.setup_link(hw, speed, autoneg_wait_to_complete);
694 * ngbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
695 * @hw: pointer to hardware structure
697 * Inits the thermal sensor thresholds according to the NVM map
698 * and save off the threshold and location values into mac.thermal_sensor_data
700 s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw)
702 struct ngbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
704 DEBUGFUNC("ngbe_init_thermal_sensor_thresh");
706 memset(data, 0, sizeof(struct ngbe_thermal_sensor_data));
708 if (hw->bus.lan_id != 0)
709 return NGBE_NOT_IMPLEMENTED;
711 wr32(hw, NGBE_TSINTR,
712 NGBE_TSINTR_AEN | NGBE_TSINTR_DEN);
713 wr32(hw, NGBE_TSEN, NGBE_TSEN_ENA);
716 data->sensor[0].alarm_thresh = 115;
717 wr32(hw, NGBE_TSATHRE, 0x344);
718 data->sensor[0].dalarm_thresh = 110;
719 wr32(hw, NGBE_TSDTHRE, 0x330);
724 s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw)
729 DEBUGFUNC("ngbe_mac_check_overtemp");
731 /* Check that the LASI temp alarm status was triggered */
732 ts_state = rd32(hw, NGBE_TSALM);
734 if (ts_state & NGBE_TSALM_HI)
735 status = NGBE_ERR_UNDERTEMP;
736 else if (ts_state & NGBE_TSALM_LO)
737 status = NGBE_ERR_OVERTEMP;
742 void ngbe_disable_rx(struct ngbe_hw *hw)
746 pfdtxgswc = rd32(hw, NGBE_PSRCTL);
747 if (pfdtxgswc & NGBE_PSRCTL_LBENA) {
748 pfdtxgswc &= ~NGBE_PSRCTL_LBENA;
749 wr32(hw, NGBE_PSRCTL, pfdtxgswc);
750 hw->mac.set_lben = true;
752 hw->mac.set_lben = false;
755 wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, 0);
756 wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, 0);
760 * ngbe_set_mac_type - Sets MAC type
761 * @hw: pointer to the HW structure
763 * This function sets the mac type of the adapter based on the
764 * vendor ID and device ID stored in the hw structure.
766 s32 ngbe_set_mac_type(struct ngbe_hw *hw)
770 DEBUGFUNC("ngbe_set_mac_type");
772 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
773 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
774 return NGBE_ERR_DEVICE_NOT_SUPPORTED;
777 switch (hw->sub_device_id) {
778 case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
779 case NGBE_SUB_DEV_ID_EM_MVL_RGMII:
780 hw->phy.media_type = ngbe_media_type_copper;
781 hw->mac.type = ngbe_mac_em;
783 case NGBE_SUB_DEV_ID_EM_MVL_SFP:
784 case NGBE_SUB_DEV_ID_EM_YT8521S_SFP:
785 hw->phy.media_type = ngbe_media_type_fiber;
786 hw->mac.type = ngbe_mac_em;
788 case NGBE_SUB_DEV_ID_EM_VF:
789 hw->phy.media_type = ngbe_media_type_virtual;
790 hw->mac.type = ngbe_mac_em_vf;
793 err = NGBE_ERR_DEVICE_NOT_SUPPORTED;
794 hw->phy.media_type = ngbe_media_type_unknown;
795 hw->mac.type = ngbe_mac_unknown;
796 DEBUGOUT("Unsupported device id: %x", hw->device_id);
800 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
801 hw->mac.type, hw->phy.media_type, err);
805 void ngbe_map_device_id(struct ngbe_hw *hw)
807 u16 oem = hw->sub_system_id & NGBE_OEM_MASK;
808 u16 internal = hw->sub_system_id & NGBE_INTERNAL_MASK;
811 /* move subsystem_device_id to device_id */
812 switch (hw->device_id) {
813 case NGBE_DEV_ID_EM_WX1860AL_W_VF:
814 case NGBE_DEV_ID_EM_WX1860A2_VF:
815 case NGBE_DEV_ID_EM_WX1860A2S_VF:
816 case NGBE_DEV_ID_EM_WX1860A4_VF:
817 case NGBE_DEV_ID_EM_WX1860A4S_VF:
818 case NGBE_DEV_ID_EM_WX1860AL2_VF:
819 case NGBE_DEV_ID_EM_WX1860AL2S_VF:
820 case NGBE_DEV_ID_EM_WX1860AL4_VF:
821 case NGBE_DEV_ID_EM_WX1860AL4S_VF:
822 case NGBE_DEV_ID_EM_WX1860NCSI_VF:
823 case NGBE_DEV_ID_EM_WX1860A1_VF:
824 case NGBE_DEV_ID_EM_WX1860A1L_VF:
825 hw->device_id = NGBE_DEV_ID_EM_VF;
826 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_VF;
829 case NGBE_DEV_ID_EM_WX1860AL_W:
830 case NGBE_DEV_ID_EM_WX1860A2:
831 case NGBE_DEV_ID_EM_WX1860A2S:
832 case NGBE_DEV_ID_EM_WX1860A4:
833 case NGBE_DEV_ID_EM_WX1860A4S:
834 case NGBE_DEV_ID_EM_WX1860AL2:
835 case NGBE_DEV_ID_EM_WX1860AL2S:
836 case NGBE_DEV_ID_EM_WX1860AL4:
837 case NGBE_DEV_ID_EM_WX1860AL4S:
838 case NGBE_DEV_ID_EM_WX1860NCSI:
839 case NGBE_DEV_ID_EM_WX1860A1:
840 case NGBE_DEV_ID_EM_WX1860A1L:
841 hw->device_id = NGBE_DEV_ID_EM;
842 if (oem == NGBE_LY_M88E1512_SFP ||
843 internal == NGBE_INTERNAL_SFP)
844 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_SFP;
845 else if (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45)
846 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_RGMII;
847 else if (oem == NGBE_YT8521S_SFP ||
848 oem == NGBE_LY_YT8521S_SFP)
849 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_YT8521S_SFP;
851 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_SGMII;
859 * ngbe_init_ops_pf - Inits func ptrs and MAC type
860 * @hw: pointer to hardware structure
862 * Initialize the function pointers and assign the MAC type.
863 * Does not touch the hardware.
865 s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
867 struct ngbe_bus_info *bus = &hw->bus;
868 struct ngbe_mac_info *mac = &hw->mac;
869 struct ngbe_phy_info *phy = &hw->phy;
870 struct ngbe_rom_info *rom = &hw->rom;
872 DEBUGFUNC("ngbe_init_ops_pf");
875 bus->set_lan_id = ngbe_set_lan_id_multi_port;
878 phy->identify = ngbe_identify_phy;
879 phy->read_reg = ngbe_read_phy_reg;
880 phy->write_reg = ngbe_write_phy_reg;
881 phy->read_reg_unlocked = ngbe_read_phy_reg_mdi;
882 phy->write_reg_unlocked = ngbe_write_phy_reg_mdi;
883 phy->reset_hw = ngbe_reset_phy;
886 mac->init_hw = ngbe_init_hw;
887 mac->reset_hw = ngbe_reset_hw_em;
888 mac->start_hw = ngbe_start_hw;
889 mac->get_mac_addr = ngbe_get_mac_addr;
890 mac->stop_hw = ngbe_stop_hw;
891 mac->acquire_swfw_sync = ngbe_acquire_swfw_sync;
892 mac->release_swfw_sync = ngbe_release_swfw_sync;
895 mac->set_rar = ngbe_set_rar;
896 mac->clear_rar = ngbe_clear_rar;
897 mac->init_rx_addrs = ngbe_init_rx_addrs;
898 mac->set_vmdq = ngbe_set_vmdq;
899 mac->clear_vmdq = ngbe_clear_vmdq;
902 mac->get_link_capabilities = ngbe_get_link_capabilities_em;
903 mac->check_link = ngbe_check_mac_link_em;
904 mac->setup_link = ngbe_setup_mac_link_em;
906 /* Manageability interface */
907 mac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;
908 mac->check_overtemp = ngbe_mac_check_overtemp;
911 rom->init_params = ngbe_init_eeprom_params;
912 rom->validate_checksum = ngbe_validate_eeprom_checksum_em;
914 mac->mcft_size = NGBE_EM_MC_TBL_SIZE;
915 mac->num_rar_entries = NGBE_EM_RAR_ENTRIES;
916 mac->max_rx_queues = NGBE_EM_MAX_RX_QUEUES;
917 mac->max_tx_queues = NGBE_EM_MAX_TX_QUEUES;
919 mac->default_speeds = NGBE_LINK_SPEED_10M_FULL |
920 NGBE_LINK_SPEED_100M_FULL |
921 NGBE_LINK_SPEED_1GB_FULL;
927 * ngbe_init_shared_code - Initialize the shared code
928 * @hw: pointer to hardware structure
930 * This will assign function pointers and assign the MAC type and PHY code.
931 * Does not touch the hardware. This function must be called prior to any
932 * other function in the shared code. The ngbe_hw structure should be
933 * memset to 0 prior to calling this function. The following fields in
934 * hw structure should be filled in prior to calling this function:
935 * hw_addr, back, device_id, vendor_id, subsystem_device_id
937 s32 ngbe_init_shared_code(struct ngbe_hw *hw)
941 DEBUGFUNC("ngbe_init_shared_code");
946 ngbe_set_mac_type(hw);
948 ngbe_init_ops_dummy(hw);
949 switch (hw->mac.type) {
951 ngbe_init_ops_pf(hw);
954 status = NGBE_ERR_DEVICE_NOT_SUPPORTED;
957 hw->mac.max_link_up_time = NGBE_LINK_UP_TIME;
959 hw->bus.set_lan_id(hw);