1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
5 #include "txgbe_type.h"
6 #include "txgbe_eeprom.h"
9 #define TXGBE_RAPTOR_RAR_ENTRIES 128
12 * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
13 * @hw: pointer to the HW structure
15 * Determines the LAN function id by reading memory-mapped registers and swaps
16 * the port value if requested, and set MAC instance for devices.
18 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
20 struct txgbe_bus_info *bus = &hw->bus;
23 DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie");
25 reg = rd32(hw, TXGBE_PORTSTAT);
26 bus->lan_id = TXGBE_PORTSTAT_ID(reg);
28 /* check for single port */
29 reg = rd32(hw, TXGBE_PWR);
30 if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
33 bus->func = bus->lan_id;
37 * txgbe_init_shared_code - Initialize the shared code
38 * @hw: pointer to hardware structure
40 * This will assign function pointers and assign the MAC type and PHY code.
41 * Does not touch the hardware. This function must be called prior to any
42 * other function in the shared code. The txgbe_hw structure should be
43 * memset to 0 prior to calling this function. The following fields in
44 * hw structure should be filled in prior to calling this function:
45 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
46 * subsystem_vendor_id, and revision_id
48 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
52 DEBUGFUNC("txgbe_init_shared_code");
57 txgbe_set_mac_type(hw);
59 txgbe_init_ops_dummy(hw);
60 switch (hw->mac.type) {
61 case txgbe_mac_raptor:
62 status = txgbe_init_ops_pf(hw);
65 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
68 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
70 hw->bus.set_lan_id(hw);
76 * txgbe_set_mac_type - Sets MAC type
77 * @hw: pointer to the HW structure
79 * This function sets the mac type of the adapter based on the
80 * vendor ID and device ID stored in the hw structure.
82 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
86 DEBUGFUNC("txgbe_set_mac_type");
88 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
89 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
90 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
93 switch (hw->device_id) {
94 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
95 hw->phy.media_type = txgbe_media_type_backplane;
96 hw->mac.type = txgbe_mac_raptor;
98 case TXGBE_DEV_ID_RAPTOR_XAUI:
99 case TXGBE_DEV_ID_RAPTOR_SGMII:
100 hw->phy.media_type = txgbe_media_type_copper;
101 hw->mac.type = txgbe_mac_raptor;
103 case TXGBE_DEV_ID_RAPTOR_SFP:
104 case TXGBE_DEV_ID_WX1820_SFP:
105 hw->phy.media_type = txgbe_media_type_fiber;
106 hw->mac.type = txgbe_mac_raptor;
108 case TXGBE_DEV_ID_RAPTOR_QSFP:
109 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
110 hw->mac.type = txgbe_mac_raptor;
112 case TXGBE_DEV_ID_RAPTOR_VF:
113 case TXGBE_DEV_ID_RAPTOR_VF_HV:
114 hw->phy.media_type = txgbe_media_type_virtual;
115 hw->mac.type = txgbe_mac_raptor_vf;
118 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
119 DEBUGOUT("Unsupported device id: %x", hw->device_id);
123 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
124 hw->mac.type, hw->phy.media_type, err);
129 * txgbe_init_ops_pf - Inits func ptrs and MAC type
130 * @hw: pointer to hardware structure
132 * Initialize the function pointers and assign the MAC type.
133 * Does not touch the hardware.
135 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
137 struct txgbe_bus_info *bus = &hw->bus;
138 struct txgbe_mac_info *mac = &hw->mac;
139 struct txgbe_rom_info *rom = &hw->rom;
141 DEBUGFUNC("txgbe_init_ops_pf");
144 bus->set_lan_id = txgbe_set_lan_id_multi_port;
147 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
150 rom->init_params = txgbe_init_eeprom_params;
151 rom->read16 = txgbe_ee_read16;
152 rom->readw_buffer = txgbe_ee_readw_buffer;
153 rom->readw_sw = txgbe_ee_readw_sw;
154 rom->read32 = txgbe_ee_read32;
155 rom->write16 = txgbe_ee_write16;
156 rom->writew_buffer = txgbe_ee_writew_buffer;
157 rom->writew_sw = txgbe_ee_writew_sw;
158 rom->write32 = txgbe_ee_write32;
159 rom->validate_checksum = txgbe_validate_eeprom_checksum;
160 rom->update_checksum = txgbe_update_eeprom_checksum;
161 rom->calc_checksum = txgbe_calc_eeprom_checksum;