Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / devs / networks / e1000 / e1000_82543.c
blob66b710a298e3134a1d4b32471b0cbf42c4dcc22d
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 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
13 more details.
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".
22 Contact Information:
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 *******************************************************************************/
29 /* e1000_82543
30 * e1000_82544
33 #include "e1000_api.h"
34 #include "e1000_82543.h"
36 static s32 e1000_init_phy_params_82543(struct e1000_hw *hw);
37 static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw);
38 static s32 e1000_init_mac_params_82543(struct e1000_hw *hw);
39 static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset,
40 u16 *data);
41 static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset,
42 u16 data);
43 static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw);
44 static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw);
45 static s32 e1000_reset_hw_82543(struct e1000_hw *hw);
46 static s32 e1000_init_hw_82543(struct e1000_hw *hw);
47 static s32 e1000_setup_link_82543(struct e1000_hw *hw);
48 static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw);
49 static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw);
50 static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw);
51 static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw);
52 static s32 e1000_led_on_82543(struct e1000_hw *hw);
53 static s32 e1000_led_off_82543(struct e1000_hw *hw);
54 static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset,
55 u32 value);
56 static void e1000_mta_set_82543(struct e1000_hw *hw, u32 hash_value);
57 static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw);
58 static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw);
59 static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw);
60 static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl);
61 static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw);
62 static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl);
63 static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw);
64 static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data,
65 u16 count);
66 static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw);
67 static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state);
69 struct e1000_dev_spec_82543 {
70 u32 tbi_compatibility;
71 bool dma_fairness;
72 bool init_phy_disabled;
75 /**
76 * e1000_init_phy_params_82543 - Init PHY func ptrs.
77 * @hw: pointer to the HW structure
79 * This is a function pointer entry point called by the api module.
80 **/
81 static s32 e1000_init_phy_params_82543(struct e1000_hw *hw)
83 struct e1000_phy_info *phy = &hw->phy;
84 s32 ret_val = E1000_SUCCESS;
86 DEBUGFUNC("e1000_init_phy_params_82543");
88 if (hw->phy.media_type != e1000_media_type_copper) {
89 phy->type = e1000_phy_none;
90 goto out;
91 } else {
92 phy->ops.power_up = e1000_power_up_phy_copper;
93 phy->ops.power_down = e1000_power_down_phy_copper;
96 phy->addr = 1;
97 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
98 phy->reset_delay_us = 10000;
99 phy->type = e1000_phy_m88;
101 /* Function Pointers */
102 phy->ops.check_polarity = e1000_check_polarity_m88;
103 phy->ops.commit = e1000_phy_sw_reset_generic;
104 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_82543;
105 phy->ops.get_cable_length = e1000_get_cable_length_m88;
106 phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
107 phy->ops.read_reg = (hw->mac.type == e1000_82543)
108 ? e1000_read_phy_reg_82543
109 : e1000_read_phy_reg_m88;
110 phy->ops.reset = (hw->mac.type == e1000_82543)
111 ? e1000_phy_hw_reset_82543
112 : e1000_phy_hw_reset_generic;
113 phy->ops.write_reg = (hw->mac.type == e1000_82543)
114 ? e1000_write_phy_reg_82543
115 : e1000_write_phy_reg_m88;
116 phy->ops.get_info = e1000_get_phy_info_m88;
119 * The external PHY of the 82543 can be in a funky state.
120 * Resetting helps us read the PHY registers for acquiring
121 * the PHY ID.
123 if (!e1000_init_phy_disabled_82543(hw)) {
124 ret_val = phy->ops.reset(hw);
125 if (ret_val) {
126 DEBUGOUT("Resetting PHY during init failed.\n");
127 goto out;
129 msec_delay(20);
132 ret_val = e1000_get_phy_id(hw);
133 if (ret_val)
134 goto out;
136 /* Verify phy id */
137 switch (hw->mac.type) {
138 case e1000_82543:
139 if (phy->id != M88E1000_E_PHY_ID) {
140 ret_val = -E1000_ERR_PHY;
141 goto out;
143 break;
144 case e1000_82544:
145 if (phy->id != M88E1000_I_PHY_ID) {
146 ret_val = -E1000_ERR_PHY;
147 goto out;
149 break;
150 default:
151 ret_val = -E1000_ERR_PHY;
152 goto out;
153 break;
156 out:
157 return ret_val;
161 * e1000_init_nvm_params_82543 - Init NVM func ptrs.
162 * @hw: pointer to the HW structure
164 * This is a function pointer entry point called by the api module.
166 static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw)
168 struct e1000_nvm_info *nvm = &hw->nvm;
170 DEBUGFUNC("e1000_init_nvm_params_82543");
172 nvm->type = e1000_nvm_eeprom_microwire;
173 nvm->word_size = 64;
174 nvm->delay_usec = 50;
175 nvm->address_bits = 6;
176 nvm->opcode_bits = 3;
178 /* Function Pointers */
179 nvm->ops.read = e1000_read_nvm_microwire;
180 nvm->ops.update = e1000_update_nvm_checksum_generic;
181 nvm->ops.valid_led_default = e1000_valid_led_default_generic;
182 nvm->ops.validate = e1000_validate_nvm_checksum_generic;
183 nvm->ops.write = e1000_write_nvm_microwire;
185 return E1000_SUCCESS;
189 * e1000_init_mac_params_82543 - Init MAC func ptrs.
190 * @hw: pointer to the HW structure
192 * This is a function pointer entry point called by the api module.
194 static s32 e1000_init_mac_params_82543(struct e1000_hw *hw)
196 struct e1000_mac_info *mac = &hw->mac;
197 s32 ret_val;
199 DEBUGFUNC("e1000_init_mac_params_82543");
201 /* Set media type */
202 switch (hw->device_id) {
203 case E1000_DEV_ID_82543GC_FIBER:
204 case E1000_DEV_ID_82544EI_FIBER:
205 hw->phy.media_type = e1000_media_type_fiber;
206 break;
207 default:
208 hw->phy.media_type = e1000_media_type_copper;
209 break;
212 /* Set mta register count */
213 mac->mta_reg_count = 128;
214 /* Set rar entry count */
215 mac->rar_entry_count = E1000_RAR_ENTRIES;
217 /* Function pointers */
219 /* bus type/speed/width */
220 mac->ops.get_bus_info = e1000_get_bus_info_pci_generic;
221 /* reset */
222 mac->ops.reset_hw = e1000_reset_hw_82543;
223 /* hw initialization */
224 mac->ops.init_hw = e1000_init_hw_82543;
225 /* link setup */
226 mac->ops.setup_link = e1000_setup_link_82543;
227 /* physical interface setup */
228 mac->ops.setup_physical_interface =
229 (hw->phy.media_type == e1000_media_type_copper)
230 ? e1000_setup_copper_link_82543
231 : e1000_setup_fiber_link_82543;
232 /* check for link */
233 mac->ops.check_for_link =
234 (hw->phy.media_type == e1000_media_type_copper)
235 ? e1000_check_for_copper_link_82543
236 : e1000_check_for_fiber_link_82543;
237 /* link info */
238 mac->ops.get_link_up_info =
239 (hw->phy.media_type == e1000_media_type_copper)
240 ? e1000_get_speed_and_duplex_copper_generic
241 : e1000_get_speed_and_duplex_fiber_serdes_generic;
242 /* multicast address update */
243 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
244 /* writing VFTA */
245 mac->ops.write_vfta = e1000_write_vfta_82543;
246 /* clearing VFTA */
247 mac->ops.clear_vfta = e1000_clear_vfta_generic;
248 /* setting MTA */
249 mac->ops.mta_set = e1000_mta_set_82543;
250 /* turn on/off LED */
251 mac->ops.led_on = e1000_led_on_82543;
252 mac->ops.led_off = e1000_led_off_82543;
253 /* remove device */
254 mac->ops.remove_device = e1000_remove_device_generic;
255 /* clear hardware counters */
256 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82543;
258 hw->dev_spec_size = sizeof(struct e1000_dev_spec_82543);
260 /* Device-specific structure allocation */
261 ret_val = e1000_alloc_zeroed_dev_spec_struct(hw, hw->dev_spec_size);
262 if (ret_val)
263 goto out;
265 /* Set tbi compatibility */
266 if ((hw->mac.type != e1000_82543) ||
267 (hw->phy.media_type == e1000_media_type_fiber))
268 e1000_set_tbi_compatibility_82543(hw, FALSE);
270 out:
271 return ret_val;
275 * e1000_init_function_pointers_82543 - Init func ptrs.
276 * @hw: pointer to the HW structure
278 * The only function explicitly called by the api module to initialize
279 * all function pointers and parameters.
281 void e1000_init_function_pointers_82543(struct e1000_hw *hw)
283 DEBUGFUNC("e1000_init_function_pointers_82543");
285 hw->mac.ops.init_params = e1000_init_mac_params_82543;
286 hw->nvm.ops.init_params = e1000_init_nvm_params_82543;
287 hw->phy.ops.init_params = e1000_init_phy_params_82543;
291 * e1000_tbi_compatibility_enabled_82543 - Returns TBI compat status
292 * @hw: pointer to the HW structure
294 * Returns the current status of 10-bit Interface (TBI) compatibility
295 * (enabled/disabled).
297 static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw)
299 struct e1000_dev_spec_82543 *dev_spec;
300 bool state = FALSE;
302 DEBUGFUNC("e1000_tbi_compatibility_enabled_82543");
304 if (hw->mac.type != e1000_82543) {
305 DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
306 goto out;
309 dev_spec = (struct e1000_dev_spec_82543 *)hw->dev_spec;
311 if (!dev_spec) {
312 DEBUGOUT("dev_spec pointer is set to NULL.\n");
313 goto out;
316 state = (dev_spec->tbi_compatibility & TBI_COMPAT_ENABLED)
317 ? TRUE : FALSE;
319 out:
320 return state;
324 * e1000_set_tbi_compatibility_82543 - Set TBI compatibility
325 * @hw: pointer to the HW structure
326 * @state: enable/disable TBI compatibility
328 * Enables or disabled 10-bit Interface (TBI) compatibility.
330 void e1000_set_tbi_compatibility_82543(struct e1000_hw *hw, bool state)
332 struct e1000_dev_spec_82543 *dev_spec;
334 DEBUGFUNC("e1000_set_tbi_compatibility_82543");
336 if (hw->mac.type != e1000_82543) {
337 DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
338 goto out;
341 dev_spec = (struct e1000_dev_spec_82543 *)hw->dev_spec;
343 if (!dev_spec) {
344 DEBUGOUT("dev_spec pointer is set to NULL.\n");
345 goto out;
348 if (state)
349 dev_spec->tbi_compatibility |= TBI_COMPAT_ENABLED;
350 else
351 dev_spec->tbi_compatibility &= ~TBI_COMPAT_ENABLED;
353 out:
354 return;
358 * e1000_tbi_sbp_enabled_82543 - Returns TBI SBP status
359 * @hw: pointer to the HW structure
361 * Returns the current status of 10-bit Interface (TBI) store bad packet (SBP)
362 * (enabled/disabled).
364 bool e1000_tbi_sbp_enabled_82543(struct e1000_hw *hw)
366 struct e1000_dev_spec_82543 *dev_spec;
367 bool state = FALSE;
369 DEBUGFUNC("e1000_tbi_sbp_enabled_82543");
371 if (hw->mac.type != e1000_82543) {
372 DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
373 goto out;
376 dev_spec = (struct e1000_dev_spec_82543 *)hw->dev_spec;
378 if (!dev_spec) {
379 DEBUGOUT("dev_spec pointer is set to NULL.\n");
380 goto out;
383 state = (dev_spec->tbi_compatibility & TBI_SBP_ENABLED)
384 ? TRUE : FALSE;
386 out:
387 return state;
391 * e1000_set_tbi_sbp_82543 - Set TBI SBP
392 * @hw: pointer to the HW structure
393 * @state: enable/disable TBI store bad packet
395 * Enables or disabled 10-bit Interface (TBI) store bad packet (SBP).
397 static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state)
399 struct e1000_dev_spec_82543 *dev_spec;
401 DEBUGFUNC("e1000_set_tbi_sbp_82543");
403 dev_spec = (struct e1000_dev_spec_82543 *)hw->dev_spec;
405 if (state && e1000_tbi_compatibility_enabled_82543(hw))
406 dev_spec->tbi_compatibility |= TBI_SBP_ENABLED;
407 else
408 dev_spec->tbi_compatibility &= ~TBI_SBP_ENABLED;
410 return;
414 * e1000_init_phy_disabled_82543 - Returns init PHY status
415 * @hw: pointer to the HW structure
417 * Returns the current status of whether PHY initialization is disabled.
418 * True if PHY initialization is disabled else false.
420 static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw)
422 struct e1000_dev_spec_82543 *dev_spec;
423 bool ret_val;
425 DEBUGFUNC("e1000_init_phy_disabled_82543");
427 if (hw->mac.type != e1000_82543) {
428 ret_val = FALSE;
429 goto out;
432 dev_spec = (struct e1000_dev_spec_82543 *)hw->dev_spec;
434 if (!dev_spec) {
435 DEBUGOUT("dev_spec pointer is set to NULL.\n");
436 ret_val = FALSE;
437 goto out;
440 ret_val = dev_spec->init_phy_disabled;
442 out:
443 return ret_val;
447 * e1000_tbi_adjust_stats_82543 - Adjust stats when TBI enabled
448 * @hw: pointer to the HW structure
449 * @stats: Struct containing statistic register values
450 * @frame_len: The length of the frame in question
451 * @mac_addr: The Ethernet destination address of the frame in question
452 * @max_frame_size: The maximum frame size
454 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
456 void e1000_tbi_adjust_stats_82543(struct e1000_hw *hw,
457 struct e1000_hw_stats *stats, u32 frame_len,
458 u8 *mac_addr, u32 max_frame_size)
460 if (!(e1000_tbi_sbp_enabled_82543(hw)))
461 goto out;
463 /* First adjust the frame length. */
464 frame_len--;
466 * We need to adjust the statistics counters, since the hardware
467 * counters overcount this packet as a CRC error and undercount
468 * the packet as a good packet
470 /* This packet should not be counted as a CRC error. */
471 stats->crcerrs--;
472 /* This packet does count as a Good Packet Received. */
473 stats->gprc++;
475 /* Adjust the Good Octets received counters */
476 stats->gorc += frame_len;
479 * Is this a broadcast or multicast? Check broadcast first,
480 * since the test for a multicast frame will test positive on
481 * a broadcast frame.
483 if ((mac_addr[0] == 0xff) && (mac_addr[1] == 0xff))
484 /* Broadcast packet */
485 stats->bprc++;
486 else if (*mac_addr & 0x01)
487 /* Multicast packet */
488 stats->mprc++;
491 * In this case, the hardware has overcounted the number of
492 * oversize frames.
494 if ((frame_len == max_frame_size) && (stats->roc > 0))
495 stats->roc--;
498 * Adjust the bin counters when the extra byte put the frame in the
499 * wrong bin. Remember that the frame_len was adjusted above.
501 if (frame_len == 64) {
502 stats->prc64++;
503 stats->prc127--;
504 } else if (frame_len == 127) {
505 stats->prc127++;
506 stats->prc255--;
507 } else if (frame_len == 255) {
508 stats->prc255++;
509 stats->prc511--;
510 } else if (frame_len == 511) {
511 stats->prc511++;
512 stats->prc1023--;
513 } else if (frame_len == 1023) {
514 stats->prc1023++;
515 stats->prc1522--;
516 } else if (frame_len == 1522) {
517 stats->prc1522++;
520 out:
521 return;
525 * e1000_read_phy_reg_82543 - Read PHY register
526 * @hw: pointer to the HW structure
527 * @offset: register offset to be read
528 * @data: pointer to the read data
530 * Reads the PHY at offset and stores the information read to data.
532 static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 *data)
534 u32 mdic;
535 s32 ret_val = E1000_SUCCESS;
537 DEBUGFUNC("e1000_read_phy_reg_82543");
539 if (offset > MAX_PHY_REG_ADDRESS) {
540 DEBUGOUT1("PHY Address %d is out of range\n", offset);
541 ret_val = -E1000_ERR_PARAM;
542 goto out;
546 * We must first send a preamble through the MDIO pin to signal the
547 * beginning of an MII instruction. This is done by sending 32
548 * consecutive "1" bits.
550 e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
553 * Now combine the next few fields that are required for a read
554 * operation. We use this method instead of calling the
555 * e1000_shift_out_mdi_bits routine five different times. The format
556 * of an MII read instruction consists of a shift out of 14 bits and
557 * is defined as follows:
558 * <Preamble><SOF><Op Code><Phy Addr><Offset>
559 * followed by a shift in of 18 bits. This first two bits shifted in
560 * are TurnAround bits used to avoid contention on the MDIO pin when a
561 * READ operation is performed. These two bits are thrown away
562 * followed by a shift in of 16 bits which contains the desired data.
564 mdic = (offset | (hw->phy.addr << 5) |
565 (PHY_OP_READ << 10) | (PHY_SOF << 12));
567 e1000_shift_out_mdi_bits_82543(hw, mdic, 14);
570 * Now that we've shifted out the read command to the MII, we need to
571 * "shift in" the 16-bit value (18 total bits) of the requested PHY
572 * register address.
574 *data = e1000_shift_in_mdi_bits_82543(hw);
576 out:
577 return ret_val;
581 * e1000_write_phy_reg_82543 - Write PHY register
582 * @hw: pointer to the HW structure
583 * @offset: register offset to be written
584 * @data: pointer to the data to be written at offset
586 * Writes data to the PHY at offset.
588 static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 data)
590 u32 mdic;
591 s32 ret_val = E1000_SUCCESS;
593 DEBUGFUNC("e1000_write_phy_reg_82543");
595 if (offset > MAX_PHY_REG_ADDRESS) {
596 DEBUGOUT1("PHY Address %d is out of range\n", offset);
597 ret_val = -E1000_ERR_PARAM;
598 goto out;
602 * We'll need to use the SW defined pins to shift the write command
603 * out to the PHY. We first send a preamble to the PHY to signal the
604 * beginning of the MII instruction. This is done by sending 32
605 * consecutive "1" bits.
607 e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
610 * Now combine the remaining required fields that will indicate a
611 * write operation. We use this method instead of calling the
612 * e1000_shift_out_mdi_bits routine for each field in the command. The
613 * format of a MII write instruction is as follows:
614 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
616 mdic = ((PHY_TURNAROUND) | (offset << 2) | (hw->phy.addr << 7) |
617 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
618 mdic <<= 16;
619 mdic |= (u32) data;
621 e1000_shift_out_mdi_bits_82543(hw, mdic, 32);
623 out:
624 return ret_val;
628 * e1000_raise_mdi_clk_82543 - Raise Management Data Input clock
629 * @hw: pointer to the HW structure
630 * @ctrl: pointer to the control register
632 * Raise the management data input clock by setting the MDC bit in the control
633 * register.
635 static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl)
638 * Raise the clock input to the Management Data Clock (by setting the
639 * MDC bit), and then delay a sufficient amount of time.
641 E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl | E1000_CTRL_MDC));
642 E1000_WRITE_FLUSH(hw);
643 usec_delay(10);
647 * e1000_lower_mdi_clk_82543 - Lower Management Data Input clock
648 * @hw: pointer to the HW structure
649 * @ctrl: pointer to the control register
651 * Lower the management data input clock by clearing the MDC bit in the
652 * control register.
654 static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl)
657 * Lower the clock input to the Management Data Clock (by clearing the
658 * MDC bit), and then delay a sufficient amount of time.
660 E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl & ~E1000_CTRL_MDC));
661 E1000_WRITE_FLUSH(hw);
662 usec_delay(10);
666 * e1000_shift_out_mdi_bits_82543 - Shift data bits our to the PHY
667 * @hw: pointer to the HW structure
668 * @data: data to send to the PHY
669 * @count: number of bits to shift out
671 * We need to shift 'count' bits out to the PHY. So, the value in the
672 * "data" parameter will be shifted out to the PHY one bit at a time.
673 * In order to do this, "data" must be broken down into bits.
675 static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data,
676 u16 count)
678 u32 ctrl, mask;
681 * We need to shift "count" number of bits out to the PHY. So, the
682 * value in the "data" parameter will be shifted out to the PHY one
683 * bit at a time. In order to do this, "data" must be broken down
684 * into bits.
686 mask = 0x01;
687 mask <<= (count -1);
689 ctrl = E1000_READ_REG(hw, E1000_CTRL);
691 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
692 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
694 while (mask) {
696 * A "1" is shifted out to the PHY by setting the MDIO bit to
697 * "1" and then raising and lowering the Management Data Clock.
698 * A "0" is shifted out to the PHY by setting the MDIO bit to
699 * "0" and then raising and lowering the clock.
701 if (data & mask) ctrl |= E1000_CTRL_MDIO;
702 else ctrl &= ~E1000_CTRL_MDIO;
704 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
705 E1000_WRITE_FLUSH(hw);
707 usec_delay(10);
709 e1000_raise_mdi_clk_82543(hw, &ctrl);
710 e1000_lower_mdi_clk_82543(hw, &ctrl);
712 mask >>= 1;
717 * e1000_shift_in_mdi_bits_82543 - Shift data bits in from the PHY
718 * @hw: pointer to the HW structure
720 * In order to read a register from the PHY, we need to shift 18 bits
721 * in from the PHY. Bits are "shifted in" by raising the clock input to
722 * the PHY (setting the MDC bit), and then reading the value of the data out
723 * MDIO bit.
725 static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw)
727 u32 ctrl;
728 u16 data = 0;
729 u8 i;
732 * In order to read a register from the PHY, we need to shift in a
733 * total of 18 bits from the PHY. The first two bit (turnaround)
734 * times are used to avoid contention on the MDIO pin when a read
735 * operation is performed. These two bits are ignored by us and
736 * thrown away. Bits are "shifted in" by raising the input to the
737 * Management Data Clock (setting the MDC bit) and then reading the
738 * value of the MDIO bit.
740 ctrl = E1000_READ_REG(hw, E1000_CTRL);
743 * Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
744 * input.
746 ctrl &= ~E1000_CTRL_MDIO_DIR;
747 ctrl &= ~E1000_CTRL_MDIO;
749 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
750 E1000_WRITE_FLUSH(hw);
753 * Raise and lower the clock before reading in the data. This accounts
754 * for the turnaround bits. The first clock occurred when we clocked
755 * out the last bit of the Register Address.
757 e1000_raise_mdi_clk_82543(hw, &ctrl);
758 e1000_lower_mdi_clk_82543(hw, &ctrl);
760 for (data = 0, i = 0; i < 16; i++) {
761 data <<= 1;
762 e1000_raise_mdi_clk_82543(hw, &ctrl);
763 ctrl = E1000_READ_REG(hw, E1000_CTRL);
764 /* Check to see if we shifted in a "1". */
765 if (ctrl & E1000_CTRL_MDIO)
766 data |= 1;
767 e1000_lower_mdi_clk_82543(hw, &ctrl);
770 e1000_raise_mdi_clk_82543(hw, &ctrl);
771 e1000_lower_mdi_clk_82543(hw, &ctrl);
773 return data;
777 * e1000_phy_force_speed_duplex_82543 - Force speed/duplex for PHY
778 * @hw: pointer to the HW structure
780 * Calls the function to force speed and duplex for the m88 PHY, and
781 * if the PHY is not auto-negotiating and the speed is forced to 10Mbit,
782 * then call the function for polarity reversal workaround.
784 static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw)
786 s32 ret_val;
788 DEBUGFUNC("e1000_phy_force_speed_duplex_82543");
790 ret_val = e1000_phy_force_speed_duplex_m88(hw);
791 if (ret_val)
792 goto out;
794 if (!hw->mac.autoneg &&
795 (hw->mac.forced_speed_duplex & E1000_ALL_10_SPEED))
796 ret_val = e1000_polarity_reversal_workaround_82543(hw);
798 out:
799 return ret_val;
803 * e1000_polarity_reversal_workaround_82543 - Workaround polarity reversal
804 * @hw: pointer to the HW structure
806 * When forcing link to 10 Full or 10 Half, the PHY can reverse the polarity
807 * inadvertently. To workaround the issue, we disable the transmitter on
808 * the PHY until we have established the link partner's link parameters.
810 static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw)
812 s32 ret_val = E1000_SUCCESS;
813 u16 mii_status_reg;
814 u16 i;
815 bool link;
817 if (!(hw->phy.ops.write_reg))
818 goto out;
820 /* Polarity reversal workaround for forced 10F/10H links. */
822 /* Disable the transmitter on the PHY */
824 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
825 if (ret_val)
826 goto out;
827 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
828 if (ret_val)
829 goto out;
831 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
832 if (ret_val)
833 goto out;
836 * This loop will early-out if the NO link condition has been met.
837 * In other words, DO NOT use e1000_phy_has_link_generic() here.
839 for (i = PHY_FORCE_TIME; i > 0; i--) {
841 * Read the MII Status Register and wait for Link Status bit
842 * to be clear.
845 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
846 if (ret_val)
847 goto out;
849 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
850 if (ret_val)
851 goto out;
853 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
854 break;
855 msec_delay_irq(100);
858 /* Recommended delay time after link has been lost */
859 msec_delay_irq(1000);
861 /* Now we will re-enable the transmitter on the PHY */
863 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
864 if (ret_val)
865 goto out;
866 msec_delay_irq(50);
867 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
868 if (ret_val)
869 goto out;
870 msec_delay_irq(50);
871 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
872 if (ret_val)
873 goto out;
874 msec_delay_irq(50);
875 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
876 if (ret_val)
877 goto out;
879 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
880 if (ret_val)
881 goto out;
884 * Read the MII Status Register and wait for Link Status bit
885 * to be set.
887 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_TIME, 100000, &link);
888 if (ret_val)
889 goto out;
891 out:
892 return ret_val;
896 * e1000_phy_hw_reset_82543 - PHY hardware reset
897 * @hw: pointer to the HW structure
899 * Sets the PHY_RESET_DIR bit in the extended device control register
900 * to put the PHY into a reset and waits for completion. Once the reset
901 * has been accomplished, clear the PHY_RESET_DIR bit to take the PHY out
902 * of reset. This is a function pointer entry point called by the api module.
904 static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw)
906 u32 ctrl_ext;
907 s32 ret_val;
909 DEBUGFUNC("e1000_phy_hw_reset_82543");
912 * Read the Extended Device Control Register, assert the PHY_RESET_DIR
913 * bit to put the PHY into reset...
915 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
916 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
917 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
918 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
919 E1000_WRITE_FLUSH(hw);
921 msec_delay(10);
923 /* ...then take it out of reset. */
924 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
925 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
926 E1000_WRITE_FLUSH(hw);
928 usec_delay(150);
930 if (!(hw->phy.ops.get_cfg_done))
931 return E1000_SUCCESS;
933 ret_val = hw->phy.ops.get_cfg_done(hw);
935 return ret_val;
939 * e1000_reset_hw_82543 - Reset hardware
940 * @hw: pointer to the HW structure
942 * This resets the hardware into a known state. This is a
943 * function pointer entry point called by the api module.
945 static s32 e1000_reset_hw_82543(struct e1000_hw *hw)
947 u32 ctrl, icr;
948 s32 ret_val = E1000_SUCCESS;
950 DEBUGFUNC("e1000_reset_hw_82543");
952 DEBUGOUT("Masking off all interrupts\n");
953 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
955 E1000_WRITE_REG(hw, E1000_RCTL, 0);
956 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
957 E1000_WRITE_FLUSH(hw);
959 e1000_set_tbi_sbp_82543(hw, FALSE);
962 * Delay to allow any outstanding PCI transactions to complete before
963 * resetting the device
965 msec_delay(10);
967 ctrl = E1000_READ_REG(hw, E1000_CTRL);
969 DEBUGOUT("Issuing a global reset to 82543/82544 MAC\n");
970 if (hw->mac.type == e1000_82543) {
971 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
972 } else {
974 * The 82544 can't ACK the 64-bit write when issuing the
975 * reset, so use IO-mapping as a workaround.
977 E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
981 * After MAC reset, force reload of NVM to restore power-on
982 * settings to device.
984 hw->nvm.ops.reload(hw);
985 msec_delay(2);
987 /* Masking off and clearing any pending interrupts */
988 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
989 icr = E1000_READ_REG(hw, E1000_ICR);
991 return ret_val;
995 * e1000_init_hw_82543 - Initialize hardware
996 * @hw: pointer to the HW structure
998 * This inits the hardware readying it for operation.
1000 static s32 e1000_init_hw_82543(struct e1000_hw *hw)
1002 struct e1000_mac_info *mac = &hw->mac;
1003 struct e1000_dev_spec_82543 *dev_spec;
1004 u32 ctrl;
1005 s32 ret_val;
1006 u16 i;
1008 DEBUGFUNC("e1000_init_hw_82543");
1010 dev_spec = (struct e1000_dev_spec_82543 *)hw->dev_spec;
1012 if (!dev_spec) {
1013 DEBUGOUT("dev_spec pointer is set to NULL.\n");
1014 ret_val = -E1000_ERR_CONFIG;
1015 goto out;
1018 /* Disabling VLAN filtering */
1019 E1000_WRITE_REG(hw, E1000_VET, 0);
1020 mac->ops.clear_vfta(hw);
1022 /* Setup the receive address. */
1023 e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
1025 /* Zero out the Multicast HASH table */
1026 DEBUGOUT("Zeroing the MTA\n");
1027 for (i = 0; i < mac->mta_reg_count; i++) {
1028 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
1029 E1000_WRITE_FLUSH(hw);
1033 * Set the PCI priority bit correctly in the CTRL register. This
1034 * determines if the adapter gives priority to receives, or if it
1035 * gives equal priority to transmits and receives.
1037 if (hw->mac.type == e1000_82543 && dev_spec->dma_fairness) {
1038 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1039 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PRIOR);
1042 e1000_pcix_mmrbc_workaround_generic(hw);
1044 /* Setup link and flow control */
1045 ret_val = mac->ops.setup_link(hw);
1048 * Clear all of the statistics registers (clear on read). It is
1049 * important that we do this after we have tried to establish link
1050 * because the symbol error count will increment wildly if there
1051 * is no link.
1053 e1000_clear_hw_cntrs_82543(hw);
1055 out:
1056 return ret_val;
1060 * e1000_setup_link_82543 - Setup flow control and link settings
1061 * @hw: pointer to the HW structure
1063 * Read the EEPROM to determine the initial polarity value and write the
1064 * extended device control register with the information before calling
1065 * the generic setup link function, which does the following:
1066 * Determines which flow control settings to use, then configures flow
1067 * control. Calls the appropriate media-specific link configuration
1068 * function. Assuming the adapter has a valid link partner, a valid link
1069 * should be established. Assumes the hardware has previously been reset
1070 * and the transmitter and receiver are not enabled.
1072 static s32 e1000_setup_link_82543(struct e1000_hw *hw)
1074 u32 ctrl_ext;
1075 s32 ret_val;
1076 u16 data;
1078 DEBUGFUNC("e1000_setup_link_82543");
1081 * Take the 4 bits from NVM word 0xF that determine the initial
1082 * polarity value for the SW controlled pins, and setup the
1083 * Extended Device Control reg with that info.
1084 * This is needed because one of the SW controlled pins is used for
1085 * signal detection. So this should be done before phy setup.
1087 if (hw->mac.type == e1000_82543) {
1088 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &data);
1089 if (ret_val) {
1090 DEBUGOUT("NVM Read Error\n");
1091 ret_val = -E1000_ERR_NVM;
1092 goto out;
1094 ctrl_ext = ((data & NVM_WORD0F_SWPDIO_EXT_MASK) <<
1095 NVM_SWDPIO_EXT_SHIFT);
1096 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1099 ret_val = e1000_setup_link_generic(hw);
1101 out:
1102 return ret_val;
1106 * e1000_setup_copper_link_82543 - Configure copper link settings
1107 * @hw: pointer to the HW structure
1109 * Configures the link for auto-neg or forced speed and duplex. Then we check
1110 * for link, once link is established calls to configure collision distance
1111 * and flow control are called.
1113 static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw)
1115 u32 ctrl;
1116 s32 ret_val;
1117 bool link;
1119 DEBUGFUNC("e1000_setup_copper_link_82543");
1121 ctrl = E1000_READ_REG(hw, E1000_CTRL) | E1000_CTRL_SLU;
1123 * With 82543, we need to force speed and duplex on the MAC
1124 * equal to what the PHY speed and duplex configuration is.
1125 * In addition, we need to perform a hardware reset on the
1126 * PHY to take it out of reset.
1128 if (hw->mac.type == e1000_82543) {
1129 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1130 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1131 ret_val = hw->phy.ops.reset(hw);
1132 if (ret_val)
1133 goto out;
1134 hw->phy.reset_disable = FALSE;
1135 } else {
1136 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1137 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1140 /* Set MDI/MDI-X, Polarity Reversal, and downshift settings */
1141 ret_val = e1000_copper_link_setup_m88(hw);
1142 if (ret_val)
1143 goto out;
1145 if (hw->mac.autoneg) {
1147 * Setup autoneg and flow control advertisement and perform
1148 * autonegotiation.
1150 ret_val = e1000_copper_link_autoneg(hw);
1151 if (ret_val)
1152 goto out;
1153 } else {
1155 * PHY will be set to 10H, 10F, 100H or 100F
1156 * depending on user settings.
1158 DEBUGOUT("Forcing Speed and Duplex\n");
1159 ret_val = e1000_phy_force_speed_duplex_82543(hw);
1160 if (ret_val) {
1161 DEBUGOUT("Error Forcing Speed and Duplex\n");
1162 goto out;
1167 * Check link status. Wait up to 100 microseconds for link to become
1168 * valid.
1170 ret_val = e1000_phy_has_link_generic(hw,
1171 COPPER_LINK_UP_LIMIT,
1173 &link);
1174 if (ret_val)
1175 goto out;
1178 if (link) {
1179 DEBUGOUT("Valid link established!!!\n");
1180 /* Config the MAC and PHY after link is up */
1181 if (hw->mac.type == e1000_82544) {
1182 e1000_config_collision_dist_generic(hw);
1183 } else {
1184 ret_val = e1000_config_mac_to_phy_82543(hw);
1185 if (ret_val)
1186 goto out;
1188 ret_val = e1000_config_fc_after_link_up_generic(hw);
1189 } else {
1190 DEBUGOUT("Unable to establish link!!!\n");
1193 out:
1194 return ret_val;
1198 * e1000_setup_fiber_link_82543 - Setup link for fiber
1199 * @hw: pointer to the HW structure
1201 * Configures collision distance and flow control for fiber links. Upon
1202 * successful setup, poll for link.
1204 static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw)
1206 u32 ctrl;
1207 s32 ret_val;
1209 DEBUGFUNC("e1000_setup_fiber_link_82543");
1211 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1213 /* Take the link out of reset */
1214 ctrl &= ~E1000_CTRL_LRST;
1216 e1000_config_collision_dist_generic(hw);
1218 ret_val = e1000_commit_fc_settings_generic(hw);
1219 if (ret_val)
1220 goto out;
1222 DEBUGOUT("Auto-negotiation enabled\n");
1224 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1225 E1000_WRITE_FLUSH(hw);
1226 msec_delay(1);
1229 * For these adapters, the SW definable pin 1 is cleared when the
1230 * optics detect a signal. If we have a signal, then poll for a
1231 * "Link-Up" indication.
1233 if (!(E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) {
1234 ret_val = e1000_poll_fiber_serdes_link_generic(hw);
1235 } else {
1236 DEBUGOUT("No signal detected\n");
1239 out:
1240 return ret_val;
1244 * e1000_check_for_copper_link_82543 - Check for link (Copper)
1245 * @hw: pointer to the HW structure
1247 * Checks the phy for link, if link exists, do the following:
1248 * - check for downshift
1249 * - do polarity workaround (if necessary)
1250 * - configure collision distance
1251 * - configure flow control after link up
1252 * - configure tbi compatibility
1254 static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw)
1256 struct e1000_mac_info *mac = &hw->mac;
1257 u32 icr, rctl;
1258 s32 ret_val;
1259 u16 speed, duplex;
1260 bool link;
1262 DEBUGFUNC("e1000_check_for_copper_link_82543");
1264 if (!mac->get_link_status) {
1265 ret_val = E1000_SUCCESS;
1266 goto out;
1269 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
1270 if (ret_val)
1271 goto out;
1273 if (!link)
1274 goto out; /* No link detected */
1276 mac->get_link_status = FALSE;
1278 e1000_check_downshift_generic(hw);
1281 * If we are forcing speed/duplex, then we can return since
1282 * we have already determined whether we have link or not.
1284 if (!mac->autoneg) {
1286 * If speed and duplex are forced to 10H or 10F, then we will
1287 * implement the polarity reversal workaround. We disable
1288 * interrupts first, and upon returning, place the devices
1289 * interrupt state to its previous value except for the link
1290 * status change interrupt which will happened due to the
1291 * execution of this workaround.
1293 if (mac->forced_speed_duplex & E1000_ALL_10_SPEED) {
1294 E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);
1295 ret_val = e1000_polarity_reversal_workaround_82543(hw);
1296 icr = E1000_READ_REG(hw, E1000_ICR);
1297 E1000_WRITE_REG(hw, E1000_ICS, (icr & ~E1000_ICS_LSC));
1298 E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK);
1301 ret_val = -E1000_ERR_CONFIG;
1302 goto out;
1306 * We have a M88E1000 PHY and Auto-Neg is enabled. If we
1307 * have Si on board that is 82544 or newer, Auto
1308 * Speed Detection takes care of MAC speed/duplex
1309 * configuration. So we only need to configure Collision
1310 * Distance in the MAC. Otherwise, we need to force
1311 * speed/duplex on the MAC to the current PHY speed/duplex
1312 * settings.
1314 if (mac->type == e1000_82544)
1315 e1000_config_collision_dist_generic(hw);
1316 else {
1317 ret_val = e1000_config_mac_to_phy_82543(hw);
1318 if (ret_val) {
1319 DEBUGOUT("Error configuring MAC to PHY settings\n");
1320 goto out;
1325 * Configure Flow Control now that Auto-Neg has completed.
1326 * First, we need to restore the desired flow control
1327 * settings because we may have had to re-autoneg with a
1328 * different link partner.
1330 ret_val = e1000_config_fc_after_link_up_generic(hw);
1331 if (ret_val) {
1332 DEBUGOUT("Error configuring flow control\n");
1336 * At this point we know that we are on copper and we have
1337 * auto-negotiated link. These are conditions for checking the link
1338 * partner capability register. We use the link speed to determine if
1339 * TBI compatibility needs to be turned on or off. If the link is not
1340 * at gigabit speed, then TBI compatibility is not needed. If we are
1341 * at gigabit speed, we turn on TBI compatibility.
1343 if (e1000_tbi_compatibility_enabled_82543(hw)) {
1344 ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
1345 if (ret_val) {
1346 DEBUGOUT("Error getting link speed and duplex\n");
1347 return ret_val;
1349 if (speed != SPEED_1000) {
1351 * If link speed is not set to gigabit speed,
1352 * we do not need to enable TBI compatibility.
1354 if (e1000_tbi_sbp_enabled_82543(hw)) {
1356 * If we previously were in the mode,
1357 * turn it off.
1359 e1000_set_tbi_sbp_82543(hw, FALSE);
1360 rctl = E1000_READ_REG(hw, E1000_RCTL);
1361 rctl &= ~E1000_RCTL_SBP;
1362 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1364 } else {
1366 * If TBI compatibility is was previously off,
1367 * turn it on. For compatibility with a TBI link
1368 * partner, we will store bad packets. Some
1369 * frames have an additional byte on the end and
1370 * will look like CRC errors to to the hardware.
1372 if (!e1000_tbi_sbp_enabled_82543(hw)) {
1373 e1000_set_tbi_sbp_82543(hw, TRUE);
1374 rctl = E1000_READ_REG(hw, E1000_RCTL);
1375 rctl |= E1000_RCTL_SBP;
1376 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1380 out:
1381 return ret_val;
1385 * e1000_check_for_fiber_link_82543 - Check for link (Fiber)
1386 * @hw: pointer to the HW structure
1388 * Checks for link up on the hardware. If link is not up and we have
1389 * a signal, then we need to force link up.
1391 static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw)
1393 struct e1000_mac_info *mac = &hw->mac;
1394 u32 rxcw, ctrl, status;
1395 s32 ret_val = E1000_SUCCESS;
1397 DEBUGFUNC("e1000_check_for_fiber_link_82543");
1399 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1400 status = E1000_READ_REG(hw, E1000_STATUS);
1401 rxcw = E1000_READ_REG(hw, E1000_RXCW);
1404 * If we don't have link (auto-negotiation failed or link partner
1405 * cannot auto-negotiate), the cable is plugged in (we have signal),
1406 * and our link partner is not trying to auto-negotiate with us (we
1407 * are receiving idles or data), we need to force link up. We also
1408 * need to give auto-negotiation time to complete, in case the cable
1409 * was just plugged in. The autoneg_failed flag does this.
1411 /* (ctrl & E1000_CTRL_SWDPIN1) == 0 == have signal */
1412 if ((!(ctrl & E1000_CTRL_SWDPIN1)) &&
1413 (!(status & E1000_STATUS_LU)) &&
1414 (!(rxcw & E1000_RXCW_C))) {
1415 if (mac->autoneg_failed == 0) {
1416 mac->autoneg_failed = 1;
1417 ret_val = 0;
1418 goto out;
1420 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
1422 /* Disable auto-negotiation in the TXCW register */
1423 E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
1425 /* Force link-up and also force full-duplex. */
1426 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1427 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
1428 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1430 /* Configure Flow Control after forcing link up. */
1431 ret_val = e1000_config_fc_after_link_up_generic(hw);
1432 if (ret_val) {
1433 DEBUGOUT("Error configuring flow control\n");
1434 goto out;
1436 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
1438 * If we are forcing link and we are receiving /C/ ordered
1439 * sets, re-enable auto-negotiation in the TXCW register
1440 * and disable forced link in the Device Control register
1441 * in an attempt to auto-negotiate with our link partner.
1443 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
1444 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
1445 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
1447 mac->serdes_has_link = TRUE;
1450 out:
1451 return ret_val;
1455 * e1000_config_mac_to_phy_82543 - Configure MAC to PHY settings
1456 * @hw: pointer to the HW structure
1458 * For the 82543 silicon, we need to set the MAC to match the settings
1459 * of the PHY, even if the PHY is auto-negotiating.
1461 static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw)
1463 u32 ctrl;
1464 s32 ret_val = E1000_SUCCESS;
1465 u16 phy_data;
1467 DEBUGFUNC("e1000_config_mac_to_phy_82543");
1469 if (!(hw->phy.ops.read_reg))
1470 goto out;
1472 /* Set the bits to force speed and duplex */
1473 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1474 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1475 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1478 * Set up duplex in the Device Control and Transmit Control
1479 * registers depending on negotiated values.
1481 ret_val = hw->phy.ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1482 if (ret_val)
1483 goto out;
1485 ctrl &= ~E1000_CTRL_FD;
1486 if (phy_data & M88E1000_PSSR_DPLX)
1487 ctrl |= E1000_CTRL_FD;
1489 e1000_config_collision_dist_generic(hw);
1492 * Set up speed in the Device Control register depending on
1493 * negotiated values.
1495 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1496 ctrl |= E1000_CTRL_SPD_1000;
1497 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1498 ctrl |= E1000_CTRL_SPD_100;
1500 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1502 out:
1503 return ret_val;
1507 * e1000_write_vfta_82543 - Write value to VLAN filter table
1508 * @hw: pointer to the HW structure
1509 * @offset: the 32-bit offset in which to write the value to.
1510 * @value: the 32-bit value to write at location offset.
1512 * This writes a 32-bit value to a 32-bit offset in the VLAN filter
1513 * table.
1515 static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset, u32 value)
1517 u32 temp;
1519 DEBUGFUNC("e1000_write_vfta_82543");
1521 if ((hw->mac.type == e1000_82544) && (offset & 1)) {
1522 temp = E1000_READ_REG_ARRAY(hw, E1000_VFTA, offset - 1);
1523 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
1524 E1000_WRITE_FLUSH(hw);
1525 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset - 1, temp);
1526 E1000_WRITE_FLUSH(hw);
1527 } else {
1528 e1000_write_vfta_generic(hw, offset, value);
1533 * e1000_mta_set_82543 - Set multicast filter table address
1534 * @hw: pointer to the HW structure
1535 * @hash_value: determines the MTA register and bit to set
1537 * The multicast table address is a register array of 32-bit registers.
1538 * The hash_value is used to determine what register the bit is in, the
1539 * current value is read, the new bit is OR'd in and the new value is
1540 * written back into the register.
1542 static void e1000_mta_set_82543(struct e1000_hw *hw, u32 hash_value)
1544 u32 hash_bit, hash_reg, mta, temp;
1546 DEBUGFUNC("e1000_mta_set_82543");
1548 hash_reg = (hash_value >> 5);
1551 * If we are on an 82544 and we are trying to write an odd offset
1552 * in the MTA, save off the previous entry before writing and
1553 * restore the old value after writing.
1555 if ((hw->mac.type == e1000_82544) && (hash_reg & 1)) {
1556 hash_reg &= (hw->mac.mta_reg_count - 1);
1557 hash_bit = hash_value & 0x1F;
1558 mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
1559 mta |= (1 << hash_bit);
1560 temp = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg - 1);
1562 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
1563 E1000_WRITE_FLUSH(hw);
1564 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg - 1, temp);
1565 E1000_WRITE_FLUSH(hw);
1566 } else {
1567 e1000_mta_set_generic(hw, hash_value);
1572 * e1000_led_on_82543 - Turn on SW controllable LED
1573 * @hw: pointer to the HW structure
1575 * Turns the SW defined LED on. This is a function pointer entry point
1576 * called by the api module.
1578 static s32 e1000_led_on_82543(struct e1000_hw *hw)
1580 u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1582 DEBUGFUNC("e1000_led_on_82543");
1584 if (hw->mac.type == e1000_82544 &&
1585 hw->phy.media_type == e1000_media_type_copper) {
1586 /* Clear SW-definable Pin 0 to turn on the LED */
1587 ctrl &= ~E1000_CTRL_SWDPIN0;
1588 ctrl |= E1000_CTRL_SWDPIO0;
1589 } else {
1590 /* Fiber 82544 and all 82543 use this method */
1591 ctrl |= E1000_CTRL_SWDPIN0;
1592 ctrl |= E1000_CTRL_SWDPIO0;
1594 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1596 return E1000_SUCCESS;
1600 * e1000_led_off_82543 - Turn off SW controllable LED
1601 * @hw: pointer to the HW structure
1603 * Turns the SW defined LED off. This is a function pointer entry point
1604 * called by the api module.
1606 static s32 e1000_led_off_82543(struct e1000_hw *hw)
1608 u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1610 DEBUGFUNC("e1000_led_off_82543");
1612 if (hw->mac.type == e1000_82544 &&
1613 hw->phy.media_type == e1000_media_type_copper) {
1614 /* Set SW-definable Pin 0 to turn off the LED */
1615 ctrl |= E1000_CTRL_SWDPIN0;
1616 ctrl |= E1000_CTRL_SWDPIO0;
1617 } else {
1618 ctrl &= ~E1000_CTRL_SWDPIN0;
1619 ctrl |= E1000_CTRL_SWDPIO0;
1621 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1623 return E1000_SUCCESS;
1627 * e1000_clear_hw_cntrs_82543 - Clear device specific hardware counters
1628 * @hw: pointer to the HW structure
1630 * Clears the hardware counters by reading the counter registers.
1632 static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw)
1634 volatile u32 temp;
1636 DEBUGFUNC("e1000_clear_hw_cntrs_82543");
1638 e1000_clear_hw_cntrs_base_generic(hw);
1640 temp = E1000_READ_REG(hw, E1000_PRC64);
1641 temp = E1000_READ_REG(hw, E1000_PRC127);
1642 temp = E1000_READ_REG(hw, E1000_PRC255);
1643 temp = E1000_READ_REG(hw, E1000_PRC511);
1644 temp = E1000_READ_REG(hw, E1000_PRC1023);
1645 temp = E1000_READ_REG(hw, E1000_PRC1522);
1646 temp = E1000_READ_REG(hw, E1000_PTC64);
1647 temp = E1000_READ_REG(hw, E1000_PTC127);
1648 temp = E1000_READ_REG(hw, E1000_PTC255);
1649 temp = E1000_READ_REG(hw, E1000_PTC511);
1650 temp = E1000_READ_REG(hw, E1000_PTC1023);
1651 temp = E1000_READ_REG(hw, E1000_PTC1522);
1653 temp = E1000_READ_REG(hw, E1000_ALGNERRC);
1654 temp = E1000_READ_REG(hw, E1000_RXERRC);
1655 temp = E1000_READ_REG(hw, E1000_TNCRS);
1656 temp = E1000_READ_REG(hw, E1000_CEXTERR);
1657 temp = E1000_READ_REG(hw, E1000_TSCTC);
1658 temp = E1000_READ_REG(hw, E1000_TSCTFC);