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;
36 * txgbe_init_shared_code - Initialize the shared code
37 * @hw: pointer to hardware structure
39 * This will assign function pointers and assign the MAC type and PHY code.
40 * Does not touch the hardware. This function must be called prior to any
41 * other function in the shared code. The txgbe_hw structure should be
42 * memset to 0 prior to calling this function. The following fields in
43 * hw structure should be filled in prior to calling this function:
44 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
45 * subsystem_vendor_id, and revision_id
47 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
51 DEBUGFUNC("txgbe_init_shared_code");
56 txgbe_set_mac_type(hw);
58 txgbe_init_ops_dummy(hw);
59 switch (hw->mac.type) {
60 case txgbe_mac_raptor:
61 status = txgbe_init_ops_pf(hw);
64 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
67 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
69 hw->bus.set_lan_id(hw);
75 * txgbe_set_mac_type - Sets MAC type
76 * @hw: pointer to the HW structure
78 * This function sets the mac type of the adapter based on the
79 * vendor ID and device ID stored in the hw structure.
81 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
85 DEBUGFUNC("txgbe_set_mac_type");
87 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
88 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
89 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
92 switch (hw->device_id) {
93 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
94 hw->phy.media_type = txgbe_media_type_backplane;
95 hw->mac.type = txgbe_mac_raptor;
97 case TXGBE_DEV_ID_RAPTOR_XAUI:
98 case TXGBE_DEV_ID_RAPTOR_SGMII:
99 hw->phy.media_type = txgbe_media_type_copper;
100 hw->mac.type = txgbe_mac_raptor;
102 case TXGBE_DEV_ID_RAPTOR_SFP:
103 case TXGBE_DEV_ID_WX1820_SFP:
104 hw->phy.media_type = txgbe_media_type_fiber;
105 hw->mac.type = txgbe_mac_raptor;
107 case TXGBE_DEV_ID_RAPTOR_QSFP:
108 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
109 hw->mac.type = txgbe_mac_raptor;
111 case TXGBE_DEV_ID_RAPTOR_VF:
112 case TXGBE_DEV_ID_RAPTOR_VF_HV:
113 hw->phy.media_type = txgbe_media_type_virtual;
114 hw->mac.type = txgbe_mac_raptor_vf;
117 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
118 DEBUGOUT("Unsupported device id: %x", hw->device_id);
122 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
123 hw->mac.type, hw->phy.media_type, err);
128 * txgbe_init_ops_pf - Inits func ptrs and MAC type
129 * @hw: pointer to hardware structure
131 * Initialize the function pointers and assign the MAC type.
132 * Does not touch the hardware.
134 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
136 struct txgbe_bus_info *bus = &hw->bus;
137 struct txgbe_mac_info *mac = &hw->mac;
139 DEBUGFUNC("txgbe_init_ops_pf");
142 bus->set_lan_id = txgbe_set_lan_id_multi_port;
144 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;