blob: 10b8c8c25325acd63eef44ac369c4ee94e4fa891 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
Auke Kok3d41e302006-04-14 19:05:31 -07004 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
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>
Auke Kok3d41e302006-04-14 19:05:31 -070025 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 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
Auke Kok8fc897b2006-08-28 14:56:16 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "e1000_hw.h"
36
37static int32_t e1000_set_phy_type(struct e1000_hw *hw);
38static void e1000_phy_init_script(struct e1000_hw *hw);
39static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
40static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
41static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
42static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
43static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
44static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
45static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
46static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
47 uint16_t count);
48static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
49static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
50static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
51 uint16_t words, uint16_t *data);
52static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
53 uint16_t offset, uint16_t words,
54 uint16_t *data);
55static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
56static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
57static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
58static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
59 uint16_t count);
60static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
61 uint16_t phy_data);
62static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
63 uint16_t *phy_data);
64static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
65static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
66static void e1000_release_eeprom(struct e1000_hw *hw);
67static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
69static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
70static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -070071static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
72static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010073static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
74static int32_t e1000_check_downshift(struct e1000_hw *hw);
75static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
76static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
77static void e1000_clear_vfta(struct e1000_hw *hw);
78static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
79static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
80 boolean_t link_up);
81static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
82static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
83static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
84static int32_t e1000_get_cable_length(struct e1000_hw *hw,
85 uint16_t *min_length,
86 uint16_t *max_length);
87static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
88static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
89static int32_t e1000_id_led_init(struct e1000_hw * hw);
90static void e1000_init_rx_addrs(struct e1000_hw *hw);
91static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
92static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
93static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
94static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
95 uint16_t words, uint16_t *data);
96static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
97static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
98static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
99
100static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
101 uint32_t value);
102
103#define E1000_WRITE_REG_IO(a, reg, val) \
104 e1000_write_reg_io((a), E1000_##reg, val)
Auke Kokcd94dd02006-06-27 09:08:22 -0700105static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
106 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800107static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Adrian Bunke4c780b2006-08-14 23:00:10 -0700109static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw,
110 uint32_t segment);
111static int32_t e1000_get_software_flag(struct e1000_hw *hw);
112static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
113static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
114static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
115static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
116 uint16_t words, uint16_t *data);
117static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index,
118 uint8_t* data);
119static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index,
120 uint16_t *data);
121static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
122 uint16_t *data);
123static void e1000_release_software_flag(struct e1000_hw *hw);
124static void e1000_release_software_semaphore(struct e1000_hw *hw);
125static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw,
126 uint32_t no_snoop);
127static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw,
128 uint32_t index, uint8_t byte);
129static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
130 uint16_t words, uint16_t *data);
131static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index,
132 uint8_t data);
133static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
134 uint16_t data);
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* IGP cable length table */
137static const
138uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
139 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
140 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
141 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
142 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
143 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
144 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
145 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
146 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
147
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700148static const
149uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400150 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
151 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
152 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
153 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
154 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
155 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
156 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
157 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160/******************************************************************************
161 * Set the phy type member in the hw struct.
162 *
163 * hw - Struct containing variables accessed by shared code
164 *****************************************************************************/
165int32_t
166e1000_set_phy_type(struct e1000_hw *hw)
167{
168 DEBUGFUNC("e1000_set_phy_type");
169
Auke Kok8fc897b2006-08-28 14:56:16 -0700170 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700171 return -E1000_ERR_PHY_TYPE;
172
Auke Kok8fc897b2006-08-28 14:56:16 -0700173 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 case M88E1000_E_PHY_ID:
175 case M88E1000_I_PHY_ID:
176 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700177 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 hw->phy_type = e1000_phy_m88;
179 break;
180 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700181 if (hw->mac_type == e1000_82541 ||
182 hw->mac_type == e1000_82541_rev_2 ||
183 hw->mac_type == e1000_82547 ||
184 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 hw->phy_type = e1000_phy_igp;
186 break;
187 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700188 case IGP03E1000_E_PHY_ID:
189 hw->phy_type = e1000_phy_igp_3;
190 break;
191 case IFE_E_PHY_ID:
192 case IFE_PLUS_E_PHY_ID:
193 case IFE_C_E_PHY_ID:
194 hw->phy_type = e1000_phy_ife;
195 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800196 case GG82563_E_PHY_ID:
197 if (hw->mac_type == e1000_80003es2lan) {
198 hw->phy_type = e1000_phy_gg82563;
199 break;
200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* Fall Through */
202 default:
203 /* Should never have loaded on this device */
204 hw->phy_type = e1000_phy_undefined;
205 return -E1000_ERR_PHY_TYPE;
206 }
207
208 return E1000_SUCCESS;
209}
210
Auke Kok8fc897b2006-08-28 14:56:16 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/******************************************************************************
213 * IGP phy init script - initializes the GbE PHY
214 *
215 * hw - Struct containing variables accessed by shared code
216 *****************************************************************************/
217static void
218e1000_phy_init_script(struct e1000_hw *hw)
219{
220 uint32_t ret_val;
221 uint16_t phy_saved_data;
222
223 DEBUGFUNC("e1000_phy_init_script");
224
Auke Kok8fc897b2006-08-28 14:56:16 -0700225 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400226 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* Save off the current value of register 0x2F5B to be restored at
229 * the end of this routine. */
230 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
231
232 /* Disabled the PHY transmitter */
233 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
234
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400235 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 e1000_write_phy_reg(hw,0x0000,0x0140);
238
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400239 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Auke Kok8fc897b2006-08-28 14:56:16 -0700241 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 case e1000_82541:
243 case e1000_82547:
244 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
245
246 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
247
248 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
249
250 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
251
252 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
253
254 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
255
256 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
257
258 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
259
260 e1000_write_phy_reg(hw, 0x2010, 0x0008);
261 break;
262
263 case e1000_82541_rev_2:
264 case e1000_82547_rev_2:
265 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
266 break;
267 default:
268 break;
269 }
270
271 e1000_write_phy_reg(hw, 0x0000, 0x3300);
272
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400273 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 /* Now enable the transmitter */
276 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
277
Auke Kok8fc897b2006-08-28 14:56:16 -0700278 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 uint16_t fused, fine, coarse;
280
281 /* Move to analog registers page */
282 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
283
Auke Kok8fc897b2006-08-28 14:56:16 -0700284 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
286
287 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
288 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
289
Auke Kok8fc897b2006-08-28 14:56:16 -0700290 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
292 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700293 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
295
296 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
297 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
298 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
299
300 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
301 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
302 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
303 }
304 }
305 }
306}
307
308/******************************************************************************
309 * Set the mac type member in the hw struct.
310 *
311 * hw - Struct containing variables accessed by shared code
312 *****************************************************************************/
313int32_t
314e1000_set_mac_type(struct e1000_hw *hw)
315{
316 DEBUGFUNC("e1000_set_mac_type");
317
318 switch (hw->device_id) {
319 case E1000_DEV_ID_82542:
320 switch (hw->revision_id) {
321 case E1000_82542_2_0_REV_ID:
322 hw->mac_type = e1000_82542_rev2_0;
323 break;
324 case E1000_82542_2_1_REV_ID:
325 hw->mac_type = e1000_82542_rev2_1;
326 break;
327 default:
328 /* Invalid 82542 revision ID */
329 return -E1000_ERR_MAC_TYPE;
330 }
331 break;
332 case E1000_DEV_ID_82543GC_FIBER:
333 case E1000_DEV_ID_82543GC_COPPER:
334 hw->mac_type = e1000_82543;
335 break;
336 case E1000_DEV_ID_82544EI_COPPER:
337 case E1000_DEV_ID_82544EI_FIBER:
338 case E1000_DEV_ID_82544GC_COPPER:
339 case E1000_DEV_ID_82544GC_LOM:
340 hw->mac_type = e1000_82544;
341 break;
342 case E1000_DEV_ID_82540EM:
343 case E1000_DEV_ID_82540EM_LOM:
344 case E1000_DEV_ID_82540EP:
345 case E1000_DEV_ID_82540EP_LOM:
346 case E1000_DEV_ID_82540EP_LP:
347 hw->mac_type = e1000_82540;
348 break;
349 case E1000_DEV_ID_82545EM_COPPER:
350 case E1000_DEV_ID_82545EM_FIBER:
351 hw->mac_type = e1000_82545;
352 break;
353 case E1000_DEV_ID_82545GM_COPPER:
354 case E1000_DEV_ID_82545GM_FIBER:
355 case E1000_DEV_ID_82545GM_SERDES:
356 hw->mac_type = e1000_82545_rev_3;
357 break;
358 case E1000_DEV_ID_82546EB_COPPER:
359 case E1000_DEV_ID_82546EB_FIBER:
360 case E1000_DEV_ID_82546EB_QUAD_COPPER:
361 hw->mac_type = e1000_82546;
362 break;
363 case E1000_DEV_ID_82546GB_COPPER:
364 case E1000_DEV_ID_82546GB_FIBER:
365 case E1000_DEV_ID_82546GB_SERDES:
366 case E1000_DEV_ID_82546GB_PCIE:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800367 case E1000_DEV_ID_82546GB_QUAD_COPPER:
368 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 hw->mac_type = e1000_82546_rev_3;
370 break;
371 case E1000_DEV_ID_82541EI:
372 case E1000_DEV_ID_82541EI_MOBILE:
Auke Kokcd94dd02006-06-27 09:08:22 -0700373 case E1000_DEV_ID_82541ER_LOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 hw->mac_type = e1000_82541;
375 break;
376 case E1000_DEV_ID_82541ER:
377 case E1000_DEV_ID_82541GI:
378 case E1000_DEV_ID_82541GI_LF:
379 case E1000_DEV_ID_82541GI_MOBILE:
380 hw->mac_type = e1000_82541_rev_2;
381 break;
382 case E1000_DEV_ID_82547EI:
Auke Kokcd94dd02006-06-27 09:08:22 -0700383 case E1000_DEV_ID_82547EI_MOBILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 hw->mac_type = e1000_82547;
385 break;
386 case E1000_DEV_ID_82547GI:
387 hw->mac_type = e1000_82547_rev_2;
388 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400389 case E1000_DEV_ID_82571EB_COPPER:
390 case E1000_DEV_ID_82571EB_FIBER:
391 case E1000_DEV_ID_82571EB_SERDES:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700392 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400393 hw->mac_type = e1000_82571;
394 break;
395 case E1000_DEV_ID_82572EI_COPPER:
396 case E1000_DEV_ID_82572EI_FIBER:
397 case E1000_DEV_ID_82572EI_SERDES:
Auke Kokcd94dd02006-06-27 09:08:22 -0700398 case E1000_DEV_ID_82572EI:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400399 hw->mac_type = e1000_82572;
400 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700401 case E1000_DEV_ID_82573E:
402 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400403 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700404 hw->mac_type = e1000_82573;
405 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700406 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
407 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800408 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
409 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
410 hw->mac_type = e1000_80003es2lan;
411 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700412 case E1000_DEV_ID_ICH8_IGP_M_AMT:
413 case E1000_DEV_ID_ICH8_IGP_AMT:
414 case E1000_DEV_ID_ICH8_IGP_C:
415 case E1000_DEV_ID_ICH8_IFE:
416 case E1000_DEV_ID_ICH8_IGP_M:
417 hw->mac_type = e1000_ich8lan;
418 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 default:
420 /* Should never have loaded on this device */
421 return -E1000_ERR_MAC_TYPE;
422 }
423
Auke Kok8fc897b2006-08-28 14:56:16 -0700424 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700425 case e1000_ich8lan:
426 hw->swfwhw_semaphore_present = TRUE;
427 hw->asf_firmware_present = TRUE;
428 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800429 case e1000_80003es2lan:
430 hw->swfw_sync_present = TRUE;
431 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400432 case e1000_82571:
433 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700434 case e1000_82573:
435 hw->eeprom_semaphore_present = TRUE;
436 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 case e1000_82541:
438 case e1000_82547:
439 case e1000_82541_rev_2:
440 case e1000_82547_rev_2:
441 hw->asf_firmware_present = TRUE;
442 break;
443 default:
444 break;
445 }
446
447 return E1000_SUCCESS;
448}
449
450/*****************************************************************************
451 * Set media type and TBI compatibility.
452 *
453 * hw - Struct containing variables accessed by shared code
454 * **************************************************************************/
455void
456e1000_set_media_type(struct e1000_hw *hw)
457{
458 uint32_t status;
459
460 DEBUGFUNC("e1000_set_media_type");
461
Auke Kok8fc897b2006-08-28 14:56:16 -0700462 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 /* tbi_compatibility is only valid on 82543 */
464 hw->tbi_compatibility_en = FALSE;
465 }
466
467 switch (hw->device_id) {
468 case E1000_DEV_ID_82545GM_SERDES:
469 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400470 case E1000_DEV_ID_82571EB_SERDES:
471 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800472 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 hw->media_type = e1000_media_type_internal_serdes;
474 break;
475 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700476 switch (hw->mac_type) {
477 case e1000_82542_rev2_0:
478 case e1000_82542_rev2_1:
479 hw->media_type = e1000_media_type_fiber;
480 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700481 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700482 case e1000_82573:
483 /* The STATUS_TBIMODE bit is reserved or reused for the this
484 * device.
485 */
486 hw->media_type = e1000_media_type_copper;
487 break;
488 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700490 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 hw->media_type = e1000_media_type_fiber;
492 /* tbi_compatibility not valid on fiber */
493 hw->tbi_compatibility_en = FALSE;
494 } else {
495 hw->media_type = e1000_media_type_copper;
496 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499 }
500}
501
502/******************************************************************************
503 * Reset the transmit and receive units; mask and clear all interrupts.
504 *
505 * hw - Struct containing variables accessed by shared code
506 *****************************************************************************/
507int32_t
508e1000_reset_hw(struct e1000_hw *hw)
509{
510 uint32_t ctrl;
511 uint32_t ctrl_ext;
512 uint32_t icr;
513 uint32_t manc;
514 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700515 uint32_t timeout;
516 uint32_t extcnf_ctrl;
517 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 DEBUGFUNC("e1000_reset_hw");
520
521 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700522 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
524 e1000_pci_clear_mwi(hw);
525 }
526
Auke Kok8fc897b2006-08-28 14:56:16 -0700527 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700528 /* Prevent the PCI-E bus from sticking if there is no TLP connection
529 * on the last TLP read/write transaction when MAC is reset.
530 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700531 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700532 DEBUGOUT("PCI-E Master disable polling has failed.\n");
533 }
534 }
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 /* Clear interrupt mask to stop board from generating interrupts */
537 DEBUGOUT("Masking off all interrupts\n");
538 E1000_WRITE_REG(hw, IMC, 0xffffffff);
539
540 /* Disable the Transmit and Receive units. Then delay to allow
541 * any pending transactions to complete before we hit the MAC with
542 * the global reset.
543 */
544 E1000_WRITE_REG(hw, RCTL, 0);
545 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
546 E1000_WRITE_FLUSH(hw);
547
548 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
549 hw->tbi_compatibility_on = FALSE;
550
551 /* Delay to allow any outstanding PCI transactions to complete before
552 * resetting the device
553 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400554 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 ctrl = E1000_READ_REG(hw, CTRL);
557
558 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700559 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700560 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400561 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700564 /* Must acquire the MDIO ownership before MAC reset.
565 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700566 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700567 timeout = 10;
568
569 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
570 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
571
572 do {
573 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
574 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
575
Auke Kok8fc897b2006-08-28 14:56:16 -0700576 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700577 break;
578 else
579 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
580
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400581 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700582 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700583 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700584 }
585
Auke Kokcd94dd02006-06-27 09:08:22 -0700586 /* Workaround for ICH8 bit corruption issue in FIFO memory */
587 if (hw->mac_type == e1000_ich8lan) {
588 /* Set Tx and Rx buffer allocation to 8k apiece. */
589 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
590 /* Set Packet Buffer Size to 16k. */
591 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
592 }
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 /* Issue a global reset to the MAC. This will reset the chip's
595 * transmit, receive, DMA, and link units. It will not effect
596 * the current PCI configuration. The global reset bit is self-
597 * clearing, and should clear within a microsecond.
598 */
599 DEBUGOUT("Issuing a global reset to MAC\n");
600
Auke Kok8fc897b2006-08-28 14:56:16 -0700601 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 case e1000_82544:
603 case e1000_82540:
604 case e1000_82545:
605 case e1000_82546:
606 case e1000_82541:
607 case e1000_82541_rev_2:
608 /* These controllers can't ack the 64-bit write when issuing the
609 * reset, so use IO-mapping as a workaround to issue the reset */
610 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
611 break;
612 case e1000_82545_rev_3:
613 case e1000_82546_rev_3:
614 /* Reset is performed on a shadow of the control register */
615 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
616 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700617 case e1000_ich8lan:
618 if (!hw->phy_reset_disable &&
619 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
620 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
621 * at the same time to make sure the interface between
622 * MAC and the external PHY is reset.
623 */
624 ctrl |= E1000_CTRL_PHY_RST;
625 }
626
627 e1000_get_software_flag(hw);
628 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400629 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700630 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 default:
632 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
633 break;
634 }
635
636 /* After MAC reset, force reload of EEPROM to restore power-on settings to
637 * device. Later controllers reload the EEPROM automatically, so just wait
638 * for reload to complete.
639 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700640 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 case e1000_82542_rev2_0:
642 case e1000_82542_rev2_1:
643 case e1000_82543:
644 case e1000_82544:
645 /* Wait for reset to complete */
646 udelay(10);
647 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
648 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
649 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
650 E1000_WRITE_FLUSH(hw);
651 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400652 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 break;
654 case e1000_82541:
655 case e1000_82541_rev_2:
656 case e1000_82547:
657 case e1000_82547_rev_2:
658 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400659 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700661 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500662 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
663 udelay(10);
664 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
665 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
666 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
667 E1000_WRITE_FLUSH(hw);
668 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700669 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400670 case e1000_82571:
671 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -0700672 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800673 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700674 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700675 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700676 /* We don't want to continue accessing MAC registers. */
677 return ret_val;
678 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 default:
680 /* Wait for EEPROM reload (it happens automatically) */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400681 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 break;
683 }
684
685 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700686 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 manc = E1000_READ_REG(hw, MANC);
688 manc &= ~(E1000_MANC_ARP_EN);
689 E1000_WRITE_REG(hw, MANC, manc);
690 }
691
Auke Kok8fc897b2006-08-28 14:56:16 -0700692 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 e1000_phy_init_script(hw);
694
695 /* Configure activity LED after PHY reset */
696 led_ctrl = E1000_READ_REG(hw, LEDCTL);
697 led_ctrl &= IGP_ACTIVITY_LED_MASK;
698 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
699 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
700 }
701
702 /* Clear interrupt mask to stop board from generating interrupts */
703 DEBUGOUT("Masking off all interrupts\n");
704 E1000_WRITE_REG(hw, IMC, 0xffffffff);
705
706 /* Clear any pending interrupt events. */
707 icr = E1000_READ_REG(hw, ICR);
708
709 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700710 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400711 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 e1000_pci_set_mwi(hw);
713 }
714
Auke Kokcd94dd02006-06-27 09:08:22 -0700715 if (hw->mac_type == e1000_ich8lan) {
716 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
717 kab |= E1000_KABGTXD_BGSQLBIAS;
718 E1000_WRITE_REG(hw, KABGTXD, kab);
719 }
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return E1000_SUCCESS;
722}
723
724/******************************************************************************
725 * Performs basic configuration of the adapter.
726 *
727 * hw - Struct containing variables accessed by shared code
728 *
729 * Assumes that the controller has previously been reset and is in a
730 * post-reset uninitialized state. Initializes the receive address registers,
731 * multicast table, and VLAN filter table. Calls routines to setup link
732 * configuration and flow control settings. Clears all on-chip counters. Leaves
733 * the transmit and receive units disabled and uninitialized.
734 *****************************************************************************/
735int32_t
736e1000_init_hw(struct e1000_hw *hw)
737{
738 uint32_t ctrl;
739 uint32_t i;
740 int32_t ret_val;
741 uint16_t pcix_cmd_word;
742 uint16_t pcix_stat_hi_word;
743 uint16_t cmd_mmrbc;
744 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700745 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800746 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800747 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 DEBUGFUNC("e1000_init_hw");
750
Jeff Kirsher7820d422006-08-16 13:39:00 -0700751 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
752 if (hw->mac_type == e1000_ich8lan) {
753 reg_data = E1000_READ_REG(hw, TARC0);
754 reg_data |= 0x30000000;
755 E1000_WRITE_REG(hw, TARC0, reg_data);
756
757 reg_data = E1000_READ_REG(hw, STATUS);
758 reg_data &= ~0x80000000;
759 E1000_WRITE_REG(hw, STATUS, reg_data);
760 }
761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 /* Initialize Identification LED */
763 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700764 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 DEBUGOUT("Error Initializing Identification LED\n");
766 return ret_val;
767 }
768
769 /* Set the media type and TBI compatibility */
770 e1000_set_media_type(hw);
771
772 /* Disabling VLAN filtering. */
773 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700774 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
775 if (hw->mac_type != e1000_ich8lan) {
776 if (hw->mac_type < e1000_82545_rev_3)
777 E1000_WRITE_REG(hw, VET, 0);
778 e1000_clear_vfta(hw);
779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700782 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
784 e1000_pci_clear_mwi(hw);
785 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
786 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400787 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 }
789
790 /* Setup the receive address. This involves initializing all of the Receive
791 * Address Registers (RARs 0 - 15).
792 */
793 e1000_init_rx_addrs(hw);
794
795 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700796 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 E1000_WRITE_REG(hw, RCTL, 0);
798 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400799 msleep(1);
800 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 e1000_pci_set_mwi(hw);
802 }
803
804 /* Zero out the Multicast HASH table */
805 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700806 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700807 if (hw->mac_type == e1000_ich8lan)
808 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700809 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700811 /* use write flush to prevent Memory Write Block (MWB) from
812 * occuring when accessing our register space */
813 E1000_WRITE_FLUSH(hw);
814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 /* Set the PCI priority bit correctly in the CTRL register. This
817 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700818 * gives equal priority to transmits and receives. Valid only on
819 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700821 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 ctrl = E1000_READ_REG(hw, CTRL);
823 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
824 }
825
Auke Kok8fc897b2006-08-28 14:56:16 -0700826 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 case e1000_82545_rev_3:
828 case e1000_82546_rev_3:
829 break;
830 default:
831 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700832 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
834 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
835 &pcix_stat_hi_word);
836 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
837 PCIX_COMMAND_MMRBC_SHIFT;
838 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
839 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700840 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700842 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
844 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
845 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
846 &pcix_cmd_word);
847 }
848 }
849 break;
850 }
851
Auke Kokcd94dd02006-06-27 09:08:22 -0700852 /* More time needed for PHY to initialize */
853 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400854 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* Call a subroutine to configure the link and setup flow control. */
857 ret_val = e1000_setup_link(hw);
858
859 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700860 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 ctrl = E1000_READ_REG(hw, TXDCTL);
862 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700863 switch (hw->mac_type) {
864 default:
865 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400866 case e1000_82571:
867 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700868 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -0700869 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800870 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700871 ctrl |= E1000_TXDCTL_COUNT_DESC;
872 break;
873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 E1000_WRITE_REG(hw, TXDCTL, ctrl);
875 }
876
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700877 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700878 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700879 }
880
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400881 switch (hw->mac_type) {
882 default:
883 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800884 case e1000_80003es2lan:
885 /* Enable retransmit on late collisions */
886 reg_data = E1000_READ_REG(hw, TCTL);
887 reg_data |= E1000_TCTL_RTLC;
888 E1000_WRITE_REG(hw, TCTL, reg_data);
889
890 /* Configure Gigabit Carry Extend Padding */
891 reg_data = E1000_READ_REG(hw, TCTL_EXT);
892 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
893 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
894 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
895
896 /* Configure Transmit Inter-Packet Gap */
897 reg_data = E1000_READ_REG(hw, TIPG);
898 reg_data &= ~E1000_TIPG_IPGT_MASK;
899 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
900 E1000_WRITE_REG(hw, TIPG, reg_data);
901
902 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
903 reg_data &= ~0x00100000;
904 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
905 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400906 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400907 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -0700908 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400909 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800910 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Auke Kok8fc897b2006-08-28 14:56:16 -0700911 if (hw->mac_type >= e1000_82571)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800912 ctrl |= E1000_TXDCTL_COUNT_DESC;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400913 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
914 break;
915 }
916
917
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400918 if (hw->mac_type == e1000_82573) {
919 uint32_t gcr = E1000_READ_REG(hw, GCR);
920 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
921 E1000_WRITE_REG(hw, GCR, gcr);
922 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 /* Clear all of the statistics registers (clear on read). It is
925 * important that we do this after we have tried to establish link
926 * because the symbol error count will increment wildly if there
927 * is no link.
928 */
929 e1000_clear_hw_cntrs(hw);
930
Auke Kokcd94dd02006-06-27 09:08:22 -0700931 /* ICH8 No-snoop bits are opposite polarity.
932 * Set to snoop by default after reset. */
933 if (hw->mac_type == e1000_ich8lan)
934 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
935
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800936 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
937 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
938 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
939 /* Relaxed ordering must be disabled to avoid a parity
940 * error crash in a PCI slot. */
941 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
942 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
943 }
944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return ret_val;
946}
947
948/******************************************************************************
949 * Adjust SERDES output amplitude based on EEPROM setting.
950 *
951 * hw - Struct containing variables accessed by shared code.
952 *****************************************************************************/
953static int32_t
954e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
955{
956 uint16_t eeprom_data;
957 int32_t ret_val;
958
959 DEBUGFUNC("e1000_adjust_serdes_amplitude");
960
Auke Kok8fc897b2006-08-28 14:56:16 -0700961 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 return E1000_SUCCESS;
963
Auke Kok8fc897b2006-08-28 14:56:16 -0700964 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 case e1000_82545_rev_3:
966 case e1000_82546_rev_3:
967 break;
968 default:
969 return E1000_SUCCESS;
970 }
971
972 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
973 if (ret_val) {
974 return ret_val;
975 }
976
Auke Kok8fc897b2006-08-28 14:56:16 -0700977 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -0700979 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -0700981 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 return ret_val;
983 }
984
985 return E1000_SUCCESS;
986}
987
988/******************************************************************************
989 * Configures flow control and link settings.
990 *
991 * hw - Struct containing variables accessed by shared code
992 *
993 * Determines which flow control settings to use. Calls the apropriate media-
994 * specific link configuration function. Configures the flow control settings.
995 * Assuming the adapter has a valid link partner, a valid link should be
996 * established. Assumes the hardware has previously been reset and the
997 * transmitter and receiver are not enabled.
998 *****************************************************************************/
999int32_t
1000e1000_setup_link(struct e1000_hw *hw)
1001{
1002 uint32_t ctrl_ext;
1003 int32_t ret_val;
1004 uint16_t eeprom_data;
1005
1006 DEBUGFUNC("e1000_setup_link");
1007
Jeff Kirsher526f9952006-01-12 16:50:46 -08001008 /* In the case of the phy reset being blocked, we already have a link.
1009 * We do not have to set it up again. */
1010 if (e1000_check_phy_reset_block(hw))
1011 return E1000_SUCCESS;
1012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 /* Read and store word 0x0F of the EEPROM. This word contains bits
1014 * that determine the hardware's default PAUSE (flow control) mode,
1015 * a bit that determines whether the HW defaults to enabling or
1016 * disabling auto-negotiation, and the direction of the
1017 * SW defined pins. If there is no SW over-ride of the flow
1018 * control setting, then the variable hw->fc will
1019 * be initialized based on a value in the EEPROM.
1020 */
Jeff Kirsherfd803242005-12-13 00:06:22 -05001021 if (hw->fc == e1000_fc_default) {
1022 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001023 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001024 case e1000_82573:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 hw->fc = e1000_fc_full;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001026 break;
1027 default:
1028 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1029 1, &eeprom_data);
1030 if (ret_val) {
1031 DEBUGOUT("EEPROM Read Error\n");
1032 return -E1000_ERR_EEPROM;
1033 }
1034 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1035 hw->fc = e1000_fc_none;
1036 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1037 EEPROM_WORD0F_ASM_DIR)
1038 hw->fc = e1000_fc_tx_pause;
1039 else
1040 hw->fc = e1000_fc_full;
1041 break;
1042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 }
1044
1045 /* We want to save off the original Flow Control configuration just
1046 * in case we get disconnected and then reconnected into a different
1047 * hub or switch with different Flow Control capabilities.
1048 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001049 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 hw->fc &= (~e1000_fc_tx_pause);
1051
Auke Kok8fc897b2006-08-28 14:56:16 -07001052 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 hw->fc &= (~e1000_fc_rx_pause);
1054
1055 hw->original_fc = hw->fc;
1056
1057 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1058
1059 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1060 * polarity value for the SW controlled pins, and setup the
1061 * Extended Device Control reg with that info.
1062 * This is needed because one of the SW controlled pins is used for
1063 * signal detection. So this should be done before e1000_setup_pcs_link()
1064 * or e1000_phy_setup() is called.
1065 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001066 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001067 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1068 1, &eeprom_data);
1069 if (ret_val) {
1070 DEBUGOUT("EEPROM Read Error\n");
1071 return -E1000_ERR_EEPROM;
1072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1074 SWDPIO__EXT_SHIFT);
1075 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1076 }
1077
1078 /* Call the necessary subroutine to configure the link. */
1079 ret_val = (hw->media_type == e1000_media_type_copper) ?
1080 e1000_setup_copper_link(hw) :
1081 e1000_setup_fiber_serdes_link(hw);
1082
1083 /* Initialize the flow control address, type, and PAUSE timer
1084 * registers to their default values. This is done even if flow
1085 * control is disabled, because it does not hurt anything to
1086 * initialize these registers.
1087 */
1088 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1089
Auke Kokcd94dd02006-06-27 09:08:22 -07001090 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1091 if (hw->mac_type != e1000_ich8lan) {
1092 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1093 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1094 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1095 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1098
1099 /* Set the flow control receive threshold registers. Normally,
1100 * these registers will be set to a default threshold that may be
1101 * adjusted later by the driver's runtime code. However, if the
1102 * ability to transmit pause frames in not enabled, then these
1103 * registers will be set to 0.
1104 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001105 if (!(hw->fc & e1000_fc_tx_pause)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 E1000_WRITE_REG(hw, FCRTL, 0);
1107 E1000_WRITE_REG(hw, FCRTH, 0);
1108 } else {
1109 /* We need to set up the Receive Threshold high and low water marks
1110 * as well as (optionally) enabling the transmission of XON frames.
1111 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001112 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1114 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1115 } else {
1116 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1117 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1118 }
1119 }
1120 return ret_val;
1121}
1122
1123/******************************************************************************
1124 * Sets up link for a fiber based or serdes based adapter
1125 *
1126 * hw - Struct containing variables accessed by shared code
1127 *
1128 * Manipulates Physical Coding Sublayer functions in order to configure
1129 * link. Assumes the hardware has been previously reset and the transmitter
1130 * and receiver are not enabled.
1131 *****************************************************************************/
1132static int32_t
1133e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1134{
1135 uint32_t ctrl;
1136 uint32_t status;
1137 uint32_t txcw = 0;
1138 uint32_t i;
1139 uint32_t signal = 0;
1140 int32_t ret_val;
1141
1142 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1143
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001144 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1145 * until explicitly turned off or a power cycle is performed. A read to
1146 * the register does not indicate its status. Therefore, we ensure
1147 * loopback mode is disabled during initialization.
1148 */
1149 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1150 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1153 * set when the optics detect a signal. On older adapters, it will be
1154 * cleared when there is a signal. This applies to fiber media only.
1155 * If we're on serdes media, adjust the output amplitude to value set in
1156 * the EEPROM.
1157 */
1158 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001159 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1161
1162 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001163 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 return ret_val;
1165
1166 /* Take the link out of reset */
1167 ctrl &= ~(E1000_CTRL_LRST);
1168
1169 /* Adjust VCO speed to improve BER performance */
1170 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001171 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 return ret_val;
1173
1174 e1000_config_collision_dist(hw);
1175
1176 /* Check for a software override of the flow control settings, and setup
1177 * the device accordingly. If auto-negotiation is enabled, then software
1178 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1179 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1180 * auto-negotiation is disabled, then software will have to manually
1181 * configure the two flow control enable bits in the CTRL register.
1182 *
1183 * The possible values of the "fc" parameter are:
1184 * 0: Flow control is completely disabled
1185 * 1: Rx flow control is enabled (we can receive pause frames, but
1186 * not send pause frames).
1187 * 2: Tx flow control is enabled (we can send pause frames but we do
1188 * not support receiving pause frames).
1189 * 3: Both Rx and TX flow control (symmetric) are enabled.
1190 */
1191 switch (hw->fc) {
1192 case e1000_fc_none:
1193 /* Flow control is completely disabled by a software over-ride. */
1194 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1195 break;
1196 case e1000_fc_rx_pause:
1197 /* RX Flow control is enabled and TX Flow control is disabled by a
1198 * software over-ride. Since there really isn't a way to advertise
1199 * that we are capable of RX Pause ONLY, we will advertise that we
1200 * support both symmetric and asymmetric RX PAUSE. Later, we will
1201 * disable the adapter's ability to send PAUSE frames.
1202 */
1203 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1204 break;
1205 case e1000_fc_tx_pause:
1206 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1207 * software over-ride.
1208 */
1209 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1210 break;
1211 case e1000_fc_full:
1212 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1213 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1214 break;
1215 default:
1216 DEBUGOUT("Flow control param set incorrectly\n");
1217 return -E1000_ERR_CONFIG;
1218 break;
1219 }
1220
1221 /* Since auto-negotiation is enabled, take the link out of reset (the link
1222 * will be in reset, because we previously reset the chip). This will
1223 * restart auto-negotiation. If auto-neogtiation is successful then the
1224 * link-up status bit will be set and the flow control enable bits (RFCE
1225 * and TFCE) will be set according to their negotiated value.
1226 */
1227 DEBUGOUT("Auto-negotiation enabled\n");
1228
1229 E1000_WRITE_REG(hw, TXCW, txcw);
1230 E1000_WRITE_REG(hw, CTRL, ctrl);
1231 E1000_WRITE_FLUSH(hw);
1232
1233 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001234 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1237 * indication in the Device Status Register. Time-out if a link isn't
1238 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1239 * less than 500 milliseconds even if the other end is doing it in SW).
1240 * For internal serdes, we just assume a signal is present, then poll.
1241 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001242 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1244 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001245 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001246 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001248 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001250 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1252 hw->autoneg_failed = 1;
1253 /* AutoNeg failed to achieve a link, so we'll call
1254 * e1000_check_for_link. This routine will force the link up if
1255 * we detect a signal. This will allow us to communicate with
1256 * non-autonegotiating link partners.
1257 */
1258 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001259 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 DEBUGOUT("Error while checking for link\n");
1261 return ret_val;
1262 }
1263 hw->autoneg_failed = 0;
1264 } else {
1265 hw->autoneg_failed = 0;
1266 DEBUGOUT("Valid Link Found\n");
1267 }
1268 } else {
1269 DEBUGOUT("No Signal Detected\n");
1270 }
1271 return E1000_SUCCESS;
1272}
1273
1274/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001275* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276*
1277* hw - Struct containing variables accessed by shared code
1278******************************************************************************/
1279static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001280e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
1282 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 uint16_t phy_data;
1285
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001286 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288 ctrl = E1000_READ_REG(hw, CTRL);
1289 /* With 82543, we need to force speed and duplex on the MAC equal to what
1290 * the PHY speed and duplex configuration is. In addition, we need to
1291 * perform a hardware reset on the PHY to take it out of reset.
1292 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001293 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 ctrl |= E1000_CTRL_SLU;
1295 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1296 E1000_WRITE_REG(hw, CTRL, ctrl);
1297 } else {
1298 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1299 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001300 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001301 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001302 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
1304
1305 /* Make sure we have a valid PHY */
1306 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001307 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 DEBUGOUT("Error, did not detect valid phy.\n");
1309 return ret_val;
1310 }
1311 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1312
1313 /* Set PHY to class A mode (if necessary) */
1314 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001315 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 return ret_val;
1317
Auke Kok8fc897b2006-08-28 14:56:16 -07001318 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 (hw->mac_type == e1000_82546_rev_3)) {
1320 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1321 phy_data |= 0x00000008;
1322 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1323 }
1324
Auke Kok8fc897b2006-08-28 14:56:16 -07001325 if (hw->mac_type <= e1000_82543 ||
1326 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1327 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 hw->phy_reset_disable = FALSE;
1329
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001330 return E1000_SUCCESS;
1331}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001334/********************************************************************
1335* Copper link setup for e1000_phy_igp series.
1336*
1337* hw - Struct containing variables accessed by shared code
1338*********************************************************************/
1339static int32_t
1340e1000_copper_link_igp_setup(struct e1000_hw *hw)
1341{
1342 uint32_t led_ctrl;
1343 int32_t ret_val;
1344 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001346 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001348 if (hw->phy_reset_disable)
1349 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001350
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001351 ret_val = e1000_phy_reset(hw);
1352 if (ret_val) {
1353 DEBUGOUT("Error Resetting the PHY\n");
1354 return ret_val;
1355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Auke Kok8fc897b2006-08-28 14:56:16 -07001357 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001358 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001359 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001360 /* Configure activity LED after PHY reset */
1361 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1362 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1363 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1364 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001365 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001366
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001367 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1368 if (hw->phy_type == e1000_phy_igp) {
1369 /* disable lplu d3 during driver init */
1370 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1371 if (ret_val) {
1372 DEBUGOUT("Error Disabling LPLU D3\n");
1373 return ret_val;
1374 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001375 }
1376
1377 /* disable lplu d0 during driver init */
1378 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1379 if (ret_val) {
1380 DEBUGOUT("Error Disabling LPLU D0\n");
1381 return ret_val;
1382 }
1383 /* Configure mdi-mdix settings */
1384 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1385 if (ret_val)
1386 return ret_val;
1387
1388 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1389 hw->dsp_config_state = e1000_dsp_config_disabled;
1390 /* Force MDI for earlier revs of the IGP PHY */
1391 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1392 hw->mdix = 1;
1393
1394 } else {
1395 hw->dsp_config_state = e1000_dsp_config_enabled;
1396 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1397
1398 switch (hw->mdix) {
1399 case 1:
1400 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1401 break;
1402 case 2:
1403 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1404 break;
1405 case 0:
1406 default:
1407 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1408 break;
1409 }
1410 }
1411 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001412 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001413 return ret_val;
1414
1415 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001416 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001417 e1000_ms_type phy_ms_setting = hw->master_slave;
1418
Auke Kok8fc897b2006-08-28 14:56:16 -07001419 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001420 hw->ffe_config_state = e1000_ffe_config_enabled;
1421
Auke Kok8fc897b2006-08-28 14:56:16 -07001422 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001423 hw->dsp_config_state = e1000_dsp_config_enabled;
1424
1425 /* when autonegotiation advertisment is only 1000Mbps then we
1426 * should disable SmartSpeed and enable Auto MasterSlave
1427 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001428 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001429 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001430 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1431 &phy_data);
1432 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001434 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001435 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1436 phy_data);
1437 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001439 /* Set auto Master/Slave resolution process */
1440 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001441 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001442 return ret_val;
1443 phy_data &= ~CR_1000T_MS_ENABLE;
1444 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001445 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001446 return ret_val;
1447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001449 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001450 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001451 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001453 /* load defaults for future use */
1454 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1455 ((phy_data & CR_1000T_MS_VALUE) ?
1456 e1000_ms_force_master :
1457 e1000_ms_force_slave) :
1458 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001460 switch (phy_ms_setting) {
1461 case e1000_ms_force_master:
1462 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1463 break;
1464 case e1000_ms_force_slave:
1465 phy_data |= CR_1000T_MS_ENABLE;
1466 phy_data &= ~(CR_1000T_MS_VALUE);
1467 break;
1468 case e1000_ms_auto:
1469 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001471 break;
1472 }
1473 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001474 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001475 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Malli Chilakala2b028932005-06-17 17:46:06 -07001478 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001479}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001481/********************************************************************
1482* Copper link setup for e1000_phy_gg82563 series.
1483*
1484* hw - Struct containing variables accessed by shared code
1485*********************************************************************/
1486static int32_t
1487e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1488{
1489 int32_t ret_val;
1490 uint16_t phy_data;
1491 uint32_t reg_data;
1492
1493 DEBUGFUNC("e1000_copper_link_ggp_setup");
1494
Auke Kok8fc897b2006-08-28 14:56:16 -07001495 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001496
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001497 /* Enable CRS on TX for half-duplex operation. */
1498 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1499 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001500 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001501 return ret_val;
1502
1503 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1504 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1505 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1506
1507 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1508 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001509 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001510 return ret_val;
1511
1512 /* Options:
1513 * MDI/MDI-X = 0 (default)
1514 * 0 - Auto for all speeds
1515 * 1 - MDI mode
1516 * 2 - MDI-X mode
1517 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1518 */
1519 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001520 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001521 return ret_val;
1522
1523 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1524
1525 switch (hw->mdix) {
1526 case 1:
1527 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1528 break;
1529 case 2:
1530 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1531 break;
1532 case 0:
1533 default:
1534 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1535 break;
1536 }
1537
1538 /* Options:
1539 * disable_polarity_correction = 0 (default)
1540 * Automatic Correction for Reversed Cable Polarity
1541 * 0 - Disabled
1542 * 1 - Enabled
1543 */
1544 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001545 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001546 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1547 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1548
Auke Kok8fc897b2006-08-28 14:56:16 -07001549 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001550 return ret_val;
1551
1552 /* SW Reset the PHY so all changes take effect */
1553 ret_val = e1000_phy_reset(hw);
1554 if (ret_val) {
1555 DEBUGOUT("Error Resetting the PHY\n");
1556 return ret_val;
1557 }
1558 } /* phy_reset_disable */
1559
1560 if (hw->mac_type == e1000_80003es2lan) {
1561 /* Bypass RX and TX FIFO's */
1562 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1563 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1564 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1565 if (ret_val)
1566 return ret_val;
1567
1568 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1569 if (ret_val)
1570 return ret_val;
1571
1572 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1573 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1574
1575 if (ret_val)
1576 return ret_val;
1577
1578 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1579 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1580 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1581
1582 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1583 &phy_data);
1584 if (ret_val)
1585 return ret_val;
1586
1587 /* Do not init these registers when the HW is in IAMT mode, since the
1588 * firmware will have already initialized them. We only initialize
1589 * them if the HW is not in IAMT mode.
1590 */
1591 if (e1000_check_mng_mode(hw) == FALSE) {
1592 /* Enable Electrical Idle on the PHY */
1593 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1594 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1595 phy_data);
1596 if (ret_val)
1597 return ret_val;
1598
1599 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1600 &phy_data);
1601 if (ret_val)
1602 return ret_val;
1603
Auke Kokcd94dd02006-06-27 09:08:22 -07001604 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001605 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1606 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001607
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001608 if (ret_val)
1609 return ret_val;
1610 }
1611
1612 /* Workaround: Disable padding in Kumeran interface in the MAC
1613 * and in the PHY to avoid CRC errors.
1614 */
1615 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1616 &phy_data);
1617 if (ret_val)
1618 return ret_val;
1619 phy_data |= GG82563_ICR_DIS_PADDING;
1620 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1621 phy_data);
1622 if (ret_val)
1623 return ret_val;
1624 }
1625
1626 return E1000_SUCCESS;
1627}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001629/********************************************************************
1630* Copper link setup for e1000_phy_m88 series.
1631*
1632* hw - Struct containing variables accessed by shared code
1633*********************************************************************/
1634static int32_t
1635e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1636{
1637 int32_t ret_val;
1638 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001640 DEBUGFUNC("e1000_copper_link_mgp_setup");
1641
Auke Kok8fc897b2006-08-28 14:56:16 -07001642 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001643 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001644
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001645 /* Enable CRS on TX. This must be set for half-duplex operation. */
1646 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001647 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001648 return ret_val;
1649
1650 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1651
1652 /* Options:
1653 * MDI/MDI-X = 0 (default)
1654 * 0 - Auto for all speeds
1655 * 1 - MDI mode
1656 * 2 - MDI-X mode
1657 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1658 */
1659 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1660
1661 switch (hw->mdix) {
1662 case 1:
1663 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1664 break;
1665 case 2:
1666 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1667 break;
1668 case 3:
1669 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1670 break;
1671 case 0:
1672 default:
1673 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1674 break;
1675 }
1676
1677 /* Options:
1678 * disable_polarity_correction = 0 (default)
1679 * Automatic Correction for Reversed Cable Polarity
1680 * 0 - Disabled
1681 * 1 - Enabled
1682 */
1683 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001684 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001685 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001686 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1687 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001688 return ret_val;
1689
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001690 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001691 /* Force TX_CLK in the Extended PHY Specific Control Register
1692 * to 25MHz clock.
1693 */
1694 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1695 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001696 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001697
1698 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1699
1700 if ((hw->phy_revision == E1000_REVISION_2) &&
1701 (hw->phy_id == M88E1111_I_PHY_ID)) {
1702 /* Vidalia Phy, set the downshift counter to 5x */
1703 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1704 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1705 ret_val = e1000_write_phy_reg(hw,
1706 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1707 if (ret_val)
1708 return ret_val;
1709 } else {
1710 /* Configure Master and Slave downshift values */
1711 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1712 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1713 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1714 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1715 ret_val = e1000_write_phy_reg(hw,
1716 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1717 if (ret_val)
1718 return ret_val;
1719 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001722 /* SW Reset the PHY so all changes take effect */
1723 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001724 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001725 DEBUGOUT("Error Resetting the PHY\n");
1726 return ret_val;
1727 }
1728
1729 return E1000_SUCCESS;
1730}
1731
1732/********************************************************************
1733* Setup auto-negotiation and flow control advertisements,
1734* and then perform auto-negotiation.
1735*
1736* hw - Struct containing variables accessed by shared code
1737*********************************************************************/
1738static int32_t
1739e1000_copper_link_autoneg(struct e1000_hw *hw)
1740{
1741 int32_t ret_val;
1742 uint16_t phy_data;
1743
1744 DEBUGFUNC("e1000_copper_link_autoneg");
1745
1746 /* Perform some bounds checking on the hw->autoneg_advertised
1747 * parameter. If this variable is zero, then set it to the default.
1748 */
1749 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1750
1751 /* If autoneg_advertised is zero, we assume it was not defaulted
1752 * by the calling code so we set to advertise full capability.
1753 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001754 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001755 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1756
Auke Kokcd94dd02006-06-27 09:08:22 -07001757 /* IFE phy only supports 10/100 */
1758 if (hw->phy_type == e1000_phy_ife)
1759 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1760
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001761 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1762 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001763 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001764 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1765 return ret_val;
1766 }
1767 DEBUGOUT("Restarting Auto-Neg\n");
1768
1769 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1770 * the Auto Neg Restart bit in the PHY control register.
1771 */
1772 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001773 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001774 return ret_val;
1775
1776 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1777 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001778 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001779 return ret_val;
1780
1781 /* Does the user want to wait for Auto-Neg to complete here, or
1782 * check at a later time (for example, callback routine).
1783 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001784 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001785 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001786 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001787 DEBUGOUT("Error while waiting for autoneg to complete\n");
1788 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001792 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001794 return E1000_SUCCESS;
1795}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001797/******************************************************************************
1798* Config the MAC and the PHY after link is up.
1799* 1) Set up the MAC to the current PHY speed/duplex
1800* if we are on 82543. If we
1801* are on newer silicon, we only need to configure
1802* collision distance in the Transmit Control Register.
1803* 2) Set up flow control on the MAC to that established with
1804* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001805* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001806*
1807* hw - Struct containing variables accessed by shared code
1808******************************************************************************/
1809static int32_t
1810e1000_copper_link_postconfig(struct e1000_hw *hw)
1811{
1812 int32_t ret_val;
1813 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001814
Auke Kok8fc897b2006-08-28 14:56:16 -07001815 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001816 e1000_config_collision_dist(hw);
1817 } else {
1818 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001819 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001820 DEBUGOUT("Error configuring MAC to PHY settings\n");
1821 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001823 }
1824 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001825 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826 DEBUGOUT("Error Configuring Flow Control\n");
1827 return ret_val;
1828 }
1829
1830 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001831 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001832 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001833 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001834 DEBUGOUT("Error Configuring DSP after link up\n");
1835 return ret_val;
1836 }
1837 }
Auke Kok76c224b2006-05-23 13:36:06 -07001838
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001839 return E1000_SUCCESS;
1840}
1841
1842/******************************************************************************
1843* Detects which PHY is present and setup the speed and duplex
1844*
1845* hw - Struct containing variables accessed by shared code
1846******************************************************************************/
1847static int32_t
1848e1000_setup_copper_link(struct e1000_hw *hw)
1849{
1850 int32_t ret_val;
1851 uint16_t i;
1852 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001853 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001854
1855 DEBUGFUNC("e1000_setup_copper_link");
1856
Auke Kokcd94dd02006-06-27 09:08:22 -07001857 switch (hw->mac_type) {
1858 case e1000_80003es2lan:
1859 case e1000_ich8lan:
1860 /* Set the mac to wait the maximum time between each
1861 * iteration and increase the max iterations when
1862 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1863 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1864 if (ret_val)
1865 return ret_val;
1866 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1867 if (ret_val)
1868 return ret_val;
1869 reg_data |= 0x3F;
1870 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1871 if (ret_val)
1872 return ret_val;
1873 default:
1874 break;
1875 }
1876
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001877 /* Check if it is a valid PHY and set PHY mode if necessary. */
1878 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001879 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001880 return ret_val;
1881
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001882 switch (hw->mac_type) {
1883 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001884 /* Kumeran registers are written-only */
1885 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001886 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1887 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1888 reg_data);
1889 if (ret_val)
1890 return ret_val;
1891 break;
1892 default:
1893 break;
1894 }
1895
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001896 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07001897 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001898 hw->phy_type == e1000_phy_igp_2) {
1899 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001900 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001901 return ret_val;
1902 } else if (hw->phy_type == e1000_phy_m88) {
1903 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001904 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001905 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001906 } else if (hw->phy_type == e1000_phy_gg82563) {
1907 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001908 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001909 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001910 }
1911
Auke Kok8fc897b2006-08-28 14:56:16 -07001912 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07001913 /* Setup autoneg and flow control advertisement
1914 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001915 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001916 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07001917 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001918 } else {
1919 /* PHY will be set to 10H, 10F, 100H,or 100F
1920 * depending on value from forced_speed_duplex. */
1921 DEBUGOUT("Forcing speed and duplex\n");
1922 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001923 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001924 DEBUGOUT("Error Forcing Speed and Duplex\n");
1925 return ret_val;
1926 }
1927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
1929 /* Check link status. Wait up to 100 microseconds for link to become
1930 * valid.
1931 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001932 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001934 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 return ret_val;
1936 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001937 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 return ret_val;
1939
Auke Kok8fc897b2006-08-28 14:56:16 -07001940 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001941 /* Config the MAC and PHY after link is up */
1942 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001943 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001945
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 DEBUGOUT("Valid link established!!!\n");
1947 return E1000_SUCCESS;
1948 }
1949 udelay(10);
1950 }
1951
1952 DEBUGOUT("Unable to establish link!!!\n");
1953 return E1000_SUCCESS;
1954}
1955
1956/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001957* Configure the MAC-to-PHY interface for 10/100Mbps
1958*
1959* hw - Struct containing variables accessed by shared code
1960******************************************************************************/
1961static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07001962e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001963{
1964 int32_t ret_val = E1000_SUCCESS;
1965 uint32_t tipg;
1966 uint16_t reg_data;
1967
1968 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1969
1970 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1971 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1972 reg_data);
1973 if (ret_val)
1974 return ret_val;
1975
1976 /* Configure Transmit Inter-Packet Gap */
1977 tipg = E1000_READ_REG(hw, TIPG);
1978 tipg &= ~E1000_TIPG_IPGT_MASK;
1979 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1980 E1000_WRITE_REG(hw, TIPG, tipg);
1981
Auke Kokcd94dd02006-06-27 09:08:22 -07001982 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
1983
1984 if (ret_val)
1985 return ret_val;
1986
1987 if (duplex == HALF_DUPLEX)
1988 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1989 else
1990 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1991
1992 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1993
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001994 return ret_val;
1995}
1996
1997static int32_t
1998e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1999{
2000 int32_t ret_val = E1000_SUCCESS;
2001 uint16_t reg_data;
2002 uint32_t tipg;
2003
2004 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2005
2006 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2007 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2008 reg_data);
2009 if (ret_val)
2010 return ret_val;
2011
2012 /* Configure Transmit Inter-Packet Gap */
2013 tipg = E1000_READ_REG(hw, TIPG);
2014 tipg &= ~E1000_TIPG_IPGT_MASK;
2015 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2016 E1000_WRITE_REG(hw, TIPG, tipg);
2017
Auke Kokcd94dd02006-06-27 09:08:22 -07002018 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2019
2020 if (ret_val)
2021 return ret_val;
2022
2023 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2024 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2025
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002026 return ret_val;
2027}
2028
2029/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030* Configures PHY autoneg and flow control advertisement settings
2031*
2032* hw - Struct containing variables accessed by shared code
2033******************************************************************************/
2034int32_t
2035e1000_phy_setup_autoneg(struct e1000_hw *hw)
2036{
2037 int32_t ret_val;
2038 uint16_t mii_autoneg_adv_reg;
2039 uint16_t mii_1000t_ctrl_reg;
2040
2041 DEBUGFUNC("e1000_phy_setup_autoneg");
2042
2043 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2044 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002045 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 return ret_val;
2047
Auke Kokcd94dd02006-06-27 09:08:22 -07002048 if (hw->phy_type != e1000_phy_ife) {
2049 /* Read the MII 1000Base-T Control Register (Address 9). */
2050 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2051 if (ret_val)
2052 return ret_val;
2053 } else
2054 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
2056 /* Need to parse both autoneg_advertised and fc and set up
2057 * the appropriate PHY registers. First we will parse for
2058 * autoneg_advertised software override. Since we can advertise
2059 * a plethora of combinations, we need to check each bit
2060 * individually.
2061 */
2062
2063 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2064 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2065 * the 1000Base-T Control Register (Address 9).
2066 */
2067 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2068 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2069
2070 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2071
2072 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002073 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 DEBUGOUT("Advertise 10mb Half duplex\n");
2075 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2076 }
2077
2078 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002079 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 DEBUGOUT("Advertise 10mb Full duplex\n");
2081 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2082 }
2083
2084 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002085 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 DEBUGOUT("Advertise 100mb Half duplex\n");
2087 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2088 }
2089
2090 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002091 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 DEBUGOUT("Advertise 100mb Full duplex\n");
2093 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2094 }
2095
2096 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002097 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2099 }
2100
2101 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002102 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 DEBUGOUT("Advertise 1000mb Full duplex\n");
2104 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002105 if (hw->phy_type == e1000_phy_ife) {
2106 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 }
2109
2110 /* Check for a software override of the flow control settings, and
2111 * setup the PHY advertisement registers accordingly. If
2112 * auto-negotiation is enabled, then software will have to set the
2113 * "PAUSE" bits to the correct value in the Auto-Negotiation
2114 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2115 *
2116 * The possible values of the "fc" parameter are:
2117 * 0: Flow control is completely disabled
2118 * 1: Rx flow control is enabled (we can receive pause frames
2119 * but not send pause frames).
2120 * 2: Tx flow control is enabled (we can send pause frames
2121 * but we do not support receiving pause frames).
2122 * 3: Both Rx and TX flow control (symmetric) are enabled.
2123 * other: No software override. The flow control configuration
2124 * in the EEPROM is used.
2125 */
2126 switch (hw->fc) {
2127 case e1000_fc_none: /* 0 */
2128 /* Flow control (RX & TX) is completely disabled by a
2129 * software over-ride.
2130 */
2131 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2132 break;
2133 case e1000_fc_rx_pause: /* 1 */
2134 /* RX Flow control is enabled, and TX Flow control is
2135 * disabled, by a software over-ride.
2136 */
2137 /* Since there really isn't a way to advertise that we are
2138 * capable of RX Pause ONLY, we will advertise that we
2139 * support both symmetric and asymmetric RX PAUSE. Later
2140 * (in e1000_config_fc_after_link_up) we will disable the
2141 *hw's ability to send PAUSE frames.
2142 */
2143 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2144 break;
2145 case e1000_fc_tx_pause: /* 2 */
2146 /* TX Flow control is enabled, and RX Flow control is
2147 * disabled, by a software over-ride.
2148 */
2149 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2150 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2151 break;
2152 case e1000_fc_full: /* 3 */
2153 /* Flow control (both RX and TX) is enabled by a software
2154 * over-ride.
2155 */
2156 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2157 break;
2158 default:
2159 DEBUGOUT("Flow control param set incorrectly\n");
2160 return -E1000_ERR_CONFIG;
2161 }
2162
2163 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002164 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 return ret_val;
2166
2167 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2168
Auke Kokcd94dd02006-06-27 09:08:22 -07002169 if (hw->phy_type != e1000_phy_ife) {
2170 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2171 if (ret_val)
2172 return ret_val;
2173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 return E1000_SUCCESS;
2176}
2177
2178/******************************************************************************
2179* Force PHY speed and duplex settings to hw->forced_speed_duplex
2180*
2181* hw - Struct containing variables accessed by shared code
2182******************************************************************************/
2183static int32_t
2184e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2185{
2186 uint32_t ctrl;
2187 int32_t ret_val;
2188 uint16_t mii_ctrl_reg;
2189 uint16_t mii_status_reg;
2190 uint16_t phy_data;
2191 uint16_t i;
2192
2193 DEBUGFUNC("e1000_phy_force_speed_duplex");
2194
2195 /* Turn off Flow control if we are forcing speed and duplex. */
2196 hw->fc = e1000_fc_none;
2197
2198 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2199
2200 /* Read the Device Control Register. */
2201 ctrl = E1000_READ_REG(hw, CTRL);
2202
2203 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2204 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2205 ctrl &= ~(DEVICE_SPEED_MASK);
2206
2207 /* Clear the Auto Speed Detect Enable bit. */
2208 ctrl &= ~E1000_CTRL_ASDE;
2209
2210 /* Read the MII Control Register. */
2211 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002212 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 return ret_val;
2214
2215 /* We need to disable autoneg in order to force link and duplex. */
2216
2217 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2218
2219 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002220 if (hw->forced_speed_duplex == e1000_100_full ||
2221 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 /* We want to force full duplex so we SET the full duplex bits in the
2223 * Device and MII Control Registers.
2224 */
2225 ctrl |= E1000_CTRL_FD;
2226 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2227 DEBUGOUT("Full Duplex\n");
2228 } else {
2229 /* We want to force half duplex so we CLEAR the full duplex bits in
2230 * the Device and MII Control Registers.
2231 */
2232 ctrl &= ~E1000_CTRL_FD;
2233 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2234 DEBUGOUT("Half Duplex\n");
2235 }
2236
2237 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002238 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 hw->forced_speed_duplex == e1000_100_half) {
2240 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2241 ctrl |= E1000_CTRL_SPD_100;
2242 mii_ctrl_reg |= MII_CR_SPEED_100;
2243 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2244 DEBUGOUT("Forcing 100mb ");
2245 } else {
2246 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2247 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2248 mii_ctrl_reg |= MII_CR_SPEED_10;
2249 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2250 DEBUGOUT("Forcing 10mb ");
2251 }
2252
2253 e1000_config_collision_dist(hw);
2254
2255 /* Write the configured values back to the Device Control Reg. */
2256 E1000_WRITE_REG(hw, CTRL, ctrl);
2257
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002258 if ((hw->phy_type == e1000_phy_m88) ||
2259 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002261 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return ret_val;
2263
2264 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2265 * forced whenever speed are duplex are forced.
2266 */
2267 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2268 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002269 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 return ret_val;
2271
2272 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2273
2274 /* Need to reset the PHY or these changes will be ignored */
2275 mii_ctrl_reg |= MII_CR_RESET;
Auke Kokcd94dd02006-06-27 09:08:22 -07002276 /* Disable MDI-X support for 10/100 */
2277 } else if (hw->phy_type == e1000_phy_ife) {
2278 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2279 if (ret_val)
2280 return ret_val;
2281
2282 phy_data &= ~IFE_PMC_AUTO_MDIX;
2283 phy_data &= ~IFE_PMC_FORCE_MDIX;
2284
2285 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2286 if (ret_val)
2287 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 } else {
2289 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2290 * forced whenever speed or duplex are forced.
2291 */
2292 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002293 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 return ret_val;
2295
2296 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2297 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2298
2299 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002300 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 return ret_val;
2302 }
2303
2304 /* Write back the modified PHY MII control register. */
2305 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002306 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 return ret_val;
2308
2309 udelay(1);
2310
2311 /* The wait_autoneg_complete flag may be a little misleading here.
2312 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2313 * But we do want to delay for a period while forcing only so we
2314 * don't generate false No Link messages. So we will wait here
2315 * only if the user has set wait_autoneg_complete to 1, which is
2316 * the default.
2317 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002318 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 /* We will wait for autoneg to complete. */
2320 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2321 mii_status_reg = 0;
2322
2323 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002324 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2326 * to be set.
2327 */
2328 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002329 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 return ret_val;
2331
2332 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002333 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 return ret_val;
2335
Auke Kok8fc897b2006-08-28 14:56:16 -07002336 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002337 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002339 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002340 ((hw->phy_type == e1000_phy_m88) ||
2341 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 /* We didn't get link. Reset the DSP and wait again for link. */
2343 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002344 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 DEBUGOUT("Error Resetting PHY DSP\n");
2346 return ret_val;
2347 }
2348 }
2349 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002350 for (i = PHY_FORCE_TIME; i > 0; i--) {
2351 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002352 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2354 * to be set.
2355 */
2356 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002357 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 return ret_val;
2359
2360 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002361 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 return ret_val;
2363 }
2364 }
2365
2366 if (hw->phy_type == e1000_phy_m88) {
2367 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2368 * Extended PHY Specific Control Register to 25MHz clock. This value
2369 * defaults back to a 2.5MHz clock when the PHY is reset.
2370 */
2371 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002372 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 return ret_val;
2374
2375 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2376 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002377 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 return ret_val;
2379
2380 /* In addition, because of the s/w reset above, we need to enable CRS on
2381 * TX. This must be set for both full and half duplex operation.
2382 */
2383 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002384 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 return ret_val;
2386
2387 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2388 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002389 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 return ret_val;
2391
Auke Kok8fc897b2006-08-28 14:56:16 -07002392 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2393 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2394 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002396 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 return ret_val;
2398 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002399 } else if (hw->phy_type == e1000_phy_gg82563) {
2400 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2401 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2402 * we're not in a forced 10/duplex configuration. */
2403 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2404 if (ret_val)
2405 return ret_val;
2406
2407 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2408 if ((hw->forced_speed_duplex == e1000_10_full) ||
2409 (hw->forced_speed_duplex == e1000_10_half))
2410 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2411 else
2412 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2413
2414 /* Also due to the reset, we need to enable CRS on Tx. */
2415 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2416
2417 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2418 if (ret_val)
2419 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 }
2421 return E1000_SUCCESS;
2422}
2423
2424/******************************************************************************
2425* Sets the collision distance in the Transmit Control register
2426*
2427* hw - Struct containing variables accessed by shared code
2428*
2429* Link should have been established previously. Reads the speed and duplex
2430* information from the Device Status register.
2431******************************************************************************/
2432void
2433e1000_config_collision_dist(struct e1000_hw *hw)
2434{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002435 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
2437 DEBUGFUNC("e1000_config_collision_dist");
2438
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002439 if (hw->mac_type < e1000_82543)
2440 coll_dist = E1000_COLLISION_DISTANCE_82542;
2441 else
2442 coll_dist = E1000_COLLISION_DISTANCE;
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 tctl = E1000_READ_REG(hw, TCTL);
2445
2446 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002447 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
2449 E1000_WRITE_REG(hw, TCTL, tctl);
2450 E1000_WRITE_FLUSH(hw);
2451}
2452
2453/******************************************************************************
2454* Sets MAC speed and duplex settings to reflect the those in the PHY
2455*
2456* hw - Struct containing variables accessed by shared code
2457* mii_reg - data to write to the MII control register
2458*
2459* The contents of the PHY register containing the needed information need to
2460* be passed in.
2461******************************************************************************/
2462static int32_t
2463e1000_config_mac_to_phy(struct e1000_hw *hw)
2464{
2465 uint32_t ctrl;
2466 int32_t ret_val;
2467 uint16_t phy_data;
2468
2469 DEBUGFUNC("e1000_config_mac_to_phy");
2470
Auke Kok76c224b2006-05-23 13:36:06 -07002471 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002472 * MAC speed/duplex configuration.*/
2473 if (hw->mac_type >= e1000_82544)
2474 return E1000_SUCCESS;
2475
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 /* Read the Device Control Register and set the bits to Force Speed
2477 * and Duplex.
2478 */
2479 ctrl = E1000_READ_REG(hw, CTRL);
2480 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2481 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2482
2483 /* Set up duplex in the Device Control and Transmit Control
2484 * registers depending on negotiated values.
2485 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002486 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002487 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002488 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Auke Kok8fc897b2006-08-28 14:56:16 -07002490 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002491 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002492 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002493 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002495 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002497 /* Set up speed in the Device Control register depending on
2498 * negotiated values.
2499 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002500 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002501 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002502 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002503 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 /* Write the configured values back to the Device Control Reg. */
2506 E1000_WRITE_REG(hw, CTRL, ctrl);
2507 return E1000_SUCCESS;
2508}
2509
2510/******************************************************************************
2511 * Forces the MAC's flow control settings.
2512 *
2513 * hw - Struct containing variables accessed by shared code
2514 *
2515 * Sets the TFCE and RFCE bits in the device control register to reflect
2516 * the adapter settings. TFCE and RFCE need to be explicitly set by
2517 * software when a Copper PHY is used because autonegotiation is managed
2518 * by the PHY rather than the MAC. Software must also configure these
2519 * bits when link is forced on a fiber connection.
2520 *****************************************************************************/
2521int32_t
2522e1000_force_mac_fc(struct e1000_hw *hw)
2523{
2524 uint32_t ctrl;
2525
2526 DEBUGFUNC("e1000_force_mac_fc");
2527
2528 /* Get the current configuration of the Device Control Register */
2529 ctrl = E1000_READ_REG(hw, CTRL);
2530
2531 /* Because we didn't get link via the internal auto-negotiation
2532 * mechanism (we either forced link or we got link via PHY
2533 * auto-neg), we have to manually enable/disable transmit an
2534 * receive flow control.
2535 *
2536 * The "Case" statement below enables/disable flow control
2537 * according to the "hw->fc" parameter.
2538 *
2539 * The possible values of the "fc" parameter are:
2540 * 0: Flow control is completely disabled
2541 * 1: Rx flow control is enabled (we can receive pause
2542 * frames but not send pause frames).
2543 * 2: Tx flow control is enabled (we can send pause frames
2544 * frames but we do not receive pause frames).
2545 * 3: Both Rx and TX flow control (symmetric) is enabled.
2546 * other: No other values should be possible at this point.
2547 */
2548
2549 switch (hw->fc) {
2550 case e1000_fc_none:
2551 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2552 break;
2553 case e1000_fc_rx_pause:
2554 ctrl &= (~E1000_CTRL_TFCE);
2555 ctrl |= E1000_CTRL_RFCE;
2556 break;
2557 case e1000_fc_tx_pause:
2558 ctrl &= (~E1000_CTRL_RFCE);
2559 ctrl |= E1000_CTRL_TFCE;
2560 break;
2561 case e1000_fc_full:
2562 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2563 break;
2564 default:
2565 DEBUGOUT("Flow control param set incorrectly\n");
2566 return -E1000_ERR_CONFIG;
2567 }
2568
2569 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002570 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 ctrl &= (~E1000_CTRL_TFCE);
2572
2573 E1000_WRITE_REG(hw, CTRL, ctrl);
2574 return E1000_SUCCESS;
2575}
2576
2577/******************************************************************************
2578 * Configures flow control settings after link is established
2579 *
2580 * hw - Struct containing variables accessed by shared code
2581 *
2582 * Should be called immediately after a valid link has been established.
2583 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2584 * and autonegotiation is enabled, the MAC flow control settings will be set
2585 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2586 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2587 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002588static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589e1000_config_fc_after_link_up(struct e1000_hw *hw)
2590{
2591 int32_t ret_val;
2592 uint16_t mii_status_reg;
2593 uint16_t mii_nway_adv_reg;
2594 uint16_t mii_nway_lp_ability_reg;
2595 uint16_t speed;
2596 uint16_t duplex;
2597
2598 DEBUGFUNC("e1000_config_fc_after_link_up");
2599
2600 /* Check for the case where we have fiber media and auto-neg failed
2601 * so we had to force link. In this case, we need to force the
2602 * configuration of the MAC to match the "fc" parameter.
2603 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002604 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2605 ((hw->media_type == e1000_media_type_internal_serdes) &&
2606 (hw->autoneg_failed)) ||
2607 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002609 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 DEBUGOUT("Error forcing flow control settings\n");
2611 return ret_val;
2612 }
2613 }
2614
2615 /* Check for the case where we have copper media and auto-neg is
2616 * enabled. In this case, we need to check and see if Auto-Neg
2617 * has completed, and if so, how the PHY and link partner has
2618 * flow control configured.
2619 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002620 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 /* Read the MII Status Register and check to see if AutoNeg
2622 * has completed. We read this twice because this reg has
2623 * some "sticky" (latched) bits.
2624 */
2625 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002626 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 return ret_val;
2628 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002629 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 return ret_val;
2631
Auke Kok8fc897b2006-08-28 14:56:16 -07002632 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 /* The AutoNeg process has completed, so we now need to
2634 * read both the Auto Negotiation Advertisement Register
2635 * (Address 4) and the Auto_Negotiation Base Page Ability
2636 * Register (Address 5) to determine how flow control was
2637 * negotiated.
2638 */
2639 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2640 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002641 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 return ret_val;
2643 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2644 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002645 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 return ret_val;
2647
2648 /* Two bits in the Auto Negotiation Advertisement Register
2649 * (Address 4) and two bits in the Auto Negotiation Base
2650 * Page Ability Register (Address 5) determine flow control
2651 * for both the PHY and the link partner. The following
2652 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2653 * 1999, describes these PAUSE resolution bits and how flow
2654 * control is determined based upon these settings.
2655 * NOTE: DC = Don't Care
2656 *
2657 * LOCAL DEVICE | LINK PARTNER
2658 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2659 *-------|---------|-------|---------|--------------------
2660 * 0 | 0 | DC | DC | e1000_fc_none
2661 * 0 | 1 | 0 | DC | e1000_fc_none
2662 * 0 | 1 | 1 | 0 | e1000_fc_none
2663 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2664 * 1 | 0 | 0 | DC | e1000_fc_none
2665 * 1 | DC | 1 | DC | e1000_fc_full
2666 * 1 | 1 | 0 | 0 | e1000_fc_none
2667 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2668 *
2669 */
2670 /* Are both PAUSE bits set to 1? If so, this implies
2671 * Symmetric Flow Control is enabled at both ends. The
2672 * ASM_DIR bits are irrelevant per the spec.
2673 *
2674 * For Symmetric Flow Control:
2675 *
2676 * LOCAL DEVICE | LINK PARTNER
2677 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2678 *-------|---------|-------|---------|--------------------
2679 * 1 | DC | 1 | DC | e1000_fc_full
2680 *
2681 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002682 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2683 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 /* Now we need to check if the user selected RX ONLY
2685 * of pause frames. In this case, we had to advertise
2686 * FULL flow control because we could not advertise RX
2687 * ONLY. Hence, we must now check to see if we need to
2688 * turn OFF the TRANSMISSION of PAUSE frames.
2689 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002690 if (hw->original_fc == e1000_fc_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 hw->fc = e1000_fc_full;
Auke Koka42a5072006-05-23 13:36:01 -07002692 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 } else {
2694 hw->fc = e1000_fc_rx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002695 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 }
2697 }
2698 /* For receiving PAUSE frames ONLY.
2699 *
2700 * LOCAL DEVICE | LINK PARTNER
2701 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2702 *-------|---------|-------|---------|--------------------
2703 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2704 *
2705 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002706 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)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 hw->fc = e1000_fc_tx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002711 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 }
2713 /* For transmitting PAUSE frames ONLY.
2714 *
2715 * LOCAL DEVICE | LINK PARTNER
2716 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2717 *-------|---------|-------|---------|--------------------
2718 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2719 *
2720 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002721 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2722 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2723 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2724 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 hw->fc = e1000_fc_rx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002726 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 }
2728 /* Per the IEEE spec, at this point flow control should be
2729 * disabled. However, we want to consider that we could
2730 * be connected to a legacy switch that doesn't advertise
2731 * desired flow control, but can be forced on the link
2732 * partner. So if we advertised no flow control, that is
2733 * what we will resolve to. If we advertised some kind of
2734 * receive capability (Rx Pause Only or Full Flow Control)
2735 * and the link partner advertised none, we will configure
2736 * ourselves to enable Rx Flow Control only. We can do
2737 * this safely for two reasons: If the link partner really
2738 * didn't want flow control enabled, and we enable Rx, no
2739 * harm done since we won't be receiving any PAUSE frames
2740 * anyway. If the intent on the link partner was to have
2741 * flow control enabled, then by us enabling RX only, we
2742 * can at least receive pause frames and process them.
2743 * This is a good idea because in most cases, since we are
2744 * predominantly a server NIC, more times than not we will
2745 * be asked to delay transmission of packets than asking
2746 * our link partner to pause transmission of frames.
2747 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002748 else if ((hw->original_fc == e1000_fc_none ||
2749 hw->original_fc == e1000_fc_tx_pause) ||
2750 hw->fc_strict_ieee) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 hw->fc = e1000_fc_none;
Auke Koka42a5072006-05-23 13:36:01 -07002752 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 } else {
2754 hw->fc = e1000_fc_rx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002755 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 }
2757
2758 /* Now we need to do one last check... If we auto-
2759 * negotiated to HALF DUPLEX, flow control should not be
2760 * enabled per IEEE 802.3 spec.
2761 */
2762 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002763 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 DEBUGOUT("Error getting link speed and duplex\n");
2765 return ret_val;
2766 }
2767
Auke Kok8fc897b2006-08-28 14:56:16 -07002768 if (duplex == HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 hw->fc = e1000_fc_none;
2770
2771 /* Now we call a subroutine to actually force the MAC
2772 * controller to use the correct flow control settings.
2773 */
2774 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002775 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 DEBUGOUT("Error forcing flow control settings\n");
2777 return ret_val;
2778 }
2779 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002780 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 }
2782 }
2783 return E1000_SUCCESS;
2784}
2785
2786/******************************************************************************
2787 * Checks to see if the link status of the hardware has changed.
2788 *
2789 * hw - Struct containing variables accessed by shared code
2790 *
2791 * Called by any function that needs to check the link status of the adapter.
2792 *****************************************************************************/
2793int32_t
2794e1000_check_for_link(struct e1000_hw *hw)
2795{
2796 uint32_t rxcw = 0;
2797 uint32_t ctrl;
2798 uint32_t status;
2799 uint32_t rctl;
2800 uint32_t icr;
2801 uint32_t signal = 0;
2802 int32_t ret_val;
2803 uint16_t phy_data;
2804
2805 DEBUGFUNC("e1000_check_for_link");
2806
2807 ctrl = E1000_READ_REG(hw, CTRL);
2808 status = E1000_READ_REG(hw, STATUS);
2809
2810 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2811 * set when the optics detect a signal. On older adapters, it will be
2812 * cleared when there is a signal. This applies to fiber media only.
2813 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002814 if ((hw->media_type == e1000_media_type_fiber) ||
2815 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 rxcw = E1000_READ_REG(hw, RXCW);
2817
Auke Kok8fc897b2006-08-28 14:56:16 -07002818 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002820 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 hw->get_link_status = FALSE;
2822 }
2823 }
2824
2825 /* If we have a copper PHY then we only want to go out to the PHY
2826 * registers to see if Auto-Neg has completed and/or if our link
2827 * status has changed. The get_link_status flag will be set if we
2828 * receive a Link Status Change interrupt or we have Rx Sequence
2829 * Errors.
2830 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002831 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 /* First we want to see if the MII Status Register reports
2833 * link. If so, then we want to get the current speed/duplex
2834 * of the PHY.
2835 * Read the register twice since the link bit is sticky.
2836 */
2837 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002838 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 return ret_val;
2840 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002841 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 return ret_val;
2843
Auke Kok8fc897b2006-08-28 14:56:16 -07002844 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 hw->get_link_status = FALSE;
2846 /* Check if there was DownShift, must be checked immediately after
2847 * link-up */
2848 e1000_check_downshift(hw);
2849
2850 /* If we are on 82544 or 82543 silicon and speed/duplex
2851 * are forced to 10H or 10F, then we will implement the polarity
2852 * reversal workaround. We disable interrupts first, and upon
2853 * returning, place the devices interrupt state to its previous
2854 * value except for the link status change interrupt which will
2855 * happen due to the execution of this workaround.
2856 */
2857
Auke Kok8fc897b2006-08-28 14:56:16 -07002858 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2859 (!hw->autoneg) &&
2860 (hw->forced_speed_duplex == e1000_10_full ||
2861 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2863 ret_val = e1000_polarity_reversal_workaround(hw);
2864 icr = E1000_READ_REG(hw, ICR);
2865 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2866 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2867 }
2868
2869 } else {
2870 /* No link detected */
2871 e1000_config_dsp_after_link_change(hw, FALSE);
2872 return 0;
2873 }
2874
2875 /* If we are forcing speed/duplex, then we simply return since
2876 * we have already determined whether we have link or not.
2877 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002878 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
2880 /* optimize the dsp settings for the igp phy */
2881 e1000_config_dsp_after_link_change(hw, TRUE);
2882
2883 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2884 * have Si on board that is 82544 or newer, Auto
2885 * Speed Detection takes care of MAC speed/duplex
2886 * configuration. So we only need to configure Collision
2887 * Distance in the MAC. Otherwise, we need to force
2888 * speed/duplex on the MAC to the current PHY speed/duplex
2889 * settings.
2890 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002891 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 e1000_config_collision_dist(hw);
2893 else {
2894 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002895 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 DEBUGOUT("Error configuring MAC to PHY settings\n");
2897 return ret_val;
2898 }
2899 }
2900
2901 /* Configure Flow Control now that Auto-Neg has completed. First, we
2902 * need to restore the desired flow control settings because we may
2903 * have had to re-autoneg with a different link partner.
2904 */
2905 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002906 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 DEBUGOUT("Error configuring flow control\n");
2908 return ret_val;
2909 }
2910
2911 /* At this point we know that we are on copper and we have
2912 * auto-negotiated link. These are conditions for checking the link
2913 * partner capability register. We use the link speed to determine if
2914 * TBI compatibility needs to be turned on or off. If the link is not
2915 * at gigabit speed, then TBI compatibility is not needed. If we are
2916 * at gigabit speed, we turn on TBI compatibility.
2917 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002918 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07002920 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2921 if (ret_val) {
2922 DEBUGOUT("Error getting link speed and duplex\n");
2923 return ret_val;
2924 }
2925 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 /* If link speed is not set to gigabit speed, we do not need
2927 * to enable TBI compatibility.
2928 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002929 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 /* If we previously were in the mode, turn it off. */
2931 rctl = E1000_READ_REG(hw, RCTL);
2932 rctl &= ~E1000_RCTL_SBP;
2933 E1000_WRITE_REG(hw, RCTL, rctl);
2934 hw->tbi_compatibility_on = FALSE;
2935 }
2936 } else {
2937 /* If TBI compatibility is was previously off, turn it on. For
2938 * compatibility with a TBI link partner, we will store bad
2939 * packets. Some frames have an additional byte on the end and
2940 * will look like CRC errors to to the hardware.
2941 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002942 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 hw->tbi_compatibility_on = TRUE;
2944 rctl = E1000_READ_REG(hw, RCTL);
2945 rctl |= E1000_RCTL_SBP;
2946 E1000_WRITE_REG(hw, RCTL, rctl);
2947 }
2948 }
2949 }
2950 }
2951 /* If we don't have link (auto-negotiation failed or link partner cannot
2952 * auto-negotiate), the cable is plugged in (we have signal), and our
2953 * link partner is not trying to auto-negotiate with us (we are receiving
2954 * idles or data), we need to force link up. We also need to give
2955 * auto-negotiation time to complete, in case the cable was just plugged
2956 * in. The autoneg_failed flag does this.
2957 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002958 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002960 (hw->media_type == e1000_media_type_internal_serdes)) &&
2961 (!(status & E1000_STATUS_LU)) &&
2962 (!(rxcw & E1000_RXCW_C))) {
2963 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 hw->autoneg_failed = 1;
2965 return 0;
2966 }
Auke Koka42a5072006-05-23 13:36:01 -07002967 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
2969 /* Disable auto-negotiation in the TXCW register */
2970 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2971
2972 /* Force link-up and also force full-duplex. */
2973 ctrl = E1000_READ_REG(hw, CTRL);
2974 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2975 E1000_WRITE_REG(hw, CTRL, ctrl);
2976
2977 /* Configure Flow Control after forcing link up. */
2978 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002979 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 DEBUGOUT("Error configuring flow control\n");
2981 return ret_val;
2982 }
2983 }
2984 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2985 * auto-negotiation in the TXCW register and disable forced link in the
2986 * Device Control register in an attempt to auto-negotiate with our link
2987 * partner.
2988 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002989 else if (((hw->media_type == e1000_media_type_fiber) ||
2990 (hw->media_type == e1000_media_type_internal_serdes)) &&
2991 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07002992 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2994 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2995
2996 hw->serdes_link_down = FALSE;
2997 }
2998 /* If we force link for non-auto-negotiation switch, check link status
2999 * based on MAC synchronization for internal serdes media type.
3000 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003001 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3002 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 /* SYNCH bit and IV bit are sticky. */
3004 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003005 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3006 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 hw->serdes_link_down = FALSE;
3008 DEBUGOUT("SERDES: Link is up.\n");
3009 }
3010 } else {
3011 hw->serdes_link_down = TRUE;
3012 DEBUGOUT("SERDES: Link is down.\n");
3013 }
3014 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003015 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3016 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3018 }
3019 return E1000_SUCCESS;
3020}
3021
3022/******************************************************************************
3023 * Detects the current speed and duplex settings of the hardware.
3024 *
3025 * hw - Struct containing variables accessed by shared code
3026 * speed - Speed of the connection
3027 * duplex - Duplex setting of the connection
3028 *****************************************************************************/
3029int32_t
3030e1000_get_speed_and_duplex(struct e1000_hw *hw,
3031 uint16_t *speed,
3032 uint16_t *duplex)
3033{
3034 uint32_t status;
3035 int32_t ret_val;
3036 uint16_t phy_data;
3037
3038 DEBUGFUNC("e1000_get_speed_and_duplex");
3039
Auke Kok8fc897b2006-08-28 14:56:16 -07003040 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003042 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 *speed = SPEED_1000;
3044 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003045 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 *speed = SPEED_100;
3047 DEBUGOUT("100 Mbs, ");
3048 } else {
3049 *speed = SPEED_10;
3050 DEBUGOUT("10 Mbs, ");
3051 }
3052
Auke Kok8fc897b2006-08-28 14:56:16 -07003053 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003055 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 } else {
3057 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003058 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 }
3060 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003061 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 *speed = SPEED_1000;
3063 *duplex = FULL_DUPLEX;
3064 }
3065
3066 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3067 * if it is operating at half duplex. Here we set the duplex settings to
3068 * match the duplex in the link partner's capabilities.
3069 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003070 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003072 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 return ret_val;
3074
Auke Kok8fc897b2006-08-28 14:56:16 -07003075 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 *duplex = HALF_DUPLEX;
3077 else {
3078 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003079 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003081 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3083 *duplex = HALF_DUPLEX;
3084 }
3085 }
3086
Auke Kok76c224b2006-05-23 13:36:06 -07003087 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003088 (hw->media_type == e1000_media_type_copper)) {
3089 if (*speed == SPEED_1000)
3090 ret_val = e1000_configure_kmrn_for_1000(hw);
3091 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003092 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3093 if (ret_val)
3094 return ret_val;
3095 }
3096
3097 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3098 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003099 if (ret_val)
3100 return ret_val;
3101 }
3102
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 return E1000_SUCCESS;
3104}
3105
3106/******************************************************************************
3107* Blocks until autoneg completes or times out (~4.5 seconds)
3108*
3109* hw - Struct containing variables accessed by shared code
3110******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003111static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112e1000_wait_autoneg(struct e1000_hw *hw)
3113{
3114 int32_t ret_val;
3115 uint16_t i;
3116 uint16_t phy_data;
3117
3118 DEBUGFUNC("e1000_wait_autoneg");
3119 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3120
3121 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003122 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 /* Read the MII Status Register and wait for Auto-Neg
3124 * Complete bit to be set.
3125 */
3126 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003127 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 return ret_val;
3129 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003130 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003132 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 return E1000_SUCCESS;
3134 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003135 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
3137 return E1000_SUCCESS;
3138}
3139
3140/******************************************************************************
3141* Raises the Management Data Clock
3142*
3143* hw - Struct containing variables accessed by shared code
3144* ctrl - Device control register's current value
3145******************************************************************************/
3146static void
3147e1000_raise_mdi_clk(struct e1000_hw *hw,
3148 uint32_t *ctrl)
3149{
3150 /* Raise the clock input to the Management Data Clock (by setting the MDC
3151 * bit), and then delay 10 microseconds.
3152 */
3153 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3154 E1000_WRITE_FLUSH(hw);
3155 udelay(10);
3156}
3157
3158/******************************************************************************
3159* Lowers the Management Data Clock
3160*
3161* hw - Struct containing variables accessed by shared code
3162* ctrl - Device control register's current value
3163******************************************************************************/
3164static void
3165e1000_lower_mdi_clk(struct e1000_hw *hw,
3166 uint32_t *ctrl)
3167{
3168 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3169 * bit), and then delay 10 microseconds.
3170 */
3171 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3172 E1000_WRITE_FLUSH(hw);
3173 udelay(10);
3174}
3175
3176/******************************************************************************
3177* Shifts data bits out to the PHY
3178*
3179* hw - Struct containing variables accessed by shared code
3180* data - Data to send out to the PHY
3181* count - Number of bits to shift out
3182*
3183* Bits are shifted out in MSB to LSB order.
3184******************************************************************************/
3185static void
3186e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3187 uint32_t data,
3188 uint16_t count)
3189{
3190 uint32_t ctrl;
3191 uint32_t mask;
3192
3193 /* We need to shift "count" number of bits out to the PHY. So, the value
3194 * in the "data" parameter will be shifted out to the PHY one bit at a
3195 * time. In order to do this, "data" must be broken down into bits.
3196 */
3197 mask = 0x01;
3198 mask <<= (count - 1);
3199
3200 ctrl = E1000_READ_REG(hw, CTRL);
3201
3202 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3203 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3204
Auke Kok8fc897b2006-08-28 14:56:16 -07003205 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3207 * then raising and lowering the Management Data Clock. A "0" is
3208 * shifted out to the PHY by setting the MDIO bit to "0" and then
3209 * raising and lowering the clock.
3210 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003211 if (data & mask)
3212 ctrl |= E1000_CTRL_MDIO;
3213 else
3214 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 E1000_WRITE_REG(hw, CTRL, ctrl);
3217 E1000_WRITE_FLUSH(hw);
3218
3219 udelay(10);
3220
3221 e1000_raise_mdi_clk(hw, &ctrl);
3222 e1000_lower_mdi_clk(hw, &ctrl);
3223
3224 mask = mask >> 1;
3225 }
3226}
3227
3228/******************************************************************************
3229* Shifts data bits in from the PHY
3230*
3231* hw - Struct containing variables accessed by shared code
3232*
3233* Bits are shifted in in MSB to LSB order.
3234******************************************************************************/
3235static uint16_t
3236e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3237{
3238 uint32_t ctrl;
3239 uint16_t data = 0;
3240 uint8_t i;
3241
3242 /* In order to read a register from the PHY, we need to shift in a total
3243 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3244 * to avoid contention on the MDIO pin when a read operation is performed.
3245 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3246 * by raising the input to the Management Data Clock (setting the MDC bit),
3247 * and then reading the value of the MDIO bit.
3248 */
3249 ctrl = E1000_READ_REG(hw, CTRL);
3250
3251 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3252 ctrl &= ~E1000_CTRL_MDIO_DIR;
3253 ctrl &= ~E1000_CTRL_MDIO;
3254
3255 E1000_WRITE_REG(hw, CTRL, ctrl);
3256 E1000_WRITE_FLUSH(hw);
3257
3258 /* Raise and Lower the clock before reading in the data. This accounts for
3259 * the turnaround bits. The first clock occurred when we clocked out the
3260 * last bit of the Register Address.
3261 */
3262 e1000_raise_mdi_clk(hw, &ctrl);
3263 e1000_lower_mdi_clk(hw, &ctrl);
3264
Auke Kok8fc897b2006-08-28 14:56:16 -07003265 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 data = data << 1;
3267 e1000_raise_mdi_clk(hw, &ctrl);
3268 ctrl = E1000_READ_REG(hw, CTRL);
3269 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003270 if (ctrl & E1000_CTRL_MDIO)
3271 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 e1000_lower_mdi_clk(hw, &ctrl);
3273 }
3274
3275 e1000_raise_mdi_clk(hw, &ctrl);
3276 e1000_lower_mdi_clk(hw, &ctrl);
3277
3278 return data;
3279}
3280
Adrian Bunke4c780b2006-08-14 23:00:10 -07003281static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003282e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3283{
3284 uint32_t swfw_sync = 0;
3285 uint32_t swmask = mask;
3286 uint32_t fwmask = mask << 16;
3287 int32_t timeout = 200;
3288
3289 DEBUGFUNC("e1000_swfw_sync_acquire");
3290
Auke Kokcd94dd02006-06-27 09:08:22 -07003291 if (hw->swfwhw_semaphore_present)
3292 return e1000_get_software_flag(hw);
3293
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003294 if (!hw->swfw_sync_present)
3295 return e1000_get_hw_eeprom_semaphore(hw);
3296
Auke Kok8fc897b2006-08-28 14:56:16 -07003297 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003298 if (e1000_get_hw_eeprom_semaphore(hw))
3299 return -E1000_ERR_SWFW_SYNC;
3300
3301 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3302 if (!(swfw_sync & (fwmask | swmask))) {
3303 break;
3304 }
3305
3306 /* firmware currently using resource (fwmask) */
3307 /* or other software thread currently using resource (swmask) */
3308 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003309 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003310 timeout--;
3311 }
3312
3313 if (!timeout) {
3314 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3315 return -E1000_ERR_SWFW_SYNC;
3316 }
3317
3318 swfw_sync |= swmask;
3319 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3320
3321 e1000_put_hw_eeprom_semaphore(hw);
3322 return E1000_SUCCESS;
3323}
3324
Adrian Bunke4c780b2006-08-14 23:00:10 -07003325static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003326e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3327{
3328 uint32_t swfw_sync;
3329 uint32_t swmask = mask;
3330
3331 DEBUGFUNC("e1000_swfw_sync_release");
3332
Auke Kokcd94dd02006-06-27 09:08:22 -07003333 if (hw->swfwhw_semaphore_present) {
3334 e1000_release_software_flag(hw);
3335 return;
3336 }
3337
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003338 if (!hw->swfw_sync_present) {
3339 e1000_put_hw_eeprom_semaphore(hw);
3340 return;
3341 }
3342
3343 /* if (e1000_get_hw_eeprom_semaphore(hw))
3344 * return -E1000_ERR_SWFW_SYNC; */
3345 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3346 /* empty */
3347
3348 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3349 swfw_sync &= ~swmask;
3350 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3351
3352 e1000_put_hw_eeprom_semaphore(hw);
3353}
3354
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355/*****************************************************************************
3356* Reads the value from a PHY register, if the value is on a specific non zero
3357* page, sets the page first.
3358* hw - Struct containing variables accessed by shared code
3359* reg_addr - address of the PHY register to read
3360******************************************************************************/
3361int32_t
3362e1000_read_phy_reg(struct e1000_hw *hw,
3363 uint32_t reg_addr,
3364 uint16_t *phy_data)
3365{
3366 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003367 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
3369 DEBUGFUNC("e1000_read_phy_reg");
3370
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003371 if ((hw->mac_type == e1000_80003es2lan) &&
3372 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3373 swfw = E1000_SWFW_PHY1_SM;
3374 } else {
3375 swfw = E1000_SWFW_PHY0_SM;
3376 }
3377 if (e1000_swfw_sync_acquire(hw, swfw))
3378 return -E1000_ERR_SWFW_SYNC;
3379
Auke Kokcd94dd02006-06-27 09:08:22 -07003380 if ((hw->phy_type == e1000_phy_igp ||
3381 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003382 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3384 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3385 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003386 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003387 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 return ret_val;
3389 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003390 } else if (hw->phy_type == e1000_phy_gg82563) {
3391 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3392 (hw->mac_type == e1000_80003es2lan)) {
3393 /* Select Configuration Page */
3394 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3395 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3396 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3397 } else {
3398 /* Use Alternative Page Select register to access
3399 * registers 30 and 31
3400 */
3401 ret_val = e1000_write_phy_reg_ex(hw,
3402 GG82563_PHY_PAGE_SELECT_ALT,
3403 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3404 }
3405
3406 if (ret_val) {
3407 e1000_swfw_sync_release(hw, swfw);
3408 return ret_val;
3409 }
3410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 }
3412
3413 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3414 phy_data);
3415
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003416 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 return ret_val;
3418}
3419
3420int32_t
3421e1000_read_phy_reg_ex(struct e1000_hw *hw,
3422 uint32_t reg_addr,
3423 uint16_t *phy_data)
3424{
3425 uint32_t i;
3426 uint32_t mdic = 0;
3427 const uint32_t phy_addr = 1;
3428
3429 DEBUGFUNC("e1000_read_phy_reg_ex");
3430
Auke Kok8fc897b2006-08-28 14:56:16 -07003431 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3433 return -E1000_ERR_PARAM;
3434 }
3435
Auke Kok8fc897b2006-08-28 14:56:16 -07003436 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 /* Set up Op-code, Phy Address, and register address in the MDI
3438 * Control register. The MAC will take care of interfacing with the
3439 * PHY to retrieve the desired data.
3440 */
3441 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3442 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3443 (E1000_MDIC_OP_READ));
3444
3445 E1000_WRITE_REG(hw, MDIC, mdic);
3446
3447 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003448 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 udelay(50);
3450 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003451 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003453 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 DEBUGOUT("MDI Read did not complete\n");
3455 return -E1000_ERR_PHY;
3456 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003457 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 DEBUGOUT("MDI Error\n");
3459 return -E1000_ERR_PHY;
3460 }
3461 *phy_data = (uint16_t) mdic;
3462 } else {
3463 /* We must first send a preamble through the MDIO pin to signal the
3464 * beginning of an MII instruction. This is done by sending 32
3465 * consecutive "1" bits.
3466 */
3467 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3468
3469 /* Now combine the next few fields that are required for a read
3470 * operation. We use this method instead of calling the
3471 * e1000_shift_out_mdi_bits routine five different times. The format of
3472 * a MII read instruction consists of a shift out of 14 bits and is
3473 * defined as follows:
3474 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3475 * followed by a shift in of 18 bits. This first two bits shifted in
3476 * are TurnAround bits used to avoid contention on the MDIO pin when a
3477 * READ operation is performed. These two bits are thrown away
3478 * followed by a shift in of 16 bits which contains the desired data.
3479 */
3480 mdic = ((reg_addr) | (phy_addr << 5) |
3481 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3482
3483 e1000_shift_out_mdi_bits(hw, mdic, 14);
3484
3485 /* Now that we've shifted out the read command to the MII, we need to
3486 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3487 * register address.
3488 */
3489 *phy_data = e1000_shift_in_mdi_bits(hw);
3490 }
3491 return E1000_SUCCESS;
3492}
3493
3494/******************************************************************************
3495* Writes a value to a PHY register
3496*
3497* hw - Struct containing variables accessed by shared code
3498* reg_addr - address of the PHY register to write
3499* data - data to write to the PHY
3500******************************************************************************/
3501int32_t
3502e1000_write_phy_reg(struct e1000_hw *hw,
3503 uint32_t reg_addr,
3504 uint16_t phy_data)
3505{
3506 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003507 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
3509 DEBUGFUNC("e1000_write_phy_reg");
3510
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003511 if ((hw->mac_type == e1000_80003es2lan) &&
3512 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3513 swfw = E1000_SWFW_PHY1_SM;
3514 } else {
3515 swfw = E1000_SWFW_PHY0_SM;
3516 }
3517 if (e1000_swfw_sync_acquire(hw, swfw))
3518 return -E1000_ERR_SWFW_SYNC;
3519
Auke Kokcd94dd02006-06-27 09:08:22 -07003520 if ((hw->phy_type == e1000_phy_igp ||
3521 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003522 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3524 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3525 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003526 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003527 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 return ret_val;
3529 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003530 } else if (hw->phy_type == e1000_phy_gg82563) {
3531 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3532 (hw->mac_type == e1000_80003es2lan)) {
3533 /* Select Configuration Page */
3534 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3535 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3536 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3537 } else {
3538 /* Use Alternative Page Select register to access
3539 * registers 30 and 31
3540 */
3541 ret_val = e1000_write_phy_reg_ex(hw,
3542 GG82563_PHY_PAGE_SELECT_ALT,
3543 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3544 }
3545
3546 if (ret_val) {
3547 e1000_swfw_sync_release(hw, swfw);
3548 return ret_val;
3549 }
3550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 }
3552
3553 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3554 phy_data);
3555
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003556 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 return ret_val;
3558}
3559
3560int32_t
3561e1000_write_phy_reg_ex(struct e1000_hw *hw,
3562 uint32_t reg_addr,
3563 uint16_t phy_data)
3564{
3565 uint32_t i;
3566 uint32_t mdic = 0;
3567 const uint32_t phy_addr = 1;
3568
3569 DEBUGFUNC("e1000_write_phy_reg_ex");
3570
Auke Kok8fc897b2006-08-28 14:56:16 -07003571 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3573 return -E1000_ERR_PARAM;
3574 }
3575
Auke Kok8fc897b2006-08-28 14:56:16 -07003576 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 /* Set up Op-code, Phy Address, register address, and data intended
3578 * for the PHY register in the MDI Control register. The MAC will take
3579 * care of interfacing with the PHY to send the desired data.
3580 */
3581 mdic = (((uint32_t) phy_data) |
3582 (reg_addr << E1000_MDIC_REG_SHIFT) |
3583 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3584 (E1000_MDIC_OP_WRITE));
3585
3586 E1000_WRITE_REG(hw, MDIC, mdic);
3587
3588 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003589 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 udelay(5);
3591 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003592 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003594 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 DEBUGOUT("MDI Write did not complete\n");
3596 return -E1000_ERR_PHY;
3597 }
3598 } else {
3599 /* We'll need to use the SW defined pins to shift the write command
3600 * out to the PHY. We first send a preamble to the PHY to signal the
3601 * beginning of the MII instruction. This is done by sending 32
3602 * consecutive "1" bits.
3603 */
3604 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3605
3606 /* Now combine the remaining required fields that will indicate a
3607 * write operation. We use this method instead of calling the
3608 * e1000_shift_out_mdi_bits routine for each field in the command. The
3609 * format of a MII write instruction is as follows:
3610 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3611 */
3612 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3613 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3614 mdic <<= 16;
3615 mdic |= (uint32_t) phy_data;
3616
3617 e1000_shift_out_mdi_bits(hw, mdic, 32);
3618 }
3619
3620 return E1000_SUCCESS;
3621}
3622
Adrian Bunke4c780b2006-08-14 23:00:10 -07003623static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003624e1000_read_kmrn_reg(struct e1000_hw *hw,
3625 uint32_t reg_addr,
3626 uint16_t *data)
3627{
3628 uint32_t reg_val;
3629 uint16_t swfw;
3630 DEBUGFUNC("e1000_read_kmrn_reg");
3631
3632 if ((hw->mac_type == e1000_80003es2lan) &&
3633 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3634 swfw = E1000_SWFW_PHY1_SM;
3635 } else {
3636 swfw = E1000_SWFW_PHY0_SM;
3637 }
3638 if (e1000_swfw_sync_acquire(hw, swfw))
3639 return -E1000_ERR_SWFW_SYNC;
3640
3641 /* Write register address */
3642 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3643 E1000_KUMCTRLSTA_OFFSET) |
3644 E1000_KUMCTRLSTA_REN;
3645 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3646 udelay(2);
3647
3648 /* Read the data returned */
3649 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3650 *data = (uint16_t)reg_val;
3651
3652 e1000_swfw_sync_release(hw, swfw);
3653 return E1000_SUCCESS;
3654}
3655
Adrian Bunke4c780b2006-08-14 23:00:10 -07003656static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003657e1000_write_kmrn_reg(struct e1000_hw *hw,
3658 uint32_t reg_addr,
3659 uint16_t data)
3660{
3661 uint32_t reg_val;
3662 uint16_t swfw;
3663 DEBUGFUNC("e1000_write_kmrn_reg");
3664
3665 if ((hw->mac_type == e1000_80003es2lan) &&
3666 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3667 swfw = E1000_SWFW_PHY1_SM;
3668 } else {
3669 swfw = E1000_SWFW_PHY0_SM;
3670 }
3671 if (e1000_swfw_sync_acquire(hw, swfw))
3672 return -E1000_ERR_SWFW_SYNC;
3673
3674 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3675 E1000_KUMCTRLSTA_OFFSET) | data;
3676 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3677 udelay(2);
3678
3679 e1000_swfw_sync_release(hw, swfw);
3680 return E1000_SUCCESS;
3681}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003682
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683/******************************************************************************
3684* Returns the PHY to the power-on reset state
3685*
3686* hw - Struct containing variables accessed by shared code
3687******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003688int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689e1000_phy_hw_reset(struct e1000_hw *hw)
3690{
3691 uint32_t ctrl, ctrl_ext;
3692 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003693 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003694 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695
3696 DEBUGFUNC("e1000_phy_hw_reset");
3697
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003698 /* In the case of the phy reset being blocked, it's not an error, we
3699 * simply return success without performing the reset. */
3700 ret_val = e1000_check_phy_reset_block(hw);
3701 if (ret_val)
3702 return E1000_SUCCESS;
3703
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 DEBUGOUT("Resetting Phy...\n");
3705
Auke Kok8fc897b2006-08-28 14:56:16 -07003706 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003707 if ((hw->mac_type == e1000_80003es2lan) &&
3708 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3709 swfw = E1000_SWFW_PHY1_SM;
3710 } else {
3711 swfw = E1000_SWFW_PHY0_SM;
3712 }
3713 if (e1000_swfw_sync_acquire(hw, swfw)) {
3714 e1000_release_software_semaphore(hw);
3715 return -E1000_ERR_SWFW_SYNC;
3716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3718 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003719 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003720 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003721 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 */
3723 ctrl = E1000_READ_REG(hw, CTRL);
3724 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3725 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003726
3727 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003728 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003729 else
3730 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003731
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 E1000_WRITE_REG(hw, CTRL, ctrl);
3733 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003734
Jeff Kirsherfd803242005-12-13 00:06:22 -05003735 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003736 mdelay(10);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003737 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 } else {
3739 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3740 * bit to put the PHY into reset. Then, take it out of reset.
3741 */
3742 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3743 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3744 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3745 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3746 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003747 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3749 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3750 E1000_WRITE_FLUSH(hw);
3751 }
3752 udelay(150);
3753
Auke Kok8fc897b2006-08-28 14:56:16 -07003754 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 /* Configure activity LED after PHY reset */
3756 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3757 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3758 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3759 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3760 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003761
3762 /* Wait for FW to finish PHY configuration. */
3763 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003764 if (ret_val != E1000_SUCCESS)
3765 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003766 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003767
Auke Kok8fc897b2006-08-28 14:56:16 -07003768 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3769 ret_val = e1000_init_lcd_from_nvm(hw);
3770
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003771 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772}
3773
3774/******************************************************************************
3775* Resets the PHY
3776*
3777* hw - Struct containing variables accessed by shared code
3778*
3779* Sets bit 15 of the MII Control regiser
3780******************************************************************************/
3781int32_t
3782e1000_phy_reset(struct e1000_hw *hw)
3783{
3784 int32_t ret_val;
3785 uint16_t phy_data;
3786
3787 DEBUGFUNC("e1000_phy_reset");
3788
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003789 /* In the case of the phy reset being blocked, it's not an error, we
3790 * simply return success without performing the reset. */
3791 ret_val = e1000_check_phy_reset_block(hw);
3792 if (ret_val)
3793 return E1000_SUCCESS;
3794
3795 switch (hw->mac_type) {
3796 case e1000_82541_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003797 case e1000_82571:
3798 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07003799 case e1000_ich8lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003800 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003801 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003802 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07003803
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003804 break;
3805 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003807 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 return ret_val;
3809
3810 phy_data |= MII_CR_RESET;
3811 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003812 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 return ret_val;
3814
3815 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003816 break;
3817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
Auke Kok8fc897b2006-08-28 14:56:16 -07003819 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 e1000_phy_init_script(hw);
3821
3822 return E1000_SUCCESS;
3823}
3824
3825/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003826* Work-around for 82566 power-down: on D3 entry-
3827* 1) disable gigabit link
3828* 2) write VR power-down enable
3829* 3) read it back
3830* if successful continue, else issue LCD reset and repeat
3831*
3832* hw - struct containing variables accessed by shared code
3833******************************************************************************/
3834void
3835e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3836{
3837 int32_t reg;
3838 uint16_t phy_data;
3839 int32_t retry = 0;
3840
3841 DEBUGFUNC("e1000_phy_powerdown_workaround");
3842
3843 if (hw->phy_type != e1000_phy_igp_3)
3844 return;
3845
3846 do {
3847 /* Disable link */
3848 reg = E1000_READ_REG(hw, PHY_CTRL);
3849 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3850 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3851
3852 /* Write VR power-down enable */
3853 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3854 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data |
3855 IGP3_VR_CTRL_MODE_SHUT);
3856
3857 /* Read it back and test */
3858 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3859 if ((phy_data & IGP3_VR_CTRL_MODE_SHUT) || retry)
3860 break;
3861
3862 /* Issue PHY reset and repeat at most one more time */
3863 reg = E1000_READ_REG(hw, CTRL);
3864 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3865 retry++;
3866 } while (retry);
3867
3868 return;
3869
3870}
3871
3872/******************************************************************************
3873* Work-around for 82566 Kumeran PCS lock loss:
3874* On link status change (i.e. PCI reset, speed change) and link is up and
3875* speed is gigabit-
3876* 0) if workaround is optionally disabled do nothing
3877* 1) wait 1ms for Kumeran link to come up
3878* 2) check Kumeran Diagnostic register PCS lock loss bit
3879* 3) if not set the link is locked (all is good), otherwise...
3880* 4) reset the PHY
3881* 5) repeat up to 10 times
3882* Note: this is only called for IGP3 copper when speed is 1gb.
3883*
3884* hw - struct containing variables accessed by shared code
3885******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003886static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003887e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3888{
3889 int32_t ret_val;
3890 int32_t reg;
3891 int32_t cnt;
3892 uint16_t phy_data;
3893
3894 if (hw->kmrn_lock_loss_workaround_disabled)
3895 return E1000_SUCCESS;
3896
Auke Kok8fc897b2006-08-28 14:56:16 -07003897 /* Make sure link is up before proceeding. If not just return.
3898 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003899 * stability */
3900 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3901 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3902
3903 if (phy_data & MII_SR_LINK_STATUS) {
3904 for (cnt = 0; cnt < 10; cnt++) {
3905 /* read once to clear */
3906 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3907 if (ret_val)
3908 return ret_val;
3909 /* and again to get new status */
3910 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3911 if (ret_val)
3912 return ret_val;
3913
3914 /* check for PCS lock */
3915 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3916 return E1000_SUCCESS;
3917
3918 /* Issue PHY reset */
3919 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003920 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003921 }
3922 /* Disable GigE link negotiation */
3923 reg = E1000_READ_REG(hw, PHY_CTRL);
3924 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3925 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3926
3927 /* unable to acquire PCS lock */
3928 return E1000_ERR_PHY;
3929 }
3930
3931 return E1000_SUCCESS;
3932}
3933
3934/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935* Probes the expected PHY address for known PHY IDs
3936*
3937* hw - Struct containing variables accessed by shared code
3938******************************************************************************/
Auke Kokd37ea5d2006-06-27 09:08:17 -07003939int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940e1000_detect_gig_phy(struct e1000_hw *hw)
3941{
3942 int32_t phy_init_status, ret_val;
3943 uint16_t phy_id_high, phy_id_low;
3944 boolean_t match = FALSE;
3945
3946 DEBUGFUNC("e1000_detect_gig_phy");
3947
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003948 /* The 82571 firmware may still be configuring the PHY. In this
3949 * case, we cannot access the PHY until the configuration is done. So
3950 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07003951 if (hw->mac_type == e1000_82571 ||
3952 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003953 hw->phy_id = IGP01E1000_I_PHY_ID;
3954 hw->phy_type = e1000_phy_igp_2;
3955 return E1000_SUCCESS;
3956 }
3957
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003958 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3959 * around that forces PHY page 0 to be set or the reads fail. The rest of
3960 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3961 * So for ESB-2 we need to have this set so our reads won't fail. If the
3962 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3963 * this out as well. */
3964 if (hw->mac_type == e1000_80003es2lan)
3965 hw->phy_type = e1000_phy_gg82563;
3966
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 /* Read the PHY ID Registers to identify which PHY is onboard. */
3968 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07003969 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 return ret_val;
3971
3972 hw->phy_id = (uint32_t) (phy_id_high << 16);
3973 udelay(20);
3974 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07003975 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 return ret_val;
3977
3978 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3979 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3980
Auke Kok8fc897b2006-08-28 14:56:16 -07003981 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07003983 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 break;
3985 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07003986 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 break;
3988 case e1000_82540:
3989 case e1000_82545:
3990 case e1000_82545_rev_3:
3991 case e1000_82546:
3992 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07003993 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 break;
3995 case e1000_82541:
3996 case e1000_82541_rev_2:
3997 case e1000_82547:
3998 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07003999 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004001 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004002 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004003 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004004 case e1000_80003es2lan:
4005 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4006 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004007 case e1000_ich8lan:
4008 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4009 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4010 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4011 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4012 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013 default:
4014 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4015 return -E1000_ERR_CONFIG;
4016 }
4017 phy_init_status = e1000_set_phy_type(hw);
4018
4019 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4020 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4021 return E1000_SUCCESS;
4022 }
4023 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4024 return -E1000_ERR_PHY;
4025}
4026
4027/******************************************************************************
4028* Resets the PHY's DSP
4029*
4030* hw - Struct containing variables accessed by shared code
4031******************************************************************************/
4032static int32_t
4033e1000_phy_reset_dsp(struct e1000_hw *hw)
4034{
4035 int32_t ret_val;
4036 DEBUGFUNC("e1000_phy_reset_dsp");
4037
4038 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004039 if (hw->phy_type != e1000_phy_gg82563) {
4040 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004041 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004044 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004046 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004048 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049
4050 return ret_val;
4051}
4052
4053/******************************************************************************
4054* Get PHY information from various PHY registers for igp PHY only.
4055*
4056* hw - Struct containing variables accessed by shared code
4057* phy_info - PHY information structure
4058******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004059static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060e1000_phy_igp_get_info(struct e1000_hw *hw,
4061 struct e1000_phy_info *phy_info)
4062{
4063 int32_t ret_val;
4064 uint16_t phy_data, polarity, min_length, max_length, average;
4065
4066 DEBUGFUNC("e1000_phy_igp_get_info");
4067
4068 /* The downshift status is checked only once, after link is established,
4069 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004070 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071
4072 /* IGP01E1000 does not need to support it. */
4073 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4074
4075 /* IGP01E1000 always correct polarity reversal */
4076 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4077
4078 /* Check polarity status */
4079 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004080 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 return ret_val;
4082
4083 phy_info->cable_polarity = polarity;
4084
4085 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004086 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 return ret_val;
4088
4089 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
4090 IGP01E1000_PSSR_MDIX_SHIFT;
4091
Auke Kok8fc897b2006-08-28 14:56:16 -07004092 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 IGP01E1000_PSSR_SPEED_1000MBPS) {
4094 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4095 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004096 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 return ret_val;
4098
4099 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4100 SR_1000T_LOCAL_RX_STATUS_SHIFT;
4101 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4102 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4103
4104 /* Get cable length */
4105 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004106 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 return ret_val;
4108
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004109 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 average = (max_length + min_length) / 2;
4111
Auke Kok8fc897b2006-08-28 14:56:16 -07004112 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004114 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004116 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004118 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 phy_info->cable_length = e1000_cable_length_110_140;
4120 else
4121 phy_info->cable_length = e1000_cable_length_140;
4122 }
4123
4124 return E1000_SUCCESS;
4125}
4126
4127/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004128* Get PHY information from various PHY registers for ife PHY only.
4129*
4130* hw - Struct containing variables accessed by shared code
4131* phy_info - PHY information structure
4132******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004133static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004134e1000_phy_ife_get_info(struct e1000_hw *hw,
4135 struct e1000_phy_info *phy_info)
4136{
4137 int32_t ret_val;
4138 uint16_t phy_data, polarity;
4139
4140 DEBUGFUNC("e1000_phy_ife_get_info");
4141
4142 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4143 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4144
4145 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4146 if (ret_val)
4147 return ret_val;
4148 phy_info->polarity_correction =
4149 (phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4150 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT;
4151
4152 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4153 ret_val = e1000_check_polarity(hw, &polarity);
4154 if (ret_val)
4155 return ret_val;
4156 } else {
4157 /* Polarity is forced. */
4158 polarity = (phy_data & IFE_PSC_FORCE_POLARITY) >>
4159 IFE_PSC_FORCE_POLARITY_SHIFT;
4160 }
4161 phy_info->cable_polarity = polarity;
4162
4163 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4164 if (ret_val)
4165 return ret_val;
4166
4167 phy_info->mdix_mode =
4168 (phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4169 IFE_PMC_MDIX_MODE_SHIFT;
4170
4171 return E1000_SUCCESS;
4172}
4173
4174/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175* Get PHY information from various PHY registers fot m88 PHY only.
4176*
4177* hw - Struct containing variables accessed by shared code
4178* phy_info - PHY information structure
4179******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004180static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181e1000_phy_m88_get_info(struct e1000_hw *hw,
4182 struct e1000_phy_info *phy_info)
4183{
4184 int32_t ret_val;
4185 uint16_t phy_data, polarity;
4186
4187 DEBUGFUNC("e1000_phy_m88_get_info");
4188
4189 /* The downshift status is checked only once, after link is established,
4190 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004191 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
4193 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004194 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 return ret_val;
4196
4197 phy_info->extended_10bt_distance =
4198 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4199 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
4200 phy_info->polarity_correction =
4201 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4202 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
4203
4204 /* Check polarity status */
4205 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004206 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004207 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 phy_info->cable_polarity = polarity;
4209
4210 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004211 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 return ret_val;
4213
4214 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
4215 M88E1000_PSSR_MDIX_SHIFT;
4216
4217 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4218 /* Cable Length Estimation and Local/Remote Receiver Information
4219 * are only valid at 1000 Mbps.
4220 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004221 if (hw->phy_type != e1000_phy_gg82563) {
4222 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4223 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4224 } else {
4225 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4226 &phy_data);
4227 if (ret_val)
4228 return ret_val;
4229
4230 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
4231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232
4233 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004234 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 return ret_val;
4236
4237 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4238 SR_1000T_LOCAL_RX_STATUS_SHIFT;
4239
4240 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4241 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4242 }
4243
4244 return E1000_SUCCESS;
4245}
4246
4247/******************************************************************************
4248* Get PHY information from various PHY registers
4249*
4250* hw - Struct containing variables accessed by shared code
4251* phy_info - PHY information structure
4252******************************************************************************/
4253int32_t
4254e1000_phy_get_info(struct e1000_hw *hw,
4255 struct e1000_phy_info *phy_info)
4256{
4257 int32_t ret_val;
4258 uint16_t phy_data;
4259
4260 DEBUGFUNC("e1000_phy_get_info");
4261
4262 phy_info->cable_length = e1000_cable_length_undefined;
4263 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4264 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4265 phy_info->downshift = e1000_downshift_undefined;
4266 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4267 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4268 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4269 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4270
Auke Kok8fc897b2006-08-28 14:56:16 -07004271 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 DEBUGOUT("PHY info is only valid for copper media\n");
4273 return -E1000_ERR_CONFIG;
4274 }
4275
4276 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004277 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 return ret_val;
4279
4280 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004281 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 return ret_val;
4283
Auke Kok8fc897b2006-08-28 14:56:16 -07004284 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 DEBUGOUT("PHY info is only valid if link is up\n");
4286 return -E1000_ERR_CONFIG;
4287 }
4288
Auke Kokcd94dd02006-06-27 09:08:22 -07004289 if (hw->phy_type == e1000_phy_igp ||
4290 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004291 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004293 else if (hw->phy_type == e1000_phy_ife)
4294 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 else
4296 return e1000_phy_m88_get_info(hw, phy_info);
4297}
4298
4299int32_t
4300e1000_validate_mdi_setting(struct e1000_hw *hw)
4301{
4302 DEBUGFUNC("e1000_validate_mdi_settings");
4303
Auke Kok8fc897b2006-08-28 14:56:16 -07004304 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 DEBUGOUT("Invalid MDI setting detected\n");
4306 hw->mdix = 1;
4307 return -E1000_ERR_CONFIG;
4308 }
4309 return E1000_SUCCESS;
4310}
4311
4312
4313/******************************************************************************
4314 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004315 * is configured. Additionally, if this is ICH8, the flash controller GbE
4316 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 *
4318 * hw - Struct containing variables accessed by shared code
4319 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004320int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321e1000_init_eeprom_params(struct e1000_hw *hw)
4322{
4323 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4324 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004325 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 uint16_t eeprom_size;
4327
4328 DEBUGFUNC("e1000_init_eeprom_params");
4329
4330 switch (hw->mac_type) {
4331 case e1000_82542_rev2_0:
4332 case e1000_82542_rev2_1:
4333 case e1000_82543:
4334 case e1000_82544:
4335 eeprom->type = e1000_eeprom_microwire;
4336 eeprom->word_size = 64;
4337 eeprom->opcode_bits = 3;
4338 eeprom->address_bits = 6;
4339 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004340 eeprom->use_eerd = FALSE;
4341 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 break;
4343 case e1000_82540:
4344 case e1000_82545:
4345 case e1000_82545_rev_3:
4346 case e1000_82546:
4347 case e1000_82546_rev_3:
4348 eeprom->type = e1000_eeprom_microwire;
4349 eeprom->opcode_bits = 3;
4350 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004351 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 eeprom->word_size = 256;
4353 eeprom->address_bits = 8;
4354 } else {
4355 eeprom->word_size = 64;
4356 eeprom->address_bits = 6;
4357 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004358 eeprom->use_eerd = FALSE;
4359 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 break;
4361 case e1000_82541:
4362 case e1000_82541_rev_2:
4363 case e1000_82547:
4364 case e1000_82547_rev_2:
4365 if (eecd & E1000_EECD_TYPE) {
4366 eeprom->type = e1000_eeprom_spi;
4367 eeprom->opcode_bits = 8;
4368 eeprom->delay_usec = 1;
4369 if (eecd & E1000_EECD_ADDR_BITS) {
4370 eeprom->page_size = 32;
4371 eeprom->address_bits = 16;
4372 } else {
4373 eeprom->page_size = 8;
4374 eeprom->address_bits = 8;
4375 }
4376 } else {
4377 eeprom->type = e1000_eeprom_microwire;
4378 eeprom->opcode_bits = 3;
4379 eeprom->delay_usec = 50;
4380 if (eecd & E1000_EECD_ADDR_BITS) {
4381 eeprom->word_size = 256;
4382 eeprom->address_bits = 8;
4383 } else {
4384 eeprom->word_size = 64;
4385 eeprom->address_bits = 6;
4386 }
4387 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004388 eeprom->use_eerd = FALSE;
4389 eeprom->use_eewr = FALSE;
4390 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004391 case e1000_82571:
4392 case e1000_82572:
4393 eeprom->type = e1000_eeprom_spi;
4394 eeprom->opcode_bits = 8;
4395 eeprom->delay_usec = 1;
4396 if (eecd & E1000_EECD_ADDR_BITS) {
4397 eeprom->page_size = 32;
4398 eeprom->address_bits = 16;
4399 } else {
4400 eeprom->page_size = 8;
4401 eeprom->address_bits = 8;
4402 }
4403 eeprom->use_eerd = FALSE;
4404 eeprom->use_eewr = FALSE;
4405 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004406 case e1000_82573:
4407 eeprom->type = e1000_eeprom_spi;
4408 eeprom->opcode_bits = 8;
4409 eeprom->delay_usec = 1;
4410 if (eecd & E1000_EECD_ADDR_BITS) {
4411 eeprom->page_size = 32;
4412 eeprom->address_bits = 16;
4413 } else {
4414 eeprom->page_size = 8;
4415 eeprom->address_bits = 8;
4416 }
4417 eeprom->use_eerd = TRUE;
4418 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004419 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004420 eeprom->type = e1000_eeprom_flash;
4421 eeprom->word_size = 2048;
4422
4423 /* Ensure that the Autonomous FLASH update bit is cleared due to
4424 * Flash update issue on parts which use a FLASH for NVM. */
4425 eecd &= ~E1000_EECD_AUPDEN;
4426 E1000_WRITE_REG(hw, EECD, eecd);
4427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004429 case e1000_80003es2lan:
4430 eeprom->type = e1000_eeprom_spi;
4431 eeprom->opcode_bits = 8;
4432 eeprom->delay_usec = 1;
4433 if (eecd & E1000_EECD_ADDR_BITS) {
4434 eeprom->page_size = 32;
4435 eeprom->address_bits = 16;
4436 } else {
4437 eeprom->page_size = 8;
4438 eeprom->address_bits = 8;
4439 }
4440 eeprom->use_eerd = TRUE;
4441 eeprom->use_eewr = FALSE;
4442 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004443 case e1000_ich8lan:
4444 {
4445 int32_t i = 0;
4446 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4447
4448 eeprom->type = e1000_eeprom_ich8;
4449 eeprom->use_eerd = FALSE;
4450 eeprom->use_eewr = FALSE;
4451 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4452
4453 /* Zero the shadow RAM structure. But don't load it from NVM
4454 * so as to save time for driver init */
4455 if (hw->eeprom_shadow_ram != NULL) {
4456 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4457 hw->eeprom_shadow_ram[i].modified = FALSE;
4458 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4459 }
4460 }
4461
4462 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4463 ICH8_FLASH_SECTOR_SIZE;
4464
4465 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4466 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4467 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4468 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4469
4470 break;
4471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 default:
4473 break;
4474 }
4475
4476 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004477 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4478 * 32KB (incremented by powers of 2).
4479 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004480 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004481 /* Set to default value for initial eeprom read. */
4482 eeprom->word_size = 64;
4483 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004484 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004485 return ret_val;
4486 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4487 /* 256B eeprom size was not supported in earlier hardware, so we
4488 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4489 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004490 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004491 eeprom_size++;
4492 } else {
4493 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4494 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004496
4497 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004499 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500}
4501
4502/******************************************************************************
4503 * Raises the EEPROM's clock input.
4504 *
4505 * hw - Struct containing variables accessed by shared code
4506 * eecd - EECD's current value
4507 *****************************************************************************/
4508static void
4509e1000_raise_ee_clk(struct e1000_hw *hw,
4510 uint32_t *eecd)
4511{
4512 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4513 * wait <delay> microseconds.
4514 */
4515 *eecd = *eecd | E1000_EECD_SK;
4516 E1000_WRITE_REG(hw, EECD, *eecd);
4517 E1000_WRITE_FLUSH(hw);
4518 udelay(hw->eeprom.delay_usec);
4519}
4520
4521/******************************************************************************
4522 * Lowers the EEPROM's clock input.
4523 *
4524 * hw - Struct containing variables accessed by shared code
4525 * eecd - EECD's current value
4526 *****************************************************************************/
4527static void
4528e1000_lower_ee_clk(struct e1000_hw *hw,
4529 uint32_t *eecd)
4530{
4531 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4532 * wait 50 microseconds.
4533 */
4534 *eecd = *eecd & ~E1000_EECD_SK;
4535 E1000_WRITE_REG(hw, EECD, *eecd);
4536 E1000_WRITE_FLUSH(hw);
4537 udelay(hw->eeprom.delay_usec);
4538}
4539
4540/******************************************************************************
4541 * Shift data bits out to the EEPROM.
4542 *
4543 * hw - Struct containing variables accessed by shared code
4544 * data - data to send to the EEPROM
4545 * count - number of bits to shift out
4546 *****************************************************************************/
4547static void
4548e1000_shift_out_ee_bits(struct e1000_hw *hw,
4549 uint16_t data,
4550 uint16_t count)
4551{
4552 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4553 uint32_t eecd;
4554 uint32_t mask;
4555
4556 /* We need to shift "count" bits out to the EEPROM. So, value in the
4557 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4558 * In order to do this, "data" must be broken down into bits.
4559 */
4560 mask = 0x01 << (count - 1);
4561 eecd = E1000_READ_REG(hw, EECD);
4562 if (eeprom->type == e1000_eeprom_microwire) {
4563 eecd &= ~E1000_EECD_DO;
4564 } else if (eeprom->type == e1000_eeprom_spi) {
4565 eecd |= E1000_EECD_DO;
4566 }
4567 do {
4568 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4569 * and then raising and then lowering the clock (the SK bit controls
4570 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4571 * by setting "DI" to "0" and then raising and then lowering the clock.
4572 */
4573 eecd &= ~E1000_EECD_DI;
4574
Auke Kok8fc897b2006-08-28 14:56:16 -07004575 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 eecd |= E1000_EECD_DI;
4577
4578 E1000_WRITE_REG(hw, EECD, eecd);
4579 E1000_WRITE_FLUSH(hw);
4580
4581 udelay(eeprom->delay_usec);
4582
4583 e1000_raise_ee_clk(hw, &eecd);
4584 e1000_lower_ee_clk(hw, &eecd);
4585
4586 mask = mask >> 1;
4587
Auke Kok8fc897b2006-08-28 14:56:16 -07004588 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589
4590 /* We leave the "DI" bit set to "0" when we leave this routine. */
4591 eecd &= ~E1000_EECD_DI;
4592 E1000_WRITE_REG(hw, EECD, eecd);
4593}
4594
4595/******************************************************************************
4596 * Shift data bits in from the EEPROM
4597 *
4598 * hw - Struct containing variables accessed by shared code
4599 *****************************************************************************/
4600static uint16_t
4601e1000_shift_in_ee_bits(struct e1000_hw *hw,
4602 uint16_t count)
4603{
4604 uint32_t eecd;
4605 uint32_t i;
4606 uint16_t data;
4607
4608 /* In order to read a register from the EEPROM, we need to shift 'count'
4609 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4610 * input to the EEPROM (setting the SK bit), and then reading the value of
4611 * the "DO" bit. During this "shifting in" process the "DI" bit should
4612 * always be clear.
4613 */
4614
4615 eecd = E1000_READ_REG(hw, EECD);
4616
4617 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4618 data = 0;
4619
Auke Kok8fc897b2006-08-28 14:56:16 -07004620 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 data = data << 1;
4622 e1000_raise_ee_clk(hw, &eecd);
4623
4624 eecd = E1000_READ_REG(hw, EECD);
4625
4626 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004627 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 data |= 1;
4629
4630 e1000_lower_ee_clk(hw, &eecd);
4631 }
4632
4633 return data;
4634}
4635
4636/******************************************************************************
4637 * Prepares EEPROM for access
4638 *
4639 * hw - Struct containing variables accessed by shared code
4640 *
4641 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4642 * function should be called before issuing a command to the EEPROM.
4643 *****************************************************************************/
4644static int32_t
4645e1000_acquire_eeprom(struct e1000_hw *hw)
4646{
4647 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4648 uint32_t eecd, i=0;
4649
4650 DEBUGFUNC("e1000_acquire_eeprom");
4651
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004652 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4653 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 eecd = E1000_READ_REG(hw, EECD);
4655
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004656 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004657 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004658 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004659 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004661 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004662 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004663 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4664 i++;
4665 udelay(5);
4666 eecd = E1000_READ_REG(hw, EECD);
4667 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004668 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004669 eecd &= ~E1000_EECD_REQ;
4670 E1000_WRITE_REG(hw, EECD, eecd);
4671 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004672 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004673 return -E1000_ERR_EEPROM;
4674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 }
4676 }
4677
4678 /* Setup EEPROM for Read/Write */
4679
4680 if (eeprom->type == e1000_eeprom_microwire) {
4681 /* Clear SK and DI */
4682 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4683 E1000_WRITE_REG(hw, EECD, eecd);
4684
4685 /* Set CS */
4686 eecd |= E1000_EECD_CS;
4687 E1000_WRITE_REG(hw, EECD, eecd);
4688 } else if (eeprom->type == e1000_eeprom_spi) {
4689 /* Clear SK and CS */
4690 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4691 E1000_WRITE_REG(hw, EECD, eecd);
4692 udelay(1);
4693 }
4694
4695 return E1000_SUCCESS;
4696}
4697
4698/******************************************************************************
4699 * Returns EEPROM to a "standby" state
4700 *
4701 * hw - Struct containing variables accessed by shared code
4702 *****************************************************************************/
4703static void
4704e1000_standby_eeprom(struct e1000_hw *hw)
4705{
4706 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4707 uint32_t eecd;
4708
4709 eecd = E1000_READ_REG(hw, EECD);
4710
Auke Kok8fc897b2006-08-28 14:56:16 -07004711 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4713 E1000_WRITE_REG(hw, EECD, eecd);
4714 E1000_WRITE_FLUSH(hw);
4715 udelay(eeprom->delay_usec);
4716
4717 /* Clock high */
4718 eecd |= E1000_EECD_SK;
4719 E1000_WRITE_REG(hw, EECD, eecd);
4720 E1000_WRITE_FLUSH(hw);
4721 udelay(eeprom->delay_usec);
4722
4723 /* Select EEPROM */
4724 eecd |= E1000_EECD_CS;
4725 E1000_WRITE_REG(hw, EECD, eecd);
4726 E1000_WRITE_FLUSH(hw);
4727 udelay(eeprom->delay_usec);
4728
4729 /* Clock low */
4730 eecd &= ~E1000_EECD_SK;
4731 E1000_WRITE_REG(hw, EECD, eecd);
4732 E1000_WRITE_FLUSH(hw);
4733 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004734 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 /* Toggle CS to flush commands */
4736 eecd |= E1000_EECD_CS;
4737 E1000_WRITE_REG(hw, EECD, eecd);
4738 E1000_WRITE_FLUSH(hw);
4739 udelay(eeprom->delay_usec);
4740 eecd &= ~E1000_EECD_CS;
4741 E1000_WRITE_REG(hw, EECD, eecd);
4742 E1000_WRITE_FLUSH(hw);
4743 udelay(eeprom->delay_usec);
4744 }
4745}
4746
4747/******************************************************************************
4748 * Terminates a command by inverting the EEPROM's chip select pin
4749 *
4750 * hw - Struct containing variables accessed by shared code
4751 *****************************************************************************/
4752static void
4753e1000_release_eeprom(struct e1000_hw *hw)
4754{
4755 uint32_t eecd;
4756
4757 DEBUGFUNC("e1000_release_eeprom");
4758
4759 eecd = E1000_READ_REG(hw, EECD);
4760
4761 if (hw->eeprom.type == e1000_eeprom_spi) {
4762 eecd |= E1000_EECD_CS; /* Pull CS high */
4763 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4764
4765 E1000_WRITE_REG(hw, EECD, eecd);
4766
4767 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004768 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 /* cleanup eeprom */
4770
4771 /* CS on Microwire is active-high */
4772 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4773
4774 E1000_WRITE_REG(hw, EECD, eecd);
4775
4776 /* Rising edge of clock */
4777 eecd |= E1000_EECD_SK;
4778 E1000_WRITE_REG(hw, EECD, eecd);
4779 E1000_WRITE_FLUSH(hw);
4780 udelay(hw->eeprom.delay_usec);
4781
4782 /* Falling edge of clock */
4783 eecd &= ~E1000_EECD_SK;
4784 E1000_WRITE_REG(hw, EECD, eecd);
4785 E1000_WRITE_FLUSH(hw);
4786 udelay(hw->eeprom.delay_usec);
4787 }
4788
4789 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004790 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 eecd &= ~E1000_EECD_REQ;
4792 E1000_WRITE_REG(hw, EECD, eecd);
4793 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004794
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004795 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796}
4797
4798/******************************************************************************
4799 * Reads a 16 bit word from the EEPROM.
4800 *
4801 * hw - Struct containing variables accessed by shared code
4802 *****************************************************************************/
4803int32_t
4804e1000_spi_eeprom_ready(struct e1000_hw *hw)
4805{
4806 uint16_t retry_count = 0;
4807 uint8_t spi_stat_reg;
4808
4809 DEBUGFUNC("e1000_spi_eeprom_ready");
4810
4811 /* Read "Status Register" repeatedly until the LSB is cleared. The
4812 * EEPROM will signal that the command has been completed by clearing
4813 * bit 0 of the internal status register. If it's not cleared within
4814 * 5 milliseconds, then error out.
4815 */
4816 retry_count = 0;
4817 do {
4818 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4819 hw->eeprom.opcode_bits);
4820 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4821 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4822 break;
4823
4824 udelay(5);
4825 retry_count += 5;
4826
4827 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004828 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829
4830 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4831 * only 0-5mSec on 5V devices)
4832 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004833 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 DEBUGOUT("SPI EEPROM Status error\n");
4835 return -E1000_ERR_EEPROM;
4836 }
4837
4838 return E1000_SUCCESS;
4839}
4840
4841/******************************************************************************
4842 * Reads a 16 bit word from the EEPROM.
4843 *
4844 * hw - Struct containing variables accessed by shared code
4845 * offset - offset of word in the EEPROM to read
4846 * data - word read from the EEPROM
4847 * words - number of words to read
4848 *****************************************************************************/
4849int32_t
4850e1000_read_eeprom(struct e1000_hw *hw,
4851 uint16_t offset,
4852 uint16_t words,
4853 uint16_t *data)
4854{
4855 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4856 uint32_t i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004857 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858
4859 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004860
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 /* A check for invalid values: offset too large, too many words, and not
4862 * enough words.
4863 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004864 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 (words == 0)) {
4866 DEBUGOUT("\"words\" parameter out of bounds\n");
4867 return -E1000_ERR_EEPROM;
4868 }
4869
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004870 /* FLASH reads without acquiring the semaphore are safe */
4871 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004872 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004873 switch (hw->mac_type) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004874 case e1000_80003es2lan:
4875 break;
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004876 default:
4877 /* Prepare the EEPROM for reading */
4878 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4879 return -E1000_ERR_EEPROM;
4880 break;
4881 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004882 }
4883
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004884 if (eeprom->use_eerd == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004885 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4886 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4887 (hw->mac_type != e1000_82573))
4888 e1000_release_eeprom(hw);
4889 return ret_val;
4890 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891
Auke Kokcd94dd02006-06-27 09:08:22 -07004892 if (eeprom->type == e1000_eeprom_ich8)
4893 return e1000_read_eeprom_ich8(hw, offset, words, data);
4894
4895 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 uint16_t word_in;
4897 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4898
Auke Kok8fc897b2006-08-28 14:56:16 -07004899 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 e1000_release_eeprom(hw);
4901 return -E1000_ERR_EEPROM;
4902 }
4903
4904 e1000_standby_eeprom(hw);
4905
4906 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07004907 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 read_opcode |= EEPROM_A8_OPCODE_SPI;
4909
4910 /* Send the READ command (opcode + addr) */
4911 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4912 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4913
4914 /* Read the data. The address of the eeprom internally increments with
4915 * each byte (spi) being read, saving on the overhead of eeprom setup
4916 * and tear-down. The address counter will roll over if reading beyond
4917 * the size of the eeprom, thus allowing the entire memory to be read
4918 * starting from any offset. */
4919 for (i = 0; i < words; i++) {
4920 word_in = e1000_shift_in_ee_bits(hw, 16);
4921 data[i] = (word_in >> 8) | (word_in << 8);
4922 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004923 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 for (i = 0; i < words; i++) {
4925 /* Send the READ command (opcode + addr) */
4926 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4927 eeprom->opcode_bits);
4928 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4929 eeprom->address_bits);
4930
4931 /* Read the data. For microwire, each word requires the overhead
4932 * of eeprom setup and tear-down. */
4933 data[i] = e1000_shift_in_ee_bits(hw, 16);
4934 e1000_standby_eeprom(hw);
4935 }
4936 }
4937
4938 /* End this read operation */
4939 e1000_release_eeprom(hw);
4940
4941 return E1000_SUCCESS;
4942}
4943
4944/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004945 * Reads a 16 bit word from the EEPROM using the EERD register.
4946 *
4947 * hw - Struct containing variables accessed by shared code
4948 * offset - offset of word in the EEPROM to read
4949 * data - word read from the EEPROM
4950 * words - number of words to read
4951 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004952static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004953e1000_read_eeprom_eerd(struct e1000_hw *hw,
4954 uint16_t offset,
4955 uint16_t words,
4956 uint16_t *data)
4957{
4958 uint32_t i, eerd = 0;
4959 int32_t error = 0;
4960
4961 for (i = 0; i < words; i++) {
4962 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4963 E1000_EEPROM_RW_REG_START;
4964
4965 E1000_WRITE_REG(hw, EERD, eerd);
4966 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07004967
Auke Kok8fc897b2006-08-28 14:56:16 -07004968 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004969 break;
4970 }
4971 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07004972
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004973 }
Auke Kok76c224b2006-05-23 13:36:06 -07004974
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004975 return error;
4976}
4977
4978/******************************************************************************
4979 * Writes a 16 bit word from the EEPROM using the EEWR register.
4980 *
4981 * hw - Struct containing variables accessed by shared code
4982 * offset - offset of word in the EEPROM to read
4983 * data - word read from the EEPROM
4984 * words - number of words to read
4985 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004986static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004987e1000_write_eeprom_eewr(struct e1000_hw *hw,
4988 uint16_t offset,
4989 uint16_t words,
4990 uint16_t *data)
4991{
4992 uint32_t register_value = 0;
4993 uint32_t i = 0;
4994 int32_t error = 0;
4995
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004996 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4997 return -E1000_ERR_SWFW_SYNC;
4998
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004999 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005000 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5001 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005002 E1000_EEPROM_RW_REG_START;
5003
5004 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005005 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005006 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005007 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005008
5009 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005010
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005011 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005012
Auke Kok8fc897b2006-08-28 14:56:16 -07005013 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005014 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005015 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005016 }
Auke Kok76c224b2006-05-23 13:36:06 -07005017
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005018 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005019 return error;
5020}
5021
5022/******************************************************************************
5023 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5024 *
5025 * hw - Struct containing variables accessed by shared code
5026 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005027static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005028e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5029{
5030 uint32_t attempts = 100000;
5031 uint32_t i, reg = 0;
5032 int32_t done = E1000_ERR_EEPROM;
5033
Auke Kok8fc897b2006-08-28 14:56:16 -07005034 for (i = 0; i < attempts; i++) {
5035 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005036 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005037 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005038 reg = E1000_READ_REG(hw, EEWR);
5039
Auke Kok8fc897b2006-08-28 14:56:16 -07005040 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005041 done = E1000_SUCCESS;
5042 break;
5043 }
5044 udelay(5);
5045 }
5046
5047 return done;
5048}
5049
5050/***************************************************************************
5051* Description: Determines if the onboard NVM is FLASH or EEPROM.
5052*
5053* hw - Struct containing variables accessed by shared code
5054****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005055static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005056e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5057{
5058 uint32_t eecd = 0;
5059
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005060 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5061
Auke Kokcd94dd02006-06-27 09:08:22 -07005062 if (hw->mac_type == e1000_ich8lan)
5063 return FALSE;
5064
5065 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005066 eecd = E1000_READ_REG(hw, EECD);
5067
5068 /* Isolate bits 15 & 16 */
5069 eecd = ((eecd >> 15) & 0x03);
5070
5071 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005072 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005073 return FALSE;
5074 }
5075 }
5076 return TRUE;
5077}
5078
5079/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 * Verifies that the EEPROM has a valid checksum
5081 *
5082 * hw - Struct containing variables accessed by shared code
5083 *
5084 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5085 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5086 * valid.
5087 *****************************************************************************/
5088int32_t
5089e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5090{
5091 uint16_t checksum = 0;
5092 uint16_t i, eeprom_data;
5093
5094 DEBUGFUNC("e1000_validate_eeprom_checksum");
5095
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005096 if ((hw->mac_type == e1000_82573) &&
5097 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5098 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5099 * 10h-12h. Checksum may need to be fixed. */
5100 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5101 if ((eeprom_data & 0x10) == 0) {
5102 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5103 * has already been fixed. If the checksum is still wrong and this
5104 * bit is a 1, we need to return bad checksum. Otherwise, we need
5105 * to set this bit to a 1 and update the checksum. */
5106 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5107 if ((eeprom_data & 0x8000) == 0) {
5108 eeprom_data |= 0x8000;
5109 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5110 e1000_update_eeprom_checksum(hw);
5111 }
5112 }
5113 }
5114
Auke Kokcd94dd02006-06-27 09:08:22 -07005115 if (hw->mac_type == e1000_ich8lan) {
5116 /* Drivers must allocate the shadow ram structure for the
5117 * EEPROM checksum to be updated. Otherwise, this bit as well
5118 * as the checksum must both be set correctly for this
5119 * validation to pass.
5120 */
5121 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5122 if ((eeprom_data & 0x40) == 0) {
5123 eeprom_data |= 0x40;
5124 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5125 e1000_update_eeprom_checksum(hw);
5126 }
5127 }
5128
5129 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5130 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 DEBUGOUT("EEPROM Read Error\n");
5132 return -E1000_ERR_EEPROM;
5133 }
5134 checksum += eeprom_data;
5135 }
5136
Auke Kok8fc897b2006-08-28 14:56:16 -07005137 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 return E1000_SUCCESS;
5139 else {
5140 DEBUGOUT("EEPROM Checksum Invalid\n");
5141 return -E1000_ERR_EEPROM;
5142 }
5143}
5144
5145/******************************************************************************
5146 * Calculates the EEPROM checksum and writes it to the EEPROM
5147 *
5148 * hw - Struct containing variables accessed by shared code
5149 *
5150 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5151 * Writes the difference to word offset 63 of the EEPROM.
5152 *****************************************************************************/
5153int32_t
5154e1000_update_eeprom_checksum(struct e1000_hw *hw)
5155{
Auke Kokcd94dd02006-06-27 09:08:22 -07005156 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 uint16_t checksum = 0;
5158 uint16_t i, eeprom_data;
5159
5160 DEBUGFUNC("e1000_update_eeprom_checksum");
5161
Auke Kok8fc897b2006-08-28 14:56:16 -07005162 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5163 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 DEBUGOUT("EEPROM Read Error\n");
5165 return -E1000_ERR_EEPROM;
5166 }
5167 checksum += eeprom_data;
5168 }
5169 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005170 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 DEBUGOUT("EEPROM Write Error\n");
5172 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005173 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5174 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005175 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5176 e1000_commit_shadow_ram(hw);
5177 /* Reload the EEPROM, or else modifications will not appear
5178 * until after next adapter reset. */
5179 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5180 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5181 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005182 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 }
5184 return E1000_SUCCESS;
5185}
5186
5187/******************************************************************************
5188 * Parent function for writing words to the different EEPROM types.
5189 *
5190 * hw - Struct containing variables accessed by shared code
5191 * offset - offset within the EEPROM to be written to
5192 * words - number of words to write
5193 * data - 16 bit word to be written to the EEPROM
5194 *
5195 * If e1000_update_eeprom_checksum is not called after this function, the
5196 * EEPROM will most likely contain an invalid checksum.
5197 *****************************************************************************/
5198int32_t
5199e1000_write_eeprom(struct e1000_hw *hw,
5200 uint16_t offset,
5201 uint16_t words,
5202 uint16_t *data)
5203{
5204 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5205 int32_t status = 0;
5206
5207 DEBUGFUNC("e1000_write_eeprom");
5208
5209 /* A check for invalid values: offset too large, too many words, and not
5210 * enough words.
5211 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005212 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213 (words == 0)) {
5214 DEBUGOUT("\"words\" parameter out of bounds\n");
5215 return -E1000_ERR_EEPROM;
5216 }
5217
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005218 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005219 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005220 return e1000_write_eeprom_eewr(hw, offset, words, data);
5221
Auke Kokcd94dd02006-06-27 09:08:22 -07005222 if (eeprom->type == e1000_eeprom_ich8)
5223 return e1000_write_eeprom_ich8(hw, offset, words, data);
5224
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225 /* Prepare the EEPROM for writing */
5226 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5227 return -E1000_ERR_EEPROM;
5228
Auke Kok8fc897b2006-08-28 14:56:16 -07005229 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5231 } else {
5232 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005233 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 }
5235
5236 /* Done with writing */
5237 e1000_release_eeprom(hw);
5238
5239 return status;
5240}
5241
5242/******************************************************************************
5243 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5244 *
5245 * hw - Struct containing variables accessed by shared code
5246 * offset - offset within the EEPROM to be written to
5247 * words - number of words to write
5248 * data - pointer to array of 8 bit words to be written to the EEPROM
5249 *
5250 *****************************************************************************/
5251int32_t
5252e1000_write_eeprom_spi(struct e1000_hw *hw,
5253 uint16_t offset,
5254 uint16_t words,
5255 uint16_t *data)
5256{
5257 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5258 uint16_t widx = 0;
5259
5260 DEBUGFUNC("e1000_write_eeprom_spi");
5261
5262 while (widx < words) {
5263 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5264
Auke Kok8fc897b2006-08-28 14:56:16 -07005265 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266
5267 e1000_standby_eeprom(hw);
5268
5269 /* Send the WRITE ENABLE command (8 bit opcode ) */
5270 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5271 eeprom->opcode_bits);
5272
5273 e1000_standby_eeprom(hw);
5274
5275 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005276 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 write_opcode |= EEPROM_A8_OPCODE_SPI;
5278
5279 /* Send the Write command (8-bit opcode + addr) */
5280 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5281
5282 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5283 eeprom->address_bits);
5284
5285 /* Send the data */
5286
5287 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5288 while (widx < words) {
5289 uint16_t word_out = data[widx];
5290 word_out = (word_out >> 8) | (word_out << 8);
5291 e1000_shift_out_ee_bits(hw, word_out, 16);
5292 widx++;
5293
5294 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5295 * operation, while the smaller eeproms are capable of an 8-byte
5296 * PAGE WRITE operation. Break the inner loop to pass new address
5297 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005298 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 e1000_standby_eeprom(hw);
5300 break;
5301 }
5302 }
5303 }
5304
5305 return E1000_SUCCESS;
5306}
5307
5308/******************************************************************************
5309 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5310 *
5311 * hw - Struct containing variables accessed by shared code
5312 * offset - offset within the EEPROM to be written to
5313 * words - number of words to write
5314 * data - pointer to array of 16 bit words to be written to the EEPROM
5315 *
5316 *****************************************************************************/
5317int32_t
5318e1000_write_eeprom_microwire(struct e1000_hw *hw,
5319 uint16_t offset,
5320 uint16_t words,
5321 uint16_t *data)
5322{
5323 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5324 uint32_t eecd;
5325 uint16_t words_written = 0;
5326 uint16_t i = 0;
5327
5328 DEBUGFUNC("e1000_write_eeprom_microwire");
5329
5330 /* Send the write enable command to the EEPROM (3-bit opcode plus
5331 * 6/8-bit dummy address beginning with 11). It's less work to include
5332 * the 11 of the dummy address as part of the opcode than it is to shift
5333 * it over the correct number of bits for the address. This puts the
5334 * EEPROM into write/erase mode.
5335 */
5336 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5337 (uint16_t)(eeprom->opcode_bits + 2));
5338
5339 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5340
5341 /* Prepare the EEPROM */
5342 e1000_standby_eeprom(hw);
5343
5344 while (words_written < words) {
5345 /* Send the Write command (3-bit opcode + addr) */
5346 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5347 eeprom->opcode_bits);
5348
5349 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5350 eeprom->address_bits);
5351
5352 /* Send the data */
5353 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5354
5355 /* Toggle the CS line. This in effect tells the EEPROM to execute
5356 * the previous command.
5357 */
5358 e1000_standby_eeprom(hw);
5359
5360 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5361 * signal that the command has been completed by raising the DO signal.
5362 * If DO does not go high in 10 milliseconds, then error out.
5363 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005364 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005366 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367 udelay(50);
5368 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005369 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370 DEBUGOUT("EEPROM Write did not complete\n");
5371 return -E1000_ERR_EEPROM;
5372 }
5373
5374 /* Recover from write */
5375 e1000_standby_eeprom(hw);
5376
5377 words_written++;
5378 }
5379
5380 /* Send the write disable command to the EEPROM (3-bit opcode plus
5381 * 6/8-bit dummy address beginning with 10). It's less work to include
5382 * the 10 of the dummy address as part of the opcode than it is to shift
5383 * it over the correct number of bits for the address. This takes the
5384 * EEPROM out of write/erase mode.
5385 */
5386 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5387 (uint16_t)(eeprom->opcode_bits + 2));
5388
5389 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5390
5391 return E1000_SUCCESS;
5392}
5393
5394/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005395 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5396 * in the eeprom cache and the non modified values in the currently active bank
5397 * to the new bank.
5398 *
5399 * hw - Struct containing variables accessed by shared code
5400 * offset - offset of word in the EEPROM to read
5401 * data - word read from the EEPROM
5402 * words - number of words to read
5403 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005404static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005405e1000_commit_shadow_ram(struct e1000_hw *hw)
5406{
5407 uint32_t attempts = 100000;
5408 uint32_t eecd = 0;
5409 uint32_t flop = 0;
5410 uint32_t i = 0;
5411 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005412 uint32_t old_bank_offset = 0;
5413 uint32_t new_bank_offset = 0;
5414 uint32_t sector_retries = 0;
5415 uint8_t low_byte = 0;
5416 uint8_t high_byte = 0;
5417 uint8_t temp_byte = 0;
5418 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005419
5420 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005421 /* The flop register will be used to determine if flash type is STM */
5422 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005423 for (i=0; i < attempts; i++) {
5424 eecd = E1000_READ_REG(hw, EECD);
5425 if ((eecd & E1000_EECD_FLUPD) == 0) {
5426 break;
5427 }
5428 udelay(5);
5429 }
5430
5431 if (i == attempts) {
5432 return -E1000_ERR_EEPROM;
5433 }
5434
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005435 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005436 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5437 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5438 }
5439
5440 /* Perform the flash update */
5441 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5442
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005443 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005444 eecd = E1000_READ_REG(hw, EECD);
5445 if ((eecd & E1000_EECD_FLUPD) == 0) {
5446 break;
5447 }
5448 udelay(5);
5449 }
5450
5451 if (i == attempts) {
5452 return -E1000_ERR_EEPROM;
5453 }
5454 }
5455
Auke Kokcd94dd02006-06-27 09:08:22 -07005456 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5457 /* We're writing to the opposite bank so if we're on bank 1,
5458 * write to bank 0 etc. We also need to erase the segment that
5459 * is going to be written */
5460 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5461 new_bank_offset = hw->flash_bank_size * 2;
5462 old_bank_offset = 0;
5463 e1000_erase_ich8_4k_segment(hw, 1);
5464 } else {
5465 old_bank_offset = hw->flash_bank_size * 2;
5466 new_bank_offset = 0;
5467 e1000_erase_ich8_4k_segment(hw, 0);
5468 }
5469
5470 do {
5471 sector_write_failed = FALSE;
5472 /* Loop for every byte in the shadow RAM,
5473 * which is in units of words. */
5474 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5475 /* Determine whether to write the value stored
5476 * in the other NVM bank or a modified value stored
5477 * in the shadow RAM */
5478 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5479 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5480 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5481 &temp_byte);
5482 udelay(100);
5483 error = e1000_verify_write_ich8_byte(hw,
5484 (i << 1) + new_bank_offset,
5485 low_byte);
5486 if (error != E1000_SUCCESS)
5487 sector_write_failed = TRUE;
5488 high_byte =
5489 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5490 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5491 &temp_byte);
5492 udelay(100);
5493 } else {
5494 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5495 &low_byte);
5496 udelay(100);
5497 error = e1000_verify_write_ich8_byte(hw,
5498 (i << 1) + new_bank_offset, low_byte);
5499 if (error != E1000_SUCCESS)
5500 sector_write_failed = TRUE;
5501 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5502 &high_byte);
5503 }
5504
5505 /* If the word is 0x13, then make sure the signature bits
5506 * (15:14) are 11b until the commit has completed.
5507 * This will allow us to write 10b which indicates the
5508 * signature is valid. We want to do this after the write
5509 * has completed so that we don't mark the segment valid
5510 * while the write is still in progress */
5511 if (i == E1000_ICH8_NVM_SIG_WORD)
5512 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5513
5514 error = e1000_verify_write_ich8_byte(hw,
5515 (i << 1) + new_bank_offset + 1, high_byte);
5516 if (error != E1000_SUCCESS)
5517 sector_write_failed = TRUE;
5518
5519 if (sector_write_failed == FALSE) {
5520 /* Clear the now not used entry in the cache */
5521 hw->eeprom_shadow_ram[i].modified = FALSE;
5522 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5523 }
5524 }
5525
5526 /* Don't bother writing the segment valid bits if sector
5527 * programming failed. */
5528 if (sector_write_failed == FALSE) {
5529 /* Finally validate the new segment by setting bit 15:14
5530 * to 10b in word 0x13 , this can be done without an
5531 * erase as well since these bits are 11 to start with
5532 * and we need to change bit 14 to 0b */
5533 e1000_read_ich8_byte(hw,
5534 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5535 &high_byte);
5536 high_byte &= 0xBF;
5537 error = e1000_verify_write_ich8_byte(hw,
5538 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5539 high_byte);
5540 if (error != E1000_SUCCESS)
5541 sector_write_failed = TRUE;
5542
5543 /* And invalidate the previously valid segment by setting
5544 * its signature word (0x13) high_byte to 0b. This can be
5545 * done without an erase because flash erase sets all bits
5546 * to 1's. We can write 1's to 0's without an erase */
5547 error = e1000_verify_write_ich8_byte(hw,
5548 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5549 0);
5550 if (error != E1000_SUCCESS)
5551 sector_write_failed = TRUE;
5552 }
5553 } while (++sector_retries < 10 && sector_write_failed == TRUE);
5554 }
5555
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005556 return error;
5557}
5558
5559/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005560 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5561 * second function of dual function devices
5562 *
5563 * hw - Struct containing variables accessed by shared code
5564 *****************************************************************************/
5565int32_t
5566e1000_read_mac_addr(struct e1000_hw * hw)
5567{
5568 uint16_t offset;
5569 uint16_t eeprom_data, i;
5570
5571 DEBUGFUNC("e1000_read_mac_addr");
5572
Auke Kok8fc897b2006-08-28 14:56:16 -07005573 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005575 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 DEBUGOUT("EEPROM Read Error\n");
5577 return -E1000_ERR_EEPROM;
5578 }
5579 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5580 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5581 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005582
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005583 switch (hw->mac_type) {
5584 default:
5585 break;
5586 case e1000_82546:
5587 case e1000_82546_rev_3:
5588 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005589 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005590 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005591 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005592 break;
5593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594
Auke Kok8fc897b2006-08-28 14:56:16 -07005595 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596 hw->mac_addr[i] = hw->perm_mac_addr[i];
5597 return E1000_SUCCESS;
5598}
5599
5600/******************************************************************************
5601 * Initializes receive address filters.
5602 *
5603 * hw - Struct containing variables accessed by shared code
5604 *
5605 * Places the MAC address in receive address register 0 and clears the rest
5606 * of the receive addresss registers. Clears the multicast table. Assumes
5607 * the receiver is in reset when the routine is called.
5608 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005609static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610e1000_init_rx_addrs(struct e1000_hw *hw)
5611{
5612 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005613 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614
5615 DEBUGFUNC("e1000_init_rx_addrs");
5616
5617 /* Setup the receive address. */
5618 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5619
5620 e1000_rar_set(hw, hw->mac_addr, 0);
5621
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005622 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005623
5624 /* Reserve a spot for the Locally Administered Address to work around
5625 * an 82571 issue in which a reset on one port will reload the MAC on
5626 * the other port. */
5627 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5628 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005629 if (hw->mac_type == e1000_ich8lan)
5630 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5631
Linus Torvalds1da177e2005-04-16 15:20:36 -07005632 /* Zero out the other 15 receive addresses. */
5633 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005634 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005636 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005638 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639 }
5640}
5641
5642/******************************************************************************
5643 * Updates the MAC's list of multicast addresses.
5644 *
5645 * hw - Struct containing variables accessed by shared code
5646 * mc_addr_list - the list of new multicast addresses
5647 * mc_addr_count - number of addresses
5648 * pad - number of bytes between addresses in the list
5649 * rar_used_count - offset where to start adding mc addresses into the RAR's
5650 *
5651 * The given list replaces any existing list. Clears the last 15 receive
5652 * address registers and the multicast table. Uses receive address registers
5653 * for the first 15 multicast addresses, and hashes the rest into the
5654 * multicast table.
5655 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07005656#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07005657void
5658e1000_mc_addr_list_update(struct e1000_hw *hw,
5659 uint8_t *mc_addr_list,
5660 uint32_t mc_addr_count,
5661 uint32_t pad,
5662 uint32_t rar_used_count)
5663{
5664 uint32_t hash_value;
5665 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005666 uint32_t num_rar_entry;
5667 uint32_t num_mta_entry;
Auke Kok76c224b2006-05-23 13:36:06 -07005668
Linus Torvalds1da177e2005-04-16 15:20:36 -07005669 DEBUGFUNC("e1000_mc_addr_list_update");
5670
5671 /* Set the new number of MC addresses that we are being requested to use. */
5672 hw->num_mc_addrs = mc_addr_count;
5673
5674 /* Clear RAR[1-15] */
5675 DEBUGOUT(" Clearing RAR[1-15]\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005676 num_rar_entry = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07005677 if (hw->mac_type == e1000_ich8lan)
5678 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005679 /* Reserve a spot for the Locally Administered Address to work around
5680 * an 82571 issue in which a reset on one port will reload the MAC on
5681 * the other port. */
5682 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5683 num_rar_entry -= 1;
5684
Auke Kok8fc897b2006-08-28 14:56:16 -07005685 for (i = rar_used_count; i < num_rar_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005687 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005689 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005690 }
5691
5692 /* Clear the MTA */
5693 DEBUGOUT(" Clearing MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005694 num_mta_entry = E1000_NUM_MTA_REGISTERS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005695 if (hw->mac_type == e1000_ich8lan)
5696 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -07005697 for (i = 0; i < num_mta_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005698 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005699 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 }
5701
5702 /* Add the new addresses */
Auke Kok8fc897b2006-08-28 14:56:16 -07005703 for (i = 0; i < mc_addr_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704 DEBUGOUT(" Adding the multicast addresses:\n");
5705 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5706 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5707 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5708 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5709 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5710 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5711 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5712
5713 hash_value = e1000_hash_mc_addr(hw,
5714 mc_addr_list +
5715 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5716
5717 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5718
5719 /* Place this multicast address in the RAR if there is room, *
5720 * else put it in the MTA
5721 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005722 if (rar_used_count < num_rar_entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 e1000_rar_set(hw,
5724 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5725 rar_used_count);
5726 rar_used_count++;
5727 } else {
5728 e1000_mta_set(hw, hash_value);
5729 }
5730 }
5731 DEBUGOUT("MC Update Complete\n");
5732}
Adrian Bunke4c780b2006-08-14 23:00:10 -07005733#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734
5735/******************************************************************************
5736 * Hashes an address to determine its location in the multicast table
5737 *
5738 * hw - Struct containing variables accessed by shared code
5739 * mc_addr - the multicast address to hash
5740 *****************************************************************************/
5741uint32_t
5742e1000_hash_mc_addr(struct e1000_hw *hw,
5743 uint8_t *mc_addr)
5744{
5745 uint32_t hash_value = 0;
5746
5747 /* The portion of the address that is used for the hash table is
5748 * determined by the mc_filter_type setting.
5749 */
5750 switch (hw->mc_filter_type) {
5751 /* [0] [1] [2] [3] [4] [5]
5752 * 01 AA 00 12 34 56
5753 * LSB MSB
5754 */
5755 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005756 if (hw->mac_type == e1000_ich8lan) {
5757 /* [47:38] i.e. 0x158 for above example address */
5758 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5759 } else {
5760 /* [47:36] i.e. 0x563 for above example address */
5761 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 break;
5764 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005765 if (hw->mac_type == e1000_ich8lan) {
5766 /* [46:37] i.e. 0x2B1 for above example address */
5767 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5768 } else {
5769 /* [46:35] i.e. 0xAC6 for above example address */
5770 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772 break;
5773 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005774 if (hw->mac_type == e1000_ich8lan) {
5775 /*[45:36] i.e. 0x163 for above example address */
5776 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5777 } else {
5778 /* [45:34] i.e. 0x5D8 for above example address */
5779 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005781 break;
5782 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005783 if (hw->mac_type == e1000_ich8lan) {
5784 /* [43:34] i.e. 0x18D for above example address */
5785 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5786 } else {
5787 /* [43:32] i.e. 0x634 for above example address */
5788 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 break;
5791 }
5792
5793 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005794 if (hw->mac_type == e1000_ich8lan)
5795 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005796
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797 return hash_value;
5798}
5799
5800/******************************************************************************
5801 * Sets the bit in the multicast table corresponding to the hash value.
5802 *
5803 * hw - Struct containing variables accessed by shared code
5804 * hash_value - Multicast address hash value
5805 *****************************************************************************/
5806void
5807e1000_mta_set(struct e1000_hw *hw,
5808 uint32_t hash_value)
5809{
5810 uint32_t hash_bit, hash_reg;
5811 uint32_t mta;
5812 uint32_t temp;
5813
5814 /* The MTA is a register array of 128 32-bit registers.
5815 * It is treated like an array of 4096 bits. We want to set
5816 * bit BitArray[hash_value]. So we figure out what register
5817 * the bit is in, read it, OR in the new bit, then write
5818 * back the new value. The register is determined by the
5819 * upper 7 bits of the hash value and the bit within that
5820 * register are determined by the lower 5 bits of the value.
5821 */
5822 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005823 if (hw->mac_type == e1000_ich8lan)
5824 hash_reg &= 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 hash_bit = hash_value & 0x1F;
5826
5827 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5828
5829 mta |= (1 << hash_bit);
5830
5831 /* If we are on an 82544 and we are trying to write an odd offset
5832 * in the MTA, save off the previous entry before writing and
5833 * restore the old value after writing.
5834 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005835 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5837 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005838 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005840 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841 } else {
5842 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005843 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 }
5845}
5846
5847/******************************************************************************
5848 * Puts an ethernet address into a receive address register.
5849 *
5850 * hw - Struct containing variables accessed by shared code
5851 * addr - Address to put into receive address register
5852 * index - Receive address register to write
5853 *****************************************************************************/
5854void
5855e1000_rar_set(struct e1000_hw *hw,
5856 uint8_t *addr,
5857 uint32_t index)
5858{
5859 uint32_t rar_low, rar_high;
5860
5861 /* HW expects these in little endian so we reverse the byte order
5862 * from network order (big endian) to little endian
5863 */
5864 rar_low = ((uint32_t) addr[0] |
5865 ((uint32_t) addr[1] << 8) |
5866 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005867 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005869 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5870 * unit hang.
5871 *
5872 * Description:
5873 * If there are any Rx frames queued up or otherwise present in the HW
5874 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5875 * hang. To work around this issue, we have to disable receives and
5876 * flush out all Rx frames before we enable RSS. To do so, we modify we
5877 * redirect all Rx traffic to manageability and then reset the HW.
5878 * This flushes away Rx frames, and (since the redirections to
5879 * manageability persists across resets) keeps new ones from coming in
5880 * while we work. Then, we clear the Address Valid AV bit for all MAC
5881 * addresses and undo the re-direction to manageability.
5882 * Now, frames are coming in again, but the MAC won't accept them, so
5883 * far so good. We now proceed to initialize RSS (if necessary) and
5884 * configure the Rx unit. Last, we re-enable the AV bits and continue
5885 * on our merry way.
5886 */
5887 switch (hw->mac_type) {
5888 case e1000_82571:
5889 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005890 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005891 if (hw->leave_av_bit_off == TRUE)
5892 break;
5893 default:
5894 /* Indicate to hardware the Address is Valid. */
5895 rar_high |= E1000_RAH_AV;
5896 break;
5897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898
5899 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005900 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005902 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903}
5904
5905/******************************************************************************
5906 * Writes a value to the specified offset in the VLAN filter table.
5907 *
5908 * hw - Struct containing variables accessed by shared code
5909 * offset - Offset in VLAN filer table to write
5910 * value - Value to write into VLAN filter table
5911 *****************************************************************************/
5912void
5913e1000_write_vfta(struct e1000_hw *hw,
5914 uint32_t offset,
5915 uint32_t value)
5916{
5917 uint32_t temp;
5918
Auke Kokcd94dd02006-06-27 09:08:22 -07005919 if (hw->mac_type == e1000_ich8lan)
5920 return;
5921
5922 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5924 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005925 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005927 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928 } else {
5929 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005930 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 }
5932}
5933
5934/******************************************************************************
5935 * Clears the VLAN filer table
5936 *
5937 * hw - Struct containing variables accessed by shared code
5938 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005939static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940e1000_clear_vfta(struct e1000_hw *hw)
5941{
5942 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005943 uint32_t vfta_value = 0;
5944 uint32_t vfta_offset = 0;
5945 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946
Auke Kokcd94dd02006-06-27 09:08:22 -07005947 if (hw->mac_type == e1000_ich8lan)
5948 return;
5949
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005950 if (hw->mac_type == e1000_82573) {
5951 if (hw->mng_cookie.vlan_id != 0) {
5952 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5953 * ID. The following operations determine which 32b entry
5954 * (i.e. offset) into the array we want to set the VLAN ID
5955 * (i.e. bit) of the manageability unit. */
5956 vfta_offset = (hw->mng_cookie.vlan_id >>
5957 E1000_VFTA_ENTRY_SHIFT) &
5958 E1000_VFTA_ENTRY_MASK;
5959 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5960 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5961 }
5962 }
5963 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5964 /* If the offset we want to clear is the same offset of the
5965 * manageability VLAN ID, then clear all bits except that of the
5966 * manageability unit */
5967 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5968 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005969 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005970 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971}
5972
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005973static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974e1000_id_led_init(struct e1000_hw * hw)
5975{
5976 uint32_t ledctl;
5977 const uint32_t ledctl_mask = 0x000000FF;
5978 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5979 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5980 uint16_t eeprom_data, i, temp;
5981 const uint16_t led_mask = 0x0F;
5982
5983 DEBUGFUNC("e1000_id_led_init");
5984
Auke Kok8fc897b2006-08-28 14:56:16 -07005985 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 /* Nothing to do */
5987 return E1000_SUCCESS;
5988 }
5989
5990 ledctl = E1000_READ_REG(hw, LEDCTL);
5991 hw->ledctl_default = ledctl;
5992 hw->ledctl_mode1 = hw->ledctl_default;
5993 hw->ledctl_mode2 = hw->ledctl_default;
5994
Auke Kok8fc897b2006-08-28 14:56:16 -07005995 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996 DEBUGOUT("EEPROM Read Error\n");
5997 return -E1000_ERR_EEPROM;
5998 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005999
6000 if ((hw->mac_type == e1000_82573) &&
6001 (eeprom_data == ID_LED_RESERVED_82573))
6002 eeprom_data = ID_LED_DEFAULT_82573;
6003 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6004 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6005 if (hw->mac_type == e1000_ich8lan)
6006 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6007 else
6008 eeprom_data = ID_LED_DEFAULT;
6009 }
6010 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006012 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 case ID_LED_ON1_DEF2:
6014 case ID_LED_ON1_ON2:
6015 case ID_LED_ON1_OFF2:
6016 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6017 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6018 break;
6019 case ID_LED_OFF1_DEF2:
6020 case ID_LED_OFF1_ON2:
6021 case ID_LED_OFF1_OFF2:
6022 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6023 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6024 break;
6025 default:
6026 /* Do nothing */
6027 break;
6028 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006029 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 case ID_LED_DEF1_ON2:
6031 case ID_LED_ON1_ON2:
6032 case ID_LED_OFF1_ON2:
6033 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6034 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6035 break;
6036 case ID_LED_DEF1_OFF2:
6037 case ID_LED_ON1_OFF2:
6038 case ID_LED_OFF1_OFF2:
6039 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6040 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6041 break;
6042 default:
6043 /* Do nothing */
6044 break;
6045 }
6046 }
6047 return E1000_SUCCESS;
6048}
6049
6050/******************************************************************************
6051 * Prepares SW controlable LED for use and saves the current state of the LED.
6052 *
6053 * hw - Struct containing variables accessed by shared code
6054 *****************************************************************************/
6055int32_t
6056e1000_setup_led(struct e1000_hw *hw)
6057{
6058 uint32_t ledctl;
6059 int32_t ret_val = E1000_SUCCESS;
6060
6061 DEBUGFUNC("e1000_setup_led");
6062
Auke Kok8fc897b2006-08-28 14:56:16 -07006063 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 case e1000_82542_rev2_0:
6065 case e1000_82542_rev2_1:
6066 case e1000_82543:
6067 case e1000_82544:
6068 /* No setup necessary */
6069 break;
6070 case e1000_82541:
6071 case e1000_82547:
6072 case e1000_82541_rev_2:
6073 case e1000_82547_rev_2:
6074 /* Turn off PHY Smart Power Down (if enabled) */
6075 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6076 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006077 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 return ret_val;
6079 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6080 (uint16_t)(hw->phy_spd_default &
6081 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006082 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 return ret_val;
6084 /* Fall Through */
6085 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006086 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 ledctl = E1000_READ_REG(hw, LEDCTL);
6088 /* Save current LEDCTL settings */
6089 hw->ledctl_default = ledctl;
6090 /* Turn off LED0 */
6091 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6092 E1000_LEDCTL_LED0_BLINK |
6093 E1000_LEDCTL_LED0_MODE_MASK);
6094 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6095 E1000_LEDCTL_LED0_MODE_SHIFT);
6096 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006097 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6099 break;
6100 }
6101
6102 return E1000_SUCCESS;
6103}
6104
Auke Kok8fc897b2006-08-28 14:56:16 -07006105
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006107 * Used on 82571 and later Si that has LED blink bits.
6108 * Callers must use their own timer and should have already called
6109 * e1000_id_led_init()
6110 * Call e1000_cleanup led() to stop blinking
6111 *
6112 * hw - Struct containing variables accessed by shared code
6113 *****************************************************************************/
6114int32_t
6115e1000_blink_led_start(struct e1000_hw *hw)
6116{
6117 int16_t i;
6118 uint32_t ledctl_blink = 0;
6119
6120 DEBUGFUNC("e1000_id_led_blink_on");
6121
6122 if (hw->mac_type < e1000_82571) {
6123 /* Nothing to do */
6124 return E1000_SUCCESS;
6125 }
6126 if (hw->media_type == e1000_media_type_fiber) {
6127 /* always blink LED0 for PCI-E fiber */
6128 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6129 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6130 } else {
6131 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6132 ledctl_blink = hw->ledctl_mode2;
6133 for (i=0; i < 4; i++)
6134 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6135 E1000_LEDCTL_MODE_LED_ON)
6136 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6137 }
6138
6139 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6140
6141 return E1000_SUCCESS;
6142}
6143
6144/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 * Restores the saved state of the SW controlable LED.
6146 *
6147 * hw - Struct containing variables accessed by shared code
6148 *****************************************************************************/
6149int32_t
6150e1000_cleanup_led(struct e1000_hw *hw)
6151{
6152 int32_t ret_val = E1000_SUCCESS;
6153
6154 DEBUGFUNC("e1000_cleanup_led");
6155
Auke Kok8fc897b2006-08-28 14:56:16 -07006156 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 case e1000_82542_rev2_0:
6158 case e1000_82542_rev2_1:
6159 case e1000_82543:
6160 case e1000_82544:
6161 /* No cleanup necessary */
6162 break;
6163 case e1000_82541:
6164 case e1000_82547:
6165 case e1000_82541_rev_2:
6166 case e1000_82547_rev_2:
6167 /* Turn on PHY Smart Power Down (if previously enabled) */
6168 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6169 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006170 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 return ret_val;
6172 /* Fall Through */
6173 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006174 if (hw->phy_type == e1000_phy_ife) {
6175 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6176 break;
6177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 /* Restore LEDCTL settings */
6179 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6180 break;
6181 }
6182
6183 return E1000_SUCCESS;
6184}
6185
6186/******************************************************************************
6187 * Turns on the software controllable LED
6188 *
6189 * hw - Struct containing variables accessed by shared code
6190 *****************************************************************************/
6191int32_t
6192e1000_led_on(struct e1000_hw *hw)
6193{
6194 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6195
6196 DEBUGFUNC("e1000_led_on");
6197
Auke Kok8fc897b2006-08-28 14:56:16 -07006198 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199 case e1000_82542_rev2_0:
6200 case e1000_82542_rev2_1:
6201 case e1000_82543:
6202 /* Set SW Defineable Pin 0 to turn on the LED */
6203 ctrl |= E1000_CTRL_SWDPIN0;
6204 ctrl |= E1000_CTRL_SWDPIO0;
6205 break;
6206 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006207 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 /* Set SW Defineable Pin 0 to turn on the LED */
6209 ctrl |= E1000_CTRL_SWDPIN0;
6210 ctrl |= E1000_CTRL_SWDPIO0;
6211 } else {
6212 /* Clear SW Defineable Pin 0 to turn on the LED */
6213 ctrl &= ~E1000_CTRL_SWDPIN0;
6214 ctrl |= E1000_CTRL_SWDPIO0;
6215 }
6216 break;
6217 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006218 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 /* Clear SW Defineable Pin 0 to turn on the LED */
6220 ctrl &= ~E1000_CTRL_SWDPIN0;
6221 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006222 } else if (hw->phy_type == e1000_phy_ife) {
6223 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6224 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6225 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6227 return E1000_SUCCESS;
6228 }
6229 break;
6230 }
6231
6232 E1000_WRITE_REG(hw, CTRL, ctrl);
6233
6234 return E1000_SUCCESS;
6235}
6236
6237/******************************************************************************
6238 * Turns off the software controllable LED
6239 *
6240 * hw - Struct containing variables accessed by shared code
6241 *****************************************************************************/
6242int32_t
6243e1000_led_off(struct e1000_hw *hw)
6244{
6245 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6246
6247 DEBUGFUNC("e1000_led_off");
6248
Auke Kok8fc897b2006-08-28 14:56:16 -07006249 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250 case e1000_82542_rev2_0:
6251 case e1000_82542_rev2_1:
6252 case e1000_82543:
6253 /* Clear SW Defineable Pin 0 to turn off the LED */
6254 ctrl &= ~E1000_CTRL_SWDPIN0;
6255 ctrl |= E1000_CTRL_SWDPIO0;
6256 break;
6257 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006258 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259 /* Clear SW Defineable Pin 0 to turn off the LED */
6260 ctrl &= ~E1000_CTRL_SWDPIN0;
6261 ctrl |= E1000_CTRL_SWDPIO0;
6262 } else {
6263 /* Set SW Defineable Pin 0 to turn off the LED */
6264 ctrl |= E1000_CTRL_SWDPIN0;
6265 ctrl |= E1000_CTRL_SWDPIO0;
6266 }
6267 break;
6268 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006269 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 /* Set SW Defineable Pin 0 to turn off the LED */
6271 ctrl |= E1000_CTRL_SWDPIN0;
6272 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006273 } else if (hw->phy_type == e1000_phy_ife) {
6274 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6275 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6276 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6278 return E1000_SUCCESS;
6279 }
6280 break;
6281 }
6282
6283 E1000_WRITE_REG(hw, CTRL, ctrl);
6284
6285 return E1000_SUCCESS;
6286}
6287
6288/******************************************************************************
6289 * Clears all hardware statistics counters.
6290 *
6291 * hw - Struct containing variables accessed by shared code
6292 *****************************************************************************/
Auke Kok8fc897b2006-08-28 14:56:16 -07006293void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294e1000_clear_hw_cntrs(struct e1000_hw *hw)
6295{
6296 volatile uint32_t temp;
6297
6298 temp = E1000_READ_REG(hw, CRCERRS);
6299 temp = E1000_READ_REG(hw, SYMERRS);
6300 temp = E1000_READ_REG(hw, MPC);
6301 temp = E1000_READ_REG(hw, SCC);
6302 temp = E1000_READ_REG(hw, ECOL);
6303 temp = E1000_READ_REG(hw, MCC);
6304 temp = E1000_READ_REG(hw, LATECOL);
6305 temp = E1000_READ_REG(hw, COLC);
6306 temp = E1000_READ_REG(hw, DC);
6307 temp = E1000_READ_REG(hw, SEC);
6308 temp = E1000_READ_REG(hw, RLEC);
6309 temp = E1000_READ_REG(hw, XONRXC);
6310 temp = E1000_READ_REG(hw, XONTXC);
6311 temp = E1000_READ_REG(hw, XOFFRXC);
6312 temp = E1000_READ_REG(hw, XOFFTXC);
6313 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006314
6315 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 temp = E1000_READ_REG(hw, PRC64);
6317 temp = E1000_READ_REG(hw, PRC127);
6318 temp = E1000_READ_REG(hw, PRC255);
6319 temp = E1000_READ_REG(hw, PRC511);
6320 temp = E1000_READ_REG(hw, PRC1023);
6321 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006322 }
6323
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 temp = E1000_READ_REG(hw, GPRC);
6325 temp = E1000_READ_REG(hw, BPRC);
6326 temp = E1000_READ_REG(hw, MPRC);
6327 temp = E1000_READ_REG(hw, GPTC);
6328 temp = E1000_READ_REG(hw, GORCL);
6329 temp = E1000_READ_REG(hw, GORCH);
6330 temp = E1000_READ_REG(hw, GOTCL);
6331 temp = E1000_READ_REG(hw, GOTCH);
6332 temp = E1000_READ_REG(hw, RNBC);
6333 temp = E1000_READ_REG(hw, RUC);
6334 temp = E1000_READ_REG(hw, RFC);
6335 temp = E1000_READ_REG(hw, ROC);
6336 temp = E1000_READ_REG(hw, RJC);
6337 temp = E1000_READ_REG(hw, TORL);
6338 temp = E1000_READ_REG(hw, TORH);
6339 temp = E1000_READ_REG(hw, TOTL);
6340 temp = E1000_READ_REG(hw, TOTH);
6341 temp = E1000_READ_REG(hw, TPR);
6342 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006343
6344 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 temp = E1000_READ_REG(hw, PTC64);
6346 temp = E1000_READ_REG(hw, PTC127);
6347 temp = E1000_READ_REG(hw, PTC255);
6348 temp = E1000_READ_REG(hw, PTC511);
6349 temp = E1000_READ_REG(hw, PTC1023);
6350 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006351 }
6352
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 temp = E1000_READ_REG(hw, MPTC);
6354 temp = E1000_READ_REG(hw, BPTC);
6355
Auke Kok8fc897b2006-08-28 14:56:16 -07006356 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357
6358 temp = E1000_READ_REG(hw, ALGNERRC);
6359 temp = E1000_READ_REG(hw, RXERRC);
6360 temp = E1000_READ_REG(hw, TNCRS);
6361 temp = E1000_READ_REG(hw, CEXTERR);
6362 temp = E1000_READ_REG(hw, TSCTC);
6363 temp = E1000_READ_REG(hw, TSCTFC);
6364
Auke Kok8fc897b2006-08-28 14:56:16 -07006365 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366
6367 temp = E1000_READ_REG(hw, MGTPRC);
6368 temp = E1000_READ_REG(hw, MGTPDC);
6369 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006370
Auke Kok8fc897b2006-08-28 14:56:16 -07006371 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006372
6373 temp = E1000_READ_REG(hw, IAC);
6374 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006375
6376 if (hw->mac_type == e1000_ich8lan) return;
6377
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006378 temp = E1000_READ_REG(hw, ICRXPTC);
6379 temp = E1000_READ_REG(hw, ICRXATC);
6380 temp = E1000_READ_REG(hw, ICTXPTC);
6381 temp = E1000_READ_REG(hw, ICTXATC);
6382 temp = E1000_READ_REG(hw, ICTXQEC);
6383 temp = E1000_READ_REG(hw, ICTXQMTC);
6384 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385}
6386
6387/******************************************************************************
6388 * Resets Adaptive IFS to its default state.
6389 *
6390 * hw - Struct containing variables accessed by shared code
6391 *
6392 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6393 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6394 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6395 * before calling this function.
6396 *****************************************************************************/
6397void
6398e1000_reset_adaptive(struct e1000_hw *hw)
6399{
6400 DEBUGFUNC("e1000_reset_adaptive");
6401
Auke Kok8fc897b2006-08-28 14:56:16 -07006402 if (hw->adaptive_ifs) {
6403 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 hw->current_ifs_val = 0;
6405 hw->ifs_min_val = IFS_MIN;
6406 hw->ifs_max_val = IFS_MAX;
6407 hw->ifs_step_size = IFS_STEP;
6408 hw->ifs_ratio = IFS_RATIO;
6409 }
6410 hw->in_ifs_mode = FALSE;
6411 E1000_WRITE_REG(hw, AIT, 0);
6412 } else {
6413 DEBUGOUT("Not in Adaptive IFS mode!\n");
6414 }
6415}
6416
6417/******************************************************************************
6418 * Called during the callback/watchdog routine to update IFS value based on
6419 * the ratio of transmits to collisions.
6420 *
6421 * hw - Struct containing variables accessed by shared code
6422 * tx_packets - Number of transmits since last callback
6423 * total_collisions - Number of collisions since last callback
6424 *****************************************************************************/
6425void
6426e1000_update_adaptive(struct e1000_hw *hw)
6427{
6428 DEBUGFUNC("e1000_update_adaptive");
6429
Auke Kok8fc897b2006-08-28 14:56:16 -07006430 if (hw->adaptive_ifs) {
6431 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6432 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006434 if (hw->current_ifs_val < hw->ifs_max_val) {
6435 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 hw->current_ifs_val = hw->ifs_min_val;
6437 else
6438 hw->current_ifs_val += hw->ifs_step_size;
6439 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6440 }
6441 }
6442 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006443 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 hw->current_ifs_val = 0;
6445 hw->in_ifs_mode = FALSE;
6446 E1000_WRITE_REG(hw, AIT, 0);
6447 }
6448 }
6449 } else {
6450 DEBUGOUT("Not in Adaptive IFS mode!\n");
6451 }
6452}
6453
6454/******************************************************************************
6455 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6456 *
6457 * hw - Struct containing variables accessed by shared code
6458 * frame_len - The length of the frame in question
6459 * mac_addr - The Ethernet destination address of the frame in question
6460 *****************************************************************************/
6461void
6462e1000_tbi_adjust_stats(struct e1000_hw *hw,
6463 struct e1000_hw_stats *stats,
6464 uint32_t frame_len,
6465 uint8_t *mac_addr)
6466{
6467 uint64_t carry_bit;
6468
6469 /* First adjust the frame length. */
6470 frame_len--;
6471 /* We need to adjust the statistics counters, since the hardware
6472 * counters overcount this packet as a CRC error and undercount
6473 * the packet as a good packet
6474 */
6475 /* This packet should not be counted as a CRC error. */
6476 stats->crcerrs--;
6477 /* This packet does count as a Good Packet Received. */
6478 stats->gprc++;
6479
6480 /* Adjust the Good Octets received counters */
6481 carry_bit = 0x80000000 & stats->gorcl;
6482 stats->gorcl += frame_len;
6483 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6484 * Received Count) was one before the addition,
6485 * AND it is zero after, then we lost the carry out,
6486 * need to add one to Gorch (Good Octets Received Count High).
6487 * This could be simplified if all environments supported
6488 * 64-bit integers.
6489 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006490 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 stats->gorch++;
6492 /* Is this a broadcast or multicast? Check broadcast first,
6493 * since the test for a multicast frame will test positive on
6494 * a broadcast frame.
6495 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006496 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 /* Broadcast packet */
6498 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006499 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500 /* Multicast packet */
6501 stats->mprc++;
6502
Auke Kok8fc897b2006-08-28 14:56:16 -07006503 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504 /* In this case, the hardware has overcounted the number of
6505 * oversize frames.
6506 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006507 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 stats->roc--;
6509 }
6510
6511 /* Adjust the bin counters when the extra byte put the frame in the
6512 * wrong bin. Remember that the frame_len was adjusted above.
6513 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006514 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 stats->prc64++;
6516 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006517 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 stats->prc127++;
6519 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006520 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 stats->prc255++;
6522 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006523 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 stats->prc511++;
6525 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006526 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 stats->prc1023++;
6528 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006529 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 stats->prc1522++;
6531 }
6532}
6533
6534/******************************************************************************
6535 * Gets the current PCI bus type, speed, and width of the hardware
6536 *
6537 * hw - Struct containing variables accessed by shared code
6538 *****************************************************************************/
6539void
6540e1000_get_bus_info(struct e1000_hw *hw)
6541{
6542 uint32_t status;
6543
6544 switch (hw->mac_type) {
6545 case e1000_82542_rev2_0:
6546 case e1000_82542_rev2_1:
6547 hw->bus_type = e1000_bus_type_unknown;
6548 hw->bus_speed = e1000_bus_speed_unknown;
6549 hw->bus_width = e1000_bus_width_unknown;
6550 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006551 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006552 case e1000_82573:
6553 hw->bus_type = e1000_bus_type_pci_express;
6554 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirsherfd803242005-12-13 00:06:22 -05006555 hw->bus_width = e1000_bus_width_pciex_1;
6556 break;
6557 case e1000_82571:
Auke Kokcd94dd02006-06-27 09:08:22 -07006558 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006559 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006560 hw->bus_type = e1000_bus_type_pci_express;
6561 hw->bus_speed = e1000_bus_speed_2500;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006562 hw->bus_width = e1000_bus_width_pciex_4;
6563 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564 default:
6565 status = E1000_READ_REG(hw, STATUS);
6566 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6567 e1000_bus_type_pcix : e1000_bus_type_pci;
6568
Auke Kok8fc897b2006-08-28 14:56:16 -07006569 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6571 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006572 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6574 e1000_bus_speed_66 : e1000_bus_speed_33;
6575 } else {
6576 switch (status & E1000_STATUS_PCIX_SPEED) {
6577 case E1000_STATUS_PCIX_SPEED_66:
6578 hw->bus_speed = e1000_bus_speed_66;
6579 break;
6580 case E1000_STATUS_PCIX_SPEED_100:
6581 hw->bus_speed = e1000_bus_speed_100;
6582 break;
6583 case E1000_STATUS_PCIX_SPEED_133:
6584 hw->bus_speed = e1000_bus_speed_133;
6585 break;
6586 default:
6587 hw->bus_speed = e1000_bus_speed_reserved;
6588 break;
6589 }
6590 }
6591 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6592 e1000_bus_width_64 : e1000_bus_width_32;
6593 break;
6594 }
6595}
6596/******************************************************************************
6597 * Reads a value from one of the devices registers using port I/O (as opposed
6598 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6599 *
6600 * hw - Struct containing variables accessed by shared code
6601 * offset - offset to read from
6602 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07006603#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604uint32_t
6605e1000_read_reg_io(struct e1000_hw *hw,
6606 uint32_t offset)
6607{
6608 unsigned long io_addr = hw->io_base;
6609 unsigned long io_data = hw->io_base + 4;
6610
6611 e1000_io_write(hw, io_addr, offset);
6612 return e1000_io_read(hw, io_data);
6613}
Adrian Bunke4c780b2006-08-14 23:00:10 -07006614#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615
6616/******************************************************************************
6617 * Writes a value to one of the devices registers using port I/O (as opposed to
6618 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6619 *
6620 * hw - Struct containing variables accessed by shared code
6621 * offset - offset to write to
6622 * value - value to write
6623 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006624static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625e1000_write_reg_io(struct e1000_hw *hw,
6626 uint32_t offset,
6627 uint32_t value)
6628{
6629 unsigned long io_addr = hw->io_base;
6630 unsigned long io_data = hw->io_base + 4;
6631
6632 e1000_io_write(hw, io_addr, offset);
6633 e1000_io_write(hw, io_data, value);
6634}
6635
6636
6637/******************************************************************************
6638 * Estimates the cable length.
6639 *
6640 * hw - Struct containing variables accessed by shared code
6641 * min_length - The estimated minimum length
6642 * max_length - The estimated maximum length
6643 *
6644 * returns: - E1000_ERR_XXX
6645 * E1000_SUCCESS
6646 *
6647 * This function always returns a ranged length (minimum & maximum).
6648 * So for M88 phy's, this function interprets the one value returned from the
6649 * register to the minimum and maximum range.
6650 * For IGP phy's, the function calculates the range by the AGC registers.
6651 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006652static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653e1000_get_cable_length(struct e1000_hw *hw,
6654 uint16_t *min_length,
6655 uint16_t *max_length)
6656{
6657 int32_t ret_val;
6658 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 uint16_t i, phy_data;
6660 uint16_t cable_length;
6661
6662 DEBUGFUNC("e1000_get_cable_length");
6663
6664 *min_length = *max_length = 0;
6665
6666 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006667 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006668
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6670 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006671 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 return ret_val;
6673 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6674 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6675
6676 /* Convert the enum value to ranged values */
6677 switch (cable_length) {
6678 case e1000_cable_length_50:
6679 *min_length = 0;
6680 *max_length = e1000_igp_cable_length_50;
6681 break;
6682 case e1000_cable_length_50_80:
6683 *min_length = e1000_igp_cable_length_50;
6684 *max_length = e1000_igp_cable_length_80;
6685 break;
6686 case e1000_cable_length_80_110:
6687 *min_length = e1000_igp_cable_length_80;
6688 *max_length = e1000_igp_cable_length_110;
6689 break;
6690 case e1000_cable_length_110_140:
6691 *min_length = e1000_igp_cable_length_110;
6692 *max_length = e1000_igp_cable_length_140;
6693 break;
6694 case e1000_cable_length_140:
6695 *min_length = e1000_igp_cable_length_140;
6696 *max_length = e1000_igp_cable_length_170;
6697 break;
6698 default:
6699 return -E1000_ERR_PHY;
6700 break;
6701 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006702 } else if (hw->phy_type == e1000_phy_gg82563) {
6703 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6704 &phy_data);
6705 if (ret_val)
6706 return ret_val;
6707 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6708
6709 switch (cable_length) {
6710 case e1000_gg_cable_length_60:
6711 *min_length = 0;
6712 *max_length = e1000_igp_cable_length_60;
6713 break;
6714 case e1000_gg_cable_length_60_115:
6715 *min_length = e1000_igp_cable_length_60;
6716 *max_length = e1000_igp_cable_length_115;
6717 break;
6718 case e1000_gg_cable_length_115_150:
6719 *min_length = e1000_igp_cable_length_115;
6720 *max_length = e1000_igp_cable_length_150;
6721 break;
6722 case e1000_gg_cable_length_150:
6723 *min_length = e1000_igp_cable_length_150;
6724 *max_length = e1000_igp_cable_length_180;
6725 break;
6726 default:
6727 return -E1000_ERR_PHY;
6728 break;
6729 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006730 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006731 uint16_t cur_agc_value;
6732 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6734 {IGP01E1000_PHY_AGC_A,
6735 IGP01E1000_PHY_AGC_B,
6736 IGP01E1000_PHY_AGC_C,
6737 IGP01E1000_PHY_AGC_D};
6738 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006739 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740
6741 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006742 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 return ret_val;
6744
Auke Kokcd94dd02006-06-27 09:08:22 -07006745 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746
Auke Kokcd94dd02006-06-27 09:08:22 -07006747 /* Value bound check. */
6748 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6749 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750 return -E1000_ERR_PHY;
6751
Auke Kokcd94dd02006-06-27 09:08:22 -07006752 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753
6754 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006755 if (min_agc_value > cur_agc_value)
6756 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 }
6758
6759 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006760 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6761 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762
6763 /* Get the average length of the remaining 3 channels */
6764 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6765 } else {
6766 /* Get the average length of all the 4 channels. */
6767 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6768 }
6769
6770 /* Set the range of the calculated length. */
6771 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6772 IGP01E1000_AGC_RANGE) > 0) ?
6773 (e1000_igp_cable_length_table[agc_value] -
6774 IGP01E1000_AGC_RANGE) : 0;
6775 *max_length = e1000_igp_cable_length_table[agc_value] +
6776 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006777 } else if (hw->phy_type == e1000_phy_igp_2 ||
6778 hw->phy_type == e1000_phy_igp_3) {
6779 uint16_t cur_agc_index, max_agc_index = 0;
6780 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006781 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6782 {IGP02E1000_PHY_AGC_A,
6783 IGP02E1000_PHY_AGC_B,
6784 IGP02E1000_PHY_AGC_C,
6785 IGP02E1000_PHY_AGC_D};
6786 /* Read the AGC registers for all channels */
6787 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6788 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6789 if (ret_val)
6790 return ret_val;
6791
Auke Kok8fc897b2006-08-28 14:56:16 -07006792 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006793 * fine gain values. The result is a number that can be put into
6794 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006795 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6796 IGP02E1000_AGC_LENGTH_MASK;
6797
6798 /* Array index bound check. */
6799 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6800 (cur_agc_index == 0))
6801 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006802
6803 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006804 if (e1000_igp_2_cable_length_table[min_agc_index] >
6805 e1000_igp_2_cable_length_table[cur_agc_index])
6806 min_agc_index = cur_agc_index;
6807 if (e1000_igp_2_cable_length_table[max_agc_index] <
6808 e1000_igp_2_cable_length_table[cur_agc_index])
6809 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006810
Auke Kokcd94dd02006-06-27 09:08:22 -07006811 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006812 }
6813
Auke Kokcd94dd02006-06-27 09:08:22 -07006814 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6815 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006816 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6817
6818 /* Calculate cable length with the error range of +/- 10 meters. */
6819 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6820 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6821 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006822 }
6823
6824 return E1000_SUCCESS;
6825}
6826
6827/******************************************************************************
6828 * Check the cable polarity
6829 *
6830 * hw - Struct containing variables accessed by shared code
6831 * polarity - output parameter : 0 - Polarity is not reversed
6832 * 1 - Polarity is reversed.
6833 *
6834 * returns: - E1000_ERR_XXX
6835 * E1000_SUCCESS
6836 *
6837 * For phy's older then IGP, this function simply reads the polarity bit in the
6838 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6839 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6840 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6841 * IGP01E1000_PHY_PCS_INIT_REG.
6842 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006843static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006844e1000_check_polarity(struct e1000_hw *hw,
6845 uint16_t *polarity)
6846{
6847 int32_t ret_val;
6848 uint16_t phy_data;
6849
6850 DEBUGFUNC("e1000_check_polarity");
6851
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006852 if ((hw->phy_type == e1000_phy_m88) ||
6853 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006854 /* return the Polarity bit in the Status register. */
6855 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6856 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006857 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 return ret_val;
6859 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6860 M88E1000_PSSR_REV_POLARITY_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006861 } else if (hw->phy_type == e1000_phy_igp ||
6862 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006863 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 /* Read the Status register to check the speed */
6865 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6866 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006867 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868 return ret_val;
6869
6870 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6871 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006872 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 IGP01E1000_PSSR_SPEED_1000MBPS) {
6874
6875 /* Read the GIG initialization PCS register (0x00B4) */
6876 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6877 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006878 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 return ret_val;
6880
6881 /* Check the polarity bits */
6882 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6883 } else {
6884 /* For 10 Mbps, read the polarity bit in the status register. (for
6885 * 100 Mbps this bit is always 0) */
6886 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6887 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006888 } else if (hw->phy_type == e1000_phy_ife) {
6889 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6890 &phy_data);
6891 if (ret_val)
6892 return ret_val;
6893 *polarity = (phy_data & IFE_PESC_POLARITY_REVERSED) >>
6894 IFE_PESC_POLARITY_REVERSED_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 }
6896 return E1000_SUCCESS;
6897}
6898
6899/******************************************************************************
6900 * Check if Downshift occured
6901 *
6902 * hw - Struct containing variables accessed by shared code
6903 * downshift - output parameter : 0 - No Downshift ocured.
6904 * 1 - Downshift ocured.
6905 *
6906 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006907 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006908 *
6909 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6910 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6911 * Link Health register. In IGP this bit is latched high, so the driver must
6912 * read it immediately after link is established.
6913 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006914static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006915e1000_check_downshift(struct e1000_hw *hw)
6916{
6917 int32_t ret_val;
6918 uint16_t phy_data;
6919
6920 DEBUGFUNC("e1000_check_downshift");
6921
Auke Kokcd94dd02006-06-27 09:08:22 -07006922 if (hw->phy_type == e1000_phy_igp ||
6923 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006924 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6926 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006927 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928 return ret_val;
6929
6930 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006931 } else if ((hw->phy_type == e1000_phy_m88) ||
6932 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6934 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006935 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006936 return ret_val;
6937
6938 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6939 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006940 } else if (hw->phy_type == e1000_phy_ife) {
6941 /* e1000_phy_ife supports 10/100 speed only */
6942 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006944
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 return E1000_SUCCESS;
6946}
6947
6948/*****************************************************************************
6949 *
6950 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6951 * gigabit link is achieved to improve link quality.
6952 *
6953 * hw: Struct containing variables accessed by shared code
6954 *
6955 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6956 * E1000_SUCCESS at any other case.
6957 *
6958 ****************************************************************************/
6959
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006960static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6962 boolean_t link_up)
6963{
6964 int32_t ret_val;
6965 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6966 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6967 {IGP01E1000_PHY_AGC_PARAM_A,
6968 IGP01E1000_PHY_AGC_PARAM_B,
6969 IGP01E1000_PHY_AGC_PARAM_C,
6970 IGP01E1000_PHY_AGC_PARAM_D};
6971 uint16_t min_length, max_length;
6972
6973 DEBUGFUNC("e1000_config_dsp_after_link_change");
6974
Auke Kok8fc897b2006-08-28 14:56:16 -07006975 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 return E1000_SUCCESS;
6977
Auke Kok8fc897b2006-08-28 14:56:16 -07006978 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006979 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07006980 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006981 DEBUGOUT("Error getting link speed and duplex\n");
6982 return ret_val;
6983 }
6984
Auke Kok8fc897b2006-08-28 14:56:16 -07006985 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006986
Auke Kokcd94dd02006-06-27 09:08:22 -07006987 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
6988 if (ret_val)
6989 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990
Auke Kok8fc897b2006-08-28 14:56:16 -07006991 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992 min_length >= e1000_igp_cable_length_50) {
6993
Auke Kok8fc897b2006-08-28 14:56:16 -07006994 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006995 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6996 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006997 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006998 return ret_val;
6999
7000 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7001
7002 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7003 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007004 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007005 return ret_val;
7006 }
7007 hw->dsp_config_state = e1000_dsp_config_activated;
7008 }
7009
Auke Kok8fc897b2006-08-28 14:56:16 -07007010 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011 (min_length < e1000_igp_cable_length_50)) {
7012
7013 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7014 uint32_t idle_errs = 0;
7015
7016 /* clear previous idle error counts */
7017 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7018 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007019 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007020 return ret_val;
7021
Auke Kok8fc897b2006-08-28 14:56:16 -07007022 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023 udelay(1000);
7024 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7025 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007026 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007027 return ret_val;
7028
7029 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007030 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031 hw->ffe_config_state = e1000_ffe_config_active;
7032
7033 ret_val = e1000_write_phy_reg(hw,
7034 IGP01E1000_PHY_DSP_FFE,
7035 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007036 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 return ret_val;
7038 break;
7039 }
7040
Auke Kok8fc897b2006-08-28 14:56:16 -07007041 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7043 }
7044 }
7045 }
7046 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007047 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 /* Save off the current value of register 0x2F5B to be restored at
7049 * the end of the routines. */
7050 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7051
Auke Kok8fc897b2006-08-28 14:56:16 -07007052 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 return ret_val;
7054
7055 /* Disable the PHY transmitter */
7056 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7057
Auke Kok8fc897b2006-08-28 14:56:16 -07007058 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 return ret_val;
7060
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007061 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007062
7063 ret_val = e1000_write_phy_reg(hw, 0x0000,
7064 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007065 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007066 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007067 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007069 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007070 return ret_val;
7071
7072 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7073 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7074
7075 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007076 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077 return ret_val;
7078 }
7079
7080 ret_val = e1000_write_phy_reg(hw, 0x0000,
7081 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007082 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007083 return ret_val;
7084
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007085 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086
7087 /* Now enable the transmitter */
7088 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7089
Auke Kok8fc897b2006-08-28 14:56:16 -07007090 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007091 return ret_val;
7092
7093 hw->dsp_config_state = e1000_dsp_config_enabled;
7094 }
7095
Auke Kok8fc897b2006-08-28 14:56:16 -07007096 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007097 /* Save off the current value of register 0x2F5B to be restored at
7098 * the end of the routines. */
7099 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7100
Auke Kok8fc897b2006-08-28 14:56:16 -07007101 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007102 return ret_val;
7103
7104 /* Disable the PHY transmitter */
7105 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7106
Auke Kok8fc897b2006-08-28 14:56:16 -07007107 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007108 return ret_val;
7109
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007110 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007111
7112 ret_val = e1000_write_phy_reg(hw, 0x0000,
7113 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007114 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007115 return ret_val;
7116 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7117 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007118 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007119 return ret_val;
7120
7121 ret_val = e1000_write_phy_reg(hw, 0x0000,
7122 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007123 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007124 return ret_val;
7125
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007126 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007127
7128 /* Now enable the transmitter */
7129 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7130
Auke Kok8fc897b2006-08-28 14:56:16 -07007131 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007132 return ret_val;
7133
7134 hw->ffe_config_state = e1000_ffe_config_enabled;
7135 }
7136 }
7137 return E1000_SUCCESS;
7138}
7139
7140/*****************************************************************************
7141 * Set PHY to class A mode
7142 * Assumes the following operations will follow to enable the new class mode.
7143 * 1. Do a PHY soft reset
7144 * 2. Restart auto-negotiation or force link.
7145 *
7146 * hw - Struct containing variables accessed by shared code
7147 ****************************************************************************/
7148static int32_t
7149e1000_set_phy_mode(struct e1000_hw *hw)
7150{
7151 int32_t ret_val;
7152 uint16_t eeprom_data;
7153
7154 DEBUGFUNC("e1000_set_phy_mode");
7155
Auke Kok8fc897b2006-08-28 14:56:16 -07007156 if ((hw->mac_type == e1000_82545_rev_3) &&
7157 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007158 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007159 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007160 return ret_val;
7161 }
7162
Auke Kok8fc897b2006-08-28 14:56:16 -07007163 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7164 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007165 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007166 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007167 return ret_val;
7168 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007169 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007170 return ret_val;
7171
7172 hw->phy_reset_disable = FALSE;
7173 }
7174 }
7175
7176 return E1000_SUCCESS;
7177}
7178
7179/*****************************************************************************
7180 *
7181 * This function sets the lplu state according to the active flag. When
7182 * activating lplu this function also disables smart speed and vise versa.
7183 * lplu will not be activated unless the device autonegotiation advertisment
7184 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7185 * hw: Struct containing variables accessed by shared code
7186 * active - true to enable lplu false to disable lplu.
7187 *
7188 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7189 * E1000_SUCCESS at any other case.
7190 *
7191 ****************************************************************************/
7192
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007193static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007194e1000_set_d3_lplu_state(struct e1000_hw *hw,
7195 boolean_t active)
7196{
Auke Kokcd94dd02006-06-27 09:08:22 -07007197 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198 int32_t ret_val;
7199 uint16_t phy_data;
7200 DEBUGFUNC("e1000_set_d3_lplu_state");
7201
Auke Kokcd94dd02006-06-27 09:08:22 -07007202 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7203 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007204 return E1000_SUCCESS;
7205
7206 /* During driver activity LPLU should not be used or it will attain link
7207 * from the lowest speeds starting from 10Mbps. The capability is used for
7208 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007209 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007210 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007211 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007212 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007213 } else if (hw->mac_type == e1000_ich8lan) {
7214 /* MAC writes into PHY register based on the state transition
7215 * and start auto-negotiation. SW driver can overwrite the settings
7216 * in CSR PHY power control E1000_PHY_CTRL register. */
7217 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007218 } else {
7219 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007220 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007221 return ret_val;
7222 }
7223
Auke Kok8fc897b2006-08-28 14:56:16 -07007224 if (!active) {
7225 if (hw->mac_type == e1000_82541_rev_2 ||
7226 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007227 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7228 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007229 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007230 return ret_val;
7231 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007232 if (hw->mac_type == e1000_ich8lan) {
7233 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7234 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7235 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007236 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7237 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7238 phy_data);
7239 if (ret_val)
7240 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007241 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007243
7244 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7245 * Dx states where the power conservation is most important. During
7246 * driver activity we should enable SmartSpeed, so performance is
7247 * maintained. */
7248 if (hw->smart_speed == e1000_smart_speed_on) {
7249 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7250 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007251 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007252 return ret_val;
7253
7254 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7255 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7256 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007257 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007258 return ret_val;
7259 } else if (hw->smart_speed == e1000_smart_speed_off) {
7260 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7261 &phy_data);
7262 if (ret_val)
7263 return ret_val;
7264
7265 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7266 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7267 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007269 return ret_val;
7270 }
7271
Auke Kok8fc897b2006-08-28 14:56:16 -07007272 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7273 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7274 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007275
Auke Kok8fc897b2006-08-28 14:56:16 -07007276 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007277 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007278 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7279 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007280 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007281 return ret_val;
7282 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007283 if (hw->mac_type == e1000_ich8lan) {
7284 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7285 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7286 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007287 phy_data |= IGP02E1000_PM_D3_LPLU;
7288 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7289 phy_data);
7290 if (ret_val)
7291 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007292 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007293 }
7294
7295 /* When LPLU is enabled we should disable SmartSpeed */
7296 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007297 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298 return ret_val;
7299
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007300 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7301 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007302 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007303 return ret_val;
7304
7305 }
7306 return E1000_SUCCESS;
7307}
7308
7309/*****************************************************************************
7310 *
7311 * This function sets the lplu d0 state according to the active flag. When
7312 * activating lplu this function also disables smart speed and vise versa.
7313 * lplu will not be activated unless the device autonegotiation advertisment
7314 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7315 * hw: Struct containing variables accessed by shared code
7316 * active - true to enable lplu false to disable lplu.
7317 *
7318 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7319 * E1000_SUCCESS at any other case.
7320 *
7321 ****************************************************************************/
7322
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007323static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007324e1000_set_d0_lplu_state(struct e1000_hw *hw,
7325 boolean_t active)
7326{
Auke Kokcd94dd02006-06-27 09:08:22 -07007327 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007328 int32_t ret_val;
7329 uint16_t phy_data;
7330 DEBUGFUNC("e1000_set_d0_lplu_state");
7331
Auke Kok8fc897b2006-08-28 14:56:16 -07007332 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007333 return E1000_SUCCESS;
7334
Auke Kokcd94dd02006-06-27 09:08:22 -07007335 if (hw->mac_type == e1000_ich8lan) {
7336 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7337 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007338 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007339 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007340 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007341 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007342
7343 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007344 if (hw->mac_type == e1000_ich8lan) {
7345 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7346 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7347 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007348 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7349 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7350 if (ret_val)
7351 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007352 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007353
7354 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7355 * Dx states where the power conservation is most important. During
7356 * driver activity we should enable SmartSpeed, so performance is
7357 * maintained. */
7358 if (hw->smart_speed == e1000_smart_speed_on) {
7359 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7360 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007361 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007362 return ret_val;
7363
7364 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7365 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7366 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007367 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007368 return ret_val;
7369 } else if (hw->smart_speed == e1000_smart_speed_off) {
7370 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7371 &phy_data);
7372 if (ret_val)
7373 return ret_val;
7374
7375 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7376 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7377 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007378 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007379 return ret_val;
7380 }
7381
7382
7383 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007384
Auke Kokcd94dd02006-06-27 09:08:22 -07007385 if (hw->mac_type == e1000_ich8lan) {
7386 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7387 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7388 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007389 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007390 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7391 if (ret_val)
7392 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007393 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007394
Linus Torvalds1da177e2005-04-16 15:20:36 -07007395 /* When LPLU is enabled we should disable SmartSpeed */
7396 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007397 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007398 return ret_val;
7399
7400 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7401 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007402 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007403 return ret_val;
7404
7405 }
7406 return E1000_SUCCESS;
7407}
7408
7409/******************************************************************************
7410 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7411 *
7412 * hw - Struct containing variables accessed by shared code
7413 *****************************************************************************/
7414static int32_t
7415e1000_set_vco_speed(struct e1000_hw *hw)
7416{
7417 int32_t ret_val;
7418 uint16_t default_page = 0;
7419 uint16_t phy_data;
7420
7421 DEBUGFUNC("e1000_set_vco_speed");
7422
Auke Kok8fc897b2006-08-28 14:56:16 -07007423 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424 case e1000_82545_rev_3:
7425 case e1000_82546_rev_3:
7426 break;
7427 default:
7428 return E1000_SUCCESS;
7429 }
7430
7431 /* Set PHY register 30, page 5, bit 8 to 0 */
7432
7433 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007434 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007435 return ret_val;
7436
7437 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007438 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007439 return ret_val;
7440
7441 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007442 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007443 return ret_val;
7444
7445 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7446 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007447 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007448 return ret_val;
7449
7450 /* Set PHY register 30, page 4, bit 11 to 1 */
7451
7452 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007453 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007454 return ret_val;
7455
7456 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007457 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007458 return ret_val;
7459
7460 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7461 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007462 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007463 return ret_val;
7464
7465 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007466 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007467 return ret_val;
7468
7469 return E1000_SUCCESS;
7470}
7471
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007472
7473/*****************************************************************************
7474 * This function reads the cookie from ARC ram.
7475 *
7476 * returns: - E1000_SUCCESS .
7477 ****************************************************************************/
7478int32_t
7479e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7480{
7481 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007482 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007483 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7484
7485 length = (length >> 2);
7486 offset = (offset >> 2);
7487
7488 for (i = 0; i < length; i++) {
7489 *((uint32_t *) buffer + i) =
7490 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7491 }
7492 return E1000_SUCCESS;
7493}
7494
7495
7496/*****************************************************************************
7497 * This function checks whether the HOST IF is enabled for command operaton
7498 * and also checks whether the previous command is completed.
7499 * It busy waits in case of previous command is not completed.
7500 *
Auke Kok76c224b2006-05-23 13:36:06 -07007501 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007502 * timeout
7503 * - E1000_SUCCESS for success.
7504 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007505static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007506e1000_mng_enable_host_if(struct e1000_hw * hw)
7507{
7508 uint32_t hicr;
7509 uint8_t i;
7510
7511 /* Check that the host interface is enabled. */
7512 hicr = E1000_READ_REG(hw, HICR);
7513 if ((hicr & E1000_HICR_EN) == 0) {
7514 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7515 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7516 }
7517 /* check the previous command is completed */
7518 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7519 hicr = E1000_READ_REG(hw, HICR);
7520 if (!(hicr & E1000_HICR_C))
7521 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007522 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007523 }
7524
Auke Kok76c224b2006-05-23 13:36:06 -07007525 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007526 DEBUGOUT("Previous command timeout failed .\n");
7527 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7528 }
7529 return E1000_SUCCESS;
7530}
7531
7532/*****************************************************************************
7533 * This function writes the buffer content at the offset given on the host if.
7534 * It also does alignment considerations to do the writes in most efficient way.
7535 * Also fills up the sum of the buffer in *buffer parameter.
7536 *
7537 * returns - E1000_SUCCESS for success.
7538 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007539static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007540e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7541 uint16_t length, uint16_t offset, uint8_t *sum)
7542{
7543 uint8_t *tmp;
7544 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007545 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007546 uint16_t remaining, i, j, prev_bytes;
7547
7548 /* sum = only sum of the data and it is not checksum */
7549
7550 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7551 return -E1000_ERR_PARAM;
7552 }
7553
7554 tmp = (uint8_t *)&data;
7555 prev_bytes = offset & 0x3;
7556 offset &= 0xFFFC;
7557 offset >>= 2;
7558
7559 if (prev_bytes) {
7560 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7561 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7562 *(tmp + j) = *bufptr++;
7563 *sum += *(tmp + j);
7564 }
7565 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7566 length -= j - prev_bytes;
7567 offset++;
7568 }
7569
7570 remaining = length & 0x3;
7571 length -= remaining;
7572
7573 /* Calculate length in DWORDs */
7574 length >>= 2;
7575
7576 /* The device driver writes the relevant command block into the
7577 * ram area. */
7578 for (i = 0; i < length; i++) {
7579 for (j = 0; j < sizeof(uint32_t); j++) {
7580 *(tmp + j) = *bufptr++;
7581 *sum += *(tmp + j);
7582 }
7583
7584 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7585 }
7586 if (remaining) {
7587 for (j = 0; j < sizeof(uint32_t); j++) {
7588 if (j < remaining)
7589 *(tmp + j) = *bufptr++;
7590 else
7591 *(tmp + j) = 0;
7592
7593 *sum += *(tmp + j);
7594 }
7595 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7596 }
7597
7598 return E1000_SUCCESS;
7599}
7600
7601
7602/*****************************************************************************
7603 * This function writes the command header after does the checksum calculation.
7604 *
7605 * returns - E1000_SUCCESS for success.
7606 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007607static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007608e1000_mng_write_cmd_header(struct e1000_hw * hw,
7609 struct e1000_host_mng_command_header * hdr)
7610{
7611 uint16_t i;
7612 uint8_t sum;
7613 uint8_t *buffer;
7614
7615 /* Write the whole command header structure which includes sum of
7616 * the buffer */
7617
7618 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7619
7620 sum = hdr->checksum;
7621 hdr->checksum = 0;
7622
7623 buffer = (uint8_t *) hdr;
7624 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007625 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007626 sum += buffer[i];
7627
7628 hdr->checksum = 0 - sum;
7629
7630 length >>= 2;
7631 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007632 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007633 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007634 E1000_WRITE_FLUSH(hw);
7635 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007636
7637 return E1000_SUCCESS;
7638}
7639
7640
7641/*****************************************************************************
7642 * This function indicates to ARC that a new command is pending which completes
7643 * one write operation by the driver.
7644 *
7645 * returns - E1000_SUCCESS for success.
7646 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007647static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007648e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007649{
7650 uint32_t hicr;
7651
7652 hicr = E1000_READ_REG(hw, HICR);
7653 /* Setting this bit tells the ARC that a new command is pending. */
7654 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7655
7656 return E1000_SUCCESS;
7657}
7658
7659
7660/*****************************************************************************
7661 * This function checks the mode of the firmware.
7662 *
7663 * returns - TRUE when the mode is IAMT or FALSE.
7664 ****************************************************************************/
7665boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007666e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007667{
7668 uint32_t fwsm;
7669
7670 fwsm = E1000_READ_REG(hw, FWSM);
7671
Auke Kokcd94dd02006-06-27 09:08:22 -07007672 if (hw->mac_type == e1000_ich8lan) {
7673 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7674 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7675 return TRUE;
7676 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7677 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007678 return TRUE;
7679
7680 return FALSE;
7681}
7682
7683
7684/*****************************************************************************
7685 * This function writes the dhcp info .
7686 ****************************************************************************/
7687int32_t
7688e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7689 uint16_t length)
7690{
7691 int32_t ret_val;
7692 struct e1000_host_mng_command_header hdr;
7693
7694 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7695 hdr.command_length = length;
7696 hdr.reserved1 = 0;
7697 hdr.reserved2 = 0;
7698 hdr.checksum = 0;
7699
7700 ret_val = e1000_mng_enable_host_if(hw);
7701 if (ret_val == E1000_SUCCESS) {
7702 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7703 &(hdr.checksum));
7704 if (ret_val == E1000_SUCCESS) {
7705 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7706 if (ret_val == E1000_SUCCESS)
7707 ret_val = e1000_mng_write_commit(hw);
7708 }
7709 }
7710 return ret_val;
7711}
7712
7713
7714/*****************************************************************************
7715 * This function calculates the checksum.
7716 *
7717 * returns - checksum of buffer contents.
7718 ****************************************************************************/
7719uint8_t
7720e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7721{
7722 uint8_t sum = 0;
7723 uint32_t i;
7724
7725 if (!buffer)
7726 return 0;
7727
7728 for (i=0; i < length; i++)
7729 sum += buffer[i];
7730
7731 return (uint8_t) (0 - sum);
7732}
7733
7734/*****************************************************************************
7735 * This function checks whether tx pkt filtering needs to be enabled or not.
7736 *
7737 * returns - TRUE for packet filtering or FALSE.
7738 ****************************************************************************/
7739boolean_t
7740e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7741{
7742 /* called in init as well as watchdog timer functions */
7743
7744 int32_t ret_val, checksum;
7745 boolean_t tx_filter = FALSE;
7746 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7747 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7748
7749 if (e1000_check_mng_mode(hw)) {
7750 ret_val = e1000_mng_enable_host_if(hw);
7751 if (ret_val == E1000_SUCCESS) {
7752 ret_val = e1000_host_if_read_cookie(hw, buffer);
7753 if (ret_val == E1000_SUCCESS) {
7754 checksum = hdr->checksum;
7755 hdr->checksum = 0;
7756 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7757 checksum == e1000_calculate_mng_checksum((char *)buffer,
7758 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7759 if (hdr->status &
7760 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7761 tx_filter = TRUE;
7762 } else
7763 tx_filter = TRUE;
7764 } else
7765 tx_filter = TRUE;
7766 }
7767 }
7768
7769 hw->tx_pkt_filtering = tx_filter;
7770 return tx_filter;
7771}
7772
7773/******************************************************************************
7774 * Verifies the hardware needs to allow ARPs to be processed by the host
7775 *
7776 * hw - Struct containing variables accessed by shared code
7777 *
7778 * returns: - TRUE/FALSE
7779 *
7780 *****************************************************************************/
7781uint32_t
7782e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7783{
7784 uint32_t manc;
7785 uint32_t fwsm, factps;
7786
7787 if (hw->asf_firmware_present) {
7788 manc = E1000_READ_REG(hw, MANC);
7789
7790 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7791 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7792 return FALSE;
7793 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7794 fwsm = E1000_READ_REG(hw, FWSM);
7795 factps = E1000_READ_REG(hw, FACTPS);
7796
7797 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7798 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7799 (factps & E1000_FACTPS_MNGCG))
7800 return TRUE;
7801 } else
7802 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7803 return TRUE;
7804 }
7805 return FALSE;
7806}
7807
Linus Torvalds1da177e2005-04-16 15:20:36 -07007808static int32_t
7809e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7810{
7811 int32_t ret_val;
7812 uint16_t mii_status_reg;
7813 uint16_t i;
7814
7815 /* Polarity reversal workaround for forced 10F/10H links. */
7816
7817 /* Disable the transmitter on the PHY */
7818
7819 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007820 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007821 return ret_val;
7822 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007823 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007824 return ret_val;
7825
7826 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007827 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007828 return ret_val;
7829
7830 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007831 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007832 /* Read the MII Status Register and wait for Link Status bit
7833 * to be clear.
7834 */
7835
7836 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007837 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007838 return ret_val;
7839
7840 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007841 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007842 return ret_val;
7843
Auke Kok8fc897b2006-08-28 14:56:16 -07007844 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007845 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007846 }
7847
7848 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007849 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007850
7851 /* Now we will re-enable th transmitter on the PHY */
7852
7853 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007854 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007855 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007856 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007857 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007858 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007859 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007860 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007861 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007862 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007863 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007864 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007865 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007866 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007867 return ret_val;
7868
7869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007870 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007871 return ret_val;
7872
7873 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007874 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007875 /* Read the MII Status Register and wait for Link Status bit
7876 * to be set.
7877 */
7878
7879 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007880 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007881 return ret_val;
7882
7883 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007884 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007885 return ret_val;
7886
Auke Kok8fc897b2006-08-28 14:56:16 -07007887 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007888 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007889 }
7890 return E1000_SUCCESS;
7891}
7892
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007893/***************************************************************************
7894 *
7895 * Disables PCI-Express master access.
7896 *
7897 * hw: Struct containing variables accessed by shared code
7898 *
7899 * returns: - none.
7900 *
7901 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007902static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007903e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7904{
7905 uint32_t ctrl;
7906
7907 DEBUGFUNC("e1000_set_pci_express_master_disable");
7908
7909 if (hw->bus_type != e1000_bus_type_pci_express)
7910 return;
7911
7912 ctrl = E1000_READ_REG(hw, CTRL);
7913 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7914 E1000_WRITE_REG(hw, CTRL, ctrl);
7915}
7916
7917/***************************************************************************
7918 *
7919 * Enables PCI-Express master access.
7920 *
7921 * hw: Struct containing variables accessed by shared code
7922 *
7923 * returns: - none.
7924 *
7925 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07007926#if 0
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007927void
7928e1000_enable_pciex_master(struct e1000_hw *hw)
7929{
7930 uint32_t ctrl;
7931
7932 DEBUGFUNC("e1000_enable_pciex_master");
7933
7934 if (hw->bus_type != e1000_bus_type_pci_express)
7935 return;
7936
7937 ctrl = E1000_READ_REG(hw, CTRL);
7938 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7939 E1000_WRITE_REG(hw, CTRL, ctrl);
7940}
Adrian Bunke4c780b2006-08-14 23:00:10 -07007941#endif /* 0 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007942
7943/*******************************************************************************
7944 *
7945 * Disables PCI-Express master access and verifies there are no pending requests
7946 *
7947 * hw: Struct containing variables accessed by shared code
7948 *
7949 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7950 * caused the master requests to be disabled.
7951 * E1000_SUCCESS master requests disabled.
7952 *
7953 ******************************************************************************/
7954int32_t
7955e1000_disable_pciex_master(struct e1000_hw *hw)
7956{
7957 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7958
7959 DEBUGFUNC("e1000_disable_pciex_master");
7960
7961 if (hw->bus_type != e1000_bus_type_pci_express)
7962 return E1000_SUCCESS;
7963
7964 e1000_set_pci_express_master_disable(hw);
7965
Auke Kok8fc897b2006-08-28 14:56:16 -07007966 while (timeout) {
7967 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007968 break;
7969 else
7970 udelay(100);
7971 timeout--;
7972 }
7973
Auke Kok8fc897b2006-08-28 14:56:16 -07007974 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007975 DEBUGOUT("Master requests are pending.\n");
7976 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7977 }
7978
7979 return E1000_SUCCESS;
7980}
7981
7982/*******************************************************************************
7983 *
7984 * Check for EEPROM Auto Read bit done.
7985 *
7986 * hw: Struct containing variables accessed by shared code
7987 *
7988 * returns: - E1000_ERR_RESET if fail to reset MAC
7989 * E1000_SUCCESS at any other case.
7990 *
7991 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007992static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007993e1000_get_auto_rd_done(struct e1000_hw *hw)
7994{
7995 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7996
7997 DEBUGFUNC("e1000_get_auto_rd_done");
7998
7999 switch (hw->mac_type) {
8000 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008001 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008002 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008003 case e1000_82571:
8004 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008005 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008006 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008007 case e1000_ich8lan:
8008 while (timeout) {
8009 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8010 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008011 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008012 timeout--;
8013 }
8014
Auke Kok8fc897b2006-08-28 14:56:16 -07008015 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008016 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8017 return -E1000_ERR_RESET;
8018 }
8019 break;
8020 }
8021
Jeff Kirsherfd803242005-12-13 00:06:22 -05008022 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8023 * Need to wait for PHY configuration completion before accessing NVM
8024 * and PHY. */
8025 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008026 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008027
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008028 return E1000_SUCCESS;
8029}
8030
8031/***************************************************************************
8032 * Checks if the PHY configuration is done
8033 *
8034 * hw: Struct containing variables accessed by shared code
8035 *
8036 * returns: - E1000_ERR_RESET if fail to reset MAC
8037 * E1000_SUCCESS at any other case.
8038 *
8039 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008040static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008041e1000_get_phy_cfg_done(struct e1000_hw *hw)
8042{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008043 int32_t timeout = PHY_CFG_TIMEOUT;
8044 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8045
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008046 DEBUGFUNC("e1000_get_phy_cfg_done");
8047
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008048 switch (hw->mac_type) {
8049 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008050 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008051 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008052 case e1000_80003es2lan:
8053 /* Separate *_CFG_DONE_* bit for each port */
8054 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8055 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8056 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008057 case e1000_82571:
8058 case e1000_82572:
8059 while (timeout) {
8060 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8061 break;
8062 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008063 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008064 timeout--;
8065 }
8066
8067 if (!timeout) {
8068 DEBUGOUT("MNG configuration cycle has not completed.\n");
8069 return -E1000_ERR_RESET;
8070 }
8071 break;
8072 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008073
8074 return E1000_SUCCESS;
8075}
8076
8077/***************************************************************************
8078 *
8079 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8080 * adapter or Eeprom access.
8081 *
8082 * hw: Struct containing variables accessed by shared code
8083 *
8084 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8085 * E1000_SUCCESS at any other case.
8086 *
8087 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008088static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008089e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8090{
8091 int32_t timeout;
8092 uint32_t swsm;
8093
8094 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8095
Auke Kok8fc897b2006-08-28 14:56:16 -07008096 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008097 return E1000_SUCCESS;
8098
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008099 if (hw->mac_type == e1000_80003es2lan) {
8100 /* Get the SW semaphore. */
8101 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8102 return -E1000_ERR_EEPROM;
8103 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008104
8105 /* Get the FW semaphore. */
8106 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008107 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008108 swsm = E1000_READ_REG(hw, SWSM);
8109 swsm |= E1000_SWSM_SWESMBI;
8110 E1000_WRITE_REG(hw, SWSM, swsm);
8111 /* if we managed to set the bit we got the semaphore. */
8112 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008113 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008114 break;
8115
8116 udelay(50);
8117 timeout--;
8118 }
8119
Auke Kok8fc897b2006-08-28 14:56:16 -07008120 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008121 /* Release semaphores */
8122 e1000_put_hw_eeprom_semaphore(hw);
8123 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8124 return -E1000_ERR_EEPROM;
8125 }
8126
8127 return E1000_SUCCESS;
8128}
8129
8130/***************************************************************************
8131 * This function clears HW semaphore bits.
8132 *
8133 * hw: Struct containing variables accessed by shared code
8134 *
8135 * returns: - None.
8136 *
8137 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008138static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008139e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8140{
8141 uint32_t swsm;
8142
8143 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8144
Auke Kok8fc897b2006-08-28 14:56:16 -07008145 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008146 return;
8147
8148 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008149 if (hw->mac_type == e1000_80003es2lan) {
8150 /* Release both semaphores. */
8151 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8152 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008153 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008154 E1000_WRITE_REG(hw, SWSM, swsm);
8155}
8156
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008157/***************************************************************************
8158 *
8159 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8160 *
8161 * hw: Struct containing variables accessed by shared code
8162 *
8163 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8164 * E1000_SUCCESS at any other case.
8165 *
8166 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008167static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008168e1000_get_software_semaphore(struct e1000_hw *hw)
8169{
8170 int32_t timeout = hw->eeprom.word_size + 1;
8171 uint32_t swsm;
8172
8173 DEBUGFUNC("e1000_get_software_semaphore");
8174
8175 if (hw->mac_type != e1000_80003es2lan)
8176 return E1000_SUCCESS;
8177
Auke Kok8fc897b2006-08-28 14:56:16 -07008178 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008179 swsm = E1000_READ_REG(hw, SWSM);
8180 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008181 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008182 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008183 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008184 timeout--;
8185 }
8186
Auke Kok8fc897b2006-08-28 14:56:16 -07008187 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008188 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8189 return -E1000_ERR_RESET;
8190 }
8191
8192 return E1000_SUCCESS;
8193}
8194
8195/***************************************************************************
8196 *
8197 * Release semaphore bit (SMBI).
8198 *
8199 * hw: Struct containing variables accessed by shared code
8200 *
8201 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008202static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008203e1000_release_software_semaphore(struct e1000_hw *hw)
8204{
8205 uint32_t swsm;
8206
8207 DEBUGFUNC("e1000_release_software_semaphore");
8208
8209 if (hw->mac_type != e1000_80003es2lan)
8210 return;
8211
8212 swsm = E1000_READ_REG(hw, SWSM);
8213 /* Release the SW semaphores.*/
8214 swsm &= ~E1000_SWSM_SMBI;
8215 E1000_WRITE_REG(hw, SWSM, swsm);
8216}
8217
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008218/******************************************************************************
8219 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8220 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8221 * the caller to figure out how to deal with it.
8222 *
8223 * hw - Struct containing variables accessed by shared code
8224 *
8225 * returns: - E1000_BLK_PHY_RESET
8226 * E1000_SUCCESS
8227 *
8228 *****************************************************************************/
8229int32_t
8230e1000_check_phy_reset_block(struct e1000_hw *hw)
8231{
8232 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008233 uint32_t fwsm = 0;
8234
8235 if (hw->mac_type == e1000_ich8lan) {
8236 fwsm = E1000_READ_REG(hw, FWSM);
8237 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8238 : E1000_BLK_PHY_RESET;
8239 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008240
8241 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008242 manc = E1000_READ_REG(hw, MANC);
8243 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8244 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8245}
8246
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008247static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008248e1000_arc_subsystem_valid(struct e1000_hw *hw)
8249{
8250 uint32_t fwsm;
8251
8252 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8253 * may not be provided a DMA clock when no manageability features are
8254 * enabled. We do not want to perform any reads/writes to these registers
8255 * if this is the case. We read FWSM to determine the manageability mode.
8256 */
8257 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008258 case e1000_82571:
8259 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008260 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008261 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008262 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008263 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008264 return TRUE;
8265 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008266 case e1000_ich8lan:
8267 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008268 default:
8269 break;
8270 }
8271 return FALSE;
8272}
8273
8274
Auke Kokd37ea5d2006-06-27 09:08:17 -07008275/******************************************************************************
8276 * Configure PCI-Ex no-snoop
8277 *
8278 * hw - Struct containing variables accessed by shared code.
8279 * no_snoop - Bitmap of no-snoop events.
8280 *
8281 * returns: E1000_SUCCESS
8282 *
8283 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008284static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008285e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8286{
8287 uint32_t gcr_reg = 0;
8288
8289 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8290
8291 if (hw->bus_type == e1000_bus_type_unknown)
8292 e1000_get_bus_info(hw);
8293
8294 if (hw->bus_type != e1000_bus_type_pci_express)
8295 return E1000_SUCCESS;
8296
8297 if (no_snoop) {
8298 gcr_reg = E1000_READ_REG(hw, GCR);
8299 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8300 gcr_reg |= no_snoop;
8301 E1000_WRITE_REG(hw, GCR, gcr_reg);
8302 }
8303 if (hw->mac_type == e1000_ich8lan) {
8304 uint32_t ctrl_ext;
8305
8306 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8307
8308 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8309 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8310 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8311 }
8312
8313 return E1000_SUCCESS;
8314}
8315
8316/***************************************************************************
8317 *
8318 * Get software semaphore FLAG bit (SWFLAG).
8319 * SWFLAG is used to synchronize the access to all shared resource between
8320 * SW, FW and HW.
8321 *
8322 * hw: Struct containing variables accessed by shared code
8323 *
8324 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008325static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008326e1000_get_software_flag(struct e1000_hw *hw)
8327{
8328 int32_t timeout = PHY_CFG_TIMEOUT;
8329 uint32_t extcnf_ctrl;
8330
8331 DEBUGFUNC("e1000_get_software_flag");
8332
8333 if (hw->mac_type == e1000_ich8lan) {
8334 while (timeout) {
8335 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8336 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8337 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8338
8339 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8340 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8341 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008342 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008343 timeout--;
8344 }
8345
8346 if (!timeout) {
8347 DEBUGOUT("FW or HW locks the resource too long.\n");
8348 return -E1000_ERR_CONFIG;
8349 }
8350 }
8351
8352 return E1000_SUCCESS;
8353}
8354
8355/***************************************************************************
8356 *
8357 * Release software semaphore FLAG bit (SWFLAG).
8358 * SWFLAG is used to synchronize the access to all shared resource between
8359 * SW, FW and HW.
8360 *
8361 * hw: Struct containing variables accessed by shared code
8362 *
8363 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008364static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008365e1000_release_software_flag(struct e1000_hw *hw)
8366{
8367 uint32_t extcnf_ctrl;
8368
8369 DEBUGFUNC("e1000_release_software_flag");
8370
8371 if (hw->mac_type == e1000_ich8lan) {
8372 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8373 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8374 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8375 }
8376
8377 return;
8378}
8379
8380/***************************************************************************
8381 *
8382 * Disable dynamic power down mode in ife PHY.
8383 * It can be used to workaround band-gap problem.
8384 *
8385 * hw: Struct containing variables accessed by shared code
8386 *
8387 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008388#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008389int32_t
8390e1000_ife_disable_dynamic_power_down(struct e1000_hw *hw)
8391{
8392 uint16_t phy_data;
8393 int32_t ret_val = E1000_SUCCESS;
8394
8395 DEBUGFUNC("e1000_ife_disable_dynamic_power_down");
8396
8397 if (hw->phy_type == e1000_phy_ife) {
8398 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8399 if (ret_val)
8400 return ret_val;
8401
8402 phy_data |= IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8403 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8404 }
8405
8406 return ret_val;
8407}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008408#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008409
8410/***************************************************************************
8411 *
8412 * Enable dynamic power down mode in ife PHY.
8413 * It can be used to workaround band-gap problem.
8414 *
8415 * hw: Struct containing variables accessed by shared code
8416 *
8417 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008418#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008419int32_t
8420e1000_ife_enable_dynamic_power_down(struct e1000_hw *hw)
8421{
8422 uint16_t phy_data;
8423 int32_t ret_val = E1000_SUCCESS;
8424
8425 DEBUGFUNC("e1000_ife_enable_dynamic_power_down");
8426
8427 if (hw->phy_type == e1000_phy_ife) {
8428 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8429 if (ret_val)
8430 return ret_val;
8431
8432 phy_data &= ~IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8433 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8434 }
8435
8436 return ret_val;
8437}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008438#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008439
8440/******************************************************************************
8441 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8442 * register.
8443 *
8444 * hw - Struct containing variables accessed by shared code
8445 * offset - offset of word in the EEPROM to read
8446 * data - word read from the EEPROM
8447 * words - number of words to read
8448 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008449static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008450e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8451 uint16_t *data)
8452{
8453 int32_t error = E1000_SUCCESS;
8454 uint32_t flash_bank = 0;
8455 uint32_t act_offset = 0;
8456 uint32_t bank_offset = 0;
8457 uint16_t word = 0;
8458 uint16_t i = 0;
8459
8460 /* We need to know which is the valid flash bank. In the event
8461 * that we didn't allocate eeprom_shadow_ram, we may not be
8462 * managing flash_bank. So it cannot be trusted and needs
8463 * to be updated with each read.
8464 */
8465 /* Value of bit 22 corresponds to the flash bank we're on. */
8466 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8467
8468 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8469 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8470
8471 error = e1000_get_software_flag(hw);
8472 if (error != E1000_SUCCESS)
8473 return error;
8474
8475 for (i = 0; i < words; i++) {
8476 if (hw->eeprom_shadow_ram != NULL &&
8477 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8478 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8479 } else {
8480 /* The NVM part needs a byte offset, hence * 2 */
8481 act_offset = bank_offset + ((offset + i) * 2);
8482 error = e1000_read_ich8_word(hw, act_offset, &word);
8483 if (error != E1000_SUCCESS)
8484 break;
8485 data[i] = word;
8486 }
8487 }
8488
8489 e1000_release_software_flag(hw);
8490
8491 return error;
8492}
8493
8494/******************************************************************************
8495 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8496 * register. Actually, writes are written to the shadow ram cache in the hw
8497 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8498 * the NVM, which occurs when the NVM checksum is updated.
8499 *
8500 * hw - Struct containing variables accessed by shared code
8501 * offset - offset of word in the EEPROM to write
8502 * words - number of words to write
8503 * data - words to write to the EEPROM
8504 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008505static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008506e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8507 uint16_t *data)
8508{
8509 uint32_t i = 0;
8510 int32_t error = E1000_SUCCESS;
8511
8512 error = e1000_get_software_flag(hw);
8513 if (error != E1000_SUCCESS)
8514 return error;
8515
8516 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8517 * allocated. Subsequent reads to the modified words are read from
8518 * this cached structure as well. Writes will only go into this
8519 * cached structure unless it's followed by a call to
8520 * e1000_update_eeprom_checksum() where it will commit the changes
8521 * and clear the "modified" field.
8522 */
8523 if (hw->eeprom_shadow_ram != NULL) {
8524 for (i = 0; i < words; i++) {
8525 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8526 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8527 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8528 } else {
8529 error = -E1000_ERR_EEPROM;
8530 break;
8531 }
8532 }
8533 } else {
8534 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8535 * as they don't perform any NVM writes. An attempt in doing so
8536 * will result in this error.
8537 */
8538 error = -E1000_ERR_EEPROM;
8539 }
8540
8541 e1000_release_software_flag(hw);
8542
8543 return error;
8544}
8545
8546/******************************************************************************
8547 * This function does initial flash setup so that a new read/write/erase cycle
8548 * can be started.
8549 *
8550 * hw - The pointer to the hw structure
8551 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008552static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008553e1000_ich8_cycle_init(struct e1000_hw *hw)
8554{
8555 union ich8_hws_flash_status hsfsts;
8556 int32_t error = E1000_ERR_EEPROM;
8557 int32_t i = 0;
8558
8559 DEBUGFUNC("e1000_ich8_cycle_init");
8560
8561 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8562
8563 /* May be check the Flash Des Valid bit in Hw status */
8564 if (hsfsts.hsf_status.fldesvalid == 0) {
8565 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8566 return error;
8567 }
8568
8569 /* Clear FCERR in Hw status by writing 1 */
8570 /* Clear DAEL in Hw status by writing a 1 */
8571 hsfsts.hsf_status.flcerr = 1;
8572 hsfsts.hsf_status.dael = 1;
8573
8574 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8575
8576 /* Either we should have a hardware SPI cycle in progress bit to check
8577 * against, in order to start a new cycle or FDONE bit should be changed
8578 * in the hardware so that it is 1 after harware reset, which can then be
8579 * used as an indication whether a cycle is in progress or has been
8580 * completed .. we should also have some software semaphore mechanism to
8581 * guard FDONE or the cycle in progress bit so that two threads access to
8582 * those bits can be sequentiallized or a way so that 2 threads dont
8583 * start the cycle at the same time */
8584
8585 if (hsfsts.hsf_status.flcinprog == 0) {
8586 /* There is no cycle running at present, so we can start a cycle */
8587 /* Begin by setting Flash Cycle Done. */
8588 hsfsts.hsf_status.flcdone = 1;
8589 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8590 error = E1000_SUCCESS;
8591 } else {
8592 /* otherwise poll for sometime so the current cycle has a chance
8593 * to end before giving up. */
8594 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8595 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8596 if (hsfsts.hsf_status.flcinprog == 0) {
8597 error = E1000_SUCCESS;
8598 break;
8599 }
8600 udelay(1);
8601 }
8602 if (error == E1000_SUCCESS) {
8603 /* Successful in waiting for previous cycle to timeout,
8604 * now set the Flash Cycle Done. */
8605 hsfsts.hsf_status.flcdone = 1;
8606 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8607 } else {
8608 DEBUGOUT("Flash controller busy, cannot get access");
8609 }
8610 }
8611 return error;
8612}
8613
8614/******************************************************************************
8615 * This function starts a flash cycle and waits for its completion
8616 *
8617 * hw - The pointer to the hw structure
8618 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008619static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008620e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8621{
8622 union ich8_hws_flash_ctrl hsflctl;
8623 union ich8_hws_flash_status hsfsts;
8624 int32_t error = E1000_ERR_EEPROM;
8625 uint32_t i = 0;
8626
8627 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8628 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8629 hsflctl.hsf_ctrl.flcgo = 1;
8630 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8631
8632 /* wait till FDONE bit is set to 1 */
8633 do {
8634 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8635 if (hsfsts.hsf_status.flcdone == 1)
8636 break;
8637 udelay(1);
8638 i++;
8639 } while (i < timeout);
8640 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8641 error = E1000_SUCCESS;
8642 }
8643 return error;
8644}
8645
8646/******************************************************************************
8647 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8648 *
8649 * hw - The pointer to the hw structure
8650 * index - The index of the byte or word to read.
8651 * size - Size of data to read, 1=byte 2=word
8652 * data - Pointer to the word to store the value read.
8653 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008654static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008655e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8656 uint32_t size, uint16_t* data)
8657{
8658 union ich8_hws_flash_status hsfsts;
8659 union ich8_hws_flash_ctrl hsflctl;
8660 uint32_t flash_linear_address;
8661 uint32_t flash_data = 0;
8662 int32_t error = -E1000_ERR_EEPROM;
8663 int32_t count = 0;
8664
8665 DEBUGFUNC("e1000_read_ich8_data");
8666
8667 if (size < 1 || size > 2 || data == 0x0 ||
8668 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8669 return error;
8670
8671 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8672 hw->flash_base_addr;
8673
8674 do {
8675 udelay(1);
8676 /* Steps */
8677 error = e1000_ich8_cycle_init(hw);
8678 if (error != E1000_SUCCESS)
8679 break;
8680
8681 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8682 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8683 hsflctl.hsf_ctrl.fldbcount = size - 1;
8684 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8685 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8686
8687 /* Write the last 24 bits of index into Flash Linear address field in
8688 * Flash Address */
8689 /* TODO: TBD maybe check the index against the size of flash */
8690
8691 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8692
8693 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8694
8695 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8696 * sequence a few more times, else read in (shift in) the Flash Data0,
8697 * the order is least significant byte first msb to lsb */
8698 if (error == E1000_SUCCESS) {
8699 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8700 if (size == 1) {
8701 *data = (uint8_t)(flash_data & 0x000000FF);
8702 } else if (size == 2) {
8703 *data = (uint16_t)(flash_data & 0x0000FFFF);
8704 }
8705 break;
8706 } else {
8707 /* If we've gotten here, then things are probably completely hosed,
8708 * but if the error condition is detected, it won't hurt to give
8709 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8710 */
8711 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8712 if (hsfsts.hsf_status.flcerr == 1) {
8713 /* Repeat for some time before giving up. */
8714 continue;
8715 } else if (hsfsts.hsf_status.flcdone == 0) {
8716 DEBUGOUT("Timeout error - flash cycle did not complete.");
8717 break;
8718 }
8719 }
8720 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8721
8722 return error;
8723}
8724
8725/******************************************************************************
8726 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8727 *
8728 * hw - The pointer to the hw structure
8729 * index - The index of the byte/word to read.
8730 * size - Size of data to read, 1=byte 2=word
8731 * data - The byte(s) to write to the NVM.
8732 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008733static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008734e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8735 uint16_t data)
8736{
8737 union ich8_hws_flash_status hsfsts;
8738 union ich8_hws_flash_ctrl hsflctl;
8739 uint32_t flash_linear_address;
8740 uint32_t flash_data = 0;
8741 int32_t error = -E1000_ERR_EEPROM;
8742 int32_t count = 0;
8743
8744 DEBUGFUNC("e1000_write_ich8_data");
8745
8746 if (size < 1 || size > 2 || data > size * 0xff ||
8747 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8748 return error;
8749
8750 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8751 hw->flash_base_addr;
8752
8753 do {
8754 udelay(1);
8755 /* Steps */
8756 error = e1000_ich8_cycle_init(hw);
8757 if (error != E1000_SUCCESS)
8758 break;
8759
8760 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8761 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8762 hsflctl.hsf_ctrl.fldbcount = size -1;
8763 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8764 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8765
8766 /* Write the last 24 bits of index into Flash Linear address field in
8767 * Flash Address */
8768 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8769
8770 if (size == 1)
8771 flash_data = (uint32_t)data & 0x00FF;
8772 else
8773 flash_data = (uint32_t)data;
8774
8775 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8776
8777 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8778 * sequence a few more times else done */
8779 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8780 if (error == E1000_SUCCESS) {
8781 break;
8782 } else {
8783 /* If we're here, then things are most likely completely hosed,
8784 * but if the error condition is detected, it won't hurt to give
8785 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8786 */
8787 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8788 if (hsfsts.hsf_status.flcerr == 1) {
8789 /* Repeat for some time before giving up. */
8790 continue;
8791 } else if (hsfsts.hsf_status.flcdone == 0) {
8792 DEBUGOUT("Timeout error - flash cycle did not complete.");
8793 break;
8794 }
8795 }
8796 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8797
8798 return error;
8799}
8800
8801/******************************************************************************
8802 * Reads a single byte from the NVM using the ICH8 flash access registers.
8803 *
8804 * hw - pointer to e1000_hw structure
8805 * index - The index of the byte to read.
8806 * data - Pointer to a byte to store the value read.
8807 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008808static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008809e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8810{
8811 int32_t status = E1000_SUCCESS;
8812 uint16_t word = 0;
8813
8814 status = e1000_read_ich8_data(hw, index, 1, &word);
8815 if (status == E1000_SUCCESS) {
8816 *data = (uint8_t)word;
8817 }
8818
8819 return status;
8820}
8821
8822/******************************************************************************
8823 * Writes a single byte to the NVM using the ICH8 flash access registers.
8824 * Performs verification by reading back the value and then going through
8825 * a retry algorithm before giving up.
8826 *
8827 * hw - pointer to e1000_hw structure
8828 * index - The index of the byte to write.
8829 * byte - The byte to write to the NVM.
8830 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008831static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008832e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8833{
8834 int32_t error = E1000_SUCCESS;
8835 int32_t program_retries;
8836 uint8_t temp_byte;
8837
8838 e1000_write_ich8_byte(hw, index, byte);
8839 udelay(100);
8840
8841 for (program_retries = 0; program_retries < 100; program_retries++) {
8842 e1000_read_ich8_byte(hw, index, &temp_byte);
8843 if (temp_byte == byte)
8844 break;
8845 udelay(10);
8846 e1000_write_ich8_byte(hw, index, byte);
8847 udelay(100);
8848 }
8849 if (program_retries == 100)
8850 error = E1000_ERR_EEPROM;
8851
8852 return error;
8853}
8854
8855/******************************************************************************
8856 * Writes a single byte to the NVM using the ICH8 flash access registers.
8857 *
8858 * hw - pointer to e1000_hw structure
8859 * index - The index of the byte to read.
8860 * data - The byte to write to the NVM.
8861 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008862static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008863e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8864{
8865 int32_t status = E1000_SUCCESS;
8866 uint16_t word = (uint16_t)data;
8867
8868 status = e1000_write_ich8_data(hw, index, 1, word);
8869
8870 return status;
8871}
8872
8873/******************************************************************************
8874 * Reads a word from the NVM using the ICH8 flash access registers.
8875 *
8876 * hw - pointer to e1000_hw structure
8877 * index - The starting byte index of the word to read.
8878 * data - Pointer to a word to store the value read.
8879 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008880static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008881e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8882{
8883 int32_t status = E1000_SUCCESS;
8884 status = e1000_read_ich8_data(hw, index, 2, data);
8885 return status;
8886}
8887
8888/******************************************************************************
8889 * Writes a word to the NVM using the ICH8 flash access registers.
8890 *
8891 * hw - pointer to e1000_hw structure
8892 * index - The starting byte index of the word to read.
8893 * data - The word to write to the NVM.
8894 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008895#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008896int32_t
8897e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8898{
8899 int32_t status = E1000_SUCCESS;
8900 status = e1000_write_ich8_data(hw, index, 2, data);
8901 return status;
8902}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008903#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008904
8905/******************************************************************************
8906 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8907 * segment N is 4096 * N + flash_reg_addr.
8908 *
8909 * hw - pointer to e1000_hw structure
8910 * segment - 0 for first segment, 1 for second segment, etc.
8911 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008912static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008913e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8914{
8915 union ich8_hws_flash_status hsfsts;
8916 union ich8_hws_flash_ctrl hsflctl;
8917 uint32_t flash_linear_address;
8918 int32_t count = 0;
8919 int32_t error = E1000_ERR_EEPROM;
8920 int32_t iteration, seg_size;
8921 int32_t sector_size;
8922 int32_t j = 0;
8923 int32_t error_flag = 0;
8924
8925 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8926
8927 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8928 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8929 * consecutive sectors. The start index for the nth Hw sector can be
8930 * calculated as = segment * 4096 + n * 256
8931 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8932 * The start index for the nth Hw sector can be calculated
8933 * as = segment * 4096
8934 * 10: Error condition
8935 * 11: The Hw sector size is much bigger than the size asked to
8936 * erase...error condition */
8937 if (hsfsts.hsf_status.berasesz == 0x0) {
8938 /* Hw sector size 256 */
8939 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256;
8940 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8941 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8942 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K;
8943 iteration = 1;
8944 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8945 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K;
8946 iteration = 1;
8947 } else {
8948 return error;
8949 }
8950
8951 for (j = 0; j < iteration ; j++) {
8952 do {
8953 count++;
8954 /* Steps */
8955 error = e1000_ich8_cycle_init(hw);
8956 if (error != E1000_SUCCESS) {
8957 error_flag = 1;
8958 break;
8959 }
8960
8961 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8962 * Control */
8963 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8964 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8965 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8966
8967 /* Write the last 24 bits of an index within the block into Flash
8968 * Linear address field in Flash Address. This probably needs to
8969 * be calculated here based off the on-chip segment size and the
8970 * software segment size assumed (4K) */
8971 /* TBD */
8972 flash_linear_address = segment * sector_size + j * seg_size;
8973 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8974 flash_linear_address += hw->flash_base_addr;
8975
8976 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8977
8978 error = e1000_ich8_flash_cycle(hw, 1000000);
8979 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8980 * sequence a few more times else Done */
8981 if (error == E1000_SUCCESS) {
8982 break;
8983 } else {
8984 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8985 if (hsfsts.hsf_status.flcerr == 1) {
8986 /* repeat for some time before giving up */
8987 continue;
8988 } else if (hsfsts.hsf_status.flcdone == 0) {
8989 error_flag = 1;
8990 break;
8991 }
8992 }
8993 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8994 if (error_flag == 1)
8995 break;
8996 }
8997 if (error_flag != 1)
8998 error = E1000_SUCCESS;
8999 return error;
9000}
9001
9002/******************************************************************************
9003 *
9004 * Reverse duplex setting without breaking the link.
9005 *
9006 * hw: Struct containing variables accessed by shared code
9007 *
9008 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07009009#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07009010int32_t
9011e1000_duplex_reversal(struct e1000_hw *hw)
9012{
9013 int32_t ret_val;
9014 uint16_t phy_data;
9015
9016 if (hw->phy_type != e1000_phy_igp_3)
9017 return E1000_SUCCESS;
9018
9019 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
9020 if (ret_val)
9021 return ret_val;
9022
9023 phy_data ^= MII_CR_FULL_DUPLEX;
9024
9025 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
9026 if (ret_val)
9027 return ret_val;
9028
9029 ret_val = e1000_read_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, &phy_data);
9030 if (ret_val)
9031 return ret_val;
9032
9033 phy_data |= IGP3_PHY_MISC_DUPLEX_MANUAL_SET;
9034 ret_val = e1000_write_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, phy_data);
9035
9036 return ret_val;
9037}
Adrian Bunke4c780b2006-08-14 23:00:10 -07009038#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07009039
Adrian Bunke4c780b2006-08-14 23:00:10 -07009040static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07009041e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9042 uint32_t cnf_base_addr, uint32_t cnf_size)
9043{
9044 uint32_t ret_val = E1000_SUCCESS;
9045 uint16_t word_addr, reg_data, reg_addr;
9046 uint16_t i;
9047
9048 /* cnf_base_addr is in DWORD */
9049 word_addr = (uint16_t)(cnf_base_addr << 1);
9050
9051 /* cnf_size is returned in size of dwords */
9052 for (i = 0; i < cnf_size; i++) {
9053 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
9054 if (ret_val)
9055 return ret_val;
9056
9057 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
9058 if (ret_val)
9059 return ret_val;
9060
9061 ret_val = e1000_get_software_flag(hw);
9062 if (ret_val != E1000_SUCCESS)
9063 return ret_val;
9064
9065 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
9066
9067 e1000_release_software_flag(hw);
9068 }
9069
9070 return ret_val;
9071}
9072
9073
Adrian Bunke4c780b2006-08-14 23:00:10 -07009074static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07009075e1000_init_lcd_from_nvm(struct e1000_hw *hw)
9076{
9077 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
9078
9079 if (hw->phy_type != e1000_phy_igp_3)
9080 return E1000_SUCCESS;
9081
9082 /* Check if SW needs configure the PHY */
9083 reg_data = E1000_READ_REG(hw, FEXTNVM);
9084 if (!(reg_data & FEXTNVM_SW_CONFIG))
9085 return E1000_SUCCESS;
9086
9087 /* Wait for basic configuration completes before proceeding*/
9088 loop = 0;
9089 do {
9090 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9091 udelay(100);
9092 loop++;
9093 } while ((!reg_data) && (loop < 50));
9094
9095 /* Clear the Init Done bit for the next init event */
9096 reg_data = E1000_READ_REG(hw, STATUS);
9097 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9098 E1000_WRITE_REG(hw, STATUS, reg_data);
9099
9100 /* Make sure HW does not configure LCD from PHY extended configuration
9101 before SW configuration */
9102 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9103 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9104 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9105 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9106 cnf_size >>= 16;
9107 if (cnf_size) {
9108 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9109 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9110 /* cnf_base_addr is in DWORD */
9111 cnf_base_addr >>= 16;
9112
9113 /* Configure LCD from extended configuration region. */
9114 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9115 cnf_size);
9116 if (ret_val)
9117 return ret_val;
9118 }
9119 }
9120
9121 return E1000_SUCCESS;
9122}
9123
9124
Malli Chilakala2d7edb92005-04-28 19:43:52 -07009125