]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - drivers/net/e1000/e1000_hw.c
b3b919116e0fd28c38b753aedf12b1ed0c09a721
[linux-2.6.git] / drivers / net / e1000 / e1000_hw.c
1 /*******************************************************************************
2
3   
4   Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
5   
6   This program is free software; you can redistribute it and/or modify it 
7   under the terms of the GNU General Public License as published by the Free 
8   Software Foundation; either version 2 of the License, or (at your option) 
9   any later version.
10   
11   This program is distributed in the hope that it will be useful, but WITHOUT 
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
14   more details.
15   
16   You should have received a copy of the GNU General Public License along with
17   this program; if not, write to the Free Software Foundation, Inc., 59 
18   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19   
20   The full GNU General Public License is included in this distribution in the
21   file called LICENSE.
22   
23   Contact Information:
24   Linux NICS <linux.nics@intel.com>
25   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
28 *******************************************************************************/
29
30 /* e1000_hw.c
31  * Shared functions for accessing and configuring the MAC
32  */
33
34 #include "e1000_hw.h"
35
36 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
37 static void e1000_phy_init_script(struct e1000_hw *hw);
38 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
39 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
40 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
41 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
42 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
43 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
45 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46                                      uint16_t count);
47 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
48 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
49 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
50                                       uint16_t words, uint16_t *data);
51 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
52                                             uint16_t offset, uint16_t words,
53                                             uint16_t *data);
54 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
55 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
57 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58                                     uint16_t count);
59 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60                                       uint16_t phy_data);
61 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62                                      uint16_t *phy_data);
63 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
64 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
65 static void e1000_release_eeprom(struct e1000_hw *hw);
66 static void e1000_standby_eeprom(struct e1000_hw *hw);
67 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
69 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
70 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
71 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
72 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
73 static int32_t e1000_check_downshift(struct e1000_hw *hw);
74 static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
75 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
76 static void e1000_clear_vfta(struct e1000_hw *hw);
77 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
78 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
79                                                   boolean_t link_up);
80 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
81 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
82 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
83 static int32_t e1000_get_cable_length(struct e1000_hw *hw,
84                                       uint16_t *min_length,
85                                       uint16_t *max_length);
86 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
87 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
88 static int32_t e1000_id_led_init(struct e1000_hw * hw);
89 static void e1000_init_rx_addrs(struct e1000_hw *hw);
90 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
91 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
92 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
93 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
94                                       uint16_t words, uint16_t *data);
95 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
96 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
97 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
98
99 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
100                                uint32_t value);
101
102 #define E1000_WRITE_REG_IO(a, reg, val) \
103             e1000_write_reg_io((a), E1000_##reg, val)
104 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
105                                                uint16_t duplex);
106 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
107
108 static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw,
109                                            uint32_t segment);
110 static int32_t e1000_get_software_flag(struct e1000_hw *hw);
111 static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
112 static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
113 static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
114 static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
115                                       uint16_t words, uint16_t *data);
116 static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index,
117                                     uint8_t* data);
118 static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index,
119                                     uint16_t *data);
120 static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
121                                    uint16_t *data);
122 static void e1000_release_software_flag(struct e1000_hw *hw);
123 static void e1000_release_software_semaphore(struct e1000_hw *hw);
124 static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw,
125                                          uint32_t no_snoop);
126 static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw,
127                                             uint32_t index, uint8_t byte);
128 static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
129                                        uint16_t words, uint16_t *data);
130 static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index,
131                                      uint8_t data);
132 static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
133                                     uint16_t data);
134
135 /* IGP cable length table */
136 static const
137 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
138     { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
139       5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
140       25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
141       40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
142       60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
143       90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
144       100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
145       110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
146
147 static const
148 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
149     { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
150       0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
151       6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
152       21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
153       40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
154       60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
155       83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
156       104, 109, 114, 118, 121, 124};
157
158
159 /******************************************************************************
160  * Set the phy type member in the hw struct.
161  *
162  * hw - Struct containing variables accessed by shared code
163  *****************************************************************************/
164 int32_t
165 e1000_set_phy_type(struct e1000_hw *hw)
166 {
167     DEBUGFUNC("e1000_set_phy_type");
168
169     if(hw->mac_type == e1000_undefined)
170         return -E1000_ERR_PHY_TYPE;
171
172     switch(hw->phy_id) {
173     case M88E1000_E_PHY_ID:
174     case M88E1000_I_PHY_ID:
175     case M88E1011_I_PHY_ID:
176     case M88E1111_I_PHY_ID:
177         hw->phy_type = e1000_phy_m88;
178         break;
179     case IGP01E1000_I_PHY_ID:
180         if(hw->mac_type == e1000_82541 ||
181            hw->mac_type == e1000_82541_rev_2 ||
182            hw->mac_type == e1000_82547 ||
183            hw->mac_type == e1000_82547_rev_2) {
184             hw->phy_type = e1000_phy_igp;
185             break;
186         }
187     case IGP03E1000_E_PHY_ID:
188         hw->phy_type = e1000_phy_igp_3;
189         break;
190     case IFE_E_PHY_ID:
191     case IFE_PLUS_E_PHY_ID:
192     case IFE_C_E_PHY_ID:
193         hw->phy_type = e1000_phy_ife;
194         break;
195     case GG82563_E_PHY_ID:
196         if (hw->mac_type == e1000_80003es2lan) {
197             hw->phy_type = e1000_phy_gg82563;
198             break;
199         }
200         /* Fall Through */
201     default:
202         /* Should never have loaded on this device */
203         hw->phy_type = e1000_phy_undefined;
204         return -E1000_ERR_PHY_TYPE;
205     }
206
207     return E1000_SUCCESS;
208 }
209
210 /******************************************************************************
211  * IGP phy init script - initializes the GbE PHY
212  *
213  * hw - Struct containing variables accessed by shared code
214  *****************************************************************************/
215 static void
216 e1000_phy_init_script(struct e1000_hw *hw)
217 {
218     uint32_t ret_val;
219     uint16_t phy_saved_data;
220
221     DEBUGFUNC("e1000_phy_init_script");
222
223     if(hw->phy_init_script) {
224         msec_delay(20);
225
226         /* Save off the current value of register 0x2F5B to be restored at
227          * the end of this routine. */
228         ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
229
230         /* Disabled the PHY transmitter */
231         e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
232
233         msec_delay(20);
234
235         e1000_write_phy_reg(hw,0x0000,0x0140);
236
237         msec_delay(5);
238
239         switch(hw->mac_type) {
240         case e1000_82541:
241         case e1000_82547:
242             e1000_write_phy_reg(hw, 0x1F95, 0x0001);
243
244             e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
245
246             e1000_write_phy_reg(hw, 0x1F79, 0x0018);
247
248             e1000_write_phy_reg(hw, 0x1F30, 0x1600);
249
250             e1000_write_phy_reg(hw, 0x1F31, 0x0014);
251
252             e1000_write_phy_reg(hw, 0x1F32, 0x161C);
253
254             e1000_write_phy_reg(hw, 0x1F94, 0x0003);
255
256             e1000_write_phy_reg(hw, 0x1F96, 0x003F);
257
258             e1000_write_phy_reg(hw, 0x2010, 0x0008);
259             break;
260
261         case e1000_82541_rev_2:
262         case e1000_82547_rev_2:
263             e1000_write_phy_reg(hw, 0x1F73, 0x0099);
264             break;
265         default:
266             break;
267         }
268
269         e1000_write_phy_reg(hw, 0x0000, 0x3300);
270
271         msec_delay(20);
272
273         /* Now enable the transmitter */
274         e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
275
276         if(hw->mac_type == e1000_82547) {
277             uint16_t fused, fine, coarse;
278
279             /* Move to analog registers page */
280             e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
281
282             if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
283                 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
284
285                 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
286                 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
287
288                 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
289                     coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
290                     fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
291                 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
292                     fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
293
294                 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
295                         (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
296                         (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
297
298                 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
299                 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
300                                     IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
301             }
302         }
303     }
304 }
305
306 /******************************************************************************
307  * Set the mac type member in the hw struct.
308  *
309  * hw - Struct containing variables accessed by shared code
310  *****************************************************************************/
311 int32_t
312 e1000_set_mac_type(struct e1000_hw *hw)
313 {
314     DEBUGFUNC("e1000_set_mac_type");
315
316     switch (hw->device_id) {
317     case E1000_DEV_ID_82542:
318         switch (hw->revision_id) {
319         case E1000_82542_2_0_REV_ID:
320             hw->mac_type = e1000_82542_rev2_0;
321             break;
322         case E1000_82542_2_1_REV_ID:
323             hw->mac_type = e1000_82542_rev2_1;
324             break;
325         default:
326             /* Invalid 82542 revision ID */
327             return -E1000_ERR_MAC_TYPE;
328         }
329         break;
330     case E1000_DEV_ID_82543GC_FIBER:
331     case E1000_DEV_ID_82543GC_COPPER:
332         hw->mac_type = e1000_82543;
333         break;
334     case E1000_DEV_ID_82544EI_COPPER:
335     case E1000_DEV_ID_82544EI_FIBER:
336     case E1000_DEV_ID_82544GC_COPPER:
337     case E1000_DEV_ID_82544GC_LOM:
338         hw->mac_type = e1000_82544;
339         break;
340     case E1000_DEV_ID_82540EM:
341     case E1000_DEV_ID_82540EM_LOM:
342     case E1000_DEV_ID_82540EP:
343     case E1000_DEV_ID_82540EP_LOM:
344     case E1000_DEV_ID_82540EP_LP:
345         hw->mac_type = e1000_82540;
346         break;
347     case E1000_DEV_ID_82545EM_COPPER:
348     case E1000_DEV_ID_82545EM_FIBER:
349         hw->mac_type = e1000_82545;
350         break;
351     case E1000_DEV_ID_82545GM_COPPER:
352     case E1000_DEV_ID_82545GM_FIBER:
353     case E1000_DEV_ID_82545GM_SERDES:
354         hw->mac_type = e1000_82545_rev_3;
355         break;
356     case E1000_DEV_ID_82546EB_COPPER:
357     case E1000_DEV_ID_82546EB_FIBER:
358     case E1000_DEV_ID_82546EB_QUAD_COPPER:
359         hw->mac_type = e1000_82546;
360         break;
361     case E1000_DEV_ID_82546GB_COPPER:
362     case E1000_DEV_ID_82546GB_FIBER:
363     case E1000_DEV_ID_82546GB_SERDES:
364     case E1000_DEV_ID_82546GB_PCIE:
365     case E1000_DEV_ID_82546GB_QUAD_COPPER:
366     case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
367         hw->mac_type = e1000_82546_rev_3;
368         break;
369     case E1000_DEV_ID_82541EI:
370     case E1000_DEV_ID_82541EI_MOBILE:
371     case E1000_DEV_ID_82541ER_LOM:
372         hw->mac_type = e1000_82541;
373         break;
374     case E1000_DEV_ID_82541ER:
375     case E1000_DEV_ID_82541GI:
376     case E1000_DEV_ID_82541GI_LF:
377     case E1000_DEV_ID_82541GI_MOBILE:
378         hw->mac_type = e1000_82541_rev_2;
379         break;
380     case E1000_DEV_ID_82547EI:
381     case E1000_DEV_ID_82547EI_MOBILE:
382         hw->mac_type = e1000_82547;
383         break;
384     case E1000_DEV_ID_82547GI:
385         hw->mac_type = e1000_82547_rev_2;
386         break;
387     case E1000_DEV_ID_82571EB_COPPER:
388     case E1000_DEV_ID_82571EB_FIBER:
389     case E1000_DEV_ID_82571EB_SERDES:
390             hw->mac_type = e1000_82571;
391         break;
392     case E1000_DEV_ID_82572EI_COPPER:
393     case E1000_DEV_ID_82572EI_FIBER:
394     case E1000_DEV_ID_82572EI_SERDES:
395     case E1000_DEV_ID_82572EI:
396         hw->mac_type = e1000_82572;
397         break;
398     case E1000_DEV_ID_82573E:
399     case E1000_DEV_ID_82573E_IAMT:
400     case E1000_DEV_ID_82573L:
401         hw->mac_type = e1000_82573;
402         break;
403     case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
404     case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
405     case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
406     case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
407         hw->mac_type = e1000_80003es2lan;
408         break;
409     case E1000_DEV_ID_ICH8_IGP_M_AMT:
410     case E1000_DEV_ID_ICH8_IGP_AMT:
411     case E1000_DEV_ID_ICH8_IGP_C:
412     case E1000_DEV_ID_ICH8_IFE:
413     case E1000_DEV_ID_ICH8_IGP_M:
414         hw->mac_type = e1000_ich8lan;
415         break;
416     default:
417         /* Should never have loaded on this device */
418         return -E1000_ERR_MAC_TYPE;
419     }
420
421     switch(hw->mac_type) {
422     case e1000_ich8lan:
423         hw->swfwhw_semaphore_present = TRUE;
424         hw->asf_firmware_present = TRUE;
425         break;
426     case e1000_80003es2lan:
427         hw->swfw_sync_present = TRUE;
428         /* fall through */
429     case e1000_82571:
430     case e1000_82572:
431     case e1000_82573:
432         hw->eeprom_semaphore_present = TRUE;
433         /* fall through */
434     case e1000_82541:
435     case e1000_82547:
436     case e1000_82541_rev_2:
437     case e1000_82547_rev_2:
438         hw->asf_firmware_present = TRUE;
439         break;
440     default:
441         break;
442     }
443
444     return E1000_SUCCESS;
445 }
446
447 /*****************************************************************************
448  * Set media type and TBI compatibility.
449  *
450  * hw - Struct containing variables accessed by shared code
451  * **************************************************************************/
452 void
453 e1000_set_media_type(struct e1000_hw *hw)
454 {
455     uint32_t status;
456
457     DEBUGFUNC("e1000_set_media_type");
458
459     if(hw->mac_type != e1000_82543) {
460         /* tbi_compatibility is only valid on 82543 */
461         hw->tbi_compatibility_en = FALSE;
462     }
463
464     switch (hw->device_id) {
465     case E1000_DEV_ID_82545GM_SERDES:
466     case E1000_DEV_ID_82546GB_SERDES:
467     case E1000_DEV_ID_82571EB_SERDES:
468     case E1000_DEV_ID_82572EI_SERDES:
469     case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
470         hw->media_type = e1000_media_type_internal_serdes;
471         break;
472     default:
473         switch (hw->mac_type) {
474         case e1000_82542_rev2_0:
475         case e1000_82542_rev2_1:
476             hw->media_type = e1000_media_type_fiber;
477             break;
478         case e1000_ich8lan:
479         case e1000_82573:
480             /* The STATUS_TBIMODE bit is reserved or reused for the this
481              * device.
482              */
483             hw->media_type = e1000_media_type_copper;
484             break;
485         default:
486             status = E1000_READ_REG(hw, STATUS);
487             if (status & E1000_STATUS_TBIMODE) {
488                 hw->media_type = e1000_media_type_fiber;
489                 /* tbi_compatibility not valid on fiber */
490                 hw->tbi_compatibility_en = FALSE;
491             } else {
492                 hw->media_type = e1000_media_type_copper;
493             }
494             break;
495         }
496     }
497 }
498
499 /******************************************************************************
500  * Reset the transmit and receive units; mask and clear all interrupts.
501  *
502  * hw - Struct containing variables accessed by shared code
503  *****************************************************************************/
504 int32_t
505 e1000_reset_hw(struct e1000_hw *hw)
506 {
507     uint32_t ctrl;
508     uint32_t ctrl_ext;
509     uint32_t icr;
510     uint32_t manc;
511     uint32_t led_ctrl;
512     uint32_t timeout;
513     uint32_t extcnf_ctrl;
514     int32_t ret_val;
515
516     DEBUGFUNC("e1000_reset_hw");
517
518     /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
519     if(hw->mac_type == e1000_82542_rev2_0) {
520         DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
521         e1000_pci_clear_mwi(hw);
522     }
523
524     if(hw->bus_type == e1000_bus_type_pci_express) {
525         /* Prevent the PCI-E bus from sticking if there is no TLP connection
526          * on the last TLP read/write transaction when MAC is reset.
527          */
528         if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
529             DEBUGOUT("PCI-E Master disable polling has failed.\n");
530         }
531     }
532
533     /* Clear interrupt mask to stop board from generating interrupts */
534     DEBUGOUT("Masking off all interrupts\n");
535     E1000_WRITE_REG(hw, IMC, 0xffffffff);
536
537     /* Disable the Transmit and Receive units.  Then delay to allow
538      * any pending transactions to complete before we hit the MAC with
539      * the global reset.
540      */
541     E1000_WRITE_REG(hw, RCTL, 0);
542     E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
543     E1000_WRITE_FLUSH(hw);
544
545     /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
546     hw->tbi_compatibility_on = FALSE;
547
548     /* Delay to allow any outstanding PCI transactions to complete before
549      * resetting the device
550      */
551     msec_delay(10);
552
553     ctrl = E1000_READ_REG(hw, CTRL);
554
555     /* Must reset the PHY before resetting the MAC */
556     if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
557         E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
558         msec_delay(5);
559     }
560
561     /* Must acquire the MDIO ownership before MAC reset.
562      * Ownership defaults to firmware after a reset. */
563     if(hw->mac_type == e1000_82573) {
564         timeout = 10;
565
566         extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
567         extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
568
569         do {
570             E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
571             extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
572
573             if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
574                 break;
575             else
576                 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
577
578             msec_delay(2);
579             timeout--;
580         } while(timeout);
581     }
582
583     /* Workaround for ICH8 bit corruption issue in FIFO memory */
584     if (hw->mac_type == e1000_ich8lan) {
585         /* Set Tx and Rx buffer allocation to 8k apiece. */
586         E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
587         /* Set Packet Buffer Size to 16k. */
588         E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
589     }
590
591     /* Issue a global reset to the MAC.  This will reset the chip's
592      * transmit, receive, DMA, and link units.  It will not effect
593      * the current PCI configuration.  The global reset bit is self-
594      * clearing, and should clear within a microsecond.
595      */
596     DEBUGOUT("Issuing a global reset to MAC\n");
597
598     switch(hw->mac_type) {
599         case e1000_82544:
600         case e1000_82540:
601         case e1000_82545:
602         case e1000_82546:
603         case e1000_82541:
604         case e1000_82541_rev_2:
605             /* These controllers can't ack the 64-bit write when issuing the
606              * reset, so use IO-mapping as a workaround to issue the reset */
607             E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
608             break;
609         case e1000_82545_rev_3:
610         case e1000_82546_rev_3:
611             /* Reset is performed on a shadow of the control register */
612             E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
613             break;
614         case e1000_ich8lan:
615             if (!hw->phy_reset_disable &&
616                 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
617                 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
618                  * at the same time to make sure the interface between
619                  * MAC and the external PHY is reset.
620                  */
621                 ctrl |= E1000_CTRL_PHY_RST;
622             }
623
624             e1000_get_software_flag(hw);
625             E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
626             msec_delay(5);
627             break;
628         default:
629             E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
630             break;
631     }
632
633     /* After MAC reset, force reload of EEPROM to restore power-on settings to
634      * device.  Later controllers reload the EEPROM automatically, so just wait
635      * for reload to complete.
636      */
637     switch(hw->mac_type) {
638         case e1000_82542_rev2_0:
639         case e1000_82542_rev2_1:
640         case e1000_82543:
641         case e1000_82544:
642             /* Wait for reset to complete */
643             udelay(10);
644             ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
645             ctrl_ext |= E1000_CTRL_EXT_EE_RST;
646             E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
647             E1000_WRITE_FLUSH(hw);
648             /* Wait for EEPROM reload */
649             msec_delay(2);
650             break;
651         case e1000_82541:
652         case e1000_82541_rev_2:
653         case e1000_82547:
654         case e1000_82547_rev_2:
655             /* Wait for EEPROM reload */
656             msec_delay(20);
657             break;
658         case e1000_82573:
659             if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
660                 udelay(10);
661                 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
662                 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
663                 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
664                 E1000_WRITE_FLUSH(hw);
665             }
666             /* fall through */
667         case e1000_82571:
668         case e1000_82572:
669         case e1000_ich8lan:
670         case e1000_80003es2lan:
671             ret_val = e1000_get_auto_rd_done(hw);
672             if(ret_val)
673                 /* We don't want to continue accessing MAC registers. */
674                 return ret_val;
675             break;
676         default:
677             /* Wait for EEPROM reload (it happens automatically) */
678             msec_delay(5);
679             break;
680     }
681
682     /* Disable HW ARPs on ASF enabled adapters */
683     if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
684         manc = E1000_READ_REG(hw, MANC);
685         manc &= ~(E1000_MANC_ARP_EN);
686         E1000_WRITE_REG(hw, MANC, manc);
687     }
688
689     if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
690         e1000_phy_init_script(hw);
691
692         /* Configure activity LED after PHY reset */
693         led_ctrl = E1000_READ_REG(hw, LEDCTL);
694         led_ctrl &= IGP_ACTIVITY_LED_MASK;
695         led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
696         E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
697     }
698
699     /* Clear interrupt mask to stop board from generating interrupts */
700     DEBUGOUT("Masking off all interrupts\n");
701     E1000_WRITE_REG(hw, IMC, 0xffffffff);
702
703     /* Clear any pending interrupt events. */
704     icr = E1000_READ_REG(hw, ICR);
705
706     /* If MWI was previously enabled, reenable it. */
707     if(hw->mac_type == e1000_82542_rev2_0) {
708         if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
709             e1000_pci_set_mwi(hw);
710     }
711
712     if (hw->mac_type == e1000_ich8lan) {
713         uint32_t kab = E1000_READ_REG(hw, KABGTXD);
714         kab |= E1000_KABGTXD_BGSQLBIAS;
715         E1000_WRITE_REG(hw, KABGTXD, kab);
716     }
717
718     return E1000_SUCCESS;
719 }
720
721 /******************************************************************************
722  * Performs basic configuration of the adapter.
723  *
724  * hw - Struct containing variables accessed by shared code
725  *
726  * Assumes that the controller has previously been reset and is in a
727  * post-reset uninitialized state. Initializes the receive address registers,
728  * multicast table, and VLAN filter table. Calls routines to setup link
729  * configuration and flow control settings. Clears all on-chip counters. Leaves
730  * the transmit and receive units disabled and uninitialized.
731  *****************************************************************************/
732 int32_t
733 e1000_init_hw(struct e1000_hw *hw)
734 {
735     uint32_t ctrl;
736     uint32_t i;
737     int32_t ret_val;
738     uint16_t pcix_cmd_word;
739     uint16_t pcix_stat_hi_word;
740     uint16_t cmd_mmrbc;
741     uint16_t stat_mmrbc;
742     uint32_t mta_size;
743     uint32_t reg_data;
744     uint32_t ctrl_ext;
745
746     DEBUGFUNC("e1000_init_hw");
747
748     /* Initialize Identification LED */
749     ret_val = e1000_id_led_init(hw);
750     if(ret_val) {
751         DEBUGOUT("Error Initializing Identification LED\n");
752         return ret_val;
753     }
754
755     /* Set the media type and TBI compatibility */
756     e1000_set_media_type(hw);
757
758     /* Disabling VLAN filtering. */
759     DEBUGOUT("Initializing the IEEE VLAN\n");
760     /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
761     if (hw->mac_type != e1000_ich8lan) {
762         if (hw->mac_type < e1000_82545_rev_3)
763             E1000_WRITE_REG(hw, VET, 0);
764         e1000_clear_vfta(hw);
765     }
766
767     /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
768     if(hw->mac_type == e1000_82542_rev2_0) {
769         DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
770         e1000_pci_clear_mwi(hw);
771         E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
772         E1000_WRITE_FLUSH(hw);
773         msec_delay(5);
774     }
775
776     /* Setup the receive address. This involves initializing all of the Receive
777      * Address Registers (RARs 0 - 15).
778      */
779     e1000_init_rx_addrs(hw);
780
781     /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
782     if(hw->mac_type == e1000_82542_rev2_0) {
783         E1000_WRITE_REG(hw, RCTL, 0);
784         E1000_WRITE_FLUSH(hw);
785         msec_delay(1);
786         if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
787             e1000_pci_set_mwi(hw);
788     }
789
790     /* Zero out the Multicast HASH table */
791     DEBUGOUT("Zeroing the MTA\n");
792     mta_size = E1000_MC_TBL_SIZE;
793     if (hw->mac_type == e1000_ich8lan)
794         mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
795     for(i = 0; i < mta_size; i++) {
796         E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
797         /* use write flush to prevent Memory Write Block (MWB) from
798          * occuring when accessing our register space */
799         E1000_WRITE_FLUSH(hw);
800     }
801
802     /* Set the PCI priority bit correctly in the CTRL register.  This
803      * determines if the adapter gives priority to receives, or if it
804      * gives equal priority to transmits and receives.  Valid only on
805      * 82542 and 82543 silicon.
806      */
807     if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
808         ctrl = E1000_READ_REG(hw, CTRL);
809         E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
810     }
811
812     switch(hw->mac_type) {
813     case e1000_82545_rev_3:
814     case e1000_82546_rev_3:
815         break;
816     default:
817         /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
818         if(hw->bus_type == e1000_bus_type_pcix) {
819             e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
820             e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
821                 &pcix_stat_hi_word);
822             cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
823                 PCIX_COMMAND_MMRBC_SHIFT;
824             stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
825                 PCIX_STATUS_HI_MMRBC_SHIFT;
826             if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
827                 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
828             if(cmd_mmrbc > stat_mmrbc) {
829                 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
830                 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
831                 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
832                     &pcix_cmd_word);
833             }
834         }
835         break;
836     }
837
838     /* More time needed for PHY to initialize */
839     if (hw->mac_type == e1000_ich8lan)
840         msec_delay(15);
841
842     /* Call a subroutine to configure the link and setup flow control. */
843     ret_val = e1000_setup_link(hw);
844
845     /* Set the transmit descriptor write-back policy */
846     if(hw->mac_type > e1000_82544) {
847         ctrl = E1000_READ_REG(hw, TXDCTL);
848         ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
849         switch (hw->mac_type) {
850         default:
851             break;
852         case e1000_82571:
853         case e1000_82572:
854         case e1000_82573:
855         case e1000_ich8lan:
856         case e1000_80003es2lan:
857             ctrl |= E1000_TXDCTL_COUNT_DESC;
858             break;
859         }
860         E1000_WRITE_REG(hw, TXDCTL, ctrl);
861     }
862
863     if (hw->mac_type == e1000_82573) {
864         e1000_enable_tx_pkt_filtering(hw);
865     }
866
867     switch (hw->mac_type) {
868     default:
869         break;
870     case e1000_80003es2lan:
871         /* Enable retransmit on late collisions */
872         reg_data = E1000_READ_REG(hw, TCTL);
873         reg_data |= E1000_TCTL_RTLC;
874         E1000_WRITE_REG(hw, TCTL, reg_data);
875
876         /* Configure Gigabit Carry Extend Padding */
877         reg_data = E1000_READ_REG(hw, TCTL_EXT);
878         reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
879         reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
880         E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
881
882         /* Configure Transmit Inter-Packet Gap */
883         reg_data = E1000_READ_REG(hw, TIPG);
884         reg_data &= ~E1000_TIPG_IPGT_MASK;
885         reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
886         E1000_WRITE_REG(hw, TIPG, reg_data);
887
888         reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
889         reg_data &= ~0x00100000;
890         E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
891         /* Fall through */
892     case e1000_82571:
893     case e1000_82572:
894     case e1000_ich8lan:
895         ctrl = E1000_READ_REG(hw, TXDCTL1);
896         ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
897         if(hw->mac_type >= e1000_82571)
898             ctrl |= E1000_TXDCTL_COUNT_DESC;
899         E1000_WRITE_REG(hw, TXDCTL1, ctrl);
900         break;
901     }
902
903
904
905     if (hw->mac_type == e1000_82573) {
906         uint32_t gcr = E1000_READ_REG(hw, GCR);
907         gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
908         E1000_WRITE_REG(hw, GCR, gcr);
909     }
910
911     /* Clear all of the statistics registers (clear on read).  It is
912      * important that we do this after we have tried to establish link
913      * because the symbol error count will increment wildly if there
914      * is no link.
915      */
916     e1000_clear_hw_cntrs(hw);
917
918     /* ICH8 No-snoop bits are opposite polarity.
919      * Set to snoop by default after reset. */
920     if (hw->mac_type == e1000_ich8lan)
921         e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
922
923     if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
924         hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
925         ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
926         /* Relaxed ordering must be disabled to avoid a parity
927          * error crash in a PCI slot. */
928         ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
929         E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
930     }
931
932     return ret_val;
933 }
934
935 /******************************************************************************
936  * Adjust SERDES output amplitude based on EEPROM setting.
937  *
938  * hw - Struct containing variables accessed by shared code.
939  *****************************************************************************/
940 static int32_t
941 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
942 {
943     uint16_t eeprom_data;
944     int32_t  ret_val;
945
946     DEBUGFUNC("e1000_adjust_serdes_amplitude");
947
948     if(hw->media_type != e1000_media_type_internal_serdes)
949         return E1000_SUCCESS;
950
951     switch(hw->mac_type) {
952     case e1000_82545_rev_3:
953     case e1000_82546_rev_3:
954         break;
955     default:
956         return E1000_SUCCESS;
957     }
958
959     ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
960     if (ret_val) {
961         return ret_val;
962     }
963
964     if(eeprom_data != EEPROM_RESERVED_WORD) {
965         /* Adjust SERDES output amplitude only. */
966         eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
967         ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
968         if(ret_val)
969             return ret_val;
970     }
971
972     return E1000_SUCCESS;
973 }
974
975 /******************************************************************************
976  * Configures flow control and link settings.
977  *
978  * hw - Struct containing variables accessed by shared code
979  *
980  * Determines which flow control settings to use. Calls the apropriate media-
981  * specific link configuration function. Configures the flow control settings.
982  * Assuming the adapter has a valid link partner, a valid link should be
983  * established. Assumes the hardware has previously been reset and the
984  * transmitter and receiver are not enabled.
985  *****************************************************************************/
986 int32_t
987 e1000_setup_link(struct e1000_hw *hw)
988 {
989     uint32_t ctrl_ext;
990     int32_t ret_val;
991     uint16_t eeprom_data;
992
993     DEBUGFUNC("e1000_setup_link");
994
995     /* In the case of the phy reset being blocked, we already have a link.
996      * We do not have to set it up again. */
997     if (e1000_check_phy_reset_block(hw))
998         return E1000_SUCCESS;
999
1000     /* Read and store word 0x0F of the EEPROM. This word contains bits
1001      * that determine the hardware's default PAUSE (flow control) mode,
1002      * a bit that determines whether the HW defaults to enabling or
1003      * disabling auto-negotiation, and the direction of the
1004      * SW defined pins. If there is no SW over-ride of the flow
1005      * control setting, then the variable hw->fc will
1006      * be initialized based on a value in the EEPROM.
1007      */
1008     if (hw->fc == e1000_fc_default) {
1009         switch (hw->mac_type) {
1010         case e1000_ich8lan:
1011         case e1000_82573:
1012             hw->fc = e1000_fc_full;
1013             break;
1014         default:
1015             ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1016                                         1, &eeprom_data);
1017             if (ret_val) {
1018                 DEBUGOUT("EEPROM Read Error\n");
1019                 return -E1000_ERR_EEPROM;
1020             }
1021             if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1022                 hw->fc = e1000_fc_none;
1023             else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1024                     EEPROM_WORD0F_ASM_DIR)
1025                 hw->fc = e1000_fc_tx_pause;
1026             else
1027                 hw->fc = e1000_fc_full;
1028             break;
1029         }
1030     }
1031
1032     /* We want to save off the original Flow Control configuration just
1033      * in case we get disconnected and then reconnected into a different
1034      * hub or switch with different Flow Control capabilities.
1035      */
1036     if(hw->mac_type == e1000_82542_rev2_0)
1037         hw->fc &= (~e1000_fc_tx_pause);
1038
1039     if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1040         hw->fc &= (~e1000_fc_rx_pause);
1041
1042     hw->original_fc = hw->fc;
1043
1044     DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1045
1046     /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1047      * polarity value for the SW controlled pins, and setup the
1048      * Extended Device Control reg with that info.
1049      * This is needed because one of the SW controlled pins is used for
1050      * signal detection.  So this should be done before e1000_setup_pcs_link()
1051      * or e1000_phy_setup() is called.
1052      */
1053     if (hw->mac_type == e1000_82543) {
1054                 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1055                                                                         1, &eeprom_data);
1056                 if (ret_val) {
1057                         DEBUGOUT("EEPROM Read Error\n");
1058                         return -E1000_ERR_EEPROM;
1059                 }
1060         ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1061                     SWDPIO__EXT_SHIFT);
1062         E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1063     }
1064
1065     /* Call the necessary subroutine to configure the link. */
1066     ret_val = (hw->media_type == e1000_media_type_copper) ?
1067               e1000_setup_copper_link(hw) :
1068               e1000_setup_fiber_serdes_link(hw);
1069
1070     /* Initialize the flow control address, type, and PAUSE timer
1071      * registers to their default values.  This is done even if flow
1072      * control is disabled, because it does not hurt anything to
1073      * initialize these registers.
1074      */
1075     DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1076
1077     /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1078     if (hw->mac_type != e1000_ich8lan) {
1079         E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1080         E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1081         E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1082     }
1083
1084     E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1085
1086     /* Set the flow control receive threshold registers.  Normally,
1087      * these registers will be set to a default threshold that may be
1088      * adjusted later by the driver's runtime code.  However, if the
1089      * ability to transmit pause frames in not enabled, then these
1090      * registers will be set to 0.
1091      */
1092     if(!(hw->fc & e1000_fc_tx_pause)) {
1093         E1000_WRITE_REG(hw, FCRTL, 0);
1094         E1000_WRITE_REG(hw, FCRTH, 0);
1095     } else {
1096         /* We need to set up the Receive Threshold high and low water marks
1097          * as well as (optionally) enabling the transmission of XON frames.
1098          */
1099         if(hw->fc_send_xon) {
1100             E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1101             E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1102         } else {
1103             E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1104             E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1105         }
1106     }
1107     return ret_val;
1108 }
1109
1110 /******************************************************************************
1111  * Sets up link for a fiber based or serdes based adapter
1112  *
1113  * hw - Struct containing variables accessed by shared code
1114  *
1115  * Manipulates Physical Coding Sublayer functions in order to configure
1116  * link. Assumes the hardware has been previously reset and the transmitter
1117  * and receiver are not enabled.
1118  *****************************************************************************/
1119 static int32_t
1120 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1121 {
1122     uint32_t ctrl;
1123     uint32_t status;
1124     uint32_t txcw = 0;
1125     uint32_t i;
1126     uint32_t signal = 0;
1127     int32_t ret_val;
1128
1129     DEBUGFUNC("e1000_setup_fiber_serdes_link");
1130
1131     /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1132      * until explicitly turned off or a power cycle is performed.  A read to
1133      * the register does not indicate its status.  Therefore, we ensure
1134      * loopback mode is disabled during initialization.
1135      */
1136     if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1137         E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1138
1139     /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1140      * set when the optics detect a signal. On older adapters, it will be
1141      * cleared when there is a signal.  This applies to fiber media only.
1142      * If we're on serdes media, adjust the output amplitude to value set in
1143      * the EEPROM.
1144      */
1145     ctrl = E1000_READ_REG(hw, CTRL);
1146     if(hw->media_type == e1000_media_type_fiber)
1147         signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1148
1149     ret_val = e1000_adjust_serdes_amplitude(hw);
1150     if(ret_val)
1151         return ret_val;
1152
1153     /* Take the link out of reset */
1154     ctrl &= ~(E1000_CTRL_LRST);
1155
1156     /* Adjust VCO speed to improve BER performance */
1157     ret_val = e1000_set_vco_speed(hw);
1158     if(ret_val)
1159         return ret_val;
1160
1161     e1000_config_collision_dist(hw);
1162
1163     /* Check for a software override of the flow control settings, and setup
1164      * the device accordingly.  If auto-negotiation is enabled, then software
1165      * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1166      * Config Word Register (TXCW) and re-start auto-negotiation.  However, if
1167      * auto-negotiation is disabled, then software will have to manually
1168      * configure the two flow control enable bits in the CTRL register.
1169      *
1170      * The possible values of the "fc" parameter are:
1171      *      0:  Flow control is completely disabled
1172      *      1:  Rx flow control is enabled (we can receive pause frames, but
1173      *          not send pause frames).
1174      *      2:  Tx flow control is enabled (we can send pause frames but we do
1175      *          not support receiving pause frames).
1176      *      3:  Both Rx and TX flow control (symmetric) are enabled.
1177      */
1178     switch (hw->fc) {
1179     case e1000_fc_none:
1180         /* Flow control is completely disabled by a software over-ride. */
1181         txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1182         break;
1183     case e1000_fc_rx_pause:
1184         /* RX Flow control is enabled and TX Flow control is disabled by a
1185          * software over-ride. Since there really isn't a way to advertise
1186          * that we are capable of RX Pause ONLY, we will advertise that we
1187          * support both symmetric and asymmetric RX PAUSE. Later, we will
1188          *  disable the adapter's ability to send PAUSE frames.
1189          */
1190         txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1191         break;
1192     case e1000_fc_tx_pause:
1193         /* TX Flow control is enabled, and RX Flow control is disabled, by a
1194          * software over-ride.
1195          */
1196         txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1197         break;
1198     case e1000_fc_full:
1199         /* Flow control (both RX and TX) is enabled by a software over-ride. */
1200         txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1201         break;
1202     default:
1203         DEBUGOUT("Flow control param set incorrectly\n");
1204         return -E1000_ERR_CONFIG;
1205         break;
1206     }
1207
1208     /* Since auto-negotiation is enabled, take the link out of reset (the link
1209      * will be in reset, because we previously reset the chip). This will
1210      * restart auto-negotiation.  If auto-neogtiation is successful then the
1211      * link-up status bit will be set and the flow control enable bits (RFCE
1212      * and TFCE) will be set according to their negotiated value.
1213      */
1214     DEBUGOUT("Auto-negotiation enabled\n");
1215
1216     E1000_WRITE_REG(hw, TXCW, txcw);
1217     E1000_WRITE_REG(hw, CTRL, ctrl);
1218     E1000_WRITE_FLUSH(hw);
1219
1220     hw->txcw = txcw;
1221     msec_delay(1);
1222
1223     /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1224      * indication in the Device Status Register.  Time-out if a link isn't
1225      * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1226      * less than 500 milliseconds even if the other end is doing it in SW).
1227      * For internal serdes, we just assume a signal is present, then poll.
1228      */
1229     if(hw->media_type == e1000_media_type_internal_serdes ||
1230        (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1231         DEBUGOUT("Looking for Link\n");
1232         for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1233             msec_delay(10);
1234             status = E1000_READ_REG(hw, STATUS);
1235             if(status & E1000_STATUS_LU) break;
1236         }
1237         if(i == (LINK_UP_TIMEOUT / 10)) {
1238             DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1239             hw->autoneg_failed = 1;
1240             /* AutoNeg failed to achieve a link, so we'll call
1241              * e1000_check_for_link. This routine will force the link up if
1242              * we detect a signal. This will allow us to communicate with
1243              * non-autonegotiating link partners.
1244              */
1245             ret_val = e1000_check_for_link(hw);
1246             if(ret_val) {
1247                 DEBUGOUT("Error while checking for link\n");
1248                 return ret_val;
1249             }
1250             hw->autoneg_failed = 0;
1251         } else {
1252             hw->autoneg_failed = 0;
1253             DEBUGOUT("Valid Link Found\n");
1254         }
1255     } else {
1256         DEBUGOUT("No Signal Detected\n");
1257     }
1258     return E1000_SUCCESS;
1259 }
1260
1261 /******************************************************************************
1262 * Make sure we have a valid PHY and change PHY mode before link setup.
1263 *
1264 * hw - Struct containing variables accessed by shared code
1265 ******************************************************************************/
1266 static int32_t
1267 e1000_copper_link_preconfig(struct e1000_hw *hw)
1268 {
1269     uint32_t ctrl;
1270     int32_t ret_val;
1271     uint16_t phy_data;
1272
1273     DEBUGFUNC("e1000_copper_link_preconfig");
1274
1275     ctrl = E1000_READ_REG(hw, CTRL);
1276     /* With 82543, we need to force speed and duplex on the MAC equal to what
1277      * the PHY speed and duplex configuration is. In addition, we need to
1278      * perform a hardware reset on the PHY to take it out of reset.
1279      */
1280     if(hw->mac_type > e1000_82543) {
1281         ctrl |= E1000_CTRL_SLU;
1282         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1283         E1000_WRITE_REG(hw, CTRL, ctrl);
1284     } else {
1285         ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1286         E1000_WRITE_REG(hw, CTRL, ctrl);
1287         ret_val = e1000_phy_hw_reset(hw);
1288         if(ret_val)
1289             return ret_val;
1290     }
1291
1292     /* Make sure we have a valid PHY */
1293     ret_val = e1000_detect_gig_phy(hw);
1294     if(ret_val) {
1295         DEBUGOUT("Error, did not detect valid phy.\n");
1296         return ret_val;
1297     }
1298     DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1299
1300     /* Set PHY to class A mode (if necessary) */
1301     ret_val = e1000_set_phy_mode(hw);
1302     if(ret_val)
1303         return ret_val;
1304
1305     if((hw->mac_type == e1000_82545_rev_3) ||
1306        (hw->mac_type == e1000_82546_rev_3)) {
1307         ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1308         phy_data |= 0x00000008;
1309         ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1310     }
1311
1312     if(hw->mac_type <= e1000_82543 ||
1313        hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1314        hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1315         hw->phy_reset_disable = FALSE;
1316
1317    return E1000_SUCCESS;
1318 }
1319
1320
1321 /********************************************************************
1322 * Copper link setup for e1000_phy_igp series.
1323 *
1324 * hw - Struct containing variables accessed by shared code
1325 *********************************************************************/
1326 static int32_t
1327 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1328 {
1329     uint32_t led_ctrl;
1330     int32_t ret_val;
1331     uint16_t phy_data;
1332
1333     DEBUGFUNC("e1000_copper_link_igp_setup");
1334
1335     if (hw->phy_reset_disable)
1336         return E1000_SUCCESS;
1337
1338     ret_val = e1000_phy_reset(hw);
1339     if (ret_val) {
1340         DEBUGOUT("Error Resetting the PHY\n");
1341         return ret_val;
1342     }
1343
1344     /* Wait 10ms for MAC to configure PHY from eeprom settings */
1345     msec_delay(15);
1346     if (hw->mac_type != e1000_ich8lan) {
1347     /* Configure activity LED after PHY reset */
1348     led_ctrl = E1000_READ_REG(hw, LEDCTL);
1349     led_ctrl &= IGP_ACTIVITY_LED_MASK;
1350     led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1351     E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1352     }
1353
1354     /* disable lplu d3 during driver init */
1355     ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1356     if (ret_val) {
1357         DEBUGOUT("Error Disabling LPLU D3\n");
1358         return ret_val;
1359     }
1360
1361     /* disable lplu d0 during driver init */
1362     ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1363     if (ret_val) {
1364         DEBUGOUT("Error Disabling LPLU D0\n");
1365         return ret_val;
1366     }
1367     /* Configure mdi-mdix settings */
1368     ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1369     if (ret_val)
1370         return ret_val;
1371
1372     if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1373         hw->dsp_config_state = e1000_dsp_config_disabled;
1374         /* Force MDI for earlier revs of the IGP PHY */
1375         phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1376         hw->mdix = 1;
1377
1378     } else {
1379         hw->dsp_config_state = e1000_dsp_config_enabled;
1380         phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1381
1382         switch (hw->mdix) {
1383         case 1:
1384             phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1385             break;
1386         case 2:
1387             phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1388             break;
1389         case 0:
1390         default:
1391             phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1392             break;
1393         }
1394     }
1395     ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1396     if(ret_val)
1397         return ret_val;
1398
1399     /* set auto-master slave resolution settings */
1400     if(hw->autoneg) {
1401         e1000_ms_type phy_ms_setting = hw->master_slave;
1402
1403         if(hw->ffe_config_state == e1000_ffe_config_active)
1404             hw->ffe_config_state = e1000_ffe_config_enabled;
1405
1406         if(hw->dsp_config_state == e1000_dsp_config_activated)
1407             hw->dsp_config_state = e1000_dsp_config_enabled;
1408
1409         /* when autonegotiation advertisment is only 1000Mbps then we
1410           * should disable SmartSpeed and enable Auto MasterSlave
1411           * resolution as hardware default. */
1412         if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1413             /* Disable SmartSpeed */
1414             ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1415             if(ret_val)
1416                 return ret_val;
1417             phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1418             ret_val = e1000_write_phy_reg(hw,
1419                                                   IGP01E1000_PHY_PORT_CONFIG,
1420                                                   phy_data);
1421             if(ret_val)
1422                 return ret_val;
1423             /* Set auto Master/Slave resolution process */
1424             ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1425             if(ret_val)
1426                 return ret_val;
1427             phy_data &= ~CR_1000T_MS_ENABLE;
1428             ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1429             if(ret_val)
1430                 return ret_val;
1431         }
1432
1433         ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1434         if(ret_val)
1435             return ret_val;
1436
1437         /* load defaults for future use */
1438         hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1439                                         ((phy_data & CR_1000T_MS_VALUE) ?
1440                                          e1000_ms_force_master :
1441                                          e1000_ms_force_slave) :
1442                                          e1000_ms_auto;
1443
1444         switch (phy_ms_setting) {
1445         case e1000_ms_force_master:
1446             phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1447             break;
1448         case e1000_ms_force_slave:
1449             phy_data |= CR_1000T_MS_ENABLE;
1450             phy_data &= ~(CR_1000T_MS_VALUE);
1451             break;
1452         case e1000_ms_auto:
1453             phy_data &= ~CR_1000T_MS_ENABLE;
1454             default:
1455             break;
1456         }
1457         ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1458         if(ret_val)
1459             return ret_val;
1460     }
1461
1462     return E1000_SUCCESS;
1463 }
1464
1465 /********************************************************************
1466 * Copper link setup for e1000_phy_gg82563 series.
1467 *
1468 * hw - Struct containing variables accessed by shared code
1469 *********************************************************************/
1470 static int32_t
1471 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1472 {
1473     int32_t ret_val;
1474     uint16_t phy_data;
1475     uint32_t reg_data;
1476
1477     DEBUGFUNC("e1000_copper_link_ggp_setup");
1478
1479     if(!hw->phy_reset_disable) {
1480
1481         /* Enable CRS on TX for half-duplex operation. */
1482         ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1483                                      &phy_data);
1484         if(ret_val)
1485             return ret_val;
1486
1487         phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1488         /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1489         phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1490
1491         ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1492                                       phy_data);
1493         if(ret_val)
1494             return ret_val;
1495
1496         /* Options:
1497          *   MDI/MDI-X = 0 (default)
1498          *   0 - Auto for all speeds
1499          *   1 - MDI mode
1500          *   2 - MDI-X mode
1501          *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1502          */
1503         ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1504         if(ret_val)
1505             return ret_val;
1506
1507         phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1508
1509         switch (hw->mdix) {
1510         case 1:
1511             phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1512             break;
1513         case 2:
1514             phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1515             break;
1516         case 0:
1517         default:
1518             phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1519             break;
1520         }
1521
1522         /* Options:
1523          *   disable_polarity_correction = 0 (default)
1524          *       Automatic Correction for Reversed Cable Polarity
1525          *   0 - Disabled
1526          *   1 - Enabled
1527          */
1528         phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1529         if(hw->disable_polarity_correction == 1)
1530             phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1531         ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1532
1533         if(ret_val)
1534             return ret_val;
1535
1536         /* SW Reset the PHY so all changes take effect */
1537         ret_val = e1000_phy_reset(hw);
1538         if (ret_val) {
1539             DEBUGOUT("Error Resetting the PHY\n");
1540             return ret_val;
1541         }
1542     } /* phy_reset_disable */
1543
1544     if (hw->mac_type == e1000_80003es2lan) {
1545         /* Bypass RX and TX FIFO's */
1546         ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1547                                        E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1548                                        E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1549         if (ret_val)
1550             return ret_val;
1551
1552         ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1553         if (ret_val)
1554             return ret_val;
1555
1556         phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1557         ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1558
1559         if (ret_val)
1560             return ret_val;
1561
1562         reg_data = E1000_READ_REG(hw, CTRL_EXT);
1563         reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1564         E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1565
1566         ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1567                                           &phy_data);
1568         if (ret_val)
1569             return ret_val;
1570
1571         /* Do not init these registers when the HW is in IAMT mode, since the
1572          * firmware will have already initialized them.  We only initialize
1573          * them if the HW is not in IAMT mode.
1574          */
1575         if (e1000_check_mng_mode(hw) == FALSE) {
1576             /* Enable Electrical Idle on the PHY */
1577             phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1578             ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1579                                           phy_data);
1580             if (ret_val)
1581                 return ret_val;
1582
1583             ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1584                                          &phy_data);
1585             if (ret_val)
1586                 return ret_val;
1587
1588             phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1589
1590             ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1591                                           phy_data);
1592             if (ret_val)
1593                 return ret_val;
1594         }
1595
1596         /* Workaround: Disable padding in Kumeran interface in the MAC
1597          * and in the PHY to avoid CRC errors.
1598          */
1599         ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1600                                      &phy_data);
1601         if (ret_val)
1602             return ret_val;
1603         phy_data |= GG82563_ICR_DIS_PADDING;
1604         ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1605                                       phy_data);
1606         if (ret_val)
1607             return ret_val;
1608     }
1609
1610     return E1000_SUCCESS;
1611 }
1612
1613 /********************************************************************
1614 * Copper link setup for e1000_phy_m88 series.
1615 *
1616 * hw - Struct containing variables accessed by shared code
1617 *********************************************************************/
1618 static int32_t
1619 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1620 {
1621     int32_t ret_val;
1622     uint16_t phy_data;
1623
1624     DEBUGFUNC("e1000_copper_link_mgp_setup");
1625
1626     if(hw->phy_reset_disable)
1627         return E1000_SUCCESS;
1628
1629     /* Enable CRS on TX. This must be set for half-duplex operation. */
1630     ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1631     if(ret_val)
1632         return ret_val;
1633
1634     phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1635
1636     /* Options:
1637      *   MDI/MDI-X = 0 (default)
1638      *   0 - Auto for all speeds
1639      *   1 - MDI mode
1640      *   2 - MDI-X mode
1641      *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1642      */
1643     phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1644
1645     switch (hw->mdix) {
1646     case 1:
1647         phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1648         break;
1649     case 2:
1650         phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1651         break;
1652     case 3:
1653         phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1654         break;
1655     case 0:
1656     default:
1657         phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1658         break;
1659     }
1660
1661     /* Options:
1662      *   disable_polarity_correction = 0 (default)
1663      *       Automatic Correction for Reversed Cable Polarity
1664      *   0 - Disabled
1665      *   1 - Enabled
1666      */
1667     phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1668     if(hw->disable_polarity_correction == 1)
1669         phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1670     ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1671     if (ret_val)
1672         return ret_val;
1673
1674     if (hw->phy_revision < M88E1011_I_REV_4) {
1675         /* Force TX_CLK in the Extended PHY Specific Control Register
1676          * to 25MHz clock.
1677          */
1678         ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1679         if (ret_val)
1680             return ret_val;
1681
1682         phy_data |= M88E1000_EPSCR_TX_CLK_25;
1683
1684         if ((hw->phy_revision == E1000_REVISION_2) &&
1685             (hw->phy_id == M88E1111_I_PHY_ID)) {
1686             /* Vidalia Phy, set the downshift counter to 5x */
1687             phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1688             phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1689             ret_val = e1000_write_phy_reg(hw,
1690                                         M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1691             if (ret_val)
1692                 return ret_val;
1693         } else {
1694             /* Configure Master and Slave downshift values */
1695             phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1696                               M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1697             phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1698                              M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1699             ret_val = e1000_write_phy_reg(hw,
1700                                         M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1701             if (ret_val)
1702                return ret_val;
1703         }
1704     }
1705
1706     /* SW Reset the PHY so all changes take effect */
1707     ret_val = e1000_phy_reset(hw);
1708     if(ret_val) {
1709         DEBUGOUT("Error Resetting the PHY\n");
1710         return ret_val;
1711     }
1712
1713    return E1000_SUCCESS;
1714 }
1715
1716 /********************************************************************
1717 * Setup auto-negotiation and flow control advertisements,
1718 * and then perform auto-negotiation.
1719 *
1720 * hw - Struct containing variables accessed by shared code
1721 *********************************************************************/
1722 static int32_t
1723 e1000_copper_link_autoneg(struct e1000_hw *hw)
1724 {
1725     int32_t ret_val;
1726     uint16_t phy_data;
1727
1728     DEBUGFUNC("e1000_copper_link_autoneg");
1729
1730     /* Perform some bounds checking on the hw->autoneg_advertised
1731      * parameter.  If this variable is zero, then set it to the default.
1732      */
1733     hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1734
1735     /* If autoneg_advertised is zero, we assume it was not defaulted
1736      * by the calling code so we set to advertise full capability.
1737      */
1738     if(hw->autoneg_advertised == 0)
1739         hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1740
1741     /* IFE phy only supports 10/100 */
1742     if (hw->phy_type == e1000_phy_ife)
1743         hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1744
1745     DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1746     ret_val = e1000_phy_setup_autoneg(hw);
1747     if(ret_val) {
1748         DEBUGOUT("Error Setting up Auto-Negotiation\n");
1749         return ret_val;
1750     }
1751     DEBUGOUT("Restarting Auto-Neg\n");
1752
1753     /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1754      * the Auto Neg Restart bit in the PHY control register.
1755      */
1756     ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1757     if(ret_val)
1758         return ret_val;
1759
1760     phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1761     ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1762     if(ret_val)
1763         return ret_val;
1764
1765     /* Does the user want to wait for Auto-Neg to complete here, or
1766      * check at a later time (for example, callback routine).
1767      */
1768     if(hw->wait_autoneg_complete) {
1769         ret_val = e1000_wait_autoneg(hw);
1770         if(ret_val) {
1771             DEBUGOUT("Error while waiting for autoneg to complete\n");
1772             return ret_val;
1773         }
1774     }
1775
1776     hw->get_link_status = TRUE;
1777
1778     return E1000_SUCCESS;
1779 }
1780
1781
1782 /******************************************************************************
1783 * Config the MAC and the PHY after link is up.
1784 *   1) Set up the MAC to the current PHY speed/duplex
1785 *      if we are on 82543.  If we
1786 *      are on newer silicon, we only need to configure
1787 *      collision distance in the Transmit Control Register.
1788 *   2) Set up flow control on the MAC to that established with
1789 *      the link partner.
1790 *   3) Config DSP to improve Gigabit link quality for some PHY revisions.
1791 *
1792 * hw - Struct containing variables accessed by shared code
1793 ******************************************************************************/
1794 static int32_t
1795 e1000_copper_link_postconfig(struct e1000_hw *hw)
1796 {
1797     int32_t ret_val;
1798     DEBUGFUNC("e1000_copper_link_postconfig");
1799
1800     if(hw->mac_type >= e1000_82544) {
1801         e1000_config_collision_dist(hw);
1802     } else {
1803         ret_val = e1000_config_mac_to_phy(hw);
1804         if(ret_val) {
1805             DEBUGOUT("Error configuring MAC to PHY settings\n");
1806             return ret_val;
1807         }
1808     }
1809     ret_val = e1000_config_fc_after_link_up(hw);
1810     if(ret_val) {
1811         DEBUGOUT("Error Configuring Flow Control\n");
1812         return ret_val;
1813     }
1814
1815     /* Config DSP to improve Giga link quality */
1816     if(hw->phy_type == e1000_phy_igp) {
1817         ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1818         if(ret_val) {
1819             DEBUGOUT("Error Configuring DSP after link up\n");
1820             return ret_val;
1821         }
1822     }
1823
1824     return E1000_SUCCESS;
1825 }
1826
1827 /******************************************************************************
1828 * Detects which PHY is present and setup the speed and duplex
1829 *
1830 * hw - Struct containing variables accessed by shared code
1831 ******************************************************************************/
1832 static int32_t
1833 e1000_setup_copper_link(struct e1000_hw *hw)
1834 {
1835     int32_t ret_val;
1836     uint16_t i;
1837     uint16_t phy_data;
1838     uint16_t reg_data;
1839
1840     DEBUGFUNC("e1000_setup_copper_link");
1841
1842     switch (hw->mac_type) {
1843     case e1000_80003es2lan:
1844     case e1000_ich8lan:
1845         /* Set the mac to wait the maximum time between each
1846          * iteration and increase the max iterations when
1847          * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1848         ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1849         if (ret_val)
1850             return ret_val;
1851         ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1852         if (ret_val)
1853             return ret_val;
1854         reg_data |= 0x3F;
1855         ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1856         if (ret_val)
1857             return ret_val;
1858     default:
1859         break;
1860     }
1861
1862     /* Check if it is a valid PHY and set PHY mode if necessary. */
1863     ret_val = e1000_copper_link_preconfig(hw);
1864     if(ret_val)
1865         return ret_val;
1866
1867     switch (hw->mac_type) {
1868     case e1000_80003es2lan:
1869         /* Kumeran registers are written-only */
1870         reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
1871         reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1872         ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1873                                        reg_data);
1874         if (ret_val)
1875             return ret_val;
1876         break;
1877     default:
1878         break;
1879     }
1880
1881     if (hw->phy_type == e1000_phy_igp ||
1882         hw->phy_type == e1000_phy_igp_3 ||
1883         hw->phy_type == e1000_phy_igp_2) {
1884         ret_val = e1000_copper_link_igp_setup(hw);
1885         if(ret_val)
1886             return ret_val;
1887     } else if (hw->phy_type == e1000_phy_m88) {
1888         ret_val = e1000_copper_link_mgp_setup(hw);
1889         if(ret_val)
1890             return ret_val;
1891     } else if (hw->phy_type == e1000_phy_gg82563) {
1892         ret_val = e1000_copper_link_ggp_setup(hw);
1893         if(ret_val)
1894             return ret_val;
1895     }
1896
1897     if(hw->autoneg) {
1898         /* Setup autoneg and flow control advertisement
1899           * and perform autonegotiation */
1900         ret_val = e1000_copper_link_autoneg(hw);
1901         if(ret_val)
1902             return ret_val;
1903     } else {
1904         /* PHY will be set to 10H, 10F, 100H,or 100F
1905           * depending on value from forced_speed_duplex. */
1906         DEBUGOUT("Forcing speed and duplex\n");
1907         ret_val = e1000_phy_force_speed_duplex(hw);
1908         if(ret_val) {
1909             DEBUGOUT("Error Forcing Speed and Duplex\n");
1910             return ret_val;
1911         }
1912     }
1913
1914     /* Check link status. Wait up to 100 microseconds for link to become
1915      * valid.
1916      */
1917     for(i = 0; i < 10; i++) {
1918         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1919         if(ret_val)
1920             return ret_val;
1921         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1922         if(ret_val)
1923             return ret_val;
1924
1925         if(phy_data & MII_SR_LINK_STATUS) {
1926             /* Config the MAC and PHY after link is up */
1927             ret_val = e1000_copper_link_postconfig(hw);
1928             if(ret_val)
1929                 return ret_val;
1930
1931             DEBUGOUT("Valid link established!!!\n");
1932             return E1000_SUCCESS;
1933         }
1934         udelay(10);
1935     }
1936
1937     DEBUGOUT("Unable to establish link!!!\n");
1938     return E1000_SUCCESS;
1939 }
1940
1941 /******************************************************************************
1942 * Configure the MAC-to-PHY interface for 10/100Mbps
1943 *
1944 * hw - Struct containing variables accessed by shared code
1945 ******************************************************************************/
1946 static int32_t
1947 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
1948 {
1949     int32_t ret_val = E1000_SUCCESS;
1950     uint32_t tipg;
1951     uint16_t reg_data;
1952
1953     DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1954
1955     reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1956     ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1957                                    reg_data);
1958     if (ret_val)
1959         return ret_val;
1960
1961     /* Configure Transmit Inter-Packet Gap */
1962     tipg = E1000_READ_REG(hw, TIPG);
1963     tipg &= ~E1000_TIPG_IPGT_MASK;
1964     tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1965     E1000_WRITE_REG(hw, TIPG, tipg);
1966
1967     ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
1968
1969     if (ret_val)
1970         return ret_val;
1971
1972     if (duplex == HALF_DUPLEX)
1973         reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1974     else
1975         reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1976
1977     ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1978
1979     return ret_val;
1980 }
1981
1982 static int32_t
1983 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1984 {
1985     int32_t ret_val = E1000_SUCCESS;
1986     uint16_t reg_data;
1987     uint32_t tipg;
1988
1989     DEBUGFUNC("e1000_configure_kmrn_for_1000");
1990
1991     reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
1992     ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1993                                    reg_data);
1994     if (ret_val)
1995         return ret_val;
1996
1997     /* Configure Transmit Inter-Packet Gap */
1998     tipg = E1000_READ_REG(hw, TIPG);
1999     tipg &= ~E1000_TIPG_IPGT_MASK;
2000     tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2001     E1000_WRITE_REG(hw, TIPG, tipg);
2002
2003     ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2004
2005     if (ret_val)
2006         return ret_val;
2007
2008     reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2009     ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2010
2011     return ret_val;
2012 }
2013
2014 /******************************************************************************
2015 * Configures PHY autoneg and flow control advertisement settings
2016 *
2017 * hw - Struct containing variables accessed by shared code
2018 ******************************************************************************/
2019 int32_t
2020 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2021 {
2022     int32_t ret_val;
2023     uint16_t mii_autoneg_adv_reg;
2024     uint16_t mii_1000t_ctrl_reg;
2025
2026     DEBUGFUNC("e1000_phy_setup_autoneg");
2027
2028     /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2029     ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2030     if(ret_val)
2031         return ret_val;
2032
2033     if (hw->phy_type != e1000_phy_ife) {
2034         /* Read the MII 1000Base-T Control Register (Address 9). */
2035         ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2036         if (ret_val)
2037             return ret_val;
2038     } else
2039         mii_1000t_ctrl_reg=0;
2040
2041     /* Need to parse both autoneg_advertised and fc and set up
2042      * the appropriate PHY registers.  First we will parse for
2043      * autoneg_advertised software override.  Since we can advertise
2044      * a plethora of combinations, we need to check each bit
2045      * individually.
2046      */
2047
2048     /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2049      * Advertisement Register (Address 4) and the 1000 mb speed bits in
2050      * the  1000Base-T Control Register (Address 9).
2051      */
2052     mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2053     mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2054
2055     DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2056
2057     /* Do we want to advertise 10 Mb Half Duplex? */
2058     if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
2059         DEBUGOUT("Advertise 10mb Half duplex\n");
2060         mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2061     }
2062
2063     /* Do we want to advertise 10 Mb Full Duplex? */
2064     if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
2065         DEBUGOUT("Advertise 10mb Full duplex\n");
2066         mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2067     }
2068
2069     /* Do we want to advertise 100 Mb Half Duplex? */
2070     if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
2071         DEBUGOUT("Advertise 100mb Half duplex\n");
2072         mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2073     }
2074
2075     /* Do we want to advertise 100 Mb Full Duplex? */
2076     if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
2077         DEBUGOUT("Advertise 100mb Full duplex\n");
2078         mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2079     }
2080
2081     /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2082     if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2083         DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2084     }
2085
2086     /* Do we want to advertise 1000 Mb Full Duplex? */
2087     if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2088         DEBUGOUT("Advertise 1000mb Full duplex\n");
2089         mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2090         if (hw->phy_type == e1000_phy_ife) {
2091             DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2092         }
2093     }
2094
2095     /* Check for a software override of the flow control settings, and
2096      * setup the PHY advertisement registers accordingly.  If
2097      * auto-negotiation is enabled, then software will have to set the
2098      * "PAUSE" bits to the correct value in the Auto-Negotiation
2099      * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2100      *
2101      * The possible values of the "fc" parameter are:
2102      *      0:  Flow control is completely disabled
2103      *      1:  Rx flow control is enabled (we can receive pause frames
2104      *          but not send pause frames).
2105      *      2:  Tx flow control is enabled (we can send pause frames
2106      *          but we do not support receiving pause frames).
2107      *      3:  Both Rx and TX flow control (symmetric) are enabled.
2108      *  other:  No software override.  The flow control configuration
2109      *          in the EEPROM is used.
2110      */
2111     switch (hw->fc) {
2112     case e1000_fc_none: /* 0 */
2113         /* Flow control (RX & TX) is completely disabled by a
2114          * software over-ride.
2115          */
2116         mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2117         break;
2118     case e1000_fc_rx_pause: /* 1 */
2119         /* RX Flow control is enabled, and TX Flow control is
2120          * disabled, by a software over-ride.
2121          */
2122         /* Since there really isn't a way to advertise that we are
2123          * capable of RX Pause ONLY, we will advertise that we
2124          * support both symmetric and asymmetric RX PAUSE.  Later
2125          * (in e1000_config_fc_after_link_up) we will disable the
2126          *hw's ability to send PAUSE frames.
2127          */
2128         mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2129         break;
2130     case e1000_fc_tx_pause: /* 2 */
2131         /* TX Flow control is enabled, and RX Flow control is
2132          * disabled, by a software over-ride.
2133          */
2134         mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2135         mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2136         break;
2137     case e1000_fc_full: /* 3 */
2138         /* Flow control (both RX and TX) is enabled by a software
2139          * over-ride.
2140          */
2141         mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2142         break;
2143     default:
2144         DEBUGOUT("Flow control param set incorrectly\n");
2145         return -E1000_ERR_CONFIG;
2146     }
2147
2148     ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2149     if(ret_val)
2150         return ret_val;
2151
2152     DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2153
2154     if (hw->phy_type != e1000_phy_ife) {
2155         ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2156         if (ret_val)
2157             return ret_val;
2158     }
2159
2160     return E1000_SUCCESS;
2161 }
2162
2163 /******************************************************************************
2164 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2165 *
2166 * hw - Struct containing variables accessed by shared code
2167 ******************************************************************************/
2168 static int32_t
2169 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2170 {
2171     uint32_t ctrl;
2172     int32_t ret_val;
2173     uint16_t mii_ctrl_reg;
2174     uint16_t mii_status_reg;
2175     uint16_t phy_data;
2176     uint16_t i;
2177
2178     DEBUGFUNC("e1000_phy_force_speed_duplex");
2179
2180     /* Turn off Flow control if we are forcing speed and duplex. */
2181     hw->fc = e1000_fc_none;
2182
2183     DEBUGOUT1("hw->fc = %d\n", hw->fc);
2184
2185     /* Read the Device Control Register. */
2186     ctrl = E1000_READ_REG(hw, CTRL);
2187
2188     /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2189     ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2190     ctrl &= ~(DEVICE_SPEED_MASK);
2191
2192     /* Clear the Auto Speed Detect Enable bit. */
2193     ctrl &= ~E1000_CTRL_ASDE;
2194
2195     /* Read the MII Control Register. */
2196     ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2197     if(ret_val)
2198         return ret_val;
2199
2200     /* We need to disable autoneg in order to force link and duplex. */
2201
2202     mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2203
2204     /* Are we forcing Full or Half Duplex? */
2205     if(hw->forced_speed_duplex == e1000_100_full ||
2206        hw->forced_speed_duplex == e1000_10_full) {
2207         /* We want to force full duplex so we SET the full duplex bits in the
2208          * Device and MII Control Registers.
2209          */
2210         ctrl |= E1000_CTRL_FD;
2211         mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2212         DEBUGOUT("Full Duplex\n");
2213     } else {
2214         /* We want to force half duplex so we CLEAR the full duplex bits in
2215          * the Device and MII Control Registers.
2216          */
2217         ctrl &= ~E1000_CTRL_FD;
2218         mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2219         DEBUGOUT("Half Duplex\n");
2220     }
2221
2222     /* Are we forcing 100Mbps??? */
2223     if(hw->forced_speed_duplex == e1000_100_full ||
2224        hw->forced_speed_duplex == e1000_100_half) {
2225         /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2226         ctrl |= E1000_CTRL_SPD_100;
2227         mii_ctrl_reg |= MII_CR_SPEED_100;
2228         mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2229         DEBUGOUT("Forcing 100mb ");
2230     } else {
2231         /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2232         ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2233         mii_ctrl_reg |= MII_CR_SPEED_10;
2234         mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2235         DEBUGOUT("Forcing 10mb ");
2236     }
2237
2238     e1000_config_collision_dist(hw);
2239
2240     /* Write the configured values back to the Device Control Reg. */
2241     E1000_WRITE_REG(hw, CTRL, ctrl);
2242
2243     if ((hw->phy_type == e1000_phy_m88) ||
2244         (hw->phy_type == e1000_phy_gg82563)) {
2245         ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2246         if(ret_val)
2247             return ret_val;
2248
2249         /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2250          * forced whenever speed are duplex are forced.
2251          */
2252         phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2253         ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2254         if(ret_val)
2255             return ret_val;
2256
2257         DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2258
2259         /* Need to reset the PHY or these changes will be ignored */
2260         mii_ctrl_reg |= MII_CR_RESET;
2261     /* Disable MDI-X support for 10/100 */
2262     } else if (hw->phy_type == e1000_phy_ife) {
2263         ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2264         if (ret_val)
2265             return ret_val;
2266
2267         phy_data &= ~IFE_PMC_AUTO_MDIX;
2268         phy_data &= ~IFE_PMC_FORCE_MDIX;
2269
2270         ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2271         if (ret_val)
2272             return ret_val;
2273     } else {
2274         /* Clear Auto-Crossover to force MDI manually.  IGP requires MDI
2275          * forced whenever speed or duplex are forced.
2276          */
2277         ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2278         if(ret_val)
2279             return ret_val;
2280
2281         phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2282         phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2283
2284         ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2285         if(ret_val)
2286             return ret_val;
2287     }
2288
2289     /* Write back the modified PHY MII control register. */
2290     ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2291     if(ret_val)
2292         return ret_val;
2293
2294     udelay(1);
2295
2296     /* The wait_autoneg_complete flag may be a little misleading here.
2297      * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2298      * But we do want to delay for a period while forcing only so we
2299      * don't generate false No Link messages.  So we will wait here
2300      * only if the user has set wait_autoneg_complete to 1, which is
2301      * the default.
2302      */
2303     if(hw->wait_autoneg_complete) {
2304         /* We will wait for autoneg to complete. */
2305         DEBUGOUT("Waiting for forced speed/duplex link.\n");
2306         mii_status_reg = 0;
2307
2308         /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2309         for(i = PHY_FORCE_TIME; i > 0; i--) {
2310             /* Read the MII Status Register and wait for Auto-Neg Complete bit
2311              * to be set.
2312              */
2313             ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2314             if(ret_val)
2315                 return ret_val;
2316
2317             ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2318             if(ret_val)
2319                 return ret_val;
2320
2321             if(mii_status_reg & MII_SR_LINK_STATUS) break;
2322             msec_delay(100);
2323         }
2324         if((i == 0) &&
2325            ((hw->phy_type == e1000_phy_m88) ||
2326             (hw->phy_type == e1000_phy_gg82563))) {
2327             /* We didn't get link.  Reset the DSP and wait again for link. */
2328             ret_val = e1000_phy_reset_dsp(hw);
2329             if(ret_val) {
2330                 DEBUGOUT("Error Resetting PHY DSP\n");
2331                 return ret_val;
2332             }
2333         }
2334         /* This loop will early-out if the link condition has been met.  */
2335         for(i = PHY_FORCE_TIME; i > 0; i--) {
2336             if(mii_status_reg & MII_SR_LINK_STATUS) break;
2337             msec_delay(100);
2338             /* Read the MII Status Register and wait for Auto-Neg Complete bit
2339              * to be set.
2340              */
2341             ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2342             if(ret_val)
2343                 return ret_val;
2344
2345             ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2346             if(ret_val)
2347                 return ret_val;
2348         }
2349     }
2350
2351     if (hw->phy_type == e1000_phy_m88) {
2352         /* Because we reset the PHY above, we need to re-force TX_CLK in the
2353          * Extended PHY Specific Control Register to 25MHz clock.  This value
2354          * defaults back to a 2.5MHz clock when the PHY is reset.
2355          */
2356         ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2357         if(ret_val)
2358             return ret_val;
2359
2360         phy_data |= M88E1000_EPSCR_TX_CLK_25;
2361         ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2362         if(ret_val)
2363             return ret_val;
2364
2365         /* In addition, because of the s/w reset above, we need to enable CRS on
2366          * TX.  This must be set for both full and half duplex operation.
2367          */
2368         ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2369         if(ret_val)
2370             return ret_val;
2371
2372         phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2373         ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2374         if(ret_val)
2375             return ret_val;
2376
2377         if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2378            (!hw->autoneg) &&
2379            (hw->forced_speed_duplex == e1000_10_full ||
2380             hw->forced_speed_duplex == e1000_10_half)) {
2381             ret_val = e1000_polarity_reversal_workaround(hw);
2382             if(ret_val)
2383                 return ret_val;
2384         }
2385     } else if (hw->phy_type == e1000_phy_gg82563) {
2386         /* The TX_CLK of the Extended PHY Specific Control Register defaults
2387          * to 2.5MHz on a reset.  We need to re-force it back to 25MHz, if
2388          * we're not in a forced 10/duplex configuration. */
2389         ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2390         if (ret_val)
2391             return ret_val;
2392
2393         phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2394         if ((hw->forced_speed_duplex == e1000_10_full) ||
2395             (hw->forced_speed_duplex == e1000_10_half))
2396             phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2397         else
2398             phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2399
2400         /* Also due to the reset, we need to enable CRS on Tx. */
2401         phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2402
2403         ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2404         if (ret_val)
2405             return ret_val;
2406     }
2407     return E1000_SUCCESS;
2408 }
2409
2410 /******************************************************************************
2411 * Sets the collision distance in the Transmit Control register
2412 *
2413 * hw - Struct containing variables accessed by shared code
2414 *
2415 * Link should have been established previously. Reads the speed and duplex
2416 * information from the Device Status register.
2417 ******************************************************************************/
2418 void
2419 e1000_config_collision_dist(struct e1000_hw *hw)
2420 {
2421     uint32_t tctl, coll_dist;
2422
2423     DEBUGFUNC("e1000_config_collision_dist");
2424
2425     if (hw->mac_type < e1000_82543)
2426         coll_dist = E1000_COLLISION_DISTANCE_82542;
2427     else
2428         coll_dist = E1000_COLLISION_DISTANCE;
2429
2430     tctl = E1000_READ_REG(hw, TCTL);
2431
2432     tctl &= ~E1000_TCTL_COLD;
2433     tctl |= coll_dist << E1000_COLD_SHIFT;
2434
2435     E1000_WRITE_REG(hw, TCTL, tctl);
2436     E1000_WRITE_FLUSH(hw);
2437 }
2438
2439 /******************************************************************************
2440 * Sets MAC speed and duplex settings to reflect the those in the PHY
2441 *
2442 * hw - Struct containing variables accessed by shared code
2443 * mii_reg - data to write to the MII control register
2444 *
2445 * The contents of the PHY register containing the needed information need to
2446 * be passed in.
2447 ******************************************************************************/
2448 static int32_t
2449 e1000_config_mac_to_phy(struct e1000_hw *hw)
2450 {
2451     uint32_t ctrl;
2452     int32_t ret_val;
2453     uint16_t phy_data;
2454
2455     DEBUGFUNC("e1000_config_mac_to_phy");
2456
2457     /* 82544 or newer MAC, Auto Speed Detection takes care of
2458     * MAC speed/duplex configuration.*/
2459     if (hw->mac_type >= e1000_82544)
2460         return E1000_SUCCESS;
2461
2462     /* Read the Device Control Register and set the bits to Force Speed
2463      * and Duplex.
2464      */
2465     ctrl = E1000_READ_REG(hw, CTRL);
2466     ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2467     ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2468
2469     /* Set up duplex in the Device Control and Transmit Control
2470      * registers depending on negotiated values.
2471      */
2472     ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2473     if(ret_val)
2474         return ret_val;
2475
2476     if(phy_data & M88E1000_PSSR_DPLX)
2477         ctrl |= E1000_CTRL_FD;
2478     else
2479         ctrl &= ~E1000_CTRL_FD;
2480
2481     e1000_config_collision_dist(hw);
2482
2483     /* Set up speed in the Device Control register depending on
2484      * negotiated values.
2485      */
2486     if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2487         ctrl |= E1000_CTRL_SPD_1000;
2488     else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2489         ctrl |= E1000_CTRL_SPD_100;
2490
2491     /* Write the configured values back to the Device Control Reg. */
2492     E1000_WRITE_REG(hw, CTRL, ctrl);
2493     return E1000_SUCCESS;
2494 }
2495
2496 /******************************************************************************
2497  * Forces the MAC's flow control settings.
2498  *
2499  * hw - Struct containing variables accessed by shared code
2500  *
2501  * Sets the TFCE and RFCE bits in the device control register to reflect
2502  * the adapter settings. TFCE and RFCE need to be explicitly set by
2503  * software when a Copper PHY is used because autonegotiation is managed
2504  * by the PHY rather than the MAC. Software must also configure these
2505  * bits when link is forced on a fiber connection.
2506  *****************************************************************************/
2507 int32_t
2508 e1000_force_mac_fc(struct e1000_hw *hw)
2509 {
2510     uint32_t ctrl;
2511
2512     DEBUGFUNC("e1000_force_mac_fc");
2513
2514     /* Get the current configuration of the Device Control Register */
2515     ctrl = E1000_READ_REG(hw, CTRL);
2516
2517     /* Because we didn't get link via the internal auto-negotiation
2518      * mechanism (we either forced link or we got link via PHY
2519      * auto-neg), we have to manually enable/disable transmit an
2520      * receive flow control.
2521      *
2522      * The "Case" statement below enables/disable flow control
2523      * according to the "hw->fc" parameter.
2524      *
2525      * The possible values of the "fc" parameter are:
2526      *      0:  Flow control is completely disabled
2527      *      1:  Rx flow control is enabled (we can receive pause
2528      *          frames but not send pause frames).
2529      *      2:  Tx flow control is enabled (we can send pause frames
2530      *          frames but we do not receive pause frames).
2531      *      3:  Both Rx and TX flow control (symmetric) is enabled.
2532      *  other:  No other values should be possible at this point.
2533      */
2534
2535     switch (hw->fc) {
2536     case e1000_fc_none:
2537         ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2538         break;
2539     case e1000_fc_rx_pause:
2540         ctrl &= (~E1000_CTRL_TFCE);
2541         ctrl |= E1000_CTRL_RFCE;
2542         break;
2543     case e1000_fc_tx_pause:
2544         ctrl &= (~E1000_CTRL_RFCE);
2545         ctrl |= E1000_CTRL_TFCE;
2546         break;
2547     case e1000_fc_full:
2548         ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2549         break;
2550     default:
2551         DEBUGOUT("Flow control param set incorrectly\n");
2552         return -E1000_ERR_CONFIG;
2553     }
2554
2555     /* Disable TX Flow Control for 82542 (rev 2.0) */
2556     if(hw->mac_type == e1000_82542_rev2_0)
2557         ctrl &= (~E1000_CTRL_TFCE);
2558
2559     E1000_WRITE_REG(hw, CTRL, ctrl);
2560     return E1000_SUCCESS;
2561 }
2562
2563 /******************************************************************************
2564  * Configures flow control settings after link is established
2565  *
2566  * hw - Struct containing variables accessed by shared code
2567  *
2568  * Should be called immediately after a valid link has been established.
2569  * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2570  * and autonegotiation is enabled, the MAC flow control settings will be set
2571  * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2572  * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2573  *****************************************************************************/
2574 static int32_t
2575 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2576 {
2577     int32_t ret_val;
2578     uint16_t mii_status_reg;
2579     uint16_t mii_nway_adv_reg;
2580     uint16_t mii_nway_lp_ability_reg;
2581     uint16_t speed;
2582     uint16_t duplex;
2583
2584     DEBUGFUNC("e1000_config_fc_after_link_up");
2585
2586     /* Check for the case where we have fiber media and auto-neg failed
2587      * so we had to force link.  In this case, we need to force the
2588      * configuration of the MAC to match the "fc" parameter.
2589      */
2590     if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2591        ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2592        ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2593         ret_val = e1000_force_mac_fc(hw);
2594         if(ret_val) {
2595             DEBUGOUT("Error forcing flow control settings\n");
2596             return ret_val;
2597         }
2598     }
2599
2600     /* Check for the case where we have copper media and auto-neg is
2601      * enabled.  In this case, we need to check and see if Auto-Neg
2602      * has completed, and if so, how the PHY and link partner has
2603      * flow control configured.
2604      */
2605     if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2606         /* Read the MII Status Register and check to see if AutoNeg
2607          * has completed.  We read this twice because this reg has
2608          * some "sticky" (latched) bits.
2609          */
2610         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2611         if(ret_val)
2612             return ret_val;
2613         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2614         if(ret_val)
2615             return ret_val;
2616
2617         if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2618             /* The AutoNeg process has completed, so we now need to
2619              * read both the Auto Negotiation Advertisement Register
2620              * (Address 4) and the Auto_Negotiation Base Page Ability
2621              * Register (Address 5) to determine how flow control was
2622              * negotiated.
2623              */
2624             ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2625                                          &mii_nway_adv_reg);
2626             if(ret_val)
2627                 return ret_val;
2628             ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2629                                          &mii_nway_lp_ability_reg);
2630             if(ret_val)
2631                 return ret_val;
2632
2633             /* Two bits in the Auto Negotiation Advertisement Register
2634              * (Address 4) and two bits in the Auto Negotiation Base
2635              * Page Ability Register (Address 5) determine flow control
2636              * for both the PHY and the link partner.  The following
2637              * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2638              * 1999, describes these PAUSE resolution bits and how flow
2639              * control is determined based upon these settings.
2640              * NOTE:  DC = Don't Care
2641              *
2642              *   LOCAL DEVICE  |   LINK PARTNER
2643              * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2644              *-------|---------|-------|---------|--------------------
2645              *   0   |    0    |  DC   |   DC    | e1000_fc_none
2646              *   0   |    1    |   0   |   DC    | e1000_fc_none
2647              *   0   |    1    |   1   |    0    | e1000_fc_none
2648              *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
2649              *   1   |    0    |   0   |   DC    | e1000_fc_none
2650              *   1   |   DC    |   1   |   DC    | e1000_fc_full
2651              *   1   |    1    |   0   |    0    | e1000_fc_none
2652              *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
2653              *
2654              */
2655             /* Are both PAUSE bits set to 1?  If so, this implies
2656              * Symmetric Flow Control is enabled at both ends.  The
2657              * ASM_DIR bits are irrelevant per the spec.
2658              *
2659              * For Symmetric Flow Control:
2660              *
2661              *   LOCAL DEVICE  |   LINK PARTNER
2662              * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2663              *-------|---------|-------|---------|--------------------
2664              *   1   |   DC    |   1   |   DC    | e1000_fc_full
2665              *
2666              */
2667             if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2668                (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2669                 /* Now we need to check if the user selected RX ONLY
2670                  * of pause frames.  In this case, we had to advertise
2671                  * FULL flow control because we could not advertise RX
2672                  * ONLY. Hence, we must now check to see if we need to
2673                  * turn OFF  the TRANSMISSION of PAUSE frames.
2674                  */
2675                 if(hw->original_fc == e1000_fc_full) {
2676                     hw->fc = e1000_fc_full;
2677                     DEBUGOUT("Flow Control = FULL.\n");
2678                 } else {
2679                     hw->fc = e1000_fc_rx_pause;
2680                     DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2681                 }
2682             }
2683             /* For receiving PAUSE frames ONLY.
2684              *
2685              *   LOCAL DEVICE  |   LINK PARTNER
2686              * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2687              *-------|---------|-------|---------|--------------------
2688              *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
2689              *
2690              */
2691             else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2692                     (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2693                     (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2694                     (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2695                 hw->fc = e1000_fc_tx_pause;
2696                 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2697             }
2698             /* For transmitting PAUSE frames ONLY.
2699              *
2700              *   LOCAL DEVICE  |   LINK PARTNER
2701              * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2702              *-------|---------|-------|---------|--------------------
2703              *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
2704              *
2705              */
2706             else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2707                     (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2708                     !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2709                     (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2710                 hw->fc = e1000_fc_rx_pause;
2711                 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2712             }
2713             /* Per the IEEE spec, at this point flow control should be
2714              * disabled.  However, we want to consider that we could
2715              * be connected to a legacy switch that doesn't advertise
2716              * desired flow control, but can be forced on the link
2717              * partner.  So if we advertised no flow control, that is
2718              * what we will resolve to.  If we advertised some kind of
2719              * receive capability (Rx Pause Only or Full Flow Control)
2720              * and the link partner advertised none, we will configure
2721              * ourselves to enable Rx Flow Control only.  We can do
2722              * this safely for two reasons:  If the link partner really
2723              * didn't want flow control enabled, and we enable Rx, no
2724              * harm done since we won't be receiving any PAUSE frames
2725              * anyway.  If the intent on the link partner was to have
2726              * flow control enabled, then by us enabling RX only, we
2727              * can at least receive pause frames and process them.
2728              * This is a good idea because in most cases, since we are
2729              * predominantly a server NIC, more times than not we will
2730              * be asked to delay transmission of packets than asking
2731              * our link partner to pause transmission of frames.
2732              */
2733             else if((hw->original_fc == e1000_fc_none ||
2734                      hw->original_fc == e1000_fc_tx_pause) ||
2735                     hw->fc_strict_ieee) {
2736                 hw->fc = e1000_fc_none;
2737                 DEBUGOUT("Flow Control = NONE.\n");
2738             } else {
2739                 hw->fc = e1000_fc_rx_pause;
2740                 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2741             }
2742
2743             /* Now we need to do one last check...  If we auto-
2744              * negotiated to HALF DUPLEX, flow control should not be
2745              * enabled per IEEE 802.3 spec.
2746              */
2747             ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2748             if(ret_val) {
2749                 DEBUGOUT("Error getting link speed and duplex\n");
2750                 return ret_val;
2751             }
2752
2753             if(duplex == HALF_DUPLEX)
2754                 hw->fc = e1000_fc_none;
2755
2756             /* Now we call a subroutine to actually force the MAC
2757              * controller to use the correct flow control settings.
2758              */
2759             ret_val = e1000_force_mac_fc(hw);
2760             if(ret_val) {
2761                 DEBUGOUT("Error forcing flow control settings\n");
2762                 return ret_val;
2763             }
2764         } else {
2765             DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2766         }
2767     }
2768     return E1000_SUCCESS;
2769 }
2770
2771 /******************************************************************************
2772  * Checks to see if the link status of the hardware has changed.
2773  *
2774  * hw - Struct containing variables accessed by shared code
2775  *
2776  * Called by any function that needs to check the link status of the adapter.
2777  *****************************************************************************/
2778 int32_t
2779 e1000_check_for_link(struct e1000_hw *hw)
2780 {
2781     uint32_t rxcw = 0;
2782     uint32_t ctrl;
2783     uint32_t status;
2784     uint32_t rctl;
2785     uint32_t icr;
2786     uint32_t signal = 0;
2787     int32_t ret_val;
2788     uint16_t phy_data;
2789
2790     DEBUGFUNC("e1000_check_for_link");
2791
2792     ctrl = E1000_READ_REG(hw, CTRL);
2793     status = E1000_READ_REG(hw, STATUS);
2794
2795     /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2796      * set when the optics detect a signal. On older adapters, it will be
2797      * cleared when there is a signal.  This applies to fiber media only.
2798      */
2799     if((hw->media_type == e1000_media_type_fiber) ||
2800        (hw->media_type == e1000_media_type_internal_serdes)) {
2801         rxcw = E1000_READ_REG(hw, RXCW);
2802
2803         if(hw->media_type == e1000_media_type_fiber) {
2804             signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2805             if(status & E1000_STATUS_LU)
2806                 hw->get_link_status = FALSE;
2807         }
2808     }
2809
2810     /* If we have a copper PHY then we only want to go out to the PHY
2811      * registers to see if Auto-Neg has completed and/or if our link
2812      * status has changed.  The get_link_status flag will be set if we
2813      * receive a Link Status Change interrupt or we have Rx Sequence
2814      * Errors.
2815      */
2816     if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2817         /* First we want to see if the MII Status Register reports
2818          * link.  If so, then we want to get the current speed/duplex
2819          * of the PHY.
2820          * Read the register twice since the link bit is sticky.
2821          */
2822         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2823         if(ret_val)
2824             return ret_val;
2825         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2826         if(ret_val)
2827             return ret_val;
2828
2829         if(phy_data & MII_SR_LINK_STATUS) {
2830             hw->get_link_status = FALSE;
2831             /* Check if there was DownShift, must be checked immediately after
2832              * link-up */
2833             e1000_check_downshift(hw);
2834
2835             /* If we are on 82544 or 82543 silicon and speed/duplex
2836              * are forced to 10H or 10F, then we will implement the polarity
2837              * reversal workaround.  We disable interrupts first, and upon
2838              * returning, place the devices interrupt state to its previous
2839              * value except for the link status change interrupt which will
2840              * happen due to the execution of this workaround.
2841              */
2842
2843             if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2844                (!hw->autoneg) &&
2845                (hw->forced_speed_duplex == e1000_10_full ||
2846                 hw->forced_speed_duplex == e1000_10_half)) {
2847                 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2848                 ret_val = e1000_polarity_reversal_workaround(hw);
2849                 icr = E1000_READ_REG(hw, ICR);
2850                 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2851                 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2852             }
2853
2854         } else {
2855             /* No link detected */
2856             e1000_config_dsp_after_link_change(hw, FALSE);
2857             return 0;
2858         }
2859
2860         /* If we are forcing speed/duplex, then we simply return since
2861          * we have already determined whether we have link or not.
2862          */
2863         if(!hw->autoneg) return -E1000_ERR_CONFIG;
2864
2865         /* optimize the dsp settings for the igp phy */
2866         e1000_config_dsp_after_link_change(hw, TRUE);
2867
2868         /* We have a M88E1000 PHY and Auto-Neg is enabled.  If we
2869          * have Si on board that is 82544 or newer, Auto
2870          * Speed Detection takes care of MAC speed/duplex
2871          * configuration.  So we only need to configure Collision
2872          * Distance in the MAC.  Otherwise, we need to force
2873          * speed/duplex on the MAC to the current PHY speed/duplex
2874          * settings.
2875          */
2876         if(hw->mac_type >= e1000_82544)
2877             e1000_config_collision_dist(hw);
2878         else {
2879             ret_val = e1000_config_mac_to_phy(hw);
2880             if(ret_val) {
2881                 DEBUGOUT("Error configuring MAC to PHY settings\n");
2882                 return ret_val;
2883             }
2884         }
2885
2886         /* Configure Flow Control now that Auto-Neg has completed. First, we
2887          * need to restore the desired flow control settings because we may
2888          * have had to re-autoneg with a different link partner.
2889          */
2890         ret_val = e1000_config_fc_after_link_up(hw);
2891         if(ret_val) {
2892             DEBUGOUT("Error configuring flow control\n");
2893             return ret_val;
2894         }
2895
2896         /* At this point we know that we are on copper and we have
2897          * auto-negotiated link.  These are conditions for checking the link
2898          * partner capability register.  We use the link speed to determine if
2899          * TBI compatibility needs to be turned on or off.  If the link is not
2900          * at gigabit speed, then TBI compatibility is not needed.  If we are
2901          * at gigabit speed, we turn on TBI compatibility.
2902          */
2903         if(hw->tbi_compatibility_en) {
2904             uint16_t speed, duplex;
2905             ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2906             if (ret_val) {
2907                 DEBUGOUT("Error getting link speed and duplex\n");
2908                 return ret_val;
2909             }
2910             if (speed != SPEED_1000) {
2911                 /* If link speed is not set to gigabit speed, we do not need
2912                  * to enable TBI compatibility.
2913                  */
2914                 if(hw->tbi_compatibility_on) {
2915                     /* If we previously were in the mode, turn it off. */
2916                     rctl = E1000_READ_REG(hw, RCTL);
2917                     rctl &= ~E1000_RCTL_SBP;
2918                     E1000_WRITE_REG(hw, RCTL, rctl);
2919                     hw->tbi_compatibility_on = FALSE;
2920                 }
2921             } else {
2922                 /* If TBI compatibility is was previously off, turn it on. For
2923                  * compatibility with a TBI link partner, we will store bad
2924                  * packets. Some frames have an additional byte on the end and
2925                  * will look like CRC errors to to the hardware.
2926                  */
2927                 if(!hw->tbi_compatibility_on) {
2928                     hw->tbi_compatibility_on = TRUE;
2929                     rctl = E1000_READ_REG(hw, RCTL);
2930                     rctl |= E1000_RCTL_SBP;
2931                     E1000_WRITE_REG(hw, RCTL, rctl);
2932                 }
2933             }
2934         }
2935     }
2936     /* If we don't have link (auto-negotiation failed or link partner cannot
2937      * auto-negotiate), the cable is plugged in (we have signal), and our
2938      * link partner is not trying to auto-negotiate with us (we are receiving
2939      * idles or data), we need to force link up. We also need to give
2940      * auto-negotiation time to complete, in case the cable was just plugged
2941      * in. The autoneg_failed flag does this.
2942      */
2943     else if((((hw->media_type == e1000_media_type_fiber) &&
2944               ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2945              (hw->media_type == e1000_media_type_internal_serdes)) &&
2946             (!(status & E1000_STATUS_LU)) &&
2947             (!(rxcw & E1000_RXCW_C))) {
2948         if(hw->autoneg_failed == 0) {
2949             hw->autoneg_failed = 1;
2950             return 0;
2951         }
2952         DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2953
2954         /* Disable auto-negotiation in the TXCW register */
2955         E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2956
2957         /* Force link-up and also force full-duplex. */
2958         ctrl = E1000_READ_REG(hw, CTRL);
2959         ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2960         E1000_WRITE_REG(hw, CTRL, ctrl);
2961
2962         /* Configure Flow Control after forcing link up. */
2963         ret_val = e1000_config_fc_after_link_up(hw);
2964         if(ret_val) {
2965             DEBUGOUT("Error configuring flow control\n");
2966             return ret_val;
2967         }
2968     }
2969     /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2970      * auto-negotiation in the TXCW register and disable forced link in the
2971      * Device Control register in an attempt to auto-negotiate with our link
2972      * partner.
2973      */
2974     else if(((hw->media_type == e1000_media_type_fiber) ||
2975              (hw->media_type == e1000_media_type_internal_serdes)) &&
2976             (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2977         DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2978         E1000_WRITE_REG(hw, TXCW, hw->txcw);
2979         E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2980
2981         hw->serdes_link_down = FALSE;
2982     }
2983     /* If we force link for non-auto-negotiation switch, check link status
2984      * based on MAC synchronization for internal serdes media type.
2985      */
2986     else if((hw->media_type == e1000_media_type_internal_serdes) &&
2987             !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2988         /* SYNCH bit and IV bit are sticky. */
2989         udelay(10);
2990         if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2991             if(!(rxcw & E1000_RXCW_IV)) {
2992                 hw->serdes_link_down = FALSE;
2993                 DEBUGOUT("SERDES: Link is up.\n");
2994             }
2995         } else {
2996             hw->serdes_link_down = TRUE;
2997             DEBUGOUT("SERDES: Link is down.\n");
2998         }
2999     }
3000     if((hw->media_type == e1000_media_type_internal_serdes) &&
3001        (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3002         hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3003     }
3004     return E1000_SUCCESS;
3005 }
3006
3007 /******************************************************************************
3008  * Detects the current speed and duplex settings of the hardware.
3009  *
3010  * hw - Struct containing variables accessed by shared code
3011  * speed - Speed of the connection
3012  * duplex - Duplex setting of the connection
3013  *****************************************************************************/
3014 int32_t
3015 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3016                            uint16_t *speed,
3017                            uint16_t *duplex)
3018 {
3019     uint32_t status;
3020     int32_t ret_val;
3021     uint16_t phy_data;
3022
3023     DEBUGFUNC("e1000_get_speed_and_duplex");
3024
3025     if(hw->mac_type >= e1000_82543) {
3026         status = E1000_READ_REG(hw, STATUS);
3027         if(status & E1000_STATUS_SPEED_1000) {
3028             *speed = SPEED_1000;
3029             DEBUGOUT("1000 Mbs, ");
3030         } else if(status & E1000_STATUS_SPEED_100) {
3031             *speed = SPEED_100;
3032             DEBUGOUT("100 Mbs, ");
3033         } else {
3034             *speed = SPEED_10;
3035             DEBUGOUT("10 Mbs, ");
3036         }
3037
3038         if(status & E1000_STATUS_FD) {
3039             *duplex = FULL_DUPLEX;
3040             DEBUGOUT("Full Duplex\n");
3041         } else {
3042             *duplex = HALF_DUPLEX;
3043             DEBUGOUT(" Half Duplex\n");
3044         }
3045     } else {
3046         DEBUGOUT("1000 Mbs, Full Duplex\n");
3047         *speed = SPEED_1000;
3048         *duplex = FULL_DUPLEX;
3049     }
3050
3051     /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3052      * if it is operating at half duplex.  Here we set the duplex settings to
3053      * match the duplex in the link partner's capabilities.
3054      */
3055     if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3056         ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3057         if(ret_val)
3058             return ret_val;
3059
3060         if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3061             *duplex = HALF_DUPLEX;
3062         else {
3063             ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3064             if(ret_val)
3065                 return ret_val;
3066             if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3067                (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3068                 *duplex = HALF_DUPLEX;
3069         }
3070     }
3071
3072     if ((hw->mac_type == e1000_80003es2lan) &&
3073         (hw->media_type == e1000_media_type_copper)) {
3074         if (*speed == SPEED_1000)
3075             ret_val = e1000_configure_kmrn_for_1000(hw);
3076         else
3077             ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3078         if (ret_val)
3079             return ret_val;
3080     }
3081
3082     if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3083         ret_val = e1000_kumeran_lock_loss_workaround(hw);
3084         if (ret_val)
3085             return ret_val;
3086     }
3087
3088     return E1000_SUCCESS;
3089 }
3090
3091 /******************************************************************************
3092 * Blocks until autoneg completes or times out (~4.5 seconds)
3093 *
3094 * hw - Struct containing variables accessed by shared code
3095 ******************************************************************************/
3096 static int32_t
3097 e1000_wait_autoneg(struct e1000_hw *hw)
3098 {
3099     int32_t ret_val;
3100     uint16_t i;
3101     uint16_t phy_data;
3102
3103     DEBUGFUNC("e1000_wait_autoneg");
3104     DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3105
3106     /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3107     for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3108         /* Read the MII Status Register and wait for Auto-Neg
3109          * Complete bit to be set.
3110          */
3111         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3112         if(ret_val)
3113             return ret_val;
3114         ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3115         if(ret_val)
3116             return ret_val;
3117         if(phy_data & MII_SR_AUTONEG_COMPLETE) {
3118             return E1000_SUCCESS;
3119         }
3120         msec_delay(100);
3121     }
3122     return E1000_SUCCESS;
3123 }
3124
3125 /******************************************************************************
3126 * Raises the Management Data Clock
3127 *
3128 * hw - Struct containing variables accessed by shared code
3129 * ctrl - Device control register's current value
3130 ******************************************************************************/
3131 static void
3132 e1000_raise_mdi_clk(struct e1000_hw *hw,
3133                     uint32_t *ctrl)
3134 {
3135     /* Raise the clock input to the Management Data Clock (by setting the MDC
3136      * bit), and then delay 10 microseconds.
3137      */
3138     E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3139     E1000_WRITE_FLUSH(hw);
3140     udelay(10);
3141 }
3142
3143 /******************************************************************************
3144 * Lowers the Management Data Clock
3145 *
3146 * hw - Struct containing variables accessed by shared code
3147 * ctrl - Device control register's current value
3148 ******************************************************************************/
3149 static void
3150 e1000_lower_mdi_clk(struct e1000_hw *hw,
3151                     uint32_t *ctrl)
3152 {
3153     /* Lower the clock input to the Management Data Clock (by clearing the MDC
3154      * bit), and then delay 10 microseconds.
3155      */
3156     E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3157     E1000_WRITE_FLUSH(hw);
3158     udelay(10);
3159 }
3160
3161 /******************************************************************************
3162 * Shifts data bits out to the PHY
3163 *
3164 * hw - Struct containing variables accessed by shared code
3165 * data - Data to send out to the PHY
3166 * count - Number of bits to shift out
3167 *
3168 * Bits are shifted out in MSB to LSB order.
3169 ******************************************************************************/
3170 static void
3171 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3172                          uint32_t data,
3173                          uint16_t count)
3174 {
3175     uint32_t ctrl;
3176     uint32_t mask;
3177
3178     /* We need to shift "count" number of bits out to the PHY. So, the value
3179      * in the "data" parameter will be shifted out to the PHY one bit at a
3180      * time. In order to do this, "data" must be broken down into bits.
3181      */
3182     mask = 0x01;
3183     mask <<= (count - 1);
3184
3185     ctrl = E1000_READ_REG(hw, CTRL);
3186
3187     /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3188     ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3189
3190     while(mask) {
3191         /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3192          * then raising and lowering the Management Data Clock. A "0" is
3193          * shifted out to the PHY by setting the MDIO bit to "0" and then
3194          * raising and lowering the clock.
3195          */
3196         if(data & mask) ctrl |= E1000_CTRL_MDIO;
3197         else ctrl &= ~E1000_CTRL_MDIO;
3198
3199         E1000_WRITE_REG(hw, CTRL, ctrl);
3200         E1000_WRITE_FLUSH(hw);
3201
3202         udelay(10);
3203
3204         e1000_raise_mdi_clk(hw, &ctrl);
3205         e1000_lower_mdi_clk(hw, &ctrl);
3206
3207         mask = mask >> 1;
3208     }
3209 }
3210
3211 /******************************************************************************
3212 * Shifts data bits in from the PHY
3213 *
3214 * hw - Struct containing variables accessed by shared code
3215 *
3216 * Bits are shifted in in MSB to LSB order.
3217 ******************************************************************************/
3218 static uint16_t
3219 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3220 {
3221     uint32_t ctrl;
3222     uint16_t data = 0;
3223     uint8_t i;
3224
3225     /* In order to read a register from the PHY, we need to shift in a total
3226      * of 18 bits from the PHY. The first two bit (turnaround) times are used
3227      * to avoid contention on the MDIO pin when a read operation is performed.
3228      * These two bits are ignored by us and thrown away. Bits are "shifted in"
3229      * by raising the input to the Management Data Clock (setting the MDC bit),
3230      * and then reading the value of the MDIO bit.
3231      */
3232     ctrl = E1000_READ_REG(hw, CTRL);
3233
3234     /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3235     ctrl &= ~E1000_CTRL_MDIO_DIR;
3236     ctrl &= ~E1000_CTRL_MDIO;
3237
3238     E1000_WRITE_REG(hw, CTRL, ctrl);
3239     E1000_WRITE_FLUSH(hw);
3240
3241     /* Raise and Lower the clock before reading in the data. This accounts for
3242      * the turnaround bits. The first clock occurred when we clocked out the
3243      * last bit of the Register Address.
3244      */
3245     e1000_raise_mdi_clk(hw, &ctrl);
3246     e1000_lower_mdi_clk(hw, &ctrl);
3247
3248     for(data = 0, i = 0; i < 16; i++) {
3249         data = data << 1;
3250         e1000_raise_mdi_clk(hw, &ctrl);
3251         ctrl = E1000_READ_REG(hw, CTRL);
3252         /* Check to see if we shifted in a "1". */
3253         if(ctrl & E1000_CTRL_MDIO) data |= 1;
3254         e1000_lower_mdi_clk(hw, &ctrl);
3255     }
3256
3257     e1000_raise_mdi_clk(hw, &ctrl);
3258     e1000_lower_mdi_clk(hw, &ctrl);
3259
3260     return data;
3261 }
3262
3263 static int32_t
3264 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3265 {
3266     uint32_t swfw_sync = 0;
3267     uint32_t swmask = mask;
3268     uint32_t fwmask = mask << 16;
3269     int32_t timeout = 200;
3270
3271     DEBUGFUNC("e1000_swfw_sync_acquire");
3272
3273     if (hw->swfwhw_semaphore_present)
3274         return e1000_get_software_flag(hw);
3275
3276     if (!hw->swfw_sync_present)
3277         return e1000_get_hw_eeprom_semaphore(hw);
3278
3279     while(timeout) {
3280             if (e1000_get_hw_eeprom_semaphore(hw))
3281                 return -E1000_ERR_SWFW_SYNC;
3282
3283             swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3284             if (!(swfw_sync & (fwmask | swmask))) {
3285                 break;
3286             }
3287
3288             /* firmware currently using resource (fwmask) */
3289             /* or other software thread currently using resource (swmask) */
3290             e1000_put_hw_eeprom_semaphore(hw);
3291             msec_delay_irq(5);
3292             timeout--;
3293     }
3294
3295     if (!timeout) {
3296         DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3297         return -E1000_ERR_SWFW_SYNC;
3298     }
3299
3300     swfw_sync |= swmask;
3301     E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3302
3303     e1000_put_hw_eeprom_semaphore(hw);
3304     return E1000_SUCCESS;
3305 }
3306
3307 static void
3308 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3309 {
3310     uint32_t swfw_sync;
3311     uint32_t swmask = mask;
3312
3313     DEBUGFUNC("e1000_swfw_sync_release");
3314
3315     if (hw->swfwhw_semaphore_present) {
3316         e1000_release_software_flag(hw);
3317         return;
3318     }
3319
3320     if (!hw->swfw_sync_present) {
3321         e1000_put_hw_eeprom_semaphore(hw);
3322         return;
3323     }
3324
3325     /* if (e1000_get_hw_eeprom_semaphore(hw))
3326      *    return -E1000_ERR_SWFW_SYNC; */
3327     while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3328         /* empty */
3329
3330     swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3331     swfw_sync &= ~swmask;
3332     E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3333
3334     e1000_put_hw_eeprom_semaphore(hw);
3335 }
3336
3337 /*****************************************************************************
3338 * Reads the value from a PHY register, if the value is on a specific non zero
3339 * page, sets the page first.
3340 * hw - Struct containing variables accessed by shared code
3341 * reg_addr - address of the PHY register to read
3342 ******************************************************************************/
3343 int32_t
3344 e1000_read_phy_reg(struct e1000_hw *hw,
3345                    uint32_t reg_addr,
3346                    uint16_t *phy_data)
3347 {
3348     uint32_t ret_val;
3349     uint16_t swfw;
3350
3351     DEBUGFUNC("e1000_read_phy_reg");
3352
3353     if ((hw->mac_type == e1000_80003es2lan) &&
3354         (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3355         swfw = E1000_SWFW_PHY1_SM;
3356     } else {
3357         swfw = E1000_SWFW_PHY0_SM;
3358     }
3359     if (e1000_swfw_sync_acquire(hw, swfw))
3360         return -E1000_ERR_SWFW_SYNC;
3361
3362     if ((hw->phy_type == e1000_phy_igp ||
3363         hw->phy_type == e1000_phy_igp_3 ||
3364         hw->phy_type == e1000_phy_igp_2) &&
3365        (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3366         ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3367                                          (uint16_t)reg_addr);
3368         if(ret_val) {
3369             e1000_swfw_sync_release(hw, swfw);
3370             return ret_val;
3371         }
3372     } else if (hw->phy_type == e1000_phy_gg82563) {
3373         if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3374             (hw->mac_type == e1000_80003es2lan)) {
3375             /* Select Configuration Page */
3376             if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3377                 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3378                           (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3379             } else {
3380                 /* Use Alternative Page Select register to access