blob: 784f9505864a0a9d9a0a9057d8c3a3aff5b7d40a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
Auke Kok3d41e302006-04-14 19:05:31 -07004 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070025 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
28*******************************************************************************/
29
30/* e1000_hw.c
31 * Shared functions for accessing and configuring the MAC
32 */
33
34#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);
74static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
75static 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)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800104static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw);
105static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107/* IGP cable length table */
108static const
109uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
110 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
111 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
112 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
113 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
114 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
115 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
116 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
117 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
118
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700119static const
120uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400121 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
122 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
123 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
124 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
125 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
126 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
127 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
128 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/******************************************************************************
132 * Set the phy type member in the hw struct.
133 *
134 * hw - Struct containing variables accessed by shared code
135 *****************************************************************************/
136int32_t
137e1000_set_phy_type(struct e1000_hw *hw)
138{
139 DEBUGFUNC("e1000_set_phy_type");
140
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700141 if(hw->mac_type == e1000_undefined)
142 return -E1000_ERR_PHY_TYPE;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 switch(hw->phy_id) {
145 case M88E1000_E_PHY_ID:
146 case M88E1000_I_PHY_ID:
147 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700148 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 hw->phy_type = e1000_phy_m88;
150 break;
151 case IGP01E1000_I_PHY_ID:
152 if(hw->mac_type == e1000_82541 ||
153 hw->mac_type == e1000_82541_rev_2 ||
154 hw->mac_type == e1000_82547 ||
155 hw->mac_type == e1000_82547_rev_2) {
156 hw->phy_type = e1000_phy_igp;
157 break;
158 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800159 case GG82563_E_PHY_ID:
160 if (hw->mac_type == e1000_80003es2lan) {
161 hw->phy_type = e1000_phy_gg82563;
162 break;
163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 /* Fall Through */
165 default:
166 /* Should never have loaded on this device */
167 hw->phy_type = e1000_phy_undefined;
168 return -E1000_ERR_PHY_TYPE;
169 }
170
171 return E1000_SUCCESS;
172}
173
174/******************************************************************************
175 * IGP phy init script - initializes the GbE PHY
176 *
177 * hw - Struct containing variables accessed by shared code
178 *****************************************************************************/
179static void
180e1000_phy_init_script(struct e1000_hw *hw)
181{
182 uint32_t ret_val;
183 uint16_t phy_saved_data;
184
185 DEBUGFUNC("e1000_phy_init_script");
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 if(hw->phy_init_script) {
188 msec_delay(20);
189
190 /* Save off the current value of register 0x2F5B to be restored at
191 * the end of this routine. */
192 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
193
194 /* Disabled the PHY transmitter */
195 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
196
197 msec_delay(20);
198
199 e1000_write_phy_reg(hw,0x0000,0x0140);
200
201 msec_delay(5);
202
203 switch(hw->mac_type) {
204 case e1000_82541:
205 case e1000_82547:
206 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
207
208 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
209
210 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
211
212 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
213
214 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
215
216 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
217
218 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
219
220 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
221
222 e1000_write_phy_reg(hw, 0x2010, 0x0008);
223 break;
224
225 case e1000_82541_rev_2:
226 case e1000_82547_rev_2:
227 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
228 break;
229 default:
230 break;
231 }
232
233 e1000_write_phy_reg(hw, 0x0000, 0x3300);
234
235 msec_delay(20);
236
237 /* Now enable the transmitter */
238 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
239
240 if(hw->mac_type == e1000_82547) {
241 uint16_t fused, fine, coarse;
242
243 /* Move to analog registers page */
244 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
245
246 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
247 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
248
249 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
250 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
251
252 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
253 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
254 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
255 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
256 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
257
258 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
259 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
260 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
261
262 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
263 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
264 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
265 }
266 }
267 }
268}
269
270/******************************************************************************
271 * Set the mac type member in the hw struct.
272 *
273 * hw - Struct containing variables accessed by shared code
274 *****************************************************************************/
275int32_t
276e1000_set_mac_type(struct e1000_hw *hw)
277{
278 DEBUGFUNC("e1000_set_mac_type");
279
280 switch (hw->device_id) {
281 case E1000_DEV_ID_82542:
282 switch (hw->revision_id) {
283 case E1000_82542_2_0_REV_ID:
284 hw->mac_type = e1000_82542_rev2_0;
285 break;
286 case E1000_82542_2_1_REV_ID:
287 hw->mac_type = e1000_82542_rev2_1;
288 break;
289 default:
290 /* Invalid 82542 revision ID */
291 return -E1000_ERR_MAC_TYPE;
292 }
293 break;
294 case E1000_DEV_ID_82543GC_FIBER:
295 case E1000_DEV_ID_82543GC_COPPER:
296 hw->mac_type = e1000_82543;
297 break;
298 case E1000_DEV_ID_82544EI_COPPER:
299 case E1000_DEV_ID_82544EI_FIBER:
300 case E1000_DEV_ID_82544GC_COPPER:
301 case E1000_DEV_ID_82544GC_LOM:
302 hw->mac_type = e1000_82544;
303 break;
304 case E1000_DEV_ID_82540EM:
305 case E1000_DEV_ID_82540EM_LOM:
306 case E1000_DEV_ID_82540EP:
307 case E1000_DEV_ID_82540EP_LOM:
308 case E1000_DEV_ID_82540EP_LP:
309 hw->mac_type = e1000_82540;
310 break;
311 case E1000_DEV_ID_82545EM_COPPER:
312 case E1000_DEV_ID_82545EM_FIBER:
313 hw->mac_type = e1000_82545;
314 break;
315 case E1000_DEV_ID_82545GM_COPPER:
316 case E1000_DEV_ID_82545GM_FIBER:
317 case E1000_DEV_ID_82545GM_SERDES:
318 hw->mac_type = e1000_82545_rev_3;
319 break;
320 case E1000_DEV_ID_82546EB_COPPER:
321 case E1000_DEV_ID_82546EB_FIBER:
322 case E1000_DEV_ID_82546EB_QUAD_COPPER:
323 hw->mac_type = e1000_82546;
324 break;
325 case E1000_DEV_ID_82546GB_COPPER:
326 case E1000_DEV_ID_82546GB_FIBER:
327 case E1000_DEV_ID_82546GB_SERDES:
328 case E1000_DEV_ID_82546GB_PCIE:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800329 case E1000_DEV_ID_82546GB_QUAD_COPPER:
330 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 hw->mac_type = e1000_82546_rev_3;
332 break;
333 case E1000_DEV_ID_82541EI:
334 case E1000_DEV_ID_82541EI_MOBILE:
335 hw->mac_type = e1000_82541;
336 break;
337 case E1000_DEV_ID_82541ER:
338 case E1000_DEV_ID_82541GI:
339 case E1000_DEV_ID_82541GI_LF:
340 case E1000_DEV_ID_82541GI_MOBILE:
341 hw->mac_type = e1000_82541_rev_2;
342 break;
343 case E1000_DEV_ID_82547EI:
344 hw->mac_type = e1000_82547;
345 break;
346 case E1000_DEV_ID_82547GI:
347 hw->mac_type = e1000_82547_rev_2;
348 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400349 case E1000_DEV_ID_82571EB_COPPER:
350 case E1000_DEV_ID_82571EB_FIBER:
351 case E1000_DEV_ID_82571EB_SERDES:
352 hw->mac_type = e1000_82571;
353 break;
354 case E1000_DEV_ID_82572EI_COPPER:
355 case E1000_DEV_ID_82572EI_FIBER:
356 case E1000_DEV_ID_82572EI_SERDES:
357 hw->mac_type = e1000_82572;
358 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700359 case E1000_DEV_ID_82573E:
360 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400361 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700362 hw->mac_type = e1000_82573;
363 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800364 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
365 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
366 hw->mac_type = e1000_80003es2lan;
367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 default:
369 /* Should never have loaded on this device */
370 return -E1000_ERR_MAC_TYPE;
371 }
372
373 switch(hw->mac_type) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800374 case e1000_80003es2lan:
375 hw->swfw_sync_present = TRUE;
376 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400377 case e1000_82571:
378 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700379 case e1000_82573:
380 hw->eeprom_semaphore_present = TRUE;
381 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 case e1000_82541:
383 case e1000_82547:
384 case e1000_82541_rev_2:
385 case e1000_82547_rev_2:
386 hw->asf_firmware_present = TRUE;
387 break;
388 default:
389 break;
390 }
391
392 return E1000_SUCCESS;
393}
394
395/*****************************************************************************
396 * Set media type and TBI compatibility.
397 *
398 * hw - Struct containing variables accessed by shared code
399 * **************************************************************************/
400void
401e1000_set_media_type(struct e1000_hw *hw)
402{
403 uint32_t status;
404
405 DEBUGFUNC("e1000_set_media_type");
406
407 if(hw->mac_type != e1000_82543) {
408 /* tbi_compatibility is only valid on 82543 */
409 hw->tbi_compatibility_en = FALSE;
410 }
411
412 switch (hw->device_id) {
413 case E1000_DEV_ID_82545GM_SERDES:
414 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400415 case E1000_DEV_ID_82571EB_SERDES:
416 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800417 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 hw->media_type = e1000_media_type_internal_serdes;
419 break;
420 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700421 switch (hw->mac_type) {
422 case e1000_82542_rev2_0:
423 case e1000_82542_rev2_1:
424 hw->media_type = e1000_media_type_fiber;
425 break;
426 case e1000_82573:
427 /* The STATUS_TBIMODE bit is reserved or reused for the this
428 * device.
429 */
430 hw->media_type = e1000_media_type_copper;
431 break;
432 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700434 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 hw->media_type = e1000_media_type_fiber;
436 /* tbi_compatibility not valid on fiber */
437 hw->tbi_compatibility_en = FALSE;
438 } else {
439 hw->media_type = e1000_media_type_copper;
440 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700441 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443 }
444}
445
446/******************************************************************************
447 * Reset the transmit and receive units; mask and clear all interrupts.
448 *
449 * hw - Struct containing variables accessed by shared code
450 *****************************************************************************/
451int32_t
452e1000_reset_hw(struct e1000_hw *hw)
453{
454 uint32_t ctrl;
455 uint32_t ctrl_ext;
456 uint32_t icr;
457 uint32_t manc;
458 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700459 uint32_t timeout;
460 uint32_t extcnf_ctrl;
461 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 DEBUGFUNC("e1000_reset_hw");
464
465 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
466 if(hw->mac_type == e1000_82542_rev2_0) {
467 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
468 e1000_pci_clear_mwi(hw);
469 }
470
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700471 if(hw->bus_type == e1000_bus_type_pci_express) {
472 /* Prevent the PCI-E bus from sticking if there is no TLP connection
473 * on the last TLP read/write transaction when MAC is reset.
474 */
475 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
476 DEBUGOUT("PCI-E Master disable polling has failed.\n");
477 }
478 }
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 /* Clear interrupt mask to stop board from generating interrupts */
481 DEBUGOUT("Masking off all interrupts\n");
482 E1000_WRITE_REG(hw, IMC, 0xffffffff);
483
484 /* Disable the Transmit and Receive units. Then delay to allow
485 * any pending transactions to complete before we hit the MAC with
486 * the global reset.
487 */
488 E1000_WRITE_REG(hw, RCTL, 0);
489 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
490 E1000_WRITE_FLUSH(hw);
491
492 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
493 hw->tbi_compatibility_on = FALSE;
494
495 /* Delay to allow any outstanding PCI transactions to complete before
496 * resetting the device
497 */
498 msec_delay(10);
499
500 ctrl = E1000_READ_REG(hw, CTRL);
501
502 /* Must reset the PHY before resetting the MAC */
503 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700504 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 msec_delay(5);
506 }
507
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700508 /* Must acquire the MDIO ownership before MAC reset.
509 * Ownership defaults to firmware after a reset. */
510 if(hw->mac_type == e1000_82573) {
511 timeout = 10;
512
513 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
514 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
515
516 do {
517 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
518 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
519
520 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
521 break;
522 else
523 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
524
525 msec_delay(2);
526 timeout--;
527 } while(timeout);
528 }
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* Issue a global reset to the MAC. This will reset the chip's
531 * transmit, receive, DMA, and link units. It will not effect
532 * the current PCI configuration. The global reset bit is self-
533 * clearing, and should clear within a microsecond.
534 */
535 DEBUGOUT("Issuing a global reset to MAC\n");
536
537 switch(hw->mac_type) {
538 case e1000_82544:
539 case e1000_82540:
540 case e1000_82545:
541 case e1000_82546:
542 case e1000_82541:
543 case e1000_82541_rev_2:
544 /* These controllers can't ack the 64-bit write when issuing the
545 * reset, so use IO-mapping as a workaround to issue the reset */
546 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
547 break;
548 case e1000_82545_rev_3:
549 case e1000_82546_rev_3:
550 /* Reset is performed on a shadow of the control register */
551 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
552 break;
553 default:
554 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
555 break;
556 }
557
558 /* After MAC reset, force reload of EEPROM to restore power-on settings to
559 * device. Later controllers reload the EEPROM automatically, so just wait
560 * for reload to complete.
561 */
562 switch(hw->mac_type) {
563 case e1000_82542_rev2_0:
564 case e1000_82542_rev2_1:
565 case e1000_82543:
566 case e1000_82544:
567 /* Wait for reset to complete */
568 udelay(10);
569 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
570 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
571 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
572 E1000_WRITE_FLUSH(hw);
573 /* Wait for EEPROM reload */
574 msec_delay(2);
575 break;
576 case e1000_82541:
577 case e1000_82541_rev_2:
578 case e1000_82547:
579 case e1000_82547_rev_2:
580 /* Wait for EEPROM reload */
581 msec_delay(20);
582 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700583 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500584 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
585 udelay(10);
586 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
587 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
588 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
589 E1000_WRITE_FLUSH(hw);
590 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700591 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400592 case e1000_82571:
593 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800594 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700595 ret_val = e1000_get_auto_rd_done(hw);
596 if(ret_val)
597 /* We don't want to continue accessing MAC registers. */
598 return ret_val;
599 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 default:
601 /* Wait for EEPROM reload (it happens automatically) */
602 msec_delay(5);
603 break;
604 }
605
606 /* Disable HW ARPs on ASF enabled adapters */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700607 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 manc = E1000_READ_REG(hw, MANC);
609 manc &= ~(E1000_MANC_ARP_EN);
610 E1000_WRITE_REG(hw, MANC, manc);
611 }
612
613 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
614 e1000_phy_init_script(hw);
615
616 /* Configure activity LED after PHY reset */
617 led_ctrl = E1000_READ_REG(hw, LEDCTL);
618 led_ctrl &= IGP_ACTIVITY_LED_MASK;
619 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
620 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
621 }
622
623 /* Clear interrupt mask to stop board from generating interrupts */
624 DEBUGOUT("Masking off all interrupts\n");
625 E1000_WRITE_REG(hw, IMC, 0xffffffff);
626
627 /* Clear any pending interrupt events. */
628 icr = E1000_READ_REG(hw, ICR);
629
630 /* If MWI was previously enabled, reenable it. */
631 if(hw->mac_type == e1000_82542_rev2_0) {
632 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
633 e1000_pci_set_mwi(hw);
634 }
635
636 return E1000_SUCCESS;
637}
638
639/******************************************************************************
640 * Performs basic configuration of the adapter.
641 *
642 * hw - Struct containing variables accessed by shared code
643 *
644 * Assumes that the controller has previously been reset and is in a
645 * post-reset uninitialized state. Initializes the receive address registers,
646 * multicast table, and VLAN filter table. Calls routines to setup link
647 * configuration and flow control settings. Clears all on-chip counters. Leaves
648 * the transmit and receive units disabled and uninitialized.
649 *****************************************************************************/
650int32_t
651e1000_init_hw(struct e1000_hw *hw)
652{
653 uint32_t ctrl;
654 uint32_t i;
655 int32_t ret_val;
656 uint16_t pcix_cmd_word;
657 uint16_t pcix_stat_hi_word;
658 uint16_t cmd_mmrbc;
659 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700660 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800661 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800662 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 DEBUGFUNC("e1000_init_hw");
665
666 /* Initialize Identification LED */
667 ret_val = e1000_id_led_init(hw);
668 if(ret_val) {
669 DEBUGOUT("Error Initializing Identification LED\n");
670 return ret_val;
671 }
672
673 /* Set the media type and TBI compatibility */
674 e1000_set_media_type(hw);
675
676 /* Disabling VLAN filtering. */
677 DEBUGOUT("Initializing the IEEE VLAN\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700678 if (hw->mac_type < e1000_82545_rev_3)
679 E1000_WRITE_REG(hw, VET, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 e1000_clear_vfta(hw);
681
682 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
683 if(hw->mac_type == e1000_82542_rev2_0) {
684 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
685 e1000_pci_clear_mwi(hw);
686 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
687 E1000_WRITE_FLUSH(hw);
688 msec_delay(5);
689 }
690
691 /* Setup the receive address. This involves initializing all of the Receive
692 * Address Registers (RARs 0 - 15).
693 */
694 e1000_init_rx_addrs(hw);
695
696 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
697 if(hw->mac_type == e1000_82542_rev2_0) {
698 E1000_WRITE_REG(hw, RCTL, 0);
699 E1000_WRITE_FLUSH(hw);
700 msec_delay(1);
701 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
702 e1000_pci_set_mwi(hw);
703 }
704
705 /* Zero out the Multicast HASH table */
706 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700707 mta_size = E1000_MC_TBL_SIZE;
Auke Kok4ca213a2006-06-27 09:07:08 -0700708 for(i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700710 /* use write flush to prevent Memory Write Block (MWB) from
711 * occuring when accessing our register space */
712 E1000_WRITE_FLUSH(hw);
713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 /* Set the PCI priority bit correctly in the CTRL register. This
716 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700717 * gives equal priority to transmits and receives. Valid only on
718 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700720 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 ctrl = E1000_READ_REG(hw, CTRL);
722 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
723 }
724
725 switch(hw->mac_type) {
726 case e1000_82545_rev_3:
727 case e1000_82546_rev_3:
728 break;
729 default:
730 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
731 if(hw->bus_type == e1000_bus_type_pcix) {
732 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
733 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
734 &pcix_stat_hi_word);
735 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
736 PCIX_COMMAND_MMRBC_SHIFT;
737 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
738 PCIX_STATUS_HI_MMRBC_SHIFT;
739 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
740 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
741 if(cmd_mmrbc > stat_mmrbc) {
742 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
743 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
744 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
745 &pcix_cmd_word);
746 }
747 }
748 break;
749 }
750
751 /* Call a subroutine to configure the link and setup flow control. */
752 ret_val = e1000_setup_link(hw);
753
754 /* Set the transmit descriptor write-back policy */
755 if(hw->mac_type > e1000_82544) {
756 ctrl = E1000_READ_REG(hw, TXDCTL);
757 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700758 switch (hw->mac_type) {
759 default:
760 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400761 case e1000_82571:
762 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700763 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800764 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700765 ctrl |= E1000_TXDCTL_COUNT_DESC;
766 break;
767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 E1000_WRITE_REG(hw, TXDCTL, ctrl);
769 }
770
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700771 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700772 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700773 }
774
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400775 switch (hw->mac_type) {
776 default:
777 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800778 case e1000_80003es2lan:
779 /* Enable retransmit on late collisions */
780 reg_data = E1000_READ_REG(hw, TCTL);
781 reg_data |= E1000_TCTL_RTLC;
782 E1000_WRITE_REG(hw, TCTL, reg_data);
783
784 /* Configure Gigabit Carry Extend Padding */
785 reg_data = E1000_READ_REG(hw, TCTL_EXT);
786 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
787 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
788 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
789
790 /* Configure Transmit Inter-Packet Gap */
791 reg_data = E1000_READ_REG(hw, TIPG);
792 reg_data &= ~E1000_TIPG_IPGT_MASK;
793 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
794 E1000_WRITE_REG(hw, TIPG, reg_data);
795
796 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
797 reg_data &= ~0x00100000;
798 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
799 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400800 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400801 case e1000_82572:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400802 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800803 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
804 if(hw->mac_type >= e1000_82571)
805 ctrl |= E1000_TXDCTL_COUNT_DESC;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400806 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
807 break;
808 }
809
810
811
812 if (hw->mac_type == e1000_82573) {
813 uint32_t gcr = E1000_READ_REG(hw, GCR);
814 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
815 E1000_WRITE_REG(hw, GCR, gcr);
816 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 /* Clear all of the statistics registers (clear on read). It is
819 * important that we do this after we have tried to establish link
820 * because the symbol error count will increment wildly if there
821 * is no link.
822 */
823 e1000_clear_hw_cntrs(hw);
824
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800825 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
826 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
827 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
828 /* Relaxed ordering must be disabled to avoid a parity
829 * error crash in a PCI slot. */
830 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
831 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
832 }
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return ret_val;
835}
836
837/******************************************************************************
838 * Adjust SERDES output amplitude based on EEPROM setting.
839 *
840 * hw - Struct containing variables accessed by shared code.
841 *****************************************************************************/
842static int32_t
843e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
844{
845 uint16_t eeprom_data;
846 int32_t ret_val;
847
848 DEBUGFUNC("e1000_adjust_serdes_amplitude");
849
850 if(hw->media_type != e1000_media_type_internal_serdes)
851 return E1000_SUCCESS;
852
853 switch(hw->mac_type) {
854 case e1000_82545_rev_3:
855 case e1000_82546_rev_3:
856 break;
857 default:
858 return E1000_SUCCESS;
859 }
860
861 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
862 if (ret_val) {
863 return ret_val;
864 }
865
866 if(eeprom_data != EEPROM_RESERVED_WORD) {
867 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -0700868 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
870 if(ret_val)
871 return ret_val;
872 }
873
874 return E1000_SUCCESS;
875}
876
877/******************************************************************************
878 * Configures flow control and link settings.
879 *
880 * hw - Struct containing variables accessed by shared code
881 *
882 * Determines which flow control settings to use. Calls the apropriate media-
883 * specific link configuration function. Configures the flow control settings.
884 * Assuming the adapter has a valid link partner, a valid link should be
885 * established. Assumes the hardware has previously been reset and the
886 * transmitter and receiver are not enabled.
887 *****************************************************************************/
888int32_t
889e1000_setup_link(struct e1000_hw *hw)
890{
891 uint32_t ctrl_ext;
892 int32_t ret_val;
893 uint16_t eeprom_data;
894
895 DEBUGFUNC("e1000_setup_link");
896
Jeff Kirsher526f9952006-01-12 16:50:46 -0800897 /* In the case of the phy reset being blocked, we already have a link.
898 * We do not have to set it up again. */
899 if (e1000_check_phy_reset_block(hw))
900 return E1000_SUCCESS;
901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /* Read and store word 0x0F of the EEPROM. This word contains bits
903 * that determine the hardware's default PAUSE (flow control) mode,
904 * a bit that determines whether the HW defaults to enabling or
905 * disabling auto-negotiation, and the direction of the
906 * SW defined pins. If there is no SW over-ride of the flow
907 * control setting, then the variable hw->fc will
908 * be initialized based on a value in the EEPROM.
909 */
Jeff Kirsherfd803242005-12-13 00:06:22 -0500910 if (hw->fc == e1000_fc_default) {
911 switch (hw->mac_type) {
912 case e1000_82573:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 hw->fc = e1000_fc_full;
Jeff Kirsherfd803242005-12-13 00:06:22 -0500914 break;
915 default:
916 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
917 1, &eeprom_data);
918 if (ret_val) {
919 DEBUGOUT("EEPROM Read Error\n");
920 return -E1000_ERR_EEPROM;
921 }
922 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
923 hw->fc = e1000_fc_none;
924 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
925 EEPROM_WORD0F_ASM_DIR)
926 hw->fc = e1000_fc_tx_pause;
927 else
928 hw->fc = e1000_fc_full;
929 break;
930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932
933 /* We want to save off the original Flow Control configuration just
934 * in case we get disconnected and then reconnected into a different
935 * hub or switch with different Flow Control capabilities.
936 */
937 if(hw->mac_type == e1000_82542_rev2_0)
938 hw->fc &= (~e1000_fc_tx_pause);
939
940 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
941 hw->fc &= (~e1000_fc_rx_pause);
942
943 hw->original_fc = hw->fc;
944
945 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
946
947 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
948 * polarity value for the SW controlled pins, and setup the
949 * Extended Device Control reg with that info.
950 * This is needed because one of the SW controlled pins is used for
951 * signal detection. So this should be done before e1000_setup_pcs_link()
952 * or e1000_phy_setup() is called.
953 */
Jeff Kirsher497fce52006-03-02 18:18:20 -0800954 if (hw->mac_type == e1000_82543) {
955 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
956 1, &eeprom_data);
957 if (ret_val) {
958 DEBUGOUT("EEPROM Read Error\n");
959 return -E1000_ERR_EEPROM;
960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
962 SWDPIO__EXT_SHIFT);
963 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
964 }
965
966 /* Call the necessary subroutine to configure the link. */
967 ret_val = (hw->media_type == e1000_media_type_copper) ?
968 e1000_setup_copper_link(hw) :
969 e1000_setup_fiber_serdes_link(hw);
970
971 /* Initialize the flow control address, type, and PAUSE timer
972 * registers to their default values. This is done even if flow
973 * control is disabled, because it does not hurt anything to
974 * initialize these registers.
975 */
976 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
977
978 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
979 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
980 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
983
984 /* Set the flow control receive threshold registers. Normally,
985 * these registers will be set to a default threshold that may be
986 * adjusted later by the driver's runtime code. However, if the
987 * ability to transmit pause frames in not enabled, then these
988 * registers will be set to 0.
989 */
990 if(!(hw->fc & e1000_fc_tx_pause)) {
991 E1000_WRITE_REG(hw, FCRTL, 0);
992 E1000_WRITE_REG(hw, FCRTH, 0);
993 } else {
994 /* We need to set up the Receive Threshold high and low water marks
995 * as well as (optionally) enabling the transmission of XON frames.
996 */
997 if(hw->fc_send_xon) {
998 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
999 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1000 } else {
1001 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1002 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1003 }
1004 }
1005 return ret_val;
1006}
1007
1008/******************************************************************************
1009 * Sets up link for a fiber based or serdes based adapter
1010 *
1011 * hw - Struct containing variables accessed by shared code
1012 *
1013 * Manipulates Physical Coding Sublayer functions in order to configure
1014 * link. Assumes the hardware has been previously reset and the transmitter
1015 * and receiver are not enabled.
1016 *****************************************************************************/
1017static int32_t
1018e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1019{
1020 uint32_t ctrl;
1021 uint32_t status;
1022 uint32_t txcw = 0;
1023 uint32_t i;
1024 uint32_t signal = 0;
1025 int32_t ret_val;
1026
1027 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1028
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001029 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1030 * until explicitly turned off or a power cycle is performed. A read to
1031 * the register does not indicate its status. Therefore, we ensure
1032 * loopback mode is disabled during initialization.
1033 */
1034 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1035 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1038 * set when the optics detect a signal. On older adapters, it will be
1039 * cleared when there is a signal. This applies to fiber media only.
1040 * If we're on serdes media, adjust the output amplitude to value set in
1041 * the EEPROM.
1042 */
1043 ctrl = E1000_READ_REG(hw, CTRL);
1044 if(hw->media_type == e1000_media_type_fiber)
1045 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1046
1047 ret_val = e1000_adjust_serdes_amplitude(hw);
1048 if(ret_val)
1049 return ret_val;
1050
1051 /* Take the link out of reset */
1052 ctrl &= ~(E1000_CTRL_LRST);
1053
1054 /* Adjust VCO speed to improve BER performance */
1055 ret_val = e1000_set_vco_speed(hw);
1056 if(ret_val)
1057 return ret_val;
1058
1059 e1000_config_collision_dist(hw);
1060
1061 /* Check for a software override of the flow control settings, and setup
1062 * the device accordingly. If auto-negotiation is enabled, then software
1063 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1064 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1065 * auto-negotiation is disabled, then software will have to manually
1066 * configure the two flow control enable bits in the CTRL register.
1067 *
1068 * The possible values of the "fc" parameter are:
1069 * 0: Flow control is completely disabled
1070 * 1: Rx flow control is enabled (we can receive pause frames, but
1071 * not send pause frames).
1072 * 2: Tx flow control is enabled (we can send pause frames but we do
1073 * not support receiving pause frames).
1074 * 3: Both Rx and TX flow control (symmetric) are enabled.
1075 */
1076 switch (hw->fc) {
1077 case e1000_fc_none:
1078 /* Flow control is completely disabled by a software over-ride. */
1079 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1080 break;
1081 case e1000_fc_rx_pause:
1082 /* RX Flow control is enabled and TX Flow control is disabled by a
1083 * software over-ride. Since there really isn't a way to advertise
1084 * that we are capable of RX Pause ONLY, we will advertise that we
1085 * support both symmetric and asymmetric RX PAUSE. Later, we will
1086 * disable the adapter's ability to send PAUSE frames.
1087 */
1088 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1089 break;
1090 case e1000_fc_tx_pause:
1091 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1092 * software over-ride.
1093 */
1094 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1095 break;
1096 case e1000_fc_full:
1097 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1098 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1099 break;
1100 default:
1101 DEBUGOUT("Flow control param set incorrectly\n");
1102 return -E1000_ERR_CONFIG;
1103 break;
1104 }
1105
1106 /* Since auto-negotiation is enabled, take the link out of reset (the link
1107 * will be in reset, because we previously reset the chip). This will
1108 * restart auto-negotiation. If auto-neogtiation is successful then the
1109 * link-up status bit will be set and the flow control enable bits (RFCE
1110 * and TFCE) will be set according to their negotiated value.
1111 */
1112 DEBUGOUT("Auto-negotiation enabled\n");
1113
1114 E1000_WRITE_REG(hw, TXCW, txcw);
1115 E1000_WRITE_REG(hw, CTRL, ctrl);
1116 E1000_WRITE_FLUSH(hw);
1117
1118 hw->txcw = txcw;
1119 msec_delay(1);
1120
1121 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1122 * indication in the Device Status Register. Time-out if a link isn't
1123 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1124 * less than 500 milliseconds even if the other end is doing it in SW).
1125 * For internal serdes, we just assume a signal is present, then poll.
1126 */
1127 if(hw->media_type == e1000_media_type_internal_serdes ||
1128 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1129 DEBUGOUT("Looking for Link\n");
1130 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1131 msec_delay(10);
1132 status = E1000_READ_REG(hw, STATUS);
1133 if(status & E1000_STATUS_LU) break;
1134 }
1135 if(i == (LINK_UP_TIMEOUT / 10)) {
1136 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1137 hw->autoneg_failed = 1;
1138 /* AutoNeg failed to achieve a link, so we'll call
1139 * e1000_check_for_link. This routine will force the link up if
1140 * we detect a signal. This will allow us to communicate with
1141 * non-autonegotiating link partners.
1142 */
1143 ret_val = e1000_check_for_link(hw);
1144 if(ret_val) {
1145 DEBUGOUT("Error while checking for link\n");
1146 return ret_val;
1147 }
1148 hw->autoneg_failed = 0;
1149 } else {
1150 hw->autoneg_failed = 0;
1151 DEBUGOUT("Valid Link Found\n");
1152 }
1153 } else {
1154 DEBUGOUT("No Signal Detected\n");
1155 }
1156 return E1000_SUCCESS;
1157}
1158
1159/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001160* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161*
1162* hw - Struct containing variables accessed by shared code
1163******************************************************************************/
1164static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001165e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
1167 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 uint16_t phy_data;
1170
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001171 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 ctrl = E1000_READ_REG(hw, CTRL);
1174 /* With 82543, we need to force speed and duplex on the MAC equal to what
1175 * the PHY speed and duplex configuration is. In addition, we need to
1176 * perform a hardware reset on the PHY to take it out of reset.
1177 */
1178 if(hw->mac_type > e1000_82543) {
1179 ctrl |= E1000_CTRL_SLU;
1180 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1181 E1000_WRITE_REG(hw, CTRL, ctrl);
1182 } else {
1183 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1184 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001185 ret_val = e1000_phy_hw_reset(hw);
1186 if(ret_val)
1187 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
1189
1190 /* Make sure we have a valid PHY */
1191 ret_val = e1000_detect_gig_phy(hw);
1192 if(ret_val) {
1193 DEBUGOUT("Error, did not detect valid phy.\n");
1194 return ret_val;
1195 }
1196 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1197
1198 /* Set PHY to class A mode (if necessary) */
1199 ret_val = e1000_set_phy_mode(hw);
1200 if(ret_val)
1201 return ret_val;
1202
1203 if((hw->mac_type == e1000_82545_rev_3) ||
1204 (hw->mac_type == e1000_82546_rev_3)) {
1205 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1206 phy_data |= 0x00000008;
1207 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1208 }
1209
1210 if(hw->mac_type <= e1000_82543 ||
1211 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1212 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1213 hw->phy_reset_disable = FALSE;
1214
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001215 return E1000_SUCCESS;
1216}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001219/********************************************************************
1220* Copper link setup for e1000_phy_igp series.
1221*
1222* hw - Struct containing variables accessed by shared code
1223*********************************************************************/
1224static int32_t
1225e1000_copper_link_igp_setup(struct e1000_hw *hw)
1226{
1227 uint32_t led_ctrl;
1228 int32_t ret_val;
1229 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001231 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001233 if (hw->phy_reset_disable)
1234 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001235
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001236 ret_val = e1000_phy_reset(hw);
1237 if (ret_val) {
1238 DEBUGOUT("Error Resetting the PHY\n");
1239 return ret_val;
1240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001242 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1243 msec_delay(15);
1244
1245 /* Configure activity LED after PHY reset */
1246 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1247 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1248 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1249 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1250
1251 /* disable lplu d3 during driver init */
1252 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1253 if (ret_val) {
1254 DEBUGOUT("Error Disabling LPLU D3\n");
1255 return ret_val;
1256 }
1257
1258 /* disable lplu d0 during driver init */
1259 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1260 if (ret_val) {
1261 DEBUGOUT("Error Disabling LPLU D0\n");
1262 return ret_val;
1263 }
1264 /* Configure mdi-mdix settings */
1265 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1266 if (ret_val)
1267 return ret_val;
1268
1269 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1270 hw->dsp_config_state = e1000_dsp_config_disabled;
1271 /* Force MDI for earlier revs of the IGP PHY */
1272 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1273 hw->mdix = 1;
1274
1275 } else {
1276 hw->dsp_config_state = e1000_dsp_config_enabled;
1277 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1278
1279 switch (hw->mdix) {
1280 case 1:
1281 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1282 break;
1283 case 2:
1284 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1285 break;
1286 case 0:
1287 default:
1288 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1289 break;
1290 }
1291 }
1292 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1293 if(ret_val)
1294 return ret_val;
1295
1296 /* set auto-master slave resolution settings */
1297 if(hw->autoneg) {
1298 e1000_ms_type phy_ms_setting = hw->master_slave;
1299
1300 if(hw->ffe_config_state == e1000_ffe_config_active)
1301 hw->ffe_config_state = e1000_ffe_config_enabled;
1302
1303 if(hw->dsp_config_state == e1000_dsp_config_activated)
1304 hw->dsp_config_state = e1000_dsp_config_enabled;
1305
1306 /* when autonegotiation advertisment is only 1000Mbps then we
1307 * should disable SmartSpeed and enable Auto MasterSlave
1308 * resolution as hardware default. */
1309 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1310 /* Disable SmartSpeed */
1311 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if(ret_val)
1313 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001314 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1315 ret_val = e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 IGP01E1000_PHY_PORT_CONFIG,
1317 phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 if(ret_val)
1319 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001320 /* Set auto Master/Slave resolution process */
1321 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1322 if(ret_val)
1323 return ret_val;
1324 phy_data &= ~CR_1000T_MS_ENABLE;
1325 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1326 if(ret_val)
1327 return ret_val;
1328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001330 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1331 if(ret_val)
1332 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001334 /* load defaults for future use */
1335 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1336 ((phy_data & CR_1000T_MS_VALUE) ?
1337 e1000_ms_force_master :
1338 e1000_ms_force_slave) :
1339 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001341 switch (phy_ms_setting) {
1342 case e1000_ms_force_master:
1343 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1344 break;
1345 case e1000_ms_force_slave:
1346 phy_data |= CR_1000T_MS_ENABLE;
1347 phy_data &= ~(CR_1000T_MS_VALUE);
1348 break;
1349 case e1000_ms_auto:
1350 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001352 break;
1353 }
1354 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1355 if(ret_val)
1356 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Malli Chilakala2b028932005-06-17 17:46:06 -07001359 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001360}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001362/********************************************************************
1363* Copper link setup for e1000_phy_gg82563 series.
1364*
1365* hw - Struct containing variables accessed by shared code
1366*********************************************************************/
1367static int32_t
1368e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1369{
1370 int32_t ret_val;
1371 uint16_t phy_data;
1372 uint32_t reg_data;
1373
1374 DEBUGFUNC("e1000_copper_link_ggp_setup");
1375
1376 if(!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001377
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001378 /* Enable CRS on TX for half-duplex operation. */
1379 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1380 &phy_data);
1381 if(ret_val)
1382 return ret_val;
1383
1384 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1385 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1386 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1387
1388 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1389 phy_data);
1390 if(ret_val)
1391 return ret_val;
1392
1393 /* Options:
1394 * MDI/MDI-X = 0 (default)
1395 * 0 - Auto for all speeds
1396 * 1 - MDI mode
1397 * 2 - MDI-X mode
1398 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1399 */
1400 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1401 if(ret_val)
1402 return ret_val;
1403
1404 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1405
1406 switch (hw->mdix) {
1407 case 1:
1408 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1409 break;
1410 case 2:
1411 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1412 break;
1413 case 0:
1414 default:
1415 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1416 break;
1417 }
1418
1419 /* Options:
1420 * disable_polarity_correction = 0 (default)
1421 * Automatic Correction for Reversed Cable Polarity
1422 * 0 - Disabled
1423 * 1 - Enabled
1424 */
1425 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1426 if(hw->disable_polarity_correction == 1)
1427 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1428 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1429
1430 if(ret_val)
1431 return ret_val;
1432
1433 /* SW Reset the PHY so all changes take effect */
1434 ret_val = e1000_phy_reset(hw);
1435 if (ret_val) {
1436 DEBUGOUT("Error Resetting the PHY\n");
1437 return ret_val;
1438 }
1439 } /* phy_reset_disable */
1440
1441 if (hw->mac_type == e1000_80003es2lan) {
1442 /* Bypass RX and TX FIFO's */
1443 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1444 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1445 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1446 if (ret_val)
1447 return ret_val;
1448
1449 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1450 if (ret_val)
1451 return ret_val;
1452
1453 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1454 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1455
1456 if (ret_val)
1457 return ret_val;
1458
1459 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1460 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1461 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1462
1463 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1464 &phy_data);
1465 if (ret_val)
1466 return ret_val;
1467
1468 /* Do not init these registers when the HW is in IAMT mode, since the
1469 * firmware will have already initialized them. We only initialize
1470 * them if the HW is not in IAMT mode.
1471 */
1472 if (e1000_check_mng_mode(hw) == FALSE) {
1473 /* Enable Electrical Idle on the PHY */
1474 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1475 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1476 phy_data);
1477 if (ret_val)
1478 return ret_val;
1479
1480 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1481 &phy_data);
1482 if (ret_val)
1483 return ret_val;
1484
1485 /* Enable Pass False Carrier on the PHY */
1486 phy_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1487
1488 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1489 phy_data);
1490 if (ret_val)
1491 return ret_val;
1492 }
1493
1494 /* Workaround: Disable padding in Kumeran interface in the MAC
1495 * and in the PHY to avoid CRC errors.
1496 */
1497 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1498 &phy_data);
1499 if (ret_val)
1500 return ret_val;
1501 phy_data |= GG82563_ICR_DIS_PADDING;
1502 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1503 phy_data);
1504 if (ret_val)
1505 return ret_val;
1506 }
1507
1508 return E1000_SUCCESS;
1509}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001511/********************************************************************
1512* Copper link setup for e1000_phy_m88 series.
1513*
1514* hw - Struct containing variables accessed by shared code
1515*********************************************************************/
1516static int32_t
1517e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1518{
1519 int32_t ret_val;
1520 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001522 DEBUGFUNC("e1000_copper_link_mgp_setup");
1523
1524 if(hw->phy_reset_disable)
1525 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001526
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001527 /* Enable CRS on TX. This must be set for half-duplex operation. */
1528 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1529 if(ret_val)
1530 return ret_val;
1531
1532 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1533
1534 /* Options:
1535 * MDI/MDI-X = 0 (default)
1536 * 0 - Auto for all speeds
1537 * 1 - MDI mode
1538 * 2 - MDI-X mode
1539 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1540 */
1541 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1542
1543 switch (hw->mdix) {
1544 case 1:
1545 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1546 break;
1547 case 2:
1548 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1549 break;
1550 case 3:
1551 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1552 break;
1553 case 0:
1554 default:
1555 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1556 break;
1557 }
1558
1559 /* Options:
1560 * disable_polarity_correction = 0 (default)
1561 * Automatic Correction for Reversed Cable Polarity
1562 * 0 - Disabled
1563 * 1 - Enabled
1564 */
1565 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1566 if(hw->disable_polarity_correction == 1)
1567 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001568 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1569 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001570 return ret_val;
1571
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001572 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001573 /* Force TX_CLK in the Extended PHY Specific Control Register
1574 * to 25MHz clock.
1575 */
1576 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1577 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001578 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001579
1580 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1581
1582 if ((hw->phy_revision == E1000_REVISION_2) &&
1583 (hw->phy_id == M88E1111_I_PHY_ID)) {
1584 /* Vidalia Phy, set the downshift counter to 5x */
1585 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1586 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1587 ret_val = e1000_write_phy_reg(hw,
1588 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1589 if (ret_val)
1590 return ret_val;
1591 } else {
1592 /* Configure Master and Slave downshift values */
1593 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1594 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1595 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1596 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1597 ret_val = e1000_write_phy_reg(hw,
1598 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1599 if (ret_val)
1600 return ret_val;
1601 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001604 /* SW Reset the PHY so all changes take effect */
1605 ret_val = e1000_phy_reset(hw);
1606 if(ret_val) {
1607 DEBUGOUT("Error Resetting the PHY\n");
1608 return ret_val;
1609 }
1610
1611 return E1000_SUCCESS;
1612}
1613
1614/********************************************************************
1615* Setup auto-negotiation and flow control advertisements,
1616* and then perform auto-negotiation.
1617*
1618* hw - Struct containing variables accessed by shared code
1619*********************************************************************/
1620static int32_t
1621e1000_copper_link_autoneg(struct e1000_hw *hw)
1622{
1623 int32_t ret_val;
1624 uint16_t phy_data;
1625
1626 DEBUGFUNC("e1000_copper_link_autoneg");
1627
1628 /* Perform some bounds checking on the hw->autoneg_advertised
1629 * parameter. If this variable is zero, then set it to the default.
1630 */
1631 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1632
1633 /* If autoneg_advertised is zero, we assume it was not defaulted
1634 * by the calling code so we set to advertise full capability.
1635 */
1636 if(hw->autoneg_advertised == 0)
1637 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1638
1639 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1640 ret_val = e1000_phy_setup_autoneg(hw);
1641 if(ret_val) {
1642 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1643 return ret_val;
1644 }
1645 DEBUGOUT("Restarting Auto-Neg\n");
1646
1647 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1648 * the Auto Neg Restart bit in the PHY control register.
1649 */
1650 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1651 if(ret_val)
1652 return ret_val;
1653
1654 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1655 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1656 if(ret_val)
1657 return ret_val;
1658
1659 /* Does the user want to wait for Auto-Neg to complete here, or
1660 * check at a later time (for example, callback routine).
1661 */
1662 if(hw->wait_autoneg_complete) {
1663 ret_val = e1000_wait_autoneg(hw);
1664 if(ret_val) {
1665 DEBUGOUT("Error while waiting for autoneg to complete\n");
1666 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001670 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001672 return E1000_SUCCESS;
1673}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001676/******************************************************************************
1677* Config the MAC and the PHY after link is up.
1678* 1) Set up the MAC to the current PHY speed/duplex
1679* if we are on 82543. If we
1680* are on newer silicon, we only need to configure
1681* collision distance in the Transmit Control Register.
1682* 2) Set up flow control on the MAC to that established with
1683* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001684* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001685*
1686* hw - Struct containing variables accessed by shared code
1687******************************************************************************/
1688static int32_t
1689e1000_copper_link_postconfig(struct e1000_hw *hw)
1690{
1691 int32_t ret_val;
1692 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001693
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001694 if(hw->mac_type >= e1000_82544) {
1695 e1000_config_collision_dist(hw);
1696 } else {
1697 ret_val = e1000_config_mac_to_phy(hw);
1698 if(ret_val) {
1699 DEBUGOUT("Error configuring MAC to PHY settings\n");
1700 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001702 }
1703 ret_val = e1000_config_fc_after_link_up(hw);
1704 if(ret_val) {
1705 DEBUGOUT("Error Configuring Flow Control\n");
1706 return ret_val;
1707 }
1708
1709 /* Config DSP to improve Giga link quality */
1710 if(hw->phy_type == e1000_phy_igp) {
1711 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1712 if(ret_val) {
1713 DEBUGOUT("Error Configuring DSP after link up\n");
1714 return ret_val;
1715 }
1716 }
Auke Kok76c224b2006-05-23 13:36:06 -07001717
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001718 return E1000_SUCCESS;
1719}
1720
1721/******************************************************************************
1722* Detects which PHY is present and setup the speed and duplex
1723*
1724* hw - Struct containing variables accessed by shared code
1725******************************************************************************/
1726static int32_t
1727e1000_setup_copper_link(struct e1000_hw *hw)
1728{
1729 int32_t ret_val;
1730 uint16_t i;
1731 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001732 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001733
1734 DEBUGFUNC("e1000_setup_copper_link");
1735
1736 /* Check if it is a valid PHY and set PHY mode if necessary. */
1737 ret_val = e1000_copper_link_preconfig(hw);
1738 if(ret_val)
1739 return ret_val;
1740
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001741 switch (hw->mac_type) {
1742 case e1000_80003es2lan:
1743 ret_val = e1000_read_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1744 &reg_data);
1745 if (ret_val)
1746 return ret_val;
1747 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1748 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1749 reg_data);
1750 if (ret_val)
1751 return ret_val;
1752 break;
1753 default:
1754 break;
1755 }
1756
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001757 if (hw->phy_type == e1000_phy_igp ||
1758 hw->phy_type == e1000_phy_igp_2) {
1759 ret_val = e1000_copper_link_igp_setup(hw);
1760 if(ret_val)
1761 return ret_val;
1762 } else if (hw->phy_type == e1000_phy_m88) {
1763 ret_val = e1000_copper_link_mgp_setup(hw);
1764 if(ret_val)
1765 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001766 } else if (hw->phy_type == e1000_phy_gg82563) {
1767 ret_val = e1000_copper_link_ggp_setup(hw);
1768 if(ret_val)
1769 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001770 }
1771
1772 if(hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07001773 /* Setup autoneg and flow control advertisement
1774 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001775 ret_val = e1000_copper_link_autoneg(hw);
1776 if(ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07001777 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001778 } else {
1779 /* PHY will be set to 10H, 10F, 100H,or 100F
1780 * depending on value from forced_speed_duplex. */
1781 DEBUGOUT("Forcing speed and duplex\n");
1782 ret_val = e1000_phy_force_speed_duplex(hw);
1783 if(ret_val) {
1784 DEBUGOUT("Error Forcing Speed and Duplex\n");
1785 return ret_val;
1786 }
1787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 /* Check link status. Wait up to 100 microseconds for link to become
1790 * valid.
1791 */
1792 for(i = 0; i < 10; i++) {
1793 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1794 if(ret_val)
1795 return ret_val;
1796 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1797 if(ret_val)
1798 return ret_val;
1799
1800 if(phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001801 /* Config the MAC and PHY after link is up */
1802 ret_val = e1000_copper_link_postconfig(hw);
1803 if(ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 DEBUGOUT("Valid link established!!!\n");
1807 return E1000_SUCCESS;
1808 }
1809 udelay(10);
1810 }
1811
1812 DEBUGOUT("Unable to establish link!!!\n");
1813 return E1000_SUCCESS;
1814}
1815
1816/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001817* Configure the MAC-to-PHY interface for 10/100Mbps
1818*
1819* hw - Struct containing variables accessed by shared code
1820******************************************************************************/
1821static int32_t
1822e1000_configure_kmrn_for_10_100(struct e1000_hw *hw)
1823{
1824 int32_t ret_val = E1000_SUCCESS;
1825 uint32_t tipg;
1826 uint16_t reg_data;
1827
1828 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1829
1830 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1831 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1832 reg_data);
1833 if (ret_val)
1834 return ret_val;
1835
1836 /* Configure Transmit Inter-Packet Gap */
1837 tipg = E1000_READ_REG(hw, TIPG);
1838 tipg &= ~E1000_TIPG_IPGT_MASK;
1839 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1840 E1000_WRITE_REG(hw, TIPG, tipg);
1841
1842 return ret_val;
1843}
1844
1845static int32_t
1846e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1847{
1848 int32_t ret_val = E1000_SUCCESS;
1849 uint16_t reg_data;
1850 uint32_t tipg;
1851
1852 DEBUGFUNC("e1000_configure_kmrn_for_1000");
1853
1854 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
1855 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1856 reg_data);
1857 if (ret_val)
1858 return ret_val;
1859
1860 /* Configure Transmit Inter-Packet Gap */
1861 tipg = E1000_READ_REG(hw, TIPG);
1862 tipg &= ~E1000_TIPG_IPGT_MASK;
1863 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1864 E1000_WRITE_REG(hw, TIPG, tipg);
1865
1866 return ret_val;
1867}
1868
1869/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870* Configures PHY autoneg and flow control advertisement settings
1871*
1872* hw - Struct containing variables accessed by shared code
1873******************************************************************************/
1874int32_t
1875e1000_phy_setup_autoneg(struct e1000_hw *hw)
1876{
1877 int32_t ret_val;
1878 uint16_t mii_autoneg_adv_reg;
1879 uint16_t mii_1000t_ctrl_reg;
1880
1881 DEBUGFUNC("e1000_phy_setup_autoneg");
1882
1883 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1884 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1885 if(ret_val)
1886 return ret_val;
1887
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001888 /* Read the MII 1000Base-T Control Register (Address 9). */
1889 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1890 if(ret_val)
1891 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
1893 /* Need to parse both autoneg_advertised and fc and set up
1894 * the appropriate PHY registers. First we will parse for
1895 * autoneg_advertised software override. Since we can advertise
1896 * a plethora of combinations, we need to check each bit
1897 * individually.
1898 */
1899
1900 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1901 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1902 * the 1000Base-T Control Register (Address 9).
1903 */
1904 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1905 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1906
1907 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1908
1909 /* Do we want to advertise 10 Mb Half Duplex? */
1910 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1911 DEBUGOUT("Advertise 10mb Half duplex\n");
1912 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1913 }
1914
1915 /* Do we want to advertise 10 Mb Full Duplex? */
1916 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1917 DEBUGOUT("Advertise 10mb Full duplex\n");
1918 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1919 }
1920
1921 /* Do we want to advertise 100 Mb Half Duplex? */
1922 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1923 DEBUGOUT("Advertise 100mb Half duplex\n");
1924 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1925 }
1926
1927 /* Do we want to advertise 100 Mb Full Duplex? */
1928 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1929 DEBUGOUT("Advertise 100mb Full duplex\n");
1930 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1931 }
1932
1933 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1934 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1935 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1936 }
1937
1938 /* Do we want to advertise 1000 Mb Full Duplex? */
1939 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1940 DEBUGOUT("Advertise 1000mb Full duplex\n");
1941 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1942 }
1943
1944 /* Check for a software override of the flow control settings, and
1945 * setup the PHY advertisement registers accordingly. If
1946 * auto-negotiation is enabled, then software will have to set the
1947 * "PAUSE" bits to the correct value in the Auto-Negotiation
1948 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1949 *
1950 * The possible values of the "fc" parameter are:
1951 * 0: Flow control is completely disabled
1952 * 1: Rx flow control is enabled (we can receive pause frames
1953 * but not send pause frames).
1954 * 2: Tx flow control is enabled (we can send pause frames
1955 * but we do not support receiving pause frames).
1956 * 3: Both Rx and TX flow control (symmetric) are enabled.
1957 * other: No software override. The flow control configuration
1958 * in the EEPROM is used.
1959 */
1960 switch (hw->fc) {
1961 case e1000_fc_none: /* 0 */
1962 /* Flow control (RX & TX) is completely disabled by a
1963 * software over-ride.
1964 */
1965 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1966 break;
1967 case e1000_fc_rx_pause: /* 1 */
1968 /* RX Flow control is enabled, and TX Flow control is
1969 * disabled, by a software over-ride.
1970 */
1971 /* Since there really isn't a way to advertise that we are
1972 * capable of RX Pause ONLY, we will advertise that we
1973 * support both symmetric and asymmetric RX PAUSE. Later
1974 * (in e1000_config_fc_after_link_up) we will disable the
1975 *hw's ability to send PAUSE frames.
1976 */
1977 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1978 break;
1979 case e1000_fc_tx_pause: /* 2 */
1980 /* TX Flow control is enabled, and RX Flow control is
1981 * disabled, by a software over-ride.
1982 */
1983 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1984 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1985 break;
1986 case e1000_fc_full: /* 3 */
1987 /* Flow control (both RX and TX) is enabled by a software
1988 * over-ride.
1989 */
1990 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1991 break;
1992 default:
1993 DEBUGOUT("Flow control param set incorrectly\n");
1994 return -E1000_ERR_CONFIG;
1995 }
1996
1997 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1998 if(ret_val)
1999 return ret_val;
2000
2001 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2002
Auke Kok76c224b2006-05-23 13:36:06 -07002003 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 if(ret_val)
2005 return ret_val;
2006
2007 return E1000_SUCCESS;
2008}
2009
2010/******************************************************************************
2011* Force PHY speed and duplex settings to hw->forced_speed_duplex
2012*
2013* hw - Struct containing variables accessed by shared code
2014******************************************************************************/
2015static int32_t
2016e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2017{
2018 uint32_t ctrl;
2019 int32_t ret_val;
2020 uint16_t mii_ctrl_reg;
2021 uint16_t mii_status_reg;
2022 uint16_t phy_data;
2023 uint16_t i;
2024
2025 DEBUGFUNC("e1000_phy_force_speed_duplex");
2026
2027 /* Turn off Flow control if we are forcing speed and duplex. */
2028 hw->fc = e1000_fc_none;
2029
2030 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2031
2032 /* Read the Device Control Register. */
2033 ctrl = E1000_READ_REG(hw, CTRL);
2034
2035 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2036 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2037 ctrl &= ~(DEVICE_SPEED_MASK);
2038
2039 /* Clear the Auto Speed Detect Enable bit. */
2040 ctrl &= ~E1000_CTRL_ASDE;
2041
2042 /* Read the MII Control Register. */
2043 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2044 if(ret_val)
2045 return ret_val;
2046
2047 /* We need to disable autoneg in order to force link and duplex. */
2048
2049 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2050
2051 /* Are we forcing Full or Half Duplex? */
2052 if(hw->forced_speed_duplex == e1000_100_full ||
2053 hw->forced_speed_duplex == e1000_10_full) {
2054 /* We want to force full duplex so we SET the full duplex bits in the
2055 * Device and MII Control Registers.
2056 */
2057 ctrl |= E1000_CTRL_FD;
2058 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2059 DEBUGOUT("Full Duplex\n");
2060 } else {
2061 /* We want to force half duplex so we CLEAR the full duplex bits in
2062 * the Device and MII Control Registers.
2063 */
2064 ctrl &= ~E1000_CTRL_FD;
2065 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2066 DEBUGOUT("Half Duplex\n");
2067 }
2068
2069 /* Are we forcing 100Mbps??? */
2070 if(hw->forced_speed_duplex == e1000_100_full ||
2071 hw->forced_speed_duplex == e1000_100_half) {
2072 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2073 ctrl |= E1000_CTRL_SPD_100;
2074 mii_ctrl_reg |= MII_CR_SPEED_100;
2075 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2076 DEBUGOUT("Forcing 100mb ");
2077 } else {
2078 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2079 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2080 mii_ctrl_reg |= MII_CR_SPEED_10;
2081 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2082 DEBUGOUT("Forcing 10mb ");
2083 }
2084
2085 e1000_config_collision_dist(hw);
2086
2087 /* Write the configured values back to the Device Control Reg. */
2088 E1000_WRITE_REG(hw, CTRL, ctrl);
2089
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002090 if ((hw->phy_type == e1000_phy_m88) ||
2091 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2093 if(ret_val)
2094 return ret_val;
2095
2096 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2097 * forced whenever speed are duplex are forced.
2098 */
2099 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2100 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2101 if(ret_val)
2102 return ret_val;
2103
2104 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2105
2106 /* Need to reset the PHY or these changes will be ignored */
2107 mii_ctrl_reg |= MII_CR_RESET;
2108 } else {
2109 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2110 * forced whenever speed or duplex are forced.
2111 */
2112 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2113 if(ret_val)
2114 return ret_val;
2115
2116 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2117 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2118
2119 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2120 if(ret_val)
2121 return ret_val;
2122 }
2123
2124 /* Write back the modified PHY MII control register. */
2125 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2126 if(ret_val)
2127 return ret_val;
2128
2129 udelay(1);
2130
2131 /* The wait_autoneg_complete flag may be a little misleading here.
2132 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2133 * But we do want to delay for a period while forcing only so we
2134 * don't generate false No Link messages. So we will wait here
2135 * only if the user has set wait_autoneg_complete to 1, which is
2136 * the default.
2137 */
2138 if(hw->wait_autoneg_complete) {
2139 /* We will wait for autoneg to complete. */
2140 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2141 mii_status_reg = 0;
2142
2143 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2144 for(i = PHY_FORCE_TIME; i > 0; i--) {
2145 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2146 * to be set.
2147 */
2148 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2149 if(ret_val)
2150 return ret_val;
2151
2152 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2153 if(ret_val)
2154 return ret_val;
2155
2156 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2157 msec_delay(100);
2158 }
2159 if((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002160 ((hw->phy_type == e1000_phy_m88) ||
2161 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 /* We didn't get link. Reset the DSP and wait again for link. */
2163 ret_val = e1000_phy_reset_dsp(hw);
2164 if(ret_val) {
2165 DEBUGOUT("Error Resetting PHY DSP\n");
2166 return ret_val;
2167 }
2168 }
2169 /* This loop will early-out if the link condition has been met. */
2170 for(i = PHY_FORCE_TIME; i > 0; i--) {
2171 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2172 msec_delay(100);
2173 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2174 * to be set.
2175 */
2176 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2177 if(ret_val)
2178 return ret_val;
2179
2180 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2181 if(ret_val)
2182 return ret_val;
2183 }
2184 }
2185
2186 if (hw->phy_type == e1000_phy_m88) {
2187 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2188 * Extended PHY Specific Control Register to 25MHz clock. This value
2189 * defaults back to a 2.5MHz clock when the PHY is reset.
2190 */
2191 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2192 if(ret_val)
2193 return ret_val;
2194
2195 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2196 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2197 if(ret_val)
2198 return ret_val;
2199
2200 /* In addition, because of the s/w reset above, we need to enable CRS on
2201 * TX. This must be set for both full and half duplex operation.
2202 */
2203 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2204 if(ret_val)
2205 return ret_val;
2206
2207 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2208 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2209 if(ret_val)
2210 return ret_val;
2211
2212 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2213 (!hw->autoneg) &&
2214 (hw->forced_speed_duplex == e1000_10_full ||
2215 hw->forced_speed_duplex == e1000_10_half)) {
2216 ret_val = e1000_polarity_reversal_workaround(hw);
2217 if(ret_val)
2218 return ret_val;
2219 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002220 } else if (hw->phy_type == e1000_phy_gg82563) {
2221 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2222 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2223 * we're not in a forced 10/duplex configuration. */
2224 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2225 if (ret_val)
2226 return ret_val;
2227
2228 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2229 if ((hw->forced_speed_duplex == e1000_10_full) ||
2230 (hw->forced_speed_duplex == e1000_10_half))
2231 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2232 else
2233 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2234
2235 /* Also due to the reset, we need to enable CRS on Tx. */
2236 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2237
2238 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2239 if (ret_val)
2240 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 }
2242 return E1000_SUCCESS;
2243}
2244
2245/******************************************************************************
2246* Sets the collision distance in the Transmit Control register
2247*
2248* hw - Struct containing variables accessed by shared code
2249*
2250* Link should have been established previously. Reads the speed and duplex
2251* information from the Device Status register.
2252******************************************************************************/
2253void
2254e1000_config_collision_dist(struct e1000_hw *hw)
2255{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002256 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
2258 DEBUGFUNC("e1000_config_collision_dist");
2259
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002260 if (hw->mac_type < e1000_82543)
2261 coll_dist = E1000_COLLISION_DISTANCE_82542;
2262 else
2263 coll_dist = E1000_COLLISION_DISTANCE;
2264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 tctl = E1000_READ_REG(hw, TCTL);
2266
2267 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002268 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
2270 E1000_WRITE_REG(hw, TCTL, tctl);
2271 E1000_WRITE_FLUSH(hw);
2272}
2273
2274/******************************************************************************
2275* Sets MAC speed and duplex settings to reflect the those in the PHY
2276*
2277* hw - Struct containing variables accessed by shared code
2278* mii_reg - data to write to the MII control register
2279*
2280* The contents of the PHY register containing the needed information need to
2281* be passed in.
2282******************************************************************************/
2283static int32_t
2284e1000_config_mac_to_phy(struct e1000_hw *hw)
2285{
2286 uint32_t ctrl;
2287 int32_t ret_val;
2288 uint16_t phy_data;
2289
2290 DEBUGFUNC("e1000_config_mac_to_phy");
2291
Auke Kok76c224b2006-05-23 13:36:06 -07002292 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002293 * MAC speed/duplex configuration.*/
2294 if (hw->mac_type >= e1000_82544)
2295 return E1000_SUCCESS;
2296
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 /* Read the Device Control Register and set the bits to Force Speed
2298 * and Duplex.
2299 */
2300 ctrl = E1000_READ_REG(hw, CTRL);
2301 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2302 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2303
2304 /* Set up duplex in the Device Control and Transmit Control
2305 * registers depending on negotiated values.
2306 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002307 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2308 if(ret_val)
2309 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Auke Kok76c224b2006-05-23 13:36:06 -07002311 if(phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002312 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002313 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002314 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002316 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002318 /* Set up speed in the Device Control register depending on
2319 * negotiated values.
2320 */
2321 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2322 ctrl |= E1000_CTRL_SPD_1000;
2323 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2324 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 /* Write the configured values back to the Device Control Reg. */
2327 E1000_WRITE_REG(hw, CTRL, ctrl);
2328 return E1000_SUCCESS;
2329}
2330
2331/******************************************************************************
2332 * Forces the MAC's flow control settings.
2333 *
2334 * hw - Struct containing variables accessed by shared code
2335 *
2336 * Sets the TFCE and RFCE bits in the device control register to reflect
2337 * the adapter settings. TFCE and RFCE need to be explicitly set by
2338 * software when a Copper PHY is used because autonegotiation is managed
2339 * by the PHY rather than the MAC. Software must also configure these
2340 * bits when link is forced on a fiber connection.
2341 *****************************************************************************/
2342int32_t
2343e1000_force_mac_fc(struct e1000_hw *hw)
2344{
2345 uint32_t ctrl;
2346
2347 DEBUGFUNC("e1000_force_mac_fc");
2348
2349 /* Get the current configuration of the Device Control Register */
2350 ctrl = E1000_READ_REG(hw, CTRL);
2351
2352 /* Because we didn't get link via the internal auto-negotiation
2353 * mechanism (we either forced link or we got link via PHY
2354 * auto-neg), we have to manually enable/disable transmit an
2355 * receive flow control.
2356 *
2357 * The "Case" statement below enables/disable flow control
2358 * according to the "hw->fc" parameter.
2359 *
2360 * The possible values of the "fc" parameter are:
2361 * 0: Flow control is completely disabled
2362 * 1: Rx flow control is enabled (we can receive pause
2363 * frames but not send pause frames).
2364 * 2: Tx flow control is enabled (we can send pause frames
2365 * frames but we do not receive pause frames).
2366 * 3: Both Rx and TX flow control (symmetric) is enabled.
2367 * other: No other values should be possible at this point.
2368 */
2369
2370 switch (hw->fc) {
2371 case e1000_fc_none:
2372 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2373 break;
2374 case e1000_fc_rx_pause:
2375 ctrl &= (~E1000_CTRL_TFCE);
2376 ctrl |= E1000_CTRL_RFCE;
2377 break;
2378 case e1000_fc_tx_pause:
2379 ctrl &= (~E1000_CTRL_RFCE);
2380 ctrl |= E1000_CTRL_TFCE;
2381 break;
2382 case e1000_fc_full:
2383 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2384 break;
2385 default:
2386 DEBUGOUT("Flow control param set incorrectly\n");
2387 return -E1000_ERR_CONFIG;
2388 }
2389
2390 /* Disable TX Flow Control for 82542 (rev 2.0) */
2391 if(hw->mac_type == e1000_82542_rev2_0)
2392 ctrl &= (~E1000_CTRL_TFCE);
2393
2394 E1000_WRITE_REG(hw, CTRL, ctrl);
2395 return E1000_SUCCESS;
2396}
2397
2398/******************************************************************************
2399 * Configures flow control settings after link is established
2400 *
2401 * hw - Struct containing variables accessed by shared code
2402 *
2403 * Should be called immediately after a valid link has been established.
2404 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2405 * and autonegotiation is enabled, the MAC flow control settings will be set
2406 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2407 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2408 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002409static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410e1000_config_fc_after_link_up(struct e1000_hw *hw)
2411{
2412 int32_t ret_val;
2413 uint16_t mii_status_reg;
2414 uint16_t mii_nway_adv_reg;
2415 uint16_t mii_nway_lp_ability_reg;
2416 uint16_t speed;
2417 uint16_t duplex;
2418
2419 DEBUGFUNC("e1000_config_fc_after_link_up");
2420
2421 /* Check for the case where we have fiber media and auto-neg failed
2422 * so we had to force link. In this case, we need to force the
2423 * configuration of the MAC to match the "fc" parameter.
2424 */
2425 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2426 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2427 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2428 ret_val = e1000_force_mac_fc(hw);
2429 if(ret_val) {
2430 DEBUGOUT("Error forcing flow control settings\n");
2431 return ret_val;
2432 }
2433 }
2434
2435 /* Check for the case where we have copper media and auto-neg is
2436 * enabled. In this case, we need to check and see if Auto-Neg
2437 * has completed, and if so, how the PHY and link partner has
2438 * flow control configured.
2439 */
2440 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2441 /* Read the MII Status Register and check to see if AutoNeg
2442 * has completed. We read this twice because this reg has
2443 * some "sticky" (latched) bits.
2444 */
2445 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2446 if(ret_val)
2447 return ret_val;
2448 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2449 if(ret_val)
2450 return ret_val;
2451
2452 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2453 /* The AutoNeg process has completed, so we now need to
2454 * read both the Auto Negotiation Advertisement Register
2455 * (Address 4) and the Auto_Negotiation Base Page Ability
2456 * Register (Address 5) to determine how flow control was
2457 * negotiated.
2458 */
2459 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2460 &mii_nway_adv_reg);
2461 if(ret_val)
2462 return ret_val;
2463 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2464 &mii_nway_lp_ability_reg);
2465 if(ret_val)
2466 return ret_val;
2467
2468 /* Two bits in the Auto Negotiation Advertisement Register
2469 * (Address 4) and two bits in the Auto Negotiation Base
2470 * Page Ability Register (Address 5) determine flow control
2471 * for both the PHY and the link partner. The following
2472 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2473 * 1999, describes these PAUSE resolution bits and how flow
2474 * control is determined based upon these settings.
2475 * NOTE: DC = Don't Care
2476 *
2477 * LOCAL DEVICE | LINK PARTNER
2478 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2479 *-------|---------|-------|---------|--------------------
2480 * 0 | 0 | DC | DC | e1000_fc_none
2481 * 0 | 1 | 0 | DC | e1000_fc_none
2482 * 0 | 1 | 1 | 0 | e1000_fc_none
2483 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2484 * 1 | 0 | 0 | DC | e1000_fc_none
2485 * 1 | DC | 1 | DC | e1000_fc_full
2486 * 1 | 1 | 0 | 0 | e1000_fc_none
2487 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2488 *
2489 */
2490 /* Are both PAUSE bits set to 1? If so, this implies
2491 * Symmetric Flow Control is enabled at both ends. The
2492 * ASM_DIR bits are irrelevant per the spec.
2493 *
2494 * For Symmetric Flow Control:
2495 *
2496 * LOCAL DEVICE | LINK PARTNER
2497 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2498 *-------|---------|-------|---------|--------------------
2499 * 1 | DC | 1 | DC | e1000_fc_full
2500 *
2501 */
2502 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2503 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2504 /* Now we need to check if the user selected RX ONLY
2505 * of pause frames. In this case, we had to advertise
2506 * FULL flow control because we could not advertise RX
2507 * ONLY. Hence, we must now check to see if we need to
2508 * turn OFF the TRANSMISSION of PAUSE frames.
2509 */
2510 if(hw->original_fc == e1000_fc_full) {
2511 hw->fc = e1000_fc_full;
Auke Koka42a5072006-05-23 13:36:01 -07002512 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 } else {
2514 hw->fc = e1000_fc_rx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002515 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 }
2517 }
2518 /* For receiving PAUSE frames ONLY.
2519 *
2520 * LOCAL DEVICE | LINK PARTNER
2521 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2522 *-------|---------|-------|---------|--------------------
2523 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2524 *
2525 */
2526 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2527 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2528 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2529 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2530 hw->fc = e1000_fc_tx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002531 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 }
2533 /* For transmitting PAUSE frames ONLY.
2534 *
2535 * LOCAL DEVICE | LINK PARTNER
2536 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2537 *-------|---------|-------|---------|--------------------
2538 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2539 *
2540 */
2541 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2542 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2543 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2544 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2545 hw->fc = e1000_fc_rx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002546 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 }
2548 /* Per the IEEE spec, at this point flow control should be
2549 * disabled. However, we want to consider that we could
2550 * be connected to a legacy switch that doesn't advertise
2551 * desired flow control, but can be forced on the link
2552 * partner. So if we advertised no flow control, that is
2553 * what we will resolve to. If we advertised some kind of
2554 * receive capability (Rx Pause Only or Full Flow Control)
2555 * and the link partner advertised none, we will configure
2556 * ourselves to enable Rx Flow Control only. We can do
2557 * this safely for two reasons: If the link partner really
2558 * didn't want flow control enabled, and we enable Rx, no
2559 * harm done since we won't be receiving any PAUSE frames
2560 * anyway. If the intent on the link partner was to have
2561 * flow control enabled, then by us enabling RX only, we
2562 * can at least receive pause frames and process them.
2563 * This is a good idea because in most cases, since we are
2564 * predominantly a server NIC, more times than not we will
2565 * be asked to delay transmission of packets than asking
2566 * our link partner to pause transmission of frames.
2567 */
2568 else if((hw->original_fc == e1000_fc_none ||
2569 hw->original_fc == e1000_fc_tx_pause) ||
2570 hw->fc_strict_ieee) {
2571 hw->fc = e1000_fc_none;
Auke Koka42a5072006-05-23 13:36:01 -07002572 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 } else {
2574 hw->fc = e1000_fc_rx_pause;
Auke Koka42a5072006-05-23 13:36:01 -07002575 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 }
2577
2578 /* Now we need to do one last check... If we auto-
2579 * negotiated to HALF DUPLEX, flow control should not be
2580 * enabled per IEEE 802.3 spec.
2581 */
2582 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2583 if(ret_val) {
2584 DEBUGOUT("Error getting link speed and duplex\n");
2585 return ret_val;
2586 }
2587
2588 if(duplex == HALF_DUPLEX)
2589 hw->fc = e1000_fc_none;
2590
2591 /* Now we call a subroutine to actually force the MAC
2592 * controller to use the correct flow control settings.
2593 */
2594 ret_val = e1000_force_mac_fc(hw);
2595 if(ret_val) {
2596 DEBUGOUT("Error forcing flow control settings\n");
2597 return ret_val;
2598 }
2599 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002600 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602 }
2603 return E1000_SUCCESS;
2604}
2605
2606/******************************************************************************
2607 * Checks to see if the link status of the hardware has changed.
2608 *
2609 * hw - Struct containing variables accessed by shared code
2610 *
2611 * Called by any function that needs to check the link status of the adapter.
2612 *****************************************************************************/
2613int32_t
2614e1000_check_for_link(struct e1000_hw *hw)
2615{
2616 uint32_t rxcw = 0;
2617 uint32_t ctrl;
2618 uint32_t status;
2619 uint32_t rctl;
2620 uint32_t icr;
2621 uint32_t signal = 0;
2622 int32_t ret_val;
2623 uint16_t phy_data;
2624
2625 DEBUGFUNC("e1000_check_for_link");
2626
2627 ctrl = E1000_READ_REG(hw, CTRL);
2628 status = E1000_READ_REG(hw, STATUS);
2629
2630 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2631 * set when the optics detect a signal. On older adapters, it will be
2632 * cleared when there is a signal. This applies to fiber media only.
2633 */
2634 if((hw->media_type == e1000_media_type_fiber) ||
2635 (hw->media_type == e1000_media_type_internal_serdes)) {
2636 rxcw = E1000_READ_REG(hw, RXCW);
2637
2638 if(hw->media_type == e1000_media_type_fiber) {
2639 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2640 if(status & E1000_STATUS_LU)
2641 hw->get_link_status = FALSE;
2642 }
2643 }
2644
2645 /* If we have a copper PHY then we only want to go out to the PHY
2646 * registers to see if Auto-Neg has completed and/or if our link
2647 * status has changed. The get_link_status flag will be set if we
2648 * receive a Link Status Change interrupt or we have Rx Sequence
2649 * Errors.
2650 */
2651 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2652 /* First we want to see if the MII Status Register reports
2653 * link. If so, then we want to get the current speed/duplex
2654 * of the PHY.
2655 * Read the register twice since the link bit is sticky.
2656 */
2657 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2658 if(ret_val)
2659 return ret_val;
2660 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2661 if(ret_val)
2662 return ret_val;
2663
2664 if(phy_data & MII_SR_LINK_STATUS) {
2665 hw->get_link_status = FALSE;
2666 /* Check if there was DownShift, must be checked immediately after
2667 * link-up */
2668 e1000_check_downshift(hw);
2669
2670 /* If we are on 82544 or 82543 silicon and speed/duplex
2671 * are forced to 10H or 10F, then we will implement the polarity
2672 * reversal workaround. We disable interrupts first, and upon
2673 * returning, place the devices interrupt state to its previous
2674 * value except for the link status change interrupt which will
2675 * happen due to the execution of this workaround.
2676 */
2677
2678 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2679 (!hw->autoneg) &&
2680 (hw->forced_speed_duplex == e1000_10_full ||
2681 hw->forced_speed_duplex == e1000_10_half)) {
2682 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2683 ret_val = e1000_polarity_reversal_workaround(hw);
2684 icr = E1000_READ_REG(hw, ICR);
2685 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2686 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2687 }
2688
2689 } else {
2690 /* No link detected */
2691 e1000_config_dsp_after_link_change(hw, FALSE);
2692 return 0;
2693 }
2694
2695 /* If we are forcing speed/duplex, then we simply return since
2696 * we have already determined whether we have link or not.
2697 */
2698 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2699
2700 /* optimize the dsp settings for the igp phy */
2701 e1000_config_dsp_after_link_change(hw, TRUE);
2702
2703 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2704 * have Si on board that is 82544 or newer, Auto
2705 * Speed Detection takes care of MAC speed/duplex
2706 * configuration. So we only need to configure Collision
2707 * Distance in the MAC. Otherwise, we need to force
2708 * speed/duplex on the MAC to the current PHY speed/duplex
2709 * settings.
2710 */
2711 if(hw->mac_type >= e1000_82544)
2712 e1000_config_collision_dist(hw);
2713 else {
2714 ret_val = e1000_config_mac_to_phy(hw);
2715 if(ret_val) {
2716 DEBUGOUT("Error configuring MAC to PHY settings\n");
2717 return ret_val;
2718 }
2719 }
2720
2721 /* Configure Flow Control now that Auto-Neg has completed. First, we
2722 * need to restore the desired flow control settings because we may
2723 * have had to re-autoneg with a different link partner.
2724 */
2725 ret_val = e1000_config_fc_after_link_up(hw);
2726 if(ret_val) {
2727 DEBUGOUT("Error configuring flow control\n");
2728 return ret_val;
2729 }
2730
2731 /* At this point we know that we are on copper and we have
2732 * auto-negotiated link. These are conditions for checking the link
2733 * partner capability register. We use the link speed to determine if
2734 * TBI compatibility needs to be turned on or off. If the link is not
2735 * at gigabit speed, then TBI compatibility is not needed. If we are
2736 * at gigabit speed, we turn on TBI compatibility.
2737 */
2738 if(hw->tbi_compatibility_en) {
2739 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07002740 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2741 if (ret_val) {
2742 DEBUGOUT("Error getting link speed and duplex\n");
2743 return ret_val;
2744 }
2745 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 /* If link speed is not set to gigabit speed, we do not need
2747 * to enable TBI compatibility.
2748 */
2749 if(hw->tbi_compatibility_on) {
2750 /* If we previously were in the mode, turn it off. */
2751 rctl = E1000_READ_REG(hw, RCTL);
2752 rctl &= ~E1000_RCTL_SBP;
2753 E1000_WRITE_REG(hw, RCTL, rctl);
2754 hw->tbi_compatibility_on = FALSE;
2755 }
2756 } else {
2757 /* If TBI compatibility is was previously off, turn it on. For
2758 * compatibility with a TBI link partner, we will store bad
2759 * packets. Some frames have an additional byte on the end and
2760 * will look like CRC errors to to the hardware.
2761 */
2762 if(!hw->tbi_compatibility_on) {
2763 hw->tbi_compatibility_on = TRUE;
2764 rctl = E1000_READ_REG(hw, RCTL);
2765 rctl |= E1000_RCTL_SBP;
2766 E1000_WRITE_REG(hw, RCTL, rctl);
2767 }
2768 }
2769 }
2770 }
2771 /* If we don't have link (auto-negotiation failed or link partner cannot
2772 * auto-negotiate), the cable is plugged in (we have signal), and our
2773 * link partner is not trying to auto-negotiate with us (we are receiving
2774 * idles or data), we need to force link up. We also need to give
2775 * auto-negotiation time to complete, in case the cable was just plugged
2776 * in. The autoneg_failed flag does this.
2777 */
2778 else if((((hw->media_type == e1000_media_type_fiber) &&
2779 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2780 (hw->media_type == e1000_media_type_internal_serdes)) &&
2781 (!(status & E1000_STATUS_LU)) &&
2782 (!(rxcw & E1000_RXCW_C))) {
2783 if(hw->autoneg_failed == 0) {
2784 hw->autoneg_failed = 1;
2785 return 0;
2786 }
Auke Koka42a5072006-05-23 13:36:01 -07002787 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
2789 /* Disable auto-negotiation in the TXCW register */
2790 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2791
2792 /* Force link-up and also force full-duplex. */
2793 ctrl = E1000_READ_REG(hw, CTRL);
2794 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2795 E1000_WRITE_REG(hw, CTRL, ctrl);
2796
2797 /* Configure Flow Control after forcing link up. */
2798 ret_val = e1000_config_fc_after_link_up(hw);
2799 if(ret_val) {
2800 DEBUGOUT("Error configuring flow control\n");
2801 return ret_val;
2802 }
2803 }
2804 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2805 * auto-negotiation in the TXCW register and disable forced link in the
2806 * Device Control register in an attempt to auto-negotiate with our link
2807 * partner.
2808 */
2809 else if(((hw->media_type == e1000_media_type_fiber) ||
2810 (hw->media_type == e1000_media_type_internal_serdes)) &&
2811 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07002812 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2814 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2815
2816 hw->serdes_link_down = FALSE;
2817 }
2818 /* If we force link for non-auto-negotiation switch, check link status
2819 * based on MAC synchronization for internal serdes media type.
2820 */
2821 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2822 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2823 /* SYNCH bit and IV bit are sticky. */
2824 udelay(10);
2825 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2826 if(!(rxcw & E1000_RXCW_IV)) {
2827 hw->serdes_link_down = FALSE;
2828 DEBUGOUT("SERDES: Link is up.\n");
2829 }
2830 } else {
2831 hw->serdes_link_down = TRUE;
2832 DEBUGOUT("SERDES: Link is down.\n");
2833 }
2834 }
2835 if((hw->media_type == e1000_media_type_internal_serdes) &&
2836 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2837 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2838 }
2839 return E1000_SUCCESS;
2840}
2841
2842/******************************************************************************
2843 * Detects the current speed and duplex settings of the hardware.
2844 *
2845 * hw - Struct containing variables accessed by shared code
2846 * speed - Speed of the connection
2847 * duplex - Duplex setting of the connection
2848 *****************************************************************************/
2849int32_t
2850e1000_get_speed_and_duplex(struct e1000_hw *hw,
2851 uint16_t *speed,
2852 uint16_t *duplex)
2853{
2854 uint32_t status;
2855 int32_t ret_val;
2856 uint16_t phy_data;
2857
2858 DEBUGFUNC("e1000_get_speed_and_duplex");
2859
2860 if(hw->mac_type >= e1000_82543) {
2861 status = E1000_READ_REG(hw, STATUS);
2862 if(status & E1000_STATUS_SPEED_1000) {
2863 *speed = SPEED_1000;
2864 DEBUGOUT("1000 Mbs, ");
2865 } else if(status & E1000_STATUS_SPEED_100) {
2866 *speed = SPEED_100;
2867 DEBUGOUT("100 Mbs, ");
2868 } else {
2869 *speed = SPEED_10;
2870 DEBUGOUT("10 Mbs, ");
2871 }
2872
2873 if(status & E1000_STATUS_FD) {
2874 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002875 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 } else {
2877 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002878 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 }
2880 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002881 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 *speed = SPEED_1000;
2883 *duplex = FULL_DUPLEX;
2884 }
2885
2886 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2887 * if it is operating at half duplex. Here we set the duplex settings to
2888 * match the duplex in the link partner's capabilities.
2889 */
2890 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2891 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2892 if(ret_val)
2893 return ret_val;
2894
2895 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2896 *duplex = HALF_DUPLEX;
2897 else {
2898 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2899 if(ret_val)
2900 return ret_val;
2901 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2902 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2903 *duplex = HALF_DUPLEX;
2904 }
2905 }
2906
Auke Kok76c224b2006-05-23 13:36:06 -07002907 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002908 (hw->media_type == e1000_media_type_copper)) {
2909 if (*speed == SPEED_1000)
2910 ret_val = e1000_configure_kmrn_for_1000(hw);
2911 else
2912 ret_val = e1000_configure_kmrn_for_10_100(hw);
2913 if (ret_val)
2914 return ret_val;
2915 }
2916
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 return E1000_SUCCESS;
2918}
2919
2920/******************************************************************************
2921* Blocks until autoneg completes or times out (~4.5 seconds)
2922*
2923* hw - Struct containing variables accessed by shared code
2924******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002925static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926e1000_wait_autoneg(struct e1000_hw *hw)
2927{
2928 int32_t ret_val;
2929 uint16_t i;
2930 uint16_t phy_data;
2931
2932 DEBUGFUNC("e1000_wait_autoneg");
2933 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2934
2935 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2936 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2937 /* Read the MII Status Register and wait for Auto-Neg
2938 * Complete bit to be set.
2939 */
2940 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2941 if(ret_val)
2942 return ret_val;
2943 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2944 if(ret_val)
2945 return ret_val;
2946 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2947 return E1000_SUCCESS;
2948 }
2949 msec_delay(100);
2950 }
2951 return E1000_SUCCESS;
2952}
2953
2954/******************************************************************************
2955* Raises the Management Data Clock
2956*
2957* hw - Struct containing variables accessed by shared code
2958* ctrl - Device control register's current value
2959******************************************************************************/
2960static void
2961e1000_raise_mdi_clk(struct e1000_hw *hw,
2962 uint32_t *ctrl)
2963{
2964 /* Raise the clock input to the Management Data Clock (by setting the MDC
2965 * bit), and then delay 10 microseconds.
2966 */
2967 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2968 E1000_WRITE_FLUSH(hw);
2969 udelay(10);
2970}
2971
2972/******************************************************************************
2973* Lowers the Management Data Clock
2974*
2975* hw - Struct containing variables accessed by shared code
2976* ctrl - Device control register's current value
2977******************************************************************************/
2978static void
2979e1000_lower_mdi_clk(struct e1000_hw *hw,
2980 uint32_t *ctrl)
2981{
2982 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2983 * bit), and then delay 10 microseconds.
2984 */
2985 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2986 E1000_WRITE_FLUSH(hw);
2987 udelay(10);
2988}
2989
2990/******************************************************************************
2991* Shifts data bits out to the PHY
2992*
2993* hw - Struct containing variables accessed by shared code
2994* data - Data to send out to the PHY
2995* count - Number of bits to shift out
2996*
2997* Bits are shifted out in MSB to LSB order.
2998******************************************************************************/
2999static void
3000e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3001 uint32_t data,
3002 uint16_t count)
3003{
3004 uint32_t ctrl;
3005 uint32_t mask;
3006
3007 /* We need to shift "count" number of bits out to the PHY. So, the value
3008 * in the "data" parameter will be shifted out to the PHY one bit at a
3009 * time. In order to do this, "data" must be broken down into bits.
3010 */
3011 mask = 0x01;
3012 mask <<= (count - 1);
3013
3014 ctrl = E1000_READ_REG(hw, CTRL);
3015
3016 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3017 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3018
3019 while(mask) {
3020 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3021 * then raising and lowering the Management Data Clock. A "0" is
3022 * shifted out to the PHY by setting the MDIO bit to "0" and then
3023 * raising and lowering the clock.
3024 */
3025 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3026 else ctrl &= ~E1000_CTRL_MDIO;
3027
3028 E1000_WRITE_REG(hw, CTRL, ctrl);
3029 E1000_WRITE_FLUSH(hw);
3030
3031 udelay(10);
3032
3033 e1000_raise_mdi_clk(hw, &ctrl);
3034 e1000_lower_mdi_clk(hw, &ctrl);
3035
3036 mask = mask >> 1;
3037 }
3038}
3039
3040/******************************************************************************
3041* Shifts data bits in from the PHY
3042*
3043* hw - Struct containing variables accessed by shared code
3044*
3045* Bits are shifted in in MSB to LSB order.
3046******************************************************************************/
3047static uint16_t
3048e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3049{
3050 uint32_t ctrl;
3051 uint16_t data = 0;
3052 uint8_t i;
3053
3054 /* In order to read a register from the PHY, we need to shift in a total
3055 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3056 * to avoid contention on the MDIO pin when a read operation is performed.
3057 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3058 * by raising the input to the Management Data Clock (setting the MDC bit),
3059 * and then reading the value of the MDIO bit.
3060 */
3061 ctrl = E1000_READ_REG(hw, CTRL);
3062
3063 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3064 ctrl &= ~E1000_CTRL_MDIO_DIR;
3065 ctrl &= ~E1000_CTRL_MDIO;
3066
3067 E1000_WRITE_REG(hw, CTRL, ctrl);
3068 E1000_WRITE_FLUSH(hw);
3069
3070 /* Raise and Lower the clock before reading in the data. This accounts for
3071 * the turnaround bits. The first clock occurred when we clocked out the
3072 * last bit of the Register Address.
3073 */
3074 e1000_raise_mdi_clk(hw, &ctrl);
3075 e1000_lower_mdi_clk(hw, &ctrl);
3076
3077 for(data = 0, i = 0; i < 16; i++) {
3078 data = data << 1;
3079 e1000_raise_mdi_clk(hw, &ctrl);
3080 ctrl = E1000_READ_REG(hw, CTRL);
3081 /* Check to see if we shifted in a "1". */
3082 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3083 e1000_lower_mdi_clk(hw, &ctrl);
3084 }
3085
3086 e1000_raise_mdi_clk(hw, &ctrl);
3087 e1000_lower_mdi_clk(hw, &ctrl);
3088
3089 return data;
3090}
3091
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003092int32_t
3093e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3094{
3095 uint32_t swfw_sync = 0;
3096 uint32_t swmask = mask;
3097 uint32_t fwmask = mask << 16;
3098 int32_t timeout = 200;
3099
3100 DEBUGFUNC("e1000_swfw_sync_acquire");
3101
3102 if (!hw->swfw_sync_present)
3103 return e1000_get_hw_eeprom_semaphore(hw);
3104
3105 while(timeout) {
3106 if (e1000_get_hw_eeprom_semaphore(hw))
3107 return -E1000_ERR_SWFW_SYNC;
3108
3109 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3110 if (!(swfw_sync & (fwmask | swmask))) {
3111 break;
3112 }
3113
3114 /* firmware currently using resource (fwmask) */
3115 /* or other software thread currently using resource (swmask) */
3116 e1000_put_hw_eeprom_semaphore(hw);
3117 msec_delay_irq(5);
3118 timeout--;
3119 }
3120
3121 if (!timeout) {
3122 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3123 return -E1000_ERR_SWFW_SYNC;
3124 }
3125
3126 swfw_sync |= swmask;
3127 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3128
3129 e1000_put_hw_eeprom_semaphore(hw);
3130 return E1000_SUCCESS;
3131}
3132
3133void
3134e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3135{
3136 uint32_t swfw_sync;
3137 uint32_t swmask = mask;
3138
3139 DEBUGFUNC("e1000_swfw_sync_release");
3140
3141 if (!hw->swfw_sync_present) {
3142 e1000_put_hw_eeprom_semaphore(hw);
3143 return;
3144 }
3145
3146 /* if (e1000_get_hw_eeprom_semaphore(hw))
3147 * return -E1000_ERR_SWFW_SYNC; */
3148 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3149 /* empty */
3150
3151 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3152 swfw_sync &= ~swmask;
3153 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3154
3155 e1000_put_hw_eeprom_semaphore(hw);
3156}
3157
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158/*****************************************************************************
3159* Reads the value from a PHY register, if the value is on a specific non zero
3160* page, sets the page first.
3161* hw - Struct containing variables accessed by shared code
3162* reg_addr - address of the PHY register to read
3163******************************************************************************/
3164int32_t
3165e1000_read_phy_reg(struct e1000_hw *hw,
3166 uint32_t reg_addr,
3167 uint16_t *phy_data)
3168{
3169 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003170 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
3172 DEBUGFUNC("e1000_read_phy_reg");
3173
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003174 if ((hw->mac_type == e1000_80003es2lan) &&
3175 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3176 swfw = E1000_SWFW_PHY1_SM;
3177 } else {
3178 swfw = E1000_SWFW_PHY0_SM;
3179 }
3180 if (e1000_swfw_sync_acquire(hw, swfw))
3181 return -E1000_ERR_SWFW_SYNC;
3182
Auke Kok76c224b2006-05-23 13:36:06 -07003183 if((hw->phy_type == e1000_phy_igp ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003184 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3186 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3187 (uint16_t)reg_addr);
3188 if(ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003189 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return ret_val;
3191 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003192 } else if (hw->phy_type == e1000_phy_gg82563) {
3193 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3194 (hw->mac_type == e1000_80003es2lan)) {
3195 /* Select Configuration Page */
3196 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3197 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3198 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3199 } else {
3200 /* Use Alternative Page Select register to access
3201 * registers 30 and 31
3202 */
3203 ret_val = e1000_write_phy_reg_ex(hw,
3204 GG82563_PHY_PAGE_SELECT_ALT,
3205 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3206 }
3207
3208 if (ret_val) {
3209 e1000_swfw_sync_release(hw, swfw);
3210 return ret_val;
3211 }
3212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 }
3214
3215 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3216 phy_data);
3217
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003218 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 return ret_val;
3220}
3221
3222int32_t
3223e1000_read_phy_reg_ex(struct e1000_hw *hw,
3224 uint32_t reg_addr,
3225 uint16_t *phy_data)
3226{
3227 uint32_t i;
3228 uint32_t mdic = 0;
3229 const uint32_t phy_addr = 1;
3230
3231 DEBUGFUNC("e1000_read_phy_reg_ex");
3232
3233 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3234 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3235 return -E1000_ERR_PARAM;
3236 }
3237
3238 if(hw->mac_type > e1000_82543) {
3239 /* Set up Op-code, Phy Address, and register address in the MDI
3240 * Control register. The MAC will take care of interfacing with the
3241 * PHY to retrieve the desired data.
3242 */
3243 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3244 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3245 (E1000_MDIC_OP_READ));
3246
3247 E1000_WRITE_REG(hw, MDIC, mdic);
3248
3249 /* Poll the ready bit to see if the MDI read completed */
3250 for(i = 0; i < 64; i++) {
3251 udelay(50);
3252 mdic = E1000_READ_REG(hw, MDIC);
3253 if(mdic & E1000_MDIC_READY) break;
3254 }
3255 if(!(mdic & E1000_MDIC_READY)) {
3256 DEBUGOUT("MDI Read did not complete\n");
3257 return -E1000_ERR_PHY;
3258 }
3259 if(mdic & E1000_MDIC_ERROR) {
3260 DEBUGOUT("MDI Error\n");
3261 return -E1000_ERR_PHY;
3262 }
3263 *phy_data = (uint16_t) mdic;
3264 } else {
3265 /* We must first send a preamble through the MDIO pin to signal the
3266 * beginning of an MII instruction. This is done by sending 32
3267 * consecutive "1" bits.
3268 */
3269 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3270
3271 /* Now combine the next few fields that are required for a read
3272 * operation. We use this method instead of calling the
3273 * e1000_shift_out_mdi_bits routine five different times. The format of
3274 * a MII read instruction consists of a shift out of 14 bits and is
3275 * defined as follows:
3276 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3277 * followed by a shift in of 18 bits. This first two bits shifted in
3278 * are TurnAround bits used to avoid contention on the MDIO pin when a
3279 * READ operation is performed. These two bits are thrown away
3280 * followed by a shift in of 16 bits which contains the desired data.
3281 */
3282 mdic = ((reg_addr) | (phy_addr << 5) |
3283 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3284
3285 e1000_shift_out_mdi_bits(hw, mdic, 14);
3286
3287 /* Now that we've shifted out the read command to the MII, we need to
3288 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3289 * register address.
3290 */
3291 *phy_data = e1000_shift_in_mdi_bits(hw);
3292 }
3293 return E1000_SUCCESS;
3294}
3295
3296/******************************************************************************
3297* Writes a value to a PHY register
3298*
3299* hw - Struct containing variables accessed by shared code
3300* reg_addr - address of the PHY register to write
3301* data - data to write to the PHY
3302******************************************************************************/
3303int32_t
3304e1000_write_phy_reg(struct e1000_hw *hw,
3305 uint32_t reg_addr,
3306 uint16_t phy_data)
3307{
3308 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003309 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
3311 DEBUGFUNC("e1000_write_phy_reg");
3312
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003313 if ((hw->mac_type == e1000_80003es2lan) &&
3314 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3315 swfw = E1000_SWFW_PHY1_SM;
3316 } else {
3317 swfw = E1000_SWFW_PHY0_SM;
3318 }
3319 if (e1000_swfw_sync_acquire(hw, swfw))
3320 return -E1000_ERR_SWFW_SYNC;
3321
Auke Kok76c224b2006-05-23 13:36:06 -07003322 if((hw->phy_type == e1000_phy_igp ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003323 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3325 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3326 (uint16_t)reg_addr);
3327 if(ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003328 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 return ret_val;
3330 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003331 } else if (hw->phy_type == e1000_phy_gg82563) {
3332 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3333 (hw->mac_type == e1000_80003es2lan)) {
3334 /* Select Configuration Page */
3335 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3336 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3337 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3338 } else {
3339 /* Use Alternative Page Select register to access
3340 * registers 30 and 31
3341 */
3342 ret_val = e1000_write_phy_reg_ex(hw,
3343 GG82563_PHY_PAGE_SELECT_ALT,
3344 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3345 }
3346
3347 if (ret_val) {
3348 e1000_swfw_sync_release(hw, swfw);
3349 return ret_val;
3350 }
3351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 }
3353
3354 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3355 phy_data);
3356
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003357 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 return ret_val;
3359}
3360
3361int32_t
3362e1000_write_phy_reg_ex(struct e1000_hw *hw,
3363 uint32_t reg_addr,
3364 uint16_t phy_data)
3365{
3366 uint32_t i;
3367 uint32_t mdic = 0;
3368 const uint32_t phy_addr = 1;
3369
3370 DEBUGFUNC("e1000_write_phy_reg_ex");
3371
3372 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3373 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3374 return -E1000_ERR_PARAM;
3375 }
3376
3377 if(hw->mac_type > e1000_82543) {
3378 /* Set up Op-code, Phy Address, register address, and data intended
3379 * for the PHY register in the MDI Control register. The MAC will take
3380 * care of interfacing with the PHY to send the desired data.
3381 */
3382 mdic = (((uint32_t) phy_data) |
3383 (reg_addr << E1000_MDIC_REG_SHIFT) |
3384 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3385 (E1000_MDIC_OP_WRITE));
3386
3387 E1000_WRITE_REG(hw, MDIC, mdic);
3388
3389 /* Poll the ready bit to see if the MDI read completed */
3390 for(i = 0; i < 640; i++) {
3391 udelay(5);
3392 mdic = E1000_READ_REG(hw, MDIC);
3393 if(mdic & E1000_MDIC_READY) break;
3394 }
3395 if(!(mdic & E1000_MDIC_READY)) {
3396 DEBUGOUT("MDI Write did not complete\n");
3397 return -E1000_ERR_PHY;
3398 }
3399 } else {
3400 /* We'll need to use the SW defined pins to shift the write command
3401 * out to the PHY. We first send a preamble to the PHY to signal the
3402 * beginning of the MII instruction. This is done by sending 32
3403 * consecutive "1" bits.
3404 */
3405 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3406
3407 /* Now combine the remaining required fields that will indicate a
3408 * write operation. We use this method instead of calling the
3409 * e1000_shift_out_mdi_bits routine for each field in the command. The
3410 * format of a MII write instruction is as follows:
3411 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3412 */
3413 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3414 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3415 mdic <<= 16;
3416 mdic |= (uint32_t) phy_data;
3417
3418 e1000_shift_out_mdi_bits(hw, mdic, 32);
3419 }
3420
3421 return E1000_SUCCESS;
3422}
3423
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003424int32_t
3425e1000_read_kmrn_reg(struct e1000_hw *hw,
3426 uint32_t reg_addr,
3427 uint16_t *data)
3428{
3429 uint32_t reg_val;
3430 uint16_t swfw;
3431 DEBUGFUNC("e1000_read_kmrn_reg");
3432
3433 if ((hw->mac_type == e1000_80003es2lan) &&
3434 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3435 swfw = E1000_SWFW_PHY1_SM;
3436 } else {
3437 swfw = E1000_SWFW_PHY0_SM;
3438 }
3439 if (e1000_swfw_sync_acquire(hw, swfw))
3440 return -E1000_ERR_SWFW_SYNC;
3441
3442 /* Write register address */
3443 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3444 E1000_KUMCTRLSTA_OFFSET) |
3445 E1000_KUMCTRLSTA_REN;
3446 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3447 udelay(2);
3448
3449 /* Read the data returned */
3450 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3451 *data = (uint16_t)reg_val;
3452
3453 e1000_swfw_sync_release(hw, swfw);
3454 return E1000_SUCCESS;
3455}
3456
3457int32_t
3458e1000_write_kmrn_reg(struct e1000_hw *hw,
3459 uint32_t reg_addr,
3460 uint16_t data)
3461{
3462 uint32_t reg_val;
3463 uint16_t swfw;
3464 DEBUGFUNC("e1000_write_kmrn_reg");
3465
3466 if ((hw->mac_type == e1000_80003es2lan) &&
3467 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3468 swfw = E1000_SWFW_PHY1_SM;
3469 } else {
3470 swfw = E1000_SWFW_PHY0_SM;
3471 }
3472 if (e1000_swfw_sync_acquire(hw, swfw))
3473 return -E1000_ERR_SWFW_SYNC;
3474
3475 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3476 E1000_KUMCTRLSTA_OFFSET) | data;
3477 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3478 udelay(2);
3479
3480 e1000_swfw_sync_release(hw, swfw);
3481 return E1000_SUCCESS;
3482}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003483
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484/******************************************************************************
3485* Returns the PHY to the power-on reset state
3486*
3487* hw - Struct containing variables accessed by shared code
3488******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003489int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490e1000_phy_hw_reset(struct e1000_hw *hw)
3491{
3492 uint32_t ctrl, ctrl_ext;
3493 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003494 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003495 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
3497 DEBUGFUNC("e1000_phy_hw_reset");
3498
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003499 /* In the case of the phy reset being blocked, it's not an error, we
3500 * simply return success without performing the reset. */
3501 ret_val = e1000_check_phy_reset_block(hw);
3502 if (ret_val)
3503 return E1000_SUCCESS;
3504
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 DEBUGOUT("Resetting Phy...\n");
3506
3507 if(hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003508 if ((hw->mac_type == e1000_80003es2lan) &&
3509 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3510 swfw = E1000_SWFW_PHY1_SM;
3511 } else {
3512 swfw = E1000_SWFW_PHY0_SM;
3513 }
3514 if (e1000_swfw_sync_acquire(hw, swfw)) {
3515 e1000_release_software_semaphore(hw);
3516 return -E1000_ERR_SWFW_SYNC;
3517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3519 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003520 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003521 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003522 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 */
3524 ctrl = E1000_READ_REG(hw, CTRL);
3525 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3526 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003527
3528 if (hw->mac_type < e1000_82571)
Jeff Kirsherfd803242005-12-13 00:06:22 -05003529 msec_delay(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003530 else
3531 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003532
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 E1000_WRITE_REG(hw, CTRL, ctrl);
3534 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003535
Jeff Kirsherfd803242005-12-13 00:06:22 -05003536 if (hw->mac_type >= e1000_82571)
3537 msec_delay(10);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003538 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 } else {
3540 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3541 * bit to put the PHY into reset. Then, take it out of reset.
3542 */
3543 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3544 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3545 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3546 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3547 E1000_WRITE_FLUSH(hw);
3548 msec_delay(10);
3549 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3550 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3551 E1000_WRITE_FLUSH(hw);
3552 }
3553 udelay(150);
3554
3555 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3556 /* Configure activity LED after PHY reset */
3557 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3558 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3559 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3560 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3561 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003562
3563 /* Wait for FW to finish PHY configuration. */
3564 ret_val = e1000_get_phy_cfg_done(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003565 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003566
3567 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568}
3569
3570/******************************************************************************
3571* Resets the PHY
3572*
3573* hw - Struct containing variables accessed by shared code
3574*
3575* Sets bit 15 of the MII Control regiser
3576******************************************************************************/
3577int32_t
3578e1000_phy_reset(struct e1000_hw *hw)
3579{
3580 int32_t ret_val;
3581 uint16_t phy_data;
3582
3583 DEBUGFUNC("e1000_phy_reset");
3584
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003585 /* In the case of the phy reset being blocked, it's not an error, we
3586 * simply return success without performing the reset. */
3587 ret_val = e1000_check_phy_reset_block(hw);
3588 if (ret_val)
3589 return E1000_SUCCESS;
3590
3591 switch (hw->mac_type) {
3592 case e1000_82541_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003593 case e1000_82571:
3594 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003595 ret_val = e1000_phy_hw_reset(hw);
3596 if(ret_val)
3597 return ret_val;
3598 break;
3599 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3601 if(ret_val)
3602 return ret_val;
3603
3604 phy_data |= MII_CR_RESET;
3605 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3606 if(ret_val)
3607 return ret_val;
3608
3609 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003610 break;
3611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003613 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 e1000_phy_init_script(hw);
3615
3616 return E1000_SUCCESS;
3617}
3618
3619/******************************************************************************
3620* Probes the expected PHY address for known PHY IDs
3621*
3622* hw - Struct containing variables accessed by shared code
3623******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003624static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625e1000_detect_gig_phy(struct e1000_hw *hw)
3626{
3627 int32_t phy_init_status, ret_val;
3628 uint16_t phy_id_high, phy_id_low;
3629 boolean_t match = FALSE;
3630
3631 DEBUGFUNC("e1000_detect_gig_phy");
3632
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003633 /* The 82571 firmware may still be configuring the PHY. In this
3634 * case, we cannot access the PHY until the configuration is done. So
3635 * we explicitly set the PHY values. */
3636 if(hw->mac_type == e1000_82571 ||
3637 hw->mac_type == e1000_82572) {
3638 hw->phy_id = IGP01E1000_I_PHY_ID;
3639 hw->phy_type = e1000_phy_igp_2;
3640 return E1000_SUCCESS;
3641 }
3642
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003643 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3644 * around that forces PHY page 0 to be set or the reads fail. The rest of
3645 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3646 * So for ESB-2 we need to have this set so our reads won't fail. If the
3647 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3648 * this out as well. */
3649 if (hw->mac_type == e1000_80003es2lan)
3650 hw->phy_type = e1000_phy_gg82563;
3651
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 /* Read the PHY ID Registers to identify which PHY is onboard. */
3653 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3654 if(ret_val)
3655 return ret_val;
3656
3657 hw->phy_id = (uint32_t) (phy_id_high << 16);
3658 udelay(20);
3659 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3660 if(ret_val)
3661 return ret_val;
3662
3663 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3664 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3665
3666 switch(hw->mac_type) {
3667 case e1000_82543:
3668 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3669 break;
3670 case e1000_82544:
3671 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3672 break;
3673 case e1000_82540:
3674 case e1000_82545:
3675 case e1000_82545_rev_3:
3676 case e1000_82546:
3677 case e1000_82546_rev_3:
3678 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3679 break;
3680 case e1000_82541:
3681 case e1000_82541_rev_2:
3682 case e1000_82547:
3683 case e1000_82547_rev_2:
3684 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3685 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003686 case e1000_82573:
3687 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3688 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003689 case e1000_80003es2lan:
3690 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3691 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 default:
3693 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3694 return -E1000_ERR_CONFIG;
3695 }
3696 phy_init_status = e1000_set_phy_type(hw);
3697
3698 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3699 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3700 return E1000_SUCCESS;
3701 }
3702 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3703 return -E1000_ERR_PHY;
3704}
3705
3706/******************************************************************************
3707* Resets the PHY's DSP
3708*
3709* hw - Struct containing variables accessed by shared code
3710******************************************************************************/
3711static int32_t
3712e1000_phy_reset_dsp(struct e1000_hw *hw)
3713{
3714 int32_t ret_val;
3715 DEBUGFUNC("e1000_phy_reset_dsp");
3716
3717 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003718 if (hw->phy_type != e1000_phy_gg82563) {
3719 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3720 if(ret_val) break;
3721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3723 if(ret_val) break;
3724 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3725 if(ret_val) break;
3726 ret_val = E1000_SUCCESS;
3727 } while(0);
3728
3729 return ret_val;
3730}
3731
3732/******************************************************************************
3733* Get PHY information from various PHY registers for igp PHY only.
3734*
3735* hw - Struct containing variables accessed by shared code
3736* phy_info - PHY information structure
3737******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003738static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739e1000_phy_igp_get_info(struct e1000_hw *hw,
3740 struct e1000_phy_info *phy_info)
3741{
3742 int32_t ret_val;
3743 uint16_t phy_data, polarity, min_length, max_length, average;
3744
3745 DEBUGFUNC("e1000_phy_igp_get_info");
3746
3747 /* The downshift status is checked only once, after link is established,
3748 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003749 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
3751 /* IGP01E1000 does not need to support it. */
3752 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3753
3754 /* IGP01E1000 always correct polarity reversal */
3755 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3756
3757 /* Check polarity status */
3758 ret_val = e1000_check_polarity(hw, &polarity);
3759 if(ret_val)
3760 return ret_val;
3761
3762 phy_info->cable_polarity = polarity;
3763
3764 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3765 if(ret_val)
3766 return ret_val;
3767
3768 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3769 IGP01E1000_PSSR_MDIX_SHIFT;
3770
3771 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3772 IGP01E1000_PSSR_SPEED_1000MBPS) {
3773 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3774 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3775 if(ret_val)
3776 return ret_val;
3777
3778 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3779 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3780 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3781 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3782
3783 /* Get cable length */
3784 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3785 if(ret_val)
3786 return ret_val;
3787
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003788 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 average = (max_length + min_length) / 2;
3790
3791 if(average <= e1000_igp_cable_length_50)
3792 phy_info->cable_length = e1000_cable_length_50;
3793 else if(average <= e1000_igp_cable_length_80)
3794 phy_info->cable_length = e1000_cable_length_50_80;
3795 else if(average <= e1000_igp_cable_length_110)
3796 phy_info->cable_length = e1000_cable_length_80_110;
3797 else if(average <= e1000_igp_cable_length_140)
3798 phy_info->cable_length = e1000_cable_length_110_140;
3799 else
3800 phy_info->cable_length = e1000_cable_length_140;
3801 }
3802
3803 return E1000_SUCCESS;
3804}
3805
3806/******************************************************************************
3807* Get PHY information from various PHY registers fot m88 PHY only.
3808*
3809* hw - Struct containing variables accessed by shared code
3810* phy_info - PHY information structure
3811******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003812static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813e1000_phy_m88_get_info(struct e1000_hw *hw,
3814 struct e1000_phy_info *phy_info)
3815{
3816 int32_t ret_val;
3817 uint16_t phy_data, polarity;
3818
3819 DEBUGFUNC("e1000_phy_m88_get_info");
3820
3821 /* The downshift status is checked only once, after link is established,
3822 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003823 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824
3825 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3826 if(ret_val)
3827 return ret_val;
3828
3829 phy_info->extended_10bt_distance =
3830 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3831 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3832 phy_info->polarity_correction =
3833 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3834 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3835
3836 /* Check polarity status */
3837 ret_val = e1000_check_polarity(hw, &polarity);
3838 if(ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07003839 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 phy_info->cable_polarity = polarity;
3841
3842 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3843 if(ret_val)
3844 return ret_val;
3845
3846 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3847 M88E1000_PSSR_MDIX_SHIFT;
3848
3849 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3850 /* Cable Length Estimation and Local/Remote Receiver Information
3851 * are only valid at 1000 Mbps.
3852 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003853 if (hw->phy_type != e1000_phy_gg82563) {
3854 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3855 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3856 } else {
3857 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
3858 &phy_data);
3859 if (ret_val)
3860 return ret_val;
3861
3862 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
3863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
3865 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3866 if(ret_val)
3867 return ret_val;
3868
3869 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3870 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3871
3872 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3873 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3874 }
3875
3876 return E1000_SUCCESS;
3877}
3878
3879/******************************************************************************
3880* Get PHY information from various PHY registers
3881*
3882* hw - Struct containing variables accessed by shared code
3883* phy_info - PHY information structure
3884******************************************************************************/
3885int32_t
3886e1000_phy_get_info(struct e1000_hw *hw,
3887 struct e1000_phy_info *phy_info)
3888{
3889 int32_t ret_val;
3890 uint16_t phy_data;
3891
3892 DEBUGFUNC("e1000_phy_get_info");
3893
3894 phy_info->cable_length = e1000_cable_length_undefined;
3895 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3896 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3897 phy_info->downshift = e1000_downshift_undefined;
3898 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3899 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3900 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3901 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3902
3903 if(hw->media_type != e1000_media_type_copper) {
3904 DEBUGOUT("PHY info is only valid for copper media\n");
3905 return -E1000_ERR_CONFIG;
3906 }
3907
3908 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3909 if(ret_val)
3910 return ret_val;
3911
3912 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3913 if(ret_val)
3914 return ret_val;
3915
3916 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3917 DEBUGOUT("PHY info is only valid if link is up\n");
3918 return -E1000_ERR_CONFIG;
3919 }
3920
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003921 if(hw->phy_type == e1000_phy_igp ||
3922 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 return e1000_phy_igp_get_info(hw, phy_info);
3924 else
3925 return e1000_phy_m88_get_info(hw, phy_info);
3926}
3927
3928int32_t
3929e1000_validate_mdi_setting(struct e1000_hw *hw)
3930{
3931 DEBUGFUNC("e1000_validate_mdi_settings");
3932
3933 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3934 DEBUGOUT("Invalid MDI setting detected\n");
3935 hw->mdix = 1;
3936 return -E1000_ERR_CONFIG;
3937 }
3938 return E1000_SUCCESS;
3939}
3940
3941
3942/******************************************************************************
3943 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003944 * is configured. Additionally, if this is ICH8, the flash controller GbE
3945 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 *
3947 * hw - Struct containing variables accessed by shared code
3948 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003949int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950e1000_init_eeprom_params(struct e1000_hw *hw)
3951{
3952 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3953 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003954 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 uint16_t eeprom_size;
3956
3957 DEBUGFUNC("e1000_init_eeprom_params");
3958
3959 switch (hw->mac_type) {
3960 case e1000_82542_rev2_0:
3961 case e1000_82542_rev2_1:
3962 case e1000_82543:
3963 case e1000_82544:
3964 eeprom->type = e1000_eeprom_microwire;
3965 eeprom->word_size = 64;
3966 eeprom->opcode_bits = 3;
3967 eeprom->address_bits = 6;
3968 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003969 eeprom->use_eerd = FALSE;
3970 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 break;
3972 case e1000_82540:
3973 case e1000_82545:
3974 case e1000_82545_rev_3:
3975 case e1000_82546:
3976 case e1000_82546_rev_3:
3977 eeprom->type = e1000_eeprom_microwire;
3978 eeprom->opcode_bits = 3;
3979 eeprom->delay_usec = 50;
3980 if(eecd & E1000_EECD_SIZE) {
3981 eeprom->word_size = 256;
3982 eeprom->address_bits = 8;
3983 } else {
3984 eeprom->word_size = 64;
3985 eeprom->address_bits = 6;
3986 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003987 eeprom->use_eerd = FALSE;
3988 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 break;
3990 case e1000_82541:
3991 case e1000_82541_rev_2:
3992 case e1000_82547:
3993 case e1000_82547_rev_2:
3994 if (eecd & E1000_EECD_TYPE) {
3995 eeprom->type = e1000_eeprom_spi;
3996 eeprom->opcode_bits = 8;
3997 eeprom->delay_usec = 1;
3998 if (eecd & E1000_EECD_ADDR_BITS) {
3999 eeprom->page_size = 32;
4000 eeprom->address_bits = 16;
4001 } else {
4002 eeprom->page_size = 8;
4003 eeprom->address_bits = 8;
4004 }
4005 } else {
4006 eeprom->type = e1000_eeprom_microwire;
4007 eeprom->opcode_bits = 3;
4008 eeprom->delay_usec = 50;
4009 if (eecd & E1000_EECD_ADDR_BITS) {
4010 eeprom->word_size = 256;
4011 eeprom->address_bits = 8;
4012 } else {
4013 eeprom->word_size = 64;
4014 eeprom->address_bits = 6;
4015 }
4016 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004017 eeprom->use_eerd = FALSE;
4018 eeprom->use_eewr = FALSE;
4019 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004020 case e1000_82571:
4021 case e1000_82572:
4022 eeprom->type = e1000_eeprom_spi;
4023 eeprom->opcode_bits = 8;
4024 eeprom->delay_usec = 1;
4025 if (eecd & E1000_EECD_ADDR_BITS) {
4026 eeprom->page_size = 32;
4027 eeprom->address_bits = 16;
4028 } else {
4029 eeprom->page_size = 8;
4030 eeprom->address_bits = 8;
4031 }
4032 eeprom->use_eerd = FALSE;
4033 eeprom->use_eewr = FALSE;
4034 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004035 case e1000_82573:
4036 eeprom->type = e1000_eeprom_spi;
4037 eeprom->opcode_bits = 8;
4038 eeprom->delay_usec = 1;
4039 if (eecd & E1000_EECD_ADDR_BITS) {
4040 eeprom->page_size = 32;
4041 eeprom->address_bits = 16;
4042 } else {
4043 eeprom->page_size = 8;
4044 eeprom->address_bits = 8;
4045 }
4046 eeprom->use_eerd = TRUE;
4047 eeprom->use_eewr = TRUE;
4048 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4049 eeprom->type = e1000_eeprom_flash;
4050 eeprom->word_size = 2048;
4051
4052 /* Ensure that the Autonomous FLASH update bit is cleared due to
4053 * Flash update issue on parts which use a FLASH for NVM. */
4054 eecd &= ~E1000_EECD_AUPDEN;
4055 E1000_WRITE_REG(hw, EECD, eecd);
4056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004058 case e1000_80003es2lan:
4059 eeprom->type = e1000_eeprom_spi;
4060 eeprom->opcode_bits = 8;
4061 eeprom->delay_usec = 1;
4062 if (eecd & E1000_EECD_ADDR_BITS) {
4063 eeprom->page_size = 32;
4064 eeprom->address_bits = 16;
4065 } else {
4066 eeprom->page_size = 8;
4067 eeprom->address_bits = 8;
4068 }
4069 eeprom->use_eerd = TRUE;
4070 eeprom->use_eewr = FALSE;
4071 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 default:
4073 break;
4074 }
4075
4076 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004077 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4078 * 32KB (incremented by powers of 2).
4079 */
4080 if(hw->mac_type <= e1000_82547_rev_2) {
4081 /* Set to default value for initial eeprom read. */
4082 eeprom->word_size = 64;
4083 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4084 if(ret_val)
4085 return ret_val;
4086 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4087 /* 256B eeprom size was not supported in earlier hardware, so we
4088 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4089 * is never the result used in the shifting logic below. */
4090 if(eeprom_size)
4091 eeprom_size++;
4092 } else {
4093 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4094 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004096
4097 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004099 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100}
4101
4102/******************************************************************************
4103 * Raises the EEPROM's clock input.
4104 *
4105 * hw - Struct containing variables accessed by shared code
4106 * eecd - EECD's current value
4107 *****************************************************************************/
4108static void
4109e1000_raise_ee_clk(struct e1000_hw *hw,
4110 uint32_t *eecd)
4111{
4112 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4113 * wait <delay> microseconds.
4114 */
4115 *eecd = *eecd | E1000_EECD_SK;
4116 E1000_WRITE_REG(hw, EECD, *eecd);
4117 E1000_WRITE_FLUSH(hw);
4118 udelay(hw->eeprom.delay_usec);
4119}
4120
4121/******************************************************************************
4122 * Lowers the EEPROM's clock input.
4123 *
4124 * hw - Struct containing variables accessed by shared code
4125 * eecd - EECD's current value
4126 *****************************************************************************/
4127static void
4128e1000_lower_ee_clk(struct e1000_hw *hw,
4129 uint32_t *eecd)
4130{
4131 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4132 * wait 50 microseconds.
4133 */
4134 *eecd = *eecd & ~E1000_EECD_SK;
4135 E1000_WRITE_REG(hw, EECD, *eecd);
4136 E1000_WRITE_FLUSH(hw);
4137 udelay(hw->eeprom.delay_usec);
4138}
4139
4140/******************************************************************************
4141 * Shift data bits out to the EEPROM.
4142 *
4143 * hw - Struct containing variables accessed by shared code
4144 * data - data to send to the EEPROM
4145 * count - number of bits to shift out
4146 *****************************************************************************/
4147static void
4148e1000_shift_out_ee_bits(struct e1000_hw *hw,
4149 uint16_t data,
4150 uint16_t count)
4151{
4152 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4153 uint32_t eecd;
4154 uint32_t mask;
4155
4156 /* We need to shift "count" bits out to the EEPROM. So, value in the
4157 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4158 * In order to do this, "data" must be broken down into bits.
4159 */
4160 mask = 0x01 << (count - 1);
4161 eecd = E1000_READ_REG(hw, EECD);
4162 if (eeprom->type == e1000_eeprom_microwire) {
4163 eecd &= ~E1000_EECD_DO;
4164 } else if (eeprom->type == e1000_eeprom_spi) {
4165 eecd |= E1000_EECD_DO;
4166 }
4167 do {
4168 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4169 * and then raising and then lowering the clock (the SK bit controls
4170 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4171 * by setting "DI" to "0" and then raising and then lowering the clock.
4172 */
4173 eecd &= ~E1000_EECD_DI;
4174
4175 if(data & mask)
4176 eecd |= E1000_EECD_DI;
4177
4178 E1000_WRITE_REG(hw, EECD, eecd);
4179 E1000_WRITE_FLUSH(hw);
4180
4181 udelay(eeprom->delay_usec);
4182
4183 e1000_raise_ee_clk(hw, &eecd);
4184 e1000_lower_ee_clk(hw, &eecd);
4185
4186 mask = mask >> 1;
4187
4188 } while(mask);
4189
4190 /* We leave the "DI" bit set to "0" when we leave this routine. */
4191 eecd &= ~E1000_EECD_DI;
4192 E1000_WRITE_REG(hw, EECD, eecd);
4193}
4194
4195/******************************************************************************
4196 * Shift data bits in from the EEPROM
4197 *
4198 * hw - Struct containing variables accessed by shared code
4199 *****************************************************************************/
4200static uint16_t
4201e1000_shift_in_ee_bits(struct e1000_hw *hw,
4202 uint16_t count)
4203{
4204 uint32_t eecd;
4205 uint32_t i;
4206 uint16_t data;
4207
4208 /* In order to read a register from the EEPROM, we need to shift 'count'
4209 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4210 * input to the EEPROM (setting the SK bit), and then reading the value of
4211 * the "DO" bit. During this "shifting in" process the "DI" bit should
4212 * always be clear.
4213 */
4214
4215 eecd = E1000_READ_REG(hw, EECD);
4216
4217 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4218 data = 0;
4219
4220 for(i = 0; i < count; i++) {
4221 data = data << 1;
4222 e1000_raise_ee_clk(hw, &eecd);
4223
4224 eecd = E1000_READ_REG(hw, EECD);
4225
4226 eecd &= ~(E1000_EECD_DI);
4227 if(eecd & E1000_EECD_DO)
4228 data |= 1;
4229
4230 e1000_lower_ee_clk(hw, &eecd);
4231 }
4232
4233 return data;
4234}
4235
4236/******************************************************************************
4237 * Prepares EEPROM for access
4238 *
4239 * hw - Struct containing variables accessed by shared code
4240 *
4241 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4242 * function should be called before issuing a command to the EEPROM.
4243 *****************************************************************************/
4244static int32_t
4245e1000_acquire_eeprom(struct e1000_hw *hw)
4246{
4247 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4248 uint32_t eecd, i=0;
4249
4250 DEBUGFUNC("e1000_acquire_eeprom");
4251
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004252 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4253 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 eecd = E1000_READ_REG(hw, EECD);
4255
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004256 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004257 /* Request EEPROM Access */
4258 if(hw->mac_type > e1000_82544) {
4259 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004261 eecd = E1000_READ_REG(hw, EECD);
4262 while((!(eecd & E1000_EECD_GNT)) &&
4263 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4264 i++;
4265 udelay(5);
4266 eecd = E1000_READ_REG(hw, EECD);
4267 }
4268 if(!(eecd & E1000_EECD_GNT)) {
4269 eecd &= ~E1000_EECD_REQ;
4270 E1000_WRITE_REG(hw, EECD, eecd);
4271 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004272 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004273 return -E1000_ERR_EEPROM;
4274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 }
4276 }
4277
4278 /* Setup EEPROM for Read/Write */
4279
4280 if (eeprom->type == e1000_eeprom_microwire) {
4281 /* Clear SK and DI */
4282 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4283 E1000_WRITE_REG(hw, EECD, eecd);
4284
4285 /* Set CS */
4286 eecd |= E1000_EECD_CS;
4287 E1000_WRITE_REG(hw, EECD, eecd);
4288 } else if (eeprom->type == e1000_eeprom_spi) {
4289 /* Clear SK and CS */
4290 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4291 E1000_WRITE_REG(hw, EECD, eecd);
4292 udelay(1);
4293 }
4294
4295 return E1000_SUCCESS;
4296}
4297
4298/******************************************************************************
4299 * Returns EEPROM to a "standby" state
4300 *
4301 * hw - Struct containing variables accessed by shared code
4302 *****************************************************************************/
4303static void
4304e1000_standby_eeprom(struct e1000_hw *hw)
4305{
4306 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4307 uint32_t eecd;
4308
4309 eecd = E1000_READ_REG(hw, EECD);
4310
4311 if(eeprom->type == e1000_eeprom_microwire) {
4312 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4313 E1000_WRITE_REG(hw, EECD, eecd);
4314 E1000_WRITE_FLUSH(hw);
4315 udelay(eeprom->delay_usec);
4316
4317 /* Clock high */
4318 eecd |= E1000_EECD_SK;
4319 E1000_WRITE_REG(hw, EECD, eecd);
4320 E1000_WRITE_FLUSH(hw);
4321 udelay(eeprom->delay_usec);
4322
4323 /* Select EEPROM */
4324 eecd |= E1000_EECD_CS;
4325 E1000_WRITE_REG(hw, EECD, eecd);
4326 E1000_WRITE_FLUSH(hw);
4327 udelay(eeprom->delay_usec);
4328
4329 /* Clock low */
4330 eecd &= ~E1000_EECD_SK;
4331 E1000_WRITE_REG(hw, EECD, eecd);
4332 E1000_WRITE_FLUSH(hw);
4333 udelay(eeprom->delay_usec);
4334 } else if(eeprom->type == e1000_eeprom_spi) {
4335 /* Toggle CS to flush commands */
4336 eecd |= E1000_EECD_CS;
4337 E1000_WRITE_REG(hw, EECD, eecd);
4338 E1000_WRITE_FLUSH(hw);
4339 udelay(eeprom->delay_usec);
4340 eecd &= ~E1000_EECD_CS;
4341 E1000_WRITE_REG(hw, EECD, eecd);
4342 E1000_WRITE_FLUSH(hw);
4343 udelay(eeprom->delay_usec);
4344 }
4345}
4346
4347/******************************************************************************
4348 * Terminates a command by inverting the EEPROM's chip select pin
4349 *
4350 * hw - Struct containing variables accessed by shared code
4351 *****************************************************************************/
4352static void
4353e1000_release_eeprom(struct e1000_hw *hw)
4354{
4355 uint32_t eecd;
4356
4357 DEBUGFUNC("e1000_release_eeprom");
4358
4359 eecd = E1000_READ_REG(hw, EECD);
4360
4361 if (hw->eeprom.type == e1000_eeprom_spi) {
4362 eecd |= E1000_EECD_CS; /* Pull CS high */
4363 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4364
4365 E1000_WRITE_REG(hw, EECD, eecd);
4366
4367 udelay(hw->eeprom.delay_usec);
4368 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4369 /* cleanup eeprom */
4370
4371 /* CS on Microwire is active-high */
4372 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4373
4374 E1000_WRITE_REG(hw, EECD, eecd);
4375
4376 /* Rising edge of clock */
4377 eecd |= E1000_EECD_SK;
4378 E1000_WRITE_REG(hw, EECD, eecd);
4379 E1000_WRITE_FLUSH(hw);
4380 udelay(hw->eeprom.delay_usec);
4381
4382 /* Falling edge of clock */
4383 eecd &= ~E1000_EECD_SK;
4384 E1000_WRITE_REG(hw, EECD, eecd);
4385 E1000_WRITE_FLUSH(hw);
4386 udelay(hw->eeprom.delay_usec);
4387 }
4388
4389 /* Stop requesting EEPROM access */
4390 if(hw->mac_type > e1000_82544) {
4391 eecd &= ~E1000_EECD_REQ;
4392 E1000_WRITE_REG(hw, EECD, eecd);
4393 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004394
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004395 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396}
4397
4398/******************************************************************************
4399 * Reads a 16 bit word from the EEPROM.
4400 *
4401 * hw - Struct containing variables accessed by shared code
4402 *****************************************************************************/
4403int32_t
4404e1000_spi_eeprom_ready(struct e1000_hw *hw)
4405{
4406 uint16_t retry_count = 0;
4407 uint8_t spi_stat_reg;
4408
4409 DEBUGFUNC("e1000_spi_eeprom_ready");
4410
4411 /* Read "Status Register" repeatedly until the LSB is cleared. The
4412 * EEPROM will signal that the command has been completed by clearing
4413 * bit 0 of the internal status register. If it's not cleared within
4414 * 5 milliseconds, then error out.
4415 */
4416 retry_count = 0;
4417 do {
4418 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4419 hw->eeprom.opcode_bits);
4420 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4421 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4422 break;
4423
4424 udelay(5);
4425 retry_count += 5;
4426
4427 e1000_standby_eeprom(hw);
4428 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4429
4430 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4431 * only 0-5mSec on 5V devices)
4432 */
4433 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4434 DEBUGOUT("SPI EEPROM Status error\n");
4435 return -E1000_ERR_EEPROM;
4436 }
4437
4438 return E1000_SUCCESS;
4439}
4440
4441/******************************************************************************
4442 * Reads a 16 bit word from the EEPROM.
4443 *
4444 * hw - Struct containing variables accessed by shared code
4445 * offset - offset of word in the EEPROM to read
4446 * data - word read from the EEPROM
4447 * words - number of words to read
4448 *****************************************************************************/
4449int32_t
4450e1000_read_eeprom(struct e1000_hw *hw,
4451 uint16_t offset,
4452 uint16_t words,
4453 uint16_t *data)
4454{
4455 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4456 uint32_t i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004457 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458
4459 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004460
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 /* A check for invalid values: offset too large, too many words, and not
4462 * enough words.
4463 */
4464 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4465 (words == 0)) {
4466 DEBUGOUT("\"words\" parameter out of bounds\n");
4467 return -E1000_ERR_EEPROM;
4468 }
4469
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004470 /* FLASH reads without acquiring the semaphore are safe */
4471 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4472 hw->eeprom.use_eerd == FALSE) {
4473 switch (hw->mac_type) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004474 case e1000_80003es2lan:
4475 break;
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004476 default:
4477 /* Prepare the EEPROM for reading */
4478 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4479 return -E1000_ERR_EEPROM;
4480 break;
4481 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004482 }
4483
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004484 if (eeprom->use_eerd == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004485 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4486 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4487 (hw->mac_type != e1000_82573))
4488 e1000_release_eeprom(hw);
4489 return ret_val;
4490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491
4492 if(eeprom->type == e1000_eeprom_spi) {
4493 uint16_t word_in;
4494 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4495
4496 if(e1000_spi_eeprom_ready(hw)) {
4497 e1000_release_eeprom(hw);
4498 return -E1000_ERR_EEPROM;
4499 }
4500
4501 e1000_standby_eeprom(hw);
4502
4503 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4504 if((eeprom->address_bits == 8) && (offset >= 128))
4505 read_opcode |= EEPROM_A8_OPCODE_SPI;
4506
4507 /* Send the READ command (opcode + addr) */
4508 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4509 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4510
4511 /* Read the data. The address of the eeprom internally increments with
4512 * each byte (spi) being read, saving on the overhead of eeprom setup
4513 * and tear-down. The address counter will roll over if reading beyond
4514 * the size of the eeprom, thus allowing the entire memory to be read
4515 * starting from any offset. */
4516 for (i = 0; i < words; i++) {
4517 word_in = e1000_shift_in_ee_bits(hw, 16);
4518 data[i] = (word_in >> 8) | (word_in << 8);
4519 }
4520 } else if(eeprom->type == e1000_eeprom_microwire) {
4521 for (i = 0; i < words; i++) {
4522 /* Send the READ command (opcode + addr) */
4523 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4524 eeprom->opcode_bits);
4525 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4526 eeprom->address_bits);
4527
4528 /* Read the data. For microwire, each word requires the overhead
4529 * of eeprom setup and tear-down. */
4530 data[i] = e1000_shift_in_ee_bits(hw, 16);
4531 e1000_standby_eeprom(hw);
4532 }
4533 }
4534
4535 /* End this read operation */
4536 e1000_release_eeprom(hw);
4537
4538 return E1000_SUCCESS;
4539}
4540
4541/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004542 * Reads a 16 bit word from the EEPROM using the EERD register.
4543 *
4544 * hw - Struct containing variables accessed by shared code
4545 * offset - offset of word in the EEPROM to read
4546 * data - word read from the EEPROM
4547 * words - number of words to read
4548 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004549static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004550e1000_read_eeprom_eerd(struct e1000_hw *hw,
4551 uint16_t offset,
4552 uint16_t words,
4553 uint16_t *data)
4554{
4555 uint32_t i, eerd = 0;
4556 int32_t error = 0;
4557
4558 for (i = 0; i < words; i++) {
4559 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4560 E1000_EEPROM_RW_REG_START;
4561
4562 E1000_WRITE_REG(hw, EERD, eerd);
4563 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07004564
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004565 if(error) {
4566 break;
4567 }
4568 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07004569
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004570 }
Auke Kok76c224b2006-05-23 13:36:06 -07004571
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004572 return error;
4573}
4574
4575/******************************************************************************
4576 * Writes a 16 bit word from the EEPROM using the EEWR register.
4577 *
4578 * hw - Struct containing variables accessed by shared code
4579 * offset - offset of word in the EEPROM to read
4580 * data - word read from the EEPROM
4581 * words - number of words to read
4582 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004583static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004584e1000_write_eeprom_eewr(struct e1000_hw *hw,
4585 uint16_t offset,
4586 uint16_t words,
4587 uint16_t *data)
4588{
4589 uint32_t register_value = 0;
4590 uint32_t i = 0;
4591 int32_t error = 0;
4592
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004593 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4594 return -E1000_ERR_SWFW_SYNC;
4595
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004596 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07004597 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4598 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004599 E1000_EEPROM_RW_REG_START;
4600
4601 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4602 if(error) {
4603 break;
Auke Kok76c224b2006-05-23 13:36:06 -07004604 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004605
4606 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07004607
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004608 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07004609
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004610 if(error) {
4611 break;
Auke Kok76c224b2006-05-23 13:36:06 -07004612 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004613 }
Auke Kok76c224b2006-05-23 13:36:06 -07004614
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004615 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004616 return error;
4617}
4618
4619/******************************************************************************
4620 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4621 *
4622 * hw - Struct containing variables accessed by shared code
4623 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004624static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004625e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
4626{
4627 uint32_t attempts = 100000;
4628 uint32_t i, reg = 0;
4629 int32_t done = E1000_ERR_EEPROM;
4630
4631 for(i = 0; i < attempts; i++) {
4632 if(eerd == E1000_EEPROM_POLL_READ)
4633 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07004634 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004635 reg = E1000_READ_REG(hw, EEWR);
4636
4637 if(reg & E1000_EEPROM_RW_REG_DONE) {
4638 done = E1000_SUCCESS;
4639 break;
4640 }
4641 udelay(5);
4642 }
4643
4644 return done;
4645}
4646
4647/***************************************************************************
4648* Description: Determines if the onboard NVM is FLASH or EEPROM.
4649*
4650* hw - Struct containing variables accessed by shared code
4651****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004652static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004653e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4654{
4655 uint32_t eecd = 0;
4656
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004657 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
4658
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004659 if(hw->mac_type == e1000_82573) {
4660 eecd = E1000_READ_REG(hw, EECD);
4661
4662 /* Isolate bits 15 & 16 */
4663 eecd = ((eecd >> 15) & 0x03);
4664
4665 /* If both bits are set, device is Flash type */
4666 if(eecd == 0x03) {
4667 return FALSE;
4668 }
4669 }
4670 return TRUE;
4671}
4672
4673/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 * Verifies that the EEPROM has a valid checksum
4675 *
4676 * hw - Struct containing variables accessed by shared code
4677 *
4678 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4679 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4680 * valid.
4681 *****************************************************************************/
4682int32_t
4683e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4684{
4685 uint16_t checksum = 0;
4686 uint16_t i, eeprom_data;
4687
4688 DEBUGFUNC("e1000_validate_eeprom_checksum");
4689
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004690 if ((hw->mac_type == e1000_82573) &&
4691 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
4692 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4693 * 10h-12h. Checksum may need to be fixed. */
4694 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
4695 if ((eeprom_data & 0x10) == 0) {
4696 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4697 * has already been fixed. If the checksum is still wrong and this
4698 * bit is a 1, we need to return bad checksum. Otherwise, we need
4699 * to set this bit to a 1 and update the checksum. */
4700 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
4701 if ((eeprom_data & 0x8000) == 0) {
4702 eeprom_data |= 0x8000;
4703 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
4704 e1000_update_eeprom_checksum(hw);
4705 }
4706 }
4707 }
4708
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4710 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4711 DEBUGOUT("EEPROM Read Error\n");
4712 return -E1000_ERR_EEPROM;
4713 }
4714 checksum += eeprom_data;
4715 }
4716
4717 if(checksum == (uint16_t) EEPROM_SUM)
4718 return E1000_SUCCESS;
4719 else {
4720 DEBUGOUT("EEPROM Checksum Invalid\n");
4721 return -E1000_ERR_EEPROM;
4722 }
4723}
4724
4725/******************************************************************************
4726 * Calculates the EEPROM checksum and writes it to the EEPROM
4727 *
4728 * hw - Struct containing variables accessed by shared code
4729 *
4730 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4731 * Writes the difference to word offset 63 of the EEPROM.
4732 *****************************************************************************/
4733int32_t
4734e1000_update_eeprom_checksum(struct e1000_hw *hw)
4735{
4736 uint16_t checksum = 0;
4737 uint16_t i, eeprom_data;
4738
4739 DEBUGFUNC("e1000_update_eeprom_checksum");
4740
4741 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4742 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4743 DEBUGOUT("EEPROM Read Error\n");
4744 return -E1000_ERR_EEPROM;
4745 }
4746 checksum += eeprom_data;
4747 }
4748 checksum = (uint16_t) EEPROM_SUM - checksum;
4749 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4750 DEBUGOUT("EEPROM Write Error\n");
4751 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004752 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4753 e1000_commit_shadow_ram(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 }
4755 return E1000_SUCCESS;
4756}
4757
4758/******************************************************************************
4759 * Parent function for writing words to the different EEPROM types.
4760 *
4761 * hw - Struct containing variables accessed by shared code
4762 * offset - offset within the EEPROM to be written to
4763 * words - number of words to write
4764 * data - 16 bit word to be written to the EEPROM
4765 *
4766 * If e1000_update_eeprom_checksum is not called after this function, the
4767 * EEPROM will most likely contain an invalid checksum.
4768 *****************************************************************************/
4769int32_t
4770e1000_write_eeprom(struct e1000_hw *hw,
4771 uint16_t offset,
4772 uint16_t words,
4773 uint16_t *data)
4774{
4775 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4776 int32_t status = 0;
4777
4778 DEBUGFUNC("e1000_write_eeprom");
4779
4780 /* A check for invalid values: offset too large, too many words, and not
4781 * enough words.
4782 */
4783 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4784 (words == 0)) {
4785 DEBUGOUT("\"words\" parameter out of bounds\n");
4786 return -E1000_ERR_EEPROM;
4787 }
4788
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004789 /* 82573 writes only through eewr */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004790 if(eeprom->use_eewr == TRUE)
4791 return e1000_write_eeprom_eewr(hw, offset, words, data);
4792
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 /* Prepare the EEPROM for writing */
4794 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4795 return -E1000_ERR_EEPROM;
4796
4797 if(eeprom->type == e1000_eeprom_microwire) {
4798 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4799 } else {
4800 status = e1000_write_eeprom_spi(hw, offset, words, data);
4801 msec_delay(10);
4802 }
4803
4804 /* Done with writing */
4805 e1000_release_eeprom(hw);
4806
4807 return status;
4808}
4809
4810/******************************************************************************
4811 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4812 *
4813 * hw - Struct containing variables accessed by shared code
4814 * offset - offset within the EEPROM to be written to
4815 * words - number of words to write
4816 * data - pointer to array of 8 bit words to be written to the EEPROM
4817 *
4818 *****************************************************************************/
4819int32_t
4820e1000_write_eeprom_spi(struct e1000_hw *hw,
4821 uint16_t offset,
4822 uint16_t words,
4823 uint16_t *data)
4824{
4825 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4826 uint16_t widx = 0;
4827
4828 DEBUGFUNC("e1000_write_eeprom_spi");
4829
4830 while (widx < words) {
4831 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4832
4833 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4834
4835 e1000_standby_eeprom(hw);
4836
4837 /* Send the WRITE ENABLE command (8 bit opcode ) */
4838 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4839 eeprom->opcode_bits);
4840
4841 e1000_standby_eeprom(hw);
4842
4843 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4844 if((eeprom->address_bits == 8) && (offset >= 128))
4845 write_opcode |= EEPROM_A8_OPCODE_SPI;
4846
4847 /* Send the Write command (8-bit opcode + addr) */
4848 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4849
4850 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4851 eeprom->address_bits);
4852
4853 /* Send the data */
4854
4855 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4856 while (widx < words) {
4857 uint16_t word_out = data[widx];
4858 word_out = (word_out >> 8) | (word_out << 8);
4859 e1000_shift_out_ee_bits(hw, word_out, 16);
4860 widx++;
4861
4862 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4863 * operation, while the smaller eeproms are capable of an 8-byte
4864 * PAGE WRITE operation. Break the inner loop to pass new address
4865 */
4866 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4867 e1000_standby_eeprom(hw);
4868 break;
4869 }
4870 }
4871 }
4872
4873 return E1000_SUCCESS;
4874}
4875
4876/******************************************************************************
4877 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4878 *
4879 * hw - Struct containing variables accessed by shared code
4880 * offset - offset within the EEPROM to be written to
4881 * words - number of words to write
4882 * data - pointer to array of 16 bit words to be written to the EEPROM
4883 *
4884 *****************************************************************************/
4885int32_t
4886e1000_write_eeprom_microwire(struct e1000_hw *hw,
4887 uint16_t offset,
4888 uint16_t words,
4889 uint16_t *data)
4890{
4891 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4892 uint32_t eecd;
4893 uint16_t words_written = 0;
4894 uint16_t i = 0;
4895
4896 DEBUGFUNC("e1000_write_eeprom_microwire");
4897
4898 /* Send the write enable command to the EEPROM (3-bit opcode plus
4899 * 6/8-bit dummy address beginning with 11). It's less work to include
4900 * the 11 of the dummy address as part of the opcode than it is to shift
4901 * it over the correct number of bits for the address. This puts the
4902 * EEPROM into write/erase mode.
4903 */
4904 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4905 (uint16_t)(eeprom->opcode_bits + 2));
4906
4907 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4908
4909 /* Prepare the EEPROM */
4910 e1000_standby_eeprom(hw);
4911
4912 while (words_written < words) {
4913 /* Send the Write command (3-bit opcode + addr) */
4914 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4915 eeprom->opcode_bits);
4916
4917 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4918 eeprom->address_bits);
4919
4920 /* Send the data */
4921 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4922
4923 /* Toggle the CS line. This in effect tells the EEPROM to execute
4924 * the previous command.
4925 */
4926 e1000_standby_eeprom(hw);
4927
4928 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4929 * signal that the command has been completed by raising the DO signal.
4930 * If DO does not go high in 10 milliseconds, then error out.
4931 */
4932 for(i = 0; i < 200; i++) {
4933 eecd = E1000_READ_REG(hw, EECD);
4934 if(eecd & E1000_EECD_DO) break;
4935 udelay(50);
4936 }
4937 if(i == 200) {
4938 DEBUGOUT("EEPROM Write did not complete\n");
4939 return -E1000_ERR_EEPROM;
4940 }
4941
4942 /* Recover from write */
4943 e1000_standby_eeprom(hw);
4944
4945 words_written++;
4946 }
4947
4948 /* Send the write disable command to the EEPROM (3-bit opcode plus
4949 * 6/8-bit dummy address beginning with 10). It's less work to include
4950 * the 10 of the dummy address as part of the opcode than it is to shift
4951 * it over the correct number of bits for the address. This takes the
4952 * EEPROM out of write/erase mode.
4953 */
4954 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4955 (uint16_t)(eeprom->opcode_bits + 2));
4956
4957 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4958
4959 return E1000_SUCCESS;
4960}
4961
4962/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004963 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4964 * in the eeprom cache and the non modified values in the currently active bank
4965 * to the new bank.
4966 *
4967 * hw - Struct containing variables accessed by shared code
4968 * offset - offset of word in the EEPROM to read
4969 * data - word read from the EEPROM
4970 * words - number of words to read
4971 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004972static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004973e1000_commit_shadow_ram(struct e1000_hw *hw)
4974{
4975 uint32_t attempts = 100000;
4976 uint32_t eecd = 0;
4977 uint32_t flop = 0;
4978 uint32_t i = 0;
4979 int32_t error = E1000_SUCCESS;
4980
4981 /* The flop register will be used to determine if flash type is STM */
4982 flop = E1000_READ_REG(hw, FLOP);
4983
4984 if (hw->mac_type == e1000_82573) {
4985 for (i=0; i < attempts; i++) {
4986 eecd = E1000_READ_REG(hw, EECD);
4987 if ((eecd & E1000_EECD_FLUPD) == 0) {
4988 break;
4989 }
4990 udelay(5);
4991 }
4992
4993 if (i == attempts) {
4994 return -E1000_ERR_EEPROM;
4995 }
4996
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004997 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004998 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4999 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5000 }
5001
5002 /* Perform the flash update */
5003 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5004
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005005 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005006 eecd = E1000_READ_REG(hw, EECD);
5007 if ((eecd & E1000_EECD_FLUPD) == 0) {
5008 break;
5009 }
5010 udelay(5);
5011 }
5012
5013 if (i == attempts) {
5014 return -E1000_ERR_EEPROM;
5015 }
5016 }
5017
5018 return error;
5019}
5020
5021/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022 * Reads the adapter's part number from the EEPROM
5023 *
5024 * hw - Struct containing variables accessed by shared code
5025 * part_num - Adapter's part number
5026 *****************************************************************************/
5027int32_t
5028e1000_read_part_num(struct e1000_hw *hw,
5029 uint32_t *part_num)
5030{
5031 uint16_t offset = EEPROM_PBA_BYTE_1;
5032 uint16_t eeprom_data;
5033
5034 DEBUGFUNC("e1000_read_part_num");
5035
5036 /* Get word 0 from EEPROM */
5037 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5038 DEBUGOUT("EEPROM Read Error\n");
5039 return -E1000_ERR_EEPROM;
5040 }
5041 /* Save word 0 in upper half of part_num */
5042 *part_num = (uint32_t) (eeprom_data << 16);
5043
5044 /* Get word 1 from EEPROM */
5045 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5046 DEBUGOUT("EEPROM Read Error\n");
5047 return -E1000_ERR_EEPROM;
5048 }
5049 /* Save word 1 in lower half of part_num */
5050 *part_num |= eeprom_data;
5051
5052 return E1000_SUCCESS;
5053}
5054
5055/******************************************************************************
5056 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5057 * second function of dual function devices
5058 *
5059 * hw - Struct containing variables accessed by shared code
5060 *****************************************************************************/
5061int32_t
5062e1000_read_mac_addr(struct e1000_hw * hw)
5063{
5064 uint16_t offset;
5065 uint16_t eeprom_data, i;
5066
5067 DEBUGFUNC("e1000_read_mac_addr");
5068
5069 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5070 offset = i >> 1;
5071 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5072 DEBUGOUT("EEPROM Read Error\n");
5073 return -E1000_ERR_EEPROM;
5074 }
5075 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5076 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5077 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005078
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005079 switch (hw->mac_type) {
5080 default:
5081 break;
5082 case e1000_82546:
5083 case e1000_82546_rev_3:
5084 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005085 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005086 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005088 break;
5089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090
5091 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5092 hw->mac_addr[i] = hw->perm_mac_addr[i];
5093 return E1000_SUCCESS;
5094}
5095
5096/******************************************************************************
5097 * Initializes receive address filters.
5098 *
5099 * hw - Struct containing variables accessed by shared code
5100 *
5101 * Places the MAC address in receive address register 0 and clears the rest
5102 * of the receive addresss registers. Clears the multicast table. Assumes
5103 * the receiver is in reset when the routine is called.
5104 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005105static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106e1000_init_rx_addrs(struct e1000_hw *hw)
5107{
5108 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005109 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110
5111 DEBUGFUNC("e1000_init_rx_addrs");
5112
5113 /* Setup the receive address. */
5114 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5115
5116 e1000_rar_set(hw, hw->mac_addr, 0);
5117
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005118 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005119
5120 /* Reserve a spot for the Locally Administered Address to work around
5121 * an 82571 issue in which a reset on one port will reload the MAC on
5122 * the other port. */
5123 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5124 rar_num -= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 /* Zero out the other 15 receive addresses. */
5126 DEBUGOUT("Clearing RAR[1-15]\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005127 for(i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005129 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005131 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 }
5133}
5134
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005135#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136/******************************************************************************
5137 * Updates the MAC's list of multicast addresses.
5138 *
5139 * hw - Struct containing variables accessed by shared code
5140 * mc_addr_list - the list of new multicast addresses
5141 * mc_addr_count - number of addresses
5142 * pad - number of bytes between addresses in the list
5143 * rar_used_count - offset where to start adding mc addresses into the RAR's
5144 *
5145 * The given list replaces any existing list. Clears the last 15 receive
5146 * address registers and the multicast table. Uses receive address registers
5147 * for the first 15 multicast addresses, and hashes the rest into the
5148 * multicast table.
5149 *****************************************************************************/
5150void
5151e1000_mc_addr_list_update(struct e1000_hw *hw,
5152 uint8_t *mc_addr_list,
5153 uint32_t mc_addr_count,
5154 uint32_t pad,
5155 uint32_t rar_used_count)
5156{
5157 uint32_t hash_value;
5158 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005159 uint32_t num_rar_entry;
5160 uint32_t num_mta_entry;
Auke Kok76c224b2006-05-23 13:36:06 -07005161
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 DEBUGFUNC("e1000_mc_addr_list_update");
5163
5164 /* Set the new number of MC addresses that we are being requested to use. */
5165 hw->num_mc_addrs = mc_addr_count;
5166
5167 /* Clear RAR[1-15] */
5168 DEBUGOUT(" Clearing RAR[1-15]\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005169 num_rar_entry = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005170 /* Reserve a spot for the Locally Administered Address to work around
5171 * an 82571 issue in which a reset on one port will reload the MAC on
5172 * the other port. */
5173 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5174 num_rar_entry -= 1;
5175
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005176 for(i = rar_used_count; i < num_rar_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005178 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005180 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 }
5182
5183 /* Clear the MTA */
5184 DEBUGOUT(" Clearing MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005185 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5186 for(i = 0; i < num_mta_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005188 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189 }
5190
5191 /* Add the new addresses */
5192 for(i = 0; i < mc_addr_count; i++) {
5193 DEBUGOUT(" Adding the multicast addresses:\n");
5194 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5195 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5196 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5197 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5198 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5199 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5200 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5201
5202 hash_value = e1000_hash_mc_addr(hw,
5203 mc_addr_list +
5204 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5205
5206 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5207
5208 /* Place this multicast address in the RAR if there is room, *
5209 * else put it in the MTA
5210 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005211 if (rar_used_count < num_rar_entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 e1000_rar_set(hw,
5213 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5214 rar_used_count);
5215 rar_used_count++;
5216 } else {
5217 e1000_mta_set(hw, hash_value);
5218 }
5219 }
5220 DEBUGOUT("MC Update Complete\n");
5221}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005222#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
5224/******************************************************************************
5225 * Hashes an address to determine its location in the multicast table
5226 *
5227 * hw - Struct containing variables accessed by shared code
5228 * mc_addr - the multicast address to hash
5229 *****************************************************************************/
5230uint32_t
5231e1000_hash_mc_addr(struct e1000_hw *hw,
5232 uint8_t *mc_addr)
5233{
5234 uint32_t hash_value = 0;
5235
5236 /* The portion of the address that is used for the hash table is
5237 * determined by the mc_filter_type setting.
5238 */
5239 switch (hw->mc_filter_type) {
5240 /* [0] [1] [2] [3] [4] [5]
5241 * 01 AA 00 12 34 56
5242 * LSB MSB
5243 */
5244 case 0:
5245 /* [47:36] i.e. 0x563 for above example address */
5246 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5247 break;
5248 case 1:
5249 /* [46:35] i.e. 0xAC6 for above example address */
5250 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5251 break;
5252 case 2:
5253 /* [45:34] i.e. 0x5D8 for above example address */
5254 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5255 break;
5256 case 3:
5257 /* [43:32] i.e. 0x634 for above example address */
5258 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5259 break;
5260 }
5261
5262 hash_value &= 0xFFF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005263
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 return hash_value;
5265}
5266
5267/******************************************************************************
5268 * Sets the bit in the multicast table corresponding to the hash value.
5269 *
5270 * hw - Struct containing variables accessed by shared code
5271 * hash_value - Multicast address hash value
5272 *****************************************************************************/
5273void
5274e1000_mta_set(struct e1000_hw *hw,
5275 uint32_t hash_value)
5276{
5277 uint32_t hash_bit, hash_reg;
5278 uint32_t mta;
5279 uint32_t temp;
5280
5281 /* The MTA is a register array of 128 32-bit registers.
5282 * It is treated like an array of 4096 bits. We want to set
5283 * bit BitArray[hash_value]. So we figure out what register
5284 * the bit is in, read it, OR in the new bit, then write
5285 * back the new value. The register is determined by the
5286 * upper 7 bits of the hash value and the bit within that
5287 * register are determined by the lower 5 bits of the value.
5288 */
5289 hash_reg = (hash_value >> 5) & 0x7F;
5290 hash_bit = hash_value & 0x1F;
5291
5292 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5293
5294 mta |= (1 << hash_bit);
5295
5296 /* If we are on an 82544 and we are trying to write an odd offset
5297 * in the MTA, save off the previous entry before writing and
5298 * restore the old value after writing.
5299 */
5300 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5301 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5302 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005303 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005305 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306 } else {
5307 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005308 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 }
5310}
5311
5312/******************************************************************************
5313 * Puts an ethernet address into a receive address register.
5314 *
5315 * hw - Struct containing variables accessed by shared code
5316 * addr - Address to put into receive address register
5317 * index - Receive address register to write
5318 *****************************************************************************/
5319void
5320e1000_rar_set(struct e1000_hw *hw,
5321 uint8_t *addr,
5322 uint32_t index)
5323{
5324 uint32_t rar_low, rar_high;
5325
5326 /* HW expects these in little endian so we reverse the byte order
5327 * from network order (big endian) to little endian
5328 */
5329 rar_low = ((uint32_t) addr[0] |
5330 ((uint32_t) addr[1] << 8) |
5331 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005332 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005334 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5335 * unit hang.
5336 *
5337 * Description:
5338 * If there are any Rx frames queued up or otherwise present in the HW
5339 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5340 * hang. To work around this issue, we have to disable receives and
5341 * flush out all Rx frames before we enable RSS. To do so, we modify we
5342 * redirect all Rx traffic to manageability and then reset the HW.
5343 * This flushes away Rx frames, and (since the redirections to
5344 * manageability persists across resets) keeps new ones from coming in
5345 * while we work. Then, we clear the Address Valid AV bit for all MAC
5346 * addresses and undo the re-direction to manageability.
5347 * Now, frames are coming in again, but the MAC won't accept them, so
5348 * far so good. We now proceed to initialize RSS (if necessary) and
5349 * configure the Rx unit. Last, we re-enable the AV bits and continue
5350 * on our merry way.
5351 */
5352 switch (hw->mac_type) {
5353 case e1000_82571:
5354 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005355 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005356 if (hw->leave_av_bit_off == TRUE)
5357 break;
5358 default:
5359 /* Indicate to hardware the Address is Valid. */
5360 rar_high |= E1000_RAH_AV;
5361 break;
5362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363
5364 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005365 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005367 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368}
5369
5370/******************************************************************************
5371 * Writes a value to the specified offset in the VLAN filter table.
5372 *
5373 * hw - Struct containing variables accessed by shared code
5374 * offset - Offset in VLAN filer table to write
5375 * value - Value to write into VLAN filter table
5376 *****************************************************************************/
5377void
5378e1000_write_vfta(struct e1000_hw *hw,
5379 uint32_t offset,
5380 uint32_t value)
5381{
5382 uint32_t temp;
5383
5384 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5385 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5386 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005387 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005389 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390 } else {
5391 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005392 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 }
5394}
5395
5396/******************************************************************************
5397 * Clears the VLAN filer table
5398 *
5399 * hw - Struct containing variables accessed by shared code
5400 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005401static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402e1000_clear_vfta(struct e1000_hw *hw)
5403{
5404 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005405 uint32_t vfta_value = 0;
5406 uint32_t vfta_offset = 0;
5407 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005409 if (hw->mac_type == e1000_82573) {
5410 if (hw->mng_cookie.vlan_id != 0) {
5411 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5412 * ID. The following operations determine which 32b entry
5413 * (i.e. offset) into the array we want to set the VLAN ID
5414 * (i.e. bit) of the manageability unit. */
5415 vfta_offset = (hw->mng_cookie.vlan_id >>
5416 E1000_VFTA_ENTRY_SHIFT) &
5417 E1000_VFTA_ENTRY_MASK;
5418 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5419 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5420 }
5421 }
5422 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5423 /* If the offset we want to clear is the same offset of the
5424 * manageability VLAN ID, then clear all bits except that of the
5425 * manageability unit */
5426 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5427 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005428 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430}
5431
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005432static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433e1000_id_led_init(struct e1000_hw * hw)
5434{
5435 uint32_t ledctl;
5436 const uint32_t ledctl_mask = 0x000000FF;
5437 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5438 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5439 uint16_t eeprom_data, i, temp;
5440 const uint16_t led_mask = 0x0F;
5441
5442 DEBUGFUNC("e1000_id_led_init");
5443
5444 if(hw->mac_type < e1000_82540) {
5445 /* Nothing to do */
5446 return E1000_SUCCESS;
5447 }
5448
5449 ledctl = E1000_READ_REG(hw, LEDCTL);
5450 hw->ledctl_default = ledctl;
5451 hw->ledctl_mode1 = hw->ledctl_default;
5452 hw->ledctl_mode2 = hw->ledctl_default;
5453
5454 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5455 DEBUGOUT("EEPROM Read Error\n");
5456 return -E1000_ERR_EEPROM;
5457 }
5458 if((eeprom_data== ID_LED_RESERVED_0000) ||
5459 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
5460 for(i = 0; i < 4; i++) {
5461 temp = (eeprom_data >> (i << 2)) & led_mask;
5462 switch(temp) {
5463 case ID_LED_ON1_DEF2:
5464 case ID_LED_ON1_ON2:
5465 case ID_LED_ON1_OFF2:
5466 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5467 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5468 break;
5469 case ID_LED_OFF1_DEF2:
5470 case ID_LED_OFF1_ON2:
5471 case ID_LED_OFF1_OFF2:
5472 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5473 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5474 break;
5475 default:
5476 /* Do nothing */
5477 break;
5478 }
5479 switch(temp) {
5480 case ID_LED_DEF1_ON2:
5481 case ID_LED_ON1_ON2:
5482 case ID_LED_OFF1_ON2:
5483 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5484 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5485 break;
5486 case ID_LED_DEF1_OFF2:
5487 case ID_LED_ON1_OFF2:
5488 case ID_LED_OFF1_OFF2:
5489 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5490 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5491 break;
5492 default:
5493 /* Do nothing */
5494 break;
5495 }
5496 }
5497 return E1000_SUCCESS;
5498}
5499
5500/******************************************************************************
5501 * Prepares SW controlable LED for use and saves the current state of the LED.
5502 *
5503 * hw - Struct containing variables accessed by shared code
5504 *****************************************************************************/
5505int32_t
5506e1000_setup_led(struct e1000_hw *hw)
5507{
5508 uint32_t ledctl;
5509 int32_t ret_val = E1000_SUCCESS;
5510
5511 DEBUGFUNC("e1000_setup_led");
5512
5513 switch(hw->mac_type) {
5514 case e1000_82542_rev2_0:
5515 case e1000_82542_rev2_1:
5516 case e1000_82543:
5517 case e1000_82544:
5518 /* No setup necessary */
5519 break;
5520 case e1000_82541:
5521 case e1000_82547:
5522 case e1000_82541_rev_2:
5523 case e1000_82547_rev_2:
5524 /* Turn off PHY Smart Power Down (if enabled) */
5525 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
5526 &hw->phy_spd_default);
5527 if(ret_val)
5528 return ret_val;
5529 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5530 (uint16_t)(hw->phy_spd_default &
5531 ~IGP01E1000_GMII_SPD));
5532 if(ret_val)
5533 return ret_val;
5534 /* Fall Through */
5535 default:
5536 if(hw->media_type == e1000_media_type_fiber) {
5537 ledctl = E1000_READ_REG(hw, LEDCTL);
5538 /* Save current LEDCTL settings */
5539 hw->ledctl_default = ledctl;
5540 /* Turn off LED0 */
5541 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
5542 E1000_LEDCTL_LED0_BLINK |
5543 E1000_LEDCTL_LED0_MODE_MASK);
5544 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
5545 E1000_LEDCTL_LED0_MODE_SHIFT);
5546 E1000_WRITE_REG(hw, LEDCTL, ledctl);
5547 } else if(hw->media_type == e1000_media_type_copper)
5548 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5549 break;
5550 }
5551
5552 return E1000_SUCCESS;
5553}
5554
5555/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07005556 * Used on 82571 and later Si that has LED blink bits.
5557 * Callers must use their own timer and should have already called
5558 * e1000_id_led_init()
5559 * Call e1000_cleanup led() to stop blinking
5560 *
5561 * hw - Struct containing variables accessed by shared code
5562 *****************************************************************************/
5563int32_t
5564e1000_blink_led_start(struct e1000_hw *hw)
5565{
5566 int16_t i;
5567 uint32_t ledctl_blink = 0;
5568
5569 DEBUGFUNC("e1000_id_led_blink_on");
5570
5571 if (hw->mac_type < e1000_82571) {
5572 /* Nothing to do */
5573 return E1000_SUCCESS;
5574 }
5575 if (hw->media_type == e1000_media_type_fiber) {
5576 /* always blink LED0 for PCI-E fiber */
5577 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
5578 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
5579 } else {
5580 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
5581 ledctl_blink = hw->ledctl_mode2;
5582 for (i=0; i < 4; i++)
5583 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
5584 E1000_LEDCTL_MODE_LED_ON)
5585 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
5586 }
5587
5588 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
5589
5590 return E1000_SUCCESS;
5591}
5592
5593/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594 * Restores the saved state of the SW controlable LED.
5595 *
5596 * hw - Struct containing variables accessed by shared code
5597 *****************************************************************************/
5598int32_t
5599e1000_cleanup_led(struct e1000_hw *hw)
5600{
5601 int32_t ret_val = E1000_SUCCESS;
5602
5603 DEBUGFUNC("e1000_cleanup_led");
5604
5605 switch(hw->mac_type) {
5606 case e1000_82542_rev2_0:
5607 case e1000_82542_rev2_1:
5608 case e1000_82543:
5609 case e1000_82544:
5610 /* No cleanup necessary */
5611 break;
5612 case e1000_82541:
5613 case e1000_82547:
5614 case e1000_82541_rev_2:
5615 case e1000_82547_rev_2:
5616 /* Turn on PHY Smart Power Down (if previously enabled) */
5617 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5618 hw->phy_spd_default);
5619 if(ret_val)
5620 return ret_val;
5621 /* Fall Through */
5622 default:
5623 /* Restore LEDCTL settings */
5624 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
5625 break;
5626 }
5627
5628 return E1000_SUCCESS;
5629}
5630
5631/******************************************************************************
5632 * Turns on the software controllable LED
5633 *
5634 * hw - Struct containing variables accessed by shared code
5635 *****************************************************************************/
5636int32_t
5637e1000_led_on(struct e1000_hw *hw)
5638{
5639 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5640
5641 DEBUGFUNC("e1000_led_on");
5642
5643 switch(hw->mac_type) {
5644 case e1000_82542_rev2_0:
5645 case e1000_82542_rev2_1:
5646 case e1000_82543:
5647 /* Set SW Defineable Pin 0 to turn on the LED */
5648 ctrl |= E1000_CTRL_SWDPIN0;
5649 ctrl |= E1000_CTRL_SWDPIO0;
5650 break;
5651 case e1000_82544:
5652 if(hw->media_type == e1000_media_type_fiber) {
5653 /* Set SW Defineable Pin 0 to turn on the LED */
5654 ctrl |= E1000_CTRL_SWDPIN0;
5655 ctrl |= E1000_CTRL_SWDPIO0;
5656 } else {
5657 /* Clear SW Defineable Pin 0 to turn on the LED */
5658 ctrl &= ~E1000_CTRL_SWDPIN0;
5659 ctrl |= E1000_CTRL_SWDPIO0;
5660 }
5661 break;
5662 default:
5663 if(hw->media_type == e1000_media_type_fiber) {
5664 /* Clear SW Defineable Pin 0 to turn on the LED */
5665 ctrl &= ~E1000_CTRL_SWDPIN0;
5666 ctrl |= E1000_CTRL_SWDPIO0;
5667 } else if(hw->media_type == e1000_media_type_copper) {
5668 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
5669 return E1000_SUCCESS;
5670 }
5671 break;
5672 }
5673
5674 E1000_WRITE_REG(hw, CTRL, ctrl);
5675
5676 return E1000_SUCCESS;
5677}
5678
5679/******************************************************************************
5680 * Turns off the software controllable LED
5681 *
5682 * hw - Struct containing variables accessed by shared code
5683 *****************************************************************************/
5684int32_t
5685e1000_led_off(struct e1000_hw *hw)
5686{
5687 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5688
5689 DEBUGFUNC("e1000_led_off");
5690
5691 switch(hw->mac_type) {
5692 case e1000_82542_rev2_0:
5693 case e1000_82542_rev2_1:
5694 case e1000_82543:
5695 /* Clear SW Defineable Pin 0 to turn off the LED */
5696 ctrl &= ~E1000_CTRL_SWDPIN0;
5697 ctrl |= E1000_CTRL_SWDPIO0;
5698 break;
5699 case e1000_82544:
5700 if(hw->media_type == e1000_media_type_fiber) {
5701 /* Clear SW Defineable Pin 0 to turn off the LED */
5702 ctrl &= ~E1000_CTRL_SWDPIN0;
5703 ctrl |= E1000_CTRL_SWDPIO0;
5704 } else {
5705 /* Set SW Defineable Pin 0 to turn off the LED */
5706 ctrl |= E1000_CTRL_SWDPIN0;
5707 ctrl |= E1000_CTRL_SWDPIO0;
5708 }
5709 break;
5710 default:
5711 if(hw->media_type == e1000_media_type_fiber) {
5712 /* Set SW Defineable Pin 0 to turn off the LED */
5713 ctrl |= E1000_CTRL_SWDPIN0;
5714 ctrl |= E1000_CTRL_SWDPIO0;
5715 } else if(hw->media_type == e1000_media_type_copper) {
5716 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5717 return E1000_SUCCESS;
5718 }
5719 break;
5720 }
5721
5722 E1000_WRITE_REG(hw, CTRL, ctrl);
5723
5724 return E1000_SUCCESS;
5725}
5726
5727/******************************************************************************
5728 * Clears all hardware statistics counters.
5729 *
5730 * hw - Struct containing variables accessed by shared code
5731 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005732static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733e1000_clear_hw_cntrs(struct e1000_hw *hw)
5734{
5735 volatile uint32_t temp;
5736
5737 temp = E1000_READ_REG(hw, CRCERRS);
5738 temp = E1000_READ_REG(hw, SYMERRS);
5739 temp = E1000_READ_REG(hw, MPC);
5740 temp = E1000_READ_REG(hw, SCC);
5741 temp = E1000_READ_REG(hw, ECOL);
5742 temp = E1000_READ_REG(hw, MCC);
5743 temp = E1000_READ_REG(hw, LATECOL);
5744 temp = E1000_READ_REG(hw, COLC);
5745 temp = E1000_READ_REG(hw, DC);
5746 temp = E1000_READ_REG(hw, SEC);
5747 temp = E1000_READ_REG(hw, RLEC);
5748 temp = E1000_READ_REG(hw, XONRXC);
5749 temp = E1000_READ_REG(hw, XONTXC);
5750 temp = E1000_READ_REG(hw, XOFFRXC);
5751 temp = E1000_READ_REG(hw, XOFFTXC);
5752 temp = E1000_READ_REG(hw, FCRUC);
5753 temp = E1000_READ_REG(hw, PRC64);
5754 temp = E1000_READ_REG(hw, PRC127);
5755 temp = E1000_READ_REG(hw, PRC255);
5756 temp = E1000_READ_REG(hw, PRC511);
5757 temp = E1000_READ_REG(hw, PRC1023);
5758 temp = E1000_READ_REG(hw, PRC1522);
5759 temp = E1000_READ_REG(hw, GPRC);
5760 temp = E1000_READ_REG(hw, BPRC);
5761 temp = E1000_READ_REG(hw, MPRC);
5762 temp = E1000_READ_REG(hw, GPTC);
5763 temp = E1000_READ_REG(hw, GORCL);
5764 temp = E1000_READ_REG(hw, GORCH);
5765 temp = E1000_READ_REG(hw, GOTCL);
5766 temp = E1000_READ_REG(hw, GOTCH);
5767 temp = E1000_READ_REG(hw, RNBC);
5768 temp = E1000_READ_REG(hw, RUC);
5769 temp = E1000_READ_REG(hw, RFC);
5770 temp = E1000_READ_REG(hw, ROC);
5771 temp = E1000_READ_REG(hw, RJC);
5772 temp = E1000_READ_REG(hw, TORL);
5773 temp = E1000_READ_REG(hw, TORH);
5774 temp = E1000_READ_REG(hw, TOTL);
5775 temp = E1000_READ_REG(hw, TOTH);
5776 temp = E1000_READ_REG(hw, TPR);
5777 temp = E1000_READ_REG(hw, TPT);
5778 temp = E1000_READ_REG(hw, PTC64);
5779 temp = E1000_READ_REG(hw, PTC127);
5780 temp = E1000_READ_REG(hw, PTC255);
5781 temp = E1000_READ_REG(hw, PTC511);
5782 temp = E1000_READ_REG(hw, PTC1023);
5783 temp = E1000_READ_REG(hw, PTC1522);
5784 temp = E1000_READ_REG(hw, MPTC);
5785 temp = E1000_READ_REG(hw, BPTC);
5786
5787 if(hw->mac_type < e1000_82543) return;
5788
5789 temp = E1000_READ_REG(hw, ALGNERRC);
5790 temp = E1000_READ_REG(hw, RXERRC);
5791 temp = E1000_READ_REG(hw, TNCRS);
5792 temp = E1000_READ_REG(hw, CEXTERR);
5793 temp = E1000_READ_REG(hw, TSCTC);
5794 temp = E1000_READ_REG(hw, TSCTFC);
5795
5796 if(hw->mac_type <= e1000_82544) return;
5797
5798 temp = E1000_READ_REG(hw, MGTPRC);
5799 temp = E1000_READ_REG(hw, MGTPDC);
5800 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005801
5802 if(hw->mac_type <= e1000_82547_rev_2) return;
5803
5804 temp = E1000_READ_REG(hw, IAC);
5805 temp = E1000_READ_REG(hw, ICRXOC);
5806 temp = E1000_READ_REG(hw, ICRXPTC);
5807 temp = E1000_READ_REG(hw, ICRXATC);
5808 temp = E1000_READ_REG(hw, ICTXPTC);
5809 temp = E1000_READ_REG(hw, ICTXATC);
5810 temp = E1000_READ_REG(hw, ICTXQEC);
5811 temp = E1000_READ_REG(hw, ICTXQMTC);
5812 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813}
5814
5815/******************************************************************************
5816 * Resets Adaptive IFS to its default state.
5817 *
5818 * hw - Struct containing variables accessed by shared code
5819 *
5820 * Call this after e1000_init_hw. You may override the IFS defaults by setting
5821 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5822 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5823 * before calling this function.
5824 *****************************************************************************/
5825void
5826e1000_reset_adaptive(struct e1000_hw *hw)
5827{
5828 DEBUGFUNC("e1000_reset_adaptive");
5829
5830 if(hw->adaptive_ifs) {
5831 if(!hw->ifs_params_forced) {
5832 hw->current_ifs_val = 0;
5833 hw->ifs_min_val = IFS_MIN;
5834 hw->ifs_max_val = IFS_MAX;
5835 hw->ifs_step_size = IFS_STEP;
5836 hw->ifs_ratio = IFS_RATIO;
5837 }
5838 hw->in_ifs_mode = FALSE;
5839 E1000_WRITE_REG(hw, AIT, 0);
5840 } else {
5841 DEBUGOUT("Not in Adaptive IFS mode!\n");
5842 }
5843}
5844
5845/******************************************************************************
5846 * Called during the callback/watchdog routine to update IFS value based on
5847 * the ratio of transmits to collisions.
5848 *
5849 * hw - Struct containing variables accessed by shared code
5850 * tx_packets - Number of transmits since last callback
5851 * total_collisions - Number of collisions since last callback
5852 *****************************************************************************/
5853void
5854e1000_update_adaptive(struct e1000_hw *hw)
5855{
5856 DEBUGFUNC("e1000_update_adaptive");
5857
5858 if(hw->adaptive_ifs) {
5859 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5860 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5861 hw->in_ifs_mode = TRUE;
5862 if(hw->current_ifs_val < hw->ifs_max_val) {
5863 if(hw->current_ifs_val == 0)
5864 hw->current_ifs_val = hw->ifs_min_val;
5865 else
5866 hw->current_ifs_val += hw->ifs_step_size;
5867 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5868 }
5869 }
5870 } else {
5871 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5872 hw->current_ifs_val = 0;
5873 hw->in_ifs_mode = FALSE;
5874 E1000_WRITE_REG(hw, AIT, 0);
5875 }
5876 }
5877 } else {
5878 DEBUGOUT("Not in Adaptive IFS mode!\n");
5879 }
5880}
5881
5882/******************************************************************************
5883 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5884 *
5885 * hw - Struct containing variables accessed by shared code
5886 * frame_len - The length of the frame in question
5887 * mac_addr - The Ethernet destination address of the frame in question
5888 *****************************************************************************/
5889void
5890e1000_tbi_adjust_stats(struct e1000_hw *hw,
5891 struct e1000_hw_stats *stats,
5892 uint32_t frame_len,
5893 uint8_t *mac_addr)
5894{
5895 uint64_t carry_bit;
5896
5897 /* First adjust the frame length. */
5898 frame_len--;
5899 /* We need to adjust the statistics counters, since the hardware
5900 * counters overcount this packet as a CRC error and undercount
5901 * the packet as a good packet
5902 */
5903 /* This packet should not be counted as a CRC error. */
5904 stats->crcerrs--;
5905 /* This packet does count as a Good Packet Received. */
5906 stats->gprc++;
5907
5908 /* Adjust the Good Octets received counters */
5909 carry_bit = 0x80000000 & stats->gorcl;
5910 stats->gorcl += frame_len;
5911 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5912 * Received Count) was one before the addition,
5913 * AND it is zero after, then we lost the carry out,
5914 * need to add one to Gorch (Good Octets Received Count High).
5915 * This could be simplified if all environments supported
5916 * 64-bit integers.
5917 */
5918 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5919 stats->gorch++;
5920 /* Is this a broadcast or multicast? Check broadcast first,
5921 * since the test for a multicast frame will test positive on
5922 * a broadcast frame.
5923 */
5924 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5925 /* Broadcast packet */
5926 stats->bprc++;
5927 else if(*mac_addr & 0x01)
5928 /* Multicast packet */
5929 stats->mprc++;
5930
5931 if(frame_len == hw->max_frame_size) {
5932 /* In this case, the hardware has overcounted the number of
5933 * oversize frames.
5934 */
5935 if(stats->roc > 0)
5936 stats->roc--;
5937 }
5938
5939 /* Adjust the bin counters when the extra byte put the frame in the
5940 * wrong bin. Remember that the frame_len was adjusted above.
5941 */
5942 if(frame_len == 64) {
5943 stats->prc64++;
5944 stats->prc127--;
5945 } else if(frame_len == 127) {
5946 stats->prc127++;
5947 stats->prc255--;
5948 } else if(frame_len == 255) {
5949 stats->prc255++;
5950 stats->prc511--;
5951 } else if(frame_len == 511) {
5952 stats->prc511++;
5953 stats->prc1023--;
5954 } else if(frame_len == 1023) {
5955 stats->prc1023++;
5956 stats->prc1522--;
5957 } else if(frame_len == 1522) {
5958 stats->prc1522++;
5959 }
5960}
5961
5962/******************************************************************************
5963 * Gets the current PCI bus type, speed, and width of the hardware
5964 *
5965 * hw - Struct containing variables accessed by shared code
5966 *****************************************************************************/
5967void
5968e1000_get_bus_info(struct e1000_hw *hw)
5969{
5970 uint32_t status;
5971
5972 switch (hw->mac_type) {
5973 case e1000_82542_rev2_0:
5974 case e1000_82542_rev2_1:
5975 hw->bus_type = e1000_bus_type_unknown;
5976 hw->bus_speed = e1000_bus_speed_unknown;
5977 hw->bus_width = e1000_bus_width_unknown;
5978 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005979 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005980 case e1000_82573:
5981 hw->bus_type = e1000_bus_type_pci_express;
5982 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirsherfd803242005-12-13 00:06:22 -05005983 hw->bus_width = e1000_bus_width_pciex_1;
5984 break;
5985 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005986 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05005987 hw->bus_type = e1000_bus_type_pci_express;
5988 hw->bus_speed = e1000_bus_speed_2500;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005989 hw->bus_width = e1000_bus_width_pciex_4;
5990 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 default:
5992 status = E1000_READ_REG(hw, STATUS);
5993 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5994 e1000_bus_type_pcix : e1000_bus_type_pci;
5995
5996 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5997 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5998 e1000_bus_speed_66 : e1000_bus_speed_120;
5999 } else if(hw->bus_type == e1000_bus_type_pci) {
6000 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6001 e1000_bus_speed_66 : e1000_bus_speed_33;
6002 } else {
6003 switch (status & E1000_STATUS_PCIX_SPEED) {
6004 case E1000_STATUS_PCIX_SPEED_66:
6005 hw->bus_speed = e1000_bus_speed_66;
6006 break;
6007 case E1000_STATUS_PCIX_SPEED_100:
6008 hw->bus_speed = e1000_bus_speed_100;
6009 break;
6010 case E1000_STATUS_PCIX_SPEED_133:
6011 hw->bus_speed = e1000_bus_speed_133;
6012 break;
6013 default:
6014 hw->bus_speed = e1000_bus_speed_reserved;
6015 break;
6016 }
6017 }
6018 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6019 e1000_bus_width_64 : e1000_bus_width_32;
6020 break;
6021 }
6022}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006023
6024#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025/******************************************************************************
6026 * Reads a value from one of the devices registers using port I/O (as opposed
6027 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6028 *
6029 * hw - Struct containing variables accessed by shared code
6030 * offset - offset to read from
6031 *****************************************************************************/
6032uint32_t
6033e1000_read_reg_io(struct e1000_hw *hw,
6034 uint32_t offset)
6035{
6036 unsigned long io_addr = hw->io_base;
6037 unsigned long io_data = hw->io_base + 4;
6038
6039 e1000_io_write(hw, io_addr, offset);
6040 return e1000_io_read(hw, io_data);
6041}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006042#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043
6044/******************************************************************************
6045 * Writes a value to one of the devices registers using port I/O (as opposed to
6046 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6047 *
6048 * hw - Struct containing variables accessed by shared code
6049 * offset - offset to write to
6050 * value - value to write
6051 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006052static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053e1000_write_reg_io(struct e1000_hw *hw,
6054 uint32_t offset,
6055 uint32_t value)
6056{
6057 unsigned long io_addr = hw->io_base;
6058 unsigned long io_data = hw->io_base + 4;
6059
6060 e1000_io_write(hw, io_addr, offset);
6061 e1000_io_write(hw, io_data, value);
6062}
6063
6064
6065/******************************************************************************
6066 * Estimates the cable length.
6067 *
6068 * hw - Struct containing variables accessed by shared code
6069 * min_length - The estimated minimum length
6070 * max_length - The estimated maximum length
6071 *
6072 * returns: - E1000_ERR_XXX
6073 * E1000_SUCCESS
6074 *
6075 * This function always returns a ranged length (minimum & maximum).
6076 * So for M88 phy's, this function interprets the one value returned from the
6077 * register to the minimum and maximum range.
6078 * For IGP phy's, the function calculates the range by the AGC registers.
6079 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006080static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081e1000_get_cable_length(struct e1000_hw *hw,
6082 uint16_t *min_length,
6083 uint16_t *max_length)
6084{
6085 int32_t ret_val;
6086 uint16_t agc_value = 0;
6087 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006088 uint16_t max_agc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 uint16_t i, phy_data;
6090 uint16_t cable_length;
6091
6092 DEBUGFUNC("e1000_get_cable_length");
6093
6094 *min_length = *max_length = 0;
6095
6096 /* Use old method for Phy older than IGP */
6097 if(hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006098
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6100 &phy_data);
6101 if(ret_val)
6102 return ret_val;
6103 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6104 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6105
6106 /* Convert the enum value to ranged values */
6107 switch (cable_length) {
6108 case e1000_cable_length_50:
6109 *min_length = 0;
6110 *max_length = e1000_igp_cable_length_50;
6111 break;
6112 case e1000_cable_length_50_80:
6113 *min_length = e1000_igp_cable_length_50;
6114 *max_length = e1000_igp_cable_length_80;
6115 break;
6116 case e1000_cable_length_80_110:
6117 *min_length = e1000_igp_cable_length_80;
6118 *max_length = e1000_igp_cable_length_110;
6119 break;
6120 case e1000_cable_length_110_140:
6121 *min_length = e1000_igp_cable_length_110;
6122 *max_length = e1000_igp_cable_length_140;
6123 break;
6124 case e1000_cable_length_140:
6125 *min_length = e1000_igp_cable_length_140;
6126 *max_length = e1000_igp_cable_length_170;
6127 break;
6128 default:
6129 return -E1000_ERR_PHY;
6130 break;
6131 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006132 } else if (hw->phy_type == e1000_phy_gg82563) {
6133 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6134 &phy_data);
6135 if (ret_val)
6136 return ret_val;
6137 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6138
6139 switch (cable_length) {
6140 case e1000_gg_cable_length_60:
6141 *min_length = 0;
6142 *max_length = e1000_igp_cable_length_60;
6143 break;
6144 case e1000_gg_cable_length_60_115:
6145 *min_length = e1000_igp_cable_length_60;
6146 *max_length = e1000_igp_cable_length_115;
6147 break;
6148 case e1000_gg_cable_length_115_150:
6149 *min_length = e1000_igp_cable_length_115;
6150 *max_length = e1000_igp_cable_length_150;
6151 break;
6152 case e1000_gg_cable_length_150:
6153 *min_length = e1000_igp_cable_length_150;
6154 *max_length = e1000_igp_cable_length_180;
6155 break;
6156 default:
6157 return -E1000_ERR_PHY;
6158 break;
6159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6161 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6162 {IGP01E1000_PHY_AGC_A,
6163 IGP01E1000_PHY_AGC_B,
6164 IGP01E1000_PHY_AGC_C,
6165 IGP01E1000_PHY_AGC_D};
6166 /* Read the AGC registers for all channels */
6167 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6168
6169 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6170 if(ret_val)
6171 return ret_val;
6172
6173 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6174
6175 /* Array bound check. */
6176 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6177 (cur_agc == 0))
6178 return -E1000_ERR_PHY;
6179
6180 agc_value += cur_agc;
6181
6182 /* Update minimal AGC value. */
6183 if(min_agc > cur_agc)
6184 min_agc = cur_agc;
6185 }
6186
6187 /* Remove the minimal AGC result for length < 50m */
6188 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6189 agc_value -= min_agc;
6190
6191 /* Get the average length of the remaining 3 channels */
6192 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6193 } else {
6194 /* Get the average length of all the 4 channels. */
6195 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6196 }
6197
6198 /* Set the range of the calculated length. */
6199 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6200 IGP01E1000_AGC_RANGE) > 0) ?
6201 (e1000_igp_cable_length_table[agc_value] -
6202 IGP01E1000_AGC_RANGE) : 0;
6203 *max_length = e1000_igp_cable_length_table[agc_value] +
6204 IGP01E1000_AGC_RANGE;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006205 } else if (hw->phy_type == e1000_phy_igp_2) {
6206 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6207 {IGP02E1000_PHY_AGC_A,
6208 IGP02E1000_PHY_AGC_B,
6209 IGP02E1000_PHY_AGC_C,
6210 IGP02E1000_PHY_AGC_D};
6211 /* Read the AGC registers for all channels */
6212 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6213 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6214 if (ret_val)
6215 return ret_val;
6216
6217 /* Getting bits 15:9, which represent the combination of course and
6218 * fine gain values. The result is a number that can be put into
6219 * the lookup table to obtain the approximate cable length. */
6220 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6221 IGP02E1000_AGC_LENGTH_MASK;
6222
6223 /* Remove min & max AGC values from calculation. */
6224 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
6225 min_agc = cur_agc;
6226 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
6227 max_agc = cur_agc;
6228
6229 agc_value += e1000_igp_2_cable_length_table[cur_agc];
6230 }
6231
6232 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
6233 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6234
6235 /* Calculate cable length with the error range of +/- 10 meters. */
6236 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6237 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6238 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 }
6240
6241 return E1000_SUCCESS;
6242}
6243
6244/******************************************************************************
6245 * Check the cable polarity
6246 *
6247 * hw - Struct containing variables accessed by shared code
6248 * polarity - output parameter : 0 - Polarity is not reversed
6249 * 1 - Polarity is reversed.
6250 *
6251 * returns: - E1000_ERR_XXX
6252 * E1000_SUCCESS
6253 *
6254 * For phy's older then IGP, this function simply reads the polarity bit in the
6255 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6256 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6257 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6258 * IGP01E1000_PHY_PCS_INIT_REG.
6259 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006260static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261e1000_check_polarity(struct e1000_hw *hw,
6262 uint16_t *polarity)
6263{
6264 int32_t ret_val;
6265 uint16_t phy_data;
6266
6267 DEBUGFUNC("e1000_check_polarity");
6268
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006269 if ((hw->phy_type == e1000_phy_m88) ||
6270 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 /* return the Polarity bit in the Status register. */
6272 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6273 &phy_data);
6274 if(ret_val)
6275 return ret_val;
6276 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6277 M88E1000_PSSR_REV_POLARITY_SHIFT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006278 } else if(hw->phy_type == e1000_phy_igp ||
6279 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280 /* Read the Status register to check the speed */
6281 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6282 &phy_data);
6283 if(ret_val)
6284 return ret_val;
6285
6286 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6287 * find the polarity status */
6288 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6289 IGP01E1000_PSSR_SPEED_1000MBPS) {
6290
6291 /* Read the GIG initialization PCS register (0x00B4) */
6292 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6293 &phy_data);
6294 if(ret_val)
6295 return ret_val;
6296
6297 /* Check the polarity bits */
6298 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6299 } else {
6300 /* For 10 Mbps, read the polarity bit in the status register. (for
6301 * 100 Mbps this bit is always 0) */
6302 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6303 }
6304 }
6305 return E1000_SUCCESS;
6306}
6307
6308/******************************************************************************
6309 * Check if Downshift occured
6310 *
6311 * hw - Struct containing variables accessed by shared code
6312 * downshift - output parameter : 0 - No Downshift ocured.
6313 * 1 - Downshift ocured.
6314 *
6315 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006316 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 *
6318 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6319 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6320 * Link Health register. In IGP this bit is latched high, so the driver must
6321 * read it immediately after link is established.
6322 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006323static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324e1000_check_downshift(struct e1000_hw *hw)
6325{
6326 int32_t ret_val;
6327 uint16_t phy_data;
6328
6329 DEBUGFUNC("e1000_check_downshift");
6330
Auke Kok76c224b2006-05-23 13:36:06 -07006331 if(hw->phy_type == e1000_phy_igp ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006332 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6334 &phy_data);
6335 if(ret_val)
6336 return ret_val;
6337
6338 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006339 } else if ((hw->phy_type == e1000_phy_m88) ||
6340 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6342 &phy_data);
6343 if(ret_val)
6344 return ret_val;
6345
6346 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6347 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6348 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006349
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 return E1000_SUCCESS;
6351}
6352
6353/*****************************************************************************
6354 *
6355 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6356 * gigabit link is achieved to improve link quality.
6357 *
6358 * hw: Struct containing variables accessed by shared code
6359 *
6360 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6361 * E1000_SUCCESS at any other case.
6362 *
6363 ****************************************************************************/
6364
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006365static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6367 boolean_t link_up)
6368{
6369 int32_t ret_val;
6370 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6371 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6372 {IGP01E1000_PHY_AGC_PARAM_A,
6373 IGP01E1000_PHY_AGC_PARAM_B,
6374 IGP01E1000_PHY_AGC_PARAM_C,
6375 IGP01E1000_PHY_AGC_PARAM_D};
6376 uint16_t min_length, max_length;
6377
6378 DEBUGFUNC("e1000_config_dsp_after_link_change");
6379
6380 if(hw->phy_type != e1000_phy_igp)
6381 return E1000_SUCCESS;
6382
6383 if(link_up) {
6384 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
6385 if(ret_val) {
6386 DEBUGOUT("Error getting link speed and duplex\n");
6387 return ret_val;
6388 }
6389
6390 if(speed == SPEED_1000) {
6391
6392 e1000_get_cable_length(hw, &min_length, &max_length);
6393
6394 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6395 min_length >= e1000_igp_cable_length_50) {
6396
6397 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6398 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6399 &phy_data);
6400 if(ret_val)
6401 return ret_val;
6402
6403 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6404
6405 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
6406 phy_data);
6407 if(ret_val)
6408 return ret_val;
6409 }
6410 hw->dsp_config_state = e1000_dsp_config_activated;
6411 }
6412
6413 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
6414 (min_length < e1000_igp_cable_length_50)) {
6415
6416 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6417 uint32_t idle_errs = 0;
6418
6419 /* clear previous idle error counts */
6420 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6421 &phy_data);
6422 if(ret_val)
6423 return ret_val;
6424
6425 for(i = 0; i < ffe_idle_err_timeout; i++) {
6426 udelay(1000);
6427 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6428 &phy_data);
6429 if(ret_val)
6430 return ret_val;
6431
6432 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
6433 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
6434 hw->ffe_config_state = e1000_ffe_config_active;
6435
6436 ret_val = e1000_write_phy_reg(hw,
6437 IGP01E1000_PHY_DSP_FFE,
6438 IGP01E1000_PHY_DSP_FFE_CM_CP);
6439 if(ret_val)
6440 return ret_val;
6441 break;
6442 }
6443
6444 if(idle_errs)
6445 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6446 }
6447 }
6448 }
6449 } else {
6450 if(hw->dsp_config_state == e1000_dsp_config_activated) {
6451 /* Save off the current value of register 0x2F5B to be restored at
6452 * the end of the routines. */
6453 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6454
6455 if(ret_val)
6456 return ret_val;
6457
6458 /* Disable the PHY transmitter */
6459 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6460
6461 if(ret_val)
6462 return ret_val;
6463
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006464 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465
6466 ret_val = e1000_write_phy_reg(hw, 0x0000,
6467 IGP01E1000_IEEE_FORCE_GIGA);
6468 if(ret_val)
6469 return ret_val;
6470 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6471 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
6472 if(ret_val)
6473 return ret_val;
6474
6475 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6476 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6477
6478 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
6479 if(ret_val)
6480 return ret_val;
6481 }
6482
6483 ret_val = e1000_write_phy_reg(hw, 0x0000,
6484 IGP01E1000_IEEE_RESTART_AUTONEG);
6485 if(ret_val)
6486 return ret_val;
6487
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006488 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489
6490 /* Now enable the transmitter */
6491 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6492
6493 if(ret_val)
6494 return ret_val;
6495
6496 hw->dsp_config_state = e1000_dsp_config_enabled;
6497 }
6498
6499 if(hw->ffe_config_state == e1000_ffe_config_active) {
6500 /* Save off the current value of register 0x2F5B to be restored at
6501 * the end of the routines. */
6502 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6503
6504 if(ret_val)
6505 return ret_val;
6506
6507 /* Disable the PHY transmitter */
6508 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6509
6510 if(ret_val)
6511 return ret_val;
6512
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006513 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514
6515 ret_val = e1000_write_phy_reg(hw, 0x0000,
6516 IGP01E1000_IEEE_FORCE_GIGA);
6517 if(ret_val)
6518 return ret_val;
6519 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6520 IGP01E1000_PHY_DSP_FFE_DEFAULT);
6521 if(ret_val)
6522 return ret_val;
6523
6524 ret_val = e1000_write_phy_reg(hw, 0x0000,
6525 IGP01E1000_IEEE_RESTART_AUTONEG);
6526 if(ret_val)
6527 return ret_val;
6528
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006529 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530
6531 /* Now enable the transmitter */
6532 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6533
6534 if(ret_val)
6535 return ret_val;
6536
6537 hw->ffe_config_state = e1000_ffe_config_enabled;
6538 }
6539 }
6540 return E1000_SUCCESS;
6541}
6542
6543/*****************************************************************************
6544 * Set PHY to class A mode
6545 * Assumes the following operations will follow to enable the new class mode.
6546 * 1. Do a PHY soft reset
6547 * 2. Restart auto-negotiation or force link.
6548 *
6549 * hw - Struct containing variables accessed by shared code
6550 ****************************************************************************/
6551static int32_t
6552e1000_set_phy_mode(struct e1000_hw *hw)
6553{
6554 int32_t ret_val;
6555 uint16_t eeprom_data;
6556
6557 DEBUGFUNC("e1000_set_phy_mode");
6558
6559 if((hw->mac_type == e1000_82545_rev_3) &&
6560 (hw->media_type == e1000_media_type_copper)) {
6561 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
6562 if(ret_val) {
6563 return ret_val;
6564 }
6565
6566 if((eeprom_data != EEPROM_RESERVED_WORD) &&
6567 (eeprom_data & EEPROM_PHY_CLASS_A)) {
6568 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
6569 if(ret_val)
6570 return ret_val;
6571 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
6572 if(ret_val)
6573 return ret_val;
6574
6575 hw->phy_reset_disable = FALSE;
6576 }
6577 }
6578
6579 return E1000_SUCCESS;
6580}
6581
6582/*****************************************************************************
6583 *
6584 * This function sets the lplu state according to the active flag. When
6585 * activating lplu this function also disables smart speed and vise versa.
6586 * lplu will not be activated unless the device autonegotiation advertisment
6587 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6588 * hw: Struct containing variables accessed by shared code
6589 * active - true to enable lplu false to disable lplu.
6590 *
6591 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6592 * E1000_SUCCESS at any other case.
6593 *
6594 ****************************************************************************/
6595
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006596static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597e1000_set_d3_lplu_state(struct e1000_hw *hw,
6598 boolean_t active)
6599{
6600 int32_t ret_val;
6601 uint16_t phy_data;
6602 DEBUGFUNC("e1000_set_d3_lplu_state");
6603
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006604 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605 return E1000_SUCCESS;
6606
6607 /* During driver activity LPLU should not be used or it will attain link
6608 * from the lowest speeds starting from 10Mbps. The capability is used for
6609 * Dx transitions and states */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006610 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
6611 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612 if(ret_val)
6613 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006614 } else {
6615 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6616 if(ret_val)
6617 return ret_val;
6618 }
6619
6620 if(!active) {
6621 if(hw->mac_type == e1000_82541_rev_2 ||
6622 hw->mac_type == e1000_82547_rev_2) {
6623 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
6624 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6625 if(ret_val)
6626 return ret_val;
6627 } else {
6628 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6629 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6630 phy_data);
6631 if (ret_val)
6632 return ret_val;
6633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634
6635 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6636 * Dx states where the power conservation is most important. During
6637 * driver activity we should enable SmartSpeed, so performance is
6638 * maintained. */
6639 if (hw->smart_speed == e1000_smart_speed_on) {
6640 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6641 &phy_data);
6642 if(ret_val)
6643 return ret_val;
6644
6645 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6646 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6647 phy_data);
6648 if(ret_val)
6649 return ret_val;
6650 } else if (hw->smart_speed == e1000_smart_speed_off) {
6651 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6652 &phy_data);
6653 if (ret_val)
6654 return ret_val;
6655
6656 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6657 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6658 phy_data);
6659 if(ret_val)
6660 return ret_val;
6661 }
6662
6663 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
6664 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
6665 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6666
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006667 if(hw->mac_type == e1000_82541_rev_2 ||
6668 hw->mac_type == e1000_82547_rev_2) {
6669 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6670 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6671 if(ret_val)
6672 return ret_val;
6673 } else {
6674 phy_data |= IGP02E1000_PM_D3_LPLU;
6675 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6676 phy_data);
6677 if (ret_val)
6678 return ret_val;
6679 }
6680
6681 /* When LPLU is enabled we should disable SmartSpeed */
6682 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 if(ret_val)
6684 return ret_val;
6685
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006686 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6687 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6688 if(ret_val)
6689 return ret_val;
6690
6691 }
6692 return E1000_SUCCESS;
6693}
6694
6695/*****************************************************************************
6696 *
6697 * This function sets the lplu d0 state according to the active flag. When
6698 * activating lplu this function also disables smart speed and vise versa.
6699 * lplu will not be activated unless the device autonegotiation advertisment
6700 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6701 * hw: Struct containing variables accessed by shared code
6702 * active - true to enable lplu false to disable lplu.
6703 *
6704 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6705 * E1000_SUCCESS at any other case.
6706 *
6707 ****************************************************************************/
6708
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006709static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006710e1000_set_d0_lplu_state(struct e1000_hw *hw,
6711 boolean_t active)
6712{
6713 int32_t ret_val;
6714 uint16_t phy_data;
6715 DEBUGFUNC("e1000_set_d0_lplu_state");
6716
6717 if(hw->mac_type <= e1000_82547_rev_2)
6718 return E1000_SUCCESS;
6719
6720 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6721 if(ret_val)
6722 return ret_val;
6723
6724 if (!active) {
6725 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6726 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6727 if (ret_val)
6728 return ret_val;
6729
6730 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6731 * Dx states where the power conservation is most important. During
6732 * driver activity we should enable SmartSpeed, so performance is
6733 * maintained. */
6734 if (hw->smart_speed == e1000_smart_speed_on) {
6735 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6736 &phy_data);
6737 if(ret_val)
6738 return ret_val;
6739
6740 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6741 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6742 phy_data);
6743 if(ret_val)
6744 return ret_val;
6745 } else if (hw->smart_speed == e1000_smart_speed_off) {
6746 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6747 &phy_data);
6748 if (ret_val)
6749 return ret_val;
6750
6751 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6752 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6753 phy_data);
6754 if(ret_val)
6755 return ret_val;
6756 }
6757
6758
6759 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07006760
6761 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006762 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6763 if (ret_val)
6764 return ret_val;
6765
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 /* When LPLU is enabled we should disable SmartSpeed */
6767 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6768 if(ret_val)
6769 return ret_val;
6770
6771 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6772 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6773 if(ret_val)
6774 return ret_val;
6775
6776 }
6777 return E1000_SUCCESS;
6778}
6779
6780/******************************************************************************
6781 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6782 *
6783 * hw - Struct containing variables accessed by shared code
6784 *****************************************************************************/
6785static int32_t
6786e1000_set_vco_speed(struct e1000_hw *hw)
6787{
6788 int32_t ret_val;
6789 uint16_t default_page = 0;
6790 uint16_t phy_data;
6791
6792 DEBUGFUNC("e1000_set_vco_speed");
6793
6794 switch(hw->mac_type) {
6795 case e1000_82545_rev_3:
6796 case e1000_82546_rev_3:
6797 break;
6798 default:
6799 return E1000_SUCCESS;
6800 }
6801
6802 /* Set PHY register 30, page 5, bit 8 to 0 */
6803
6804 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6805 if(ret_val)
6806 return ret_val;
6807
6808 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6809 if(ret_val)
6810 return ret_val;
6811
6812 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6813 if(ret_val)
6814 return ret_val;
6815
6816 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6817 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6818 if(ret_val)
6819 return ret_val;
6820
6821 /* Set PHY register 30, page 4, bit 11 to 1 */
6822
6823 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6824 if(ret_val)
6825 return ret_val;
6826
6827 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6828 if(ret_val)
6829 return ret_val;
6830
6831 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6832 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6833 if(ret_val)
6834 return ret_val;
6835
6836 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6837 if(ret_val)
6838 return ret_val;
6839
6840 return E1000_SUCCESS;
6841}
6842
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006843
6844/*****************************************************************************
6845 * This function reads the cookie from ARC ram.
6846 *
6847 * returns: - E1000_SUCCESS .
6848 ****************************************************************************/
6849int32_t
6850e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
6851{
6852 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07006853 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006854 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6855
6856 length = (length >> 2);
6857 offset = (offset >> 2);
6858
6859 for (i = 0; i < length; i++) {
6860 *((uint32_t *) buffer + i) =
6861 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6862 }
6863 return E1000_SUCCESS;
6864}
6865
6866
6867/*****************************************************************************
6868 * This function checks whether the HOST IF is enabled for command operaton
6869 * and also checks whether the previous command is completed.
6870 * It busy waits in case of previous command is not completed.
6871 *
Auke Kok76c224b2006-05-23 13:36:06 -07006872 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006873 * timeout
6874 * - E1000_SUCCESS for success.
6875 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006876static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006877e1000_mng_enable_host_if(struct e1000_hw * hw)
6878{
6879 uint32_t hicr;
6880 uint8_t i;
6881
6882 /* Check that the host interface is enabled. */
6883 hicr = E1000_READ_REG(hw, HICR);
6884 if ((hicr & E1000_HICR_EN) == 0) {
6885 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6886 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6887 }
6888 /* check the previous command is completed */
6889 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6890 hicr = E1000_READ_REG(hw, HICR);
6891 if (!(hicr & E1000_HICR_C))
6892 break;
6893 msec_delay_irq(1);
6894 }
6895
Auke Kok76c224b2006-05-23 13:36:06 -07006896 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006897 DEBUGOUT("Previous command timeout failed .\n");
6898 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6899 }
6900 return E1000_SUCCESS;
6901}
6902
6903/*****************************************************************************
6904 * This function writes the buffer content at the offset given on the host if.
6905 * It also does alignment considerations to do the writes in most efficient way.
6906 * Also fills up the sum of the buffer in *buffer parameter.
6907 *
6908 * returns - E1000_SUCCESS for success.
6909 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006910static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006911e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6912 uint16_t length, uint16_t offset, uint8_t *sum)
6913{
6914 uint8_t *tmp;
6915 uint8_t *bufptr = buffer;
6916 uint32_t data;
6917 uint16_t remaining, i, j, prev_bytes;
6918
6919 /* sum = only sum of the data and it is not checksum */
6920
6921 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6922 return -E1000_ERR_PARAM;
6923 }
6924
6925 tmp = (uint8_t *)&data;
6926 prev_bytes = offset & 0x3;
6927 offset &= 0xFFFC;
6928 offset >>= 2;
6929
6930 if (prev_bytes) {
6931 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6932 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6933 *(tmp + j) = *bufptr++;
6934 *sum += *(tmp + j);
6935 }
6936 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6937 length -= j - prev_bytes;
6938 offset++;
6939 }
6940
6941 remaining = length & 0x3;
6942 length -= remaining;
6943
6944 /* Calculate length in DWORDs */
6945 length >>= 2;
6946
6947 /* The device driver writes the relevant command block into the
6948 * ram area. */
6949 for (i = 0; i < length; i++) {
6950 for (j = 0; j < sizeof(uint32_t); j++) {
6951 *(tmp + j) = *bufptr++;
6952 *sum += *(tmp + j);
6953 }
6954
6955 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6956 }
6957 if (remaining) {
6958 for (j = 0; j < sizeof(uint32_t); j++) {
6959 if (j < remaining)
6960 *(tmp + j) = *bufptr++;
6961 else
6962 *(tmp + j) = 0;
6963
6964 *sum += *(tmp + j);
6965 }
6966 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6967 }
6968
6969 return E1000_SUCCESS;
6970}
6971
6972
6973/*****************************************************************************
6974 * This function writes the command header after does the checksum calculation.
6975 *
6976 * returns - E1000_SUCCESS for success.
6977 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006978static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006979e1000_mng_write_cmd_header(struct e1000_hw * hw,
6980 struct e1000_host_mng_command_header * hdr)
6981{
6982 uint16_t i;
6983 uint8_t sum;
6984 uint8_t *buffer;
6985
6986 /* Write the whole command header structure which includes sum of
6987 * the buffer */
6988
6989 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6990
6991 sum = hdr->checksum;
6992 hdr->checksum = 0;
6993
6994 buffer = (uint8_t *) hdr;
6995 i = length;
6996 while(i--)
6997 sum += buffer[i];
6998
6999 hdr->checksum = 0 - sum;
7000
7001 length >>= 2;
7002 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007003 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007004 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007005 E1000_WRITE_FLUSH(hw);
7006 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007007
7008 return E1000_SUCCESS;
7009}
7010
7011
7012/*****************************************************************************
7013 * This function indicates to ARC that a new command is pending which completes
7014 * one write operation by the driver.
7015 *
7016 * returns - E1000_SUCCESS for success.
7017 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007018static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007019e1000_mng_write_commit(
7020 struct e1000_hw * hw)
7021{
7022 uint32_t hicr;
7023
7024 hicr = E1000_READ_REG(hw, HICR);
7025 /* Setting this bit tells the ARC that a new command is pending. */
7026 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7027
7028 return E1000_SUCCESS;
7029}
7030
7031
7032/*****************************************************************************
7033 * This function checks the mode of the firmware.
7034 *
7035 * returns - TRUE when the mode is IAMT or FALSE.
7036 ****************************************************************************/
7037boolean_t
7038e1000_check_mng_mode(
7039 struct e1000_hw *hw)
7040{
7041 uint32_t fwsm;
7042
7043 fwsm = E1000_READ_REG(hw, FWSM);
7044
7045 if((fwsm & E1000_FWSM_MODE_MASK) ==
7046 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7047 return TRUE;
7048
7049 return FALSE;
7050}
7051
7052
7053/*****************************************************************************
7054 * This function writes the dhcp info .
7055 ****************************************************************************/
7056int32_t
7057e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7058 uint16_t length)
7059{
7060 int32_t ret_val;
7061 struct e1000_host_mng_command_header hdr;
7062
7063 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7064 hdr.command_length = length;
7065 hdr.reserved1 = 0;
7066 hdr.reserved2 = 0;
7067 hdr.checksum = 0;
7068
7069 ret_val = e1000_mng_enable_host_if(hw);
7070 if (ret_val == E1000_SUCCESS) {
7071 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7072 &(hdr.checksum));
7073 if (ret_val == E1000_SUCCESS) {
7074 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7075 if (ret_val == E1000_SUCCESS)
7076 ret_val = e1000_mng_write_commit(hw);
7077 }
7078 }
7079 return ret_val;
7080}
7081
7082
7083/*****************************************************************************
7084 * This function calculates the checksum.
7085 *
7086 * returns - checksum of buffer contents.
7087 ****************************************************************************/
7088uint8_t
7089e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7090{
7091 uint8_t sum = 0;
7092 uint32_t i;
7093
7094 if (!buffer)
7095 return 0;
7096
7097 for (i=0; i < length; i++)
7098 sum += buffer[i];
7099
7100 return (uint8_t) (0 - sum);
7101}
7102
7103/*****************************************************************************
7104 * This function checks whether tx pkt filtering needs to be enabled or not.
7105 *
7106 * returns - TRUE for packet filtering or FALSE.
7107 ****************************************************************************/
7108boolean_t
7109e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7110{
7111 /* called in init as well as watchdog timer functions */
7112
7113 int32_t ret_val, checksum;
7114 boolean_t tx_filter = FALSE;
7115 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7116 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7117
7118 if (e1000_check_mng_mode(hw)) {
7119 ret_val = e1000_mng_enable_host_if(hw);
7120 if (ret_val == E1000_SUCCESS) {
7121 ret_val = e1000_host_if_read_cookie(hw, buffer);
7122 if (ret_val == E1000_SUCCESS) {
7123 checksum = hdr->checksum;
7124 hdr->checksum = 0;
7125 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7126 checksum == e1000_calculate_mng_checksum((char *)buffer,
7127 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7128 if (hdr->status &
7129 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7130 tx_filter = TRUE;
7131 } else
7132 tx_filter = TRUE;
7133 } else
7134 tx_filter = TRUE;
7135 }
7136 }
7137
7138 hw->tx_pkt_filtering = tx_filter;
7139 return tx_filter;
7140}
7141
7142/******************************************************************************
7143 * Verifies the hardware needs to allow ARPs to be processed by the host
7144 *
7145 * hw - Struct containing variables accessed by shared code
7146 *
7147 * returns: - TRUE/FALSE
7148 *
7149 *****************************************************************************/
7150uint32_t
7151e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7152{
7153 uint32_t manc;
7154 uint32_t fwsm, factps;
7155
7156 if (hw->asf_firmware_present) {
7157 manc = E1000_READ_REG(hw, MANC);
7158
7159 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7160 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7161 return FALSE;
7162 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7163 fwsm = E1000_READ_REG(hw, FWSM);
7164 factps = E1000_READ_REG(hw, FACTPS);
7165
7166 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7167 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7168 (factps & E1000_FACTPS_MNGCG))
7169 return TRUE;
7170 } else
7171 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7172 return TRUE;
7173 }
7174 return FALSE;
7175}
7176
Linus Torvalds1da177e2005-04-16 15:20:36 -07007177static int32_t
7178e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7179{
7180 int32_t ret_val;
7181 uint16_t mii_status_reg;
7182 uint16_t i;
7183
7184 /* Polarity reversal workaround for forced 10F/10H links. */
7185
7186 /* Disable the transmitter on the PHY */
7187
7188 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7189 if(ret_val)
7190 return ret_val;
7191 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7192 if(ret_val)
7193 return ret_val;
7194
7195 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7196 if(ret_val)
7197 return ret_val;
7198
7199 /* This loop will early-out if the NO link condition has been met. */
7200 for(i = PHY_FORCE_TIME; i > 0; i--) {
7201 /* Read the MII Status Register and wait for Link Status bit
7202 * to be clear.
7203 */
7204
7205 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7206 if(ret_val)
7207 return ret_val;
7208
7209 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7210 if(ret_val)
7211 return ret_val;
7212
7213 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7214 msec_delay_irq(100);
7215 }
7216
7217 /* Recommended delay time after link has been lost */
7218 msec_delay_irq(1000);
7219
7220 /* Now we will re-enable th transmitter on the PHY */
7221
7222 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7223 if(ret_val)
7224 return ret_val;
7225 msec_delay_irq(50);
7226 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7227 if(ret_val)
7228 return ret_val;
7229 msec_delay_irq(50);
7230 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7231 if(ret_val)
7232 return ret_val;
7233 msec_delay_irq(50);
7234 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7235 if(ret_val)
7236 return ret_val;
7237
7238 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7239 if(ret_val)
7240 return ret_val;
7241
7242 /* This loop will early-out if the link condition has been met. */
7243 for(i = PHY_FORCE_TIME; i > 0; i--) {
7244 /* Read the MII Status Register and wait for Link Status bit
7245 * to be set.
7246 */
7247
7248 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7249 if(ret_val)
7250 return ret_val;
7251
7252 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7253 if(ret_val)
7254 return ret_val;
7255
7256 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7257 msec_delay_irq(100);
7258 }
7259 return E1000_SUCCESS;
7260}
7261
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007262/***************************************************************************
7263 *
7264 * Disables PCI-Express master access.
7265 *
7266 * hw: Struct containing variables accessed by shared code
7267 *
7268 * returns: - none.
7269 *
7270 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007271static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007272e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7273{
7274 uint32_t ctrl;
7275
7276 DEBUGFUNC("e1000_set_pci_express_master_disable");
7277
7278 if (hw->bus_type != e1000_bus_type_pci_express)
7279 return;
7280
7281 ctrl = E1000_READ_REG(hw, CTRL);
7282 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7283 E1000_WRITE_REG(hw, CTRL, ctrl);
7284}
7285
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007286#if 0
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007287/***************************************************************************
7288 *
7289 * Enables PCI-Express master access.
7290 *
7291 * hw: Struct containing variables accessed by shared code
7292 *
7293 * returns: - none.
7294 *
7295 ***************************************************************************/
7296void
7297e1000_enable_pciex_master(struct e1000_hw *hw)
7298{
7299 uint32_t ctrl;
7300
7301 DEBUGFUNC("e1000_enable_pciex_master");
7302
7303 if (hw->bus_type != e1000_bus_type_pci_express)
7304 return;
7305
7306 ctrl = E1000_READ_REG(hw, CTRL);
7307 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7308 E1000_WRITE_REG(hw, CTRL, ctrl);
7309}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007310#endif /* 0 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007311
7312/*******************************************************************************
7313 *
7314 * Disables PCI-Express master access and verifies there are no pending requests
7315 *
7316 * hw: Struct containing variables accessed by shared code
7317 *
7318 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7319 * caused the master requests to be disabled.
7320 * E1000_SUCCESS master requests disabled.
7321 *
7322 ******************************************************************************/
7323int32_t
7324e1000_disable_pciex_master(struct e1000_hw *hw)
7325{
7326 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7327
7328 DEBUGFUNC("e1000_disable_pciex_master");
7329
7330 if (hw->bus_type != e1000_bus_type_pci_express)
7331 return E1000_SUCCESS;
7332
7333 e1000_set_pci_express_master_disable(hw);
7334
7335 while(timeout) {
7336 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7337 break;
7338 else
7339 udelay(100);
7340 timeout--;
7341 }
7342
7343 if(!timeout) {
7344 DEBUGOUT("Master requests are pending.\n");
7345 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7346 }
7347
7348 return E1000_SUCCESS;
7349}
7350
7351/*******************************************************************************
7352 *
7353 * Check for EEPROM Auto Read bit done.
7354 *
7355 * hw: Struct containing variables accessed by shared code
7356 *
7357 * returns: - E1000_ERR_RESET if fail to reset MAC
7358 * E1000_SUCCESS at any other case.
7359 *
7360 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007361static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007362e1000_get_auto_rd_done(struct e1000_hw *hw)
7363{
7364 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7365
7366 DEBUGFUNC("e1000_get_auto_rd_done");
7367
7368 switch (hw->mac_type) {
7369 default:
7370 msec_delay(5);
7371 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007372 case e1000_82571:
7373 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007374 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007375 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007376 while(timeout) {
7377 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
7378 else msec_delay(1);
7379 timeout--;
7380 }
7381
7382 if(!timeout) {
7383 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7384 return -E1000_ERR_RESET;
7385 }
7386 break;
7387 }
7388
Jeff Kirsherfd803242005-12-13 00:06:22 -05007389 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
7390 * Need to wait for PHY configuration completion before accessing NVM
7391 * and PHY. */
7392 if (hw->mac_type == e1000_82573)
7393 msec_delay(25);
7394
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007395 return E1000_SUCCESS;
7396}
7397
7398/***************************************************************************
7399 * Checks if the PHY configuration is done
7400 *
7401 * hw: Struct containing variables accessed by shared code
7402 *
7403 * returns: - E1000_ERR_RESET if fail to reset MAC
7404 * E1000_SUCCESS at any other case.
7405 *
7406 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007407static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007408e1000_get_phy_cfg_done(struct e1000_hw *hw)
7409{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007410 int32_t timeout = PHY_CFG_TIMEOUT;
7411 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
7412
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007413 DEBUGFUNC("e1000_get_phy_cfg_done");
7414
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007415 switch (hw->mac_type) {
7416 default:
7417 msec_delay(10);
7418 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007419 case e1000_80003es2lan:
7420 /* Separate *_CFG_DONE_* bit for each port */
7421 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
7422 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7423 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007424 case e1000_82571:
7425 case e1000_82572:
7426 while (timeout) {
7427 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
7428 break;
7429 else
7430 msec_delay(1);
7431 timeout--;
7432 }
7433
7434 if (!timeout) {
7435 DEBUGOUT("MNG configuration cycle has not completed.\n");
7436 return -E1000_ERR_RESET;
7437 }
7438 break;
7439 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007440
7441 return E1000_SUCCESS;
7442}
7443
7444/***************************************************************************
7445 *
7446 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
7447 * adapter or Eeprom access.
7448 *
7449 * hw: Struct containing variables accessed by shared code
7450 *
7451 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
7452 * E1000_SUCCESS at any other case.
7453 *
7454 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007455static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007456e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
7457{
7458 int32_t timeout;
7459 uint32_t swsm;
7460
7461 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
7462
7463 if(!hw->eeprom_semaphore_present)
7464 return E1000_SUCCESS;
7465
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007466 if (hw->mac_type == e1000_80003es2lan) {
7467 /* Get the SW semaphore. */
7468 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
7469 return -E1000_ERR_EEPROM;
7470 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007471
7472 /* Get the FW semaphore. */
7473 timeout = hw->eeprom.word_size + 1;
7474 while(timeout) {
7475 swsm = E1000_READ_REG(hw, SWSM);
7476 swsm |= E1000_SWSM_SWESMBI;
7477 E1000_WRITE_REG(hw, SWSM, swsm);
7478 /* if we managed to set the bit we got the semaphore. */
7479 swsm = E1000_READ_REG(hw, SWSM);
7480 if(swsm & E1000_SWSM_SWESMBI)
7481 break;
7482
7483 udelay(50);
7484 timeout--;
7485 }
7486
7487 if(!timeout) {
7488 /* Release semaphores */
7489 e1000_put_hw_eeprom_semaphore(hw);
7490 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7491 return -E1000_ERR_EEPROM;
7492 }
7493
7494 return E1000_SUCCESS;
7495}
7496
7497/***************************************************************************
7498 * This function clears HW semaphore bits.
7499 *
7500 * hw: Struct containing variables accessed by shared code
7501 *
7502 * returns: - None.
7503 *
7504 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007505static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007506e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
7507{
7508 uint32_t swsm;
7509
7510 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
7511
7512 if(!hw->eeprom_semaphore_present)
7513 return;
7514
7515 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007516 if (hw->mac_type == e1000_80003es2lan) {
7517 /* Release both semaphores. */
7518 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7519 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007520 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007521 E1000_WRITE_REG(hw, SWSM, swsm);
7522}
7523
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007524/***************************************************************************
7525 *
7526 * Obtaining software semaphore bit (SMBI) before resetting PHY.
7527 *
7528 * hw: Struct containing variables accessed by shared code
7529 *
7530 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
7531 * E1000_SUCCESS at any other case.
7532 *
7533 ***************************************************************************/
7534int32_t
7535e1000_get_software_semaphore(struct e1000_hw *hw)
7536{
7537 int32_t timeout = hw->eeprom.word_size + 1;
7538 uint32_t swsm;
7539
7540 DEBUGFUNC("e1000_get_software_semaphore");
7541
7542 if (hw->mac_type != e1000_80003es2lan)
7543 return E1000_SUCCESS;
7544
7545 while(timeout) {
7546 swsm = E1000_READ_REG(hw, SWSM);
7547 /* If SMBI bit cleared, it is now set and we hold the semaphore */
7548 if(!(swsm & E1000_SWSM_SMBI))
7549 break;
7550 msec_delay_irq(1);
7551 timeout--;
7552 }
7553
7554 if(!timeout) {
7555 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
7556 return -E1000_ERR_RESET;
7557 }
7558
7559 return E1000_SUCCESS;
7560}
7561
7562/***************************************************************************
7563 *
7564 * Release semaphore bit (SMBI).
7565 *
7566 * hw: Struct containing variables accessed by shared code
7567 *
7568 ***************************************************************************/
7569void
7570e1000_release_software_semaphore(struct e1000_hw *hw)
7571{
7572 uint32_t swsm;
7573
7574 DEBUGFUNC("e1000_release_software_semaphore");
7575
7576 if (hw->mac_type != e1000_80003es2lan)
7577 return;
7578
7579 swsm = E1000_READ_REG(hw, SWSM);
7580 /* Release the SW semaphores.*/
7581 swsm &= ~E1000_SWSM_SMBI;
7582 E1000_WRITE_REG(hw, SWSM, swsm);
7583}
7584
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007585/******************************************************************************
7586 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
7587 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
7588 * the caller to figure out how to deal with it.
7589 *
7590 * hw - Struct containing variables accessed by shared code
7591 *
7592 * returns: - E1000_BLK_PHY_RESET
7593 * E1000_SUCCESS
7594 *
7595 *****************************************************************************/
7596int32_t
7597e1000_check_phy_reset_block(struct e1000_hw *hw)
7598{
7599 uint32_t manc = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08007600
7601 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007602 manc = E1000_READ_REG(hw, MANC);
7603 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
7604 E1000_BLK_PHY_RESET : E1000_SUCCESS;
7605}
7606
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007607static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007608e1000_arc_subsystem_valid(struct e1000_hw *hw)
7609{
7610 uint32_t fwsm;
7611
7612 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
7613 * may not be provided a DMA clock when no manageability features are
7614 * enabled. We do not want to perform any reads/writes to these registers
7615 * if this is the case. We read FWSM to determine the manageability mode.
7616 */
7617 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007618 case e1000_82571:
7619 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007620 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007621 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007622 fwsm = E1000_READ_REG(hw, FWSM);
7623 if((fwsm & E1000_FWSM_MODE_MASK) != 0)
7624 return TRUE;
7625 break;
7626 default:
7627 break;
7628 }
7629 return FALSE;
7630}
7631
7632
7633