1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
10 * ngbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
11 * @hw: pointer to the HW structure
13 * Determines the LAN function id by reading memory-mapped registers and swaps
14 * the port value if requested, and set MAC instance for devices.
16 void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
18 struct ngbe_bus_info *bus = &hw->bus;
21 DEBUGFUNC("ngbe_set_lan_id_multi_port");
23 reg = rd32(hw, NGBE_PORTSTAT);
24 bus->lan_id = NGBE_PORTSTAT_ID(reg);
25 bus->func = bus->lan_id;
29 * ngbe_set_mac_type - Sets MAC type
30 * @hw: pointer to the HW structure
32 * This function sets the mac type of the adapter based on the
33 * vendor ID and device ID stored in the hw structure.
35 s32 ngbe_set_mac_type(struct ngbe_hw *hw)
39 DEBUGFUNC("ngbe_set_mac_type");
41 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
42 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
43 return NGBE_ERR_DEVICE_NOT_SUPPORTED;
46 switch (hw->sub_device_id) {
47 case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
48 case NGBE_SUB_DEV_ID_EM_MVL_RGMII:
49 hw->phy.media_type = ngbe_media_type_copper;
50 hw->mac.type = ngbe_mac_em;
52 case NGBE_SUB_DEV_ID_EM_MVL_SFP:
53 case NGBE_SUB_DEV_ID_EM_YT8521S_SFP:
54 hw->phy.media_type = ngbe_media_type_fiber;
55 hw->mac.type = ngbe_mac_em;
57 case NGBE_SUB_DEV_ID_EM_VF:
58 hw->phy.media_type = ngbe_media_type_virtual;
59 hw->mac.type = ngbe_mac_em_vf;
62 err = NGBE_ERR_DEVICE_NOT_SUPPORTED;
63 hw->phy.media_type = ngbe_media_type_unknown;
64 hw->mac.type = ngbe_mac_unknown;
65 DEBUGOUT("Unsupported device id: %x", hw->device_id);
69 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
70 hw->mac.type, hw->phy.media_type, err);
74 void ngbe_map_device_id(struct ngbe_hw *hw)
76 u16 oem = hw->sub_system_id & NGBE_OEM_MASK;
77 u16 internal = hw->sub_system_id & NGBE_INTERNAL_MASK;
80 /* move subsystem_device_id to device_id */
81 switch (hw->device_id) {
82 case NGBE_DEV_ID_EM_WX1860AL_W_VF:
83 case NGBE_DEV_ID_EM_WX1860A2_VF:
84 case NGBE_DEV_ID_EM_WX1860A2S_VF:
85 case NGBE_DEV_ID_EM_WX1860A4_VF:
86 case NGBE_DEV_ID_EM_WX1860A4S_VF:
87 case NGBE_DEV_ID_EM_WX1860AL2_VF:
88 case NGBE_DEV_ID_EM_WX1860AL2S_VF:
89 case NGBE_DEV_ID_EM_WX1860AL4_VF:
90 case NGBE_DEV_ID_EM_WX1860AL4S_VF:
91 case NGBE_DEV_ID_EM_WX1860NCSI_VF:
92 case NGBE_DEV_ID_EM_WX1860A1_VF:
93 case NGBE_DEV_ID_EM_WX1860A1L_VF:
94 hw->device_id = NGBE_DEV_ID_EM_VF;
95 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_VF;
98 case NGBE_DEV_ID_EM_WX1860AL_W:
99 case NGBE_DEV_ID_EM_WX1860A2:
100 case NGBE_DEV_ID_EM_WX1860A2S:
101 case NGBE_DEV_ID_EM_WX1860A4:
102 case NGBE_DEV_ID_EM_WX1860A4S:
103 case NGBE_DEV_ID_EM_WX1860AL2:
104 case NGBE_DEV_ID_EM_WX1860AL2S:
105 case NGBE_DEV_ID_EM_WX1860AL4:
106 case NGBE_DEV_ID_EM_WX1860AL4S:
107 case NGBE_DEV_ID_EM_WX1860NCSI:
108 case NGBE_DEV_ID_EM_WX1860A1:
109 case NGBE_DEV_ID_EM_WX1860A1L:
110 hw->device_id = NGBE_DEV_ID_EM;
111 if (oem == NGBE_LY_M88E1512_SFP ||
112 internal == NGBE_INTERNAL_SFP)
113 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_SFP;
114 else if (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45)
115 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_RGMII;
116 else if (oem == NGBE_YT8521S_SFP ||
117 oem == NGBE_LY_YT8521S_SFP)
118 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_YT8521S_SFP;
120 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_SGMII;
128 * ngbe_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 ngbe_init_ops_pf(struct ngbe_hw *hw)
136 struct ngbe_bus_info *bus = &hw->bus;
138 DEBUGFUNC("ngbe_init_ops_pf");
141 bus->set_lan_id = ngbe_set_lan_id_multi_port;
147 * ngbe_init_shared_code - Initialize the shared code
148 * @hw: pointer to hardware structure
150 * This will assign function pointers and assign the MAC type and PHY code.
151 * Does not touch the hardware. This function must be called prior to any
152 * other function in the shared code. The ngbe_hw structure should be
153 * memset to 0 prior to calling this function. The following fields in
154 * hw structure should be filled in prior to calling this function:
155 * hw_addr, back, device_id, vendor_id, subsystem_device_id
157 s32 ngbe_init_shared_code(struct ngbe_hw *hw)
161 DEBUGFUNC("ngbe_init_shared_code");
166 ngbe_set_mac_type(hw);
168 ngbe_init_ops_dummy(hw);
169 switch (hw->mac.type) {
171 ngbe_init_ops_pf(hw);
174 status = NGBE_ERR_DEVICE_NOT_SUPPORTED;
178 hw->bus.set_lan_id(hw);