1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
6 * 82542 Gigabit Ethernet Controller
11 STATIC s32 e1000_init_phy_params_82542(struct e1000_hw *hw);
12 STATIC s32 e1000_init_nvm_params_82542(struct e1000_hw *hw);
13 STATIC s32 e1000_init_mac_params_82542(struct e1000_hw *hw);
14 STATIC s32 e1000_get_bus_info_82542(struct e1000_hw *hw);
15 STATIC s32 e1000_reset_hw_82542(struct e1000_hw *hw);
16 STATIC s32 e1000_init_hw_82542(struct e1000_hw *hw);
17 STATIC s32 e1000_setup_link_82542(struct e1000_hw *hw);
18 STATIC s32 e1000_led_on_82542(struct e1000_hw *hw);
19 STATIC s32 e1000_led_off_82542(struct e1000_hw *hw);
20 STATIC int e1000_rar_set_82542(struct e1000_hw *hw, u8 *addr, u32 index);
21 STATIC void e1000_clear_hw_cntrs_82542(struct e1000_hw *hw);
22 STATIC s32 e1000_read_mac_addr_82542(struct e1000_hw *hw);
25 * e1000_init_phy_params_82542 - Init PHY func ptrs.
26 * @hw: pointer to the HW structure
28 STATIC s32 e1000_init_phy_params_82542(struct e1000_hw *hw)
30 struct e1000_phy_info *phy = &hw->phy;
31 s32 ret_val = E1000_SUCCESS;
33 DEBUGFUNC("e1000_init_phy_params_82542");
35 phy->type = e1000_phy_none;
41 * e1000_init_nvm_params_82542 - Init NVM func ptrs.
42 * @hw: pointer to the HW structure
44 STATIC s32 e1000_init_nvm_params_82542(struct e1000_hw *hw)
46 struct e1000_nvm_info *nvm = &hw->nvm;
48 DEBUGFUNC("e1000_init_nvm_params_82542");
50 nvm->address_bits = 6;
53 nvm->type = e1000_nvm_eeprom_microwire;
56 /* Function Pointers */
57 nvm->ops.read = e1000_read_nvm_microwire;
58 nvm->ops.release = e1000_stop_nvm;
59 nvm->ops.write = e1000_write_nvm_microwire;
60 nvm->ops.update = e1000_update_nvm_checksum_generic;
61 nvm->ops.validate = e1000_validate_nvm_checksum_generic;
67 * e1000_init_mac_params_82542 - Init MAC func ptrs.
68 * @hw: pointer to the HW structure
70 STATIC s32 e1000_init_mac_params_82542(struct e1000_hw *hw)
72 struct e1000_mac_info *mac = &hw->mac;
74 DEBUGFUNC("e1000_init_mac_params_82542");
77 hw->phy.media_type = e1000_media_type_fiber;
79 /* Set mta register count */
80 mac->mta_reg_count = 128;
81 /* Set rar entry count */
82 mac->rar_entry_count = E1000_RAR_ENTRIES;
84 /* Function pointers */
86 /* bus type/speed/width */
87 mac->ops.get_bus_info = e1000_get_bus_info_82542;
89 mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pci;
91 mac->ops.reset_hw = e1000_reset_hw_82542;
92 /* hw initialization */
93 mac->ops.init_hw = e1000_init_hw_82542;
95 mac->ops.setup_link = e1000_setup_link_82542;
96 /* phy/fiber/serdes setup */
97 mac->ops.setup_physical_interface =
98 e1000_setup_fiber_serdes_link_generic;
100 mac->ops.check_for_link = e1000_check_for_fiber_link_generic;
101 /* multicast address update */
102 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
104 mac->ops.write_vfta = e1000_write_vfta_generic;
106 mac->ops.clear_vfta = e1000_clear_vfta_generic;
107 /* read mac address */
108 mac->ops.read_mac_addr = e1000_read_mac_addr_82542;
110 mac->ops.rar_set = e1000_rar_set_82542;
111 /* turn on/off LED */
112 mac->ops.led_on = e1000_led_on_82542;
113 mac->ops.led_off = e1000_led_off_82542;
114 /* clear hardware counters */
115 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82542;
117 mac->ops.get_link_up_info =
118 e1000_get_speed_and_duplex_fiber_serdes_generic;
120 return E1000_SUCCESS;
124 * e1000_init_function_pointers_82542 - Init func ptrs.
125 * @hw: pointer to the HW structure
127 * Called to initialize all function pointers and parameters.
129 void e1000_init_function_pointers_82542(struct e1000_hw *hw)
131 DEBUGFUNC("e1000_init_function_pointers_82542");
133 hw->mac.ops.init_params = e1000_init_mac_params_82542;
134 hw->nvm.ops.init_params = e1000_init_nvm_params_82542;
135 hw->phy.ops.init_params = e1000_init_phy_params_82542;
139 * e1000_get_bus_info_82542 - Obtain bus information for adapter
140 * @hw: pointer to the HW structure
142 * This will obtain information about the HW bus for which the
143 * adapter is attached and stores it in the hw structure.
145 STATIC s32 e1000_get_bus_info_82542(struct e1000_hw *hw)
147 DEBUGFUNC("e1000_get_bus_info_82542");
149 hw->bus.type = e1000_bus_type_pci;
150 hw->bus.speed = e1000_bus_speed_unknown;
151 hw->bus.width = e1000_bus_width_unknown;
153 return E1000_SUCCESS;
157 * e1000_reset_hw_82542 - Reset hardware
158 * @hw: pointer to the HW structure
160 * This resets the hardware into a known state.
162 STATIC s32 e1000_reset_hw_82542(struct e1000_hw *hw)
164 struct e1000_bus_info *bus = &hw->bus;
165 s32 ret_val = E1000_SUCCESS;
168 DEBUGFUNC("e1000_reset_hw_82542");
170 if (hw->revision_id == E1000_REVISION_2) {
171 DEBUGOUT("Disabling MWI on 82542 rev 2\n");
172 e1000_pci_clear_mwi(hw);
175 DEBUGOUT("Masking off all interrupts\n");
176 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
178 E1000_WRITE_REG(hw, E1000_RCTL, 0);
179 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
180 E1000_WRITE_FLUSH(hw);
183 * Delay to allow any outstanding PCI transactions to complete before
184 * resetting the device
188 ctrl = E1000_READ_REG(hw, E1000_CTRL);
190 DEBUGOUT("Issuing a global reset to 82542/82543 MAC\n");
191 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
193 hw->nvm.ops.reload(hw);
196 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
197 E1000_READ_REG(hw, E1000_ICR);
199 if (hw->revision_id == E1000_REVISION_2) {
200 if (bus->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
201 e1000_pci_set_mwi(hw);
208 * e1000_init_hw_82542 - Initialize hardware
209 * @hw: pointer to the HW structure
211 * This inits the hardware readying it for operation.
213 STATIC s32 e1000_init_hw_82542(struct e1000_hw *hw)
215 struct e1000_mac_info *mac = &hw->mac;
216 struct e1000_dev_spec_82542 *dev_spec = &hw->dev_spec._82542;
217 s32 ret_val = E1000_SUCCESS;
221 DEBUGFUNC("e1000_init_hw_82542");
223 /* Disabling VLAN filtering */
224 E1000_WRITE_REG(hw, E1000_VET, 0);
225 mac->ops.clear_vfta(hw);
227 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
228 if (hw->revision_id == E1000_REVISION_2) {
229 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
230 e1000_pci_clear_mwi(hw);
231 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST);
232 E1000_WRITE_FLUSH(hw);
236 /* Setup the receive address. */
237 e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
239 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
240 if (hw->revision_id == E1000_REVISION_2) {
241 E1000_WRITE_REG(hw, E1000_RCTL, 0);
242 E1000_WRITE_FLUSH(hw);
244 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
245 e1000_pci_set_mwi(hw);
248 /* Zero out the Multicast HASH table */
249 DEBUGOUT("Zeroing the MTA\n");
250 for (i = 0; i < mac->mta_reg_count; i++)
251 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
254 * Set the PCI priority bit correctly in the CTRL register. This
255 * determines if the adapter gives priority to receives, or if it
256 * gives equal priority to transmits and receives.
258 if (dev_spec->dma_fairness) {
259 ctrl = E1000_READ_REG(hw, E1000_CTRL);
260 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PRIOR);
263 /* Setup link and flow control */
264 ret_val = e1000_setup_link_82542(hw);
267 * Clear all of the statistics registers (clear on read). It is
268 * important that we do this after we have tried to establish link
269 * because the symbol error count will increment wildly if there
272 e1000_clear_hw_cntrs_82542(hw);
278 * e1000_setup_link_82542 - Setup flow control and link settings
279 * @hw: pointer to the HW structure
281 * Determines which flow control settings to use, then configures flow
282 * control. Calls the appropriate media-specific link configuration
283 * function. Assuming the adapter has a valid link partner, a valid link
284 * should be established. Assumes the hardware has previously been reset
285 * and the transmitter and receiver are not enabled.
287 STATIC s32 e1000_setup_link_82542(struct e1000_hw *hw)
289 struct e1000_mac_info *mac = &hw->mac;
292 DEBUGFUNC("e1000_setup_link_82542");
294 ret_val = e1000_set_default_fc_generic(hw);
298 hw->fc.requested_mode &= ~e1000_fc_tx_pause;
300 if (mac->report_tx_early)
301 hw->fc.requested_mode &= ~e1000_fc_rx_pause;
304 * Save off the requested flow control mode for use later. Depending
305 * on the link partner's capabilities, we may or may not use this mode.
307 hw->fc.current_mode = hw->fc.requested_mode;
309 DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
310 hw->fc.current_mode);
312 /* Call the necessary subroutine to configure the link. */
313 ret_val = mac->ops.setup_physical_interface(hw);
318 * Initialize the flow control address, type, and PAUSE timer
319 * registers to their default values. This is done even if flow
320 * control is disabled, because it does not hurt anything to
321 * initialize these registers.
323 DEBUGOUT("Initializing Flow Control address, type and timer regs\n");
325 E1000_WRITE_REG(hw, E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
326 E1000_WRITE_REG(hw, E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
327 E1000_WRITE_REG(hw, E1000_FCT, FLOW_CONTROL_TYPE);
329 E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
331 ret_val = e1000_set_fc_watermarks_generic(hw);
338 * e1000_led_on_82542 - Turn on SW controllable LED
339 * @hw: pointer to the HW structure
341 * Turns the SW defined LED on.
343 STATIC s32 e1000_led_on_82542(struct e1000_hw *hw)
345 u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
347 DEBUGFUNC("e1000_led_on_82542");
349 ctrl |= E1000_CTRL_SWDPIN0;
350 ctrl |= E1000_CTRL_SWDPIO0;
351 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
353 return E1000_SUCCESS;
357 * e1000_led_off_82542 - Turn off SW controllable LED
358 * @hw: pointer to the HW structure
360 * Turns the SW defined LED off.
362 STATIC s32 e1000_led_off_82542(struct e1000_hw *hw)
364 u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
366 DEBUGFUNC("e1000_led_off_82542");
368 ctrl &= ~E1000_CTRL_SWDPIN0;
369 ctrl |= E1000_CTRL_SWDPIO0;
370 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
372 return E1000_SUCCESS;
376 * e1000_rar_set_82542 - Set receive address register
377 * @hw: pointer to the HW structure
378 * @addr: pointer to the receive address
379 * @index: receive address array register
381 * Sets the receive address array register at index to the address passed
384 STATIC int e1000_rar_set_82542(struct e1000_hw *hw, u8 *addr, u32 index)
386 u32 rar_low, rar_high;
388 DEBUGFUNC("e1000_rar_set_82542");
391 * HW expects these in little endian so we reverse the byte order
392 * from network order (big endian) to little endian
394 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
395 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
397 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
399 /* If MAC address zero, no need to set the AV bit */
400 if (rar_low || rar_high)
401 rar_high |= E1000_RAH_AV;
403 E1000_WRITE_REG_ARRAY(hw, E1000_RA, (index << 1), rar_low);
404 E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((index << 1) + 1), rar_high);
406 return E1000_SUCCESS;
410 * e1000_translate_register_82542 - Translate the proper register offset
411 * @reg: e1000 register to be read
413 * Registers in 82542 are located in different offsets than other adapters
414 * even though they function in the same manner. This function takes in
415 * the name of the register to read and returns the correct offset for
418 u32 e1000_translate_register_82542(u32 reg)
421 * Some of the 82542 registers are located at different
422 * offsets than they are in newer adapters.
423 * Despite the difference in location, the registers
424 * function in the same manner.
507 * e1000_clear_hw_cntrs_82542 - Clear device specific hardware counters
508 * @hw: pointer to the HW structure
510 * Clears the hardware counters by reading the counter registers.
512 STATIC void e1000_clear_hw_cntrs_82542(struct e1000_hw *hw)
514 DEBUGFUNC("e1000_clear_hw_cntrs_82542");
516 e1000_clear_hw_cntrs_base_generic(hw);
518 E1000_READ_REG(hw, E1000_PRC64);
519 E1000_READ_REG(hw, E1000_PRC127);
520 E1000_READ_REG(hw, E1000_PRC255);
521 E1000_READ_REG(hw, E1000_PRC511);
522 E1000_READ_REG(hw, E1000_PRC1023);
523 E1000_READ_REG(hw, E1000_PRC1522);
524 E1000_READ_REG(hw, E1000_PTC64);
525 E1000_READ_REG(hw, E1000_PTC127);
526 E1000_READ_REG(hw, E1000_PTC255);
527 E1000_READ_REG(hw, E1000_PTC511);
528 E1000_READ_REG(hw, E1000_PTC1023);
529 E1000_READ_REG(hw, E1000_PTC1522);
533 * e1000_read_mac_addr_82542 - Read device MAC address
534 * @hw: pointer to the HW structure
536 * Reads the device MAC address from the EEPROM and stores the value.
538 s32 e1000_read_mac_addr_82542(struct e1000_hw *hw)
540 s32 ret_val = E1000_SUCCESS;
541 u16 offset, nvm_data, i;
543 DEBUGFUNC("e1000_read_mac_addr");
545 for (i = 0; i < ETH_ADDR_LEN; i += 2) {
547 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
549 DEBUGOUT("NVM Read Error\n");
552 hw->mac.perm_addr[i] = (u8)(nvm_data & 0xFF);
553 hw->mac.perm_addr[i+1] = (u8)(nvm_data >> 8);
556 for (i = 0; i < ETH_ADDR_LEN; i++)
557 hw->mac.addr[i] = hw->mac.perm_addr[i];