1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2010 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * 82542 Gigabit Ethernet Controller
33 #include "e1000_api.h"
35 static s32
e1000_init_phy_params_82542(struct e1000_hw
*hw
);
36 static s32
e1000_init_nvm_params_82542(struct e1000_hw
*hw
);
37 static s32
e1000_init_mac_params_82542(struct e1000_hw
*hw
);
38 static s32
e1000_get_bus_info_82542(struct e1000_hw
*hw
);
39 static s32
e1000_reset_hw_82542(struct e1000_hw
*hw
);
40 static s32
e1000_init_hw_82542(struct e1000_hw
*hw
);
41 static s32
e1000_setup_link_82542(struct e1000_hw
*hw
);
42 static s32
e1000_led_on_82542(struct e1000_hw
*hw
);
43 static s32
e1000_led_off_82542(struct e1000_hw
*hw
);
44 static void e1000_rar_set_82542(struct e1000_hw
*hw
, u8
*addr
, u32 index
);
45 static void e1000_clear_hw_cntrs_82542(struct e1000_hw
*hw
);
46 static s32
e1000_read_mac_addr_82542(struct e1000_hw
*hw
);
49 * e1000_init_phy_params_82542 - Init PHY func ptrs.
50 * @hw: pointer to the HW structure
52 static s32
e1000_init_phy_params_82542(struct e1000_hw
*hw
)
54 struct e1000_phy_info
*phy
= &hw
->phy
;
55 s32 ret_val
= E1000_SUCCESS
;
57 DEBUGFUNC("e1000_init_phy_params_82542");
59 phy
->type
= e1000_phy_none
;
65 * e1000_init_nvm_params_82542 - Init NVM func ptrs.
66 * @hw: pointer to the HW structure
68 static s32
e1000_init_nvm_params_82542(struct e1000_hw
*hw
)
70 struct e1000_nvm_info
*nvm
= &hw
->nvm
;
72 DEBUGFUNC("e1000_init_nvm_params_82542");
74 nvm
->address_bits
= 6;
77 nvm
->type
= e1000_nvm_eeprom_microwire
;
80 /* Function Pointers */
81 nvm
->ops
.read
= e1000_read_nvm_microwire
;
82 nvm
->ops
.release
= e1000_stop_nvm
;
83 nvm
->ops
.write
= e1000_write_nvm_microwire
;
84 nvm
->ops
.update
= e1000_update_nvm_checksum_generic
;
85 nvm
->ops
.validate
= e1000_validate_nvm_checksum_generic
;
91 * e1000_init_mac_params_82542 - Init MAC func ptrs.
92 * @hw: pointer to the HW structure
94 static s32
e1000_init_mac_params_82542(struct e1000_hw
*hw
)
96 struct e1000_mac_info
*mac
= &hw
->mac
;
98 DEBUGFUNC("e1000_init_mac_params_82542");
101 hw
->phy
.media_type
= e1000_media_type_fiber
;
103 /* Set mta register count */
104 mac
->mta_reg_count
= 128;
105 /* Set rar entry count */
106 mac
->rar_entry_count
= E1000_RAR_ENTRIES
;
108 /* Function pointers */
110 /* bus type/speed/width */
111 mac
->ops
.get_bus_info
= e1000_get_bus_info_82542
;
113 mac
->ops
.set_lan_id
= e1000_set_lan_id_multi_port_pci
;
115 mac
->ops
.reset_hw
= e1000_reset_hw_82542
;
116 /* hw initialization */
117 mac
->ops
.init_hw
= e1000_init_hw_82542
;
119 mac
->ops
.setup_link
= e1000_setup_link_82542
;
120 /* phy/fiber/serdes setup */
121 mac
->ops
.setup_physical_interface
= e1000_setup_fiber_serdes_link_generic
;
123 mac
->ops
.check_for_link
= e1000_check_for_fiber_link_generic
;
124 /* multicast address update */
125 mac
->ops
.update_mc_addr_list
= e1000_update_mc_addr_list_generic
;
127 mac
->ops
.write_vfta
= e1000_write_vfta_generic
;
129 mac
->ops
.clear_vfta
= e1000_clear_vfta_generic
;
130 /* read mac address */
131 mac
->ops
.read_mac_addr
= e1000_read_mac_addr_82542
;
133 mac
->ops
.rar_set
= e1000_rar_set_82542
;
134 /* turn on/off LED */
135 mac
->ops
.led_on
= e1000_led_on_82542
;
136 mac
->ops
.led_off
= e1000_led_off_82542
;
137 /* clear hardware counters */
138 mac
->ops
.clear_hw_cntrs
= e1000_clear_hw_cntrs_82542
;
140 mac
->ops
.get_link_up_info
= e1000_get_speed_and_duplex_fiber_serdes_generic
;
142 return E1000_SUCCESS
;
146 * e1000_init_function_pointers_82542 - Init func ptrs.
147 * @hw: pointer to the HW structure
149 * Called to initialize all function pointers and parameters.
151 void e1000_init_function_pointers_82542(struct e1000_hw
*hw
)
153 DEBUGFUNC("e1000_init_function_pointers_82542");
155 hw
->mac
.ops
.init_params
= e1000_init_mac_params_82542
;
156 hw
->nvm
.ops
.init_params
= e1000_init_nvm_params_82542
;
157 hw
->phy
.ops
.init_params
= e1000_init_phy_params_82542
;
161 * e1000_get_bus_info_82542 - Obtain bus information for adapter
162 * @hw: pointer to the HW structure
164 * This will obtain information about the HW bus for which the
165 * adapter is attached and stores it in the hw structure.
167 static s32
e1000_get_bus_info_82542(struct e1000_hw
*hw
)
169 DEBUGFUNC("e1000_get_bus_info_82542");
171 hw
->bus
.type
= e1000_bus_type_pci
;
172 hw
->bus
.speed
= e1000_bus_speed_unknown
;
173 hw
->bus
.width
= e1000_bus_width_unknown
;
175 return E1000_SUCCESS
;
179 * e1000_reset_hw_82542 - Reset hardware
180 * @hw: pointer to the HW structure
182 * This resets the hardware into a known state.
184 static s32
e1000_reset_hw_82542(struct e1000_hw
*hw
)
186 struct e1000_bus_info
*bus
= &hw
->bus
;
187 s32 ret_val
= E1000_SUCCESS
;
190 DEBUGFUNC("e1000_reset_hw_82542");
192 if (hw
->revision_id
== E1000_REVISION_2
) {
193 DEBUGOUT("Disabling MWI on 82542 rev 2\n");
194 e1000_pci_clear_mwi(hw
);
197 DEBUGOUT("Masking off all interrupts\n");
198 E1000_WRITE_REG(hw
, E1000_IMC
, 0xffffffff);
200 E1000_WRITE_REG(hw
, E1000_RCTL
, 0);
201 E1000_WRITE_REG(hw
, E1000_TCTL
, E1000_TCTL_PSP
);
202 E1000_WRITE_FLUSH(hw
);
205 * Delay to allow any outstanding PCI transactions to complete before
206 * resetting the device
210 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
212 DEBUGOUT("Issuing a global reset to 82542/82543 MAC\n");
213 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
| E1000_CTRL_RST
);
215 hw
->nvm
.ops
.reload(hw
);
218 E1000_WRITE_REG(hw
, E1000_IMC
, 0xffffffff);
219 E1000_READ_REG(hw
, E1000_ICR
);
221 if (hw
->revision_id
== E1000_REVISION_2
) {
222 if (bus
->pci_cmd_word
& CMD_MEM_WRT_INVALIDATE
)
223 e1000_pci_set_mwi(hw
);
230 * e1000_init_hw_82542 - Initialize hardware
231 * @hw: pointer to the HW structure
233 * This inits the hardware readying it for operation.
235 static s32
e1000_init_hw_82542(struct e1000_hw
*hw
)
237 struct e1000_mac_info
*mac
= &hw
->mac
;
238 struct e1000_dev_spec_82542
*dev_spec
= &hw
->dev_spec
._82542
;
239 s32 ret_val
= E1000_SUCCESS
;
243 DEBUGFUNC("e1000_init_hw_82542");
245 /* Disabling VLAN filtering */
246 E1000_WRITE_REG(hw
, E1000_VET
, 0);
247 mac
->ops
.clear_vfta(hw
);
249 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
250 if (hw
->revision_id
== E1000_REVISION_2
) {
251 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
252 e1000_pci_clear_mwi(hw
);
253 E1000_WRITE_REG(hw
, E1000_RCTL
, E1000_RCTL_RST
);
254 E1000_WRITE_FLUSH(hw
);
258 /* Setup the receive address. */
259 e1000_init_rx_addrs_generic(hw
, mac
->rar_entry_count
);
261 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
262 if (hw
->revision_id
== E1000_REVISION_2
) {
263 E1000_WRITE_REG(hw
, E1000_RCTL
, 0);
264 E1000_WRITE_FLUSH(hw
);
266 if (hw
->bus
.pci_cmd_word
& CMD_MEM_WRT_INVALIDATE
)
267 e1000_pci_set_mwi(hw
);
270 /* Zero out the Multicast HASH table */
271 DEBUGOUT("Zeroing the MTA\n");
272 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
273 E1000_WRITE_REG_ARRAY(hw
, E1000_MTA
, i
, 0);
276 * Set the PCI priority bit correctly in the CTRL register. This
277 * determines if the adapter gives priority to receives, or if it
278 * gives equal priority to transmits and receives.
280 if (dev_spec
->dma_fairness
) {
281 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
282 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
| E1000_CTRL_PRIOR
);
285 /* Setup link and flow control */
286 ret_val
= e1000_setup_link_82542(hw
);
289 * Clear all of the statistics registers (clear on read). It is
290 * important that we do this after we have tried to establish link
291 * because the symbol error count will increment wildly if there
294 e1000_clear_hw_cntrs_82542(hw
);
300 * e1000_setup_link_82542 - Setup flow control and link settings
301 * @hw: pointer to the HW structure
303 * Determines which flow control settings to use, then configures flow
304 * control. Calls the appropriate media-specific link configuration
305 * function. Assuming the adapter has a valid link partner, a valid link
306 * should be established. Assumes the hardware has previously been reset
307 * and the transmitter and receiver are not enabled.
309 static s32
e1000_setup_link_82542(struct e1000_hw
*hw
)
311 struct e1000_mac_info
*mac
= &hw
->mac
;
312 s32 ret_val
= E1000_SUCCESS
;
314 DEBUGFUNC("e1000_setup_link_82542");
316 ret_val
= e1000_set_default_fc_generic(hw
);
320 hw
->fc
.requested_mode
&= ~e1000_fc_tx_pause
;
322 if (mac
->report_tx_early
== 1)
323 hw
->fc
.requested_mode
&= ~e1000_fc_rx_pause
;
326 * Save off the requested flow control mode for use later. Depending
327 * on the link partner's capabilities, we may or may not use this mode.
329 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
331 DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
332 hw
->fc
.current_mode
);
334 /* Call the necessary subroutine to configure the link. */
335 ret_val
= mac
->ops
.setup_physical_interface(hw
);
340 * Initialize the flow control address, type, and PAUSE timer
341 * registers to their default values. This is done even if flow
342 * control is disabled, because it does not hurt anything to
343 * initialize these registers.
345 DEBUGOUT("Initializing Flow Control address, type and timer regs\n");
347 E1000_WRITE_REG(hw
, E1000_FCAL
, FLOW_CONTROL_ADDRESS_LOW
);
348 E1000_WRITE_REG(hw
, E1000_FCAH
, FLOW_CONTROL_ADDRESS_HIGH
);
349 E1000_WRITE_REG(hw
, E1000_FCT
, FLOW_CONTROL_TYPE
);
351 E1000_WRITE_REG(hw
, E1000_FCTTV
, hw
->fc
.pause_time
);
353 ret_val
= e1000_set_fc_watermarks_generic(hw
);
360 * e1000_led_on_82542 - Turn on SW controllable LED
361 * @hw: pointer to the HW structure
363 * Turns the SW defined LED on.
365 static s32
e1000_led_on_82542(struct e1000_hw
*hw
)
367 u32 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
369 DEBUGFUNC("e1000_led_on_82542");
371 ctrl
|= E1000_CTRL_SWDPIN0
;
372 ctrl
|= E1000_CTRL_SWDPIO0
;
373 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
);
375 return E1000_SUCCESS
;
379 * e1000_led_off_82542 - Turn off SW controllable LED
380 * @hw: pointer to the HW structure
382 * Turns the SW defined LED off.
384 static s32
e1000_led_off_82542(struct e1000_hw
*hw
)
386 u32 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
388 DEBUGFUNC("e1000_led_off_82542");
390 ctrl
&= ~E1000_CTRL_SWDPIN0
;
391 ctrl
|= E1000_CTRL_SWDPIO0
;
392 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
);
394 return E1000_SUCCESS
;
398 * e1000_rar_set_82542 - Set receive address register
399 * @hw: pointer to the HW structure
400 * @addr: pointer to the receive address
401 * @index: receive address array register
403 * Sets the receive address array register at index to the address passed
406 static void e1000_rar_set_82542(struct e1000_hw
*hw
, u8
*addr
, u32 index
)
408 u32 rar_low
, rar_high
;
410 DEBUGFUNC("e1000_rar_set_82542");
413 * HW expects these in little endian so we reverse the byte order
414 * from network order (big endian) to little endian
416 rar_low
= ((u32
) addr
[0] |
417 ((u32
) addr
[1] << 8) |
418 ((u32
) addr
[2] << 16) | ((u32
) addr
[3] << 24));
420 rar_high
= ((u32
) addr
[4] | ((u32
) addr
[5] << 8));
422 /* If MAC address zero, no need to set the AV bit */
423 if (rar_low
|| rar_high
)
424 rar_high
|= E1000_RAH_AV
;
426 E1000_WRITE_REG_ARRAY(hw
, E1000_RA
, (index
<< 1), rar_low
);
427 E1000_WRITE_REG_ARRAY(hw
, E1000_RA
, ((index
<< 1) + 1), rar_high
);
431 * e1000_translate_register_82542 - Translate the proper register offset
432 * @reg: e1000 register to be read
434 * Registers in 82542 are located in different offsets than other adapters
435 * even though they function in the same manner. This function takes in
436 * the name of the register to read and returns the correct offset for
439 u32
e1000_translate_register_82542(u32 reg
)
442 * Some of the 82542 registers are located at different
443 * offsets than they are in newer adapters.
444 * Despite the difference in location, the registers
445 * function in the same manner.
528 * e1000_clear_hw_cntrs_82542 - Clear device specific hardware counters
529 * @hw: pointer to the HW structure
531 * Clears the hardware counters by reading the counter registers.
533 static void e1000_clear_hw_cntrs_82542(struct e1000_hw
*hw
)
535 DEBUGFUNC("e1000_clear_hw_cntrs_82542");
537 e1000_clear_hw_cntrs_base_generic(hw
);
539 E1000_READ_REG(hw
, E1000_PRC64
);
540 E1000_READ_REG(hw
, E1000_PRC127
);
541 E1000_READ_REG(hw
, E1000_PRC255
);
542 E1000_READ_REG(hw
, E1000_PRC511
);
543 E1000_READ_REG(hw
, E1000_PRC1023
);
544 E1000_READ_REG(hw
, E1000_PRC1522
);
545 E1000_READ_REG(hw
, E1000_PTC64
);
546 E1000_READ_REG(hw
, E1000_PTC127
);
547 E1000_READ_REG(hw
, E1000_PTC255
);
548 E1000_READ_REG(hw
, E1000_PTC511
);
549 E1000_READ_REG(hw
, E1000_PTC1023
);
550 E1000_READ_REG(hw
, E1000_PTC1522
);
554 * e1000_read_mac_addr_82542 - Read device MAC address
555 * @hw: pointer to the HW structure
557 * Reads the device MAC address from the EEPROM and stores the value.
559 s32
e1000_read_mac_addr_82542(struct e1000_hw
*hw
)
561 s32 ret_val
= E1000_SUCCESS
;
562 u16 offset
, nvm_data
, i
;
564 DEBUGFUNC("e1000_read_mac_addr");
566 for (i
= 0; i
< ETH_ADDR_LEN
; i
+= 2) {
568 ret_val
= hw
->nvm
.ops
.read(hw
, offset
, 1, &nvm_data
);
570 DEBUGOUT("NVM Read Error\n");
573 hw
->mac
.perm_addr
[i
] = (u8
)(nvm_data
& 0xFF);
574 hw
->mac
.perm_addr
[i
+1] = (u8
)(nvm_data
>> 8);
577 for (i
= 0; i
< ETH_ADDR_LEN
; i
++)
578 hw
->mac
.addr
[i
] = hw
->mac
.perm_addr
[i
];