1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
5 #include "txgbe_type.h"
8 #define TXGBE_RAPTOR_RAR_ENTRIES 128
11 * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
12 * @hw: pointer to the HW structure
14 * Determines the LAN function id by reading memory-mapped registers and swaps
15 * the port value if requested, and set MAC instance for devices.
17 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
19 struct txgbe_bus_info *bus = &hw->bus;
22 DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie");
24 reg = rd32(hw, TXGBE_PORTSTAT);
25 bus->lan_id = TXGBE_PORTSTAT_ID(reg);
27 /* check for single port */
28 reg = rd32(hw, TXGBE_PWR);
29 if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
32 bus->func = bus->lan_id;
35 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
39 DEBUGFUNC("txgbe_init_shared_code");
44 txgbe_set_mac_type(hw);
46 switch (hw->mac.type) {
47 case txgbe_mac_raptor:
48 status = txgbe_init_ops_pf(hw);
51 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
54 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
56 hw->bus.set_lan_id(hw);
62 * txgbe_set_mac_type - Sets MAC type
63 * @hw: pointer to the HW structure
65 * This function sets the mac type of the adapter based on the
66 * vendor ID and device ID stored in the hw structure.
68 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
72 DEBUGFUNC("txgbe_set_mac_type");
74 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
75 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
76 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
79 switch (hw->device_id) {
80 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
81 hw->phy.media_type = txgbe_media_type_backplane;
82 hw->mac.type = txgbe_mac_raptor;
84 case TXGBE_DEV_ID_RAPTOR_XAUI:
85 case TXGBE_DEV_ID_RAPTOR_SGMII:
86 hw->phy.media_type = txgbe_media_type_copper;
87 hw->mac.type = txgbe_mac_raptor;
89 case TXGBE_DEV_ID_RAPTOR_SFP:
90 case TXGBE_DEV_ID_WX1820_SFP:
91 hw->phy.media_type = txgbe_media_type_fiber;
92 hw->mac.type = txgbe_mac_raptor;
94 case TXGBE_DEV_ID_RAPTOR_QSFP:
95 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
96 hw->mac.type = txgbe_mac_raptor;
98 case TXGBE_DEV_ID_RAPTOR_VF:
99 case TXGBE_DEV_ID_RAPTOR_VF_HV:
100 hw->phy.media_type = txgbe_media_type_virtual;
101 hw->mac.type = txgbe_mac_raptor_vf;
104 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
105 DEBUGOUT("Unsupported device id: %x", hw->device_id);
109 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
110 hw->mac.type, hw->phy.media_type, err);
115 * txgbe_init_ops_pf - Inits func ptrs and MAC type
116 * @hw: pointer to hardware structure
118 * Initialize the function pointers and assign the MAC type.
119 * Does not touch the hardware.
121 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
123 struct txgbe_bus_info *bus = &hw->bus;
124 struct txgbe_mac_info *mac = &hw->mac;
126 DEBUGFUNC("txgbe_init_ops_pf");
129 bus->set_lan_id = txgbe_set_lan_id_multi_port;
131 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;