1 /*******************************************************************************
3 Copyright (c) 2001-2007, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
43 #include "e1000_api.h"
45 void e1000_init_function_pointers_82540(struct e1000_hw *hw);
47 STATIC s32 e1000_init_phy_params_82540(struct e1000_hw *hw);
48 STATIC s32 e1000_init_nvm_params_82540(struct e1000_hw *hw);
49 STATIC s32 e1000_init_mac_params_82540(struct e1000_hw *hw);
50 static s32 e1000_adjust_serdes_amplitude_82540(struct e1000_hw *hw);
51 STATIC void e1000_clear_hw_cntrs_82540(struct e1000_hw *hw);
52 STATIC s32 e1000_init_hw_82540(struct e1000_hw *hw);
53 STATIC s32 e1000_reset_hw_82540(struct e1000_hw *hw);
54 static s32 e1000_set_phy_mode_82540(struct e1000_hw *hw);
55 static s32 e1000_set_vco_speed_82540(struct e1000_hw *hw);
56 STATIC s32 e1000_setup_copper_link_82540(struct e1000_hw *hw);
57 STATIC s32 e1000_setup_fiber_serdes_link_82540(struct e1000_hw *hw);
60 * e1000_init_phy_params_82540 - Init PHY func ptrs.
61 * @hw: pointer to the HW structure
63 * This is a function pointer entry point called by the api module.
65 STATIC s32 e1000_init_phy_params_82540(struct e1000_hw *hw)
67 struct e1000_phy_info *phy = &hw->phy;
68 struct e1000_functions *func = &hw->func;
69 s32 ret_val = E1000_SUCCESS;
72 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
73 phy->reset_delay_us = 10000;
74 phy->type = e1000_phy_m88;
76 /* Function Pointers */
77 func->check_polarity = e1000_check_polarity_m88;
78 func->commit_phy = e1000_phy_sw_reset_generic;
79 func->force_speed_duplex = e1000_phy_force_speed_duplex_m88;
80 func->get_cable_length = e1000_get_cable_length_m88;
81 func->get_cfg_done = e1000_get_cfg_done_generic;
82 func->read_phy_reg = e1000_read_phy_reg_m88;
83 func->reset_phy = e1000_phy_hw_reset_generic;
84 func->write_phy_reg = e1000_write_phy_reg_m88;
85 func->get_phy_info = e1000_get_phy_info_m88;
87 ret_val = e1000_get_phy_id(hw);
92 switch (hw->mac.type) {
95 case e1000_82545_rev_3:
97 case e1000_82546_rev_3:
98 if (phy->id == M88E1011_I_PHY_ID)
102 ret_val = -E1000_ERR_PHY;
112 * e1000_init_nvm_params_82540 - Init NVM func ptrs.
113 * @hw: pointer to the HW structure
115 * This is a function pointer entry point called by the api module.
117 STATIC s32 e1000_init_nvm_params_82540(struct e1000_hw *hw)
119 struct e1000_nvm_info *nvm = &hw->nvm;
120 struct e1000_functions *func = &hw->func;
121 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
123 DEBUGFUNC("e1000_init_nvm_params_82540");
125 nvm->type = e1000_nvm_eeprom_microwire;
126 nvm->delay_usec = 50;
127 nvm->opcode_bits = 3;
128 switch (nvm->override) {
129 case e1000_nvm_override_microwire_large:
130 nvm->address_bits = 8;
131 nvm->word_size = 256;
133 case e1000_nvm_override_microwire_small:
134 nvm->address_bits = 6;
138 nvm->address_bits = eecd & E1000_EECD_SIZE ? 8 : 6;
139 nvm->word_size = eecd & E1000_EECD_SIZE ? 256 : 64;
143 /* Function Pointers */
144 func->acquire_nvm = e1000_acquire_nvm_generic;
145 func->read_nvm = e1000_read_nvm_microwire;
146 func->release_nvm = e1000_release_nvm_generic;
147 func->update_nvm = e1000_update_nvm_checksum_generic;
148 func->valid_led_default = e1000_valid_led_default_generic;
149 func->validate_nvm = e1000_validate_nvm_checksum_generic;
150 func->write_nvm = e1000_write_nvm_microwire;
152 return E1000_SUCCESS;
156 * e1000_init_mac_params_82540 - Init MAC func ptrs.
157 * @hw: pointer to the HW structure
159 * This is a function pointer entry point called by the api module.
161 STATIC s32 e1000_init_mac_params_82540(struct e1000_hw *hw)
163 struct e1000_mac_info *mac = &hw->mac;
164 struct e1000_functions *func = &hw->func;
165 s32 ret_val = E1000_SUCCESS;
167 DEBUGFUNC("e1000_init_mac_params_82540");
170 switch (hw->device_id) {
171 case E1000_DEV_ID_82545EM_FIBER:
172 case E1000_DEV_ID_82545GM_FIBER:
173 case E1000_DEV_ID_82546EB_FIBER:
174 case E1000_DEV_ID_82546GB_FIBER:
175 hw->phy.media_type = e1000_media_type_fiber;
177 case E1000_DEV_ID_82545GM_SERDES:
178 case E1000_DEV_ID_82546GB_SERDES:
179 hw->phy.media_type = e1000_media_type_internal_serdes;
182 hw->phy.media_type = e1000_media_type_copper;
186 /* Set mta register count */
187 mac->mta_reg_count = 128;
188 /* Set rar entry count */
189 mac->rar_entry_count = E1000_RAR_ENTRIES;
191 /* Function pointers */
193 /* bus type/speed/width */
194 func->get_bus_info = e1000_get_bus_info_pci_generic;
196 func->reset_hw = e1000_reset_hw_82540;
197 /* hw initialization */
198 func->init_hw = e1000_init_hw_82540;
200 func->setup_link = e1000_setup_link_generic;
201 /* physical interface setup */
202 func->setup_physical_interface =
203 (hw->phy.media_type == e1000_media_type_copper)
204 ? e1000_setup_copper_link_82540
205 : e1000_setup_fiber_serdes_link_82540;
207 switch (hw->phy.media_type) {
208 case e1000_media_type_copper:
209 func->check_for_link = e1000_check_for_copper_link_generic;
211 case e1000_media_type_fiber:
212 func->check_for_link = e1000_check_for_fiber_link_generic;
214 case e1000_media_type_internal_serdes:
215 func->check_for_link = e1000_check_for_serdes_link_generic;
218 ret_val = -E1000_ERR_CONFIG;
223 func->get_link_up_info =
224 (hw->phy.media_type == e1000_media_type_copper)
225 ? e1000_get_speed_and_duplex_copper_generic
226 : e1000_get_speed_and_duplex_fiber_serdes_generic;
227 /* multicast address update */
228 func->update_mc_addr_list = e1000_update_mc_addr_list_generic;
230 func->write_vfta = e1000_write_vfta_generic;
232 func->clear_vfta = e1000_clear_vfta_generic;
234 func->mta_set = e1000_mta_set_generic;
236 func->setup_led = e1000_setup_led_generic;
238 func->cleanup_led = e1000_cleanup_led_generic;
239 /* turn on/off LED */
240 func->led_on = e1000_led_on_generic;
241 func->led_off = e1000_led_off_generic;
242 /* clear hardware counters */
243 func->clear_hw_cntrs = e1000_clear_hw_cntrs_82540;
250 * e1000_init_function_pointers_82540 - Init func ptrs.
251 * @hw: pointer to the HW structure
253 * The only function explicitly called by the api module to initialize
254 * all function pointers and parameters.
256 void e1000_init_function_pointers_82540(struct e1000_hw *hw)
258 DEBUGFUNC("e1000_init_function_pointers_82540");
260 hw->func.init_mac_params = e1000_init_mac_params_82540;
261 hw->func.init_nvm_params = e1000_init_nvm_params_82540;
262 hw->func.init_phy_params = e1000_init_phy_params_82540;
266 * e1000_reset_hw_82540 - Reset hardware
267 * @hw: pointer to the HW structure
269 * This resets the hardware into a known state. This is a
270 * function pointer entry point called by the api module.
272 STATIC s32 e1000_reset_hw_82540(struct e1000_hw *hw)
275 s32 ret_val = E1000_SUCCESS;
277 DEBUGFUNC("e1000_reset_hw_82540");
279 DEBUGOUT("Masking off all interrupts\n");
280 E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);
282 E1000_WRITE_REG(hw, E1000_RCTL, 0);
283 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
284 E1000_WRITE_FLUSH(hw);
287 * Delay to allow any outstanding PCI transactions to complete
288 * before resetting the device.
292 ctrl = E1000_READ_REG(hw, E1000_CTRL);
294 DEBUGOUT("Issuing a global reset to 82540/82545/82546 MAC\n");
295 switch (hw->mac.type) {
296 case e1000_82545_rev_3:
297 case e1000_82546_rev_3:
298 E1000_WRITE_REG(hw, E1000_CTRL_DUP, ctrl | E1000_CTRL_RST);
302 * These controllers can't ack the 64-bit write when
303 * issuing the reset, so we use IO-mapping as a
304 * workaround to issue the reset.
306 E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
310 /* Wait for EEPROM reload */
313 /* Disable HW ARPs on ASF enabled adapters */
314 manc = E1000_READ_REG(hw, E1000_MANC);
315 manc &= ~E1000_MANC_ARP_EN;
316 E1000_WRITE_REG(hw, E1000_MANC, manc);
318 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
319 icr = E1000_READ_REG(hw, E1000_ICR);
325 * e1000_init_hw_82540 - Initialize hardware
326 * @hw: pointer to the HW structure
328 * This inits the hardware readying it for operation. This is a
329 * function pointer entry point called by the api module.
331 STATIC s32 e1000_init_hw_82540(struct e1000_hw *hw)
333 struct e1000_mac_info *mac = &hw->mac;
334 u32 txdctl, ctrl_ext;
335 s32 ret_val = E1000_SUCCESS;
338 DEBUGFUNC("e1000_init_hw_82540");
340 /* Initialize identification LED */
341 ret_val = e1000_id_led_init_generic(hw);
343 DEBUGOUT("Error initializing identification LED\n");
344 /* This is not fatal and we should not stop init due to this */
347 /* Disabling VLAN filtering */
348 DEBUGOUT("Initializing the IEEE VLAN\n");
349 if (mac->type < e1000_82545_rev_3)
350 E1000_WRITE_REG(hw, E1000_VET, 0);
352 e1000_clear_vfta(hw);
354 /* Setup the receive address. */
355 e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
357 /* Zero out the Multicast HASH table */
358 DEBUGOUT("Zeroing the MTA\n");
359 for (i = 0; i < mac->mta_reg_count; i++) {
360 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
362 * Avoid back to back register writes by adding the register
363 * read (flush). This is to protect against some strange
364 * bridge configurations that may issue Memory Write Block
365 * (MWB) to our register space. The *_rev_3 hardware at
366 * least doesn't respond correctly to every other dword in an
367 * MWB to our register space.
369 E1000_WRITE_FLUSH(hw);
372 if (mac->type < e1000_82545_rev_3)
373 e1000_pcix_mmrbc_workaround_generic(hw);
375 /* Setup link and flow control */
376 ret_val = e1000_setup_link(hw);
378 txdctl = E1000_READ_REG(hw, E1000_TXDCTL(0));
379 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
380 E1000_TXDCTL_FULL_TX_DESC_WB;
381 E1000_WRITE_REG(hw, E1000_TXDCTL(0), txdctl);
384 * Clear all of the statistics registers (clear on read). It is
385 * important that we do this after we have tried to establish link
386 * because the symbol error count will increment wildly if there
389 e1000_clear_hw_cntrs_82540(hw);
391 if ((hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER) ||
392 (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3)) {
393 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
395 * Relaxed ordering must be disabled to avoid a parity
396 * error crash in a PCI slot.
398 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
399 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
406 * e1000_setup_copper_link_82540 - Configure copper link settings
407 * @hw: pointer to the HW structure
409 * Calls the appropriate function to configure the link for auto-neg or forced
410 * speed and duplex. Then we check for link, once link is established calls
411 * to configure collision distance and flow control are called. If link is
412 * not established, we return -E1000_ERR_PHY (-2). This is a function
413 * pointer entry point called by the api module.
415 STATIC s32 e1000_setup_copper_link_82540(struct e1000_hw *hw)
418 s32 ret_val = E1000_SUCCESS;
421 DEBUGFUNC("e1000_setup_copper_link_82540");
423 ctrl = E1000_READ_REG(hw, E1000_CTRL);
424 ctrl |= E1000_CTRL_SLU;
425 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
426 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
428 ret_val = e1000_set_phy_mode_82540(hw);
432 if (hw->mac.type == e1000_82545_rev_3 ||
433 hw->mac.type == e1000_82546_rev_3) {
434 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &data);
438 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, data);
443 ret_val = e1000_copper_link_setup_m88(hw);
447 ret_val = e1000_setup_copper_link_generic(hw);
454 * e1000_setup_fiber_serdes_link_82540 - Setup link for fiber/serdes
455 * @hw: pointer to the HW structure
457 * Set the output amplitude to the value in the EEPROM and adjust the VCO
458 * speed to improve Bit Error Rate (BER) performance. Configures collision
459 * distance and flow control for fiber and serdes links. Upon successful
460 * setup, poll for link. This is a function pointer entry point called by
463 STATIC s32 e1000_setup_fiber_serdes_link_82540(struct e1000_hw *hw)
465 struct e1000_mac_info *mac = &hw->mac;
466 s32 ret_val = E1000_SUCCESS;
468 DEBUGFUNC("e1000_setup_fiber_serdes_link_82540");
471 case e1000_82545_rev_3:
472 case e1000_82546_rev_3:
473 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
475 * If we're on serdes media, adjust the output
476 * amplitude to value set in the EEPROM.
478 ret_val = e1000_adjust_serdes_amplitude_82540(hw);
482 /* Adjust VCO speed to improve BER performance */
483 ret_val = e1000_set_vco_speed_82540(hw);
490 ret_val = e1000_setup_fiber_serdes_link_generic(hw);
497 * e1000_adjust_serdes_amplitude_82540 - Adjust amplitude based on EEPROM
498 * @hw: pointer to the HW structure
500 * Adjust the SERDES ouput amplitude based on the EEPROM settings.
502 static s32 e1000_adjust_serdes_amplitude_82540(struct e1000_hw *hw)
504 s32 ret_val = E1000_SUCCESS;
507 DEBUGFUNC("e1000_adjust_serdes_amplitude_82540");
509 ret_val = e1000_read_nvm(hw, NVM_SERDES_AMPLITUDE, 1, &nvm_data);
513 if (nvm_data != NVM_RESERVED_WORD) {
514 /* Adjust serdes output amplitude only. */
515 nvm_data &= NVM_SERDES_AMPLITUDE_MASK;
516 ret_val = e1000_write_phy_reg(hw,
517 M88E1000_PHY_EXT_CTRL,
528 * e1000_set_vco_speed_82540 - Set VCO speed for better performance
529 * @hw: pointer to the HW structure
531 * Set the VCO speed to improve Bit Error Rate (BER) performance.
533 static s32 e1000_set_vco_speed_82540(struct e1000_hw *hw)
535 s32 ret_val = E1000_SUCCESS;
536 u16 default_page = 0;
539 DEBUGFUNC("e1000_set_vco_speed_82540");
541 /* Set PHY register 30, page 5, bit 8 to 0 */
543 ret_val = e1000_read_phy_reg(hw,
544 M88E1000_PHY_PAGE_SELECT,
549 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
553 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
557 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
558 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
562 /* Set PHY register 30, page 4, bit 11 to 1 */
564 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
568 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
572 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
573 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
577 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
585 * e1000_set_phy_mode_82540 - Set PHY to class A mode
586 * @hw: pointer to the HW structure
588 * Sets the PHY to class A mode and assumes the following operations will
589 * follow to enable the new class mode:
590 * 1. Do a PHY soft reset.
591 * 2. Restart auto-negotiation or force link.
593 static s32 e1000_set_phy_mode_82540(struct e1000_hw *hw)
595 struct e1000_phy_info *phy = &hw->phy;
596 s32 ret_val = E1000_SUCCESS;
599 DEBUGFUNC("e1000_set_phy_mode_82540");
601 if (hw->mac.type != e1000_82545_rev_3)
604 ret_val = e1000_read_nvm(hw, NVM_PHY_CLASS_WORD, 1, &nvm_data);
606 ret_val = -E1000_ERR_PHY;
610 if ((nvm_data != NVM_RESERVED_WORD) && (nvm_data & NVM_PHY_CLASS_A)) {
611 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
614 ret_val = -E1000_ERR_PHY;
617 ret_val = e1000_write_phy_reg(hw,
618 M88E1000_PHY_GEN_CONTROL,
621 ret_val = -E1000_ERR_PHY;
625 phy->reset_disable = FALSE;
633 * e1000_clear_hw_cntrs_82540 - Clear device specific hardware counters
634 * @hw: pointer to the HW structure
636 * Clears the hardware counters by reading the counter registers.
638 STATIC void e1000_clear_hw_cntrs_82540(struct e1000_hw *hw)
642 DEBUGFUNC("e1000_clear_hw_cntrs_82540");
644 e1000_clear_hw_cntrs_base_generic(hw);
646 temp = E1000_READ_REG(hw, E1000_PRC64);
647 temp = E1000_READ_REG(hw, E1000_PRC127);
648 temp = E1000_READ_REG(hw, E1000_PRC255);
649 temp = E1000_READ_REG(hw, E1000_PRC511);
650 temp = E1000_READ_REG(hw, E1000_PRC1023);
651 temp = E1000_READ_REG(hw, E1000_PRC1522);
652 temp = E1000_READ_REG(hw, E1000_PTC64);
653 temp = E1000_READ_REG(hw, E1000_PTC127);
654 temp = E1000_READ_REG(hw, E1000_PTC255);
655 temp = E1000_READ_REG(hw, E1000_PTC511);
656 temp = E1000_READ_REG(hw, E1000_PTC1023);
657 temp = E1000_READ_REG(hw, E1000_PTC1522);
659 temp = E1000_READ_REG(hw, E1000_ALGNERRC);
660 temp = E1000_READ_REG(hw, E1000_RXERRC);
661 temp = E1000_READ_REG(hw, E1000_TNCRS);
662 temp = E1000_READ_REG(hw, E1000_CEXTERR);
663 temp = E1000_READ_REG(hw, E1000_TSCTC);
664 temp = E1000_READ_REG(hw, E1000_TSCTFC);
666 temp = E1000_READ_REG(hw, E1000_MGTPRC);
667 temp = E1000_READ_REG(hw, E1000_MGTPDC);
668 temp = E1000_READ_REG(hw, E1000_MGTPTC);