revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / networks / e1000 / e1000_82543.c
blob164e93c857cdc065dba407a4821eb44602b8066f
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
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 *******************************************************************************/
30 * 82543GC Gigabit Ethernet Controller (Fiber)
31 * 82543GC Gigabit Ethernet Controller (Copper)
32 * 82544EI Gigabit Ethernet Controller (Copper)
33 * 82544EI Gigabit Ethernet Controller (Fiber)
34 * 82544GC Gigabit Ethernet Controller (Copper)
35 * 82544GC Gigabit Ethernet Controller (LOM)
38 #include "e1000_api.h"
40 static s32 e1000_init_phy_params_82543(struct e1000_hw *hw);
41 static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw);
42 static s32 e1000_init_mac_params_82543(struct e1000_hw *hw);
43 static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset,
44 u16 *data);
45 static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset,
46 u16 data);
47 static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw);
48 static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw);
49 static s32 e1000_reset_hw_82543(struct e1000_hw *hw);
50 static s32 e1000_init_hw_82543(struct e1000_hw *hw);
51 static s32 e1000_setup_link_82543(struct e1000_hw *hw);
52 static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw);
53 static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw);
54 static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw);
55 static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw);
56 static s32 e1000_led_on_82543(struct e1000_hw *hw);
57 static s32 e1000_led_off_82543(struct e1000_hw *hw);
58 static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset,
59 u32 value);
60 static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw);
61 static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw);
62 static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw);
63 static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl);
64 static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw);
65 static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl);
66 static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw);
67 static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data,
68 u16 count);
69 static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw);
70 static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state);
72 /**
73 * e1000_init_phy_params_82543 - Init PHY func ptrs.
74 * @hw: pointer to the HW structure
75 **/
76 static s32 e1000_init_phy_params_82543(struct e1000_hw *hw)
78 struct e1000_phy_info *phy = &hw->phy;
79 s32 ret_val = E1000_SUCCESS;
81 DEBUGFUNC("e1000_init_phy_params_82543");
83 if (hw->phy.media_type != e1000_media_type_copper) {
84 phy->type = e1000_phy_none;
85 goto out;
86 } else {
87 phy->ops.power_up = e1000_power_up_phy_copper;
88 phy->ops.power_down = e1000_power_down_phy_copper;
91 phy->addr = 1;
92 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
93 phy->reset_delay_us = 10000;
94 phy->type = e1000_phy_m88;
96 /* Function Pointers */
97 phy->ops.check_polarity = e1000_check_polarity_m88;
98 phy->ops.commit = e1000_phy_sw_reset_generic;
99 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_82543;
100 phy->ops.get_cable_length = e1000_get_cable_length_m88;
101 phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
102 phy->ops.read_reg = (hw->mac.type == e1000_82543)
103 ? e1000_read_phy_reg_82543
104 : e1000_read_phy_reg_m88;
105 phy->ops.reset = (hw->mac.type == e1000_82543)
106 ? e1000_phy_hw_reset_82543
107 : e1000_phy_hw_reset_generic;
108 phy->ops.write_reg = (hw->mac.type == e1000_82543)
109 ? e1000_write_phy_reg_82543
110 : e1000_write_phy_reg_m88;
111 phy->ops.get_info = e1000_get_phy_info_m88;
114 * The external PHY of the 82543 can be in a funky state.
115 * Resetting helps us read the PHY registers for acquiring
116 * the PHY ID.
118 if (!e1000_init_phy_disabled_82543(hw)) {
119 ret_val = phy->ops.reset(hw);
120 if (ret_val) {
121 DEBUGOUT("Resetting PHY during init failed.\n");
122 goto out;
124 msec_delay(20);
127 ret_val = e1000_get_phy_id(hw);
128 if (ret_val)
129 goto out;
131 /* Verify phy id */
132 switch (hw->mac.type) {
133 case e1000_82543:
134 if (phy->id != M88E1000_E_PHY_ID) {
135 ret_val = -E1000_ERR_PHY;
136 goto out;
138 break;
139 case e1000_82544:
140 if (phy->id != M88E1000_I_PHY_ID) {
141 ret_val = -E1000_ERR_PHY;
142 goto out;
144 break;
145 default:
146 ret_val = -E1000_ERR_PHY;
147 goto out;
148 break;
151 out:
152 return ret_val;
156 * e1000_init_nvm_params_82543 - Init NVM func ptrs.
157 * @hw: pointer to the HW structure
159 static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw)
161 struct e1000_nvm_info *nvm = &hw->nvm;
163 DEBUGFUNC("e1000_init_nvm_params_82543");
165 nvm->type = e1000_nvm_eeprom_microwire;
166 nvm->word_size = 64;
167 nvm->delay_usec = 50;
168 nvm->address_bits = 6;
169 nvm->opcode_bits = 3;
171 /* Function Pointers */
172 nvm->ops.read = e1000_read_nvm_microwire;
173 nvm->ops.update = e1000_update_nvm_checksum_generic;
174 nvm->ops.valid_led_default = e1000_valid_led_default_generic;
175 nvm->ops.validate = e1000_validate_nvm_checksum_generic;
176 nvm->ops.write = e1000_write_nvm_microwire;
178 return E1000_SUCCESS;
182 * e1000_init_mac_params_82543 - Init MAC func ptrs.
183 * @hw: pointer to the HW structure
185 static s32 e1000_init_mac_params_82543(struct e1000_hw *hw)
187 struct e1000_mac_info *mac = &hw->mac;
189 DEBUGFUNC("e1000_init_mac_params_82543");
191 /* Set media type */
192 switch (hw->device_id) {
193 case E1000_DEV_ID_82543GC_FIBER:
194 case E1000_DEV_ID_82544EI_FIBER:
195 hw->phy.media_type = e1000_media_type_fiber;
196 break;
197 default:
198 hw->phy.media_type = e1000_media_type_copper;
199 break;
202 /* Set mta register count */
203 mac->mta_reg_count = 128;
204 /* Set rar entry count */
205 mac->rar_entry_count = E1000_RAR_ENTRIES;
207 /* Function pointers */
209 /* bus type/speed/width */
210 mac->ops.get_bus_info = e1000_get_bus_info_pci_generic;
211 /* function id */
212 mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pci;
213 /* reset */
214 mac->ops.reset_hw = e1000_reset_hw_82543;
215 /* hw initialization */
216 mac->ops.init_hw = e1000_init_hw_82543;
217 /* link setup */
218 mac->ops.setup_link = e1000_setup_link_82543;
219 /* physical interface setup */
220 mac->ops.setup_physical_interface =
221 (hw->phy.media_type == e1000_media_type_copper)
222 ? e1000_setup_copper_link_82543
223 : e1000_setup_fiber_link_82543;
224 /* check for link */
225 mac->ops.check_for_link =
226 (hw->phy.media_type == e1000_media_type_copper)
227 ? e1000_check_for_copper_link_82543
228 : e1000_check_for_fiber_link_82543;
229 /* link info */
230 mac->ops.get_link_up_info =
231 (hw->phy.media_type == e1000_media_type_copper)
232 ? e1000_get_speed_and_duplex_copper_generic
233 : e1000_get_speed_and_duplex_fiber_serdes_generic;
234 /* multicast address update */
235 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
236 /* writing VFTA */
237 mac->ops.write_vfta = e1000_write_vfta_82543;
238 /* clearing VFTA */
239 mac->ops.clear_vfta = e1000_clear_vfta_generic;
240 /* turn on/off LED */
241 mac->ops.led_on = e1000_led_on_82543;
242 mac->ops.led_off = e1000_led_off_82543;
243 /* clear hardware counters */
244 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82543;
246 /* Set tbi compatibility */
247 if ((hw->mac.type != e1000_82543) ||
248 (hw->phy.media_type == e1000_media_type_fiber))
249 e1000_set_tbi_compatibility_82543(hw, false);
251 return E1000_SUCCESS;
255 * e1000_init_function_pointers_82543 - Init func ptrs.
256 * @hw: pointer to the HW structure
258 * Called to initialize all function pointers and parameters.
260 void e1000_init_function_pointers_82543(struct e1000_hw *hw)
262 DEBUGFUNC("e1000_init_function_pointers_82543");
264 hw->mac.ops.init_params = e1000_init_mac_params_82543;
265 hw->nvm.ops.init_params = e1000_init_nvm_params_82543;
266 hw->phy.ops.init_params = e1000_init_phy_params_82543;
270 * e1000_tbi_compatibility_enabled_82543 - Returns TBI compat status
271 * @hw: pointer to the HW structure
273 * Returns the current status of 10-bit Interface (TBI) compatibility
274 * (enabled/disabled).
276 static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw)
278 struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
279 bool state = false;
281 DEBUGFUNC("e1000_tbi_compatibility_enabled_82543");
283 if (hw->mac.type != e1000_82543) {
284 DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
285 goto out;
288 state = (dev_spec->tbi_compatibility & TBI_COMPAT_ENABLED)
289 ? true : false;
291 out:
292 return state;
296 * e1000_set_tbi_compatibility_82543 - Set TBI compatibility
297 * @hw: pointer to the HW structure
298 * @state: enable/disable TBI compatibility
300 * Enables or disabled 10-bit Interface (TBI) compatibility.
302 void e1000_set_tbi_compatibility_82543(struct e1000_hw *hw, bool state)
304 struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
306 DEBUGFUNC("e1000_set_tbi_compatibility_82543");
308 if (hw->mac.type != e1000_82543) {
309 DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
310 goto out;
313 if (state)
314 dev_spec->tbi_compatibility |= TBI_COMPAT_ENABLED;
315 else
316 dev_spec->tbi_compatibility &= ~TBI_COMPAT_ENABLED;
318 out:
319 return;
323 * e1000_tbi_sbp_enabled_82543 - Returns TBI SBP status
324 * @hw: pointer to the HW structure
326 * Returns the current status of 10-bit Interface (TBI) store bad packet (SBP)
327 * (enabled/disabled).
329 bool e1000_tbi_sbp_enabled_82543(struct e1000_hw *hw)
331 struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
332 bool state = false;
334 DEBUGFUNC("e1000_tbi_sbp_enabled_82543");
336 if (hw->mac.type != e1000_82543) {
337 DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
338 goto out;
341 state = (dev_spec->tbi_compatibility & TBI_SBP_ENABLED)
342 ? true : false;
344 out:
345 return state;
349 * e1000_set_tbi_sbp_82543 - Set TBI SBP
350 * @hw: pointer to the HW structure
351 * @state: enable/disable TBI store bad packet
353 * Enables or disabled 10-bit Interface (TBI) store bad packet (SBP).
355 static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state)
357 struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
359 DEBUGFUNC("e1000_set_tbi_sbp_82543");
361 if (state && e1000_tbi_compatibility_enabled_82543(hw))
362 dev_spec->tbi_compatibility |= TBI_SBP_ENABLED;
363 else
364 dev_spec->tbi_compatibility &= ~TBI_SBP_ENABLED;
366 return;
370 * e1000_init_phy_disabled_82543 - Returns init PHY status
371 * @hw: pointer to the HW structure
373 * Returns the current status of whether PHY initialization is disabled.
374 * True if PHY initialization is disabled else false.
376 static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw)
378 struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
379 bool ret_val;
381 DEBUGFUNC("e1000_init_phy_disabled_82543");
383 if (hw->mac.type != e1000_82543) {
384 ret_val = false;
385 goto out;
388 ret_val = dev_spec->init_phy_disabled;
390 out:
391 return ret_val;
395 * e1000_tbi_adjust_stats_82543 - Adjust stats when TBI enabled
396 * @hw: pointer to the HW structure
397 * @stats: Struct containing statistic register values
398 * @frame_len: The length of the frame in question
399 * @mac_addr: The Ethernet destination address of the frame in question
400 * @max_frame_size: The maximum frame size
402 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
404 void e1000_tbi_adjust_stats_82543(struct e1000_hw *hw,
405 struct e1000_hw_stats *stats, u32 frame_len,
406 u8 *mac_addr, u32 max_frame_size)
408 if (!(e1000_tbi_sbp_enabled_82543(hw)))
409 goto out;
411 /* First adjust the frame length. */
412 frame_len--;
414 * We need to adjust the statistics counters, since the hardware
415 * counters overcount this packet as a CRC error and undercount
416 * the packet as a good packet
418 /* This packet should not be counted as a CRC error. */
419 stats->crcerrs--;
420 /* This packet does count as a Good Packet Received. */
421 stats->gprc++;
423 /* Adjust the Good Octets received counters */
424 stats->gorc += frame_len;
427 * Is this a broadcast or multicast? Check broadcast first,
428 * since the test for a multicast frame will test positive on
429 * a broadcast frame.
431 if ((mac_addr[0] == 0xff) && (mac_addr[1] == 0xff))
432 /* Broadcast packet */
433 stats->bprc++;
434 else if (*mac_addr & 0x01)
435 /* Multicast packet */
436 stats->mprc++;
439 * In this case, the hardware has overcounted the number of
440 * oversize frames.
442 if ((frame_len == max_frame_size) && (stats->roc > 0))
443 stats->roc--;
446 * Adjust the bin counters when the extra byte put the frame in the
447 * wrong bin. Remember that the frame_len was adjusted above.
449 if (frame_len == 64) {
450 stats->prc64++;
451 stats->prc127--;
452 } else if (frame_len == 127) {
453 stats->prc127++;
454 stats->prc255--;
455 } else if (frame_len == 255) {
456 stats->prc255++;
457 stats->prc511--;
458 } else if (frame_len == 511) {
459 stats->prc511++;
460 stats->prc1023--;
461 } else if (frame_len == 1023) {
462 stats->prc1023++;
463 stats->prc1522--;
464 } else if (frame_len == 1522) {
465 stats->prc1522++;
468 out:
469 return;
473 * e1000_read_phy_reg_82543 - Read PHY register
474 * @hw: pointer to the HW structure
475 * @offset: register offset to be read
476 * @data: pointer to the read data
478 * Reads the PHY at offset and stores the information read to data.
480 static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 *data)
482 u32 mdic;
483 s32 ret_val = E1000_SUCCESS;
485 DEBUGFUNC("e1000_read_phy_reg_82543");
487 if (offset > MAX_PHY_REG_ADDRESS) {
488 DEBUGOUT1("PHY Address %d is out of range\n", offset);
489 ret_val = -E1000_ERR_PARAM;
490 goto out;
494 * We must first send a preamble through the MDIO pin to signal the
495 * beginning of an MII instruction. This is done by sending 32
496 * consecutive "1" bits.
498 e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
501 * Now combine the next few fields that are required for a read
502 * operation. We use this method instead of calling the
503 * e1000_shift_out_mdi_bits routine five different times. The format
504 * of an MII read instruction consists of a shift out of 14 bits and
505 * is defined as follows:
506 * <Preamble><SOF><Op Code><Phy Addr><Offset>
507 * followed by a shift in of 18 bits. This first two bits shifted in
508 * are TurnAround bits used to avoid contention on the MDIO pin when a
509 * READ operation is performed. These two bits are thrown away
510 * followed by a shift in of 16 bits which contains the desired data.
512 mdic = (offset | (hw->phy.addr << 5) |
513 (PHY_OP_READ << 10) | (PHY_SOF << 12));
515 e1000_shift_out_mdi_bits_82543(hw, mdic, 14);
518 * Now that we've shifted out the read command to the MII, we need to
519 * "shift in" the 16-bit value (18 total bits) of the requested PHY
520 * register address.
522 *data = e1000_shift_in_mdi_bits_82543(hw);
524 out:
525 return ret_val;
529 * e1000_write_phy_reg_82543 - Write PHY register
530 * @hw: pointer to the HW structure
531 * @offset: register offset to be written
532 * @data: pointer to the data to be written at offset
534 * Writes data to the PHY at offset.
536 static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 data)
538 u32 mdic;
539 s32 ret_val = E1000_SUCCESS;
541 DEBUGFUNC("e1000_write_phy_reg_82543");
543 if (offset > MAX_PHY_REG_ADDRESS) {
544 DEBUGOUT1("PHY Address %d is out of range\n", offset);
545 ret_val = -E1000_ERR_PARAM;
546 goto out;
550 * We'll need to use the SW defined pins to shift the write command
551 * out to the PHY. We first send a preamble to the PHY to signal the
552 * beginning of the MII instruction. This is done by sending 32
553 * consecutive "1" bits.
555 e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
558 * Now combine the remaining required fields that will indicate a
559 * write operation. We use this method instead of calling the
560 * e1000_shift_out_mdi_bits routine for each field in the command. The
561 * format of a MII write instruction is as follows:
562 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
564 mdic = ((PHY_TURNAROUND) | (offset << 2) | (hw->phy.addr << 7) |
565 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
566 mdic <<= 16;
567 mdic |= (u32) data;
569 e1000_shift_out_mdi_bits_82543(hw, mdic, 32);
571 out:
572 return ret_val;
576 * e1000_raise_mdi_clk_82543 - Raise Management Data Input clock
577 * @hw: pointer to the HW structure
578 * @ctrl: pointer to the control register
580 * Raise the management data input clock by setting the MDC bit in the control
581 * register.
583 static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl)
586 * Raise the clock input to the Management Data Clock (by setting the
587 * MDC bit), and then delay a sufficient amount of time.
589 E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl | E1000_CTRL_MDC));
590 E1000_WRITE_FLUSH(hw);
591 usec_delay(10);
595 * e1000_lower_mdi_clk_82543 - Lower Management Data Input clock
596 * @hw: pointer to the HW structure
597 * @ctrl: pointer to the control register
599 * Lower the management data input clock by clearing the MDC bit in the
600 * control register.
602 static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl)
605 * Lower the clock input to the Management Data Clock (by clearing the
606 * MDC bit), and then delay a sufficient amount of time.
608 E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl & ~E1000_CTRL_MDC));
609 E1000_WRITE_FLUSH(hw);
610 usec_delay(10);
614 * e1000_shift_out_mdi_bits_82543 - Shift data bits our to the PHY
615 * @hw: pointer to the HW structure
616 * @data: data to send to the PHY
617 * @count: number of bits to shift out
619 * We need to shift 'count' bits out to the PHY. So, the value in the
620 * "data" parameter will be shifted out to the PHY one bit at a time.
621 * In order to do this, "data" must be broken down into bits.
623 static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data,
624 u16 count)
626 u32 ctrl, mask;
629 * We need to shift "count" number of bits out to the PHY. So, the
630 * value in the "data" parameter will be shifted out to the PHY one
631 * bit at a time. In order to do this, "data" must be broken down
632 * into bits.
634 mask = 0x01;
635 mask <<= (count -1);
637 ctrl = E1000_READ_REG(hw, E1000_CTRL);
639 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
640 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
642 while (mask) {
644 * A "1" is shifted out to the PHY by setting the MDIO bit to
645 * "1" and then raising and lowering the Management Data Clock.
646 * A "0" is shifted out to the PHY by setting the MDIO bit to
647 * "0" and then raising and lowering the clock.
649 if (data & mask) ctrl |= E1000_CTRL_MDIO;
650 else ctrl &= ~E1000_CTRL_MDIO;
652 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
653 E1000_WRITE_FLUSH(hw);
655 usec_delay(10);
657 e1000_raise_mdi_clk_82543(hw, &ctrl);
658 e1000_lower_mdi_clk_82543(hw, &ctrl);
660 mask >>= 1;
665 * e1000_shift_in_mdi_bits_82543 - Shift data bits in from the PHY
666 * @hw: pointer to the HW structure
668 * In order to read a register from the PHY, we need to shift 18 bits
669 * in from the PHY. Bits are "shifted in" by raising the clock input to
670 * the PHY (setting the MDC bit), and then reading the value of the data out
671 * MDIO bit.
673 static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw)
675 u32 ctrl;
676 u16 data = 0;
677 u8 i;
680 * In order to read a register from the PHY, we need to shift in a
681 * total of 18 bits from the PHY. The first two bit (turnaround)
682 * times are used to avoid contention on the MDIO pin when a read
683 * operation is performed. These two bits are ignored by us and
684 * thrown away. Bits are "shifted in" by raising the input to the
685 * Management Data Clock (setting the MDC bit) and then reading the
686 * value of the MDIO bit.
688 ctrl = E1000_READ_REG(hw, E1000_CTRL);
691 * Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
692 * input.
694 ctrl &= ~E1000_CTRL_MDIO_DIR;
695 ctrl &= ~E1000_CTRL_MDIO;
697 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
698 E1000_WRITE_FLUSH(hw);
701 * Raise and lower the clock before reading in the data. This accounts
702 * for the turnaround bits. The first clock occurred when we clocked
703 * out the last bit of the Register Address.
705 e1000_raise_mdi_clk_82543(hw, &ctrl);
706 e1000_lower_mdi_clk_82543(hw, &ctrl);
708 for (data = 0, i = 0; i < 16; i++) {
709 data <<= 1;
710 e1000_raise_mdi_clk_82543(hw, &ctrl);
711 ctrl = E1000_READ_REG(hw, E1000_CTRL);
712 /* Check to see if we shifted in a "1". */
713 if (ctrl & E1000_CTRL_MDIO)
714 data |= 1;
715 e1000_lower_mdi_clk_82543(hw, &ctrl);
718 e1000_raise_mdi_clk_82543(hw, &ctrl);
719 e1000_lower_mdi_clk_82543(hw, &ctrl);
721 return data;
725 * e1000_phy_force_speed_duplex_82543 - Force speed/duplex for PHY
726 * @hw: pointer to the HW structure
728 * Calls the function to force speed and duplex for the m88 PHY, and
729 * if the PHY is not auto-negotiating and the speed is forced to 10Mbit,
730 * then call the function for polarity reversal workaround.
732 static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw)
734 s32 ret_val;
736 DEBUGFUNC("e1000_phy_force_speed_duplex_82543");
738 ret_val = e1000_phy_force_speed_duplex_m88(hw);
739 if (ret_val)
740 goto out;
742 if (!hw->mac.autoneg &&
743 (hw->mac.forced_speed_duplex & E1000_ALL_10_SPEED))
744 ret_val = e1000_polarity_reversal_workaround_82543(hw);
746 out:
747 return ret_val;
751 * e1000_polarity_reversal_workaround_82543 - Workaround polarity reversal
752 * @hw: pointer to the HW structure
754 * When forcing link to 10 Full or 10 Half, the PHY can reverse the polarity
755 * inadvertently. To workaround the issue, we disable the transmitter on
756 * the PHY until we have established the link partner's link parameters.
758 static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw)
760 s32 ret_val = E1000_SUCCESS;
761 u16 mii_status_reg;
762 u16 i;
763 bool link;
765 if (!(hw->phy.ops.write_reg))
766 goto out;
768 /* Polarity reversal workaround for forced 10F/10H links. */
770 /* Disable the transmitter on the PHY */
772 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
773 if (ret_val)
774 goto out;
775 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
776 if (ret_val)
777 goto out;
779 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
780 if (ret_val)
781 goto out;
784 * This loop will early-out if the NO link condition has been met.
785 * In other words, DO NOT use e1000_phy_has_link_generic() here.
787 for (i = PHY_FORCE_TIME; i > 0; i--) {
789 * Read the MII Status Register and wait for Link Status bit
790 * to be clear.
793 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
794 if (ret_val)
795 goto out;
797 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
798 if (ret_val)
799 goto out;
801 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
802 break;
803 msec_delay_irq(100);
806 /* Recommended delay time after link has been lost */
807 msec_delay_irq(1000);
809 /* Now we will re-enable the transmitter on the PHY */
811 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
812 if (ret_val)
813 goto out;
814 msec_delay_irq(50);
815 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
816 if (ret_val)
817 goto out;
818 msec_delay_irq(50);
819 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
820 if (ret_val)
821 goto out;
822 msec_delay_irq(50);
823 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
824 if (ret_val)
825 goto out;
827 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
828 if (ret_val)
829 goto out;
832 * Read the MII Status Register and wait for Link Status bit
833 * to be set.
835 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_TIME, 100000, &link);
836 if (ret_val)
837 goto out;
839 out:
840 return ret_val;
844 * e1000_phy_hw_reset_82543 - PHY hardware reset
845 * @hw: pointer to the HW structure
847 * Sets the PHY_RESET_DIR bit in the extended device control register
848 * to put the PHY into a reset and waits for completion. Once the reset
849 * has been accomplished, clear the PHY_RESET_DIR bit to take the PHY out
850 * of reset.
852 static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw)
854 u32 ctrl_ext;
855 s32 ret_val;
857 DEBUGFUNC("e1000_phy_hw_reset_82543");
860 * Read the Extended Device Control Register, assert the PHY_RESET_DIR
861 * bit to put the PHY into reset...
863 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
864 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
865 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
866 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
867 E1000_WRITE_FLUSH(hw);
869 msec_delay(10);
871 /* ...then take it out of reset. */
872 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
873 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
874 E1000_WRITE_FLUSH(hw);
876 usec_delay(150);
878 if (!(hw->phy.ops.get_cfg_done))
879 return E1000_SUCCESS;
881 ret_val = hw->phy.ops.get_cfg_done(hw);
883 return ret_val;
887 * e1000_reset_hw_82543 - Reset hardware
888 * @hw: pointer to the HW structure
890 * This resets the hardware into a known state.
892 static s32 e1000_reset_hw_82543(struct e1000_hw *hw)
894 u32 ctrl;
895 s32 ret_val = E1000_SUCCESS;
897 DEBUGFUNC("e1000_reset_hw_82543");
899 DEBUGOUT("Masking off all interrupts\n");
900 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
902 E1000_WRITE_REG(hw, E1000_RCTL, 0);
903 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
904 E1000_WRITE_FLUSH(hw);
906 e1000_set_tbi_sbp_82543(hw, false);
909 * Delay to allow any outstanding PCI transactions to complete before
910 * resetting the device
912 msec_delay(10);
914 ctrl = E1000_READ_REG(hw, E1000_CTRL);
916 DEBUGOUT("Issuing a global reset to 82543/82544 MAC\n");
917 if (hw->mac.type == e1000_82543) {
918 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
919 } else {
921 * The 82544 can't ACK the 64-bit write when issuing the
922 * reset, so use IO-mapping as a workaround.
924 E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
928 * After MAC reset, force reload of NVM to restore power-on
929 * settings to device.
931 hw->nvm.ops.reload(hw);
932 msec_delay(2);
934 /* Masking off and clearing any pending interrupts */
935 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
936 E1000_READ_REG(hw, E1000_ICR);
938 return ret_val;
942 * e1000_init_hw_82543 - Initialize hardware
943 * @hw: pointer to the HW structure
945 * This inits the hardware readying it for operation.
947 static s32 e1000_init_hw_82543(struct e1000_hw *hw)
949 struct e1000_mac_info *mac = &hw->mac;
950 struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
951 u32 ctrl;
952 s32 ret_val;
953 u16 i;
955 DEBUGFUNC("e1000_init_hw_82543");
957 /* Disabling VLAN filtering */
958 E1000_WRITE_REG(hw, E1000_VET, 0);
959 mac->ops.clear_vfta(hw);
961 /* Setup the receive address. */
962 e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
964 /* Zero out the Multicast HASH table */
965 DEBUGOUT("Zeroing the MTA\n");
966 for (i = 0; i < mac->mta_reg_count; i++) {
967 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
968 E1000_WRITE_FLUSH(hw);
972 * Set the PCI priority bit correctly in the CTRL register. This
973 * determines if the adapter gives priority to receives, or if it
974 * gives equal priority to transmits and receives.
976 if (hw->mac.type == e1000_82543 && dev_spec->dma_fairness) {
977 ctrl = E1000_READ_REG(hw, E1000_CTRL);
978 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PRIOR);
981 e1000_pcix_mmrbc_workaround_generic(hw);
983 /* Setup link and flow control */
984 ret_val = mac->ops.setup_link(hw);
987 * Clear all of the statistics registers (clear on read). It is
988 * important that we do this after we have tried to establish link
989 * because the symbol error count will increment wildly if there
990 * is no link.
992 e1000_clear_hw_cntrs_82543(hw);
994 return ret_val;
998 * e1000_setup_link_82543 - Setup flow control and link settings
999 * @hw: pointer to the HW structure
1001 * Read the EEPROM to determine the initial polarity value and write the
1002 * extended device control register with the information before calling
1003 * the generic setup link function, which does the following:
1004 * Determines which flow control settings to use, then configures flow
1005 * control. Calls the appropriate media-specific link configuration
1006 * function. Assuming the adapter has a valid link partner, a valid link
1007 * should be established. Assumes the hardware has previously been reset
1008 * and the transmitter and receiver are not enabled.
1010 static s32 e1000_setup_link_82543(struct e1000_hw *hw)
1012 u32 ctrl_ext;
1013 s32 ret_val;
1014 u16 data;
1016 DEBUGFUNC("e1000_setup_link_82543");
1019 * Take the 4 bits from NVM word 0xF that determine the initial
1020 * polarity value for the SW controlled pins, and setup the
1021 * Extended Device Control reg with that info.
1022 * This is needed because one of the SW controlled pins is used for
1023 * signal detection. So this should be done before phy setup.
1025 if (hw->mac.type == e1000_82543) {
1026 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &data);
1027 if (ret_val) {
1028 DEBUGOUT("NVM Read Error\n");
1029 ret_val = -E1000_ERR_NVM;
1030 goto out;
1032 ctrl_ext = ((data & NVM_WORD0F_SWPDIO_EXT_MASK) <<
1033 NVM_SWDPIO_EXT_SHIFT);
1034 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1037 ret_val = e1000_setup_link_generic(hw);
1039 out:
1040 return ret_val;
1044 * e1000_setup_copper_link_82543 - Configure copper link settings
1045 * @hw: pointer to the HW structure
1047 * Configures the link for auto-neg or forced speed and duplex. Then we check
1048 * for link, once link is established calls to configure collision distance
1049 * and flow control are called.
1051 static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw)
1053 u32 ctrl;
1054 s32 ret_val;
1055 bool link;
1057 DEBUGFUNC("e1000_setup_copper_link_82543");
1059 ctrl = E1000_READ_REG(hw, E1000_CTRL) | E1000_CTRL_SLU;
1061 * With 82543, we need to force speed and duplex on the MAC
1062 * equal to what the PHY speed and duplex configuration is.
1063 * In addition, we need to perform a hardware reset on the
1064 * PHY to take it out of reset.
1066 if (hw->mac.type == e1000_82543) {
1067 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1068 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1069 ret_val = hw->phy.ops.reset(hw);
1070 if (ret_val)
1071 goto out;
1072 hw->phy.reset_disable = false;
1073 } else {
1074 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1075 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1078 /* Set MDI/MDI-X, Polarity Reversal, and downshift settings */
1079 ret_val = e1000_copper_link_setup_m88(hw);
1080 if (ret_val)
1081 goto out;
1083 if (hw->mac.autoneg) {
1085 * Setup autoneg and flow control advertisement and perform
1086 * autonegotiation.
1088 ret_val = e1000_copper_link_autoneg(hw);
1089 if (ret_val)
1090 goto out;
1091 } else {
1093 * PHY will be set to 10H, 10F, 100H or 100F
1094 * depending on user settings.
1096 DEBUGOUT("Forcing Speed and Duplex\n");
1097 ret_val = e1000_phy_force_speed_duplex_82543(hw);
1098 if (ret_val) {
1099 DEBUGOUT("Error Forcing Speed and Duplex\n");
1100 goto out;
1105 * Check link status. Wait up to 100 microseconds for link to become
1106 * valid.
1108 ret_val = e1000_phy_has_link_generic(hw,
1109 COPPER_LINK_UP_LIMIT,
1111 &link);
1112 if (ret_val)
1113 goto out;
1116 if (link) {
1117 DEBUGOUT("Valid link established!!!\n");
1118 /* Config the MAC and PHY after link is up */
1119 if (hw->mac.type == e1000_82544) {
1120 e1000_config_collision_dist_generic(hw);
1121 } else {
1122 ret_val = e1000_config_mac_to_phy_82543(hw);
1123 if (ret_val)
1124 goto out;
1126 ret_val = e1000_config_fc_after_link_up_generic(hw);
1127 } else {
1128 DEBUGOUT("Unable to establish link!!!\n");
1131 out:
1132 return ret_val;
1136 * e1000_setup_fiber_link_82543 - Setup link for fiber
1137 * @hw: pointer to the HW structure
1139 * Configures collision distance and flow control for fiber links. Upon
1140 * successful setup, poll for link.
1142 static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw)
1144 u32 ctrl;
1145 s32 ret_val;
1147 DEBUGFUNC("e1000_setup_fiber_link_82543");
1149 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1151 /* Take the link out of reset */
1152 ctrl &= ~E1000_CTRL_LRST;
1154 e1000_config_collision_dist_generic(hw);
1156 ret_val = e1000_commit_fc_settings_generic(hw);
1157 if (ret_val)
1158 goto out;
1160 DEBUGOUT("Auto-negotiation enabled\n");
1162 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1163 E1000_WRITE_FLUSH(hw);
1164 msec_delay(1);
1167 * For these adapters, the SW definable pin 1 is cleared when the
1168 * optics detect a signal. If we have a signal, then poll for a
1169 * "Link-Up" indication.
1171 if (!(E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) {
1172 ret_val = e1000_poll_fiber_serdes_link_generic(hw);
1173 } else {
1174 DEBUGOUT("No signal detected\n");
1177 out:
1178 return ret_val;
1182 * e1000_check_for_copper_link_82543 - Check for link (Copper)
1183 * @hw: pointer to the HW structure
1185 * Checks the phy for link, if link exists, do the following:
1186 * - check for downshift
1187 * - do polarity workaround (if necessary)
1188 * - configure collision distance
1189 * - configure flow control after link up
1190 * - configure tbi compatibility
1192 static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw)
1194 struct e1000_mac_info *mac = &hw->mac;
1195 u32 icr, rctl;
1196 s32 ret_val;
1197 u16 speed, duplex;
1198 bool link;
1200 DEBUGFUNC("e1000_check_for_copper_link_82543");
1202 if (!mac->get_link_status) {
1203 ret_val = E1000_SUCCESS;
1204 goto out;
1207 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
1208 if (ret_val)
1209 goto out;
1211 if (!link)
1212 goto out; /* No link detected */
1214 mac->get_link_status = false;
1216 e1000_check_downshift_generic(hw);
1219 * If we are forcing speed/duplex, then we can return since
1220 * we have already determined whether we have link or not.
1222 if (!mac->autoneg) {
1224 * If speed and duplex are forced to 10H or 10F, then we will
1225 * implement the polarity reversal workaround. We disable
1226 * interrupts first, and upon returning, place the devices
1227 * interrupt state to its previous value except for the link
1228 * status change interrupt which will happened due to the
1229 * execution of this workaround.
1231 if (mac->forced_speed_duplex & E1000_ALL_10_SPEED) {
1232 E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);
1233 ret_val = e1000_polarity_reversal_workaround_82543(hw);
1234 icr = E1000_READ_REG(hw, E1000_ICR);
1235 E1000_WRITE_REG(hw, E1000_ICS, (icr & ~E1000_ICS_LSC));
1236 E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK);
1239 ret_val = -E1000_ERR_CONFIG;
1240 goto out;
1244 * We have a M88E1000 PHY and Auto-Neg is enabled. If we
1245 * have Si on board that is 82544 or newer, Auto
1246 * Speed Detection takes care of MAC speed/duplex
1247 * configuration. So we only need to configure Collision
1248 * Distance in the MAC. Otherwise, we need to force
1249 * speed/duplex on the MAC to the current PHY speed/duplex
1250 * settings.
1252 if (mac->type == e1000_82544)
1253 e1000_config_collision_dist_generic(hw);
1254 else {
1255 ret_val = e1000_config_mac_to_phy_82543(hw);
1256 if (ret_val) {
1257 DEBUGOUT("Error configuring MAC to PHY settings\n");
1258 goto out;
1263 * Configure Flow Control now that Auto-Neg has completed.
1264 * First, we need to restore the desired flow control
1265 * settings because we may have had to re-autoneg with a
1266 * different link partner.
1268 ret_val = e1000_config_fc_after_link_up_generic(hw);
1269 if (ret_val) {
1270 DEBUGOUT("Error configuring flow control\n");
1274 * At this point we know that we are on copper and we have
1275 * auto-negotiated link. These are conditions for checking the link
1276 * partner capability register. We use the link speed to determine if
1277 * TBI compatibility needs to be turned on or off. If the link is not
1278 * at gigabit speed, then TBI compatibility is not needed. If we are
1279 * at gigabit speed, we turn on TBI compatibility.
1281 if (e1000_tbi_compatibility_enabled_82543(hw)) {
1282 ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
1283 if (ret_val) {
1284 DEBUGOUT("Error getting link speed and duplex\n");
1285 return ret_val;
1287 if (speed != SPEED_1000) {
1289 * If link speed is not set to gigabit speed,
1290 * we do not need to enable TBI compatibility.
1292 if (e1000_tbi_sbp_enabled_82543(hw)) {
1294 * If we previously were in the mode,
1295 * turn it off.
1297 e1000_set_tbi_sbp_82543(hw, false);
1298 rctl = E1000_READ_REG(hw, E1000_RCTL);
1299 rctl &= ~E1000_RCTL_SBP;
1300 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1302 } else {
1304 * If TBI compatibility is was previously off,
1305 * turn it on. For compatibility with a TBI link
1306 * partner, we will store bad packets. Some
1307 * frames have an additional byte on the end and
1308 * will look like CRC errors to to the hardware.
1310 if (!e1000_tbi_sbp_enabled_82543(hw)) {
1311 e1000_set_tbi_sbp_82543(hw, true);
1312 rctl = E1000_READ_REG(hw, E1000_RCTL);
1313 rctl |= E1000_RCTL_SBP;
1314 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1318 out:
1319 return ret_val;
1323 * e1000_check_for_fiber_link_82543 - Check for link (Fiber)
1324 * @hw: pointer to the HW structure
1326 * Checks for link up on the hardware. If link is not up and we have
1327 * a signal, then we need to force link up.
1329 static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw)
1331 struct e1000_mac_info *mac = &hw->mac;
1332 u32 rxcw, ctrl, status;
1333 s32 ret_val = E1000_SUCCESS;
1335 DEBUGFUNC("e1000_check_for_fiber_link_82543");
1337 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1338 status = E1000_READ_REG(hw, E1000_STATUS);
1339 rxcw = E1000_READ_REG(hw, E1000_RXCW);
1342 * If we don't have link (auto-negotiation failed or link partner
1343 * cannot auto-negotiate), the cable is plugged in (we have signal),
1344 * and our link partner is not trying to auto-negotiate with us (we
1345 * are receiving idles or data), we need to force link up. We also
1346 * need to give auto-negotiation time to complete, in case the cable
1347 * was just plugged in. The autoneg_failed flag does this.
1349 /* (ctrl & E1000_CTRL_SWDPIN1) == 0 == have signal */
1350 if ((!(ctrl & E1000_CTRL_SWDPIN1)) &&
1351 (!(status & E1000_STATUS_LU)) &&
1352 (!(rxcw & E1000_RXCW_C))) {
1353 if (mac->autoneg_failed == 0) {
1354 mac->autoneg_failed = 1;
1355 ret_val = 0;
1356 goto out;
1358 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
1360 /* Disable auto-negotiation in the TXCW register */
1361 E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
1363 /* Force link-up and also force full-duplex. */
1364 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1365 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
1366 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1368 /* Configure Flow Control after forcing link up. */
1369 ret_val = e1000_config_fc_after_link_up_generic(hw);
1370 if (ret_val) {
1371 DEBUGOUT("Error configuring flow control\n");
1372 goto out;
1374 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
1376 * If we are forcing link and we are receiving /C/ ordered
1377 * sets, re-enable auto-negotiation in the TXCW register
1378 * and disable forced link in the Device Control register
1379 * in an attempt to auto-negotiate with our link partner.
1381 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
1382 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
1383 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
1385 mac->serdes_has_link = true;
1388 out:
1389 return ret_val;
1393 * e1000_config_mac_to_phy_82543 - Configure MAC to PHY settings
1394 * @hw: pointer to the HW structure
1396 * For the 82543 silicon, we need to set the MAC to match the settings
1397 * of the PHY, even if the PHY is auto-negotiating.
1399 static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw)
1401 u32 ctrl;
1402 s32 ret_val = E1000_SUCCESS;
1403 u16 phy_data;
1405 DEBUGFUNC("e1000_config_mac_to_phy_82543");
1407 if (!(hw->phy.ops.read_reg))
1408 goto out;
1410 /* Set the bits to force speed and duplex */
1411 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1412 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1413 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1416 * Set up duplex in the Device Control and Transmit Control
1417 * registers depending on negotiated values.
1419 ret_val = hw->phy.ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1420 if (ret_val)
1421 goto out;
1423 ctrl &= ~E1000_CTRL_FD;
1424 if (phy_data & M88E1000_PSSR_DPLX)
1425 ctrl |= E1000_CTRL_FD;
1427 e1000_config_collision_dist_generic(hw);
1430 * Set up speed in the Device Control register depending on
1431 * negotiated values.
1433 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1434 ctrl |= E1000_CTRL_SPD_1000;
1435 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1436 ctrl |= E1000_CTRL_SPD_100;
1438 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1440 out:
1441 return ret_val;
1445 * e1000_write_vfta_82543 - Write value to VLAN filter table
1446 * @hw: pointer to the HW structure
1447 * @offset: the 32-bit offset in which to write the value to.
1448 * @value: the 32-bit value to write at location offset.
1450 * This writes a 32-bit value to a 32-bit offset in the VLAN filter
1451 * table.
1453 static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset, u32 value)
1455 u32 temp;
1457 DEBUGFUNC("e1000_write_vfta_82543");
1459 if ((hw->mac.type == e1000_82544) && (offset & 1)) {
1460 temp = E1000_READ_REG_ARRAY(hw, E1000_VFTA, offset - 1);
1461 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
1462 E1000_WRITE_FLUSH(hw);
1463 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset - 1, temp);
1464 E1000_WRITE_FLUSH(hw);
1465 } else {
1466 e1000_write_vfta_generic(hw, offset, value);
1471 * e1000_led_on_82543 - Turn on SW controllable LED
1472 * @hw: pointer to the HW structure
1474 * Turns the SW defined LED on.
1476 static s32 e1000_led_on_82543(struct e1000_hw *hw)
1478 u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1480 DEBUGFUNC("e1000_led_on_82543");
1482 if (hw->mac.type == e1000_82544 &&
1483 hw->phy.media_type == e1000_media_type_copper) {
1484 /* Clear SW-definable Pin 0 to turn on the LED */
1485 ctrl &= ~E1000_CTRL_SWDPIN0;
1486 ctrl |= E1000_CTRL_SWDPIO0;
1487 } else {
1488 /* Fiber 82544 and all 82543 use this method */
1489 ctrl |= E1000_CTRL_SWDPIN0;
1490 ctrl |= E1000_CTRL_SWDPIO0;
1492 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1494 return E1000_SUCCESS;
1498 * e1000_led_off_82543 - Turn off SW controllable LED
1499 * @hw: pointer to the HW structure
1501 * Turns the SW defined LED off.
1503 static s32 e1000_led_off_82543(struct e1000_hw *hw)
1505 u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1507 DEBUGFUNC("e1000_led_off_82543");
1509 if (hw->mac.type == e1000_82544 &&
1510 hw->phy.media_type == e1000_media_type_copper) {
1511 /* Set SW-definable Pin 0 to turn off the LED */
1512 ctrl |= E1000_CTRL_SWDPIN0;
1513 ctrl |= E1000_CTRL_SWDPIO0;
1514 } else {
1515 ctrl &= ~E1000_CTRL_SWDPIN0;
1516 ctrl |= E1000_CTRL_SWDPIO0;
1518 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1520 return E1000_SUCCESS;
1524 * e1000_clear_hw_cntrs_82543 - Clear device specific hardware counters
1525 * @hw: pointer to the HW structure
1527 * Clears the hardware counters by reading the counter registers.
1529 static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw)
1531 DEBUGFUNC("e1000_clear_hw_cntrs_82543");
1533 e1000_clear_hw_cntrs_base_generic(hw);
1535 E1000_READ_REG(hw, E1000_PRC64);
1536 E1000_READ_REG(hw, E1000_PRC127);
1537 E1000_READ_REG(hw, E1000_PRC255);
1538 E1000_READ_REG(hw, E1000_PRC511);
1539 E1000_READ_REG(hw, E1000_PRC1023);
1540 E1000_READ_REG(hw, E1000_PRC1522);
1541 E1000_READ_REG(hw, E1000_PTC64);
1542 E1000_READ_REG(hw, E1000_PTC127);
1543 E1000_READ_REG(hw, E1000_PTC255);
1544 E1000_READ_REG(hw, E1000_PTC511);
1545 E1000_READ_REG(hw, E1000_PTC1023);
1546 E1000_READ_REG(hw, E1000_PTC1522);
1548 E1000_READ_REG(hw, E1000_ALGNERRC);
1549 E1000_READ_REG(hw, E1000_RXERRC);
1550 E1000_READ_REG(hw, E1000_TNCRS);
1551 E1000_READ_REG(hw, E1000_CEXTERR);
1552 E1000_READ_REG(hw, E1000_TSCTC);
1553 E1000_READ_REG(hw, E1000_TSCTFC);