blob: 8a7d7da4cd61da9096f45af9686dece08d9d37ae [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
36static int32_t e1000_set_phy_type(struct e1000_hw *hw);
37static void e1000_phy_init_script(struct e1000_hw *hw);
38static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
39static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
40static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
41static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
42static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
43static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
45static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 uint16_t count);
47static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
48static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
49static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
50 uint16_t words, uint16_t *data);
51static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
52 uint16_t offset, uint16_t words,
53 uint16_t *data);
54static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
55static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
57static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 uint16_t count);
59static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 uint16_t phy_data);
61static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 uint16_t *phy_data);
63static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
64static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
65static void e1000_release_eeprom(struct e1000_hw *hw);
66static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
69static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -070070static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
71static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010072static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
73static int32_t e1000_check_downshift(struct e1000_hw *hw);
Jeff Kirsher70c6f302006-09-27 12:53:31 -070074static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010075static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
76static void e1000_clear_vfta(struct e1000_hw *hw);
77static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
78static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
79 boolean_t link_up);
80static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
81static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
82static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
83static int32_t e1000_get_cable_length(struct e1000_hw *hw,
84 uint16_t *min_length,
85 uint16_t *max_length);
86static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
87static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
88static int32_t e1000_id_led_init(struct e1000_hw * hw);
89static void e1000_init_rx_addrs(struct e1000_hw *hw);
90static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
91static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
92static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
93static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
94 uint16_t words, uint16_t *data);
95static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
96static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
97static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
98
99static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
100 uint32_t value);
101
102#define E1000_WRITE_REG_IO(a, reg, val) \
103 e1000_write_reg_io((a), E1000_##reg, val)
Auke Kokcd94dd02006-06-27 09:08:22 -0700104static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
105 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800106static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Adrian Bunke4c780b2006-08-14 23:00:10 -0700108static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw,
109 uint32_t segment);
110static int32_t e1000_get_software_flag(struct e1000_hw *hw);
111static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
112static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
113static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
114static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
115 uint16_t words, uint16_t *data);
116static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index,
117 uint8_t* data);
118static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index,
119 uint16_t *data);
120static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
121 uint16_t *data);
122static void e1000_release_software_flag(struct e1000_hw *hw);
123static void e1000_release_software_semaphore(struct e1000_hw *hw);
124static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw,
125 uint32_t no_snoop);
126static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw,
127 uint32_t index, uint8_t byte);
128static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
129 uint16_t words, uint16_t *data);
130static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index,
131 uint8_t data);
132static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
133 uint16_t data);
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* IGP cable length table */
136static const
137uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
138 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
139 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
140 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
141 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
142 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
143 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
144 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
145 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
146
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700147static const
148uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400149 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
150 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
151 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
152 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
153 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
154 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
155 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
156 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159/******************************************************************************
160 * Set the phy type member in the hw struct.
161 *
162 * hw - Struct containing variables accessed by shared code
163 *****************************************************************************/
164int32_t
165e1000_set_phy_type(struct e1000_hw *hw)
166{
167 DEBUGFUNC("e1000_set_phy_type");
168
Auke Kok8fc897b2006-08-28 14:56:16 -0700169 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700170 return -E1000_ERR_PHY_TYPE;
171
Auke Kok8fc897b2006-08-28 14:56:16 -0700172 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 case M88E1000_E_PHY_ID:
174 case M88E1000_I_PHY_ID:
175 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700176 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 hw->phy_type = e1000_phy_m88;
178 break;
179 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700180 if (hw->mac_type == e1000_82541 ||
181 hw->mac_type == e1000_82541_rev_2 ||
182 hw->mac_type == e1000_82547 ||
183 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 hw->phy_type = e1000_phy_igp;
185 break;
186 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700187 case IGP03E1000_E_PHY_ID:
188 hw->phy_type = e1000_phy_igp_3;
189 break;
190 case IFE_E_PHY_ID:
191 case IFE_PLUS_E_PHY_ID:
192 case IFE_C_E_PHY_ID:
193 hw->phy_type = e1000_phy_ife;
194 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800195 case GG82563_E_PHY_ID:
196 if (hw->mac_type == e1000_80003es2lan) {
197 hw->phy_type = e1000_phy_gg82563;
198 break;
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 /* Fall Through */
201 default:
202 /* Should never have loaded on this device */
203 hw->phy_type = e1000_phy_undefined;
204 return -E1000_ERR_PHY_TYPE;
205 }
206
207 return E1000_SUCCESS;
208}
209
Auke Kok8fc897b2006-08-28 14:56:16 -0700210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/******************************************************************************
212 * IGP phy init script - initializes the GbE PHY
213 *
214 * hw - Struct containing variables accessed by shared code
215 *****************************************************************************/
216static void
217e1000_phy_init_script(struct e1000_hw *hw)
218{
219 uint32_t ret_val;
220 uint16_t phy_saved_data;
221
222 DEBUGFUNC("e1000_phy_init_script");
223
Auke Kok8fc897b2006-08-28 14:56:16 -0700224 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400225 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 /* Save off the current value of register 0x2F5B to be restored at
228 * the end of this routine. */
229 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
230
231 /* Disabled the PHY transmitter */
232 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
233
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400234 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 e1000_write_phy_reg(hw,0x0000,0x0140);
237
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400238 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Auke Kok8fc897b2006-08-28 14:56:16 -0700240 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 case e1000_82541:
242 case e1000_82547:
243 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
244
245 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
246
247 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
248
249 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
250
251 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
252
253 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
254
255 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
256
257 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
258
259 e1000_write_phy_reg(hw, 0x2010, 0x0008);
260 break;
261
262 case e1000_82541_rev_2:
263 case e1000_82547_rev_2:
264 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
265 break;
266 default:
267 break;
268 }
269
270 e1000_write_phy_reg(hw, 0x0000, 0x3300);
271
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400272 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 /* Now enable the transmitter */
275 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
276
Auke Kok8fc897b2006-08-28 14:56:16 -0700277 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 uint16_t fused, fine, coarse;
279
280 /* Move to analog registers page */
281 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
282
Auke Kok8fc897b2006-08-28 14:56:16 -0700283 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
285
286 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
287 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
288
Auke Kok8fc897b2006-08-28 14:56:16 -0700289 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
291 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700292 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
294
295 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
296 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
297 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
298
299 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
300 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
301 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
302 }
303 }
304 }
305}
306
307/******************************************************************************
308 * Set the mac type member in the hw struct.
309 *
310 * hw - Struct containing variables accessed by shared code
311 *****************************************************************************/
312int32_t
313e1000_set_mac_type(struct e1000_hw *hw)
314{
315 DEBUGFUNC("e1000_set_mac_type");
316
317 switch (hw->device_id) {
318 case E1000_DEV_ID_82542:
319 switch (hw->revision_id) {
320 case E1000_82542_2_0_REV_ID:
321 hw->mac_type = e1000_82542_rev2_0;
322 break;
323 case E1000_82542_2_1_REV_ID:
324 hw->mac_type = e1000_82542_rev2_1;
325 break;
326 default:
327 /* Invalid 82542 revision ID */
328 return -E1000_ERR_MAC_TYPE;
329 }
330 break;
331 case E1000_DEV_ID_82543GC_FIBER:
332 case E1000_DEV_ID_82543GC_COPPER:
333 hw->mac_type = e1000_82543;
334 break;
335 case E1000_DEV_ID_82544EI_COPPER:
336 case E1000_DEV_ID_82544EI_FIBER:
337 case E1000_DEV_ID_82544GC_COPPER:
338 case E1000_DEV_ID_82544GC_LOM:
339 hw->mac_type = e1000_82544;
340 break;
341 case E1000_DEV_ID_82540EM:
342 case E1000_DEV_ID_82540EM_LOM:
343 case E1000_DEV_ID_82540EP:
344 case E1000_DEV_ID_82540EP_LOM:
345 case E1000_DEV_ID_82540EP_LP:
346 hw->mac_type = e1000_82540;
347 break;
348 case E1000_DEV_ID_82545EM_COPPER:
349 case E1000_DEV_ID_82545EM_FIBER:
350 hw->mac_type = e1000_82545;
351 break;
352 case E1000_DEV_ID_82545GM_COPPER:
353 case E1000_DEV_ID_82545GM_FIBER:
354 case E1000_DEV_ID_82545GM_SERDES:
355 hw->mac_type = e1000_82545_rev_3;
356 break;
357 case E1000_DEV_ID_82546EB_COPPER:
358 case E1000_DEV_ID_82546EB_FIBER:
359 case E1000_DEV_ID_82546EB_QUAD_COPPER:
360 hw->mac_type = e1000_82546;
361 break;
362 case E1000_DEV_ID_82546GB_COPPER:
363 case E1000_DEV_ID_82546GB_FIBER:
364 case E1000_DEV_ID_82546GB_SERDES:
365 case E1000_DEV_ID_82546GB_PCIE:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800366 case E1000_DEV_ID_82546GB_QUAD_COPPER:
367 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 hw->mac_type = e1000_82546_rev_3;
369 break;
370 case E1000_DEV_ID_82541EI:
371 case E1000_DEV_ID_82541EI_MOBILE:
Auke Kokcd94dd02006-06-27 09:08:22 -0700372 case E1000_DEV_ID_82541ER_LOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 hw->mac_type = e1000_82541;
374 break;
375 case E1000_DEV_ID_82541ER:
376 case E1000_DEV_ID_82541GI:
377 case E1000_DEV_ID_82541GI_LF:
378 case E1000_DEV_ID_82541GI_MOBILE:
379 hw->mac_type = e1000_82541_rev_2;
380 break;
381 case E1000_DEV_ID_82547EI:
Auke Kokcd94dd02006-06-27 09:08:22 -0700382 case E1000_DEV_ID_82547EI_MOBILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 hw->mac_type = e1000_82547;
384 break;
385 case E1000_DEV_ID_82547GI:
386 hw->mac_type = e1000_82547_rev_2;
387 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400388 case E1000_DEV_ID_82571EB_COPPER:
389 case E1000_DEV_ID_82571EB_FIBER:
390 case E1000_DEV_ID_82571EB_SERDES:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700391 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400392 hw->mac_type = e1000_82571;
393 break;
394 case E1000_DEV_ID_82572EI_COPPER:
395 case E1000_DEV_ID_82572EI_FIBER:
396 case E1000_DEV_ID_82572EI_SERDES:
Auke Kokcd94dd02006-06-27 09:08:22 -0700397 case E1000_DEV_ID_82572EI:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400398 hw->mac_type = e1000_82572;
399 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700400 case E1000_DEV_ID_82573E:
401 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400402 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700403 hw->mac_type = e1000_82573;
404 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700405 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
406 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800407 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
408 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
409 hw->mac_type = e1000_80003es2lan;
410 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700411 case E1000_DEV_ID_ICH8_IGP_M_AMT:
412 case E1000_DEV_ID_ICH8_IGP_AMT:
413 case E1000_DEV_ID_ICH8_IGP_C:
414 case E1000_DEV_ID_ICH8_IFE:
415 case E1000_DEV_ID_ICH8_IGP_M:
416 hw->mac_type = e1000_ich8lan;
417 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 default:
419 /* Should never have loaded on this device */
420 return -E1000_ERR_MAC_TYPE;
421 }
422
Auke Kok8fc897b2006-08-28 14:56:16 -0700423 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700424 case e1000_ich8lan:
425 hw->swfwhw_semaphore_present = TRUE;
426 hw->asf_firmware_present = TRUE;
427 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800428 case e1000_80003es2lan:
429 hw->swfw_sync_present = TRUE;
430 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400431 case e1000_82571:
432 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700433 case e1000_82573:
434 hw->eeprom_semaphore_present = TRUE;
435 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 case e1000_82541:
437 case e1000_82547:
438 case e1000_82541_rev_2:
439 case e1000_82547_rev_2:
440 hw->asf_firmware_present = TRUE;
441 break;
442 default:
443 break;
444 }
445
446 return E1000_SUCCESS;
447}
448
449/*****************************************************************************
450 * Set media type and TBI compatibility.
451 *
452 * hw - Struct containing variables accessed by shared code
453 * **************************************************************************/
454void
455e1000_set_media_type(struct e1000_hw *hw)
456{
457 uint32_t status;
458
459 DEBUGFUNC("e1000_set_media_type");
460
Auke Kok8fc897b2006-08-28 14:56:16 -0700461 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 /* tbi_compatibility is only valid on 82543 */
463 hw->tbi_compatibility_en = FALSE;
464 }
465
466 switch (hw->device_id) {
467 case E1000_DEV_ID_82545GM_SERDES:
468 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400469 case E1000_DEV_ID_82571EB_SERDES:
470 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800471 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 hw->media_type = e1000_media_type_internal_serdes;
473 break;
474 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700475 switch (hw->mac_type) {
476 case e1000_82542_rev2_0:
477 case e1000_82542_rev2_1:
478 hw->media_type = e1000_media_type_fiber;
479 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700480 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700481 case e1000_82573:
482 /* The STATUS_TBIMODE bit is reserved or reused for the this
483 * device.
484 */
485 hw->media_type = e1000_media_type_copper;
486 break;
487 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700489 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 hw->media_type = e1000_media_type_fiber;
491 /* tbi_compatibility not valid on fiber */
492 hw->tbi_compatibility_en = FALSE;
493 } else {
494 hw->media_type = e1000_media_type_copper;
495 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498 }
499}
500
501/******************************************************************************
502 * Reset the transmit and receive units; mask and clear all interrupts.
503 *
504 * hw - Struct containing variables accessed by shared code
505 *****************************************************************************/
506int32_t
507e1000_reset_hw(struct e1000_hw *hw)
508{
509 uint32_t ctrl;
510 uint32_t ctrl_ext;
511 uint32_t icr;
512 uint32_t manc;
513 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700514 uint32_t timeout;
515 uint32_t extcnf_ctrl;
516 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 DEBUGFUNC("e1000_reset_hw");
519
520 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700521 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
523 e1000_pci_clear_mwi(hw);
524 }
525
Auke Kok8fc897b2006-08-28 14:56:16 -0700526 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700527 /* Prevent the PCI-E bus from sticking if there is no TLP connection
528 * on the last TLP read/write transaction when MAC is reset.
529 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700530 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700531 DEBUGOUT("PCI-E Master disable polling has failed.\n");
532 }
533 }
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* Clear interrupt mask to stop board from generating interrupts */
536 DEBUGOUT("Masking off all interrupts\n");
537 E1000_WRITE_REG(hw, IMC, 0xffffffff);
538
539 /* Disable the Transmit and Receive units. Then delay to allow
540 * any pending transactions to complete before we hit the MAC with
541 * the global reset.
542 */
543 E1000_WRITE_REG(hw, RCTL, 0);
544 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
545 E1000_WRITE_FLUSH(hw);
546
547 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
548 hw->tbi_compatibility_on = FALSE;
549
550 /* Delay to allow any outstanding PCI transactions to complete before
551 * resetting the device
552 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400553 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 ctrl = E1000_READ_REG(hw, CTRL);
556
557 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700558 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700559 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400560 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700563 /* Must acquire the MDIO ownership before MAC reset.
564 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700565 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700566 timeout = 10;
567
568 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
569 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
570
571 do {
572 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
573 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
574
Auke Kok8fc897b2006-08-28 14:56:16 -0700575 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700576 break;
577 else
578 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
579
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400580 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700581 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700582 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700583 }
584
Auke Kokcd94dd02006-06-27 09:08:22 -0700585 /* Workaround for ICH8 bit corruption issue in FIFO memory */
586 if (hw->mac_type == e1000_ich8lan) {
587 /* Set Tx and Rx buffer allocation to 8k apiece. */
588 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
589 /* Set Packet Buffer Size to 16k. */
590 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
591 }
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 /* Issue a global reset to the MAC. This will reset the chip's
594 * transmit, receive, DMA, and link units. It will not effect
595 * the current PCI configuration. The global reset bit is self-
596 * clearing, and should clear within a microsecond.
597 */
598 DEBUGOUT("Issuing a global reset to MAC\n");
599
Auke Kok8fc897b2006-08-28 14:56:16 -0700600 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 case e1000_82544:
602 case e1000_82540:
603 case e1000_82545:
604 case e1000_82546:
605 case e1000_82541:
606 case e1000_82541_rev_2:
607 /* These controllers can't ack the 64-bit write when issuing the
608 * reset, so use IO-mapping as a workaround to issue the reset */
609 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
610 break;
611 case e1000_82545_rev_3:
612 case e1000_82546_rev_3:
613 /* Reset is performed on a shadow of the control register */
614 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
615 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700616 case e1000_ich8lan:
617 if (!hw->phy_reset_disable &&
618 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
619 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
620 * at the same time to make sure the interface between
621 * MAC and the external PHY is reset.
622 */
623 ctrl |= E1000_CTRL_PHY_RST;
624 }
625
626 e1000_get_software_flag(hw);
627 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400628 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700629 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 default:
631 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
632 break;
633 }
634
635 /* After MAC reset, force reload of EEPROM to restore power-on settings to
636 * device. Later controllers reload the EEPROM automatically, so just wait
637 * for reload to complete.
638 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700639 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 case e1000_82542_rev2_0:
641 case e1000_82542_rev2_1:
642 case e1000_82543:
643 case e1000_82544:
644 /* Wait for reset to complete */
645 udelay(10);
646 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
647 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
648 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
649 E1000_WRITE_FLUSH(hw);
650 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400651 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 break;
653 case e1000_82541:
654 case e1000_82541_rev_2:
655 case e1000_82547:
656 case e1000_82547_rev_2:
657 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400658 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700660 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500661 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
662 udelay(10);
663 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
664 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
665 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
666 E1000_WRITE_FLUSH(hw);
667 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700668 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400669 case e1000_82571:
670 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -0700671 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800672 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700673 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700674 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700675 /* We don't want to continue accessing MAC registers. */
676 return ret_val;
677 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 default:
679 /* Wait for EEPROM reload (it happens automatically) */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400680 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
682 }
683
684 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700685 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 manc = E1000_READ_REG(hw, MANC);
687 manc &= ~(E1000_MANC_ARP_EN);
688 E1000_WRITE_REG(hw, MANC, manc);
689 }
690
Auke Kok8fc897b2006-08-28 14:56:16 -0700691 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 e1000_phy_init_script(hw);
693
694 /* Configure activity LED after PHY reset */
695 led_ctrl = E1000_READ_REG(hw, LEDCTL);
696 led_ctrl &= IGP_ACTIVITY_LED_MASK;
697 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
698 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
699 }
700
701 /* Clear interrupt mask to stop board from generating interrupts */
702 DEBUGOUT("Masking off all interrupts\n");
703 E1000_WRITE_REG(hw, IMC, 0xffffffff);
704
705 /* Clear any pending interrupt events. */
706 icr = E1000_READ_REG(hw, ICR);
707
708 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700709 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400710 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 e1000_pci_set_mwi(hw);
712 }
713
Auke Kokcd94dd02006-06-27 09:08:22 -0700714 if (hw->mac_type == e1000_ich8lan) {
715 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
716 kab |= E1000_KABGTXD_BGSQLBIAS;
717 E1000_WRITE_REG(hw, KABGTXD, kab);
718 }
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 return E1000_SUCCESS;
721}
722
723/******************************************************************************
724 * Performs basic configuration of the adapter.
725 *
726 * hw - Struct containing variables accessed by shared code
727 *
728 * Assumes that the controller has previously been reset and is in a
729 * post-reset uninitialized state. Initializes the receive address registers,
730 * multicast table, and VLAN filter table. Calls routines to setup link
731 * configuration and flow control settings. Clears all on-chip counters. Leaves
732 * the transmit and receive units disabled and uninitialized.
733 *****************************************************************************/
734int32_t
735e1000_init_hw(struct e1000_hw *hw)
736{
737 uint32_t ctrl;
738 uint32_t i;
739 int32_t ret_val;
740 uint16_t pcix_cmd_word;
741 uint16_t pcix_stat_hi_word;
742 uint16_t cmd_mmrbc;
743 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700744 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800745 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800746 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 DEBUGFUNC("e1000_init_hw");
749
Jeff Kirsher7820d422006-08-16 13:39:00 -0700750 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
751 if (hw->mac_type == e1000_ich8lan) {
752 reg_data = E1000_READ_REG(hw, TARC0);
753 reg_data |= 0x30000000;
754 E1000_WRITE_REG(hw, TARC0, reg_data);
755
756 reg_data = E1000_READ_REG(hw, STATUS);
757 reg_data &= ~0x80000000;
758 E1000_WRITE_REG(hw, STATUS, reg_data);
759 }
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 /* Initialize Identification LED */
762 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700763 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 DEBUGOUT("Error Initializing Identification LED\n");
765 return ret_val;
766 }
767
768 /* Set the media type and TBI compatibility */
769 e1000_set_media_type(hw);
770
771 /* Disabling VLAN filtering. */
772 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700773 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
774 if (hw->mac_type != e1000_ich8lan) {
775 if (hw->mac_type < e1000_82545_rev_3)
776 E1000_WRITE_REG(hw, VET, 0);
777 e1000_clear_vfta(hw);
778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700781 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
783 e1000_pci_clear_mwi(hw);
784 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
785 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400786 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 }
788
789 /* Setup the receive address. This involves initializing all of the Receive
790 * Address Registers (RARs 0 - 15).
791 */
792 e1000_init_rx_addrs(hw);
793
794 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700795 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 E1000_WRITE_REG(hw, RCTL, 0);
797 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400798 msleep(1);
799 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 e1000_pci_set_mwi(hw);
801 }
802
803 /* Zero out the Multicast HASH table */
804 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700805 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700806 if (hw->mac_type == e1000_ich8lan)
807 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700808 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700810 /* use write flush to prevent Memory Write Block (MWB) from
811 * occuring when accessing our register space */
812 E1000_WRITE_FLUSH(hw);
813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 /* Set the PCI priority bit correctly in the CTRL register. This
816 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700817 * gives equal priority to transmits and receives. Valid only on
818 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700820 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 ctrl = E1000_READ_REG(hw, CTRL);
822 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
823 }
824
Auke Kok8fc897b2006-08-28 14:56:16 -0700825 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 case e1000_82545_rev_3:
827 case e1000_82546_rev_3:
828 break;
829 default:
830 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700831 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
833 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
834 &pcix_stat_hi_word);
835 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
836 PCIX_COMMAND_MMRBC_SHIFT;
837 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
838 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700839 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700841 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
843 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
844 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
845 &pcix_cmd_word);
846 }
847 }
848 break;
849 }
850
Auke Kokcd94dd02006-06-27 09:08:22 -0700851 /* More time needed for PHY to initialize */
852 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400853 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /* Call a subroutine to configure the link and setup flow control. */
856 ret_val = e1000_setup_link(hw);
857
858 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700859 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 ctrl = E1000_READ_REG(hw, TXDCTL);
861 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700862 switch (hw->mac_type) {
863 default:
864 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400865 case e1000_82571:
866 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700867 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -0700868 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800869 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700870 ctrl |= E1000_TXDCTL_COUNT_DESC;
871 break;
872 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 E1000_WRITE_REG(hw, TXDCTL, ctrl);
874 }
875
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700876 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700877 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700878 }
879
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400880 switch (hw->mac_type) {
881 default:
882 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800883 case e1000_80003es2lan:
884 /* Enable retransmit on late collisions */
885 reg_data = E1000_READ_REG(hw, TCTL);
886 reg_data |= E1000_TCTL_RTLC;
887 E1000_WRITE_REG(hw, TCTL, reg_data);
888
889 /* Configure Gigabit Carry Extend Padding */
890 reg_data = E1000_READ_REG(hw, TCTL_EXT);
891 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
892 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
893 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
894
895 /* Configure Transmit Inter-Packet Gap */
896 reg_data = E1000_READ_REG(hw, TIPG);
897 reg_data &= ~E1000_TIPG_IPGT_MASK;
898 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
899 E1000_WRITE_REG(hw, TIPG, reg_data);
900
901 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
902 reg_data &= ~0x00100000;
903 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
904 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400905 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400906 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -0700907 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400908 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800909 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Auke Kok8fc897b2006-08-28 14:56:16 -0700910 if (hw->mac_type >= e1000_82571)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800911 ctrl |= E1000_TXDCTL_COUNT_DESC;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400912 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
913 break;
914 }
915
916
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400917 if (hw->mac_type == e1000_82573) {
918 uint32_t gcr = E1000_READ_REG(hw, GCR);
919 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
920 E1000_WRITE_REG(hw, GCR, gcr);
921 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* Clear all of the statistics registers (clear on read). It is
924 * important that we do this after we have tried to establish link
925 * because the symbol error count will increment wildly if there
926 * is no link.
927 */
928 e1000_clear_hw_cntrs(hw);
929
Auke Kokcd94dd02006-06-27 09:08:22 -0700930 /* ICH8 No-snoop bits are opposite polarity.
931 * Set to snoop by default after reset. */
932 if (hw->mac_type == e1000_ich8lan)
933 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
934
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800935 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
936 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
937 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
938 /* Relaxed ordering must be disabled to avoid a parity
939 * error crash in a PCI slot. */
940 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
941 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
942 }
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 return ret_val;
945}
946
947/******************************************************************************
948 * Adjust SERDES output amplitude based on EEPROM setting.
949 *
950 * hw - Struct containing variables accessed by shared code.
951 *****************************************************************************/
952static int32_t
953e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
954{
955 uint16_t eeprom_data;
956 int32_t ret_val;
957
958 DEBUGFUNC("e1000_adjust_serdes_amplitude");
959
Auke Kok8fc897b2006-08-28 14:56:16 -0700960 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return E1000_SUCCESS;
962
Auke Kok8fc897b2006-08-28 14:56:16 -0700963 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 case e1000_82545_rev_3:
965 case e1000_82546_rev_3:
966 break;
967 default:
968 return E1000_SUCCESS;
969 }
970
971 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
972 if (ret_val) {
973 return ret_val;
974 }
975
Auke Kok8fc897b2006-08-28 14:56:16 -0700976 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -0700978 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -0700980 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 return ret_val;
982 }
983
984 return E1000_SUCCESS;
985}
986
987/******************************************************************************
988 * Configures flow control and link settings.
989 *
990 * hw - Struct containing variables accessed by shared code
991 *
992 * Determines which flow control settings to use. Calls the apropriate media-
993 * specific link configuration function. Configures the flow control settings.
994 * Assuming the adapter has a valid link partner, a valid link should be
995 * established. Assumes the hardware has previously been reset and the
996 * transmitter and receiver are not enabled.
997 *****************************************************************************/
998int32_t
999e1000_setup_link(struct e1000_hw *hw)
1000{
1001 uint32_t ctrl_ext;
1002 int32_t ret_val;
1003 uint16_t eeprom_data;
1004
1005 DEBUGFUNC("e1000_setup_link");
1006
Jeff Kirsher526f9952006-01-12 16:50:46 -08001007 /* In the case of the phy reset being blocked, we already have a link.
1008 * We do not have to set it up again. */
1009 if (e1000_check_phy_reset_block(hw))
1010 return E1000_SUCCESS;
1011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 /* Read and store word 0x0F of the EEPROM. This word contains bits
1013 * that determine the hardware's default PAUSE (flow control) mode,
1014 * a bit that determines whether the HW defaults to enabling or
1015 * disabling auto-negotiation, and the direction of the
1016 * SW defined pins. If there is no SW over-ride of the flow
1017 * control setting, then the variable hw->fc will
1018 * be initialized based on a value in the EEPROM.
1019 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001020 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001021 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001022 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001023 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001024 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001025 break;
1026 default:
1027 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1028 1, &eeprom_data);
1029 if (ret_val) {
1030 DEBUGOUT("EEPROM Read Error\n");
1031 return -E1000_ERR_EEPROM;
1032 }
1033 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001034 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001035 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1036 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001037 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001038 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001039 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001040 break;
1041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043
1044 /* We want to save off the original Flow Control configuration just
1045 * in case we get disconnected and then reconnected into a different
1046 * hub or switch with different Flow Control capabilities.
1047 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001048 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001049 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Auke Kok8fc897b2006-08-28 14:56:16 -07001051 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001052 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
1054 hw->original_fc = hw->fc;
1055
1056 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1057
1058 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1059 * polarity value for the SW controlled pins, and setup the
1060 * Extended Device Control reg with that info.
1061 * This is needed because one of the SW controlled pins is used for
1062 * signal detection. So this should be done before e1000_setup_pcs_link()
1063 * or e1000_phy_setup() is called.
1064 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001065 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001066 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1067 1, &eeprom_data);
1068 if (ret_val) {
1069 DEBUGOUT("EEPROM Read Error\n");
1070 return -E1000_ERR_EEPROM;
1071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1073 SWDPIO__EXT_SHIFT);
1074 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1075 }
1076
1077 /* Call the necessary subroutine to configure the link. */
1078 ret_val = (hw->media_type == e1000_media_type_copper) ?
1079 e1000_setup_copper_link(hw) :
1080 e1000_setup_fiber_serdes_link(hw);
1081
1082 /* Initialize the flow control address, type, and PAUSE timer
1083 * registers to their default values. This is done even if flow
1084 * control is disabled, because it does not hurt anything to
1085 * initialize these registers.
1086 */
1087 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1088
Auke Kokcd94dd02006-06-27 09:08:22 -07001089 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1090 if (hw->mac_type != e1000_ich8lan) {
1091 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1092 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1093 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1094 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1097
1098 /* Set the flow control receive threshold registers. Normally,
1099 * these registers will be set to a default threshold that may be
1100 * adjusted later by the driver's runtime code. However, if the
1101 * ability to transmit pause frames in not enabled, then these
1102 * registers will be set to 0.
1103 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001104 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 E1000_WRITE_REG(hw, FCRTL, 0);
1106 E1000_WRITE_REG(hw, FCRTH, 0);
1107 } else {
1108 /* We need to set up the Receive Threshold high and low water marks
1109 * as well as (optionally) enabling the transmission of XON frames.
1110 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001111 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1113 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1114 } else {
1115 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1116 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1117 }
1118 }
1119 return ret_val;
1120}
1121
1122/******************************************************************************
1123 * Sets up link for a fiber based or serdes based adapter
1124 *
1125 * hw - Struct containing variables accessed by shared code
1126 *
1127 * Manipulates Physical Coding Sublayer functions in order to configure
1128 * link. Assumes the hardware has been previously reset and the transmitter
1129 * and receiver are not enabled.
1130 *****************************************************************************/
1131static int32_t
1132e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1133{
1134 uint32_t ctrl;
1135 uint32_t status;
1136 uint32_t txcw = 0;
1137 uint32_t i;
1138 uint32_t signal = 0;
1139 int32_t ret_val;
1140
1141 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1142
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001143 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1144 * until explicitly turned off or a power cycle is performed. A read to
1145 * the register does not indicate its status. Therefore, we ensure
1146 * loopback mode is disabled during initialization.
1147 */
1148 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1149 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1152 * set when the optics detect a signal. On older adapters, it will be
1153 * cleared when there is a signal. This applies to fiber media only.
1154 * If we're on serdes media, adjust the output amplitude to value set in
1155 * the EEPROM.
1156 */
1157 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001158 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1160
1161 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001162 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 return ret_val;
1164
1165 /* Take the link out of reset */
1166 ctrl &= ~(E1000_CTRL_LRST);
1167
1168 /* Adjust VCO speed to improve BER performance */
1169 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001170 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 return ret_val;
1172
1173 e1000_config_collision_dist(hw);
1174
1175 /* Check for a software override of the flow control settings, and setup
1176 * the device accordingly. If auto-negotiation is enabled, then software
1177 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1178 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1179 * auto-negotiation is disabled, then software will have to manually
1180 * configure the two flow control enable bits in the CTRL register.
1181 *
1182 * The possible values of the "fc" parameter are:
1183 * 0: Flow control is completely disabled
1184 * 1: Rx flow control is enabled (we can receive pause frames, but
1185 * not send pause frames).
1186 * 2: Tx flow control is enabled (we can send pause frames but we do
1187 * not support receiving pause frames).
1188 * 3: Both Rx and TX flow control (symmetric) are enabled.
1189 */
1190 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001191 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 /* Flow control is completely disabled by a software over-ride. */
1193 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1194 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001195 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 /* RX Flow control is enabled and TX Flow control is disabled by a
1197 * software over-ride. Since there really isn't a way to advertise
1198 * that we are capable of RX Pause ONLY, we will advertise that we
1199 * support both symmetric and asymmetric RX PAUSE. Later, we will
1200 * disable the adapter's ability to send PAUSE frames.
1201 */
1202 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1203 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001204 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1206 * software over-ride.
1207 */
1208 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1209 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001210 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1212 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1213 break;
1214 default:
1215 DEBUGOUT("Flow control param set incorrectly\n");
1216 return -E1000_ERR_CONFIG;
1217 break;
1218 }
1219
1220 /* Since auto-negotiation is enabled, take the link out of reset (the link
1221 * will be in reset, because we previously reset the chip). This will
1222 * restart auto-negotiation. If auto-neogtiation is successful then the
1223 * link-up status bit will be set and the flow control enable bits (RFCE
1224 * and TFCE) will be set according to their negotiated value.
1225 */
1226 DEBUGOUT("Auto-negotiation enabled\n");
1227
1228 E1000_WRITE_REG(hw, TXCW, txcw);
1229 E1000_WRITE_REG(hw, CTRL, ctrl);
1230 E1000_WRITE_FLUSH(hw);
1231
1232 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001233 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1236 * indication in the Device Status Register. Time-out if a link isn't
1237 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1238 * less than 500 milliseconds even if the other end is doing it in SW).
1239 * For internal serdes, we just assume a signal is present, then poll.
1240 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001241 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1243 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001244 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001245 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001247 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001249 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1251 hw->autoneg_failed = 1;
1252 /* AutoNeg failed to achieve a link, so we'll call
1253 * e1000_check_for_link. This routine will force the link up if
1254 * we detect a signal. This will allow us to communicate with
1255 * non-autonegotiating link partners.
1256 */
1257 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001258 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 DEBUGOUT("Error while checking for link\n");
1260 return ret_val;
1261 }
1262 hw->autoneg_failed = 0;
1263 } else {
1264 hw->autoneg_failed = 0;
1265 DEBUGOUT("Valid Link Found\n");
1266 }
1267 } else {
1268 DEBUGOUT("No Signal Detected\n");
1269 }
1270 return E1000_SUCCESS;
1271}
1272
1273/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001274* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275*
1276* hw - Struct containing variables accessed by shared code
1277******************************************************************************/
1278static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001279e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
1281 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 uint16_t phy_data;
1284
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001285 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 ctrl = E1000_READ_REG(hw, CTRL);
1288 /* With 82543, we need to force speed and duplex on the MAC equal to what
1289 * the PHY speed and duplex configuration is. In addition, we need to
1290 * perform a hardware reset on the PHY to take it out of reset.
1291 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001292 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 ctrl |= E1000_CTRL_SLU;
1294 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1295 E1000_WRITE_REG(hw, CTRL, ctrl);
1296 } else {
1297 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1298 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001299 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001300 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001301 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 }
1303
1304 /* Make sure we have a valid PHY */
1305 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001306 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 DEBUGOUT("Error, did not detect valid phy.\n");
1308 return ret_val;
1309 }
1310 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1311
1312 /* Set PHY to class A mode (if necessary) */
1313 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001314 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 return ret_val;
1316
Auke Kok8fc897b2006-08-28 14:56:16 -07001317 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 (hw->mac_type == e1000_82546_rev_3)) {
1319 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1320 phy_data |= 0x00000008;
1321 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1322 }
1323
Auke Kok8fc897b2006-08-28 14:56:16 -07001324 if (hw->mac_type <= e1000_82543 ||
1325 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1326 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 hw->phy_reset_disable = FALSE;
1328
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001329 return E1000_SUCCESS;
1330}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001333/********************************************************************
1334* Copper link setup for e1000_phy_igp series.
1335*
1336* hw - Struct containing variables accessed by shared code
1337*********************************************************************/
1338static int32_t
1339e1000_copper_link_igp_setup(struct e1000_hw *hw)
1340{
1341 uint32_t led_ctrl;
1342 int32_t ret_val;
1343 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001345 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001347 if (hw->phy_reset_disable)
1348 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001349
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001350 ret_val = e1000_phy_reset(hw);
1351 if (ret_val) {
1352 DEBUGOUT("Error Resetting the PHY\n");
1353 return ret_val;
1354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Auke Kok8fc897b2006-08-28 14:56:16 -07001356 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001357 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001358 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001359 /* Configure activity LED after PHY reset */
1360 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1361 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1362 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1363 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001364 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001365
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001366 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1367 if (hw->phy_type == e1000_phy_igp) {
1368 /* disable lplu d3 during driver init */
1369 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1370 if (ret_val) {
1371 DEBUGOUT("Error Disabling LPLU D3\n");
1372 return ret_val;
1373 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001374 }
1375
1376 /* disable lplu d0 during driver init */
1377 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1378 if (ret_val) {
1379 DEBUGOUT("Error Disabling LPLU D0\n");
1380 return ret_val;
1381 }
1382 /* Configure mdi-mdix settings */
1383 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1384 if (ret_val)
1385 return ret_val;
1386
1387 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1388 hw->dsp_config_state = e1000_dsp_config_disabled;
1389 /* Force MDI for earlier revs of the IGP PHY */
1390 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1391 hw->mdix = 1;
1392
1393 } else {
1394 hw->dsp_config_state = e1000_dsp_config_enabled;
1395 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1396
1397 switch (hw->mdix) {
1398 case 1:
1399 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1400 break;
1401 case 2:
1402 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1403 break;
1404 case 0:
1405 default:
1406 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1407 break;
1408 }
1409 }
1410 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001411 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001412 return ret_val;
1413
1414 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001415 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001416 e1000_ms_type phy_ms_setting = hw->master_slave;
1417
Auke Kok8fc897b2006-08-28 14:56:16 -07001418 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001419 hw->ffe_config_state = e1000_ffe_config_enabled;
1420
Auke Kok8fc897b2006-08-28 14:56:16 -07001421 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001422 hw->dsp_config_state = e1000_dsp_config_enabled;
1423
1424 /* when autonegotiation advertisment is only 1000Mbps then we
1425 * should disable SmartSpeed and enable Auto MasterSlave
1426 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001427 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001428 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001429 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1430 &phy_data);
1431 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001433 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001434 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1435 phy_data);
1436 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001438 /* Set auto Master/Slave resolution process */
1439 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001440 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001441 return ret_val;
1442 phy_data &= ~CR_1000T_MS_ENABLE;
1443 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001444 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001445 return ret_val;
1446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001448 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001449 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001450 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001452 /* load defaults for future use */
1453 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1454 ((phy_data & CR_1000T_MS_VALUE) ?
1455 e1000_ms_force_master :
1456 e1000_ms_force_slave) :
1457 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001459 switch (phy_ms_setting) {
1460 case e1000_ms_force_master:
1461 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1462 break;
1463 case e1000_ms_force_slave:
1464 phy_data |= CR_1000T_MS_ENABLE;
1465 phy_data &= ~(CR_1000T_MS_VALUE);
1466 break;
1467 case e1000_ms_auto:
1468 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001470 break;
1471 }
1472 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001473 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001474 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Malli Chilakala2b028932005-06-17 17:46:06 -07001477 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001478}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001480/********************************************************************
1481* Copper link setup for e1000_phy_gg82563 series.
1482*
1483* hw - Struct containing variables accessed by shared code
1484*********************************************************************/
1485static int32_t
1486e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1487{
1488 int32_t ret_val;
1489 uint16_t phy_data;
1490 uint32_t reg_data;
1491
1492 DEBUGFUNC("e1000_copper_link_ggp_setup");
1493
Auke Kok8fc897b2006-08-28 14:56:16 -07001494 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001495
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001496 /* Enable CRS on TX for half-duplex operation. */
1497 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1498 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001499 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001500 return ret_val;
1501
1502 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1503 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1504 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1505
1506 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1507 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001508 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001509 return ret_val;
1510
1511 /* Options:
1512 * MDI/MDI-X = 0 (default)
1513 * 0 - Auto for all speeds
1514 * 1 - MDI mode
1515 * 2 - MDI-X mode
1516 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1517 */
1518 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001519 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001520 return ret_val;
1521
1522 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1523
1524 switch (hw->mdix) {
1525 case 1:
1526 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1527 break;
1528 case 2:
1529 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1530 break;
1531 case 0:
1532 default:
1533 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1534 break;
1535 }
1536
1537 /* Options:
1538 * disable_polarity_correction = 0 (default)
1539 * Automatic Correction for Reversed Cable Polarity
1540 * 0 - Disabled
1541 * 1 - Enabled
1542 */
1543 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001544 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001545 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1546 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1547
Auke Kok8fc897b2006-08-28 14:56:16 -07001548 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001549 return ret_val;
1550
1551 /* SW Reset the PHY so all changes take effect */
1552 ret_val = e1000_phy_reset(hw);
1553 if (ret_val) {
1554 DEBUGOUT("Error Resetting the PHY\n");
1555 return ret_val;
1556 }
1557 } /* phy_reset_disable */
1558
1559 if (hw->mac_type == e1000_80003es2lan) {
1560 /* Bypass RX and TX FIFO's */
1561 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1562 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1563 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1564 if (ret_val)
1565 return ret_val;
1566
1567 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1568 if (ret_val)
1569 return ret_val;
1570
1571 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1572 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1573
1574 if (ret_val)
1575 return ret_val;
1576
1577 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1578 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1579 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1580
1581 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1582 &phy_data);
1583 if (ret_val)
1584 return ret_val;
1585
1586 /* Do not init these registers when the HW is in IAMT mode, since the
1587 * firmware will have already initialized them. We only initialize
1588 * them if the HW is not in IAMT mode.
1589 */
1590 if (e1000_check_mng_mode(hw) == FALSE) {
1591 /* Enable Electrical Idle on the PHY */
1592 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1593 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1594 phy_data);
1595 if (ret_val)
1596 return ret_val;
1597
1598 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1599 &phy_data);
1600 if (ret_val)
1601 return ret_val;
1602
Auke Kokcd94dd02006-06-27 09:08:22 -07001603 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001604 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1605 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001606
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001607 if (ret_val)
1608 return ret_val;
1609 }
1610
1611 /* Workaround: Disable padding in Kumeran interface in the MAC
1612 * and in the PHY to avoid CRC errors.
1613 */
1614 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1615 &phy_data);
1616 if (ret_val)
1617 return ret_val;
1618 phy_data |= GG82563_ICR_DIS_PADDING;
1619 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1620 phy_data);
1621 if (ret_val)
1622 return ret_val;
1623 }
1624
1625 return E1000_SUCCESS;
1626}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001628/********************************************************************
1629* Copper link setup for e1000_phy_m88 series.
1630*
1631* hw - Struct containing variables accessed by shared code
1632*********************************************************************/
1633static int32_t
1634e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1635{
1636 int32_t ret_val;
1637 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001639 DEBUGFUNC("e1000_copper_link_mgp_setup");
1640
Auke Kok8fc897b2006-08-28 14:56:16 -07001641 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001642 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001643
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001644 /* Enable CRS on TX. This must be set for half-duplex operation. */
1645 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001646 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001647 return ret_val;
1648
1649 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1650
1651 /* Options:
1652 * MDI/MDI-X = 0 (default)
1653 * 0 - Auto for all speeds
1654 * 1 - MDI mode
1655 * 2 - MDI-X mode
1656 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1657 */
1658 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1659
1660 switch (hw->mdix) {
1661 case 1:
1662 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1663 break;
1664 case 2:
1665 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1666 break;
1667 case 3:
1668 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1669 break;
1670 case 0:
1671 default:
1672 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1673 break;
1674 }
1675
1676 /* Options:
1677 * disable_polarity_correction = 0 (default)
1678 * Automatic Correction for Reversed Cable Polarity
1679 * 0 - Disabled
1680 * 1 - Enabled
1681 */
1682 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001683 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001684 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001685 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1686 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001687 return ret_val;
1688
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001689 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001690 /* Force TX_CLK in the Extended PHY Specific Control Register
1691 * to 25MHz clock.
1692 */
1693 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1694 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001695 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001696
1697 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1698
1699 if ((hw->phy_revision == E1000_REVISION_2) &&
1700 (hw->phy_id == M88E1111_I_PHY_ID)) {
1701 /* Vidalia Phy, set the downshift counter to 5x */
1702 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1703 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1704 ret_val = e1000_write_phy_reg(hw,
1705 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1706 if (ret_val)
1707 return ret_val;
1708 } else {
1709 /* Configure Master and Slave downshift values */
1710 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1711 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1712 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1713 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1714 ret_val = e1000_write_phy_reg(hw,
1715 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1716 if (ret_val)
1717 return ret_val;
1718 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001721 /* SW Reset the PHY so all changes take effect */
1722 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001723 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001724 DEBUGOUT("Error Resetting the PHY\n");
1725 return ret_val;
1726 }
1727
1728 return E1000_SUCCESS;
1729}
1730
1731/********************************************************************
1732* Setup auto-negotiation and flow control advertisements,
1733* and then perform auto-negotiation.
1734*
1735* hw - Struct containing variables accessed by shared code
1736*********************************************************************/
1737static int32_t
1738e1000_copper_link_autoneg(struct e1000_hw *hw)
1739{
1740 int32_t ret_val;
1741 uint16_t phy_data;
1742
1743 DEBUGFUNC("e1000_copper_link_autoneg");
1744
1745 /* Perform some bounds checking on the hw->autoneg_advertised
1746 * parameter. If this variable is zero, then set it to the default.
1747 */
1748 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1749
1750 /* If autoneg_advertised is zero, we assume it was not defaulted
1751 * by the calling code so we set to advertise full capability.
1752 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001753 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001754 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1755
Auke Kokcd94dd02006-06-27 09:08:22 -07001756 /* IFE phy only supports 10/100 */
1757 if (hw->phy_type == e1000_phy_ife)
1758 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1759
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001760 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1761 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001762 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001763 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1764 return ret_val;
1765 }
1766 DEBUGOUT("Restarting Auto-Neg\n");
1767
1768 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1769 * the Auto Neg Restart bit in the PHY control register.
1770 */
1771 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001772 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001773 return ret_val;
1774
1775 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1776 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001777 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001778 return ret_val;
1779
1780 /* Does the user want to wait for Auto-Neg to complete here, or
1781 * check at a later time (for example, callback routine).
1782 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001783 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001784 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001785 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001786 DEBUGOUT("Error while waiting for autoneg to complete\n");
1787 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001791 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001793 return E1000_SUCCESS;
1794}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001796/******************************************************************************
1797* Config the MAC and the PHY after link is up.
1798* 1) Set up the MAC to the current PHY speed/duplex
1799* if we are on 82543. If we
1800* are on newer silicon, we only need to configure
1801* collision distance in the Transmit Control Register.
1802* 2) Set up flow control on the MAC to that established with
1803* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001804* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001805*
1806* hw - Struct containing variables accessed by shared code
1807******************************************************************************/
1808static int32_t
1809e1000_copper_link_postconfig(struct e1000_hw *hw)
1810{
1811 int32_t ret_val;
1812 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001813
Auke Kok8fc897b2006-08-28 14:56:16 -07001814 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001815 e1000_config_collision_dist(hw);
1816 } else {
1817 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001818 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001819 DEBUGOUT("Error configuring MAC to PHY settings\n");
1820 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001822 }
1823 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001824 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001825 DEBUGOUT("Error Configuring Flow Control\n");
1826 return ret_val;
1827 }
1828
1829 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001830 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001831 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001832 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001833 DEBUGOUT("Error Configuring DSP after link up\n");
1834 return ret_val;
1835 }
1836 }
Auke Kok76c224b2006-05-23 13:36:06 -07001837
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001838 return E1000_SUCCESS;
1839}
1840
1841/******************************************************************************
1842* Detects which PHY is present and setup the speed and duplex
1843*
1844* hw - Struct containing variables accessed by shared code
1845******************************************************************************/
1846static int32_t
1847e1000_setup_copper_link(struct e1000_hw *hw)
1848{
1849 int32_t ret_val;
1850 uint16_t i;
1851 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001852 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001853
1854 DEBUGFUNC("e1000_setup_copper_link");
1855
Auke Kokcd94dd02006-06-27 09:08:22 -07001856 switch (hw->mac_type) {
1857 case e1000_80003es2lan:
1858 case e1000_ich8lan:
1859 /* Set the mac to wait the maximum time between each
1860 * iteration and increase the max iterations when
1861 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1862 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1863 if (ret_val)
1864 return ret_val;
1865 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1866 if (ret_val)
1867 return ret_val;
1868 reg_data |= 0x3F;
1869 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1870 if (ret_val)
1871 return ret_val;
1872 default:
1873 break;
1874 }
1875
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001876 /* Check if it is a valid PHY and set PHY mode if necessary. */
1877 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001878 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001879 return ret_val;
1880
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001881 switch (hw->mac_type) {
1882 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001883 /* Kumeran registers are written-only */
1884 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001885 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1886 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1887 reg_data);
1888 if (ret_val)
1889 return ret_val;
1890 break;
1891 default:
1892 break;
1893 }
1894
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001895 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07001896 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001897 hw->phy_type == e1000_phy_igp_2) {
1898 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001899 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001900 return ret_val;
1901 } else if (hw->phy_type == e1000_phy_m88) {
1902 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001903 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001904 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001905 } else if (hw->phy_type == e1000_phy_gg82563) {
1906 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001907 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001908 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001909 }
1910
Auke Kok8fc897b2006-08-28 14:56:16 -07001911 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07001912 /* Setup autoneg and flow control advertisement
1913 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001914 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001915 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07001916 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001917 } else {
1918 /* PHY will be set to 10H, 10F, 100H,or 100F
1919 * depending on value from forced_speed_duplex. */
1920 DEBUGOUT("Forcing speed and duplex\n");
1921 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001922 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001923 DEBUGOUT("Error Forcing Speed and Duplex\n");
1924 return ret_val;
1925 }
1926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
1928 /* Check link status. Wait up to 100 microseconds for link to become
1929 * valid.
1930 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001931 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001933 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 return ret_val;
1935 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001936 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 return ret_val;
1938
Auke Kok8fc897b2006-08-28 14:56:16 -07001939 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001940 /* Config the MAC and PHY after link is up */
1941 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001942 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001944
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 DEBUGOUT("Valid link established!!!\n");
1946 return E1000_SUCCESS;
1947 }
1948 udelay(10);
1949 }
1950
1951 DEBUGOUT("Unable to establish link!!!\n");
1952 return E1000_SUCCESS;
1953}
1954
1955/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001956* Configure the MAC-to-PHY interface for 10/100Mbps
1957*
1958* hw - Struct containing variables accessed by shared code
1959******************************************************************************/
1960static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07001961e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001962{
1963 int32_t ret_val = E1000_SUCCESS;
1964 uint32_t tipg;
1965 uint16_t reg_data;
1966
1967 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1968
1969 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1970 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1971 reg_data);
1972 if (ret_val)
1973 return ret_val;
1974
1975 /* Configure Transmit Inter-Packet Gap */
1976 tipg = E1000_READ_REG(hw, TIPG);
1977 tipg &= ~E1000_TIPG_IPGT_MASK;
1978 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1979 E1000_WRITE_REG(hw, TIPG, tipg);
1980
Auke Kokcd94dd02006-06-27 09:08:22 -07001981 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
1982
1983 if (ret_val)
1984 return ret_val;
1985
1986 if (duplex == HALF_DUPLEX)
1987 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1988 else
1989 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1990
1991 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1992
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001993 return ret_val;
1994}
1995
1996static int32_t
1997e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1998{
1999 int32_t ret_val = E1000_SUCCESS;
2000 uint16_t reg_data;
2001 uint32_t tipg;
2002
2003 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2004
2005 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2006 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2007 reg_data);
2008 if (ret_val)
2009 return ret_val;
2010
2011 /* Configure Transmit Inter-Packet Gap */
2012 tipg = E1000_READ_REG(hw, TIPG);
2013 tipg &= ~E1000_TIPG_IPGT_MASK;
2014 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2015 E1000_WRITE_REG(hw, TIPG, tipg);
2016
Auke Kokcd94dd02006-06-27 09:08:22 -07002017 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2018
2019 if (ret_val)
2020 return ret_val;
2021
2022 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2023 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2024
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002025 return ret_val;
2026}
2027
2028/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029* Configures PHY autoneg and flow control advertisement settings
2030*
2031* hw - Struct containing variables accessed by shared code
2032******************************************************************************/
2033int32_t
2034e1000_phy_setup_autoneg(struct e1000_hw *hw)
2035{
2036 int32_t ret_val;
2037 uint16_t mii_autoneg_adv_reg;
2038 uint16_t mii_1000t_ctrl_reg;
2039
2040 DEBUGFUNC("e1000_phy_setup_autoneg");
2041
2042 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2043 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002044 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 return ret_val;
2046
Auke Kokcd94dd02006-06-27 09:08:22 -07002047 if (hw->phy_type != e1000_phy_ife) {
2048 /* Read the MII 1000Base-T Control Register (Address 9). */
2049 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2050 if (ret_val)
2051 return ret_val;
2052 } else
2053 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 /* Need to parse both autoneg_advertised and fc and set up
2056 * the appropriate PHY registers. First we will parse for
2057 * autoneg_advertised software override. Since we can advertise
2058 * a plethora of combinations, we need to check each bit
2059 * individually.
2060 */
2061
2062 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2063 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2064 * the 1000Base-T Control Register (Address 9).
2065 */
2066 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2067 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2068
2069 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2070
2071 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002072 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 DEBUGOUT("Advertise 10mb Half duplex\n");
2074 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2075 }
2076
2077 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002078 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 DEBUGOUT("Advertise 10mb Full duplex\n");
2080 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2081 }
2082
2083 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002084 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 DEBUGOUT("Advertise 100mb Half duplex\n");
2086 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2087 }
2088
2089 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002090 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 DEBUGOUT("Advertise 100mb Full duplex\n");
2092 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2093 }
2094
2095 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002096 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2098 }
2099
2100 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002101 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 DEBUGOUT("Advertise 1000mb Full duplex\n");
2103 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002104 if (hw->phy_type == e1000_phy_ife) {
2105 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 }
2108
2109 /* Check for a software override of the flow control settings, and
2110 * setup the PHY advertisement registers accordingly. If
2111 * auto-negotiation is enabled, then software will have to set the
2112 * "PAUSE" bits to the correct value in the Auto-Negotiation
2113 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2114 *
2115 * The possible values of the "fc" parameter are:
2116 * 0: Flow control is completely disabled
2117 * 1: Rx flow control is enabled (we can receive pause frames
2118 * but not send pause frames).
2119 * 2: Tx flow control is enabled (we can send pause frames
2120 * but we do not support receiving pause frames).
2121 * 3: Both Rx and TX flow control (symmetric) are enabled.
2122 * other: No software override. The flow control configuration
2123 * in the EEPROM is used.
2124 */
2125 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002126 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 /* Flow control (RX & TX) is completely disabled by a
2128 * software over-ride.
2129 */
2130 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2131 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002132 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 /* RX Flow control is enabled, and TX Flow control is
2134 * disabled, by a software over-ride.
2135 */
2136 /* Since there really isn't a way to advertise that we are
2137 * capable of RX Pause ONLY, we will advertise that we
2138 * support both symmetric and asymmetric RX PAUSE. Later
2139 * (in e1000_config_fc_after_link_up) we will disable the
2140 *hw's ability to send PAUSE frames.
2141 */
2142 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2143 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002144 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 /* TX Flow control is enabled, and RX Flow control is
2146 * disabled, by a software over-ride.
2147 */
2148 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2149 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2150 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002151 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 /* Flow control (both RX and TX) is enabled by a software
2153 * over-ride.
2154 */
2155 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2156 break;
2157 default:
2158 DEBUGOUT("Flow control param set incorrectly\n");
2159 return -E1000_ERR_CONFIG;
2160 }
2161
2162 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002163 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 return ret_val;
2165
2166 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2167
Auke Kokcd94dd02006-06-27 09:08:22 -07002168 if (hw->phy_type != e1000_phy_ife) {
2169 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2170 if (ret_val)
2171 return ret_val;
2172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
2174 return E1000_SUCCESS;
2175}
2176
2177/******************************************************************************
2178* Force PHY speed and duplex settings to hw->forced_speed_duplex
2179*
2180* hw - Struct containing variables accessed by shared code
2181******************************************************************************/
2182static int32_t
2183e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2184{
2185 uint32_t ctrl;
2186 int32_t ret_val;
2187 uint16_t mii_ctrl_reg;
2188 uint16_t mii_status_reg;
2189 uint16_t phy_data;
2190 uint16_t i;
2191
2192 DEBUGFUNC("e1000_phy_force_speed_duplex");
2193
2194 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002195 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
2197 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2198
2199 /* Read the Device Control Register. */
2200 ctrl = E1000_READ_REG(hw, CTRL);
2201
2202 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2203 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2204 ctrl &= ~(DEVICE_SPEED_MASK);
2205
2206 /* Clear the Auto Speed Detect Enable bit. */
2207 ctrl &= ~E1000_CTRL_ASDE;
2208
2209 /* Read the MII Control Register. */
2210 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002211 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 return ret_val;
2213
2214 /* We need to disable autoneg in order to force link and duplex. */
2215
2216 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2217
2218 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002219 if (hw->forced_speed_duplex == e1000_100_full ||
2220 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 /* We want to force full duplex so we SET the full duplex bits in the
2222 * Device and MII Control Registers.
2223 */
2224 ctrl |= E1000_CTRL_FD;
2225 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2226 DEBUGOUT("Full Duplex\n");
2227 } else {
2228 /* We want to force half duplex so we CLEAR the full duplex bits in
2229 * the Device and MII Control Registers.
2230 */
2231 ctrl &= ~E1000_CTRL_FD;
2232 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2233 DEBUGOUT("Half Duplex\n");
2234 }
2235
2236 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002237 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 hw->forced_speed_duplex == e1000_100_half) {
2239 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2240 ctrl |= E1000_CTRL_SPD_100;
2241 mii_ctrl_reg |= MII_CR_SPEED_100;
2242 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2243 DEBUGOUT("Forcing 100mb ");
2244 } else {
2245 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2246 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2247 mii_ctrl_reg |= MII_CR_SPEED_10;
2248 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2249 DEBUGOUT("Forcing 10mb ");
2250 }
2251
2252 e1000_config_collision_dist(hw);
2253
2254 /* Write the configured values back to the Device Control Reg. */
2255 E1000_WRITE_REG(hw, CTRL, ctrl);
2256
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002257 if ((hw->phy_type == e1000_phy_m88) ||
2258 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002260 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 return ret_val;
2262
2263 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2264 * forced whenever speed are duplex are forced.
2265 */
2266 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2267 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 return ret_val;
2270
2271 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2272
2273 /* Need to reset the PHY or these changes will be ignored */
2274 mii_ctrl_reg |= MII_CR_RESET;
Auke Kokcd94dd02006-06-27 09:08:22 -07002275 /* Disable MDI-X support for 10/100 */
2276 } else if (hw->phy_type == e1000_phy_ife) {
2277 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2278 if (ret_val)
2279 return ret_val;
2280
2281 phy_data &= ~IFE_PMC_AUTO_MDIX;
2282 phy_data &= ~IFE_PMC_FORCE_MDIX;
2283
2284 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2285 if (ret_val)
2286 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 } else {
2288 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2289 * forced whenever speed or duplex are forced.
2290 */
2291 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002292 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 return ret_val;
2294
2295 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2296 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2297
2298 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002299 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 return ret_val;
2301 }
2302
2303 /* Write back the modified PHY MII control register. */
2304 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002305 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 return ret_val;
2307
2308 udelay(1);
2309
2310 /* The wait_autoneg_complete flag may be a little misleading here.
2311 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2312 * But we do want to delay for a period while forcing only so we
2313 * don't generate false No Link messages. So we will wait here
2314 * only if the user has set wait_autoneg_complete to 1, which is
2315 * the default.
2316 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002317 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 /* We will wait for autoneg to complete. */
2319 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2320 mii_status_reg = 0;
2321
2322 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002323 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2325 * to be set.
2326 */
2327 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002328 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 return ret_val;
2330
2331 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002332 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 return ret_val;
2334
Auke Kok8fc897b2006-08-28 14:56:16 -07002335 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002336 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002338 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002339 ((hw->phy_type == e1000_phy_m88) ||
2340 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 /* We didn't get link. Reset the DSP and wait again for link. */
2342 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002343 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 DEBUGOUT("Error Resetting PHY DSP\n");
2345 return ret_val;
2346 }
2347 }
2348 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002349 for (i = PHY_FORCE_TIME; i > 0; i--) {
2350 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002351 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2353 * to be set.
2354 */
2355 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002356 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 return ret_val;
2358
2359 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002360 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 return ret_val;
2362 }
2363 }
2364
2365 if (hw->phy_type == e1000_phy_m88) {
2366 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2367 * Extended PHY Specific Control Register to 25MHz clock. This value
2368 * defaults back to a 2.5MHz clock when the PHY is reset.
2369 */
2370 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002371 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 return ret_val;
2373
2374 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2375 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002376 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 return ret_val;
2378
2379 /* In addition, because of the s/w reset above, we need to enable CRS on
2380 * TX. This must be set for both full and half duplex operation.
2381 */
2382 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002383 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 return ret_val;
2385
2386 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2387 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002388 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 return ret_val;
2390
Auke Kok8fc897b2006-08-28 14:56:16 -07002391 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2392 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2393 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002395 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 return ret_val;
2397 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002398 } else if (hw->phy_type == e1000_phy_gg82563) {
2399 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2400 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2401 * we're not in a forced 10/duplex configuration. */
2402 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2403 if (ret_val)
2404 return ret_val;
2405
2406 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2407 if ((hw->forced_speed_duplex == e1000_10_full) ||
2408 (hw->forced_speed_duplex == e1000_10_half))
2409 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2410 else
2411 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2412
2413 /* Also due to the reset, we need to enable CRS on Tx. */
2414 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2415
2416 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2417 if (ret_val)
2418 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 }
2420 return E1000_SUCCESS;
2421}
2422
2423/******************************************************************************
2424* Sets the collision distance in the Transmit Control register
2425*
2426* hw - Struct containing variables accessed by shared code
2427*
2428* Link should have been established previously. Reads the speed and duplex
2429* information from the Device Status register.
2430******************************************************************************/
2431void
2432e1000_config_collision_dist(struct e1000_hw *hw)
2433{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002434 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
2436 DEBUGFUNC("e1000_config_collision_dist");
2437
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002438 if (hw->mac_type < e1000_82543)
2439 coll_dist = E1000_COLLISION_DISTANCE_82542;
2440 else
2441 coll_dist = E1000_COLLISION_DISTANCE;
2442
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 tctl = E1000_READ_REG(hw, TCTL);
2444
2445 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002446 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
2448 E1000_WRITE_REG(hw, TCTL, tctl);
2449 E1000_WRITE_FLUSH(hw);
2450}
2451
2452/******************************************************************************
2453* Sets MAC speed and duplex settings to reflect the those in the PHY
2454*
2455* hw - Struct containing variables accessed by shared code
2456* mii_reg - data to write to the MII control register
2457*
2458* The contents of the PHY register containing the needed information need to
2459* be passed in.
2460******************************************************************************/
2461static int32_t
2462e1000_config_mac_to_phy(struct e1000_hw *hw)
2463{
2464 uint32_t ctrl;
2465 int32_t ret_val;
2466 uint16_t phy_data;
2467
2468 DEBUGFUNC("e1000_config_mac_to_phy");
2469
Auke Kok76c224b2006-05-23 13:36:06 -07002470 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002471 * MAC speed/duplex configuration.*/
2472 if (hw->mac_type >= e1000_82544)
2473 return E1000_SUCCESS;
2474
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 /* Read the Device Control Register and set the bits to Force Speed
2476 * and Duplex.
2477 */
2478 ctrl = E1000_READ_REG(hw, CTRL);
2479 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2480 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2481
2482 /* Set up duplex in the Device Control and Transmit Control
2483 * registers depending on negotiated values.
2484 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002485 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002486 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002487 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Auke Kok8fc897b2006-08-28 14:56:16 -07002489 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002490 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002491 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002492 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002494 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002496 /* Set up speed in the Device Control register depending on
2497 * negotiated values.
2498 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002499 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002500 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002501 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002502 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 /* Write the configured values back to the Device Control Reg. */
2505 E1000_WRITE_REG(hw, CTRL, ctrl);
2506 return E1000_SUCCESS;
2507}
2508
2509/******************************************************************************
2510 * Forces the MAC's flow control settings.
2511 *
2512 * hw - Struct containing variables accessed by shared code
2513 *
2514 * Sets the TFCE and RFCE bits in the device control register to reflect
2515 * the adapter settings. TFCE and RFCE need to be explicitly set by
2516 * software when a Copper PHY is used because autonegotiation is managed
2517 * by the PHY rather than the MAC. Software must also configure these
2518 * bits when link is forced on a fiber connection.
2519 *****************************************************************************/
2520int32_t
2521e1000_force_mac_fc(struct e1000_hw *hw)
2522{
2523 uint32_t ctrl;
2524
2525 DEBUGFUNC("e1000_force_mac_fc");
2526
2527 /* Get the current configuration of the Device Control Register */
2528 ctrl = E1000_READ_REG(hw, CTRL);
2529
2530 /* Because we didn't get link via the internal auto-negotiation
2531 * mechanism (we either forced link or we got link via PHY
2532 * auto-neg), we have to manually enable/disable transmit an
2533 * receive flow control.
2534 *
2535 * The "Case" statement below enables/disable flow control
2536 * according to the "hw->fc" parameter.
2537 *
2538 * The possible values of the "fc" parameter are:
2539 * 0: Flow control is completely disabled
2540 * 1: Rx flow control is enabled (we can receive pause
2541 * frames but not send pause frames).
2542 * 2: Tx flow control is enabled (we can send pause frames
2543 * frames but we do not receive pause frames).
2544 * 3: Both Rx and TX flow control (symmetric) is enabled.
2545 * other: No other values should be possible at this point.
2546 */
2547
2548 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002549 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2551 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002552 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 ctrl &= (~E1000_CTRL_TFCE);
2554 ctrl |= E1000_CTRL_RFCE;
2555 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002556 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 ctrl &= (~E1000_CTRL_RFCE);
2558 ctrl |= E1000_CTRL_TFCE;
2559 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002560 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2562 break;
2563 default:
2564 DEBUGOUT("Flow control param set incorrectly\n");
2565 return -E1000_ERR_CONFIG;
2566 }
2567
2568 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002569 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 ctrl &= (~E1000_CTRL_TFCE);
2571
2572 E1000_WRITE_REG(hw, CTRL, ctrl);
2573 return E1000_SUCCESS;
2574}
2575
2576/******************************************************************************
2577 * Configures flow control settings after link is established
2578 *
2579 * hw - Struct containing variables accessed by shared code
2580 *
2581 * Should be called immediately after a valid link has been established.
2582 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2583 * and autonegotiation is enabled, the MAC flow control settings will be set
2584 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2585 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2586 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002587static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588e1000_config_fc_after_link_up(struct e1000_hw *hw)
2589{
2590 int32_t ret_val;
2591 uint16_t mii_status_reg;
2592 uint16_t mii_nway_adv_reg;
2593 uint16_t mii_nway_lp_ability_reg;
2594 uint16_t speed;
2595 uint16_t duplex;
2596
2597 DEBUGFUNC("e1000_config_fc_after_link_up");
2598
2599 /* Check for the case where we have fiber media and auto-neg failed
2600 * so we had to force link. In this case, we need to force the
2601 * configuration of the MAC to match the "fc" parameter.
2602 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002603 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2604 ((hw->media_type == e1000_media_type_internal_serdes) &&
2605 (hw->autoneg_failed)) ||
2606 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002608 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 DEBUGOUT("Error forcing flow control settings\n");
2610 return ret_val;
2611 }
2612 }
2613
2614 /* Check for the case where we have copper media and auto-neg is
2615 * enabled. In this case, we need to check and see if Auto-Neg
2616 * has completed, and if so, how the PHY and link partner has
2617 * flow control configured.
2618 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002619 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 /* Read the MII Status Register and check to see if AutoNeg
2621 * has completed. We read this twice because this reg has
2622 * some "sticky" (latched) bits.
2623 */
2624 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002625 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 return ret_val;
2627 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002628 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 return ret_val;
2630
Auke Kok8fc897b2006-08-28 14:56:16 -07002631 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 /* The AutoNeg process has completed, so we now need to
2633 * read both the Auto Negotiation Advertisement Register
2634 * (Address 4) and the Auto_Negotiation Base Page Ability
2635 * Register (Address 5) to determine how flow control was
2636 * negotiated.
2637 */
2638 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2639 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002640 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 return ret_val;
2642 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2643 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002644 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 return ret_val;
2646
2647 /* Two bits in the Auto Negotiation Advertisement Register
2648 * (Address 4) and two bits in the Auto Negotiation Base
2649 * Page Ability Register (Address 5) determine flow control
2650 * for both the PHY and the link partner. The following
2651 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2652 * 1999, describes these PAUSE resolution bits and how flow
2653 * control is determined based upon these settings.
2654 * NOTE: DC = Don't Care
2655 *
2656 * LOCAL DEVICE | LINK PARTNER
2657 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2658 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002659 * 0 | 0 | DC | DC | E1000_FC_NONE
2660 * 0 | 1 | 0 | DC | E1000_FC_NONE
2661 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2662 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2663 * 1 | 0 | 0 | DC | E1000_FC_NONE
2664 * 1 | DC | 1 | DC | E1000_FC_FULL
2665 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2666 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 *
2668 */
2669 /* Are both PAUSE bits set to 1? If so, this implies
2670 * Symmetric Flow Control is enabled at both ends. The
2671 * ASM_DIR bits are irrelevant per the spec.
2672 *
2673 * For Symmetric Flow Control:
2674 *
2675 * LOCAL DEVICE | LINK PARTNER
2676 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2677 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002678 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 *
2680 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002681 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2682 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 /* Now we need to check if the user selected RX ONLY
2684 * of pause frames. In this case, we had to advertise
2685 * FULL flow control because we could not advertise RX
2686 * ONLY. Hence, we must now check to see if we need to
2687 * turn OFF the TRANSMISSION of PAUSE frames.
2688 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002689 if (hw->original_fc == E1000_FC_FULL) {
2690 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002691 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002693 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002694 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
2696 }
2697 /* For receiving PAUSE frames ONLY.
2698 *
2699 * LOCAL DEVICE | LINK PARTNER
2700 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2701 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002702 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 *
2704 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002705 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2706 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2707 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2708 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002709 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002710 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 }
2712 /* For transmitting PAUSE frames ONLY.
2713 *
2714 * LOCAL DEVICE | LINK PARTNER
2715 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2716 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002717 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 *
2719 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002720 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2721 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2722 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2723 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002724 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002725 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 }
2727 /* Per the IEEE spec, at this point flow control should be
2728 * disabled. However, we want to consider that we could
2729 * be connected to a legacy switch that doesn't advertise
2730 * desired flow control, but can be forced on the link
2731 * partner. So if we advertised no flow control, that is
2732 * what we will resolve to. If we advertised some kind of
2733 * receive capability (Rx Pause Only or Full Flow Control)
2734 * and the link partner advertised none, we will configure
2735 * ourselves to enable Rx Flow Control only. We can do
2736 * this safely for two reasons: If the link partner really
2737 * didn't want flow control enabled, and we enable Rx, no
2738 * harm done since we won't be receiving any PAUSE frames
2739 * anyway. If the intent on the link partner was to have
2740 * flow control enabled, then by us enabling RX only, we
2741 * can at least receive pause frames and process them.
2742 * This is a good idea because in most cases, since we are
2743 * predominantly a server NIC, more times than not we will
2744 * be asked to delay transmission of packets than asking
2745 * our link partner to pause transmission of frames.
2746 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002747 else if ((hw->original_fc == E1000_FC_NONE ||
2748 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002749 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002750 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002751 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002753 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002754 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 }
2756
2757 /* Now we need to do one last check... If we auto-
2758 * negotiated to HALF DUPLEX, flow control should not be
2759 * enabled per IEEE 802.3 spec.
2760 */
2761 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002762 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 DEBUGOUT("Error getting link speed and duplex\n");
2764 return ret_val;
2765 }
2766
Auke Kok8fc897b2006-08-28 14:56:16 -07002767 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002768 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
2770 /* Now we call a subroutine to actually force the MAC
2771 * controller to use the correct flow control settings.
2772 */
2773 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002774 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 DEBUGOUT("Error forcing flow control settings\n");
2776 return ret_val;
2777 }
2778 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002779 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 }
2781 }
2782 return E1000_SUCCESS;
2783}
2784
2785/******************************************************************************
2786 * Checks to see if the link status of the hardware has changed.
2787 *
2788 * hw - Struct containing variables accessed by shared code
2789 *
2790 * Called by any function that needs to check the link status of the adapter.
2791 *****************************************************************************/
2792int32_t
2793e1000_check_for_link(struct e1000_hw *hw)
2794{
2795 uint32_t rxcw = 0;
2796 uint32_t ctrl;
2797 uint32_t status;
2798 uint32_t rctl;
2799 uint32_t icr;
2800 uint32_t signal = 0;
2801 int32_t ret_val;
2802 uint16_t phy_data;
2803
2804 DEBUGFUNC("e1000_check_for_link");
2805
2806 ctrl = E1000_READ_REG(hw, CTRL);
2807 status = E1000_READ_REG(hw, STATUS);
2808
2809 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2810 * set when the optics detect a signal. On older adapters, it will be
2811 * cleared when there is a signal. This applies to fiber media only.
2812 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002813 if ((hw->media_type == e1000_media_type_fiber) ||
2814 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 rxcw = E1000_READ_REG(hw, RXCW);
2816
Auke Kok8fc897b2006-08-28 14:56:16 -07002817 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002819 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 hw->get_link_status = FALSE;
2821 }
2822 }
2823
2824 /* If we have a copper PHY then we only want to go out to the PHY
2825 * registers to see if Auto-Neg has completed and/or if our link
2826 * status has changed. The get_link_status flag will be set if we
2827 * receive a Link Status Change interrupt or we have Rx Sequence
2828 * Errors.
2829 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002830 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 /* First we want to see if the MII Status Register reports
2832 * link. If so, then we want to get the current speed/duplex
2833 * of the PHY.
2834 * Read the register twice since the link bit is sticky.
2835 */
2836 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002837 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 return ret_val;
2839 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002840 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 return ret_val;
2842
Auke Kok8fc897b2006-08-28 14:56:16 -07002843 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 hw->get_link_status = FALSE;
2845 /* Check if there was DownShift, must be checked immediately after
2846 * link-up */
2847 e1000_check_downshift(hw);
2848
2849 /* If we are on 82544 or 82543 silicon and speed/duplex
2850 * are forced to 10H or 10F, then we will implement the polarity
2851 * reversal workaround. We disable interrupts first, and upon
2852 * returning, place the devices interrupt state to its previous
2853 * value except for the link status change interrupt which will
2854 * happen due to the execution of this workaround.
2855 */
2856
Auke Kok8fc897b2006-08-28 14:56:16 -07002857 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2858 (!hw->autoneg) &&
2859 (hw->forced_speed_duplex == e1000_10_full ||
2860 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2862 ret_val = e1000_polarity_reversal_workaround(hw);
2863 icr = E1000_READ_REG(hw, ICR);
2864 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2865 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2866 }
2867
2868 } else {
2869 /* No link detected */
2870 e1000_config_dsp_after_link_change(hw, FALSE);
2871 return 0;
2872 }
2873
2874 /* If we are forcing speed/duplex, then we simply return since
2875 * we have already determined whether we have link or not.
2876 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002877 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
2879 /* optimize the dsp settings for the igp phy */
2880 e1000_config_dsp_after_link_change(hw, TRUE);
2881
2882 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2883 * have Si on board that is 82544 or newer, Auto
2884 * Speed Detection takes care of MAC speed/duplex
2885 * configuration. So we only need to configure Collision
2886 * Distance in the MAC. Otherwise, we need to force
2887 * speed/duplex on the MAC to the current PHY speed/duplex
2888 * settings.
2889 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002890 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 e1000_config_collision_dist(hw);
2892 else {
2893 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002894 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 DEBUGOUT("Error configuring MAC to PHY settings\n");
2896 return ret_val;
2897 }
2898 }
2899
2900 /* Configure Flow Control now that Auto-Neg has completed. First, we
2901 * need to restore the desired flow control settings because we may
2902 * have had to re-autoneg with a different link partner.
2903 */
2904 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002905 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 DEBUGOUT("Error configuring flow control\n");
2907 return ret_val;
2908 }
2909
2910 /* At this point we know that we are on copper and we have
2911 * auto-negotiated link. These are conditions for checking the link
2912 * partner capability register. We use the link speed to determine if
2913 * TBI compatibility needs to be turned on or off. If the link is not
2914 * at gigabit speed, then TBI compatibility is not needed. If we are
2915 * at gigabit speed, we turn on TBI compatibility.
2916 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002917 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07002919 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2920 if (ret_val) {
2921 DEBUGOUT("Error getting link speed and duplex\n");
2922 return ret_val;
2923 }
2924 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 /* If link speed is not set to gigabit speed, we do not need
2926 * to enable TBI compatibility.
2927 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002928 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 /* If we previously were in the mode, turn it off. */
2930 rctl = E1000_READ_REG(hw, RCTL);
2931 rctl &= ~E1000_RCTL_SBP;
2932 E1000_WRITE_REG(hw, RCTL, rctl);
2933 hw->tbi_compatibility_on = FALSE;
2934 }
2935 } else {
2936 /* If TBI compatibility is was previously off, turn it on. For
2937 * compatibility with a TBI link partner, we will store bad
2938 * packets. Some frames have an additional byte on the end and
2939 * will look like CRC errors to to the hardware.
2940 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002941 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 hw->tbi_compatibility_on = TRUE;
2943 rctl = E1000_READ_REG(hw, RCTL);
2944 rctl |= E1000_RCTL_SBP;
2945 E1000_WRITE_REG(hw, RCTL, rctl);
2946 }
2947 }
2948 }
2949 }
2950 /* If we don't have link (auto-negotiation failed or link partner cannot
2951 * auto-negotiate), the cable is plugged in (we have signal), and our
2952 * link partner is not trying to auto-negotiate with us (we are receiving
2953 * idles or data), we need to force link up. We also need to give
2954 * auto-negotiation time to complete, in case the cable was just plugged
2955 * in. The autoneg_failed flag does this.
2956 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002957 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002959 (hw->media_type == e1000_media_type_internal_serdes)) &&
2960 (!(status & E1000_STATUS_LU)) &&
2961 (!(rxcw & E1000_RXCW_C))) {
2962 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 hw->autoneg_failed = 1;
2964 return 0;
2965 }
Auke Koka42a5072006-05-23 13:36:01 -07002966 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
2968 /* Disable auto-negotiation in the TXCW register */
2969 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2970
2971 /* Force link-up and also force full-duplex. */
2972 ctrl = E1000_READ_REG(hw, CTRL);
2973 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2974 E1000_WRITE_REG(hw, CTRL, ctrl);
2975
2976 /* Configure Flow Control after forcing link up. */
2977 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002978 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 DEBUGOUT("Error configuring flow control\n");
2980 return ret_val;
2981 }
2982 }
2983 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2984 * auto-negotiation in the TXCW register and disable forced link in the
2985 * Device Control register in an attempt to auto-negotiate with our link
2986 * partner.
2987 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002988 else if (((hw->media_type == e1000_media_type_fiber) ||
2989 (hw->media_type == e1000_media_type_internal_serdes)) &&
2990 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07002991 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2993 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2994
2995 hw->serdes_link_down = FALSE;
2996 }
2997 /* If we force link for non-auto-negotiation switch, check link status
2998 * based on MAC synchronization for internal serdes media type.
2999 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003000 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3001 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 /* SYNCH bit and IV bit are sticky. */
3003 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003004 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3005 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 hw->serdes_link_down = FALSE;
3007 DEBUGOUT("SERDES: Link is up.\n");
3008 }
3009 } else {
3010 hw->serdes_link_down = TRUE;
3011 DEBUGOUT("SERDES: Link is down.\n");
3012 }
3013 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003014 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3015 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3017 }
3018 return E1000_SUCCESS;
3019}
3020
3021/******************************************************************************
3022 * Detects the current speed and duplex settings of the hardware.
3023 *
3024 * hw - Struct containing variables accessed by shared code
3025 * speed - Speed of the connection
3026 * duplex - Duplex setting of the connection
3027 *****************************************************************************/
3028int32_t
3029e1000_get_speed_and_duplex(struct e1000_hw *hw,
3030 uint16_t *speed,
3031 uint16_t *duplex)
3032{
3033 uint32_t status;
3034 int32_t ret_val;
3035 uint16_t phy_data;
3036
3037 DEBUGFUNC("e1000_get_speed_and_duplex");
3038
Auke Kok8fc897b2006-08-28 14:56:16 -07003039 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003041 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 *speed = SPEED_1000;
3043 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003044 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 *speed = SPEED_100;
3046 DEBUGOUT("100 Mbs, ");
3047 } else {
3048 *speed = SPEED_10;
3049 DEBUGOUT("10 Mbs, ");
3050 }
3051
Auke Kok8fc897b2006-08-28 14:56:16 -07003052 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003054 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 } else {
3056 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003057 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 }
3059 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003060 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 *speed = SPEED_1000;
3062 *duplex = FULL_DUPLEX;
3063 }
3064
3065 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3066 * if it is operating at half duplex. Here we set the duplex settings to
3067 * match the duplex in the link partner's capabilities.
3068 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003069 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003071 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 return ret_val;
3073
Auke Kok8fc897b2006-08-28 14:56:16 -07003074 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 *duplex = HALF_DUPLEX;
3076 else {
3077 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003078 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003080 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3082 *duplex = HALF_DUPLEX;
3083 }
3084 }
3085
Auke Kok76c224b2006-05-23 13:36:06 -07003086 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003087 (hw->media_type == e1000_media_type_copper)) {
3088 if (*speed == SPEED_1000)
3089 ret_val = e1000_configure_kmrn_for_1000(hw);
3090 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003091 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3092 if (ret_val)
3093 return ret_val;
3094 }
3095
3096 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3097 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003098 if (ret_val)
3099 return ret_val;
3100 }
3101
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 return E1000_SUCCESS;
3103}
3104
3105/******************************************************************************
3106* Blocks until autoneg completes or times out (~4.5 seconds)
3107*
3108* hw - Struct containing variables accessed by shared code
3109******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003110static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111e1000_wait_autoneg(struct e1000_hw *hw)
3112{
3113 int32_t ret_val;
3114 uint16_t i;
3115 uint16_t phy_data;
3116
3117 DEBUGFUNC("e1000_wait_autoneg");
3118 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3119
3120 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003121 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 /* Read the MII Status Register and wait for Auto-Neg
3123 * Complete bit to be set.
3124 */
3125 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003126 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 return ret_val;
3128 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003129 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003131 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 return E1000_SUCCESS;
3133 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003134 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 }
3136 return E1000_SUCCESS;
3137}
3138
3139/******************************************************************************
3140* Raises the Management Data Clock
3141*
3142* hw - Struct containing variables accessed by shared code
3143* ctrl - Device control register's current value
3144******************************************************************************/
3145static void
3146e1000_raise_mdi_clk(struct e1000_hw *hw,
3147 uint32_t *ctrl)
3148{
3149 /* Raise the clock input to the Management Data Clock (by setting the MDC
3150 * bit), and then delay 10 microseconds.
3151 */
3152 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3153 E1000_WRITE_FLUSH(hw);
3154 udelay(10);
3155}
3156
3157/******************************************************************************
3158* Lowers the Management Data Clock
3159*
3160* hw - Struct containing variables accessed by shared code
3161* ctrl - Device control register's current value
3162******************************************************************************/
3163static void
3164e1000_lower_mdi_clk(struct e1000_hw *hw,
3165 uint32_t *ctrl)
3166{
3167 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3168 * bit), and then delay 10 microseconds.
3169 */
3170 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3171 E1000_WRITE_FLUSH(hw);
3172 udelay(10);
3173}
3174
3175/******************************************************************************
3176* Shifts data bits out to the PHY
3177*
3178* hw - Struct containing variables accessed by shared code
3179* data - Data to send out to the PHY
3180* count - Number of bits to shift out
3181*
3182* Bits are shifted out in MSB to LSB order.
3183******************************************************************************/
3184static void
3185e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3186 uint32_t data,
3187 uint16_t count)
3188{
3189 uint32_t ctrl;
3190 uint32_t mask;
3191
3192 /* We need to shift "count" number of bits out to the PHY. So, the value
3193 * in the "data" parameter will be shifted out to the PHY one bit at a
3194 * time. In order to do this, "data" must be broken down into bits.
3195 */
3196 mask = 0x01;
3197 mask <<= (count - 1);
3198
3199 ctrl = E1000_READ_REG(hw, CTRL);
3200
3201 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3202 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3203
Auke Kok8fc897b2006-08-28 14:56:16 -07003204 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3206 * then raising and lowering the Management Data Clock. A "0" is
3207 * shifted out to the PHY by setting the MDIO bit to "0" and then
3208 * raising and lowering the clock.
3209 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003210 if (data & mask)
3211 ctrl |= E1000_CTRL_MDIO;
3212 else
3213 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 E1000_WRITE_REG(hw, CTRL, ctrl);
3216 E1000_WRITE_FLUSH(hw);
3217
3218 udelay(10);
3219
3220 e1000_raise_mdi_clk(hw, &ctrl);
3221 e1000_lower_mdi_clk(hw, &ctrl);
3222
3223 mask = mask >> 1;
3224 }
3225}
3226
3227/******************************************************************************
3228* Shifts data bits in from the PHY
3229*
3230* hw - Struct containing variables accessed by shared code
3231*
3232* Bits are shifted in in MSB to LSB order.
3233******************************************************************************/
3234static uint16_t
3235e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3236{
3237 uint32_t ctrl;
3238 uint16_t data = 0;
3239 uint8_t i;
3240
3241 /* In order to read a register from the PHY, we need to shift in a total
3242 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3243 * to avoid contention on the MDIO pin when a read operation is performed.
3244 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3245 * by raising the input to the Management Data Clock (setting the MDC bit),
3246 * and then reading the value of the MDIO bit.
3247 */
3248 ctrl = E1000_READ_REG(hw, CTRL);
3249
3250 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3251 ctrl &= ~E1000_CTRL_MDIO_DIR;
3252 ctrl &= ~E1000_CTRL_MDIO;
3253
3254 E1000_WRITE_REG(hw, CTRL, ctrl);
3255 E1000_WRITE_FLUSH(hw);
3256
3257 /* Raise and Lower the clock before reading in the data. This accounts for
3258 * the turnaround bits. The first clock occurred when we clocked out the
3259 * last bit of the Register Address.
3260 */
3261 e1000_raise_mdi_clk(hw, &ctrl);
3262 e1000_lower_mdi_clk(hw, &ctrl);
3263
Auke Kok8fc897b2006-08-28 14:56:16 -07003264 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 data = data << 1;
3266 e1000_raise_mdi_clk(hw, &ctrl);
3267 ctrl = E1000_READ_REG(hw, CTRL);
3268 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003269 if (ctrl & E1000_CTRL_MDIO)
3270 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 e1000_lower_mdi_clk(hw, &ctrl);
3272 }
3273
3274 e1000_raise_mdi_clk(hw, &ctrl);
3275 e1000_lower_mdi_clk(hw, &ctrl);
3276
3277 return data;
3278}
3279
Adrian Bunke4c780b2006-08-14 23:00:10 -07003280static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003281e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3282{
3283 uint32_t swfw_sync = 0;
3284 uint32_t swmask = mask;
3285 uint32_t fwmask = mask << 16;
3286 int32_t timeout = 200;
3287
3288 DEBUGFUNC("e1000_swfw_sync_acquire");
3289
Auke Kokcd94dd02006-06-27 09:08:22 -07003290 if (hw->swfwhw_semaphore_present)
3291 return e1000_get_software_flag(hw);
3292
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003293 if (!hw->swfw_sync_present)
3294 return e1000_get_hw_eeprom_semaphore(hw);
3295
Auke Kok8fc897b2006-08-28 14:56:16 -07003296 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003297 if (e1000_get_hw_eeprom_semaphore(hw))
3298 return -E1000_ERR_SWFW_SYNC;
3299
3300 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3301 if (!(swfw_sync & (fwmask | swmask))) {
3302 break;
3303 }
3304
3305 /* firmware currently using resource (fwmask) */
3306 /* or other software thread currently using resource (swmask) */
3307 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003308 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003309 timeout--;
3310 }
3311
3312 if (!timeout) {
3313 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3314 return -E1000_ERR_SWFW_SYNC;
3315 }
3316
3317 swfw_sync |= swmask;
3318 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3319
3320 e1000_put_hw_eeprom_semaphore(hw);
3321 return E1000_SUCCESS;
3322}
3323
Adrian Bunke4c780b2006-08-14 23:00:10 -07003324static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003325e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3326{
3327 uint32_t swfw_sync;
3328 uint32_t swmask = mask;
3329
3330 DEBUGFUNC("e1000_swfw_sync_release");
3331
Auke Kokcd94dd02006-06-27 09:08:22 -07003332 if (hw->swfwhw_semaphore_present) {
3333 e1000_release_software_flag(hw);
3334 return;
3335 }
3336
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003337 if (!hw->swfw_sync_present) {
3338 e1000_put_hw_eeprom_semaphore(hw);
3339 return;
3340 }
3341
3342 /* if (e1000_get_hw_eeprom_semaphore(hw))
3343 * return -E1000_ERR_SWFW_SYNC; */
3344 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3345 /* empty */
3346
3347 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3348 swfw_sync &= ~swmask;
3349 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3350
3351 e1000_put_hw_eeprom_semaphore(hw);
3352}
3353
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354/*****************************************************************************
3355* Reads the value from a PHY register, if the value is on a specific non zero
3356* page, sets the page first.
3357* hw - Struct containing variables accessed by shared code
3358* reg_addr - address of the PHY register to read
3359******************************************************************************/
3360int32_t
3361e1000_read_phy_reg(struct e1000_hw *hw,
3362 uint32_t reg_addr,
3363 uint16_t *phy_data)
3364{
3365 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003366 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
3368 DEBUGFUNC("e1000_read_phy_reg");
3369
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003370 if ((hw->mac_type == e1000_80003es2lan) &&
3371 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3372 swfw = E1000_SWFW_PHY1_SM;
3373 } else {
3374 swfw = E1000_SWFW_PHY0_SM;
3375 }
3376 if (e1000_swfw_sync_acquire(hw, swfw))
3377 return -E1000_ERR_SWFW_SYNC;
3378
Auke Kokcd94dd02006-06-27 09:08:22 -07003379 if ((hw->phy_type == e1000_phy_igp ||
3380 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003381 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3383 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3384 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003385 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003386 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 return ret_val;
3388 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003389 } else if (hw->phy_type == e1000_phy_gg82563) {
3390 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3391 (hw->mac_type == e1000_80003es2lan)) {
3392 /* Select Configuration Page */
3393 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3394 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3395 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3396 } else {
3397 /* Use Alternative Page Select register to access
3398 * registers 30 and 31
3399 */
3400 ret_val = e1000_write_phy_reg_ex(hw,
3401 GG82563_PHY_PAGE_SELECT_ALT,
3402 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3403 }
3404
3405 if (ret_val) {
3406 e1000_swfw_sync_release(hw, swfw);
3407 return ret_val;
3408 }
3409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 }
3411
3412 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3413 phy_data);
3414
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003415 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 return ret_val;
3417}
3418
3419int32_t
3420e1000_read_phy_reg_ex(struct e1000_hw *hw,
3421 uint32_t reg_addr,
3422 uint16_t *phy_data)
3423{
3424 uint32_t i;
3425 uint32_t mdic = 0;
3426 const uint32_t phy_addr = 1;
3427
3428 DEBUGFUNC("e1000_read_phy_reg_ex");
3429
Auke Kok8fc897b2006-08-28 14:56:16 -07003430 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3432 return -E1000_ERR_PARAM;
3433 }
3434
Auke Kok8fc897b2006-08-28 14:56:16 -07003435 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 /* Set up Op-code, Phy Address, and register address in the MDI
3437 * Control register. The MAC will take care of interfacing with the
3438 * PHY to retrieve the desired data.
3439 */
3440 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3441 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3442 (E1000_MDIC_OP_READ));
3443
3444 E1000_WRITE_REG(hw, MDIC, mdic);
3445
3446 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003447 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 udelay(50);
3449 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003450 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003452 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 DEBUGOUT("MDI Read did not complete\n");
3454 return -E1000_ERR_PHY;
3455 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003456 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 DEBUGOUT("MDI Error\n");
3458 return -E1000_ERR_PHY;
3459 }
3460 *phy_data = (uint16_t) mdic;
3461 } else {
3462 /* We must first send a preamble through the MDIO pin to signal the
3463 * beginning of an MII instruction. This is done by sending 32
3464 * consecutive "1" bits.
3465 */
3466 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3467
3468 /* Now combine the next few fields that are required for a read
3469 * operation. We use this method instead of calling the
3470 * e1000_shift_out_mdi_bits routine five different times. The format of
3471 * a MII read instruction consists of a shift out of 14 bits and is
3472 * defined as follows:
3473 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3474 * followed by a shift in of 18 bits. This first two bits shifted in
3475 * are TurnAround bits used to avoid contention on the MDIO pin when a
3476 * READ operation is performed. These two bits are thrown away
3477 * followed by a shift in of 16 bits which contains the desired data.
3478 */
3479 mdic = ((reg_addr) | (phy_addr << 5) |
3480 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3481
3482 e1000_shift_out_mdi_bits(hw, mdic, 14);
3483
3484 /* Now that we've shifted out the read command to the MII, we need to
3485 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3486 * register address.
3487 */
3488 *phy_data = e1000_shift_in_mdi_bits(hw);
3489 }
3490 return E1000_SUCCESS;
3491}
3492
3493/******************************************************************************
3494* Writes a value to a PHY register
3495*
3496* hw - Struct containing variables accessed by shared code
3497* reg_addr - address of the PHY register to write
3498* data - data to write to the PHY
3499******************************************************************************/
3500int32_t
3501e1000_write_phy_reg(struct e1000_hw *hw,
3502 uint32_t reg_addr,
3503 uint16_t phy_data)
3504{
3505 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003506 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507
3508 DEBUGFUNC("e1000_write_phy_reg");
3509
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003510 if ((hw->mac_type == e1000_80003es2lan) &&
3511 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3512 swfw = E1000_SWFW_PHY1_SM;
3513 } else {
3514 swfw = E1000_SWFW_PHY0_SM;
3515 }
3516 if (e1000_swfw_sync_acquire(hw, swfw))
3517 return -E1000_ERR_SWFW_SYNC;
3518
Auke Kokcd94dd02006-06-27 09:08:22 -07003519 if ((hw->phy_type == e1000_phy_igp ||
3520 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003521 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3523 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3524 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003525 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003526 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 return ret_val;
3528 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003529 } else if (hw->phy_type == e1000_phy_gg82563) {
3530 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3531 (hw->mac_type == e1000_80003es2lan)) {
3532 /* Select Configuration Page */
3533 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3534 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3535 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3536 } else {
3537 /* Use Alternative Page Select register to access
3538 * registers 30 and 31
3539 */
3540 ret_val = e1000_write_phy_reg_ex(hw,
3541 GG82563_PHY_PAGE_SELECT_ALT,
3542 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3543 }
3544
3545 if (ret_val) {
3546 e1000_swfw_sync_release(hw, swfw);
3547 return ret_val;
3548 }
3549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 }
3551
3552 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3553 phy_data);
3554
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003555 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 return ret_val;
3557}
3558
3559int32_t
3560e1000_write_phy_reg_ex(struct e1000_hw *hw,
3561 uint32_t reg_addr,
3562 uint16_t phy_data)
3563{
3564 uint32_t i;
3565 uint32_t mdic = 0;
3566 const uint32_t phy_addr = 1;
3567
3568 DEBUGFUNC("e1000_write_phy_reg_ex");
3569
Auke Kok8fc897b2006-08-28 14:56:16 -07003570 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3572 return -E1000_ERR_PARAM;
3573 }
3574
Auke Kok8fc897b2006-08-28 14:56:16 -07003575 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 /* Set up Op-code, Phy Address, register address, and data intended
3577 * for the PHY register in the MDI Control register. The MAC will take
3578 * care of interfacing with the PHY to send the desired data.
3579 */
3580 mdic = (((uint32_t) phy_data) |
3581 (reg_addr << E1000_MDIC_REG_SHIFT) |
3582 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3583 (E1000_MDIC_OP_WRITE));
3584
3585 E1000_WRITE_REG(hw, MDIC, mdic);
3586
3587 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003588 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 udelay(5);
3590 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003591 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003593 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 DEBUGOUT("MDI Write did not complete\n");
3595 return -E1000_ERR_PHY;
3596 }
3597 } else {
3598 /* We'll need to use the SW defined pins to shift the write command
3599 * out to the PHY. We first send a preamble to the PHY to signal the
3600 * beginning of the MII instruction. This is done by sending 32
3601 * consecutive "1" bits.
3602 */
3603 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3604
3605 /* Now combine the remaining required fields that will indicate a
3606 * write operation. We use this method instead of calling the
3607 * e1000_shift_out_mdi_bits routine for each field in the command. The
3608 * format of a MII write instruction is as follows:
3609 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3610 */
3611 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3612 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3613 mdic <<= 16;
3614 mdic |= (uint32_t) phy_data;
3615
3616 e1000_shift_out_mdi_bits(hw, mdic, 32);
3617 }
3618
3619 return E1000_SUCCESS;
3620}
3621
Adrian Bunke4c780b2006-08-14 23:00:10 -07003622static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003623e1000_read_kmrn_reg(struct e1000_hw *hw,
3624 uint32_t reg_addr,
3625 uint16_t *data)
3626{
3627 uint32_t reg_val;
3628 uint16_t swfw;
3629 DEBUGFUNC("e1000_read_kmrn_reg");
3630
3631 if ((hw->mac_type == e1000_80003es2lan) &&
3632 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3633 swfw = E1000_SWFW_PHY1_SM;
3634 } else {
3635 swfw = E1000_SWFW_PHY0_SM;
3636 }
3637 if (e1000_swfw_sync_acquire(hw, swfw))
3638 return -E1000_ERR_SWFW_SYNC;
3639
3640 /* Write register address */
3641 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3642 E1000_KUMCTRLSTA_OFFSET) |
3643 E1000_KUMCTRLSTA_REN;
3644 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3645 udelay(2);
3646
3647 /* Read the data returned */
3648 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3649 *data = (uint16_t)reg_val;
3650
3651 e1000_swfw_sync_release(hw, swfw);
3652 return E1000_SUCCESS;
3653}
3654
Adrian Bunke4c780b2006-08-14 23:00:10 -07003655static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003656e1000_write_kmrn_reg(struct e1000_hw *hw,
3657 uint32_t reg_addr,
3658 uint16_t data)
3659{
3660 uint32_t reg_val;
3661 uint16_t swfw;
3662 DEBUGFUNC("e1000_write_kmrn_reg");
3663
3664 if ((hw->mac_type == e1000_80003es2lan) &&
3665 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3666 swfw = E1000_SWFW_PHY1_SM;
3667 } else {
3668 swfw = E1000_SWFW_PHY0_SM;
3669 }
3670 if (e1000_swfw_sync_acquire(hw, swfw))
3671 return -E1000_ERR_SWFW_SYNC;
3672
3673 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3674 E1000_KUMCTRLSTA_OFFSET) | data;
3675 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3676 udelay(2);
3677
3678 e1000_swfw_sync_release(hw, swfw);
3679 return E1000_SUCCESS;
3680}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003681
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682/******************************************************************************
3683* Returns the PHY to the power-on reset state
3684*
3685* hw - Struct containing variables accessed by shared code
3686******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003687int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688e1000_phy_hw_reset(struct e1000_hw *hw)
3689{
3690 uint32_t ctrl, ctrl_ext;
3691 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003692 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003693 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694
3695 DEBUGFUNC("e1000_phy_hw_reset");
3696
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003697 /* In the case of the phy reset being blocked, it's not an error, we
3698 * simply return success without performing the reset. */
3699 ret_val = e1000_check_phy_reset_block(hw);
3700 if (ret_val)
3701 return E1000_SUCCESS;
3702
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 DEBUGOUT("Resetting Phy...\n");
3704
Auke Kok8fc897b2006-08-28 14:56:16 -07003705 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003706 if ((hw->mac_type == e1000_80003es2lan) &&
3707 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3708 swfw = E1000_SWFW_PHY1_SM;
3709 } else {
3710 swfw = E1000_SWFW_PHY0_SM;
3711 }
3712 if (e1000_swfw_sync_acquire(hw, swfw)) {
3713 e1000_release_software_semaphore(hw);
3714 return -E1000_ERR_SWFW_SYNC;
3715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3717 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003718 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003719 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003720 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 */
3722 ctrl = E1000_READ_REG(hw, CTRL);
3723 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3724 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003725
3726 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003727 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003728 else
3729 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003730
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 E1000_WRITE_REG(hw, CTRL, ctrl);
3732 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003733
Jeff Kirsherfd803242005-12-13 00:06:22 -05003734 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003735 mdelay(10);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003736 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 } else {
3738 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3739 * bit to put the PHY into reset. Then, take it out of reset.
3740 */
3741 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3742 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3743 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3744 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3745 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003746 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3748 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3749 E1000_WRITE_FLUSH(hw);
3750 }
3751 udelay(150);
3752
Auke Kok8fc897b2006-08-28 14:56:16 -07003753 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 /* Configure activity LED after PHY reset */
3755 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3756 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3757 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3758 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3759 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003760
3761 /* Wait for FW to finish PHY configuration. */
3762 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003763 if (ret_val != E1000_SUCCESS)
3764 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003765 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003766
Auke Kok8fc897b2006-08-28 14:56:16 -07003767 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3768 ret_val = e1000_init_lcd_from_nvm(hw);
3769
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003770 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771}
3772
3773/******************************************************************************
3774* Resets the PHY
3775*
3776* hw - Struct containing variables accessed by shared code
3777*
3778* Sets bit 15 of the MII Control regiser
3779******************************************************************************/
3780int32_t
3781e1000_phy_reset(struct e1000_hw *hw)
3782{
3783 int32_t ret_val;
3784 uint16_t phy_data;
3785
3786 DEBUGFUNC("e1000_phy_reset");
3787
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003788 /* In the case of the phy reset being blocked, it's not an error, we
3789 * simply return success without performing the reset. */
3790 ret_val = e1000_check_phy_reset_block(hw);
3791 if (ret_val)
3792 return E1000_SUCCESS;
3793
3794 switch (hw->mac_type) {
3795 case e1000_82541_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003796 case e1000_82571:
3797 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07003798 case e1000_ich8lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003799 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003800 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003801 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07003802
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003803 break;
3804 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003806 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 return ret_val;
3808
3809 phy_data |= MII_CR_RESET;
3810 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003811 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 return ret_val;
3813
3814 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003815 break;
3816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
Auke Kok8fc897b2006-08-28 14:56:16 -07003818 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 e1000_phy_init_script(hw);
3820
3821 return E1000_SUCCESS;
3822}
3823
3824/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003825* Work-around for 82566 power-down: on D3 entry-
3826* 1) disable gigabit link
3827* 2) write VR power-down enable
3828* 3) read it back
3829* if successful continue, else issue LCD reset and repeat
3830*
3831* hw - struct containing variables accessed by shared code
3832******************************************************************************/
3833void
3834e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3835{
3836 int32_t reg;
3837 uint16_t phy_data;
3838 int32_t retry = 0;
3839
3840 DEBUGFUNC("e1000_phy_powerdown_workaround");
3841
3842 if (hw->phy_type != e1000_phy_igp_3)
3843 return;
3844
3845 do {
3846 /* Disable link */
3847 reg = E1000_READ_REG(hw, PHY_CTRL);
3848 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3849 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3850
3851 /* Write VR power-down enable */
3852 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3853 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data |
3854 IGP3_VR_CTRL_MODE_SHUT);
3855
3856 /* Read it back and test */
3857 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3858 if ((phy_data & IGP3_VR_CTRL_MODE_SHUT) || retry)
3859 break;
3860
3861 /* Issue PHY reset and repeat at most one more time */
3862 reg = E1000_READ_REG(hw, CTRL);
3863 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3864 retry++;
3865 } while (retry);
3866
3867 return;
3868
3869}
3870
3871/******************************************************************************
3872* Work-around for 82566 Kumeran PCS lock loss:
3873* On link status change (i.e. PCI reset, speed change) and link is up and
3874* speed is gigabit-
3875* 0) if workaround is optionally disabled do nothing
3876* 1) wait 1ms for Kumeran link to come up
3877* 2) check Kumeran Diagnostic register PCS lock loss bit
3878* 3) if not set the link is locked (all is good), otherwise...
3879* 4) reset the PHY
3880* 5) repeat up to 10 times
3881* Note: this is only called for IGP3 copper when speed is 1gb.
3882*
3883* hw - struct containing variables accessed by shared code
3884******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003885static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003886e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3887{
3888 int32_t ret_val;
3889 int32_t reg;
3890 int32_t cnt;
3891 uint16_t phy_data;
3892
3893 if (hw->kmrn_lock_loss_workaround_disabled)
3894 return E1000_SUCCESS;
3895
Auke Kok8fc897b2006-08-28 14:56:16 -07003896 /* Make sure link is up before proceeding. If not just return.
3897 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003898 * stability */
3899 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3900 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3901
3902 if (phy_data & MII_SR_LINK_STATUS) {
3903 for (cnt = 0; cnt < 10; cnt++) {
3904 /* read once to clear */
3905 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3906 if (ret_val)
3907 return ret_val;
3908 /* and again to get new status */
3909 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3910 if (ret_val)
3911 return ret_val;
3912
3913 /* check for PCS lock */
3914 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3915 return E1000_SUCCESS;
3916
3917 /* Issue PHY reset */
3918 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003919 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003920 }
3921 /* Disable GigE link negotiation */
3922 reg = E1000_READ_REG(hw, PHY_CTRL);
3923 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3924 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3925
3926 /* unable to acquire PCS lock */
3927 return E1000_ERR_PHY;
3928 }
3929
3930 return E1000_SUCCESS;
3931}
3932
3933/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934* Probes the expected PHY address for known PHY IDs
3935*
3936* hw - Struct containing variables accessed by shared code
3937******************************************************************************/
Auke Kokd37ea5d2006-06-27 09:08:17 -07003938int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939e1000_detect_gig_phy(struct e1000_hw *hw)
3940{
3941 int32_t phy_init_status, ret_val;
3942 uint16_t phy_id_high, phy_id_low;
3943 boolean_t match = FALSE;
3944
3945 DEBUGFUNC("e1000_detect_gig_phy");
3946
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003947 /* The 82571 firmware may still be configuring the PHY. In this
3948 * case, we cannot access the PHY until the configuration is done. So
3949 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07003950 if (hw->mac_type == e1000_82571 ||
3951 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003952 hw->phy_id = IGP01E1000_I_PHY_ID;
3953 hw->phy_type = e1000_phy_igp_2;
3954 return E1000_SUCCESS;
3955 }
3956
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003957 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3958 * around that forces PHY page 0 to be set or the reads fail. The rest of
3959 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3960 * So for ESB-2 we need to have this set so our reads won't fail. If the
3961 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3962 * this out as well. */
3963 if (hw->mac_type == e1000_80003es2lan)
3964 hw->phy_type = e1000_phy_gg82563;
3965
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 /* Read the PHY ID Registers to identify which PHY is onboard. */
3967 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07003968 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 return ret_val;
3970
3971 hw->phy_id = (uint32_t) (phy_id_high << 16);
3972 udelay(20);
3973 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07003974 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 return ret_val;
3976
3977 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3978 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3979
Auke Kok8fc897b2006-08-28 14:56:16 -07003980 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07003982 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 break;
3984 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07003985 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 break;
3987 case e1000_82540:
3988 case e1000_82545:
3989 case e1000_82545_rev_3:
3990 case e1000_82546:
3991 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07003992 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 break;
3994 case e1000_82541:
3995 case e1000_82541_rev_2:
3996 case e1000_82547:
3997 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07003998 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004000 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004001 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004002 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004003 case e1000_80003es2lan:
4004 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4005 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004006 case e1000_ich8lan:
4007 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4008 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4009 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4010 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4011 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 default:
4013 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4014 return -E1000_ERR_CONFIG;
4015 }
4016 phy_init_status = e1000_set_phy_type(hw);
4017
4018 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4019 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4020 return E1000_SUCCESS;
4021 }
4022 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4023 return -E1000_ERR_PHY;
4024}
4025
4026/******************************************************************************
4027* Resets the PHY's DSP
4028*
4029* hw - Struct containing variables accessed by shared code
4030******************************************************************************/
4031static int32_t
4032e1000_phy_reset_dsp(struct e1000_hw *hw)
4033{
4034 int32_t ret_val;
4035 DEBUGFUNC("e1000_phy_reset_dsp");
4036
4037 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004038 if (hw->phy_type != e1000_phy_gg82563) {
4039 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004040 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004043 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004045 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004047 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048
4049 return ret_val;
4050}
4051
4052/******************************************************************************
4053* Get PHY information from various PHY registers for igp PHY only.
4054*
4055* hw - Struct containing variables accessed by shared code
4056* phy_info - PHY information structure
4057******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004058static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059e1000_phy_igp_get_info(struct e1000_hw *hw,
4060 struct e1000_phy_info *phy_info)
4061{
4062 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004063 uint16_t phy_data, min_length, max_length, average;
4064 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065
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
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004089 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4090 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091
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
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004099 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4100 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4101 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4102 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4103 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4104 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105
4106 /* Get cable length */
4107 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004108 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 return ret_val;
4110
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004111 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 average = (max_length + min_length) / 2;
4113
Auke Kok8fc897b2006-08-28 14:56:16 -07004114 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004116 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004118 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004120 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 phy_info->cable_length = e1000_cable_length_110_140;
4122 else
4123 phy_info->cable_length = e1000_cable_length_140;
4124 }
4125
4126 return E1000_SUCCESS;
4127}
4128
4129/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004130* Get PHY information from various PHY registers for ife PHY only.
4131*
4132* hw - Struct containing variables accessed by shared code
4133* phy_info - PHY information structure
4134******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004135static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004136e1000_phy_ife_get_info(struct e1000_hw *hw,
4137 struct e1000_phy_info *phy_info)
4138{
4139 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004140 uint16_t phy_data;
4141 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004142
4143 DEBUGFUNC("e1000_phy_ife_get_info");
4144
4145 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4146 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4147
4148 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4149 if (ret_val)
4150 return ret_val;
4151 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004152 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4153 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4154 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004155
4156 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4157 ret_val = e1000_check_polarity(hw, &polarity);
4158 if (ret_val)
4159 return ret_val;
4160 } else {
4161 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004162 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4163 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4164 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004165 }
4166 phy_info->cable_polarity = polarity;
4167
4168 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4169 if (ret_val)
4170 return ret_val;
4171
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004172 phy_info->mdix_mode = (e1000_auto_x_mode)
4173 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4174 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004175
4176 return E1000_SUCCESS;
4177}
4178
4179/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180* Get PHY information from various PHY registers fot m88 PHY only.
4181*
4182* hw - Struct containing variables accessed by shared code
4183* phy_info - PHY information structure
4184******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004185static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186e1000_phy_m88_get_info(struct e1000_hw *hw,
4187 struct e1000_phy_info *phy_info)
4188{
4189 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004190 uint16_t phy_data;
4191 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
4193 DEBUGFUNC("e1000_phy_m88_get_info");
4194
4195 /* The downshift status is checked only once, after link is established,
4196 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004197 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198
4199 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004200 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 return ret_val;
4202
4203 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004204 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4205 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4206 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4207
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004209 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4210 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4211 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212
4213 /* Check polarity status */
4214 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004215 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004216 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 phy_info->cable_polarity = polarity;
4218
4219 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004220 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 return ret_val;
4222
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004223 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4224 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225
4226 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4227 /* Cable Length Estimation and Local/Remote Receiver Information
4228 * are only valid at 1000 Mbps.
4229 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004230 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004231 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004232 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4233 } else {
4234 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4235 &phy_data);
4236 if (ret_val)
4237 return ret_val;
4238
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004239 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241
4242 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004243 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 return ret_val;
4245
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004246 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4247 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4248 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4249 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4250 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4251 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 }
4254
4255 return E1000_SUCCESS;
4256}
4257
4258/******************************************************************************
4259* Get PHY information from various PHY registers
4260*
4261* hw - Struct containing variables accessed by shared code
4262* phy_info - PHY information structure
4263******************************************************************************/
4264int32_t
4265e1000_phy_get_info(struct e1000_hw *hw,
4266 struct e1000_phy_info *phy_info)
4267{
4268 int32_t ret_val;
4269 uint16_t phy_data;
4270
4271 DEBUGFUNC("e1000_phy_get_info");
4272
4273 phy_info->cable_length = e1000_cable_length_undefined;
4274 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4275 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4276 phy_info->downshift = e1000_downshift_undefined;
4277 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4278 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4279 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4280 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4281
Auke Kok8fc897b2006-08-28 14:56:16 -07004282 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 DEBUGOUT("PHY info is only valid for copper media\n");
4284 return -E1000_ERR_CONFIG;
4285 }
4286
4287 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004288 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 return ret_val;
4290
4291 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004292 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 return ret_val;
4294
Auke Kok8fc897b2006-08-28 14:56:16 -07004295 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 DEBUGOUT("PHY info is only valid if link is up\n");
4297 return -E1000_ERR_CONFIG;
4298 }
4299
Auke Kokcd94dd02006-06-27 09:08:22 -07004300 if (hw->phy_type == e1000_phy_igp ||
4301 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004302 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004304 else if (hw->phy_type == e1000_phy_ife)
4305 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 else
4307 return e1000_phy_m88_get_info(hw, phy_info);
4308}
4309
4310int32_t
4311e1000_validate_mdi_setting(struct e1000_hw *hw)
4312{
4313 DEBUGFUNC("e1000_validate_mdi_settings");
4314
Auke Kok8fc897b2006-08-28 14:56:16 -07004315 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 DEBUGOUT("Invalid MDI setting detected\n");
4317 hw->mdix = 1;
4318 return -E1000_ERR_CONFIG;
4319 }
4320 return E1000_SUCCESS;
4321}
4322
4323
4324/******************************************************************************
4325 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004326 * is configured. Additionally, if this is ICH8, the flash controller GbE
4327 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 *
4329 * hw - Struct containing variables accessed by shared code
4330 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004331int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332e1000_init_eeprom_params(struct e1000_hw *hw)
4333{
4334 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4335 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004336 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 uint16_t eeprom_size;
4338
4339 DEBUGFUNC("e1000_init_eeprom_params");
4340
4341 switch (hw->mac_type) {
4342 case e1000_82542_rev2_0:
4343 case e1000_82542_rev2_1:
4344 case e1000_82543:
4345 case e1000_82544:
4346 eeprom->type = e1000_eeprom_microwire;
4347 eeprom->word_size = 64;
4348 eeprom->opcode_bits = 3;
4349 eeprom->address_bits = 6;
4350 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004351 eeprom->use_eerd = FALSE;
4352 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 break;
4354 case e1000_82540:
4355 case e1000_82545:
4356 case e1000_82545_rev_3:
4357 case e1000_82546:
4358 case e1000_82546_rev_3:
4359 eeprom->type = e1000_eeprom_microwire;
4360 eeprom->opcode_bits = 3;
4361 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004362 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 eeprom->word_size = 256;
4364 eeprom->address_bits = 8;
4365 } else {
4366 eeprom->word_size = 64;
4367 eeprom->address_bits = 6;
4368 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004369 eeprom->use_eerd = FALSE;
4370 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 break;
4372 case e1000_82541:
4373 case e1000_82541_rev_2:
4374 case e1000_82547:
4375 case e1000_82547_rev_2:
4376 if (eecd & E1000_EECD_TYPE) {
4377 eeprom->type = e1000_eeprom_spi;
4378 eeprom->opcode_bits = 8;
4379 eeprom->delay_usec = 1;
4380 if (eecd & E1000_EECD_ADDR_BITS) {
4381 eeprom->page_size = 32;
4382 eeprom->address_bits = 16;
4383 } else {
4384 eeprom->page_size = 8;
4385 eeprom->address_bits = 8;
4386 }
4387 } else {
4388 eeprom->type = e1000_eeprom_microwire;
4389 eeprom->opcode_bits = 3;
4390 eeprom->delay_usec = 50;
4391 if (eecd & E1000_EECD_ADDR_BITS) {
4392 eeprom->word_size = 256;
4393 eeprom->address_bits = 8;
4394 } else {
4395 eeprom->word_size = 64;
4396 eeprom->address_bits = 6;
4397 }
4398 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004399 eeprom->use_eerd = FALSE;
4400 eeprom->use_eewr = FALSE;
4401 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004402 case e1000_82571:
4403 case e1000_82572:
4404 eeprom->type = e1000_eeprom_spi;
4405 eeprom->opcode_bits = 8;
4406 eeprom->delay_usec = 1;
4407 if (eecd & E1000_EECD_ADDR_BITS) {
4408 eeprom->page_size = 32;
4409 eeprom->address_bits = 16;
4410 } else {
4411 eeprom->page_size = 8;
4412 eeprom->address_bits = 8;
4413 }
4414 eeprom->use_eerd = FALSE;
4415 eeprom->use_eewr = FALSE;
4416 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004417 case e1000_82573:
4418 eeprom->type = e1000_eeprom_spi;
4419 eeprom->opcode_bits = 8;
4420 eeprom->delay_usec = 1;
4421 if (eecd & E1000_EECD_ADDR_BITS) {
4422 eeprom->page_size = 32;
4423 eeprom->address_bits = 16;
4424 } else {
4425 eeprom->page_size = 8;
4426 eeprom->address_bits = 8;
4427 }
4428 eeprom->use_eerd = TRUE;
4429 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004430 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004431 eeprom->type = e1000_eeprom_flash;
4432 eeprom->word_size = 2048;
4433
4434 /* Ensure that the Autonomous FLASH update bit is cleared due to
4435 * Flash update issue on parts which use a FLASH for NVM. */
4436 eecd &= ~E1000_EECD_AUPDEN;
4437 E1000_WRITE_REG(hw, EECD, eecd);
4438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004440 case e1000_80003es2lan:
4441 eeprom->type = e1000_eeprom_spi;
4442 eeprom->opcode_bits = 8;
4443 eeprom->delay_usec = 1;
4444 if (eecd & E1000_EECD_ADDR_BITS) {
4445 eeprom->page_size = 32;
4446 eeprom->address_bits = 16;
4447 } else {
4448 eeprom->page_size = 8;
4449 eeprom->address_bits = 8;
4450 }
4451 eeprom->use_eerd = TRUE;
4452 eeprom->use_eewr = FALSE;
4453 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004454 case e1000_ich8lan:
4455 {
4456 int32_t i = 0;
4457 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4458
4459 eeprom->type = e1000_eeprom_ich8;
4460 eeprom->use_eerd = FALSE;
4461 eeprom->use_eewr = FALSE;
4462 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4463
4464 /* Zero the shadow RAM structure. But don't load it from NVM
4465 * so as to save time for driver init */
4466 if (hw->eeprom_shadow_ram != NULL) {
4467 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4468 hw->eeprom_shadow_ram[i].modified = FALSE;
4469 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4470 }
4471 }
4472
4473 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4474 ICH8_FLASH_SECTOR_SIZE;
4475
4476 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4477 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4478 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4479 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4480
4481 break;
4482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 default:
4484 break;
4485 }
4486
4487 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004488 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4489 * 32KB (incremented by powers of 2).
4490 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004491 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004492 /* Set to default value for initial eeprom read. */
4493 eeprom->word_size = 64;
4494 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004495 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004496 return ret_val;
4497 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4498 /* 256B eeprom size was not supported in earlier hardware, so we
4499 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4500 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004501 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004502 eeprom_size++;
4503 } else {
4504 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4505 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004507
4508 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004510 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511}
4512
4513/******************************************************************************
4514 * Raises the EEPROM's clock input.
4515 *
4516 * hw - Struct containing variables accessed by shared code
4517 * eecd - EECD's current value
4518 *****************************************************************************/
4519static void
4520e1000_raise_ee_clk(struct e1000_hw *hw,
4521 uint32_t *eecd)
4522{
4523 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4524 * wait <delay> microseconds.
4525 */
4526 *eecd = *eecd | E1000_EECD_SK;
4527 E1000_WRITE_REG(hw, EECD, *eecd);
4528 E1000_WRITE_FLUSH(hw);
4529 udelay(hw->eeprom.delay_usec);
4530}
4531
4532/******************************************************************************
4533 * Lowers the EEPROM's clock input.
4534 *
4535 * hw - Struct containing variables accessed by shared code
4536 * eecd - EECD's current value
4537 *****************************************************************************/
4538static void
4539e1000_lower_ee_clk(struct e1000_hw *hw,
4540 uint32_t *eecd)
4541{
4542 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4543 * wait 50 microseconds.
4544 */
4545 *eecd = *eecd & ~E1000_EECD_SK;
4546 E1000_WRITE_REG(hw, EECD, *eecd);
4547 E1000_WRITE_FLUSH(hw);
4548 udelay(hw->eeprom.delay_usec);
4549}
4550
4551/******************************************************************************
4552 * Shift data bits out to the EEPROM.
4553 *
4554 * hw - Struct containing variables accessed by shared code
4555 * data - data to send to the EEPROM
4556 * count - number of bits to shift out
4557 *****************************************************************************/
4558static void
4559e1000_shift_out_ee_bits(struct e1000_hw *hw,
4560 uint16_t data,
4561 uint16_t count)
4562{
4563 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4564 uint32_t eecd;
4565 uint32_t mask;
4566
4567 /* We need to shift "count" bits out to the EEPROM. So, value in the
4568 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4569 * In order to do this, "data" must be broken down into bits.
4570 */
4571 mask = 0x01 << (count - 1);
4572 eecd = E1000_READ_REG(hw, EECD);
4573 if (eeprom->type == e1000_eeprom_microwire) {
4574 eecd &= ~E1000_EECD_DO;
4575 } else if (eeprom->type == e1000_eeprom_spi) {
4576 eecd |= E1000_EECD_DO;
4577 }
4578 do {
4579 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4580 * and then raising and then lowering the clock (the SK bit controls
4581 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4582 * by setting "DI" to "0" and then raising and then lowering the clock.
4583 */
4584 eecd &= ~E1000_EECD_DI;
4585
Auke Kok8fc897b2006-08-28 14:56:16 -07004586 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 eecd |= E1000_EECD_DI;
4588
4589 E1000_WRITE_REG(hw, EECD, eecd);
4590 E1000_WRITE_FLUSH(hw);
4591
4592 udelay(eeprom->delay_usec);
4593
4594 e1000_raise_ee_clk(hw, &eecd);
4595 e1000_lower_ee_clk(hw, &eecd);
4596
4597 mask = mask >> 1;
4598
Auke Kok8fc897b2006-08-28 14:56:16 -07004599 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600
4601 /* We leave the "DI" bit set to "0" when we leave this routine. */
4602 eecd &= ~E1000_EECD_DI;
4603 E1000_WRITE_REG(hw, EECD, eecd);
4604}
4605
4606/******************************************************************************
4607 * Shift data bits in from the EEPROM
4608 *
4609 * hw - Struct containing variables accessed by shared code
4610 *****************************************************************************/
4611static uint16_t
4612e1000_shift_in_ee_bits(struct e1000_hw *hw,
4613 uint16_t count)
4614{
4615 uint32_t eecd;
4616 uint32_t i;
4617 uint16_t data;
4618
4619 /* In order to read a register from the EEPROM, we need to shift 'count'
4620 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4621 * input to the EEPROM (setting the SK bit), and then reading the value of
4622 * the "DO" bit. During this "shifting in" process the "DI" bit should
4623 * always be clear.
4624 */
4625
4626 eecd = E1000_READ_REG(hw, EECD);
4627
4628 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4629 data = 0;
4630
Auke Kok8fc897b2006-08-28 14:56:16 -07004631 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 data = data << 1;
4633 e1000_raise_ee_clk(hw, &eecd);
4634
4635 eecd = E1000_READ_REG(hw, EECD);
4636
4637 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004638 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 data |= 1;
4640
4641 e1000_lower_ee_clk(hw, &eecd);
4642 }
4643
4644 return data;
4645}
4646
4647/******************************************************************************
4648 * Prepares EEPROM for access
4649 *
4650 * hw - Struct containing variables accessed by shared code
4651 *
4652 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4653 * function should be called before issuing a command to the EEPROM.
4654 *****************************************************************************/
4655static int32_t
4656e1000_acquire_eeprom(struct e1000_hw *hw)
4657{
4658 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4659 uint32_t eecd, i=0;
4660
4661 DEBUGFUNC("e1000_acquire_eeprom");
4662
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004663 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4664 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 eecd = E1000_READ_REG(hw, EECD);
4666
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004667 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004668 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004669 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004670 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004672 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004673 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004674 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4675 i++;
4676 udelay(5);
4677 eecd = E1000_READ_REG(hw, EECD);
4678 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004679 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004680 eecd &= ~E1000_EECD_REQ;
4681 E1000_WRITE_REG(hw, EECD, eecd);
4682 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004683 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004684 return -E1000_ERR_EEPROM;
4685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 }
4687 }
4688
4689 /* Setup EEPROM for Read/Write */
4690
4691 if (eeprom->type == e1000_eeprom_microwire) {
4692 /* Clear SK and DI */
4693 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4694 E1000_WRITE_REG(hw, EECD, eecd);
4695
4696 /* Set CS */
4697 eecd |= E1000_EECD_CS;
4698 E1000_WRITE_REG(hw, EECD, eecd);
4699 } else if (eeprom->type == e1000_eeprom_spi) {
4700 /* Clear SK and CS */
4701 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4702 E1000_WRITE_REG(hw, EECD, eecd);
4703 udelay(1);
4704 }
4705
4706 return E1000_SUCCESS;
4707}
4708
4709/******************************************************************************
4710 * Returns EEPROM to a "standby" state
4711 *
4712 * hw - Struct containing variables accessed by shared code
4713 *****************************************************************************/
4714static void
4715e1000_standby_eeprom(struct e1000_hw *hw)
4716{
4717 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4718 uint32_t eecd;
4719
4720 eecd = E1000_READ_REG(hw, EECD);
4721
Auke Kok8fc897b2006-08-28 14:56:16 -07004722 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4724 E1000_WRITE_REG(hw, EECD, eecd);
4725 E1000_WRITE_FLUSH(hw);
4726 udelay(eeprom->delay_usec);
4727
4728 /* Clock high */
4729 eecd |= E1000_EECD_SK;
4730 E1000_WRITE_REG(hw, EECD, eecd);
4731 E1000_WRITE_FLUSH(hw);
4732 udelay(eeprom->delay_usec);
4733
4734 /* Select EEPROM */
4735 eecd |= E1000_EECD_CS;
4736 E1000_WRITE_REG(hw, EECD, eecd);
4737 E1000_WRITE_FLUSH(hw);
4738 udelay(eeprom->delay_usec);
4739
4740 /* Clock low */
4741 eecd &= ~E1000_EECD_SK;
4742 E1000_WRITE_REG(hw, EECD, eecd);
4743 E1000_WRITE_FLUSH(hw);
4744 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004745 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 /* Toggle CS to flush commands */
4747 eecd |= E1000_EECD_CS;
4748 E1000_WRITE_REG(hw, EECD, eecd);
4749 E1000_WRITE_FLUSH(hw);
4750 udelay(eeprom->delay_usec);
4751 eecd &= ~E1000_EECD_CS;
4752 E1000_WRITE_REG(hw, EECD, eecd);
4753 E1000_WRITE_FLUSH(hw);
4754 udelay(eeprom->delay_usec);
4755 }
4756}
4757
4758/******************************************************************************
4759 * Terminates a command by inverting the EEPROM's chip select pin
4760 *
4761 * hw - Struct containing variables accessed by shared code
4762 *****************************************************************************/
4763static void
4764e1000_release_eeprom(struct e1000_hw *hw)
4765{
4766 uint32_t eecd;
4767
4768 DEBUGFUNC("e1000_release_eeprom");
4769
4770 eecd = E1000_READ_REG(hw, EECD);
4771
4772 if (hw->eeprom.type == e1000_eeprom_spi) {
4773 eecd |= E1000_EECD_CS; /* Pull CS high */
4774 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4775
4776 E1000_WRITE_REG(hw, EECD, eecd);
4777
4778 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004779 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 /* cleanup eeprom */
4781
4782 /* CS on Microwire is active-high */
4783 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4784
4785 E1000_WRITE_REG(hw, EECD, eecd);
4786
4787 /* Rising edge of clock */
4788 eecd |= E1000_EECD_SK;
4789 E1000_WRITE_REG(hw, EECD, eecd);
4790 E1000_WRITE_FLUSH(hw);
4791 udelay(hw->eeprom.delay_usec);
4792
4793 /* Falling edge of clock */
4794 eecd &= ~E1000_EECD_SK;
4795 E1000_WRITE_REG(hw, EECD, eecd);
4796 E1000_WRITE_FLUSH(hw);
4797 udelay(hw->eeprom.delay_usec);
4798 }
4799
4800 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004801 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 eecd &= ~E1000_EECD_REQ;
4803 E1000_WRITE_REG(hw, EECD, eecd);
4804 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004805
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004806 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807}
4808
4809/******************************************************************************
4810 * Reads a 16 bit word from the EEPROM.
4811 *
4812 * hw - Struct containing variables accessed by shared code
4813 *****************************************************************************/
4814int32_t
4815e1000_spi_eeprom_ready(struct e1000_hw *hw)
4816{
4817 uint16_t retry_count = 0;
4818 uint8_t spi_stat_reg;
4819
4820 DEBUGFUNC("e1000_spi_eeprom_ready");
4821
4822 /* Read "Status Register" repeatedly until the LSB is cleared. The
4823 * EEPROM will signal that the command has been completed by clearing
4824 * bit 0 of the internal status register. If it's not cleared within
4825 * 5 milliseconds, then error out.
4826 */
4827 retry_count = 0;
4828 do {
4829 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4830 hw->eeprom.opcode_bits);
4831 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4832 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4833 break;
4834
4835 udelay(5);
4836 retry_count += 5;
4837
4838 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004839 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840
4841 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4842 * only 0-5mSec on 5V devices)
4843 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004844 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 DEBUGOUT("SPI EEPROM Status error\n");
4846 return -E1000_ERR_EEPROM;
4847 }
4848
4849 return E1000_SUCCESS;
4850}
4851
4852/******************************************************************************
4853 * Reads a 16 bit word from the EEPROM.
4854 *
4855 * hw - Struct containing variables accessed by shared code
4856 * offset - offset of word in the EEPROM to read
4857 * data - word read from the EEPROM
4858 * words - number of words to read
4859 *****************************************************************************/
4860int32_t
4861e1000_read_eeprom(struct e1000_hw *hw,
4862 uint16_t offset,
4863 uint16_t words,
4864 uint16_t *data)
4865{
4866 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4867 uint32_t i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004868 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869
4870 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004871
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 /* A check for invalid values: offset too large, too many words, and not
4873 * enough words.
4874 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004875 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 (words == 0)) {
4877 DEBUGOUT("\"words\" parameter out of bounds\n");
4878 return -E1000_ERR_EEPROM;
4879 }
4880
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004881 /* FLASH reads without acquiring the semaphore are safe */
4882 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004883 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004884 switch (hw->mac_type) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004885 case e1000_80003es2lan:
4886 break;
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004887 default:
4888 /* Prepare the EEPROM for reading */
4889 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4890 return -E1000_ERR_EEPROM;
4891 break;
4892 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004893 }
4894
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004895 if (eeprom->use_eerd == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004896 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4897 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4898 (hw->mac_type != e1000_82573))
4899 e1000_release_eeprom(hw);
4900 return ret_val;
4901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902
Auke Kokcd94dd02006-06-27 09:08:22 -07004903 if (eeprom->type == e1000_eeprom_ich8)
4904 return e1000_read_eeprom_ich8(hw, offset, words, data);
4905
4906 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 uint16_t word_in;
4908 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4909
Auke Kok8fc897b2006-08-28 14:56:16 -07004910 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 e1000_release_eeprom(hw);
4912 return -E1000_ERR_EEPROM;
4913 }
4914
4915 e1000_standby_eeprom(hw);
4916
4917 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07004918 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 read_opcode |= EEPROM_A8_OPCODE_SPI;
4920
4921 /* Send the READ command (opcode + addr) */
4922 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4923 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4924
4925 /* Read the data. The address of the eeprom internally increments with
4926 * each byte (spi) being read, saving on the overhead of eeprom setup
4927 * and tear-down. The address counter will roll over if reading beyond
4928 * the size of the eeprom, thus allowing the entire memory to be read
4929 * starting from any offset. */
4930 for (i = 0; i < words; i++) {
4931 word_in = e1000_shift_in_ee_bits(hw, 16);
4932 data[i] = (word_in >> 8) | (word_in << 8);
4933 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004934 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935 for (i = 0; i < words; i++) {
4936 /* Send the READ command (opcode + addr) */
4937 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4938 eeprom->opcode_bits);
4939 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4940 eeprom->address_bits);
4941
4942 /* Read the data. For microwire, each word requires the overhead
4943 * of eeprom setup and tear-down. */
4944 data[i] = e1000_shift_in_ee_bits(hw, 16);
4945 e1000_standby_eeprom(hw);
4946 }
4947 }
4948
4949 /* End this read operation */
4950 e1000_release_eeprom(hw);
4951
4952 return E1000_SUCCESS;
4953}
4954
4955/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004956 * Reads a 16 bit word from the EEPROM using the EERD register.
4957 *
4958 * hw - Struct containing variables accessed by shared code
4959 * offset - offset of word in the EEPROM to read
4960 * data - word read from the EEPROM
4961 * words - number of words to read
4962 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004963static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004964e1000_read_eeprom_eerd(struct e1000_hw *hw,
4965 uint16_t offset,
4966 uint16_t words,
4967 uint16_t *data)
4968{
4969 uint32_t i, eerd = 0;
4970 int32_t error = 0;
4971
4972 for (i = 0; i < words; i++) {
4973 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4974 E1000_EEPROM_RW_REG_START;
4975
4976 E1000_WRITE_REG(hw, EERD, eerd);
4977 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07004978
Auke Kok8fc897b2006-08-28 14:56:16 -07004979 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004980 break;
4981 }
4982 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07004983
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004984 }
Auke Kok76c224b2006-05-23 13:36:06 -07004985
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004986 return error;
4987}
4988
4989/******************************************************************************
4990 * Writes a 16 bit word from the EEPROM using the EEWR register.
4991 *
4992 * hw - Struct containing variables accessed by shared code
4993 * offset - offset of word in the EEPROM to read
4994 * data - word read from the EEPROM
4995 * words - number of words to read
4996 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004997static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004998e1000_write_eeprom_eewr(struct e1000_hw *hw,
4999 uint16_t offset,
5000 uint16_t words,
5001 uint16_t *data)
5002{
5003 uint32_t register_value = 0;
5004 uint32_t i = 0;
5005 int32_t error = 0;
5006
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005007 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5008 return -E1000_ERR_SWFW_SYNC;
5009
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005010 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005011 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5012 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005013 E1000_EEPROM_RW_REG_START;
5014
5015 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005016 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005017 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005018 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005019
5020 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005021
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005022 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005023
Auke Kok8fc897b2006-08-28 14:56:16 -07005024 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005025 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005026 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005027 }
Auke Kok76c224b2006-05-23 13:36:06 -07005028
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005029 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005030 return error;
5031}
5032
5033/******************************************************************************
5034 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5035 *
5036 * hw - Struct containing variables accessed by shared code
5037 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005038static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005039e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5040{
5041 uint32_t attempts = 100000;
5042 uint32_t i, reg = 0;
5043 int32_t done = E1000_ERR_EEPROM;
5044
Auke Kok8fc897b2006-08-28 14:56:16 -07005045 for (i = 0; i < attempts; i++) {
5046 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005047 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005048 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005049 reg = E1000_READ_REG(hw, EEWR);
5050
Auke Kok8fc897b2006-08-28 14:56:16 -07005051 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005052 done = E1000_SUCCESS;
5053 break;
5054 }
5055 udelay(5);
5056 }
5057
5058 return done;
5059}
5060
5061/***************************************************************************
5062* Description: Determines if the onboard NVM is FLASH or EEPROM.
5063*
5064* hw - Struct containing variables accessed by shared code
5065****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005066static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005067e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5068{
5069 uint32_t eecd = 0;
5070
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005071 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5072
Auke Kokcd94dd02006-06-27 09:08:22 -07005073 if (hw->mac_type == e1000_ich8lan)
5074 return FALSE;
5075
5076 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005077 eecd = E1000_READ_REG(hw, EECD);
5078
5079 /* Isolate bits 15 & 16 */
5080 eecd = ((eecd >> 15) & 0x03);
5081
5082 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005083 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005084 return FALSE;
5085 }
5086 }
5087 return TRUE;
5088}
5089
5090/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 * Verifies that the EEPROM has a valid checksum
5092 *
5093 * hw - Struct containing variables accessed by shared code
5094 *
5095 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5096 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5097 * valid.
5098 *****************************************************************************/
5099int32_t
5100e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5101{
5102 uint16_t checksum = 0;
5103 uint16_t i, eeprom_data;
5104
5105 DEBUGFUNC("e1000_validate_eeprom_checksum");
5106
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005107 if ((hw->mac_type == e1000_82573) &&
5108 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5109 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5110 * 10h-12h. Checksum may need to be fixed. */
5111 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5112 if ((eeprom_data & 0x10) == 0) {
5113 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5114 * has already been fixed. If the checksum is still wrong and this
5115 * bit is a 1, we need to return bad checksum. Otherwise, we need
5116 * to set this bit to a 1 and update the checksum. */
5117 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5118 if ((eeprom_data & 0x8000) == 0) {
5119 eeprom_data |= 0x8000;
5120 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5121 e1000_update_eeprom_checksum(hw);
5122 }
5123 }
5124 }
5125
Auke Kokcd94dd02006-06-27 09:08:22 -07005126 if (hw->mac_type == e1000_ich8lan) {
5127 /* Drivers must allocate the shadow ram structure for the
5128 * EEPROM checksum to be updated. Otherwise, this bit as well
5129 * as the checksum must both be set correctly for this
5130 * validation to pass.
5131 */
5132 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5133 if ((eeprom_data & 0x40) == 0) {
5134 eeprom_data |= 0x40;
5135 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5136 e1000_update_eeprom_checksum(hw);
5137 }
5138 }
5139
5140 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5141 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142 DEBUGOUT("EEPROM Read Error\n");
5143 return -E1000_ERR_EEPROM;
5144 }
5145 checksum += eeprom_data;
5146 }
5147
Auke Kok8fc897b2006-08-28 14:56:16 -07005148 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 return E1000_SUCCESS;
5150 else {
5151 DEBUGOUT("EEPROM Checksum Invalid\n");
5152 return -E1000_ERR_EEPROM;
5153 }
5154}
5155
5156/******************************************************************************
5157 * Calculates the EEPROM checksum and writes it to the EEPROM
5158 *
5159 * hw - Struct containing variables accessed by shared code
5160 *
5161 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5162 * Writes the difference to word offset 63 of the EEPROM.
5163 *****************************************************************************/
5164int32_t
5165e1000_update_eeprom_checksum(struct e1000_hw *hw)
5166{
Auke Kokcd94dd02006-06-27 09:08:22 -07005167 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 uint16_t checksum = 0;
5169 uint16_t i, eeprom_data;
5170
5171 DEBUGFUNC("e1000_update_eeprom_checksum");
5172
Auke Kok8fc897b2006-08-28 14:56:16 -07005173 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5174 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 DEBUGOUT("EEPROM Read Error\n");
5176 return -E1000_ERR_EEPROM;
5177 }
5178 checksum += eeprom_data;
5179 }
5180 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005181 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 DEBUGOUT("EEPROM Write Error\n");
5183 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005184 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5185 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005186 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5187 e1000_commit_shadow_ram(hw);
5188 /* Reload the EEPROM, or else modifications will not appear
5189 * until after next adapter reset. */
5190 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5191 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5192 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005193 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 }
5195 return E1000_SUCCESS;
5196}
5197
5198/******************************************************************************
5199 * Parent function for writing words to the different EEPROM types.
5200 *
5201 * hw - Struct containing variables accessed by shared code
5202 * offset - offset within the EEPROM to be written to
5203 * words - number of words to write
5204 * data - 16 bit word to be written to the EEPROM
5205 *
5206 * If e1000_update_eeprom_checksum is not called after this function, the
5207 * EEPROM will most likely contain an invalid checksum.
5208 *****************************************************************************/
5209int32_t
5210e1000_write_eeprom(struct e1000_hw *hw,
5211 uint16_t offset,
5212 uint16_t words,
5213 uint16_t *data)
5214{
5215 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5216 int32_t status = 0;
5217
5218 DEBUGFUNC("e1000_write_eeprom");
5219
5220 /* A check for invalid values: offset too large, too many words, and not
5221 * enough words.
5222 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005223 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224 (words == 0)) {
5225 DEBUGOUT("\"words\" parameter out of bounds\n");
5226 return -E1000_ERR_EEPROM;
5227 }
5228
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005229 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005230 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005231 return e1000_write_eeprom_eewr(hw, offset, words, data);
5232
Auke Kokcd94dd02006-06-27 09:08:22 -07005233 if (eeprom->type == e1000_eeprom_ich8)
5234 return e1000_write_eeprom_ich8(hw, offset, words, data);
5235
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 /* Prepare the EEPROM for writing */
5237 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5238 return -E1000_ERR_EEPROM;
5239
Auke Kok8fc897b2006-08-28 14:56:16 -07005240 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5242 } else {
5243 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005244 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 }
5246
5247 /* Done with writing */
5248 e1000_release_eeprom(hw);
5249
5250 return status;
5251}
5252
5253/******************************************************************************
5254 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5255 *
5256 * hw - Struct containing variables accessed by shared code
5257 * offset - offset within the EEPROM to be written to
5258 * words - number of words to write
5259 * data - pointer to array of 8 bit words to be written to the EEPROM
5260 *
5261 *****************************************************************************/
5262int32_t
5263e1000_write_eeprom_spi(struct e1000_hw *hw,
5264 uint16_t offset,
5265 uint16_t words,
5266 uint16_t *data)
5267{
5268 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5269 uint16_t widx = 0;
5270
5271 DEBUGFUNC("e1000_write_eeprom_spi");
5272
5273 while (widx < words) {
5274 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5275
Auke Kok8fc897b2006-08-28 14:56:16 -07005276 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277
5278 e1000_standby_eeprom(hw);
5279
5280 /* Send the WRITE ENABLE command (8 bit opcode ) */
5281 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5282 eeprom->opcode_bits);
5283
5284 e1000_standby_eeprom(hw);
5285
5286 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005287 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 write_opcode |= EEPROM_A8_OPCODE_SPI;
5289
5290 /* Send the Write command (8-bit opcode + addr) */
5291 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5292
5293 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5294 eeprom->address_bits);
5295
5296 /* Send the data */
5297
5298 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5299 while (widx < words) {
5300 uint16_t word_out = data[widx];
5301 word_out = (word_out >> 8) | (word_out << 8);
5302 e1000_shift_out_ee_bits(hw, word_out, 16);
5303 widx++;
5304
5305 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5306 * operation, while the smaller eeproms are capable of an 8-byte
5307 * PAGE WRITE operation. Break the inner loop to pass new address
5308 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005309 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310 e1000_standby_eeprom(hw);
5311 break;
5312 }
5313 }
5314 }
5315
5316 return E1000_SUCCESS;
5317}
5318
5319/******************************************************************************
5320 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5321 *
5322 * hw - Struct containing variables accessed by shared code
5323 * offset - offset within the EEPROM to be written to
5324 * words - number of words to write
5325 * data - pointer to array of 16 bit words to be written to the EEPROM
5326 *
5327 *****************************************************************************/
5328int32_t
5329e1000_write_eeprom_microwire(struct e1000_hw *hw,
5330 uint16_t offset,
5331 uint16_t words,
5332 uint16_t *data)
5333{
5334 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5335 uint32_t eecd;
5336 uint16_t words_written = 0;
5337 uint16_t i = 0;
5338
5339 DEBUGFUNC("e1000_write_eeprom_microwire");
5340
5341 /* Send the write enable command to the EEPROM (3-bit opcode plus
5342 * 6/8-bit dummy address beginning with 11). It's less work to include
5343 * the 11 of the dummy address as part of the opcode than it is to shift
5344 * it over the correct number of bits for the address. This puts the
5345 * EEPROM into write/erase mode.
5346 */
5347 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5348 (uint16_t)(eeprom->opcode_bits + 2));
5349
5350 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5351
5352 /* Prepare the EEPROM */
5353 e1000_standby_eeprom(hw);
5354
5355 while (words_written < words) {
5356 /* Send the Write command (3-bit opcode + addr) */
5357 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5358 eeprom->opcode_bits);
5359
5360 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5361 eeprom->address_bits);
5362
5363 /* Send the data */
5364 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5365
5366 /* Toggle the CS line. This in effect tells the EEPROM to execute
5367 * the previous command.
5368 */
5369 e1000_standby_eeprom(hw);
5370
5371 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5372 * signal that the command has been completed by raising the DO signal.
5373 * If DO does not go high in 10 milliseconds, then error out.
5374 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005375 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005377 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 udelay(50);
5379 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005380 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 DEBUGOUT("EEPROM Write did not complete\n");
5382 return -E1000_ERR_EEPROM;
5383 }
5384
5385 /* Recover from write */
5386 e1000_standby_eeprom(hw);
5387
5388 words_written++;
5389 }
5390
5391 /* Send the write disable command to the EEPROM (3-bit opcode plus
5392 * 6/8-bit dummy address beginning with 10). It's less work to include
5393 * the 10 of the dummy address as part of the opcode than it is to shift
5394 * it over the correct number of bits for the address. This takes the
5395 * EEPROM out of write/erase mode.
5396 */
5397 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5398 (uint16_t)(eeprom->opcode_bits + 2));
5399
5400 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5401
5402 return E1000_SUCCESS;
5403}
5404
5405/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005406 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5407 * in the eeprom cache and the non modified values in the currently active bank
5408 * to the new bank.
5409 *
5410 * hw - Struct containing variables accessed by shared code
5411 * offset - offset of word in the EEPROM to read
5412 * data - word read from the EEPROM
5413 * words - number of words to read
5414 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005415static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005416e1000_commit_shadow_ram(struct e1000_hw *hw)
5417{
5418 uint32_t attempts = 100000;
5419 uint32_t eecd = 0;
5420 uint32_t flop = 0;
5421 uint32_t i = 0;
5422 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005423 uint32_t old_bank_offset = 0;
5424 uint32_t new_bank_offset = 0;
5425 uint32_t sector_retries = 0;
5426 uint8_t low_byte = 0;
5427 uint8_t high_byte = 0;
5428 uint8_t temp_byte = 0;
5429 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005430
5431 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005432 /* The flop register will be used to determine if flash type is STM */
5433 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005434 for (i=0; i < attempts; i++) {
5435 eecd = E1000_READ_REG(hw, EECD);
5436 if ((eecd & E1000_EECD_FLUPD) == 0) {
5437 break;
5438 }
5439 udelay(5);
5440 }
5441
5442 if (i == attempts) {
5443 return -E1000_ERR_EEPROM;
5444 }
5445
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005446 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005447 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5448 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5449 }
5450
5451 /* Perform the flash update */
5452 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5453
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005454 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005455 eecd = E1000_READ_REG(hw, EECD);
5456 if ((eecd & E1000_EECD_FLUPD) == 0) {
5457 break;
5458 }
5459 udelay(5);
5460 }
5461
5462 if (i == attempts) {
5463 return -E1000_ERR_EEPROM;
5464 }
5465 }
5466
Auke Kokcd94dd02006-06-27 09:08:22 -07005467 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5468 /* We're writing to the opposite bank so if we're on bank 1,
5469 * write to bank 0 etc. We also need to erase the segment that
5470 * is going to be written */
5471 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5472 new_bank_offset = hw->flash_bank_size * 2;
5473 old_bank_offset = 0;
5474 e1000_erase_ich8_4k_segment(hw, 1);
5475 } else {
5476 old_bank_offset = hw->flash_bank_size * 2;
5477 new_bank_offset = 0;
5478 e1000_erase_ich8_4k_segment(hw, 0);
5479 }
5480
5481 do {
5482 sector_write_failed = FALSE;
5483 /* Loop for every byte in the shadow RAM,
5484 * which is in units of words. */
5485 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5486 /* Determine whether to write the value stored
5487 * in the other NVM bank or a modified value stored
5488 * in the shadow RAM */
5489 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5490 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5491 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5492 &temp_byte);
5493 udelay(100);
5494 error = e1000_verify_write_ich8_byte(hw,
5495 (i << 1) + new_bank_offset,
5496 low_byte);
5497 if (error != E1000_SUCCESS)
5498 sector_write_failed = TRUE;
5499 high_byte =
5500 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5501 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5502 &temp_byte);
5503 udelay(100);
5504 } else {
5505 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5506 &low_byte);
5507 udelay(100);
5508 error = e1000_verify_write_ich8_byte(hw,
5509 (i << 1) + new_bank_offset, low_byte);
5510 if (error != E1000_SUCCESS)
5511 sector_write_failed = TRUE;
5512 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5513 &high_byte);
5514 }
5515
5516 /* If the word is 0x13, then make sure the signature bits
5517 * (15:14) are 11b until the commit has completed.
5518 * This will allow us to write 10b which indicates the
5519 * signature is valid. We want to do this after the write
5520 * has completed so that we don't mark the segment valid
5521 * while the write is still in progress */
5522 if (i == E1000_ICH8_NVM_SIG_WORD)
5523 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5524
5525 error = e1000_verify_write_ich8_byte(hw,
5526 (i << 1) + new_bank_offset + 1, high_byte);
5527 if (error != E1000_SUCCESS)
5528 sector_write_failed = TRUE;
5529
5530 if (sector_write_failed == FALSE) {
5531 /* Clear the now not used entry in the cache */
5532 hw->eeprom_shadow_ram[i].modified = FALSE;
5533 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5534 }
5535 }
5536
5537 /* Don't bother writing the segment valid bits if sector
5538 * programming failed. */
5539 if (sector_write_failed == FALSE) {
5540 /* Finally validate the new segment by setting bit 15:14
5541 * to 10b in word 0x13 , this can be done without an
5542 * erase as well since these bits are 11 to start with
5543 * and we need to change bit 14 to 0b */
5544 e1000_read_ich8_byte(hw,
5545 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5546 &high_byte);
5547 high_byte &= 0xBF;
5548 error = e1000_verify_write_ich8_byte(hw,
5549 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5550 high_byte);
5551 if (error != E1000_SUCCESS)
5552 sector_write_failed = TRUE;
5553
5554 /* And invalidate the previously valid segment by setting
5555 * its signature word (0x13) high_byte to 0b. This can be
5556 * done without an erase because flash erase sets all bits
5557 * to 1's. We can write 1's to 0's without an erase */
5558 error = e1000_verify_write_ich8_byte(hw,
5559 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5560 0);
5561 if (error != E1000_SUCCESS)
5562 sector_write_failed = TRUE;
5563 }
5564 } while (++sector_retries < 10 && sector_write_failed == TRUE);
5565 }
5566
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005567 return error;
5568}
5569
5570/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5572 * second function of dual function devices
5573 *
5574 * hw - Struct containing variables accessed by shared code
5575 *****************************************************************************/
5576int32_t
5577e1000_read_mac_addr(struct e1000_hw * hw)
5578{
5579 uint16_t offset;
5580 uint16_t eeprom_data, i;
5581
5582 DEBUGFUNC("e1000_read_mac_addr");
5583
Auke Kok8fc897b2006-08-28 14:56:16 -07005584 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005586 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005587 DEBUGOUT("EEPROM Read Error\n");
5588 return -E1000_ERR_EEPROM;
5589 }
5590 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5591 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5592 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005593
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005594 switch (hw->mac_type) {
5595 default:
5596 break;
5597 case e1000_82546:
5598 case e1000_82546_rev_3:
5599 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005600 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005601 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005602 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005603 break;
5604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605
Auke Kok8fc897b2006-08-28 14:56:16 -07005606 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607 hw->mac_addr[i] = hw->perm_mac_addr[i];
5608 return E1000_SUCCESS;
5609}
5610
5611/******************************************************************************
5612 * Initializes receive address filters.
5613 *
5614 * hw - Struct containing variables accessed by shared code
5615 *
5616 * Places the MAC address in receive address register 0 and clears the rest
5617 * of the receive addresss registers. Clears the multicast table. Assumes
5618 * the receiver is in reset when the routine is called.
5619 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005620static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005621e1000_init_rx_addrs(struct e1000_hw *hw)
5622{
5623 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005624 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625
5626 DEBUGFUNC("e1000_init_rx_addrs");
5627
5628 /* Setup the receive address. */
5629 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5630
5631 e1000_rar_set(hw, hw->mac_addr, 0);
5632
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005633 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005634
5635 /* Reserve a spot for the Locally Administered Address to work around
5636 * an 82571 issue in which a reset on one port will reload the MAC on
5637 * the other port. */
5638 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5639 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005640 if (hw->mac_type == e1000_ich8lan)
5641 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5642
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643 /* Zero out the other 15 receive addresses. */
5644 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005645 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005647 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005649 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650 }
5651}
5652
5653/******************************************************************************
5654 * Updates the MAC's list of multicast addresses.
5655 *
5656 * hw - Struct containing variables accessed by shared code
5657 * mc_addr_list - the list of new multicast addresses
5658 * mc_addr_count - number of addresses
5659 * pad - number of bytes between addresses in the list
5660 * rar_used_count - offset where to start adding mc addresses into the RAR's
5661 *
5662 * The given list replaces any existing list. Clears the last 15 receive
5663 * address registers and the multicast table. Uses receive address registers
5664 * for the first 15 multicast addresses, and hashes the rest into the
5665 * multicast table.
5666 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07005667#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668void
5669e1000_mc_addr_list_update(struct e1000_hw *hw,
5670 uint8_t *mc_addr_list,
5671 uint32_t mc_addr_count,
5672 uint32_t pad,
5673 uint32_t rar_used_count)
5674{
5675 uint32_t hash_value;
5676 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005677 uint32_t num_rar_entry;
5678 uint32_t num_mta_entry;
Auke Kok76c224b2006-05-23 13:36:06 -07005679
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 DEBUGFUNC("e1000_mc_addr_list_update");
5681
5682 /* Set the new number of MC addresses that we are being requested to use. */
5683 hw->num_mc_addrs = mc_addr_count;
5684
5685 /* Clear RAR[1-15] */
5686 DEBUGOUT(" Clearing RAR[1-15]\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005687 num_rar_entry = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07005688 if (hw->mac_type == e1000_ich8lan)
5689 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005690 /* Reserve a spot for the Locally Administered Address to work around
5691 * an 82571 issue in which a reset on one port will reload the MAC on
5692 * the other port. */
5693 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5694 num_rar_entry -= 1;
5695
Auke Kok8fc897b2006-08-28 14:56:16 -07005696 for (i = rar_used_count; i < num_rar_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005698 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005700 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701 }
5702
5703 /* Clear the MTA */
5704 DEBUGOUT(" Clearing MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005705 num_mta_entry = E1000_NUM_MTA_REGISTERS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005706 if (hw->mac_type == e1000_ich8lan)
5707 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -07005708 for (i = 0; i < num_mta_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005710 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 }
5712
5713 /* Add the new addresses */
Auke Kok8fc897b2006-08-28 14:56:16 -07005714 for (i = 0; i < mc_addr_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715 DEBUGOUT(" Adding the multicast addresses:\n");
5716 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5717 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5718 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5719 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5720 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5721 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5722 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5723
5724 hash_value = e1000_hash_mc_addr(hw,
5725 mc_addr_list +
5726 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5727
5728 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5729
5730 /* Place this multicast address in the RAR if there is room, *
5731 * else put it in the MTA
5732 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005733 if (rar_used_count < num_rar_entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 e1000_rar_set(hw,
5735 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5736 rar_used_count);
5737 rar_used_count++;
5738 } else {
5739 e1000_mta_set(hw, hash_value);
5740 }
5741 }
5742 DEBUGOUT("MC Update Complete\n");
5743}
Adrian Bunke4c780b2006-08-14 23:00:10 -07005744#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745
5746/******************************************************************************
5747 * Hashes an address to determine its location in the multicast table
5748 *
5749 * hw - Struct containing variables accessed by shared code
5750 * mc_addr - the multicast address to hash
5751 *****************************************************************************/
5752uint32_t
5753e1000_hash_mc_addr(struct e1000_hw *hw,
5754 uint8_t *mc_addr)
5755{
5756 uint32_t hash_value = 0;
5757
5758 /* The portion of the address that is used for the hash table is
5759 * determined by the mc_filter_type setting.
5760 */
5761 switch (hw->mc_filter_type) {
5762 /* [0] [1] [2] [3] [4] [5]
5763 * 01 AA 00 12 34 56
5764 * LSB MSB
5765 */
5766 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005767 if (hw->mac_type == e1000_ich8lan) {
5768 /* [47:38] i.e. 0x158 for above example address */
5769 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5770 } else {
5771 /* [47:36] i.e. 0x563 for above example address */
5772 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774 break;
5775 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005776 if (hw->mac_type == e1000_ich8lan) {
5777 /* [46:37] i.e. 0x2B1 for above example address */
5778 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5779 } else {
5780 /* [46:35] i.e. 0xAC6 for above example address */
5781 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783 break;
5784 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005785 if (hw->mac_type == e1000_ich8lan) {
5786 /*[45:36] i.e. 0x163 for above example address */
5787 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5788 } else {
5789 /* [45:34] i.e. 0x5D8 for above example address */
5790 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005792 break;
5793 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005794 if (hw->mac_type == e1000_ich8lan) {
5795 /* [43:34] i.e. 0x18D for above example address */
5796 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5797 } else {
5798 /* [43:32] i.e. 0x634 for above example address */
5799 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801 break;
5802 }
5803
5804 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005805 if (hw->mac_type == e1000_ich8lan)
5806 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005807
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808 return hash_value;
5809}
5810
5811/******************************************************************************
5812 * Sets the bit in the multicast table corresponding to the hash value.
5813 *
5814 * hw - Struct containing variables accessed by shared code
5815 * hash_value - Multicast address hash value
5816 *****************************************************************************/
5817void
5818e1000_mta_set(struct e1000_hw *hw,
5819 uint32_t hash_value)
5820{
5821 uint32_t hash_bit, hash_reg;
5822 uint32_t mta;
5823 uint32_t temp;
5824
5825 /* The MTA is a register array of 128 32-bit registers.
5826 * It is treated like an array of 4096 bits. We want to set
5827 * bit BitArray[hash_value]. So we figure out what register
5828 * the bit is in, read it, OR in the new bit, then write
5829 * back the new value. The register is determined by the
5830 * upper 7 bits of the hash value and the bit within that
5831 * register are determined by the lower 5 bits of the value.
5832 */
5833 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005834 if (hw->mac_type == e1000_ich8lan)
5835 hash_reg &= 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 hash_bit = hash_value & 0x1F;
5837
5838 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5839
5840 mta |= (1 << hash_bit);
5841
5842 /* If we are on an 82544 and we are trying to write an odd offset
5843 * in the MTA, save off the previous entry before writing and
5844 * restore the old value after writing.
5845 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005846 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5848 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005849 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005851 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 } else {
5853 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005854 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 }
5856}
5857
5858/******************************************************************************
5859 * Puts an ethernet address into a receive address register.
5860 *
5861 * hw - Struct containing variables accessed by shared code
5862 * addr - Address to put into receive address register
5863 * index - Receive address register to write
5864 *****************************************************************************/
5865void
5866e1000_rar_set(struct e1000_hw *hw,
5867 uint8_t *addr,
5868 uint32_t index)
5869{
5870 uint32_t rar_low, rar_high;
5871
5872 /* HW expects these in little endian so we reverse the byte order
5873 * from network order (big endian) to little endian
5874 */
5875 rar_low = ((uint32_t) addr[0] |
5876 ((uint32_t) addr[1] << 8) |
5877 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005878 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005880 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5881 * unit hang.
5882 *
5883 * Description:
5884 * If there are any Rx frames queued up or otherwise present in the HW
5885 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5886 * hang. To work around this issue, we have to disable receives and
5887 * flush out all Rx frames before we enable RSS. To do so, we modify we
5888 * redirect all Rx traffic to manageability and then reset the HW.
5889 * This flushes away Rx frames, and (since the redirections to
5890 * manageability persists across resets) keeps new ones from coming in
5891 * while we work. Then, we clear the Address Valid AV bit for all MAC
5892 * addresses and undo the re-direction to manageability.
5893 * Now, frames are coming in again, but the MAC won't accept them, so
5894 * far so good. We now proceed to initialize RSS (if necessary) and
5895 * configure the Rx unit. Last, we re-enable the AV bits and continue
5896 * on our merry way.
5897 */
5898 switch (hw->mac_type) {
5899 case e1000_82571:
5900 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005901 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005902 if (hw->leave_av_bit_off == TRUE)
5903 break;
5904 default:
5905 /* Indicate to hardware the Address is Valid. */
5906 rar_high |= E1000_RAH_AV;
5907 break;
5908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909
5910 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005911 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005913 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914}
5915
5916/******************************************************************************
5917 * Writes a value to the specified offset in the VLAN filter table.
5918 *
5919 * hw - Struct containing variables accessed by shared code
5920 * offset - Offset in VLAN filer table to write
5921 * value - Value to write into VLAN filter table
5922 *****************************************************************************/
5923void
5924e1000_write_vfta(struct e1000_hw *hw,
5925 uint32_t offset,
5926 uint32_t value)
5927{
5928 uint32_t temp;
5929
Auke Kokcd94dd02006-06-27 09:08:22 -07005930 if (hw->mac_type == e1000_ich8lan)
5931 return;
5932
5933 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5935 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005936 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005938 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 } else {
5940 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005941 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942 }
5943}
5944
5945/******************************************************************************
5946 * Clears the VLAN filer table
5947 *
5948 * hw - Struct containing variables accessed by shared code
5949 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005950static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951e1000_clear_vfta(struct e1000_hw *hw)
5952{
5953 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005954 uint32_t vfta_value = 0;
5955 uint32_t vfta_offset = 0;
5956 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957
Auke Kokcd94dd02006-06-27 09:08:22 -07005958 if (hw->mac_type == e1000_ich8lan)
5959 return;
5960
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005961 if (hw->mac_type == e1000_82573) {
5962 if (hw->mng_cookie.vlan_id != 0) {
5963 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5964 * ID. The following operations determine which 32b entry
5965 * (i.e. offset) into the array we want to set the VLAN ID
5966 * (i.e. bit) of the manageability unit. */
5967 vfta_offset = (hw->mng_cookie.vlan_id >>
5968 E1000_VFTA_ENTRY_SHIFT) &
5969 E1000_VFTA_ENTRY_MASK;
5970 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5971 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5972 }
5973 }
5974 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5975 /* If the offset we want to clear is the same offset of the
5976 * manageability VLAN ID, then clear all bits except that of the
5977 * manageability unit */
5978 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5979 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005980 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982}
5983
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005984static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985e1000_id_led_init(struct e1000_hw * hw)
5986{
5987 uint32_t ledctl;
5988 const uint32_t ledctl_mask = 0x000000FF;
5989 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5990 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5991 uint16_t eeprom_data, i, temp;
5992 const uint16_t led_mask = 0x0F;
5993
5994 DEBUGFUNC("e1000_id_led_init");
5995
Auke Kok8fc897b2006-08-28 14:56:16 -07005996 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 /* Nothing to do */
5998 return E1000_SUCCESS;
5999 }
6000
6001 ledctl = E1000_READ_REG(hw, LEDCTL);
6002 hw->ledctl_default = ledctl;
6003 hw->ledctl_mode1 = hw->ledctl_default;
6004 hw->ledctl_mode2 = hw->ledctl_default;
6005
Auke Kok8fc897b2006-08-28 14:56:16 -07006006 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 DEBUGOUT("EEPROM Read Error\n");
6008 return -E1000_ERR_EEPROM;
6009 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006010
6011 if ((hw->mac_type == e1000_82573) &&
6012 (eeprom_data == ID_LED_RESERVED_82573))
6013 eeprom_data = ID_LED_DEFAULT_82573;
6014 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6015 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6016 if (hw->mac_type == e1000_ich8lan)
6017 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6018 else
6019 eeprom_data = ID_LED_DEFAULT;
6020 }
6021 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006023 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 case ID_LED_ON1_DEF2:
6025 case ID_LED_ON1_ON2:
6026 case ID_LED_ON1_OFF2:
6027 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6028 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6029 break;
6030 case ID_LED_OFF1_DEF2:
6031 case ID_LED_OFF1_ON2:
6032 case ID_LED_OFF1_OFF2:
6033 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6034 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6035 break;
6036 default:
6037 /* Do nothing */
6038 break;
6039 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006040 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 case ID_LED_DEF1_ON2:
6042 case ID_LED_ON1_ON2:
6043 case ID_LED_OFF1_ON2:
6044 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6045 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6046 break;
6047 case ID_LED_DEF1_OFF2:
6048 case ID_LED_ON1_OFF2:
6049 case ID_LED_OFF1_OFF2:
6050 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6051 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6052 break;
6053 default:
6054 /* Do nothing */
6055 break;
6056 }
6057 }
6058 return E1000_SUCCESS;
6059}
6060
6061/******************************************************************************
6062 * Prepares SW controlable LED for use and saves the current state of the LED.
6063 *
6064 * hw - Struct containing variables accessed by shared code
6065 *****************************************************************************/
6066int32_t
6067e1000_setup_led(struct e1000_hw *hw)
6068{
6069 uint32_t ledctl;
6070 int32_t ret_val = E1000_SUCCESS;
6071
6072 DEBUGFUNC("e1000_setup_led");
6073
Auke Kok8fc897b2006-08-28 14:56:16 -07006074 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075 case e1000_82542_rev2_0:
6076 case e1000_82542_rev2_1:
6077 case e1000_82543:
6078 case e1000_82544:
6079 /* No setup necessary */
6080 break;
6081 case e1000_82541:
6082 case e1000_82547:
6083 case e1000_82541_rev_2:
6084 case e1000_82547_rev_2:
6085 /* Turn off PHY Smart Power Down (if enabled) */
6086 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6087 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006088 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 return ret_val;
6090 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6091 (uint16_t)(hw->phy_spd_default &
6092 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006093 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 return ret_val;
6095 /* Fall Through */
6096 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006097 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 ledctl = E1000_READ_REG(hw, LEDCTL);
6099 /* Save current LEDCTL settings */
6100 hw->ledctl_default = ledctl;
6101 /* Turn off LED0 */
6102 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6103 E1000_LEDCTL_LED0_BLINK |
6104 E1000_LEDCTL_LED0_MODE_MASK);
6105 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6106 E1000_LEDCTL_LED0_MODE_SHIFT);
6107 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006108 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6110 break;
6111 }
6112
6113 return E1000_SUCCESS;
6114}
6115
Auke Kok8fc897b2006-08-28 14:56:16 -07006116
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006118 * Used on 82571 and later Si that has LED blink bits.
6119 * Callers must use their own timer and should have already called
6120 * e1000_id_led_init()
6121 * Call e1000_cleanup led() to stop blinking
6122 *
6123 * hw - Struct containing variables accessed by shared code
6124 *****************************************************************************/
6125int32_t
6126e1000_blink_led_start(struct e1000_hw *hw)
6127{
6128 int16_t i;
6129 uint32_t ledctl_blink = 0;
6130
6131 DEBUGFUNC("e1000_id_led_blink_on");
6132
6133 if (hw->mac_type < e1000_82571) {
6134 /* Nothing to do */
6135 return E1000_SUCCESS;
6136 }
6137 if (hw->media_type == e1000_media_type_fiber) {
6138 /* always blink LED0 for PCI-E fiber */
6139 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6140 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6141 } else {
6142 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6143 ledctl_blink = hw->ledctl_mode2;
6144 for (i=0; i < 4; i++)
6145 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6146 E1000_LEDCTL_MODE_LED_ON)
6147 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6148 }
6149
6150 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6151
6152 return E1000_SUCCESS;
6153}
6154
6155/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 * Restores the saved state of the SW controlable LED.
6157 *
6158 * hw - Struct containing variables accessed by shared code
6159 *****************************************************************************/
6160int32_t
6161e1000_cleanup_led(struct e1000_hw *hw)
6162{
6163 int32_t ret_val = E1000_SUCCESS;
6164
6165 DEBUGFUNC("e1000_cleanup_led");
6166
Auke Kok8fc897b2006-08-28 14:56:16 -07006167 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006168 case e1000_82542_rev2_0:
6169 case e1000_82542_rev2_1:
6170 case e1000_82543:
6171 case e1000_82544:
6172 /* No cleanup necessary */
6173 break;
6174 case e1000_82541:
6175 case e1000_82547:
6176 case e1000_82541_rev_2:
6177 case e1000_82547_rev_2:
6178 /* Turn on PHY Smart Power Down (if previously enabled) */
6179 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6180 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006181 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 return ret_val;
6183 /* Fall Through */
6184 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006185 if (hw->phy_type == e1000_phy_ife) {
6186 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6187 break;
6188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 /* Restore LEDCTL settings */
6190 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6191 break;
6192 }
6193
6194 return E1000_SUCCESS;
6195}
6196
6197/******************************************************************************
6198 * Turns on the software controllable LED
6199 *
6200 * hw - Struct containing variables accessed by shared code
6201 *****************************************************************************/
6202int32_t
6203e1000_led_on(struct e1000_hw *hw)
6204{
6205 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6206
6207 DEBUGFUNC("e1000_led_on");
6208
Auke Kok8fc897b2006-08-28 14:56:16 -07006209 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 case e1000_82542_rev2_0:
6211 case e1000_82542_rev2_1:
6212 case e1000_82543:
6213 /* Set SW Defineable Pin 0 to turn on the LED */
6214 ctrl |= E1000_CTRL_SWDPIN0;
6215 ctrl |= E1000_CTRL_SWDPIO0;
6216 break;
6217 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006218 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 /* Set SW Defineable Pin 0 to turn on the LED */
6220 ctrl |= E1000_CTRL_SWDPIN0;
6221 ctrl |= E1000_CTRL_SWDPIO0;
6222 } else {
6223 /* Clear SW Defineable Pin 0 to turn on the LED */
6224 ctrl &= ~E1000_CTRL_SWDPIN0;
6225 ctrl |= E1000_CTRL_SWDPIO0;
6226 }
6227 break;
6228 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006229 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230 /* Clear SW Defineable Pin 0 to turn on the LED */
6231 ctrl &= ~E1000_CTRL_SWDPIN0;
6232 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006233 } else if (hw->phy_type == e1000_phy_ife) {
6234 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6235 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6236 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6238 return E1000_SUCCESS;
6239 }
6240 break;
6241 }
6242
6243 E1000_WRITE_REG(hw, CTRL, ctrl);
6244
6245 return E1000_SUCCESS;
6246}
6247
6248/******************************************************************************
6249 * Turns off the software controllable LED
6250 *
6251 * hw - Struct containing variables accessed by shared code
6252 *****************************************************************************/
6253int32_t
6254e1000_led_off(struct e1000_hw *hw)
6255{
6256 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6257
6258 DEBUGFUNC("e1000_led_off");
6259
Auke Kok8fc897b2006-08-28 14:56:16 -07006260 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 case e1000_82542_rev2_0:
6262 case e1000_82542_rev2_1:
6263 case e1000_82543:
6264 /* Clear SW Defineable Pin 0 to turn off the LED */
6265 ctrl &= ~E1000_CTRL_SWDPIN0;
6266 ctrl |= E1000_CTRL_SWDPIO0;
6267 break;
6268 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006269 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 /* Clear SW Defineable Pin 0 to turn off the LED */
6271 ctrl &= ~E1000_CTRL_SWDPIN0;
6272 ctrl |= E1000_CTRL_SWDPIO0;
6273 } else {
6274 /* Set SW Defineable Pin 0 to turn off the LED */
6275 ctrl |= E1000_CTRL_SWDPIN0;
6276 ctrl |= E1000_CTRL_SWDPIO0;
6277 }
6278 break;
6279 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006280 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 /* Set SW Defineable Pin 0 to turn off the LED */
6282 ctrl |= E1000_CTRL_SWDPIN0;
6283 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006284 } else if (hw->phy_type == e1000_phy_ife) {
6285 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6286 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6287 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6289 return E1000_SUCCESS;
6290 }
6291 break;
6292 }
6293
6294 E1000_WRITE_REG(hw, CTRL, ctrl);
6295
6296 return E1000_SUCCESS;
6297}
6298
6299/******************************************************************************
6300 * Clears all hardware statistics counters.
6301 *
6302 * hw - Struct containing variables accessed by shared code
6303 *****************************************************************************/
Auke Kok8fc897b2006-08-28 14:56:16 -07006304void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305e1000_clear_hw_cntrs(struct e1000_hw *hw)
6306{
6307 volatile uint32_t temp;
6308
6309 temp = E1000_READ_REG(hw, CRCERRS);
6310 temp = E1000_READ_REG(hw, SYMERRS);
6311 temp = E1000_READ_REG(hw, MPC);
6312 temp = E1000_READ_REG(hw, SCC);
6313 temp = E1000_READ_REG(hw, ECOL);
6314 temp = E1000_READ_REG(hw, MCC);
6315 temp = E1000_READ_REG(hw, LATECOL);
6316 temp = E1000_READ_REG(hw, COLC);
6317 temp = E1000_READ_REG(hw, DC);
6318 temp = E1000_READ_REG(hw, SEC);
6319 temp = E1000_READ_REG(hw, RLEC);
6320 temp = E1000_READ_REG(hw, XONRXC);
6321 temp = E1000_READ_REG(hw, XONTXC);
6322 temp = E1000_READ_REG(hw, XOFFRXC);
6323 temp = E1000_READ_REG(hw, XOFFTXC);
6324 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006325
6326 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327 temp = E1000_READ_REG(hw, PRC64);
6328 temp = E1000_READ_REG(hw, PRC127);
6329 temp = E1000_READ_REG(hw, PRC255);
6330 temp = E1000_READ_REG(hw, PRC511);
6331 temp = E1000_READ_REG(hw, PRC1023);
6332 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006333 }
6334
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 temp = E1000_READ_REG(hw, GPRC);
6336 temp = E1000_READ_REG(hw, BPRC);
6337 temp = E1000_READ_REG(hw, MPRC);
6338 temp = E1000_READ_REG(hw, GPTC);
6339 temp = E1000_READ_REG(hw, GORCL);
6340 temp = E1000_READ_REG(hw, GORCH);
6341 temp = E1000_READ_REG(hw, GOTCL);
6342 temp = E1000_READ_REG(hw, GOTCH);
6343 temp = E1000_READ_REG(hw, RNBC);
6344 temp = E1000_READ_REG(hw, RUC);
6345 temp = E1000_READ_REG(hw, RFC);
6346 temp = E1000_READ_REG(hw, ROC);
6347 temp = E1000_READ_REG(hw, RJC);
6348 temp = E1000_READ_REG(hw, TORL);
6349 temp = E1000_READ_REG(hw, TORH);
6350 temp = E1000_READ_REG(hw, TOTL);
6351 temp = E1000_READ_REG(hw, TOTH);
6352 temp = E1000_READ_REG(hw, TPR);
6353 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006354
6355 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 temp = E1000_READ_REG(hw, PTC64);
6357 temp = E1000_READ_REG(hw, PTC127);
6358 temp = E1000_READ_REG(hw, PTC255);
6359 temp = E1000_READ_REG(hw, PTC511);
6360 temp = E1000_READ_REG(hw, PTC1023);
6361 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006362 }
6363
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 temp = E1000_READ_REG(hw, MPTC);
6365 temp = E1000_READ_REG(hw, BPTC);
6366
Auke Kok8fc897b2006-08-28 14:56:16 -07006367 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368
6369 temp = E1000_READ_REG(hw, ALGNERRC);
6370 temp = E1000_READ_REG(hw, RXERRC);
6371 temp = E1000_READ_REG(hw, TNCRS);
6372 temp = E1000_READ_REG(hw, CEXTERR);
6373 temp = E1000_READ_REG(hw, TSCTC);
6374 temp = E1000_READ_REG(hw, TSCTFC);
6375
Auke Kok8fc897b2006-08-28 14:56:16 -07006376 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377
6378 temp = E1000_READ_REG(hw, MGTPRC);
6379 temp = E1000_READ_REG(hw, MGTPDC);
6380 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006381
Auke Kok8fc897b2006-08-28 14:56:16 -07006382 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006383
6384 temp = E1000_READ_REG(hw, IAC);
6385 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006386
6387 if (hw->mac_type == e1000_ich8lan) return;
6388
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006389 temp = E1000_READ_REG(hw, ICRXPTC);
6390 temp = E1000_READ_REG(hw, ICRXATC);
6391 temp = E1000_READ_REG(hw, ICTXPTC);
6392 temp = E1000_READ_REG(hw, ICTXATC);
6393 temp = E1000_READ_REG(hw, ICTXQEC);
6394 temp = E1000_READ_REG(hw, ICTXQMTC);
6395 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396}
6397
6398/******************************************************************************
6399 * Resets Adaptive IFS to its default state.
6400 *
6401 * hw - Struct containing variables accessed by shared code
6402 *
6403 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6404 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6405 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6406 * before calling this function.
6407 *****************************************************************************/
6408void
6409e1000_reset_adaptive(struct e1000_hw *hw)
6410{
6411 DEBUGFUNC("e1000_reset_adaptive");
6412
Auke Kok8fc897b2006-08-28 14:56:16 -07006413 if (hw->adaptive_ifs) {
6414 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 hw->current_ifs_val = 0;
6416 hw->ifs_min_val = IFS_MIN;
6417 hw->ifs_max_val = IFS_MAX;
6418 hw->ifs_step_size = IFS_STEP;
6419 hw->ifs_ratio = IFS_RATIO;
6420 }
6421 hw->in_ifs_mode = FALSE;
6422 E1000_WRITE_REG(hw, AIT, 0);
6423 } else {
6424 DEBUGOUT("Not in Adaptive IFS mode!\n");
6425 }
6426}
6427
6428/******************************************************************************
6429 * Called during the callback/watchdog routine to update IFS value based on
6430 * the ratio of transmits to collisions.
6431 *
6432 * hw - Struct containing variables accessed by shared code
6433 * tx_packets - Number of transmits since last callback
6434 * total_collisions - Number of collisions since last callback
6435 *****************************************************************************/
6436void
6437e1000_update_adaptive(struct e1000_hw *hw)
6438{
6439 DEBUGFUNC("e1000_update_adaptive");
6440
Auke Kok8fc897b2006-08-28 14:56:16 -07006441 if (hw->adaptive_ifs) {
6442 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6443 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006445 if (hw->current_ifs_val < hw->ifs_max_val) {
6446 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447 hw->current_ifs_val = hw->ifs_min_val;
6448 else
6449 hw->current_ifs_val += hw->ifs_step_size;
6450 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6451 }
6452 }
6453 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006454 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 hw->current_ifs_val = 0;
6456 hw->in_ifs_mode = FALSE;
6457 E1000_WRITE_REG(hw, AIT, 0);
6458 }
6459 }
6460 } else {
6461 DEBUGOUT("Not in Adaptive IFS mode!\n");
6462 }
6463}
6464
6465/******************************************************************************
6466 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6467 *
6468 * hw - Struct containing variables accessed by shared code
6469 * frame_len - The length of the frame in question
6470 * mac_addr - The Ethernet destination address of the frame in question
6471 *****************************************************************************/
6472void
6473e1000_tbi_adjust_stats(struct e1000_hw *hw,
6474 struct e1000_hw_stats *stats,
6475 uint32_t frame_len,
6476 uint8_t *mac_addr)
6477{
6478 uint64_t carry_bit;
6479
6480 /* First adjust the frame length. */
6481 frame_len--;
6482 /* We need to adjust the statistics counters, since the hardware
6483 * counters overcount this packet as a CRC error and undercount
6484 * the packet as a good packet
6485 */
6486 /* This packet should not be counted as a CRC error. */
6487 stats->crcerrs--;
6488 /* This packet does count as a Good Packet Received. */
6489 stats->gprc++;
6490
6491 /* Adjust the Good Octets received counters */
6492 carry_bit = 0x80000000 & stats->gorcl;
6493 stats->gorcl += frame_len;
6494 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6495 * Received Count) was one before the addition,
6496 * AND it is zero after, then we lost the carry out,
6497 * need to add one to Gorch (Good Octets Received Count High).
6498 * This could be simplified if all environments supported
6499 * 64-bit integers.
6500 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006501 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 stats->gorch++;
6503 /* Is this a broadcast or multicast? Check broadcast first,
6504 * since the test for a multicast frame will test positive on
6505 * a broadcast frame.
6506 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006507 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 /* Broadcast packet */
6509 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006510 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511 /* Multicast packet */
6512 stats->mprc++;
6513
Auke Kok8fc897b2006-08-28 14:56:16 -07006514 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 /* In this case, the hardware has overcounted the number of
6516 * oversize frames.
6517 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006518 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 stats->roc--;
6520 }
6521
6522 /* Adjust the bin counters when the extra byte put the frame in the
6523 * wrong bin. Remember that the frame_len was adjusted above.
6524 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006525 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 stats->prc64++;
6527 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006528 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 stats->prc127++;
6530 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006531 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 stats->prc255++;
6533 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006534 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 stats->prc511++;
6536 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006537 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538 stats->prc1023++;
6539 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006540 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 stats->prc1522++;
6542 }
6543}
6544
6545/******************************************************************************
6546 * Gets the current PCI bus type, speed, and width of the hardware
6547 *
6548 * hw - Struct containing variables accessed by shared code
6549 *****************************************************************************/
6550void
6551e1000_get_bus_info(struct e1000_hw *hw)
6552{
6553 uint32_t status;
6554
6555 switch (hw->mac_type) {
6556 case e1000_82542_rev2_0:
6557 case e1000_82542_rev2_1:
6558 hw->bus_type = e1000_bus_type_unknown;
6559 hw->bus_speed = e1000_bus_speed_unknown;
6560 hw->bus_width = e1000_bus_width_unknown;
6561 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006562 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006563 case e1000_82573:
6564 hw->bus_type = e1000_bus_type_pci_express;
6565 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirsherfd803242005-12-13 00:06:22 -05006566 hw->bus_width = e1000_bus_width_pciex_1;
6567 break;
6568 case e1000_82571:
Auke Kokcd94dd02006-06-27 09:08:22 -07006569 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006570 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006571 hw->bus_type = e1000_bus_type_pci_express;
6572 hw->bus_speed = e1000_bus_speed_2500;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006573 hw->bus_width = e1000_bus_width_pciex_4;
6574 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 default:
6576 status = E1000_READ_REG(hw, STATUS);
6577 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6578 e1000_bus_type_pcix : e1000_bus_type_pci;
6579
Auke Kok8fc897b2006-08-28 14:56:16 -07006580 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6582 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006583 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6585 e1000_bus_speed_66 : e1000_bus_speed_33;
6586 } else {
6587 switch (status & E1000_STATUS_PCIX_SPEED) {
6588 case E1000_STATUS_PCIX_SPEED_66:
6589 hw->bus_speed = e1000_bus_speed_66;
6590 break;
6591 case E1000_STATUS_PCIX_SPEED_100:
6592 hw->bus_speed = e1000_bus_speed_100;
6593 break;
6594 case E1000_STATUS_PCIX_SPEED_133:
6595 hw->bus_speed = e1000_bus_speed_133;
6596 break;
6597 default:
6598 hw->bus_speed = e1000_bus_speed_reserved;
6599 break;
6600 }
6601 }
6602 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6603 e1000_bus_width_64 : e1000_bus_width_32;
6604 break;
6605 }
6606}
6607/******************************************************************************
6608 * Reads a value from one of the devices registers using port I/O (as opposed
6609 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6610 *
6611 * hw - Struct containing variables accessed by shared code
6612 * offset - offset to read from
6613 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07006614#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615uint32_t
6616e1000_read_reg_io(struct e1000_hw *hw,
6617 uint32_t offset)
6618{
6619 unsigned long io_addr = hw->io_base;
6620 unsigned long io_data = hw->io_base + 4;
6621
6622 e1000_io_write(hw, io_addr, offset);
6623 return e1000_io_read(hw, io_data);
6624}
Adrian Bunke4c780b2006-08-14 23:00:10 -07006625#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626
6627/******************************************************************************
6628 * Writes a value to one of the devices registers using port I/O (as opposed to
6629 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6630 *
6631 * hw - Struct containing variables accessed by shared code
6632 * offset - offset to write to
6633 * value - value to write
6634 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006635static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636e1000_write_reg_io(struct e1000_hw *hw,
6637 uint32_t offset,
6638 uint32_t value)
6639{
6640 unsigned long io_addr = hw->io_base;
6641 unsigned long io_data = hw->io_base + 4;
6642
6643 e1000_io_write(hw, io_addr, offset);
6644 e1000_io_write(hw, io_data, value);
6645}
6646
6647
6648/******************************************************************************
6649 * Estimates the cable length.
6650 *
6651 * hw - Struct containing variables accessed by shared code
6652 * min_length - The estimated minimum length
6653 * max_length - The estimated maximum length
6654 *
6655 * returns: - E1000_ERR_XXX
6656 * E1000_SUCCESS
6657 *
6658 * This function always returns a ranged length (minimum & maximum).
6659 * So for M88 phy's, this function interprets the one value returned from the
6660 * register to the minimum and maximum range.
6661 * For IGP phy's, the function calculates the range by the AGC registers.
6662 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006663static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664e1000_get_cable_length(struct e1000_hw *hw,
6665 uint16_t *min_length,
6666 uint16_t *max_length)
6667{
6668 int32_t ret_val;
6669 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 uint16_t i, phy_data;
6671 uint16_t cable_length;
6672
6673 DEBUGFUNC("e1000_get_cable_length");
6674
6675 *min_length = *max_length = 0;
6676
6677 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006678 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006679
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6681 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006682 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 return ret_val;
6684 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6685 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6686
6687 /* Convert the enum value to ranged values */
6688 switch (cable_length) {
6689 case e1000_cable_length_50:
6690 *min_length = 0;
6691 *max_length = e1000_igp_cable_length_50;
6692 break;
6693 case e1000_cable_length_50_80:
6694 *min_length = e1000_igp_cable_length_50;
6695 *max_length = e1000_igp_cable_length_80;
6696 break;
6697 case e1000_cable_length_80_110:
6698 *min_length = e1000_igp_cable_length_80;
6699 *max_length = e1000_igp_cable_length_110;
6700 break;
6701 case e1000_cable_length_110_140:
6702 *min_length = e1000_igp_cable_length_110;
6703 *max_length = e1000_igp_cable_length_140;
6704 break;
6705 case e1000_cable_length_140:
6706 *min_length = e1000_igp_cable_length_140;
6707 *max_length = e1000_igp_cable_length_170;
6708 break;
6709 default:
6710 return -E1000_ERR_PHY;
6711 break;
6712 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006713 } else if (hw->phy_type == e1000_phy_gg82563) {
6714 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6715 &phy_data);
6716 if (ret_val)
6717 return ret_val;
6718 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6719
6720 switch (cable_length) {
6721 case e1000_gg_cable_length_60:
6722 *min_length = 0;
6723 *max_length = e1000_igp_cable_length_60;
6724 break;
6725 case e1000_gg_cable_length_60_115:
6726 *min_length = e1000_igp_cable_length_60;
6727 *max_length = e1000_igp_cable_length_115;
6728 break;
6729 case e1000_gg_cable_length_115_150:
6730 *min_length = e1000_igp_cable_length_115;
6731 *max_length = e1000_igp_cable_length_150;
6732 break;
6733 case e1000_gg_cable_length_150:
6734 *min_length = e1000_igp_cable_length_150;
6735 *max_length = e1000_igp_cable_length_180;
6736 break;
6737 default:
6738 return -E1000_ERR_PHY;
6739 break;
6740 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006741 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006742 uint16_t cur_agc_value;
6743 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6745 {IGP01E1000_PHY_AGC_A,
6746 IGP01E1000_PHY_AGC_B,
6747 IGP01E1000_PHY_AGC_C,
6748 IGP01E1000_PHY_AGC_D};
6749 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006750 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751
6752 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006753 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 return ret_val;
6755
Auke Kokcd94dd02006-06-27 09:08:22 -07006756 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757
Auke Kokcd94dd02006-06-27 09:08:22 -07006758 /* Value bound check. */
6759 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6760 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 return -E1000_ERR_PHY;
6762
Auke Kokcd94dd02006-06-27 09:08:22 -07006763 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764
6765 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006766 if (min_agc_value > cur_agc_value)
6767 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 }
6769
6770 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006771 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6772 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773
6774 /* Get the average length of the remaining 3 channels */
6775 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6776 } else {
6777 /* Get the average length of all the 4 channels. */
6778 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6779 }
6780
6781 /* Set the range of the calculated length. */
6782 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6783 IGP01E1000_AGC_RANGE) > 0) ?
6784 (e1000_igp_cable_length_table[agc_value] -
6785 IGP01E1000_AGC_RANGE) : 0;
6786 *max_length = e1000_igp_cable_length_table[agc_value] +
6787 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006788 } else if (hw->phy_type == e1000_phy_igp_2 ||
6789 hw->phy_type == e1000_phy_igp_3) {
6790 uint16_t cur_agc_index, max_agc_index = 0;
6791 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006792 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6793 {IGP02E1000_PHY_AGC_A,
6794 IGP02E1000_PHY_AGC_B,
6795 IGP02E1000_PHY_AGC_C,
6796 IGP02E1000_PHY_AGC_D};
6797 /* Read the AGC registers for all channels */
6798 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6799 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6800 if (ret_val)
6801 return ret_val;
6802
Auke Kok8fc897b2006-08-28 14:56:16 -07006803 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006804 * fine gain values. The result is a number that can be put into
6805 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006806 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6807 IGP02E1000_AGC_LENGTH_MASK;
6808
6809 /* Array index bound check. */
6810 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6811 (cur_agc_index == 0))
6812 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006813
6814 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006815 if (e1000_igp_2_cable_length_table[min_agc_index] >
6816 e1000_igp_2_cable_length_table[cur_agc_index])
6817 min_agc_index = cur_agc_index;
6818 if (e1000_igp_2_cable_length_table[max_agc_index] <
6819 e1000_igp_2_cable_length_table[cur_agc_index])
6820 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006821
Auke Kokcd94dd02006-06-27 09:08:22 -07006822 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006823 }
6824
Auke Kokcd94dd02006-06-27 09:08:22 -07006825 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6826 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006827 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6828
6829 /* Calculate cable length with the error range of +/- 10 meters. */
6830 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6831 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6832 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833 }
6834
6835 return E1000_SUCCESS;
6836}
6837
6838/******************************************************************************
6839 * Check the cable polarity
6840 *
6841 * hw - Struct containing variables accessed by shared code
6842 * polarity - output parameter : 0 - Polarity is not reversed
6843 * 1 - Polarity is reversed.
6844 *
6845 * returns: - E1000_ERR_XXX
6846 * E1000_SUCCESS
6847 *
6848 * For phy's older then IGP, this function simply reads the polarity bit in the
6849 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6850 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6851 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6852 * IGP01E1000_PHY_PCS_INIT_REG.
6853 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006854static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006856 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857{
6858 int32_t ret_val;
6859 uint16_t phy_data;
6860
6861 DEBUGFUNC("e1000_check_polarity");
6862
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006863 if ((hw->phy_type == e1000_phy_m88) ||
6864 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865 /* return the Polarity bit in the Status register. */
6866 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6867 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006868 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006870 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6871 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6872 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6873
Auke Kokcd94dd02006-06-27 09:08:22 -07006874 } else if (hw->phy_type == e1000_phy_igp ||
6875 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006876 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 /* Read the Status register to check the speed */
6878 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6879 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006880 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881 return ret_val;
6882
6883 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6884 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006885 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 IGP01E1000_PSSR_SPEED_1000MBPS) {
6887
6888 /* Read the GIG initialization PCS register (0x00B4) */
6889 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6890 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006891 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 return ret_val;
6893
6894 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006895 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6896 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 } else {
6898 /* For 10 Mbps, read the polarity bit in the status register. (for
6899 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006900 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6901 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006903 } else if (hw->phy_type == e1000_phy_ife) {
6904 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6905 &phy_data);
6906 if (ret_val)
6907 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006908 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6909 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6910 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006911 }
6912 return E1000_SUCCESS;
6913}
6914
6915/******************************************************************************
6916 * Check if Downshift occured
6917 *
6918 * hw - Struct containing variables accessed by shared code
6919 * downshift - output parameter : 0 - No Downshift ocured.
6920 * 1 - Downshift ocured.
6921 *
6922 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006923 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 *
6925 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6926 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6927 * Link Health register. In IGP this bit is latched high, so the driver must
6928 * read it immediately after link is established.
6929 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006930static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006931e1000_check_downshift(struct e1000_hw *hw)
6932{
6933 int32_t ret_val;
6934 uint16_t phy_data;
6935
6936 DEBUGFUNC("e1000_check_downshift");
6937
Auke Kokcd94dd02006-06-27 09:08:22 -07006938 if (hw->phy_type == e1000_phy_igp ||
6939 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006940 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6942 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006943 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006944 return ret_val;
6945
6946 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006947 } else if ((hw->phy_type == e1000_phy_m88) ||
6948 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006949 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6950 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006951 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006952 return ret_val;
6953
6954 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6955 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006956 } else if (hw->phy_type == e1000_phy_ife) {
6957 /* e1000_phy_ife supports 10/100 speed only */
6958 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006960
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961 return E1000_SUCCESS;
6962}
6963
6964/*****************************************************************************
6965 *
6966 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6967 * gigabit link is achieved to improve link quality.
6968 *
6969 * hw: Struct containing variables accessed by shared code
6970 *
6971 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6972 * E1000_SUCCESS at any other case.
6973 *
6974 ****************************************************************************/
6975
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006976static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006977e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6978 boolean_t link_up)
6979{
6980 int32_t ret_val;
6981 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6982 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6983 {IGP01E1000_PHY_AGC_PARAM_A,
6984 IGP01E1000_PHY_AGC_PARAM_B,
6985 IGP01E1000_PHY_AGC_PARAM_C,
6986 IGP01E1000_PHY_AGC_PARAM_D};
6987 uint16_t min_length, max_length;
6988
6989 DEBUGFUNC("e1000_config_dsp_after_link_change");
6990
Auke Kok8fc897b2006-08-28 14:56:16 -07006991 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992 return E1000_SUCCESS;
6993
Auke Kok8fc897b2006-08-28 14:56:16 -07006994 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006995 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07006996 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 DEBUGOUT("Error getting link speed and duplex\n");
6998 return ret_val;
6999 }
7000
Auke Kok8fc897b2006-08-28 14:56:16 -07007001 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002
Auke Kokcd94dd02006-06-27 09:08:22 -07007003 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7004 if (ret_val)
7005 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007006
Auke Kok8fc897b2006-08-28 14:56:16 -07007007 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008 min_length >= e1000_igp_cable_length_50) {
7009
Auke Kok8fc897b2006-08-28 14:56:16 -07007010 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7012 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007013 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007014 return ret_val;
7015
7016 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7017
7018 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7019 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007020 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007021 return ret_val;
7022 }
7023 hw->dsp_config_state = e1000_dsp_config_activated;
7024 }
7025
Auke Kok8fc897b2006-08-28 14:56:16 -07007026 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007027 (min_length < e1000_igp_cable_length_50)) {
7028
7029 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7030 uint32_t idle_errs = 0;
7031
7032 /* clear previous idle error counts */
7033 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7034 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007035 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036 return ret_val;
7037
Auke Kok8fc897b2006-08-28 14:56:16 -07007038 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007039 udelay(1000);
7040 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7041 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007042 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 return ret_val;
7044
7045 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007046 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007047 hw->ffe_config_state = e1000_ffe_config_active;
7048
7049 ret_val = e1000_write_phy_reg(hw,
7050 IGP01E1000_PHY_DSP_FFE,
7051 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007052 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 return ret_val;
7054 break;
7055 }
7056
Auke Kok8fc897b2006-08-28 14:56:16 -07007057 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7059 }
7060 }
7061 }
7062 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007063 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 /* Save off the current value of register 0x2F5B to be restored at
7065 * the end of the routines. */
7066 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7067
Auke Kok8fc897b2006-08-28 14:56:16 -07007068 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007069 return ret_val;
7070
7071 /* Disable the PHY transmitter */
7072 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7073
Auke Kok8fc897b2006-08-28 14:56:16 -07007074 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075 return ret_val;
7076
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007077 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007078
7079 ret_val = e1000_write_phy_reg(hw, 0x0000,
7080 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007081 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007083 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007085 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086 return ret_val;
7087
7088 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7089 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7090
7091 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007092 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007093 return ret_val;
7094 }
7095
7096 ret_val = e1000_write_phy_reg(hw, 0x0000,
7097 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007098 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 return ret_val;
7100
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007101 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007102
7103 /* Now enable the transmitter */
7104 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7105
Auke Kok8fc897b2006-08-28 14:56:16 -07007106 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007107 return ret_val;
7108
7109 hw->dsp_config_state = e1000_dsp_config_enabled;
7110 }
7111
Auke Kok8fc897b2006-08-28 14:56:16 -07007112 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007113 /* Save off the current value of register 0x2F5B to be restored at
7114 * the end of the routines. */
7115 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7116
Auke Kok8fc897b2006-08-28 14:56:16 -07007117 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007118 return ret_val;
7119
7120 /* Disable the PHY transmitter */
7121 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7122
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 ret_val = e1000_write_phy_reg(hw, 0x0000,
7129 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007130 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007131 return ret_val;
7132 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7133 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007134 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007135 return ret_val;
7136
7137 ret_val = e1000_write_phy_reg(hw, 0x0000,
7138 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007139 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007140 return ret_val;
7141
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007142 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007143
7144 /* Now enable the transmitter */
7145 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7146
Auke Kok8fc897b2006-08-28 14:56:16 -07007147 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007148 return ret_val;
7149
7150 hw->ffe_config_state = e1000_ffe_config_enabled;
7151 }
7152 }
7153 return E1000_SUCCESS;
7154}
7155
7156/*****************************************************************************
7157 * Set PHY to class A mode
7158 * Assumes the following operations will follow to enable the new class mode.
7159 * 1. Do a PHY soft reset
7160 * 2. Restart auto-negotiation or force link.
7161 *
7162 * hw - Struct containing variables accessed by shared code
7163 ****************************************************************************/
7164static int32_t
7165e1000_set_phy_mode(struct e1000_hw *hw)
7166{
7167 int32_t ret_val;
7168 uint16_t eeprom_data;
7169
7170 DEBUGFUNC("e1000_set_phy_mode");
7171
Auke Kok8fc897b2006-08-28 14:56:16 -07007172 if ((hw->mac_type == e1000_82545_rev_3) &&
7173 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007174 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007175 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007176 return ret_val;
7177 }
7178
Auke Kok8fc897b2006-08-28 14:56:16 -07007179 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7180 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007182 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183 return ret_val;
7184 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007185 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007186 return ret_val;
7187
7188 hw->phy_reset_disable = FALSE;
7189 }
7190 }
7191
7192 return E1000_SUCCESS;
7193}
7194
7195/*****************************************************************************
7196 *
7197 * This function sets the lplu state according to the active flag. When
7198 * activating lplu this function also disables smart speed and vise versa.
7199 * lplu will not be activated unless the device autonegotiation advertisment
7200 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7201 * hw: Struct containing variables accessed by shared code
7202 * active - true to enable lplu false to disable lplu.
7203 *
7204 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7205 * E1000_SUCCESS at any other case.
7206 *
7207 ****************************************************************************/
7208
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007209static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007210e1000_set_d3_lplu_state(struct e1000_hw *hw,
7211 boolean_t active)
7212{
Auke Kokcd94dd02006-06-27 09:08:22 -07007213 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007214 int32_t ret_val;
7215 uint16_t phy_data;
7216 DEBUGFUNC("e1000_set_d3_lplu_state");
7217
Auke Kokcd94dd02006-06-27 09:08:22 -07007218 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7219 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007220 return E1000_SUCCESS;
7221
7222 /* During driver activity LPLU should not be used or it will attain link
7223 * from the lowest speeds starting from 10Mbps. The capability is used for
7224 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007225 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007226 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007227 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007228 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007229 } else if (hw->mac_type == e1000_ich8lan) {
7230 /* MAC writes into PHY register based on the state transition
7231 * and start auto-negotiation. SW driver can overwrite the settings
7232 * in CSR PHY power control E1000_PHY_CTRL register. */
7233 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007234 } else {
7235 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007236 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007237 return ret_val;
7238 }
7239
Auke Kok8fc897b2006-08-28 14:56:16 -07007240 if (!active) {
7241 if (hw->mac_type == e1000_82541_rev_2 ||
7242 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007243 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7244 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007245 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007246 return ret_val;
7247 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007248 if (hw->mac_type == e1000_ich8lan) {
7249 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7250 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7251 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007252 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7253 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7254 phy_data);
7255 if (ret_val)
7256 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007257 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007259
7260 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7261 * Dx states where the power conservation is most important. During
7262 * driver activity we should enable SmartSpeed, so performance is
7263 * maintained. */
7264 if (hw->smart_speed == e1000_smart_speed_on) {
7265 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7266 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007267 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007268 return ret_val;
7269
7270 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7271 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7272 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007273 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007274 return ret_val;
7275 } else if (hw->smart_speed == e1000_smart_speed_off) {
7276 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7277 &phy_data);
7278 if (ret_val)
7279 return ret_val;
7280
7281 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7282 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7283 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007284 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007285 return ret_val;
7286 }
7287
Auke Kok8fc897b2006-08-28 14:56:16 -07007288 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7289 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7290 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291
Auke Kok8fc897b2006-08-28 14:56:16 -07007292 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007293 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007294 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7295 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007296 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007297 return ret_val;
7298 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007299 if (hw->mac_type == e1000_ich8lan) {
7300 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7301 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7302 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007303 phy_data |= IGP02E1000_PM_D3_LPLU;
7304 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7305 phy_data);
7306 if (ret_val)
7307 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007308 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007309 }
7310
7311 /* When LPLU is enabled we should disable SmartSpeed */
7312 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007313 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007314 return ret_val;
7315
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007316 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7317 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007318 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007319 return ret_val;
7320
7321 }
7322 return E1000_SUCCESS;
7323}
7324
7325/*****************************************************************************
7326 *
7327 * This function sets the lplu d0 state according to the active flag. When
7328 * activating lplu this function also disables smart speed and vise versa.
7329 * lplu will not be activated unless the device autonegotiation advertisment
7330 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7331 * hw: Struct containing variables accessed by shared code
7332 * active - true to enable lplu false to disable lplu.
7333 *
7334 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7335 * E1000_SUCCESS at any other case.
7336 *
7337 ****************************************************************************/
7338
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007339static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007340e1000_set_d0_lplu_state(struct e1000_hw *hw,
7341 boolean_t active)
7342{
Auke Kokcd94dd02006-06-27 09:08:22 -07007343 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007344 int32_t ret_val;
7345 uint16_t phy_data;
7346 DEBUGFUNC("e1000_set_d0_lplu_state");
7347
Auke Kok8fc897b2006-08-28 14:56:16 -07007348 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007349 return E1000_SUCCESS;
7350
Auke Kokcd94dd02006-06-27 09:08:22 -07007351 if (hw->mac_type == e1000_ich8lan) {
7352 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7353 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007354 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007355 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007356 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007357 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007358
7359 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007360 if (hw->mac_type == e1000_ich8lan) {
7361 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7362 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7363 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007364 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7365 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7366 if (ret_val)
7367 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007368 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007369
7370 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7371 * Dx states where the power conservation is most important. During
7372 * driver activity we should enable SmartSpeed, so performance is
7373 * maintained. */
7374 if (hw->smart_speed == e1000_smart_speed_on) {
7375 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7376 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007377 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007378 return ret_val;
7379
7380 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7381 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7382 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007383 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007384 return ret_val;
7385 } else if (hw->smart_speed == e1000_smart_speed_off) {
7386 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7387 &phy_data);
7388 if (ret_val)
7389 return ret_val;
7390
7391 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7392 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7393 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007394 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007395 return ret_val;
7396 }
7397
7398
7399 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007400
Auke Kokcd94dd02006-06-27 09:08:22 -07007401 if (hw->mac_type == e1000_ich8lan) {
7402 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7403 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7404 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007405 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007406 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7407 if (ret_val)
7408 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007409 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007410
Linus Torvalds1da177e2005-04-16 15:20:36 -07007411 /* When LPLU is enabled we should disable SmartSpeed */
7412 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007413 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007414 return ret_val;
7415
7416 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7417 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007418 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007419 return ret_val;
7420
7421 }
7422 return E1000_SUCCESS;
7423}
7424
7425/******************************************************************************
7426 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7427 *
7428 * hw - Struct containing variables accessed by shared code
7429 *****************************************************************************/
7430static int32_t
7431e1000_set_vco_speed(struct e1000_hw *hw)
7432{
7433 int32_t ret_val;
7434 uint16_t default_page = 0;
7435 uint16_t phy_data;
7436
7437 DEBUGFUNC("e1000_set_vco_speed");
7438
Auke Kok8fc897b2006-08-28 14:56:16 -07007439 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007440 case e1000_82545_rev_3:
7441 case e1000_82546_rev_3:
7442 break;
7443 default:
7444 return E1000_SUCCESS;
7445 }
7446
7447 /* Set PHY register 30, page 5, bit 8 to 0 */
7448
7449 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007450 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007451 return ret_val;
7452
7453 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007454 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007455 return ret_val;
7456
7457 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007458 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007459 return ret_val;
7460
7461 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7462 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007463 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007464 return ret_val;
7465
7466 /* Set PHY register 30, page 4, bit 11 to 1 */
7467
7468 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007469 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007470 return ret_val;
7471
7472 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007473 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474 return ret_val;
7475
7476 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7477 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007478 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007479 return ret_val;
7480
7481 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007482 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007483 return ret_val;
7484
7485 return E1000_SUCCESS;
7486}
7487
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007488
7489/*****************************************************************************
7490 * This function reads the cookie from ARC ram.
7491 *
7492 * returns: - E1000_SUCCESS .
7493 ****************************************************************************/
7494int32_t
7495e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7496{
7497 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007498 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007499 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7500
7501 length = (length >> 2);
7502 offset = (offset >> 2);
7503
7504 for (i = 0; i < length; i++) {
7505 *((uint32_t *) buffer + i) =
7506 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7507 }
7508 return E1000_SUCCESS;
7509}
7510
7511
7512/*****************************************************************************
7513 * This function checks whether the HOST IF is enabled for command operaton
7514 * and also checks whether the previous command is completed.
7515 * It busy waits in case of previous command is not completed.
7516 *
Auke Kok76c224b2006-05-23 13:36:06 -07007517 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007518 * timeout
7519 * - E1000_SUCCESS for success.
7520 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007521static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007522e1000_mng_enable_host_if(struct e1000_hw * hw)
7523{
7524 uint32_t hicr;
7525 uint8_t i;
7526
7527 /* Check that the host interface is enabled. */
7528 hicr = E1000_READ_REG(hw, HICR);
7529 if ((hicr & E1000_HICR_EN) == 0) {
7530 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7531 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7532 }
7533 /* check the previous command is completed */
7534 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7535 hicr = E1000_READ_REG(hw, HICR);
7536 if (!(hicr & E1000_HICR_C))
7537 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007538 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007539 }
7540
Auke Kok76c224b2006-05-23 13:36:06 -07007541 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007542 DEBUGOUT("Previous command timeout failed .\n");
7543 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7544 }
7545 return E1000_SUCCESS;
7546}
7547
7548/*****************************************************************************
7549 * This function writes the buffer content at the offset given on the host if.
7550 * It also does alignment considerations to do the writes in most efficient way.
7551 * Also fills up the sum of the buffer in *buffer parameter.
7552 *
7553 * returns - E1000_SUCCESS for success.
7554 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007555static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007556e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7557 uint16_t length, uint16_t offset, uint8_t *sum)
7558{
7559 uint8_t *tmp;
7560 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007561 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007562 uint16_t remaining, i, j, prev_bytes;
7563
7564 /* sum = only sum of the data and it is not checksum */
7565
7566 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7567 return -E1000_ERR_PARAM;
7568 }
7569
7570 tmp = (uint8_t *)&data;
7571 prev_bytes = offset & 0x3;
7572 offset &= 0xFFFC;
7573 offset >>= 2;
7574
7575 if (prev_bytes) {
7576 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7577 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7578 *(tmp + j) = *bufptr++;
7579 *sum += *(tmp + j);
7580 }
7581 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7582 length -= j - prev_bytes;
7583 offset++;
7584 }
7585
7586 remaining = length & 0x3;
7587 length -= remaining;
7588
7589 /* Calculate length in DWORDs */
7590 length >>= 2;
7591
7592 /* The device driver writes the relevant command block into the
7593 * ram area. */
7594 for (i = 0; i < length; i++) {
7595 for (j = 0; j < sizeof(uint32_t); j++) {
7596 *(tmp + j) = *bufptr++;
7597 *sum += *(tmp + j);
7598 }
7599
7600 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7601 }
7602 if (remaining) {
7603 for (j = 0; j < sizeof(uint32_t); j++) {
7604 if (j < remaining)
7605 *(tmp + j) = *bufptr++;
7606 else
7607 *(tmp + j) = 0;
7608
7609 *sum += *(tmp + j);
7610 }
7611 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7612 }
7613
7614 return E1000_SUCCESS;
7615}
7616
7617
7618/*****************************************************************************
7619 * This function writes the command header after does the checksum calculation.
7620 *
7621 * returns - E1000_SUCCESS for success.
7622 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007623static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007624e1000_mng_write_cmd_header(struct e1000_hw * hw,
7625 struct e1000_host_mng_command_header * hdr)
7626{
7627 uint16_t i;
7628 uint8_t sum;
7629 uint8_t *buffer;
7630
7631 /* Write the whole command header structure which includes sum of
7632 * the buffer */
7633
7634 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7635
7636 sum = hdr->checksum;
7637 hdr->checksum = 0;
7638
7639 buffer = (uint8_t *) hdr;
7640 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007641 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007642 sum += buffer[i];
7643
7644 hdr->checksum = 0 - sum;
7645
7646 length >>= 2;
7647 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007648 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007649 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007650 E1000_WRITE_FLUSH(hw);
7651 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007652
7653 return E1000_SUCCESS;
7654}
7655
7656
7657/*****************************************************************************
7658 * This function indicates to ARC that a new command is pending which completes
7659 * one write operation by the driver.
7660 *
7661 * returns - E1000_SUCCESS for success.
7662 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007663static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007664e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007665{
7666 uint32_t hicr;
7667
7668 hicr = E1000_READ_REG(hw, HICR);
7669 /* Setting this bit tells the ARC that a new command is pending. */
7670 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7671
7672 return E1000_SUCCESS;
7673}
7674
7675
7676/*****************************************************************************
7677 * This function checks the mode of the firmware.
7678 *
7679 * returns - TRUE when the mode is IAMT or FALSE.
7680 ****************************************************************************/
7681boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007682e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007683{
7684 uint32_t fwsm;
7685
7686 fwsm = E1000_READ_REG(hw, FWSM);
7687
Auke Kokcd94dd02006-06-27 09:08:22 -07007688 if (hw->mac_type == e1000_ich8lan) {
7689 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7690 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7691 return TRUE;
7692 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7693 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007694 return TRUE;
7695
7696 return FALSE;
7697}
7698
7699
7700/*****************************************************************************
7701 * This function writes the dhcp info .
7702 ****************************************************************************/
7703int32_t
7704e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7705 uint16_t length)
7706{
7707 int32_t ret_val;
7708 struct e1000_host_mng_command_header hdr;
7709
7710 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7711 hdr.command_length = length;
7712 hdr.reserved1 = 0;
7713 hdr.reserved2 = 0;
7714 hdr.checksum = 0;
7715
7716 ret_val = e1000_mng_enable_host_if(hw);
7717 if (ret_val == E1000_SUCCESS) {
7718 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7719 &(hdr.checksum));
7720 if (ret_val == E1000_SUCCESS) {
7721 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7722 if (ret_val == E1000_SUCCESS)
7723 ret_val = e1000_mng_write_commit(hw);
7724 }
7725 }
7726 return ret_val;
7727}
7728
7729
7730/*****************************************************************************
7731 * This function calculates the checksum.
7732 *
7733 * returns - checksum of buffer contents.
7734 ****************************************************************************/
7735uint8_t
7736e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7737{
7738 uint8_t sum = 0;
7739 uint32_t i;
7740
7741 if (!buffer)
7742 return 0;
7743
7744 for (i=0; i < length; i++)
7745 sum += buffer[i];
7746
7747 return (uint8_t) (0 - sum);
7748}
7749
7750/*****************************************************************************
7751 * This function checks whether tx pkt filtering needs to be enabled or not.
7752 *
7753 * returns - TRUE for packet filtering or FALSE.
7754 ****************************************************************************/
7755boolean_t
7756e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7757{
7758 /* called in init as well as watchdog timer functions */
7759
7760 int32_t ret_val, checksum;
7761 boolean_t tx_filter = FALSE;
7762 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7763 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7764
7765 if (e1000_check_mng_mode(hw)) {
7766 ret_val = e1000_mng_enable_host_if(hw);
7767 if (ret_val == E1000_SUCCESS) {
7768 ret_val = e1000_host_if_read_cookie(hw, buffer);
7769 if (ret_val == E1000_SUCCESS) {
7770 checksum = hdr->checksum;
7771 hdr->checksum = 0;
7772 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7773 checksum == e1000_calculate_mng_checksum((char *)buffer,
7774 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7775 if (hdr->status &
7776 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7777 tx_filter = TRUE;
7778 } else
7779 tx_filter = TRUE;
7780 } else
7781 tx_filter = TRUE;
7782 }
7783 }
7784
7785 hw->tx_pkt_filtering = tx_filter;
7786 return tx_filter;
7787}
7788
7789/******************************************************************************
7790 * Verifies the hardware needs to allow ARPs to be processed by the host
7791 *
7792 * hw - Struct containing variables accessed by shared code
7793 *
7794 * returns: - TRUE/FALSE
7795 *
7796 *****************************************************************************/
7797uint32_t
7798e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7799{
7800 uint32_t manc;
7801 uint32_t fwsm, factps;
7802
7803 if (hw->asf_firmware_present) {
7804 manc = E1000_READ_REG(hw, MANC);
7805
7806 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7807 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7808 return FALSE;
7809 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7810 fwsm = E1000_READ_REG(hw, FWSM);
7811 factps = E1000_READ_REG(hw, FACTPS);
7812
7813 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7814 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7815 (factps & E1000_FACTPS_MNGCG))
7816 return TRUE;
7817 } else
7818 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7819 return TRUE;
7820 }
7821 return FALSE;
7822}
7823
Linus Torvalds1da177e2005-04-16 15:20:36 -07007824static int32_t
7825e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7826{
7827 int32_t ret_val;
7828 uint16_t mii_status_reg;
7829 uint16_t i;
7830
7831 /* Polarity reversal workaround for forced 10F/10H links. */
7832
7833 /* Disable the transmitter on the PHY */
7834
7835 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007836 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007837 return ret_val;
7838 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007839 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007840 return ret_val;
7841
7842 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007843 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007844 return ret_val;
7845
7846 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007847 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007848 /* Read the MII Status Register and wait for Link Status bit
7849 * to be clear.
7850 */
7851
7852 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007853 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007854 return ret_val;
7855
7856 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007857 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007858 return ret_val;
7859
Auke Kok8fc897b2006-08-28 14:56:16 -07007860 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007861 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007862 }
7863
7864 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007865 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007866
7867 /* Now we will re-enable th transmitter on the PHY */
7868
7869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007870 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007871 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007872 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007873 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007874 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007875 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007876 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007877 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007878 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007879 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007880 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007881 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007882 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007883 return ret_val;
7884
7885 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007886 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007887 return ret_val;
7888
7889 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007890 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007891 /* Read the MII Status Register and wait for Link Status bit
7892 * to be set.
7893 */
7894
7895 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007896 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007897 return ret_val;
7898
7899 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007900 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007901 return ret_val;
7902
Auke Kok8fc897b2006-08-28 14:56:16 -07007903 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007904 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007905 }
7906 return E1000_SUCCESS;
7907}
7908
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007909/***************************************************************************
7910 *
7911 * Disables PCI-Express master access.
7912 *
7913 * hw: Struct containing variables accessed by shared code
7914 *
7915 * returns: - none.
7916 *
7917 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007918static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007919e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7920{
7921 uint32_t ctrl;
7922
7923 DEBUGFUNC("e1000_set_pci_express_master_disable");
7924
7925 if (hw->bus_type != e1000_bus_type_pci_express)
7926 return;
7927
7928 ctrl = E1000_READ_REG(hw, CTRL);
7929 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7930 E1000_WRITE_REG(hw, CTRL, ctrl);
7931}
7932
7933/***************************************************************************
7934 *
7935 * Enables PCI-Express master access.
7936 *
7937 * hw: Struct containing variables accessed by shared code
7938 *
7939 * returns: - none.
7940 *
7941 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07007942#if 0
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007943void
7944e1000_enable_pciex_master(struct e1000_hw *hw)
7945{
7946 uint32_t ctrl;
7947
7948 DEBUGFUNC("e1000_enable_pciex_master");
7949
7950 if (hw->bus_type != e1000_bus_type_pci_express)
7951 return;
7952
7953 ctrl = E1000_READ_REG(hw, CTRL);
7954 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7955 E1000_WRITE_REG(hw, CTRL, ctrl);
7956}
Adrian Bunke4c780b2006-08-14 23:00:10 -07007957#endif /* 0 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007958
7959/*******************************************************************************
7960 *
7961 * Disables PCI-Express master access and verifies there are no pending requests
7962 *
7963 * hw: Struct containing variables accessed by shared code
7964 *
7965 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7966 * caused the master requests to be disabled.
7967 * E1000_SUCCESS master requests disabled.
7968 *
7969 ******************************************************************************/
7970int32_t
7971e1000_disable_pciex_master(struct e1000_hw *hw)
7972{
7973 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7974
7975 DEBUGFUNC("e1000_disable_pciex_master");
7976
7977 if (hw->bus_type != e1000_bus_type_pci_express)
7978 return E1000_SUCCESS;
7979
7980 e1000_set_pci_express_master_disable(hw);
7981
Auke Kok8fc897b2006-08-28 14:56:16 -07007982 while (timeout) {
7983 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007984 break;
7985 else
7986 udelay(100);
7987 timeout--;
7988 }
7989
Auke Kok8fc897b2006-08-28 14:56:16 -07007990 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007991 DEBUGOUT("Master requests are pending.\n");
7992 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7993 }
7994
7995 return E1000_SUCCESS;
7996}
7997
7998/*******************************************************************************
7999 *
8000 * Check for EEPROM Auto Read bit done.
8001 *
8002 * hw: Struct containing variables accessed by shared code
8003 *
8004 * returns: - E1000_ERR_RESET if fail to reset MAC
8005 * E1000_SUCCESS at any other case.
8006 *
8007 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008008static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008009e1000_get_auto_rd_done(struct e1000_hw *hw)
8010{
8011 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8012
8013 DEBUGFUNC("e1000_get_auto_rd_done");
8014
8015 switch (hw->mac_type) {
8016 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008017 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008018 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008019 case e1000_82571:
8020 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008021 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008022 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008023 case e1000_ich8lan:
8024 while (timeout) {
8025 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8026 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008027 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008028 timeout--;
8029 }
8030
Auke Kok8fc897b2006-08-28 14:56:16 -07008031 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008032 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8033 return -E1000_ERR_RESET;
8034 }
8035 break;
8036 }
8037
Jeff Kirsherfd803242005-12-13 00:06:22 -05008038 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8039 * Need to wait for PHY configuration completion before accessing NVM
8040 * and PHY. */
8041 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008042 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008043
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008044 return E1000_SUCCESS;
8045}
8046
8047/***************************************************************************
8048 * Checks if the PHY configuration is done
8049 *
8050 * hw: Struct containing variables accessed by shared code
8051 *
8052 * returns: - E1000_ERR_RESET if fail to reset MAC
8053 * E1000_SUCCESS at any other case.
8054 *
8055 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008056static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008057e1000_get_phy_cfg_done(struct e1000_hw *hw)
8058{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008059 int32_t timeout = PHY_CFG_TIMEOUT;
8060 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8061
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008062 DEBUGFUNC("e1000_get_phy_cfg_done");
8063
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008064 switch (hw->mac_type) {
8065 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008066 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008067 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008068 case e1000_80003es2lan:
8069 /* Separate *_CFG_DONE_* bit for each port */
8070 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8071 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8072 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008073 case e1000_82571:
8074 case e1000_82572:
8075 while (timeout) {
8076 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8077 break;
8078 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008079 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008080 timeout--;
8081 }
8082
8083 if (!timeout) {
8084 DEBUGOUT("MNG configuration cycle has not completed.\n");
8085 return -E1000_ERR_RESET;
8086 }
8087 break;
8088 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008089
8090 return E1000_SUCCESS;
8091}
8092
8093/***************************************************************************
8094 *
8095 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8096 * adapter or Eeprom access.
8097 *
8098 * hw: Struct containing variables accessed by shared code
8099 *
8100 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8101 * E1000_SUCCESS at any other case.
8102 *
8103 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008104static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008105e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8106{
8107 int32_t timeout;
8108 uint32_t swsm;
8109
8110 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8111
Auke Kok8fc897b2006-08-28 14:56:16 -07008112 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008113 return E1000_SUCCESS;
8114
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008115 if (hw->mac_type == e1000_80003es2lan) {
8116 /* Get the SW semaphore. */
8117 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8118 return -E1000_ERR_EEPROM;
8119 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008120
8121 /* Get the FW semaphore. */
8122 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008123 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008124 swsm = E1000_READ_REG(hw, SWSM);
8125 swsm |= E1000_SWSM_SWESMBI;
8126 E1000_WRITE_REG(hw, SWSM, swsm);
8127 /* if we managed to set the bit we got the semaphore. */
8128 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008129 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008130 break;
8131
8132 udelay(50);
8133 timeout--;
8134 }
8135
Auke Kok8fc897b2006-08-28 14:56:16 -07008136 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008137 /* Release semaphores */
8138 e1000_put_hw_eeprom_semaphore(hw);
8139 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8140 return -E1000_ERR_EEPROM;
8141 }
8142
8143 return E1000_SUCCESS;
8144}
8145
8146/***************************************************************************
8147 * This function clears HW semaphore bits.
8148 *
8149 * hw: Struct containing variables accessed by shared code
8150 *
8151 * returns: - None.
8152 *
8153 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008154static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008155e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8156{
8157 uint32_t swsm;
8158
8159 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8160
Auke Kok8fc897b2006-08-28 14:56:16 -07008161 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008162 return;
8163
8164 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008165 if (hw->mac_type == e1000_80003es2lan) {
8166 /* Release both semaphores. */
8167 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8168 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008169 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008170 E1000_WRITE_REG(hw, SWSM, swsm);
8171}
8172
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008173/***************************************************************************
8174 *
8175 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8176 *
8177 * hw: Struct containing variables accessed by shared code
8178 *
8179 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8180 * E1000_SUCCESS at any other case.
8181 *
8182 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008183static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008184e1000_get_software_semaphore(struct e1000_hw *hw)
8185{
8186 int32_t timeout = hw->eeprom.word_size + 1;
8187 uint32_t swsm;
8188
8189 DEBUGFUNC("e1000_get_software_semaphore");
8190
8191 if (hw->mac_type != e1000_80003es2lan)
8192 return E1000_SUCCESS;
8193
Auke Kok8fc897b2006-08-28 14:56:16 -07008194 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008195 swsm = E1000_READ_REG(hw, SWSM);
8196 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008197 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008198 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008199 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008200 timeout--;
8201 }
8202
Auke Kok8fc897b2006-08-28 14:56:16 -07008203 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008204 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8205 return -E1000_ERR_RESET;
8206 }
8207
8208 return E1000_SUCCESS;
8209}
8210
8211/***************************************************************************
8212 *
8213 * Release semaphore bit (SMBI).
8214 *
8215 * hw: Struct containing variables accessed by shared code
8216 *
8217 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008218static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008219e1000_release_software_semaphore(struct e1000_hw *hw)
8220{
8221 uint32_t swsm;
8222
8223 DEBUGFUNC("e1000_release_software_semaphore");
8224
8225 if (hw->mac_type != e1000_80003es2lan)
8226 return;
8227
8228 swsm = E1000_READ_REG(hw, SWSM);
8229 /* Release the SW semaphores.*/
8230 swsm &= ~E1000_SWSM_SMBI;
8231 E1000_WRITE_REG(hw, SWSM, swsm);
8232}
8233
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008234/******************************************************************************
8235 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8236 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8237 * the caller to figure out how to deal with it.
8238 *
8239 * hw - Struct containing variables accessed by shared code
8240 *
8241 * returns: - E1000_BLK_PHY_RESET
8242 * E1000_SUCCESS
8243 *
8244 *****************************************************************************/
8245int32_t
8246e1000_check_phy_reset_block(struct e1000_hw *hw)
8247{
8248 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008249 uint32_t fwsm = 0;
8250
8251 if (hw->mac_type == e1000_ich8lan) {
8252 fwsm = E1000_READ_REG(hw, FWSM);
8253 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8254 : E1000_BLK_PHY_RESET;
8255 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008256
8257 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008258 manc = E1000_READ_REG(hw, MANC);
8259 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8260 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8261}
8262
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008263static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008264e1000_arc_subsystem_valid(struct e1000_hw *hw)
8265{
8266 uint32_t fwsm;
8267
8268 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8269 * may not be provided a DMA clock when no manageability features are
8270 * enabled. We do not want to perform any reads/writes to these registers
8271 * if this is the case. We read FWSM to determine the manageability mode.
8272 */
8273 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008274 case e1000_82571:
8275 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008276 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008277 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008278 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008279 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008280 return TRUE;
8281 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008282 case e1000_ich8lan:
8283 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008284 default:
8285 break;
8286 }
8287 return FALSE;
8288}
8289
8290
Auke Kokd37ea5d2006-06-27 09:08:17 -07008291/******************************************************************************
8292 * Configure PCI-Ex no-snoop
8293 *
8294 * hw - Struct containing variables accessed by shared code.
8295 * no_snoop - Bitmap of no-snoop events.
8296 *
8297 * returns: E1000_SUCCESS
8298 *
8299 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008300static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008301e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8302{
8303 uint32_t gcr_reg = 0;
8304
8305 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8306
8307 if (hw->bus_type == e1000_bus_type_unknown)
8308 e1000_get_bus_info(hw);
8309
8310 if (hw->bus_type != e1000_bus_type_pci_express)
8311 return E1000_SUCCESS;
8312
8313 if (no_snoop) {
8314 gcr_reg = E1000_READ_REG(hw, GCR);
8315 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8316 gcr_reg |= no_snoop;
8317 E1000_WRITE_REG(hw, GCR, gcr_reg);
8318 }
8319 if (hw->mac_type == e1000_ich8lan) {
8320 uint32_t ctrl_ext;
8321
8322 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8323
8324 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8325 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8326 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8327 }
8328
8329 return E1000_SUCCESS;
8330}
8331
8332/***************************************************************************
8333 *
8334 * Get software semaphore FLAG bit (SWFLAG).
8335 * SWFLAG is used to synchronize the access to all shared resource between
8336 * SW, FW and HW.
8337 *
8338 * hw: Struct containing variables accessed by shared code
8339 *
8340 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008341static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008342e1000_get_software_flag(struct e1000_hw *hw)
8343{
8344 int32_t timeout = PHY_CFG_TIMEOUT;
8345 uint32_t extcnf_ctrl;
8346
8347 DEBUGFUNC("e1000_get_software_flag");
8348
8349 if (hw->mac_type == e1000_ich8lan) {
8350 while (timeout) {
8351 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8352 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8353 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8354
8355 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8356 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8357 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008358 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008359 timeout--;
8360 }
8361
8362 if (!timeout) {
8363 DEBUGOUT("FW or HW locks the resource too long.\n");
8364 return -E1000_ERR_CONFIG;
8365 }
8366 }
8367
8368 return E1000_SUCCESS;
8369}
8370
8371/***************************************************************************
8372 *
8373 * Release software semaphore FLAG bit (SWFLAG).
8374 * SWFLAG is used to synchronize the access to all shared resource between
8375 * SW, FW and HW.
8376 *
8377 * hw: Struct containing variables accessed by shared code
8378 *
8379 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008380static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008381e1000_release_software_flag(struct e1000_hw *hw)
8382{
8383 uint32_t extcnf_ctrl;
8384
8385 DEBUGFUNC("e1000_release_software_flag");
8386
8387 if (hw->mac_type == e1000_ich8lan) {
8388 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8389 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8390 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8391 }
8392
8393 return;
8394}
8395
8396/***************************************************************************
8397 *
8398 * Disable dynamic power down mode in ife PHY.
8399 * It can be used to workaround band-gap problem.
8400 *
8401 * hw: Struct containing variables accessed by shared code
8402 *
8403 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008404#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008405int32_t
8406e1000_ife_disable_dynamic_power_down(struct e1000_hw *hw)
8407{
8408 uint16_t phy_data;
8409 int32_t ret_val = E1000_SUCCESS;
8410
8411 DEBUGFUNC("e1000_ife_disable_dynamic_power_down");
8412
8413 if (hw->phy_type == e1000_phy_ife) {
8414 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8415 if (ret_val)
8416 return ret_val;
8417
8418 phy_data |= IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8419 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8420 }
8421
8422 return ret_val;
8423}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008424#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008425
8426/***************************************************************************
8427 *
8428 * Enable dynamic power down mode in ife PHY.
8429 * It can be used to workaround band-gap problem.
8430 *
8431 * hw: Struct containing variables accessed by shared code
8432 *
8433 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008434#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008435int32_t
8436e1000_ife_enable_dynamic_power_down(struct e1000_hw *hw)
8437{
8438 uint16_t phy_data;
8439 int32_t ret_val = E1000_SUCCESS;
8440
8441 DEBUGFUNC("e1000_ife_enable_dynamic_power_down");
8442
8443 if (hw->phy_type == e1000_phy_ife) {
8444 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8445 if (ret_val)
8446 return ret_val;
8447
8448 phy_data &= ~IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8449 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8450 }
8451
8452 return ret_val;
8453}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008454#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008455
8456/******************************************************************************
8457 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8458 * register.
8459 *
8460 * hw - Struct containing variables accessed by shared code
8461 * offset - offset of word in the EEPROM to read
8462 * data - word read from the EEPROM
8463 * words - number of words to read
8464 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008465static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008466e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8467 uint16_t *data)
8468{
8469 int32_t error = E1000_SUCCESS;
8470 uint32_t flash_bank = 0;
8471 uint32_t act_offset = 0;
8472 uint32_t bank_offset = 0;
8473 uint16_t word = 0;
8474 uint16_t i = 0;
8475
8476 /* We need to know which is the valid flash bank. In the event
8477 * that we didn't allocate eeprom_shadow_ram, we may not be
8478 * managing flash_bank. So it cannot be trusted and needs
8479 * to be updated with each read.
8480 */
8481 /* Value of bit 22 corresponds to the flash bank we're on. */
8482 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8483
8484 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8485 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8486
8487 error = e1000_get_software_flag(hw);
8488 if (error != E1000_SUCCESS)
8489 return error;
8490
8491 for (i = 0; i < words; i++) {
8492 if (hw->eeprom_shadow_ram != NULL &&
8493 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8494 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8495 } else {
8496 /* The NVM part needs a byte offset, hence * 2 */
8497 act_offset = bank_offset + ((offset + i) * 2);
8498 error = e1000_read_ich8_word(hw, act_offset, &word);
8499 if (error != E1000_SUCCESS)
8500 break;
8501 data[i] = word;
8502 }
8503 }
8504
8505 e1000_release_software_flag(hw);
8506
8507 return error;
8508}
8509
8510/******************************************************************************
8511 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8512 * register. Actually, writes are written to the shadow ram cache in the hw
8513 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8514 * the NVM, which occurs when the NVM checksum is updated.
8515 *
8516 * hw - Struct containing variables accessed by shared code
8517 * offset - offset of word in the EEPROM to write
8518 * words - number of words to write
8519 * data - words to write to the EEPROM
8520 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008521static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008522e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8523 uint16_t *data)
8524{
8525 uint32_t i = 0;
8526 int32_t error = E1000_SUCCESS;
8527
8528 error = e1000_get_software_flag(hw);
8529 if (error != E1000_SUCCESS)
8530 return error;
8531
8532 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8533 * allocated. Subsequent reads to the modified words are read from
8534 * this cached structure as well. Writes will only go into this
8535 * cached structure unless it's followed by a call to
8536 * e1000_update_eeprom_checksum() where it will commit the changes
8537 * and clear the "modified" field.
8538 */
8539 if (hw->eeprom_shadow_ram != NULL) {
8540 for (i = 0; i < words; i++) {
8541 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8542 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8543 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8544 } else {
8545 error = -E1000_ERR_EEPROM;
8546 break;
8547 }
8548 }
8549 } else {
8550 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8551 * as they don't perform any NVM writes. An attempt in doing so
8552 * will result in this error.
8553 */
8554 error = -E1000_ERR_EEPROM;
8555 }
8556
8557 e1000_release_software_flag(hw);
8558
8559 return error;
8560}
8561
8562/******************************************************************************
8563 * This function does initial flash setup so that a new read/write/erase cycle
8564 * can be started.
8565 *
8566 * hw - The pointer to the hw structure
8567 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008568static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008569e1000_ich8_cycle_init(struct e1000_hw *hw)
8570{
8571 union ich8_hws_flash_status hsfsts;
8572 int32_t error = E1000_ERR_EEPROM;
8573 int32_t i = 0;
8574
8575 DEBUGFUNC("e1000_ich8_cycle_init");
8576
8577 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8578
8579 /* May be check the Flash Des Valid bit in Hw status */
8580 if (hsfsts.hsf_status.fldesvalid == 0) {
8581 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8582 return error;
8583 }
8584
8585 /* Clear FCERR in Hw status by writing 1 */
8586 /* Clear DAEL in Hw status by writing a 1 */
8587 hsfsts.hsf_status.flcerr = 1;
8588 hsfsts.hsf_status.dael = 1;
8589
8590 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8591
8592 /* Either we should have a hardware SPI cycle in progress bit to check
8593 * against, in order to start a new cycle or FDONE bit should be changed
8594 * in the hardware so that it is 1 after harware reset, which can then be
8595 * used as an indication whether a cycle is in progress or has been
8596 * completed .. we should also have some software semaphore mechanism to
8597 * guard FDONE or the cycle in progress bit so that two threads access to
8598 * those bits can be sequentiallized or a way so that 2 threads dont
8599 * start the cycle at the same time */
8600
8601 if (hsfsts.hsf_status.flcinprog == 0) {
8602 /* There is no cycle running at present, so we can start a cycle */
8603 /* Begin by setting Flash Cycle Done. */
8604 hsfsts.hsf_status.flcdone = 1;
8605 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8606 error = E1000_SUCCESS;
8607 } else {
8608 /* otherwise poll for sometime so the current cycle has a chance
8609 * to end before giving up. */
8610 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8611 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8612 if (hsfsts.hsf_status.flcinprog == 0) {
8613 error = E1000_SUCCESS;
8614 break;
8615 }
8616 udelay(1);
8617 }
8618 if (error == E1000_SUCCESS) {
8619 /* Successful in waiting for previous cycle to timeout,
8620 * now set the Flash Cycle Done. */
8621 hsfsts.hsf_status.flcdone = 1;
8622 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8623 } else {
8624 DEBUGOUT("Flash controller busy, cannot get access");
8625 }
8626 }
8627 return error;
8628}
8629
8630/******************************************************************************
8631 * This function starts a flash cycle and waits for its completion
8632 *
8633 * hw - The pointer to the hw structure
8634 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008635static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008636e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8637{
8638 union ich8_hws_flash_ctrl hsflctl;
8639 union ich8_hws_flash_status hsfsts;
8640 int32_t error = E1000_ERR_EEPROM;
8641 uint32_t i = 0;
8642
8643 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8644 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8645 hsflctl.hsf_ctrl.flcgo = 1;
8646 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8647
8648 /* wait till FDONE bit is set to 1 */
8649 do {
8650 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8651 if (hsfsts.hsf_status.flcdone == 1)
8652 break;
8653 udelay(1);
8654 i++;
8655 } while (i < timeout);
8656 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8657 error = E1000_SUCCESS;
8658 }
8659 return error;
8660}
8661
8662/******************************************************************************
8663 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8664 *
8665 * hw - The pointer to the hw structure
8666 * index - The index of the byte or word to read.
8667 * size - Size of data to read, 1=byte 2=word
8668 * data - Pointer to the word to store the value read.
8669 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008670static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008671e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8672 uint32_t size, uint16_t* data)
8673{
8674 union ich8_hws_flash_status hsfsts;
8675 union ich8_hws_flash_ctrl hsflctl;
8676 uint32_t flash_linear_address;
8677 uint32_t flash_data = 0;
8678 int32_t error = -E1000_ERR_EEPROM;
8679 int32_t count = 0;
8680
8681 DEBUGFUNC("e1000_read_ich8_data");
8682
8683 if (size < 1 || size > 2 || data == 0x0 ||
8684 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8685 return error;
8686
8687 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8688 hw->flash_base_addr;
8689
8690 do {
8691 udelay(1);
8692 /* Steps */
8693 error = e1000_ich8_cycle_init(hw);
8694 if (error != E1000_SUCCESS)
8695 break;
8696
8697 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8698 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8699 hsflctl.hsf_ctrl.fldbcount = size - 1;
8700 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8701 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8702
8703 /* Write the last 24 bits of index into Flash Linear address field in
8704 * Flash Address */
8705 /* TODO: TBD maybe check the index against the size of flash */
8706
8707 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8708
8709 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8710
8711 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8712 * sequence a few more times, else read in (shift in) the Flash Data0,
8713 * the order is least significant byte first msb to lsb */
8714 if (error == E1000_SUCCESS) {
8715 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8716 if (size == 1) {
8717 *data = (uint8_t)(flash_data & 0x000000FF);
8718 } else if (size == 2) {
8719 *data = (uint16_t)(flash_data & 0x0000FFFF);
8720 }
8721 break;
8722 } else {
8723 /* If we've gotten here, then things are probably completely hosed,
8724 * but if the error condition is detected, it won't hurt to give
8725 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8726 */
8727 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8728 if (hsfsts.hsf_status.flcerr == 1) {
8729 /* Repeat for some time before giving up. */
8730 continue;
8731 } else if (hsfsts.hsf_status.flcdone == 0) {
8732 DEBUGOUT("Timeout error - flash cycle did not complete.");
8733 break;
8734 }
8735 }
8736 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8737
8738 return error;
8739}
8740
8741/******************************************************************************
8742 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8743 *
8744 * hw - The pointer to the hw structure
8745 * index - The index of the byte/word to read.
8746 * size - Size of data to read, 1=byte 2=word
8747 * data - The byte(s) to write to the NVM.
8748 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008749static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008750e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8751 uint16_t data)
8752{
8753 union ich8_hws_flash_status hsfsts;
8754 union ich8_hws_flash_ctrl hsflctl;
8755 uint32_t flash_linear_address;
8756 uint32_t flash_data = 0;
8757 int32_t error = -E1000_ERR_EEPROM;
8758 int32_t count = 0;
8759
8760 DEBUGFUNC("e1000_write_ich8_data");
8761
8762 if (size < 1 || size > 2 || data > size * 0xff ||
8763 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8764 return error;
8765
8766 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8767 hw->flash_base_addr;
8768
8769 do {
8770 udelay(1);
8771 /* Steps */
8772 error = e1000_ich8_cycle_init(hw);
8773 if (error != E1000_SUCCESS)
8774 break;
8775
8776 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8777 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8778 hsflctl.hsf_ctrl.fldbcount = size -1;
8779 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8780 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8781
8782 /* Write the last 24 bits of index into Flash Linear address field in
8783 * Flash Address */
8784 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8785
8786 if (size == 1)
8787 flash_data = (uint32_t)data & 0x00FF;
8788 else
8789 flash_data = (uint32_t)data;
8790
8791 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8792
8793 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8794 * sequence a few more times else done */
8795 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8796 if (error == E1000_SUCCESS) {
8797 break;
8798 } else {
8799 /* If we're here, then things are most likely completely hosed,
8800 * but if the error condition is detected, it won't hurt to give
8801 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8802 */
8803 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8804 if (hsfsts.hsf_status.flcerr == 1) {
8805 /* Repeat for some time before giving up. */
8806 continue;
8807 } else if (hsfsts.hsf_status.flcdone == 0) {
8808 DEBUGOUT("Timeout error - flash cycle did not complete.");
8809 break;
8810 }
8811 }
8812 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8813
8814 return error;
8815}
8816
8817/******************************************************************************
8818 * Reads a single byte from the NVM using the ICH8 flash access registers.
8819 *
8820 * hw - pointer to e1000_hw structure
8821 * index - The index of the byte to read.
8822 * data - Pointer to a byte to store the value read.
8823 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008824static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008825e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8826{
8827 int32_t status = E1000_SUCCESS;
8828 uint16_t word = 0;
8829
8830 status = e1000_read_ich8_data(hw, index, 1, &word);
8831 if (status == E1000_SUCCESS) {
8832 *data = (uint8_t)word;
8833 }
8834
8835 return status;
8836}
8837
8838/******************************************************************************
8839 * Writes a single byte to the NVM using the ICH8 flash access registers.
8840 * Performs verification by reading back the value and then going through
8841 * a retry algorithm before giving up.
8842 *
8843 * hw - pointer to e1000_hw structure
8844 * index - The index of the byte to write.
8845 * byte - The byte to write to the NVM.
8846 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008847static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008848e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8849{
8850 int32_t error = E1000_SUCCESS;
8851 int32_t program_retries;
8852 uint8_t temp_byte;
8853
8854 e1000_write_ich8_byte(hw, index, byte);
8855 udelay(100);
8856
8857 for (program_retries = 0; program_retries < 100; program_retries++) {
8858 e1000_read_ich8_byte(hw, index, &temp_byte);
8859 if (temp_byte == byte)
8860 break;
8861 udelay(10);
8862 e1000_write_ich8_byte(hw, index, byte);
8863 udelay(100);
8864 }
8865 if (program_retries == 100)
8866 error = E1000_ERR_EEPROM;
8867
8868 return error;
8869}
8870
8871/******************************************************************************
8872 * Writes a single byte to the NVM using the ICH8 flash access registers.
8873 *
8874 * hw - pointer to e1000_hw structure
8875 * index - The index of the byte to read.
8876 * data - The byte to write to the NVM.
8877 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008878static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008879e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8880{
8881 int32_t status = E1000_SUCCESS;
8882 uint16_t word = (uint16_t)data;
8883
8884 status = e1000_write_ich8_data(hw, index, 1, word);
8885
8886 return status;
8887}
8888
8889/******************************************************************************
8890 * Reads a word from the NVM using the ICH8 flash access registers.
8891 *
8892 * hw - pointer to e1000_hw structure
8893 * index - The starting byte index of the word to read.
8894 * data - Pointer to a word to store the value read.
8895 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008896static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008897e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8898{
8899 int32_t status = E1000_SUCCESS;
8900 status = e1000_read_ich8_data(hw, index, 2, data);
8901 return status;
8902}
8903
8904/******************************************************************************
8905 * Writes a word to the NVM using the ICH8 flash access registers.
8906 *
8907 * hw - pointer to e1000_hw structure
8908 * index - The starting byte index of the word to read.
8909 * data - The word to write to the NVM.
8910 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008911#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008912int32_t
8913e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8914{
8915 int32_t status = E1000_SUCCESS;
8916 status = e1000_write_ich8_data(hw, index, 2, data);
8917 return status;
8918}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008919#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008920
8921/******************************************************************************
8922 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8923 * segment N is 4096 * N + flash_reg_addr.
8924 *
8925 * hw - pointer to e1000_hw structure
8926 * segment - 0 for first segment, 1 for second segment, etc.
8927 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008928static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008929e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8930{
8931 union ich8_hws_flash_status hsfsts;
8932 union ich8_hws_flash_ctrl hsflctl;
8933 uint32_t flash_linear_address;
8934 int32_t count = 0;
8935 int32_t error = E1000_ERR_EEPROM;
8936 int32_t iteration, seg_size;
8937 int32_t sector_size;
8938 int32_t j = 0;
8939 int32_t error_flag = 0;
8940
8941 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8942
8943 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8944 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8945 * consecutive sectors. The start index for the nth Hw sector can be
8946 * calculated as = segment * 4096 + n * 256
8947 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8948 * The start index for the nth Hw sector can be calculated
8949 * as = segment * 4096
8950 * 10: Error condition
8951 * 11: The Hw sector size is much bigger than the size asked to
8952 * erase...error condition */
8953 if (hsfsts.hsf_status.berasesz == 0x0) {
8954 /* Hw sector size 256 */
8955 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256;
8956 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8957 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8958 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K;
8959 iteration = 1;
8960 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8961 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K;
8962 iteration = 1;
8963 } else {
8964 return error;
8965 }
8966
8967 for (j = 0; j < iteration ; j++) {
8968 do {
8969 count++;
8970 /* Steps */
8971 error = e1000_ich8_cycle_init(hw);
8972 if (error != E1000_SUCCESS) {
8973 error_flag = 1;
8974 break;
8975 }
8976
8977 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8978 * Control */
8979 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8980 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8981 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8982
8983 /* Write the last 24 bits of an index within the block into Flash
8984 * Linear address field in Flash Address. This probably needs to
8985 * be calculated here based off the on-chip segment size and the
8986 * software segment size assumed (4K) */
8987 /* TBD */
8988 flash_linear_address = segment * sector_size + j * seg_size;
8989 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8990 flash_linear_address += hw->flash_base_addr;
8991
8992 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8993
8994 error = e1000_ich8_flash_cycle(hw, 1000000);
8995 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8996 * sequence a few more times else Done */
8997 if (error == E1000_SUCCESS) {
8998 break;
8999 } else {
9000 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
9001 if (hsfsts.hsf_status.flcerr == 1) {
9002 /* repeat for some time before giving up */
9003 continue;
9004 } else if (hsfsts.hsf_status.flcdone == 0) {
9005 error_flag = 1;
9006 break;
9007 }
9008 }
9009 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
9010 if (error_flag == 1)
9011 break;
9012 }
9013 if (error_flag != 1)
9014 error = E1000_SUCCESS;
9015 return error;
9016}
9017
9018/******************************************************************************
9019 *
9020 * Reverse duplex setting without breaking the link.
9021 *
9022 * hw: Struct containing variables accessed by shared code
9023 *
9024 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07009025#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07009026int32_t
9027e1000_duplex_reversal(struct e1000_hw *hw)
9028{
9029 int32_t ret_val;
9030 uint16_t phy_data;
9031
9032 if (hw->phy_type != e1000_phy_igp_3)
9033 return E1000_SUCCESS;
9034
9035 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
9036 if (ret_val)
9037 return ret_val;
9038
9039 phy_data ^= MII_CR_FULL_DUPLEX;
9040
9041 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
9042 if (ret_val)
9043 return ret_val;
9044
9045 ret_val = e1000_read_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, &phy_data);
9046 if (ret_val)
9047 return ret_val;
9048
9049 phy_data |= IGP3_PHY_MISC_DUPLEX_MANUAL_SET;
9050 ret_val = e1000_write_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, phy_data);
9051
9052 return ret_val;
9053}
Adrian Bunke4c780b2006-08-14 23:00:10 -07009054#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07009055
Adrian Bunke4c780b2006-08-14 23:00:10 -07009056static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07009057e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9058 uint32_t cnf_base_addr, uint32_t cnf_size)
9059{
9060 uint32_t ret_val = E1000_SUCCESS;
9061 uint16_t word_addr, reg_data, reg_addr;
9062 uint16_t i;
9063
9064 /* cnf_base_addr is in DWORD */
9065 word_addr = (uint16_t)(cnf_base_addr << 1);
9066
9067 /* cnf_size is returned in size of dwords */
9068 for (i = 0; i < cnf_size; i++) {
9069 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
9070 if (ret_val)
9071 return ret_val;
9072
9073 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
9074 if (ret_val)
9075 return ret_val;
9076
9077 ret_val = e1000_get_software_flag(hw);
9078 if (ret_val != E1000_SUCCESS)
9079 return ret_val;
9080
9081 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
9082
9083 e1000_release_software_flag(hw);
9084 }
9085
9086 return ret_val;
9087}
9088
9089
Adrian Bunke4c780b2006-08-14 23:00:10 -07009090static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07009091e1000_init_lcd_from_nvm(struct e1000_hw *hw)
9092{
9093 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
9094
9095 if (hw->phy_type != e1000_phy_igp_3)
9096 return E1000_SUCCESS;
9097
9098 /* Check if SW needs configure the PHY */
9099 reg_data = E1000_READ_REG(hw, FEXTNVM);
9100 if (!(reg_data & FEXTNVM_SW_CONFIG))
9101 return E1000_SUCCESS;
9102
9103 /* Wait for basic configuration completes before proceeding*/
9104 loop = 0;
9105 do {
9106 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9107 udelay(100);
9108 loop++;
9109 } while ((!reg_data) && (loop < 50));
9110
9111 /* Clear the Init Done bit for the next init event */
9112 reg_data = E1000_READ_REG(hw, STATUS);
9113 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9114 E1000_WRITE_REG(hw, STATUS, reg_data);
9115
9116 /* Make sure HW does not configure LCD from PHY extended configuration
9117 before SW configuration */
9118 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9119 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9120 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9121 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9122 cnf_size >>= 16;
9123 if (cnf_size) {
9124 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9125 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9126 /* cnf_base_addr is in DWORD */
9127 cnf_base_addr >>= 16;
9128
9129 /* Configure LCD from extended configuration region. */
9130 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9131 cnf_size);
9132 if (ret_val)
9133 return ret_val;
9134 }
9135 }
9136
9137 return E1000_SUCCESS;
9138}
9139
9140
Malli Chilakala2d7edb92005-04-28 19:43:52 -07009141