blob: 37eb351b4c9b6bb85f3d6ebdd3175c41106dc603 [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;
2740 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2741 if(speed != SPEED_1000) {
2742 /* If link speed is not set to gigabit speed, we do not need
2743 * to enable TBI compatibility.
2744 */
2745 if(hw->tbi_compatibility_on) {
2746 /* If we previously were in the mode, turn it off. */
2747 rctl = E1000_READ_REG(hw, RCTL);
2748 rctl &= ~E1000_RCTL_SBP;
2749 E1000_WRITE_REG(hw, RCTL, rctl);
2750 hw->tbi_compatibility_on = FALSE;
2751 }
2752 } else {
2753 /* If TBI compatibility is was previously off, turn it on. For
2754 * compatibility with a TBI link partner, we will store bad
2755 * packets. Some frames have an additional byte on the end and
2756 * will look like CRC errors to to the hardware.
2757 */
2758 if(!hw->tbi_compatibility_on) {
2759 hw->tbi_compatibility_on = TRUE;
2760 rctl = E1000_READ_REG(hw, RCTL);
2761 rctl |= E1000_RCTL_SBP;
2762 E1000_WRITE_REG(hw, RCTL, rctl);
2763 }
2764 }
2765 }
2766 }
2767 /* If we don't have link (auto-negotiation failed or link partner cannot
2768 * auto-negotiate), the cable is plugged in (we have signal), and our
2769 * link partner is not trying to auto-negotiate with us (we are receiving
2770 * idles or data), we need to force link up. We also need to give
2771 * auto-negotiation time to complete, in case the cable was just plugged
2772 * in. The autoneg_failed flag does this.
2773 */
2774 else if((((hw->media_type == e1000_media_type_fiber) &&
2775 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2776 (hw->media_type == e1000_media_type_internal_serdes)) &&
2777 (!(status & E1000_STATUS_LU)) &&
2778 (!(rxcw & E1000_RXCW_C))) {
2779 if(hw->autoneg_failed == 0) {
2780 hw->autoneg_failed = 1;
2781 return 0;
2782 }
Auke Koka42a5072006-05-23 13:36:01 -07002783 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 /* Disable auto-negotiation in the TXCW register */
2786 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2787
2788 /* Force link-up and also force full-duplex. */
2789 ctrl = E1000_READ_REG(hw, CTRL);
2790 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2791 E1000_WRITE_REG(hw, CTRL, ctrl);
2792
2793 /* Configure Flow Control after forcing link up. */
2794 ret_val = e1000_config_fc_after_link_up(hw);
2795 if(ret_val) {
2796 DEBUGOUT("Error configuring flow control\n");
2797 return ret_val;
2798 }
2799 }
2800 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2801 * auto-negotiation in the TXCW register and disable forced link in the
2802 * Device Control register in an attempt to auto-negotiate with our link
2803 * partner.
2804 */
2805 else if(((hw->media_type == e1000_media_type_fiber) ||
2806 (hw->media_type == e1000_media_type_internal_serdes)) &&
2807 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07002808 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2810 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2811
2812 hw->serdes_link_down = FALSE;
2813 }
2814 /* If we force link for non-auto-negotiation switch, check link status
2815 * based on MAC synchronization for internal serdes media type.
2816 */
2817 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2818 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2819 /* SYNCH bit and IV bit are sticky. */
2820 udelay(10);
2821 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2822 if(!(rxcw & E1000_RXCW_IV)) {
2823 hw->serdes_link_down = FALSE;
2824 DEBUGOUT("SERDES: Link is up.\n");
2825 }
2826 } else {
2827 hw->serdes_link_down = TRUE;
2828 DEBUGOUT("SERDES: Link is down.\n");
2829 }
2830 }
2831 if((hw->media_type == e1000_media_type_internal_serdes) &&
2832 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2833 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2834 }
2835 return E1000_SUCCESS;
2836}
2837
2838/******************************************************************************
2839 * Detects the current speed and duplex settings of the hardware.
2840 *
2841 * hw - Struct containing variables accessed by shared code
2842 * speed - Speed of the connection
2843 * duplex - Duplex setting of the connection
2844 *****************************************************************************/
2845int32_t
2846e1000_get_speed_and_duplex(struct e1000_hw *hw,
2847 uint16_t *speed,
2848 uint16_t *duplex)
2849{
2850 uint32_t status;
2851 int32_t ret_val;
2852 uint16_t phy_data;
2853
2854 DEBUGFUNC("e1000_get_speed_and_duplex");
2855
2856 if(hw->mac_type >= e1000_82543) {
2857 status = E1000_READ_REG(hw, STATUS);
2858 if(status & E1000_STATUS_SPEED_1000) {
2859 *speed = SPEED_1000;
2860 DEBUGOUT("1000 Mbs, ");
2861 } else if(status & E1000_STATUS_SPEED_100) {
2862 *speed = SPEED_100;
2863 DEBUGOUT("100 Mbs, ");
2864 } else {
2865 *speed = SPEED_10;
2866 DEBUGOUT("10 Mbs, ");
2867 }
2868
2869 if(status & E1000_STATUS_FD) {
2870 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002871 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 } else {
2873 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002874 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 }
2876 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002877 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 *speed = SPEED_1000;
2879 *duplex = FULL_DUPLEX;
2880 }
2881
2882 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2883 * if it is operating at half duplex. Here we set the duplex settings to
2884 * match the duplex in the link partner's capabilities.
2885 */
2886 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2887 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2888 if(ret_val)
2889 return ret_val;
2890
2891 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2892 *duplex = HALF_DUPLEX;
2893 else {
2894 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2895 if(ret_val)
2896 return ret_val;
2897 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2898 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2899 *duplex = HALF_DUPLEX;
2900 }
2901 }
2902
Auke Kok76c224b2006-05-23 13:36:06 -07002903 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002904 (hw->media_type == e1000_media_type_copper)) {
2905 if (*speed == SPEED_1000)
2906 ret_val = e1000_configure_kmrn_for_1000(hw);
2907 else
2908 ret_val = e1000_configure_kmrn_for_10_100(hw);
2909 if (ret_val)
2910 return ret_val;
2911 }
2912
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return E1000_SUCCESS;
2914}
2915
2916/******************************************************************************
2917* Blocks until autoneg completes or times out (~4.5 seconds)
2918*
2919* hw - Struct containing variables accessed by shared code
2920******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002921static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922e1000_wait_autoneg(struct e1000_hw *hw)
2923{
2924 int32_t ret_val;
2925 uint16_t i;
2926 uint16_t phy_data;
2927
2928 DEBUGFUNC("e1000_wait_autoneg");
2929 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2930
2931 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2932 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2933 /* Read the MII Status Register and wait for Auto-Neg
2934 * Complete bit to be set.
2935 */
2936 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2937 if(ret_val)
2938 return ret_val;
2939 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2940 if(ret_val)
2941 return ret_val;
2942 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2943 return E1000_SUCCESS;
2944 }
2945 msec_delay(100);
2946 }
2947 return E1000_SUCCESS;
2948}
2949
2950/******************************************************************************
2951* Raises the Management Data Clock
2952*
2953* hw - Struct containing variables accessed by shared code
2954* ctrl - Device control register's current value
2955******************************************************************************/
2956static void
2957e1000_raise_mdi_clk(struct e1000_hw *hw,
2958 uint32_t *ctrl)
2959{
2960 /* Raise the clock input to the Management Data Clock (by setting the MDC
2961 * bit), and then delay 10 microseconds.
2962 */
2963 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2964 E1000_WRITE_FLUSH(hw);
2965 udelay(10);
2966}
2967
2968/******************************************************************************
2969* Lowers the Management Data Clock
2970*
2971* hw - Struct containing variables accessed by shared code
2972* ctrl - Device control register's current value
2973******************************************************************************/
2974static void
2975e1000_lower_mdi_clk(struct e1000_hw *hw,
2976 uint32_t *ctrl)
2977{
2978 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2979 * bit), and then delay 10 microseconds.
2980 */
2981 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2982 E1000_WRITE_FLUSH(hw);
2983 udelay(10);
2984}
2985
2986/******************************************************************************
2987* Shifts data bits out to the PHY
2988*
2989* hw - Struct containing variables accessed by shared code
2990* data - Data to send out to the PHY
2991* count - Number of bits to shift out
2992*
2993* Bits are shifted out in MSB to LSB order.
2994******************************************************************************/
2995static void
2996e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2997 uint32_t data,
2998 uint16_t count)
2999{
3000 uint32_t ctrl;
3001 uint32_t mask;
3002
3003 /* We need to shift "count" number of bits out to the PHY. So, the value
3004 * in the "data" parameter will be shifted out to the PHY one bit at a
3005 * time. In order to do this, "data" must be broken down into bits.
3006 */
3007 mask = 0x01;
3008 mask <<= (count - 1);
3009
3010 ctrl = E1000_READ_REG(hw, CTRL);
3011
3012 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3013 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3014
3015 while(mask) {
3016 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3017 * then raising and lowering the Management Data Clock. A "0" is
3018 * shifted out to the PHY by setting the MDIO bit to "0" and then
3019 * raising and lowering the clock.
3020 */
3021 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3022 else ctrl &= ~E1000_CTRL_MDIO;
3023
3024 E1000_WRITE_REG(hw, CTRL, ctrl);
3025 E1000_WRITE_FLUSH(hw);
3026
3027 udelay(10);
3028
3029 e1000_raise_mdi_clk(hw, &ctrl);
3030 e1000_lower_mdi_clk(hw, &ctrl);
3031
3032 mask = mask >> 1;
3033 }
3034}
3035
3036/******************************************************************************
3037* Shifts data bits in from the PHY
3038*
3039* hw - Struct containing variables accessed by shared code
3040*
3041* Bits are shifted in in MSB to LSB order.
3042******************************************************************************/
3043static uint16_t
3044e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3045{
3046 uint32_t ctrl;
3047 uint16_t data = 0;
3048 uint8_t i;
3049
3050 /* In order to read a register from the PHY, we need to shift in a total
3051 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3052 * to avoid contention on the MDIO pin when a read operation is performed.
3053 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3054 * by raising the input to the Management Data Clock (setting the MDC bit),
3055 * and then reading the value of the MDIO bit.
3056 */
3057 ctrl = E1000_READ_REG(hw, CTRL);
3058
3059 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3060 ctrl &= ~E1000_CTRL_MDIO_DIR;
3061 ctrl &= ~E1000_CTRL_MDIO;
3062
3063 E1000_WRITE_REG(hw, CTRL, ctrl);
3064 E1000_WRITE_FLUSH(hw);
3065
3066 /* Raise and Lower the clock before reading in the data. This accounts for
3067 * the turnaround bits. The first clock occurred when we clocked out the
3068 * last bit of the Register Address.
3069 */
3070 e1000_raise_mdi_clk(hw, &ctrl);
3071 e1000_lower_mdi_clk(hw, &ctrl);
3072
3073 for(data = 0, i = 0; i < 16; i++) {
3074 data = data << 1;
3075 e1000_raise_mdi_clk(hw, &ctrl);
3076 ctrl = E1000_READ_REG(hw, CTRL);
3077 /* Check to see if we shifted in a "1". */
3078 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3079 e1000_lower_mdi_clk(hw, &ctrl);
3080 }
3081
3082 e1000_raise_mdi_clk(hw, &ctrl);
3083 e1000_lower_mdi_clk(hw, &ctrl);
3084
3085 return data;
3086}
3087
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003088int32_t
3089e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3090{
3091 uint32_t swfw_sync = 0;
3092 uint32_t swmask = mask;
3093 uint32_t fwmask = mask << 16;
3094 int32_t timeout = 200;
3095
3096 DEBUGFUNC("e1000_swfw_sync_acquire");
3097
3098 if (!hw->swfw_sync_present)
3099 return e1000_get_hw_eeprom_semaphore(hw);
3100
3101 while(timeout) {
3102 if (e1000_get_hw_eeprom_semaphore(hw))
3103 return -E1000_ERR_SWFW_SYNC;
3104
3105 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3106 if (!(swfw_sync & (fwmask | swmask))) {
3107 break;
3108 }
3109
3110 /* firmware currently using resource (fwmask) */
3111 /* or other software thread currently using resource (swmask) */
3112 e1000_put_hw_eeprom_semaphore(hw);
3113 msec_delay_irq(5);
3114 timeout--;
3115 }
3116
3117 if (!timeout) {
3118 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3119 return -E1000_ERR_SWFW_SYNC;
3120 }
3121
3122 swfw_sync |= swmask;
3123 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3124
3125 e1000_put_hw_eeprom_semaphore(hw);
3126 return E1000_SUCCESS;
3127}
3128
3129void
3130e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3131{
3132 uint32_t swfw_sync;
3133 uint32_t swmask = mask;
3134
3135 DEBUGFUNC("e1000_swfw_sync_release");
3136
3137 if (!hw->swfw_sync_present) {
3138 e1000_put_hw_eeprom_semaphore(hw);
3139 return;
3140 }
3141
3142 /* if (e1000_get_hw_eeprom_semaphore(hw))
3143 * return -E1000_ERR_SWFW_SYNC; */
3144 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3145 /* empty */
3146
3147 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3148 swfw_sync &= ~swmask;
3149 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3150
3151 e1000_put_hw_eeprom_semaphore(hw);
3152}
3153
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154/*****************************************************************************
3155* Reads the value from a PHY register, if the value is on a specific non zero
3156* page, sets the page first.
3157* hw - Struct containing variables accessed by shared code
3158* reg_addr - address of the PHY register to read
3159******************************************************************************/
3160int32_t
3161e1000_read_phy_reg(struct e1000_hw *hw,
3162 uint32_t reg_addr,
3163 uint16_t *phy_data)
3164{
3165 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003166 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168 DEBUGFUNC("e1000_read_phy_reg");
3169
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003170 if ((hw->mac_type == e1000_80003es2lan) &&
3171 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3172 swfw = E1000_SWFW_PHY1_SM;
3173 } else {
3174 swfw = E1000_SWFW_PHY0_SM;
3175 }
3176 if (e1000_swfw_sync_acquire(hw, swfw))
3177 return -E1000_ERR_SWFW_SYNC;
3178
Auke Kok76c224b2006-05-23 13:36:06 -07003179 if((hw->phy_type == e1000_phy_igp ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003180 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3182 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3183 (uint16_t)reg_addr);
3184 if(ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003185 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 return ret_val;
3187 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003188 } else if (hw->phy_type == e1000_phy_gg82563) {
3189 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3190 (hw->mac_type == e1000_80003es2lan)) {
3191 /* Select Configuration Page */
3192 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3193 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3194 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3195 } else {
3196 /* Use Alternative Page Select register to access
3197 * registers 30 and 31
3198 */
3199 ret_val = e1000_write_phy_reg_ex(hw,
3200 GG82563_PHY_PAGE_SELECT_ALT,
3201 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3202 }
3203
3204 if (ret_val) {
3205 e1000_swfw_sync_release(hw, swfw);
3206 return ret_val;
3207 }
3208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 }
3210
3211 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3212 phy_data);
3213
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003214 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 return ret_val;
3216}
3217
3218int32_t
3219e1000_read_phy_reg_ex(struct e1000_hw *hw,
3220 uint32_t reg_addr,
3221 uint16_t *phy_data)
3222{
3223 uint32_t i;
3224 uint32_t mdic = 0;
3225 const uint32_t phy_addr = 1;
3226
3227 DEBUGFUNC("e1000_read_phy_reg_ex");
3228
3229 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3230 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3231 return -E1000_ERR_PARAM;
3232 }
3233
3234 if(hw->mac_type > e1000_82543) {
3235 /* Set up Op-code, Phy Address, and register address in the MDI
3236 * Control register. The MAC will take care of interfacing with the
3237 * PHY to retrieve the desired data.
3238 */
3239 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3240 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3241 (E1000_MDIC_OP_READ));
3242
3243 E1000_WRITE_REG(hw, MDIC, mdic);
3244
3245 /* Poll the ready bit to see if the MDI read completed */
3246 for(i = 0; i < 64; i++) {
3247 udelay(50);
3248 mdic = E1000_READ_REG(hw, MDIC);
3249 if(mdic & E1000_MDIC_READY) break;
3250 }
3251 if(!(mdic & E1000_MDIC_READY)) {
3252 DEBUGOUT("MDI Read did not complete\n");
3253 return -E1000_ERR_PHY;
3254 }
3255 if(mdic & E1000_MDIC_ERROR) {
3256 DEBUGOUT("MDI Error\n");
3257 return -E1000_ERR_PHY;
3258 }
3259 *phy_data = (uint16_t) mdic;
3260 } else {
3261 /* We must first send a preamble through the MDIO pin to signal the
3262 * beginning of an MII instruction. This is done by sending 32
3263 * consecutive "1" bits.
3264 */
3265 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3266
3267 /* Now combine the next few fields that are required for a read
3268 * operation. We use this method instead of calling the
3269 * e1000_shift_out_mdi_bits routine five different times. The format of
3270 * a MII read instruction consists of a shift out of 14 bits and is
3271 * defined as follows:
3272 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3273 * followed by a shift in of 18 bits. This first two bits shifted in
3274 * are TurnAround bits used to avoid contention on the MDIO pin when a
3275 * READ operation is performed. These two bits are thrown away
3276 * followed by a shift in of 16 bits which contains the desired data.
3277 */
3278 mdic = ((reg_addr) | (phy_addr << 5) |
3279 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3280
3281 e1000_shift_out_mdi_bits(hw, mdic, 14);
3282
3283 /* Now that we've shifted out the read command to the MII, we need to
3284 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3285 * register address.
3286 */
3287 *phy_data = e1000_shift_in_mdi_bits(hw);
3288 }
3289 return E1000_SUCCESS;
3290}
3291
3292/******************************************************************************
3293* Writes a value to a PHY register
3294*
3295* hw - Struct containing variables accessed by shared code
3296* reg_addr - address of the PHY register to write
3297* data - data to write to the PHY
3298******************************************************************************/
3299int32_t
3300e1000_write_phy_reg(struct e1000_hw *hw,
3301 uint32_t reg_addr,
3302 uint16_t phy_data)
3303{
3304 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003305 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
3307 DEBUGFUNC("e1000_write_phy_reg");
3308
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003309 if ((hw->mac_type == e1000_80003es2lan) &&
3310 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3311 swfw = E1000_SWFW_PHY1_SM;
3312 } else {
3313 swfw = E1000_SWFW_PHY0_SM;
3314 }
3315 if (e1000_swfw_sync_acquire(hw, swfw))
3316 return -E1000_ERR_SWFW_SYNC;
3317
Auke Kok76c224b2006-05-23 13:36:06 -07003318 if((hw->phy_type == e1000_phy_igp ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003319 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3321 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3322 (uint16_t)reg_addr);
3323 if(ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003324 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 return ret_val;
3326 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003327 } else if (hw->phy_type == e1000_phy_gg82563) {
3328 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3329 (hw->mac_type == e1000_80003es2lan)) {
3330 /* Select Configuration Page */
3331 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3332 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3333 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3334 } else {
3335 /* Use Alternative Page Select register to access
3336 * registers 30 and 31
3337 */
3338 ret_val = e1000_write_phy_reg_ex(hw,
3339 GG82563_PHY_PAGE_SELECT_ALT,
3340 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3341 }
3342
3343 if (ret_val) {
3344 e1000_swfw_sync_release(hw, swfw);
3345 return ret_val;
3346 }
3347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 }
3349
3350 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3351 phy_data);
3352
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003353 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 return ret_val;
3355}
3356
3357int32_t
3358e1000_write_phy_reg_ex(struct e1000_hw *hw,
3359 uint32_t reg_addr,
3360 uint16_t phy_data)
3361{
3362 uint32_t i;
3363 uint32_t mdic = 0;
3364 const uint32_t phy_addr = 1;
3365
3366 DEBUGFUNC("e1000_write_phy_reg_ex");
3367
3368 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3369 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3370 return -E1000_ERR_PARAM;
3371 }
3372
3373 if(hw->mac_type > e1000_82543) {
3374 /* Set up Op-code, Phy Address, register address, and data intended
3375 * for the PHY register in the MDI Control register. The MAC will take
3376 * care of interfacing with the PHY to send the desired data.
3377 */
3378 mdic = (((uint32_t) phy_data) |
3379 (reg_addr << E1000_MDIC_REG_SHIFT) |
3380 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3381 (E1000_MDIC_OP_WRITE));
3382
3383 E1000_WRITE_REG(hw, MDIC, mdic);
3384
3385 /* Poll the ready bit to see if the MDI read completed */
3386 for(i = 0; i < 640; i++) {
3387 udelay(5);
3388 mdic = E1000_READ_REG(hw, MDIC);
3389 if(mdic & E1000_MDIC_READY) break;
3390 }
3391 if(!(mdic & E1000_MDIC_READY)) {
3392 DEBUGOUT("MDI Write did not complete\n");
3393 return -E1000_ERR_PHY;
3394 }
3395 } else {
3396 /* We'll need to use the SW defined pins to shift the write command
3397 * out to the PHY. We first send a preamble to the PHY to signal the
3398 * beginning of the MII instruction. This is done by sending 32
3399 * consecutive "1" bits.
3400 */
3401 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3402
3403 /* Now combine the remaining required fields that will indicate a
3404 * write operation. We use this method instead of calling the
3405 * e1000_shift_out_mdi_bits routine for each field in the command. The
3406 * format of a MII write instruction is as follows:
3407 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3408 */
3409 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3410 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3411 mdic <<= 16;
3412 mdic |= (uint32_t) phy_data;
3413
3414 e1000_shift_out_mdi_bits(hw, mdic, 32);
3415 }
3416
3417 return E1000_SUCCESS;
3418}
3419
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003420int32_t
3421e1000_read_kmrn_reg(struct e1000_hw *hw,
3422 uint32_t reg_addr,
3423 uint16_t *data)
3424{
3425 uint32_t reg_val;
3426 uint16_t swfw;
3427 DEBUGFUNC("e1000_read_kmrn_reg");
3428
3429 if ((hw->mac_type == e1000_80003es2lan) &&
3430 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3431 swfw = E1000_SWFW_PHY1_SM;
3432 } else {
3433 swfw = E1000_SWFW_PHY0_SM;
3434 }
3435 if (e1000_swfw_sync_acquire(hw, swfw))
3436 return -E1000_ERR_SWFW_SYNC;
3437
3438 /* Write register address */
3439 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3440 E1000_KUMCTRLSTA_OFFSET) |
3441 E1000_KUMCTRLSTA_REN;
3442 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3443 udelay(2);
3444
3445 /* Read the data returned */
3446 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3447 *data = (uint16_t)reg_val;
3448
3449 e1000_swfw_sync_release(hw, swfw);
3450 return E1000_SUCCESS;
3451}
3452
3453int32_t
3454e1000_write_kmrn_reg(struct e1000_hw *hw,
3455 uint32_t reg_addr,
3456 uint16_t data)
3457{
3458 uint32_t reg_val;
3459 uint16_t swfw;
3460 DEBUGFUNC("e1000_write_kmrn_reg");
3461
3462 if ((hw->mac_type == e1000_80003es2lan) &&
3463 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3464 swfw = E1000_SWFW_PHY1_SM;
3465 } else {
3466 swfw = E1000_SWFW_PHY0_SM;
3467 }
3468 if (e1000_swfw_sync_acquire(hw, swfw))
3469 return -E1000_ERR_SWFW_SYNC;
3470
3471 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3472 E1000_KUMCTRLSTA_OFFSET) | data;
3473 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3474 udelay(2);
3475
3476 e1000_swfw_sync_release(hw, swfw);
3477 return E1000_SUCCESS;
3478}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003479
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480/******************************************************************************
3481* Returns the PHY to the power-on reset state
3482*
3483* hw - Struct containing variables accessed by shared code
3484******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003485int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486e1000_phy_hw_reset(struct e1000_hw *hw)
3487{
3488 uint32_t ctrl, ctrl_ext;
3489 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003490 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003491 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
3493 DEBUGFUNC("e1000_phy_hw_reset");
3494
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003495 /* In the case of the phy reset being blocked, it's not an error, we
3496 * simply return success without performing the reset. */
3497 ret_val = e1000_check_phy_reset_block(hw);
3498 if (ret_val)
3499 return E1000_SUCCESS;
3500
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 DEBUGOUT("Resetting Phy...\n");
3502
3503 if(hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003504 if ((hw->mac_type == e1000_80003es2lan) &&
3505 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3506 swfw = E1000_SWFW_PHY1_SM;
3507 } else {
3508 swfw = E1000_SWFW_PHY0_SM;
3509 }
3510 if (e1000_swfw_sync_acquire(hw, swfw)) {
3511 e1000_release_software_semaphore(hw);
3512 return -E1000_ERR_SWFW_SYNC;
3513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3515 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003516 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003517 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003518 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 */
3520 ctrl = E1000_READ_REG(hw, CTRL);
3521 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3522 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003523
3524 if (hw->mac_type < e1000_82571)
Jeff Kirsherfd803242005-12-13 00:06:22 -05003525 msec_delay(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003526 else
3527 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003528
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 E1000_WRITE_REG(hw, CTRL, ctrl);
3530 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003531
Jeff Kirsherfd803242005-12-13 00:06:22 -05003532 if (hw->mac_type >= e1000_82571)
3533 msec_delay(10);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003534 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 } else {
3536 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3537 * bit to put the PHY into reset. Then, take it out of reset.
3538 */
3539 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3540 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3541 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3542 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3543 E1000_WRITE_FLUSH(hw);
3544 msec_delay(10);
3545 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3546 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3547 E1000_WRITE_FLUSH(hw);
3548 }
3549 udelay(150);
3550
3551 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3552 /* Configure activity LED after PHY reset */
3553 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3554 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3555 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3556 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3557 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003558
3559 /* Wait for FW to finish PHY configuration. */
3560 ret_val = e1000_get_phy_cfg_done(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003561 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003562
3563 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564}
3565
3566/******************************************************************************
3567* Resets the PHY
3568*
3569* hw - Struct containing variables accessed by shared code
3570*
3571* Sets bit 15 of the MII Control regiser
3572******************************************************************************/
3573int32_t
3574e1000_phy_reset(struct e1000_hw *hw)
3575{
3576 int32_t ret_val;
3577 uint16_t phy_data;
3578
3579 DEBUGFUNC("e1000_phy_reset");
3580
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003581 /* In the case of the phy reset being blocked, it's not an error, we
3582 * simply return success without performing the reset. */
3583 ret_val = e1000_check_phy_reset_block(hw);
3584 if (ret_val)
3585 return E1000_SUCCESS;
3586
3587 switch (hw->mac_type) {
3588 case e1000_82541_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003589 case e1000_82571:
3590 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003591 ret_val = e1000_phy_hw_reset(hw);
3592 if(ret_val)
3593 return ret_val;
3594 break;
3595 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3597 if(ret_val)
3598 return ret_val;
3599
3600 phy_data |= MII_CR_RESET;
3601 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3602 if(ret_val)
3603 return ret_val;
3604
3605 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003606 break;
3607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003609 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 e1000_phy_init_script(hw);
3611
3612 return E1000_SUCCESS;
3613}
3614
3615/******************************************************************************
3616* Probes the expected PHY address for known PHY IDs
3617*
3618* hw - Struct containing variables accessed by shared code
3619******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003620static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621e1000_detect_gig_phy(struct e1000_hw *hw)
3622{
3623 int32_t phy_init_status, ret_val;
3624 uint16_t phy_id_high, phy_id_low;
3625 boolean_t match = FALSE;
3626
3627 DEBUGFUNC("e1000_detect_gig_phy");
3628
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003629 /* The 82571 firmware may still be configuring the PHY. In this
3630 * case, we cannot access the PHY until the configuration is done. So
3631 * we explicitly set the PHY values. */
3632 if(hw->mac_type == e1000_82571 ||
3633 hw->mac_type == e1000_82572) {
3634 hw->phy_id = IGP01E1000_I_PHY_ID;
3635 hw->phy_type = e1000_phy_igp_2;
3636 return E1000_SUCCESS;
3637 }
3638
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003639 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3640 * around that forces PHY page 0 to be set or the reads fail. The rest of
3641 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3642 * So for ESB-2 we need to have this set so our reads won't fail. If the
3643 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3644 * this out as well. */
3645 if (hw->mac_type == e1000_80003es2lan)
3646 hw->phy_type = e1000_phy_gg82563;
3647
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 /* Read the PHY ID Registers to identify which PHY is onboard. */
3649 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3650 if(ret_val)
3651 return ret_val;
3652
3653 hw->phy_id = (uint32_t) (phy_id_high << 16);
3654 udelay(20);
3655 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3656 if(ret_val)
3657 return ret_val;
3658
3659 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3660 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3661
3662 switch(hw->mac_type) {
3663 case e1000_82543:
3664 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3665 break;
3666 case e1000_82544:
3667 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3668 break;
3669 case e1000_82540:
3670 case e1000_82545:
3671 case e1000_82545_rev_3:
3672 case e1000_82546:
3673 case e1000_82546_rev_3:
3674 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3675 break;
3676 case e1000_82541:
3677 case e1000_82541_rev_2:
3678 case e1000_82547:
3679 case e1000_82547_rev_2:
3680 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3681 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003682 case e1000_82573:
3683 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3684 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003685 case e1000_80003es2lan:
3686 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 default:
3689 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3690 return -E1000_ERR_CONFIG;
3691 }
3692 phy_init_status = e1000_set_phy_type(hw);
3693
3694 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3695 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3696 return E1000_SUCCESS;
3697 }
3698 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3699 return -E1000_ERR_PHY;
3700}
3701
3702/******************************************************************************
3703* Resets the PHY's DSP
3704*
3705* hw - Struct containing variables accessed by shared code
3706******************************************************************************/
3707static int32_t
3708e1000_phy_reset_dsp(struct e1000_hw *hw)
3709{
3710 int32_t ret_val;
3711 DEBUGFUNC("e1000_phy_reset_dsp");
3712
3713 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003714 if (hw->phy_type != e1000_phy_gg82563) {
3715 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3716 if(ret_val) break;
3717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3719 if(ret_val) break;
3720 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3721 if(ret_val) break;
3722 ret_val = E1000_SUCCESS;
3723 } while(0);
3724
3725 return ret_val;
3726}
3727
3728/******************************************************************************
3729* Get PHY information from various PHY registers for igp PHY only.
3730*
3731* hw - Struct containing variables accessed by shared code
3732* phy_info - PHY information structure
3733******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003734static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735e1000_phy_igp_get_info(struct e1000_hw *hw,
3736 struct e1000_phy_info *phy_info)
3737{
3738 int32_t ret_val;
3739 uint16_t phy_data, polarity, min_length, max_length, average;
3740
3741 DEBUGFUNC("e1000_phy_igp_get_info");
3742
3743 /* The downshift status is checked only once, after link is established,
3744 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003745 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746
3747 /* IGP01E1000 does not need to support it. */
3748 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3749
3750 /* IGP01E1000 always correct polarity reversal */
3751 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3752
3753 /* Check polarity status */
3754 ret_val = e1000_check_polarity(hw, &polarity);
3755 if(ret_val)
3756 return ret_val;
3757
3758 phy_info->cable_polarity = polarity;
3759
3760 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3761 if(ret_val)
3762 return ret_val;
3763
3764 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3765 IGP01E1000_PSSR_MDIX_SHIFT;
3766
3767 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3768 IGP01E1000_PSSR_SPEED_1000MBPS) {
3769 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3770 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3771 if(ret_val)
3772 return ret_val;
3773
3774 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3775 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3776 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3777 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3778
3779 /* Get cable length */
3780 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3781 if(ret_val)
3782 return ret_val;
3783
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003784 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 average = (max_length + min_length) / 2;
3786
3787 if(average <= e1000_igp_cable_length_50)
3788 phy_info->cable_length = e1000_cable_length_50;
3789 else if(average <= e1000_igp_cable_length_80)
3790 phy_info->cable_length = e1000_cable_length_50_80;
3791 else if(average <= e1000_igp_cable_length_110)
3792 phy_info->cable_length = e1000_cable_length_80_110;
3793 else if(average <= e1000_igp_cable_length_140)
3794 phy_info->cable_length = e1000_cable_length_110_140;
3795 else
3796 phy_info->cable_length = e1000_cable_length_140;
3797 }
3798
3799 return E1000_SUCCESS;
3800}
3801
3802/******************************************************************************
3803* Get PHY information from various PHY registers fot m88 PHY only.
3804*
3805* hw - Struct containing variables accessed by shared code
3806* phy_info - PHY information structure
3807******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003808static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809e1000_phy_m88_get_info(struct e1000_hw *hw,
3810 struct e1000_phy_info *phy_info)
3811{
3812 int32_t ret_val;
3813 uint16_t phy_data, polarity;
3814
3815 DEBUGFUNC("e1000_phy_m88_get_info");
3816
3817 /* The downshift status is checked only once, after link is established,
3818 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003819 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
3821 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3822 if(ret_val)
3823 return ret_val;
3824
3825 phy_info->extended_10bt_distance =
3826 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3827 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3828 phy_info->polarity_correction =
3829 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3830 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3831
3832 /* Check polarity status */
3833 ret_val = e1000_check_polarity(hw, &polarity);
3834 if(ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07003835 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 phy_info->cable_polarity = polarity;
3837
3838 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3839 if(ret_val)
3840 return ret_val;
3841
3842 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3843 M88E1000_PSSR_MDIX_SHIFT;
3844
3845 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3846 /* Cable Length Estimation and Local/Remote Receiver Information
3847 * are only valid at 1000 Mbps.
3848 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003849 if (hw->phy_type != e1000_phy_gg82563) {
3850 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3851 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3852 } else {
3853 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
3854 &phy_data);
3855 if (ret_val)
3856 return ret_val;
3857
3858 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
3859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
3861 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3862 if(ret_val)
3863 return ret_val;
3864
3865 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3866 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3867
3868 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3869 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3870 }
3871
3872 return E1000_SUCCESS;
3873}
3874
3875/******************************************************************************
3876* Get PHY information from various PHY registers
3877*
3878* hw - Struct containing variables accessed by shared code
3879* phy_info - PHY information structure
3880******************************************************************************/
3881int32_t
3882e1000_phy_get_info(struct e1000_hw *hw,
3883 struct e1000_phy_info *phy_info)
3884{
3885 int32_t ret_val;
3886 uint16_t phy_data;
3887
3888 DEBUGFUNC("e1000_phy_get_info");
3889
3890 phy_info->cable_length = e1000_cable_length_undefined;
3891 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3892 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3893 phy_info->downshift = e1000_downshift_undefined;
3894 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3895 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3896 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3897 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3898
3899 if(hw->media_type != e1000_media_type_copper) {
3900 DEBUGOUT("PHY info is only valid for copper media\n");
3901 return -E1000_ERR_CONFIG;
3902 }
3903
3904 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3905 if(ret_val)
3906 return ret_val;
3907
3908 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3909 if(ret_val)
3910 return ret_val;
3911
3912 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3913 DEBUGOUT("PHY info is only valid if link is up\n");
3914 return -E1000_ERR_CONFIG;
3915 }
3916
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003917 if(hw->phy_type == e1000_phy_igp ||
3918 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 return e1000_phy_igp_get_info(hw, phy_info);
3920 else
3921 return e1000_phy_m88_get_info(hw, phy_info);
3922}
3923
3924int32_t
3925e1000_validate_mdi_setting(struct e1000_hw *hw)
3926{
3927 DEBUGFUNC("e1000_validate_mdi_settings");
3928
3929 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3930 DEBUGOUT("Invalid MDI setting detected\n");
3931 hw->mdix = 1;
3932 return -E1000_ERR_CONFIG;
3933 }
3934 return E1000_SUCCESS;
3935}
3936
3937
3938/******************************************************************************
3939 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003940 * is configured. Additionally, if this is ICH8, the flash controller GbE
3941 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 *
3943 * hw - Struct containing variables accessed by shared code
3944 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003945int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946e1000_init_eeprom_params(struct e1000_hw *hw)
3947{
3948 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3949 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003950 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 uint16_t eeprom_size;
3952
3953 DEBUGFUNC("e1000_init_eeprom_params");
3954
3955 switch (hw->mac_type) {
3956 case e1000_82542_rev2_0:
3957 case e1000_82542_rev2_1:
3958 case e1000_82543:
3959 case e1000_82544:
3960 eeprom->type = e1000_eeprom_microwire;
3961 eeprom->word_size = 64;
3962 eeprom->opcode_bits = 3;
3963 eeprom->address_bits = 6;
3964 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003965 eeprom->use_eerd = FALSE;
3966 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 break;
3968 case e1000_82540:
3969 case e1000_82545:
3970 case e1000_82545_rev_3:
3971 case e1000_82546:
3972 case e1000_82546_rev_3:
3973 eeprom->type = e1000_eeprom_microwire;
3974 eeprom->opcode_bits = 3;
3975 eeprom->delay_usec = 50;
3976 if(eecd & E1000_EECD_SIZE) {
3977 eeprom->word_size = 256;
3978 eeprom->address_bits = 8;
3979 } else {
3980 eeprom->word_size = 64;
3981 eeprom->address_bits = 6;
3982 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003983 eeprom->use_eerd = FALSE;
3984 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 break;
3986 case e1000_82541:
3987 case e1000_82541_rev_2:
3988 case e1000_82547:
3989 case e1000_82547_rev_2:
3990 if (eecd & E1000_EECD_TYPE) {
3991 eeprom->type = e1000_eeprom_spi;
3992 eeprom->opcode_bits = 8;
3993 eeprom->delay_usec = 1;
3994 if (eecd & E1000_EECD_ADDR_BITS) {
3995 eeprom->page_size = 32;
3996 eeprom->address_bits = 16;
3997 } else {
3998 eeprom->page_size = 8;
3999 eeprom->address_bits = 8;
4000 }
4001 } else {
4002 eeprom->type = e1000_eeprom_microwire;
4003 eeprom->opcode_bits = 3;
4004 eeprom->delay_usec = 50;
4005 if (eecd & E1000_EECD_ADDR_BITS) {
4006 eeprom->word_size = 256;
4007 eeprom->address_bits = 8;
4008 } else {
4009 eeprom->word_size = 64;
4010 eeprom->address_bits = 6;
4011 }
4012 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004013 eeprom->use_eerd = FALSE;
4014 eeprom->use_eewr = FALSE;
4015 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004016 case e1000_82571:
4017 case e1000_82572:
4018 eeprom->type = e1000_eeprom_spi;
4019 eeprom->opcode_bits = 8;
4020 eeprom->delay_usec = 1;
4021 if (eecd & E1000_EECD_ADDR_BITS) {
4022 eeprom->page_size = 32;
4023 eeprom->address_bits = 16;
4024 } else {
4025 eeprom->page_size = 8;
4026 eeprom->address_bits = 8;
4027 }
4028 eeprom->use_eerd = FALSE;
4029 eeprom->use_eewr = FALSE;
4030 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004031 case e1000_82573:
4032 eeprom->type = e1000_eeprom_spi;
4033 eeprom->opcode_bits = 8;
4034 eeprom->delay_usec = 1;
4035 if (eecd & E1000_EECD_ADDR_BITS) {
4036 eeprom->page_size = 32;
4037 eeprom->address_bits = 16;
4038 } else {
4039 eeprom->page_size = 8;
4040 eeprom->address_bits = 8;
4041 }
4042 eeprom->use_eerd = TRUE;
4043 eeprom->use_eewr = TRUE;
4044 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4045 eeprom->type = e1000_eeprom_flash;
4046 eeprom->word_size = 2048;
4047
4048 /* Ensure that the Autonomous FLASH update bit is cleared due to
4049 * Flash update issue on parts which use a FLASH for NVM. */
4050 eecd &= ~E1000_EECD_AUPDEN;
4051 E1000_WRITE_REG(hw, EECD, eecd);
4052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004054 case e1000_80003es2lan:
4055 eeprom->type = e1000_eeprom_spi;
4056 eeprom->opcode_bits = 8;
4057 eeprom->delay_usec = 1;
4058 if (eecd & E1000_EECD_ADDR_BITS) {
4059 eeprom->page_size = 32;
4060 eeprom->address_bits = 16;
4061 } else {
4062 eeprom->page_size = 8;
4063 eeprom->address_bits = 8;
4064 }
4065 eeprom->use_eerd = TRUE;
4066 eeprom->use_eewr = FALSE;
4067 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 default:
4069 break;
4070 }
4071
4072 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004073 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4074 * 32KB (incremented by powers of 2).
4075 */
4076 if(hw->mac_type <= e1000_82547_rev_2) {
4077 /* Set to default value for initial eeprom read. */
4078 eeprom->word_size = 64;
4079 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4080 if(ret_val)
4081 return ret_val;
4082 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4083 /* 256B eeprom size was not supported in earlier hardware, so we
4084 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4085 * is never the result used in the shifting logic below. */
4086 if(eeprom_size)
4087 eeprom_size++;
4088 } else {
4089 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4090 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004092
4093 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004095 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
4098/******************************************************************************
4099 * Raises the EEPROM's clock input.
4100 *
4101 * hw - Struct containing variables accessed by shared code
4102 * eecd - EECD's current value
4103 *****************************************************************************/
4104static void
4105e1000_raise_ee_clk(struct e1000_hw *hw,
4106 uint32_t *eecd)
4107{
4108 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4109 * wait <delay> microseconds.
4110 */
4111 *eecd = *eecd | E1000_EECD_SK;
4112 E1000_WRITE_REG(hw, EECD, *eecd);
4113 E1000_WRITE_FLUSH(hw);
4114 udelay(hw->eeprom.delay_usec);
4115}
4116
4117/******************************************************************************
4118 * Lowers the EEPROM's clock input.
4119 *
4120 * hw - Struct containing variables accessed by shared code
4121 * eecd - EECD's current value
4122 *****************************************************************************/
4123static void
4124e1000_lower_ee_clk(struct e1000_hw *hw,
4125 uint32_t *eecd)
4126{
4127 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4128 * wait 50 microseconds.
4129 */
4130 *eecd = *eecd & ~E1000_EECD_SK;
4131 E1000_WRITE_REG(hw, EECD, *eecd);
4132 E1000_WRITE_FLUSH(hw);
4133 udelay(hw->eeprom.delay_usec);
4134}
4135
4136/******************************************************************************
4137 * Shift data bits out to the EEPROM.
4138 *
4139 * hw - Struct containing variables accessed by shared code
4140 * data - data to send to the EEPROM
4141 * count - number of bits to shift out
4142 *****************************************************************************/
4143static void
4144e1000_shift_out_ee_bits(struct e1000_hw *hw,
4145 uint16_t data,
4146 uint16_t count)
4147{
4148 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4149 uint32_t eecd;
4150 uint32_t mask;
4151
4152 /* We need to shift "count" bits out to the EEPROM. So, value in the
4153 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4154 * In order to do this, "data" must be broken down into bits.
4155 */
4156 mask = 0x01 << (count - 1);
4157 eecd = E1000_READ_REG(hw, EECD);
4158 if (eeprom->type == e1000_eeprom_microwire) {
4159 eecd &= ~E1000_EECD_DO;
4160 } else if (eeprom->type == e1000_eeprom_spi) {
4161 eecd |= E1000_EECD_DO;
4162 }
4163 do {
4164 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4165 * and then raising and then lowering the clock (the SK bit controls
4166 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4167 * by setting "DI" to "0" and then raising and then lowering the clock.
4168 */
4169 eecd &= ~E1000_EECD_DI;
4170
4171 if(data & mask)
4172 eecd |= E1000_EECD_DI;
4173
4174 E1000_WRITE_REG(hw, EECD, eecd);
4175 E1000_WRITE_FLUSH(hw);
4176
4177 udelay(eeprom->delay_usec);
4178
4179 e1000_raise_ee_clk(hw, &eecd);
4180 e1000_lower_ee_clk(hw, &eecd);
4181
4182 mask = mask >> 1;
4183
4184 } while(mask);
4185
4186 /* We leave the "DI" bit set to "0" when we leave this routine. */
4187 eecd &= ~E1000_EECD_DI;
4188 E1000_WRITE_REG(hw, EECD, eecd);
4189}
4190
4191/******************************************************************************
4192 * Shift data bits in from the EEPROM
4193 *
4194 * hw - Struct containing variables accessed by shared code
4195 *****************************************************************************/
4196static uint16_t
4197e1000_shift_in_ee_bits(struct e1000_hw *hw,
4198 uint16_t count)
4199{
4200 uint32_t eecd;
4201 uint32_t i;
4202 uint16_t data;
4203
4204 /* In order to read a register from the EEPROM, we need to shift 'count'
4205 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4206 * input to the EEPROM (setting the SK bit), and then reading the value of
4207 * the "DO" bit. During this "shifting in" process the "DI" bit should
4208 * always be clear.
4209 */
4210
4211 eecd = E1000_READ_REG(hw, EECD);
4212
4213 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4214 data = 0;
4215
4216 for(i = 0; i < count; i++) {
4217 data = data << 1;
4218 e1000_raise_ee_clk(hw, &eecd);
4219
4220 eecd = E1000_READ_REG(hw, EECD);
4221
4222 eecd &= ~(E1000_EECD_DI);
4223 if(eecd & E1000_EECD_DO)
4224 data |= 1;
4225
4226 e1000_lower_ee_clk(hw, &eecd);
4227 }
4228
4229 return data;
4230}
4231
4232/******************************************************************************
4233 * Prepares EEPROM for access
4234 *
4235 * hw - Struct containing variables accessed by shared code
4236 *
4237 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4238 * function should be called before issuing a command to the EEPROM.
4239 *****************************************************************************/
4240static int32_t
4241e1000_acquire_eeprom(struct e1000_hw *hw)
4242{
4243 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4244 uint32_t eecd, i=0;
4245
4246 DEBUGFUNC("e1000_acquire_eeprom");
4247
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004248 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4249 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 eecd = E1000_READ_REG(hw, EECD);
4251
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004252 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004253 /* Request EEPROM Access */
4254 if(hw->mac_type > e1000_82544) {
4255 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004257 eecd = E1000_READ_REG(hw, EECD);
4258 while((!(eecd & E1000_EECD_GNT)) &&
4259 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4260 i++;
4261 udelay(5);
4262 eecd = E1000_READ_REG(hw, EECD);
4263 }
4264 if(!(eecd & E1000_EECD_GNT)) {
4265 eecd &= ~E1000_EECD_REQ;
4266 E1000_WRITE_REG(hw, EECD, eecd);
4267 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004268 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004269 return -E1000_ERR_EEPROM;
4270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 }
4272 }
4273
4274 /* Setup EEPROM for Read/Write */
4275
4276 if (eeprom->type == e1000_eeprom_microwire) {
4277 /* Clear SK and DI */
4278 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4279 E1000_WRITE_REG(hw, EECD, eecd);
4280
4281 /* Set CS */
4282 eecd |= E1000_EECD_CS;
4283 E1000_WRITE_REG(hw, EECD, eecd);
4284 } else if (eeprom->type == e1000_eeprom_spi) {
4285 /* Clear SK and CS */
4286 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4287 E1000_WRITE_REG(hw, EECD, eecd);
4288 udelay(1);
4289 }
4290
4291 return E1000_SUCCESS;
4292}
4293
4294/******************************************************************************
4295 * Returns EEPROM to a "standby" state
4296 *
4297 * hw - Struct containing variables accessed by shared code
4298 *****************************************************************************/
4299static void
4300e1000_standby_eeprom(struct e1000_hw *hw)
4301{
4302 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4303 uint32_t eecd;
4304
4305 eecd = E1000_READ_REG(hw, EECD);
4306
4307 if(eeprom->type == e1000_eeprom_microwire) {
4308 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4309 E1000_WRITE_REG(hw, EECD, eecd);
4310 E1000_WRITE_FLUSH(hw);
4311 udelay(eeprom->delay_usec);
4312
4313 /* Clock high */
4314 eecd |= E1000_EECD_SK;
4315 E1000_WRITE_REG(hw, EECD, eecd);
4316 E1000_WRITE_FLUSH(hw);
4317 udelay(eeprom->delay_usec);
4318
4319 /* Select EEPROM */
4320 eecd |= E1000_EECD_CS;
4321 E1000_WRITE_REG(hw, EECD, eecd);
4322 E1000_WRITE_FLUSH(hw);
4323 udelay(eeprom->delay_usec);
4324
4325 /* Clock low */
4326 eecd &= ~E1000_EECD_SK;
4327 E1000_WRITE_REG(hw, EECD, eecd);
4328 E1000_WRITE_FLUSH(hw);
4329 udelay(eeprom->delay_usec);
4330 } else if(eeprom->type == e1000_eeprom_spi) {
4331 /* Toggle CS to flush commands */
4332 eecd |= E1000_EECD_CS;
4333 E1000_WRITE_REG(hw, EECD, eecd);
4334 E1000_WRITE_FLUSH(hw);
4335 udelay(eeprom->delay_usec);
4336 eecd &= ~E1000_EECD_CS;
4337 E1000_WRITE_REG(hw, EECD, eecd);
4338 E1000_WRITE_FLUSH(hw);
4339 udelay(eeprom->delay_usec);
4340 }
4341}
4342
4343/******************************************************************************
4344 * Terminates a command by inverting the EEPROM's chip select pin
4345 *
4346 * hw - Struct containing variables accessed by shared code
4347 *****************************************************************************/
4348static void
4349e1000_release_eeprom(struct e1000_hw *hw)
4350{
4351 uint32_t eecd;
4352
4353 DEBUGFUNC("e1000_release_eeprom");
4354
4355 eecd = E1000_READ_REG(hw, EECD);
4356
4357 if (hw->eeprom.type == e1000_eeprom_spi) {
4358 eecd |= E1000_EECD_CS; /* Pull CS high */
4359 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4360
4361 E1000_WRITE_REG(hw, EECD, eecd);
4362
4363 udelay(hw->eeprom.delay_usec);
4364 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4365 /* cleanup eeprom */
4366
4367 /* CS on Microwire is active-high */
4368 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4369
4370 E1000_WRITE_REG(hw, EECD, eecd);
4371
4372 /* Rising edge of clock */
4373 eecd |= E1000_EECD_SK;
4374 E1000_WRITE_REG(hw, EECD, eecd);
4375 E1000_WRITE_FLUSH(hw);
4376 udelay(hw->eeprom.delay_usec);
4377
4378 /* Falling edge of clock */
4379 eecd &= ~E1000_EECD_SK;
4380 E1000_WRITE_REG(hw, EECD, eecd);
4381 E1000_WRITE_FLUSH(hw);
4382 udelay(hw->eeprom.delay_usec);
4383 }
4384
4385 /* Stop requesting EEPROM access */
4386 if(hw->mac_type > e1000_82544) {
4387 eecd &= ~E1000_EECD_REQ;
4388 E1000_WRITE_REG(hw, EECD, eecd);
4389 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004390
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004391 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392}
4393
4394/******************************************************************************
4395 * Reads a 16 bit word from the EEPROM.
4396 *
4397 * hw - Struct containing variables accessed by shared code
4398 *****************************************************************************/
4399int32_t
4400e1000_spi_eeprom_ready(struct e1000_hw *hw)
4401{
4402 uint16_t retry_count = 0;
4403 uint8_t spi_stat_reg;
4404
4405 DEBUGFUNC("e1000_spi_eeprom_ready");
4406
4407 /* Read "Status Register" repeatedly until the LSB is cleared. The
4408 * EEPROM will signal that the command has been completed by clearing
4409 * bit 0 of the internal status register. If it's not cleared within
4410 * 5 milliseconds, then error out.
4411 */
4412 retry_count = 0;
4413 do {
4414 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4415 hw->eeprom.opcode_bits);
4416 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4417 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4418 break;
4419
4420 udelay(5);
4421 retry_count += 5;
4422
4423 e1000_standby_eeprom(hw);
4424 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4425
4426 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4427 * only 0-5mSec on 5V devices)
4428 */
4429 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4430 DEBUGOUT("SPI EEPROM Status error\n");
4431 return -E1000_ERR_EEPROM;
4432 }
4433
4434 return E1000_SUCCESS;
4435}
4436
4437/******************************************************************************
4438 * Reads a 16 bit word from the EEPROM.
4439 *
4440 * hw - Struct containing variables accessed by shared code
4441 * offset - offset of word in the EEPROM to read
4442 * data - word read from the EEPROM
4443 * words - number of words to read
4444 *****************************************************************************/
4445int32_t
4446e1000_read_eeprom(struct e1000_hw *hw,
4447 uint16_t offset,
4448 uint16_t words,
4449 uint16_t *data)
4450{
4451 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4452 uint32_t i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004453 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454
4455 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004456
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 /* A check for invalid values: offset too large, too many words, and not
4458 * enough words.
4459 */
4460 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4461 (words == 0)) {
4462 DEBUGOUT("\"words\" parameter out of bounds\n");
4463 return -E1000_ERR_EEPROM;
4464 }
4465
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004466 /* FLASH reads without acquiring the semaphore are safe */
4467 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4468 hw->eeprom.use_eerd == FALSE) {
4469 switch (hw->mac_type) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004470 case e1000_80003es2lan:
4471 break;
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004472 default:
4473 /* Prepare the EEPROM for reading */
4474 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4475 return -E1000_ERR_EEPROM;
4476 break;
4477 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004478 }
4479
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004480 if (eeprom->use_eerd == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004481 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4482 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4483 (hw->mac_type != e1000_82573))
4484 e1000_release_eeprom(hw);
4485 return ret_val;
4486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487
4488 if(eeprom->type == e1000_eeprom_spi) {
4489 uint16_t word_in;
4490 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4491
4492 if(e1000_spi_eeprom_ready(hw)) {
4493 e1000_release_eeprom(hw);
4494 return -E1000_ERR_EEPROM;
4495 }
4496
4497 e1000_standby_eeprom(hw);
4498
4499 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4500 if((eeprom->address_bits == 8) && (offset >= 128))
4501 read_opcode |= EEPROM_A8_OPCODE_SPI;
4502
4503 /* Send the READ command (opcode + addr) */
4504 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4505 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4506
4507 /* Read the data. The address of the eeprom internally increments with
4508 * each byte (spi) being read, saving on the overhead of eeprom setup
4509 * and tear-down. The address counter will roll over if reading beyond
4510 * the size of the eeprom, thus allowing the entire memory to be read
4511 * starting from any offset. */
4512 for (i = 0; i < words; i++) {
4513 word_in = e1000_shift_in_ee_bits(hw, 16);
4514 data[i] = (word_in >> 8) | (word_in << 8);
4515 }
4516 } else if(eeprom->type == e1000_eeprom_microwire) {
4517 for (i = 0; i < words; i++) {
4518 /* Send the READ command (opcode + addr) */
4519 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4520 eeprom->opcode_bits);
4521 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4522 eeprom->address_bits);
4523
4524 /* Read the data. For microwire, each word requires the overhead
4525 * of eeprom setup and tear-down. */
4526 data[i] = e1000_shift_in_ee_bits(hw, 16);
4527 e1000_standby_eeprom(hw);
4528 }
4529 }
4530
4531 /* End this read operation */
4532 e1000_release_eeprom(hw);
4533
4534 return E1000_SUCCESS;
4535}
4536
4537/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004538 * Reads a 16 bit word from the EEPROM using the EERD register.
4539 *
4540 * hw - Struct containing variables accessed by shared code
4541 * offset - offset of word in the EEPROM to read
4542 * data - word read from the EEPROM
4543 * words - number of words to read
4544 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004545static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004546e1000_read_eeprom_eerd(struct e1000_hw *hw,
4547 uint16_t offset,
4548 uint16_t words,
4549 uint16_t *data)
4550{
4551 uint32_t i, eerd = 0;
4552 int32_t error = 0;
4553
4554 for (i = 0; i < words; i++) {
4555 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4556 E1000_EEPROM_RW_REG_START;
4557
4558 E1000_WRITE_REG(hw, EERD, eerd);
4559 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07004560
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004561 if(error) {
4562 break;
4563 }
4564 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07004565
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004566 }
Auke Kok76c224b2006-05-23 13:36:06 -07004567
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004568 return error;
4569}
4570
4571/******************************************************************************
4572 * Writes a 16 bit word from the EEPROM using the EEWR register.
4573 *
4574 * hw - Struct containing variables accessed by shared code
4575 * offset - offset of word in the EEPROM to read
4576 * data - word read from the EEPROM
4577 * words - number of words to read
4578 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004579static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004580e1000_write_eeprom_eewr(struct e1000_hw *hw,
4581 uint16_t offset,
4582 uint16_t words,
4583 uint16_t *data)
4584{
4585 uint32_t register_value = 0;
4586 uint32_t i = 0;
4587 int32_t error = 0;
4588
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004589 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4590 return -E1000_ERR_SWFW_SYNC;
4591
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004592 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07004593 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4594 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004595 E1000_EEPROM_RW_REG_START;
4596
4597 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4598 if(error) {
4599 break;
Auke Kok76c224b2006-05-23 13:36:06 -07004600 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004601
4602 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07004603
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004604 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07004605
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004606 if(error) {
4607 break;
Auke Kok76c224b2006-05-23 13:36:06 -07004608 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004609 }
Auke Kok76c224b2006-05-23 13:36:06 -07004610
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004611 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004612 return error;
4613}
4614
4615/******************************************************************************
4616 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4617 *
4618 * hw - Struct containing variables accessed by shared code
4619 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004620static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004621e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
4622{
4623 uint32_t attempts = 100000;
4624 uint32_t i, reg = 0;
4625 int32_t done = E1000_ERR_EEPROM;
4626
4627 for(i = 0; i < attempts; i++) {
4628 if(eerd == E1000_EEPROM_POLL_READ)
4629 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07004630 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004631 reg = E1000_READ_REG(hw, EEWR);
4632
4633 if(reg & E1000_EEPROM_RW_REG_DONE) {
4634 done = E1000_SUCCESS;
4635 break;
4636 }
4637 udelay(5);
4638 }
4639
4640 return done;
4641}
4642
4643/***************************************************************************
4644* Description: Determines if the onboard NVM is FLASH or EEPROM.
4645*
4646* hw - Struct containing variables accessed by shared code
4647****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004648static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004649e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4650{
4651 uint32_t eecd = 0;
4652
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004653 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
4654
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004655 if(hw->mac_type == e1000_82573) {
4656 eecd = E1000_READ_REG(hw, EECD);
4657
4658 /* Isolate bits 15 & 16 */
4659 eecd = ((eecd >> 15) & 0x03);
4660
4661 /* If both bits are set, device is Flash type */
4662 if(eecd == 0x03) {
4663 return FALSE;
4664 }
4665 }
4666 return TRUE;
4667}
4668
4669/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 * Verifies that the EEPROM has a valid checksum
4671 *
4672 * hw - Struct containing variables accessed by shared code
4673 *
4674 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4675 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4676 * valid.
4677 *****************************************************************************/
4678int32_t
4679e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4680{
4681 uint16_t checksum = 0;
4682 uint16_t i, eeprom_data;
4683
4684 DEBUGFUNC("e1000_validate_eeprom_checksum");
4685
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004686 if ((hw->mac_type == e1000_82573) &&
4687 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
4688 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4689 * 10h-12h. Checksum may need to be fixed. */
4690 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
4691 if ((eeprom_data & 0x10) == 0) {
4692 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4693 * has already been fixed. If the checksum is still wrong and this
4694 * bit is a 1, we need to return bad checksum. Otherwise, we need
4695 * to set this bit to a 1 and update the checksum. */
4696 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
4697 if ((eeprom_data & 0x8000) == 0) {
4698 eeprom_data |= 0x8000;
4699 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
4700 e1000_update_eeprom_checksum(hw);
4701 }
4702 }
4703 }
4704
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4706 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4707 DEBUGOUT("EEPROM Read Error\n");
4708 return -E1000_ERR_EEPROM;
4709 }
4710 checksum += eeprom_data;
4711 }
4712
4713 if(checksum == (uint16_t) EEPROM_SUM)
4714 return E1000_SUCCESS;
4715 else {
4716 DEBUGOUT("EEPROM Checksum Invalid\n");
4717 return -E1000_ERR_EEPROM;
4718 }
4719}
4720
4721/******************************************************************************
4722 * Calculates the EEPROM checksum and writes it to the EEPROM
4723 *
4724 * hw - Struct containing variables accessed by shared code
4725 *
4726 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4727 * Writes the difference to word offset 63 of the EEPROM.
4728 *****************************************************************************/
4729int32_t
4730e1000_update_eeprom_checksum(struct e1000_hw *hw)
4731{
4732 uint16_t checksum = 0;
4733 uint16_t i, eeprom_data;
4734
4735 DEBUGFUNC("e1000_update_eeprom_checksum");
4736
4737 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4738 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4739 DEBUGOUT("EEPROM Read Error\n");
4740 return -E1000_ERR_EEPROM;
4741 }
4742 checksum += eeprom_data;
4743 }
4744 checksum = (uint16_t) EEPROM_SUM - checksum;
4745 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4746 DEBUGOUT("EEPROM Write Error\n");
4747 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004748 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4749 e1000_commit_shadow_ram(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 }
4751 return E1000_SUCCESS;
4752}
4753
4754/******************************************************************************
4755 * Parent function for writing words to the different EEPROM types.
4756 *
4757 * hw - Struct containing variables accessed by shared code
4758 * offset - offset within the EEPROM to be written to
4759 * words - number of words to write
4760 * data - 16 bit word to be written to the EEPROM
4761 *
4762 * If e1000_update_eeprom_checksum is not called after this function, the
4763 * EEPROM will most likely contain an invalid checksum.
4764 *****************************************************************************/
4765int32_t
4766e1000_write_eeprom(struct e1000_hw *hw,
4767 uint16_t offset,
4768 uint16_t words,
4769 uint16_t *data)
4770{
4771 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4772 int32_t status = 0;
4773
4774 DEBUGFUNC("e1000_write_eeprom");
4775
4776 /* A check for invalid values: offset too large, too many words, and not
4777 * enough words.
4778 */
4779 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4780 (words == 0)) {
4781 DEBUGOUT("\"words\" parameter out of bounds\n");
4782 return -E1000_ERR_EEPROM;
4783 }
4784
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004785 /* 82573 writes only through eewr */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004786 if(eeprom->use_eewr == TRUE)
4787 return e1000_write_eeprom_eewr(hw, offset, words, data);
4788
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 /* Prepare the EEPROM for writing */
4790 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4791 return -E1000_ERR_EEPROM;
4792
4793 if(eeprom->type == e1000_eeprom_microwire) {
4794 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4795 } else {
4796 status = e1000_write_eeprom_spi(hw, offset, words, data);
4797 msec_delay(10);
4798 }
4799
4800 /* Done with writing */
4801 e1000_release_eeprom(hw);
4802
4803 return status;
4804}
4805
4806/******************************************************************************
4807 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4808 *
4809 * hw - Struct containing variables accessed by shared code
4810 * offset - offset within the EEPROM to be written to
4811 * words - number of words to write
4812 * data - pointer to array of 8 bit words to be written to the EEPROM
4813 *
4814 *****************************************************************************/
4815int32_t
4816e1000_write_eeprom_spi(struct e1000_hw *hw,
4817 uint16_t offset,
4818 uint16_t words,
4819 uint16_t *data)
4820{
4821 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4822 uint16_t widx = 0;
4823
4824 DEBUGFUNC("e1000_write_eeprom_spi");
4825
4826 while (widx < words) {
4827 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4828
4829 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4830
4831 e1000_standby_eeprom(hw);
4832
4833 /* Send the WRITE ENABLE command (8 bit opcode ) */
4834 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4835 eeprom->opcode_bits);
4836
4837 e1000_standby_eeprom(hw);
4838
4839 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4840 if((eeprom->address_bits == 8) && (offset >= 128))
4841 write_opcode |= EEPROM_A8_OPCODE_SPI;
4842
4843 /* Send the Write command (8-bit opcode + addr) */
4844 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4845
4846 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4847 eeprom->address_bits);
4848
4849 /* Send the data */
4850
4851 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4852 while (widx < words) {
4853 uint16_t word_out = data[widx];
4854 word_out = (word_out >> 8) | (word_out << 8);
4855 e1000_shift_out_ee_bits(hw, word_out, 16);
4856 widx++;
4857
4858 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4859 * operation, while the smaller eeproms are capable of an 8-byte
4860 * PAGE WRITE operation. Break the inner loop to pass new address
4861 */
4862 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4863 e1000_standby_eeprom(hw);
4864 break;
4865 }
4866 }
4867 }
4868
4869 return E1000_SUCCESS;
4870}
4871
4872/******************************************************************************
4873 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4874 *
4875 * hw - Struct containing variables accessed by shared code
4876 * offset - offset within the EEPROM to be written to
4877 * words - number of words to write
4878 * data - pointer to array of 16 bit words to be written to the EEPROM
4879 *
4880 *****************************************************************************/
4881int32_t
4882e1000_write_eeprom_microwire(struct e1000_hw *hw,
4883 uint16_t offset,
4884 uint16_t words,
4885 uint16_t *data)
4886{
4887 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4888 uint32_t eecd;
4889 uint16_t words_written = 0;
4890 uint16_t i = 0;
4891
4892 DEBUGFUNC("e1000_write_eeprom_microwire");
4893
4894 /* Send the write enable command to the EEPROM (3-bit opcode plus
4895 * 6/8-bit dummy address beginning with 11). It's less work to include
4896 * the 11 of the dummy address as part of the opcode than it is to shift
4897 * it over the correct number of bits for the address. This puts the
4898 * EEPROM into write/erase mode.
4899 */
4900 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4901 (uint16_t)(eeprom->opcode_bits + 2));
4902
4903 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4904
4905 /* Prepare the EEPROM */
4906 e1000_standby_eeprom(hw);
4907
4908 while (words_written < words) {
4909 /* Send the Write command (3-bit opcode + addr) */
4910 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4911 eeprom->opcode_bits);
4912
4913 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4914 eeprom->address_bits);
4915
4916 /* Send the data */
4917 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4918
4919 /* Toggle the CS line. This in effect tells the EEPROM to execute
4920 * the previous command.
4921 */
4922 e1000_standby_eeprom(hw);
4923
4924 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4925 * signal that the command has been completed by raising the DO signal.
4926 * If DO does not go high in 10 milliseconds, then error out.
4927 */
4928 for(i = 0; i < 200; i++) {
4929 eecd = E1000_READ_REG(hw, EECD);
4930 if(eecd & E1000_EECD_DO) break;
4931 udelay(50);
4932 }
4933 if(i == 200) {
4934 DEBUGOUT("EEPROM Write did not complete\n");
4935 return -E1000_ERR_EEPROM;
4936 }
4937
4938 /* Recover from write */
4939 e1000_standby_eeprom(hw);
4940
4941 words_written++;
4942 }
4943
4944 /* Send the write disable command to the EEPROM (3-bit opcode plus
4945 * 6/8-bit dummy address beginning with 10). It's less work to include
4946 * the 10 of the dummy address as part of the opcode than it is to shift
4947 * it over the correct number of bits for the address. This takes the
4948 * EEPROM out of write/erase mode.
4949 */
4950 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4951 (uint16_t)(eeprom->opcode_bits + 2));
4952
4953 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4954
4955 return E1000_SUCCESS;
4956}
4957
4958/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004959 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4960 * in the eeprom cache and the non modified values in the currently active bank
4961 * to the new bank.
4962 *
4963 * hw - Struct containing variables accessed by shared code
4964 * offset - offset of word in the EEPROM to read
4965 * data - word read from the EEPROM
4966 * words - number of words to read
4967 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004968static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004969e1000_commit_shadow_ram(struct e1000_hw *hw)
4970{
4971 uint32_t attempts = 100000;
4972 uint32_t eecd = 0;
4973 uint32_t flop = 0;
4974 uint32_t i = 0;
4975 int32_t error = E1000_SUCCESS;
4976
4977 /* The flop register will be used to determine if flash type is STM */
4978 flop = E1000_READ_REG(hw, FLOP);
4979
4980 if (hw->mac_type == e1000_82573) {
4981 for (i=0; i < attempts; i++) {
4982 eecd = E1000_READ_REG(hw, EECD);
4983 if ((eecd & E1000_EECD_FLUPD) == 0) {
4984 break;
4985 }
4986 udelay(5);
4987 }
4988
4989 if (i == attempts) {
4990 return -E1000_ERR_EEPROM;
4991 }
4992
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004993 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004994 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4995 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4996 }
4997
4998 /* Perform the flash update */
4999 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5000
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005001 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005002 eecd = E1000_READ_REG(hw, EECD);
5003 if ((eecd & E1000_EECD_FLUPD) == 0) {
5004 break;
5005 }
5006 udelay(5);
5007 }
5008
5009 if (i == attempts) {
5010 return -E1000_ERR_EEPROM;
5011 }
5012 }
5013
5014 return error;
5015}
5016
5017/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 * Reads the adapter's part number from the EEPROM
5019 *
5020 * hw - Struct containing variables accessed by shared code
5021 * part_num - Adapter's part number
5022 *****************************************************************************/
5023int32_t
5024e1000_read_part_num(struct e1000_hw *hw,
5025 uint32_t *part_num)
5026{
5027 uint16_t offset = EEPROM_PBA_BYTE_1;
5028 uint16_t eeprom_data;
5029
5030 DEBUGFUNC("e1000_read_part_num");
5031
5032 /* Get word 0 from EEPROM */
5033 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5034 DEBUGOUT("EEPROM Read Error\n");
5035 return -E1000_ERR_EEPROM;
5036 }
5037 /* Save word 0 in upper half of part_num */
5038 *part_num = (uint32_t) (eeprom_data << 16);
5039
5040 /* Get word 1 from EEPROM */
5041 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5042 DEBUGOUT("EEPROM Read Error\n");
5043 return -E1000_ERR_EEPROM;
5044 }
5045 /* Save word 1 in lower half of part_num */
5046 *part_num |= eeprom_data;
5047
5048 return E1000_SUCCESS;
5049}
5050
5051/******************************************************************************
5052 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5053 * second function of dual function devices
5054 *
5055 * hw - Struct containing variables accessed by shared code
5056 *****************************************************************************/
5057int32_t
5058e1000_read_mac_addr(struct e1000_hw * hw)
5059{
5060 uint16_t offset;
5061 uint16_t eeprom_data, i;
5062
5063 DEBUGFUNC("e1000_read_mac_addr");
5064
5065 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5066 offset = i >> 1;
5067 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5068 DEBUGOUT("EEPROM Read Error\n");
5069 return -E1000_ERR_EEPROM;
5070 }
5071 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5072 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5073 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005074
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005075 switch (hw->mac_type) {
5076 default:
5077 break;
5078 case e1000_82546:
5079 case e1000_82546_rev_3:
5080 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005081 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005082 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005084 break;
5085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086
5087 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5088 hw->mac_addr[i] = hw->perm_mac_addr[i];
5089 return E1000_SUCCESS;
5090}
5091
5092/******************************************************************************
5093 * Initializes receive address filters.
5094 *
5095 * hw - Struct containing variables accessed by shared code
5096 *
5097 * Places the MAC address in receive address register 0 and clears the rest
5098 * of the receive addresss registers. Clears the multicast table. Assumes
5099 * the receiver is in reset when the routine is called.
5100 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005101static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102e1000_init_rx_addrs(struct e1000_hw *hw)
5103{
5104 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005105 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
5107 DEBUGFUNC("e1000_init_rx_addrs");
5108
5109 /* Setup the receive address. */
5110 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5111
5112 e1000_rar_set(hw, hw->mac_addr, 0);
5113
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005114 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005115
5116 /* Reserve a spot for the Locally Administered Address to work around
5117 * an 82571 issue in which a reset on one port will reload the MAC on
5118 * the other port. */
5119 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5120 rar_num -= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121 /* Zero out the other 15 receive addresses. */
5122 DEBUGOUT("Clearing RAR[1-15]\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005123 for(i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005125 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005127 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 }
5129}
5130
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005131#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132/******************************************************************************
5133 * Updates the MAC's list of multicast addresses.
5134 *
5135 * hw - Struct containing variables accessed by shared code
5136 * mc_addr_list - the list of new multicast addresses
5137 * mc_addr_count - number of addresses
5138 * pad - number of bytes between addresses in the list
5139 * rar_used_count - offset where to start adding mc addresses into the RAR's
5140 *
5141 * The given list replaces any existing list. Clears the last 15 receive
5142 * address registers and the multicast table. Uses receive address registers
5143 * for the first 15 multicast addresses, and hashes the rest into the
5144 * multicast table.
5145 *****************************************************************************/
5146void
5147e1000_mc_addr_list_update(struct e1000_hw *hw,
5148 uint8_t *mc_addr_list,
5149 uint32_t mc_addr_count,
5150 uint32_t pad,
5151 uint32_t rar_used_count)
5152{
5153 uint32_t hash_value;
5154 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005155 uint32_t num_rar_entry;
5156 uint32_t num_mta_entry;
Auke Kok76c224b2006-05-23 13:36:06 -07005157
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158 DEBUGFUNC("e1000_mc_addr_list_update");
5159
5160 /* Set the new number of MC addresses that we are being requested to use. */
5161 hw->num_mc_addrs = mc_addr_count;
5162
5163 /* Clear RAR[1-15] */
5164 DEBUGOUT(" Clearing RAR[1-15]\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005165 num_rar_entry = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005166 /* Reserve a spot for the Locally Administered Address to work around
5167 * an 82571 issue in which a reset on one port will reload the MAC on
5168 * the other port. */
5169 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5170 num_rar_entry -= 1;
5171
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005172 for(i = rar_used_count; i < num_rar_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005174 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005176 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 }
5178
5179 /* Clear the MTA */
5180 DEBUGOUT(" Clearing MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005181 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5182 for(i = 0; i < num_mta_entry; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005184 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 }
5186
5187 /* Add the new addresses */
5188 for(i = 0; i < mc_addr_count; i++) {
5189 DEBUGOUT(" Adding the multicast addresses:\n");
5190 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5191 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5192 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5193 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5194 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5195 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5196 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5197
5198 hash_value = e1000_hash_mc_addr(hw,
5199 mc_addr_list +
5200 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5201
5202 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5203
5204 /* Place this multicast address in the RAR if there is room, *
5205 * else put it in the MTA
5206 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005207 if (rar_used_count < num_rar_entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 e1000_rar_set(hw,
5209 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5210 rar_used_count);
5211 rar_used_count++;
5212 } else {
5213 e1000_mta_set(hw, hash_value);
5214 }
5215 }
5216 DEBUGOUT("MC Update Complete\n");
5217}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005218#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219
5220/******************************************************************************
5221 * Hashes an address to determine its location in the multicast table
5222 *
5223 * hw - Struct containing variables accessed by shared code
5224 * mc_addr - the multicast address to hash
5225 *****************************************************************************/
5226uint32_t
5227e1000_hash_mc_addr(struct e1000_hw *hw,
5228 uint8_t *mc_addr)
5229{
5230 uint32_t hash_value = 0;
5231
5232 /* The portion of the address that is used for the hash table is
5233 * determined by the mc_filter_type setting.
5234 */
5235 switch (hw->mc_filter_type) {
5236 /* [0] [1] [2] [3] [4] [5]
5237 * 01 AA 00 12 34 56
5238 * LSB MSB
5239 */
5240 case 0:
5241 /* [47:36] i.e. 0x563 for above example address */
5242 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5243 break;
5244 case 1:
5245 /* [46:35] i.e. 0xAC6 for above example address */
5246 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5247 break;
5248 case 2:
5249 /* [45:34] i.e. 0x5D8 for above example address */
5250 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5251 break;
5252 case 3:
5253 /* [43:32] i.e. 0x634 for above example address */
5254 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5255 break;
5256 }
5257
5258 hash_value &= 0xFFF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005259
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 return hash_value;
5261}
5262
5263/******************************************************************************
5264 * Sets the bit in the multicast table corresponding to the hash value.
5265 *
5266 * hw - Struct containing variables accessed by shared code
5267 * hash_value - Multicast address hash value
5268 *****************************************************************************/
5269void
5270e1000_mta_set(struct e1000_hw *hw,
5271 uint32_t hash_value)
5272{
5273 uint32_t hash_bit, hash_reg;
5274 uint32_t mta;
5275 uint32_t temp;
5276
5277 /* The MTA is a register array of 128 32-bit registers.
5278 * It is treated like an array of 4096 bits. We want to set
5279 * bit BitArray[hash_value]. So we figure out what register
5280 * the bit is in, read it, OR in the new bit, then write
5281 * back the new value. The register is determined by the
5282 * upper 7 bits of the hash value and the bit within that
5283 * register are determined by the lower 5 bits of the value.
5284 */
5285 hash_reg = (hash_value >> 5) & 0x7F;
5286 hash_bit = hash_value & 0x1F;
5287
5288 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5289
5290 mta |= (1 << hash_bit);
5291
5292 /* If we are on an 82544 and we are trying to write an odd offset
5293 * in the MTA, save off the previous entry before writing and
5294 * restore the old value after writing.
5295 */
5296 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5297 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5298 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005299 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005301 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 } else {
5303 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005304 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305 }
5306}
5307
5308/******************************************************************************
5309 * Puts an ethernet address into a receive address register.
5310 *
5311 * hw - Struct containing variables accessed by shared code
5312 * addr - Address to put into receive address register
5313 * index - Receive address register to write
5314 *****************************************************************************/
5315void
5316e1000_rar_set(struct e1000_hw *hw,
5317 uint8_t *addr,
5318 uint32_t index)
5319{
5320 uint32_t rar_low, rar_high;
5321
5322 /* HW expects these in little endian so we reverse the byte order
5323 * from network order (big endian) to little endian
5324 */
5325 rar_low = ((uint32_t) addr[0] |
5326 ((uint32_t) addr[1] << 8) |
5327 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005328 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005330 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5331 * unit hang.
5332 *
5333 * Description:
5334 * If there are any Rx frames queued up or otherwise present in the HW
5335 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5336 * hang. To work around this issue, we have to disable receives and
5337 * flush out all Rx frames before we enable RSS. To do so, we modify we
5338 * redirect all Rx traffic to manageability and then reset the HW.
5339 * This flushes away Rx frames, and (since the redirections to
5340 * manageability persists across resets) keeps new ones from coming in
5341 * while we work. Then, we clear the Address Valid AV bit for all MAC
5342 * addresses and undo the re-direction to manageability.
5343 * Now, frames are coming in again, but the MAC won't accept them, so
5344 * far so good. We now proceed to initialize RSS (if necessary) and
5345 * configure the Rx unit. Last, we re-enable the AV bits and continue
5346 * on our merry way.
5347 */
5348 switch (hw->mac_type) {
5349 case e1000_82571:
5350 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005351 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005352 if (hw->leave_av_bit_off == TRUE)
5353 break;
5354 default:
5355 /* Indicate to hardware the Address is Valid. */
5356 rar_high |= E1000_RAH_AV;
5357 break;
5358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359
5360 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005361 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005363 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364}
5365
5366/******************************************************************************
5367 * Writes a value to the specified offset in the VLAN filter table.
5368 *
5369 * hw - Struct containing variables accessed by shared code
5370 * offset - Offset in VLAN filer table to write
5371 * value - Value to write into VLAN filter table
5372 *****************************************************************************/
5373void
5374e1000_write_vfta(struct e1000_hw *hw,
5375 uint32_t offset,
5376 uint32_t value)
5377{
5378 uint32_t temp;
5379
5380 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5381 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5382 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005383 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005385 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386 } else {
5387 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005388 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 }
5390}
5391
5392/******************************************************************************
5393 * Clears the VLAN filer table
5394 *
5395 * hw - Struct containing variables accessed by shared code
5396 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005397static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398e1000_clear_vfta(struct e1000_hw *hw)
5399{
5400 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005401 uint32_t vfta_value = 0;
5402 uint32_t vfta_offset = 0;
5403 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005405 if (hw->mac_type == e1000_82573) {
5406 if (hw->mng_cookie.vlan_id != 0) {
5407 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5408 * ID. The following operations determine which 32b entry
5409 * (i.e. offset) into the array we want to set the VLAN ID
5410 * (i.e. bit) of the manageability unit. */
5411 vfta_offset = (hw->mng_cookie.vlan_id >>
5412 E1000_VFTA_ENTRY_SHIFT) &
5413 E1000_VFTA_ENTRY_MASK;
5414 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5415 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5416 }
5417 }
5418 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5419 /* If the offset we want to clear is the same offset of the
5420 * manageability VLAN ID, then clear all bits except that of the
5421 * manageability unit */
5422 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5423 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005424 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426}
5427
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005428static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005429e1000_id_led_init(struct e1000_hw * hw)
5430{
5431 uint32_t ledctl;
5432 const uint32_t ledctl_mask = 0x000000FF;
5433 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5434 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5435 uint16_t eeprom_data, i, temp;
5436 const uint16_t led_mask = 0x0F;
5437
5438 DEBUGFUNC("e1000_id_led_init");
5439
5440 if(hw->mac_type < e1000_82540) {
5441 /* Nothing to do */
5442 return E1000_SUCCESS;
5443 }
5444
5445 ledctl = E1000_READ_REG(hw, LEDCTL);
5446 hw->ledctl_default = ledctl;
5447 hw->ledctl_mode1 = hw->ledctl_default;
5448 hw->ledctl_mode2 = hw->ledctl_default;
5449
5450 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5451 DEBUGOUT("EEPROM Read Error\n");
5452 return -E1000_ERR_EEPROM;
5453 }
5454 if((eeprom_data== ID_LED_RESERVED_0000) ||
5455 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
5456 for(i = 0; i < 4; i++) {
5457 temp = (eeprom_data >> (i << 2)) & led_mask;
5458 switch(temp) {
5459 case ID_LED_ON1_DEF2:
5460 case ID_LED_ON1_ON2:
5461 case ID_LED_ON1_OFF2:
5462 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5463 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5464 break;
5465 case ID_LED_OFF1_DEF2:
5466 case ID_LED_OFF1_ON2:
5467 case ID_LED_OFF1_OFF2:
5468 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5469 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5470 break;
5471 default:
5472 /* Do nothing */
5473 break;
5474 }
5475 switch(temp) {
5476 case ID_LED_DEF1_ON2:
5477 case ID_LED_ON1_ON2:
5478 case ID_LED_OFF1_ON2:
5479 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5480 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5481 break;
5482 case ID_LED_DEF1_OFF2:
5483 case ID_LED_ON1_OFF2:
5484 case ID_LED_OFF1_OFF2:
5485 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5486 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5487 break;
5488 default:
5489 /* Do nothing */
5490 break;
5491 }
5492 }
5493 return E1000_SUCCESS;
5494}
5495
5496/******************************************************************************
5497 * Prepares SW controlable LED for use and saves the current state of the LED.
5498 *
5499 * hw - Struct containing variables accessed by shared code
5500 *****************************************************************************/
5501int32_t
5502e1000_setup_led(struct e1000_hw *hw)
5503{
5504 uint32_t ledctl;
5505 int32_t ret_val = E1000_SUCCESS;
5506
5507 DEBUGFUNC("e1000_setup_led");
5508
5509 switch(hw->mac_type) {
5510 case e1000_82542_rev2_0:
5511 case e1000_82542_rev2_1:
5512 case e1000_82543:
5513 case e1000_82544:
5514 /* No setup necessary */
5515 break;
5516 case e1000_82541:
5517 case e1000_82547:
5518 case e1000_82541_rev_2:
5519 case e1000_82547_rev_2:
5520 /* Turn off PHY Smart Power Down (if enabled) */
5521 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
5522 &hw->phy_spd_default);
5523 if(ret_val)
5524 return ret_val;
5525 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5526 (uint16_t)(hw->phy_spd_default &
5527 ~IGP01E1000_GMII_SPD));
5528 if(ret_val)
5529 return ret_val;
5530 /* Fall Through */
5531 default:
5532 if(hw->media_type == e1000_media_type_fiber) {
5533 ledctl = E1000_READ_REG(hw, LEDCTL);
5534 /* Save current LEDCTL settings */
5535 hw->ledctl_default = ledctl;
5536 /* Turn off LED0 */
5537 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
5538 E1000_LEDCTL_LED0_BLINK |
5539 E1000_LEDCTL_LED0_MODE_MASK);
5540 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
5541 E1000_LEDCTL_LED0_MODE_SHIFT);
5542 E1000_WRITE_REG(hw, LEDCTL, ledctl);
5543 } else if(hw->media_type == e1000_media_type_copper)
5544 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5545 break;
5546 }
5547
5548 return E1000_SUCCESS;
5549}
5550
5551/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07005552 * Used on 82571 and later Si that has LED blink bits.
5553 * Callers must use their own timer and should have already called
5554 * e1000_id_led_init()
5555 * Call e1000_cleanup led() to stop blinking
5556 *
5557 * hw - Struct containing variables accessed by shared code
5558 *****************************************************************************/
5559int32_t
5560e1000_blink_led_start(struct e1000_hw *hw)
5561{
5562 int16_t i;
5563 uint32_t ledctl_blink = 0;
5564
5565 DEBUGFUNC("e1000_id_led_blink_on");
5566
5567 if (hw->mac_type < e1000_82571) {
5568 /* Nothing to do */
5569 return E1000_SUCCESS;
5570 }
5571 if (hw->media_type == e1000_media_type_fiber) {
5572 /* always blink LED0 for PCI-E fiber */
5573 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
5574 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
5575 } else {
5576 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
5577 ledctl_blink = hw->ledctl_mode2;
5578 for (i=0; i < 4; i++)
5579 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
5580 E1000_LEDCTL_MODE_LED_ON)
5581 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
5582 }
5583
5584 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
5585
5586 return E1000_SUCCESS;
5587}
5588
5589/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590 * Restores the saved state of the SW controlable LED.
5591 *
5592 * hw - Struct containing variables accessed by shared code
5593 *****************************************************************************/
5594int32_t
5595e1000_cleanup_led(struct e1000_hw *hw)
5596{
5597 int32_t ret_val = E1000_SUCCESS;
5598
5599 DEBUGFUNC("e1000_cleanup_led");
5600
5601 switch(hw->mac_type) {
5602 case e1000_82542_rev2_0:
5603 case e1000_82542_rev2_1:
5604 case e1000_82543:
5605 case e1000_82544:
5606 /* No cleanup necessary */
5607 break;
5608 case e1000_82541:
5609 case e1000_82547:
5610 case e1000_82541_rev_2:
5611 case e1000_82547_rev_2:
5612 /* Turn on PHY Smart Power Down (if previously enabled) */
5613 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5614 hw->phy_spd_default);
5615 if(ret_val)
5616 return ret_val;
5617 /* Fall Through */
5618 default:
5619 /* Restore LEDCTL settings */
5620 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
5621 break;
5622 }
5623
5624 return E1000_SUCCESS;
5625}
5626
5627/******************************************************************************
5628 * Turns on the software controllable LED
5629 *
5630 * hw - Struct containing variables accessed by shared code
5631 *****************************************************************************/
5632int32_t
5633e1000_led_on(struct e1000_hw *hw)
5634{
5635 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5636
5637 DEBUGFUNC("e1000_led_on");
5638
5639 switch(hw->mac_type) {
5640 case e1000_82542_rev2_0:
5641 case e1000_82542_rev2_1:
5642 case e1000_82543:
5643 /* Set SW Defineable Pin 0 to turn on the LED */
5644 ctrl |= E1000_CTRL_SWDPIN0;
5645 ctrl |= E1000_CTRL_SWDPIO0;
5646 break;
5647 case e1000_82544:
5648 if(hw->media_type == e1000_media_type_fiber) {
5649 /* Set SW Defineable Pin 0 to turn on the LED */
5650 ctrl |= E1000_CTRL_SWDPIN0;
5651 ctrl |= E1000_CTRL_SWDPIO0;
5652 } else {
5653 /* Clear SW Defineable Pin 0 to turn on the LED */
5654 ctrl &= ~E1000_CTRL_SWDPIN0;
5655 ctrl |= E1000_CTRL_SWDPIO0;
5656 }
5657 break;
5658 default:
5659 if(hw->media_type == e1000_media_type_fiber) {
5660 /* Clear SW Defineable Pin 0 to turn on the LED */
5661 ctrl &= ~E1000_CTRL_SWDPIN0;
5662 ctrl |= E1000_CTRL_SWDPIO0;
5663 } else if(hw->media_type == e1000_media_type_copper) {
5664 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
5665 return E1000_SUCCESS;
5666 }
5667 break;
5668 }
5669
5670 E1000_WRITE_REG(hw, CTRL, ctrl);
5671
5672 return E1000_SUCCESS;
5673}
5674
5675/******************************************************************************
5676 * Turns off the software controllable LED
5677 *
5678 * hw - Struct containing variables accessed by shared code
5679 *****************************************************************************/
5680int32_t
5681e1000_led_off(struct e1000_hw *hw)
5682{
5683 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5684
5685 DEBUGFUNC("e1000_led_off");
5686
5687 switch(hw->mac_type) {
5688 case e1000_82542_rev2_0:
5689 case e1000_82542_rev2_1:
5690 case e1000_82543:
5691 /* Clear SW Defineable Pin 0 to turn off the LED */
5692 ctrl &= ~E1000_CTRL_SWDPIN0;
5693 ctrl |= E1000_CTRL_SWDPIO0;
5694 break;
5695 case e1000_82544:
5696 if(hw->media_type == e1000_media_type_fiber) {
5697 /* Clear SW Defineable Pin 0 to turn off the LED */
5698 ctrl &= ~E1000_CTRL_SWDPIN0;
5699 ctrl |= E1000_CTRL_SWDPIO0;
5700 } else {
5701 /* Set SW Defineable Pin 0 to turn off the LED */
5702 ctrl |= E1000_CTRL_SWDPIN0;
5703 ctrl |= E1000_CTRL_SWDPIO0;
5704 }
5705 break;
5706 default:
5707 if(hw->media_type == e1000_media_type_fiber) {
5708 /* Set SW Defineable Pin 0 to turn off the LED */
5709 ctrl |= E1000_CTRL_SWDPIN0;
5710 ctrl |= E1000_CTRL_SWDPIO0;
5711 } else if(hw->media_type == e1000_media_type_copper) {
5712 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5713 return E1000_SUCCESS;
5714 }
5715 break;
5716 }
5717
5718 E1000_WRITE_REG(hw, CTRL, ctrl);
5719
5720 return E1000_SUCCESS;
5721}
5722
5723/******************************************************************************
5724 * Clears all hardware statistics counters.
5725 *
5726 * hw - Struct containing variables accessed by shared code
5727 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005728static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729e1000_clear_hw_cntrs(struct e1000_hw *hw)
5730{
5731 volatile uint32_t temp;
5732
5733 temp = E1000_READ_REG(hw, CRCERRS);
5734 temp = E1000_READ_REG(hw, SYMERRS);
5735 temp = E1000_READ_REG(hw, MPC);
5736 temp = E1000_READ_REG(hw, SCC);
5737 temp = E1000_READ_REG(hw, ECOL);
5738 temp = E1000_READ_REG(hw, MCC);
5739 temp = E1000_READ_REG(hw, LATECOL);
5740 temp = E1000_READ_REG(hw, COLC);
5741 temp = E1000_READ_REG(hw, DC);
5742 temp = E1000_READ_REG(hw, SEC);
5743 temp = E1000_READ_REG(hw, RLEC);
5744 temp = E1000_READ_REG(hw, XONRXC);
5745 temp = E1000_READ_REG(hw, XONTXC);
5746 temp = E1000_READ_REG(hw, XOFFRXC);
5747 temp = E1000_READ_REG(hw, XOFFTXC);
5748 temp = E1000_READ_REG(hw, FCRUC);
5749 temp = E1000_READ_REG(hw, PRC64);
5750 temp = E1000_READ_REG(hw, PRC127);
5751 temp = E1000_READ_REG(hw, PRC255);
5752 temp = E1000_READ_REG(hw, PRC511);
5753 temp = E1000_READ_REG(hw, PRC1023);
5754 temp = E1000_READ_REG(hw, PRC1522);
5755 temp = E1000_READ_REG(hw, GPRC);
5756 temp = E1000_READ_REG(hw, BPRC);
5757 temp = E1000_READ_REG(hw, MPRC);
5758 temp = E1000_READ_REG(hw, GPTC);
5759 temp = E1000_READ_REG(hw, GORCL);
5760 temp = E1000_READ_REG(hw, GORCH);
5761 temp = E1000_READ_REG(hw, GOTCL);
5762 temp = E1000_READ_REG(hw, GOTCH);
5763 temp = E1000_READ_REG(hw, RNBC);
5764 temp = E1000_READ_REG(hw, RUC);
5765 temp = E1000_READ_REG(hw, RFC);
5766 temp = E1000_READ_REG(hw, ROC);
5767 temp = E1000_READ_REG(hw, RJC);
5768 temp = E1000_READ_REG(hw, TORL);
5769 temp = E1000_READ_REG(hw, TORH);
5770 temp = E1000_READ_REG(hw, TOTL);
5771 temp = E1000_READ_REG(hw, TOTH);
5772 temp = E1000_READ_REG(hw, TPR);
5773 temp = E1000_READ_REG(hw, TPT);
5774 temp = E1000_READ_REG(hw, PTC64);
5775 temp = E1000_READ_REG(hw, PTC127);
5776 temp = E1000_READ_REG(hw, PTC255);
5777 temp = E1000_READ_REG(hw, PTC511);
5778 temp = E1000_READ_REG(hw, PTC1023);
5779 temp = E1000_READ_REG(hw, PTC1522);
5780 temp = E1000_READ_REG(hw, MPTC);
5781 temp = E1000_READ_REG(hw, BPTC);
5782
5783 if(hw->mac_type < e1000_82543) return;
5784
5785 temp = E1000_READ_REG(hw, ALGNERRC);
5786 temp = E1000_READ_REG(hw, RXERRC);
5787 temp = E1000_READ_REG(hw, TNCRS);
5788 temp = E1000_READ_REG(hw, CEXTERR);
5789 temp = E1000_READ_REG(hw, TSCTC);
5790 temp = E1000_READ_REG(hw, TSCTFC);
5791
5792 if(hw->mac_type <= e1000_82544) return;
5793
5794 temp = E1000_READ_REG(hw, MGTPRC);
5795 temp = E1000_READ_REG(hw, MGTPDC);
5796 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005797
5798 if(hw->mac_type <= e1000_82547_rev_2) return;
5799
5800 temp = E1000_READ_REG(hw, IAC);
5801 temp = E1000_READ_REG(hw, ICRXOC);
5802 temp = E1000_READ_REG(hw, ICRXPTC);
5803 temp = E1000_READ_REG(hw, ICRXATC);
5804 temp = E1000_READ_REG(hw, ICTXPTC);
5805 temp = E1000_READ_REG(hw, ICTXATC);
5806 temp = E1000_READ_REG(hw, ICTXQEC);
5807 temp = E1000_READ_REG(hw, ICTXQMTC);
5808 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809}
5810
5811/******************************************************************************
5812 * Resets Adaptive IFS to its default state.
5813 *
5814 * hw - Struct containing variables accessed by shared code
5815 *
5816 * Call this after e1000_init_hw. You may override the IFS defaults by setting
5817 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5818 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5819 * before calling this function.
5820 *****************************************************************************/
5821void
5822e1000_reset_adaptive(struct e1000_hw *hw)
5823{
5824 DEBUGFUNC("e1000_reset_adaptive");
5825
5826 if(hw->adaptive_ifs) {
5827 if(!hw->ifs_params_forced) {
5828 hw->current_ifs_val = 0;
5829 hw->ifs_min_val = IFS_MIN;
5830 hw->ifs_max_val = IFS_MAX;
5831 hw->ifs_step_size = IFS_STEP;
5832 hw->ifs_ratio = IFS_RATIO;
5833 }
5834 hw->in_ifs_mode = FALSE;
5835 E1000_WRITE_REG(hw, AIT, 0);
5836 } else {
5837 DEBUGOUT("Not in Adaptive IFS mode!\n");
5838 }
5839}
5840
5841/******************************************************************************
5842 * Called during the callback/watchdog routine to update IFS value based on
5843 * the ratio of transmits to collisions.
5844 *
5845 * hw - Struct containing variables accessed by shared code
5846 * tx_packets - Number of transmits since last callback
5847 * total_collisions - Number of collisions since last callback
5848 *****************************************************************************/
5849void
5850e1000_update_adaptive(struct e1000_hw *hw)
5851{
5852 DEBUGFUNC("e1000_update_adaptive");
5853
5854 if(hw->adaptive_ifs) {
5855 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5856 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5857 hw->in_ifs_mode = TRUE;
5858 if(hw->current_ifs_val < hw->ifs_max_val) {
5859 if(hw->current_ifs_val == 0)
5860 hw->current_ifs_val = hw->ifs_min_val;
5861 else
5862 hw->current_ifs_val += hw->ifs_step_size;
5863 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5864 }
5865 }
5866 } else {
5867 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5868 hw->current_ifs_val = 0;
5869 hw->in_ifs_mode = FALSE;
5870 E1000_WRITE_REG(hw, AIT, 0);
5871 }
5872 }
5873 } else {
5874 DEBUGOUT("Not in Adaptive IFS mode!\n");
5875 }
5876}
5877
5878/******************************************************************************
5879 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5880 *
5881 * hw - Struct containing variables accessed by shared code
5882 * frame_len - The length of the frame in question
5883 * mac_addr - The Ethernet destination address of the frame in question
5884 *****************************************************************************/
5885void
5886e1000_tbi_adjust_stats(struct e1000_hw *hw,
5887 struct e1000_hw_stats *stats,
5888 uint32_t frame_len,
5889 uint8_t *mac_addr)
5890{
5891 uint64_t carry_bit;
5892
5893 /* First adjust the frame length. */
5894 frame_len--;
5895 /* We need to adjust the statistics counters, since the hardware
5896 * counters overcount this packet as a CRC error and undercount
5897 * the packet as a good packet
5898 */
5899 /* This packet should not be counted as a CRC error. */
5900 stats->crcerrs--;
5901 /* This packet does count as a Good Packet Received. */
5902 stats->gprc++;
5903
5904 /* Adjust the Good Octets received counters */
5905 carry_bit = 0x80000000 & stats->gorcl;
5906 stats->gorcl += frame_len;
5907 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5908 * Received Count) was one before the addition,
5909 * AND it is zero after, then we lost the carry out,
5910 * need to add one to Gorch (Good Octets Received Count High).
5911 * This could be simplified if all environments supported
5912 * 64-bit integers.
5913 */
5914 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5915 stats->gorch++;
5916 /* Is this a broadcast or multicast? Check broadcast first,
5917 * since the test for a multicast frame will test positive on
5918 * a broadcast frame.
5919 */
5920 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5921 /* Broadcast packet */
5922 stats->bprc++;
5923 else if(*mac_addr & 0x01)
5924 /* Multicast packet */
5925 stats->mprc++;
5926
5927 if(frame_len == hw->max_frame_size) {
5928 /* In this case, the hardware has overcounted the number of
5929 * oversize frames.
5930 */
5931 if(stats->roc > 0)
5932 stats->roc--;
5933 }
5934
5935 /* Adjust the bin counters when the extra byte put the frame in the
5936 * wrong bin. Remember that the frame_len was adjusted above.
5937 */
5938 if(frame_len == 64) {
5939 stats->prc64++;
5940 stats->prc127--;
5941 } else if(frame_len == 127) {
5942 stats->prc127++;
5943 stats->prc255--;
5944 } else if(frame_len == 255) {
5945 stats->prc255++;
5946 stats->prc511--;
5947 } else if(frame_len == 511) {
5948 stats->prc511++;
5949 stats->prc1023--;
5950 } else if(frame_len == 1023) {
5951 stats->prc1023++;
5952 stats->prc1522--;
5953 } else if(frame_len == 1522) {
5954 stats->prc1522++;
5955 }
5956}
5957
5958/******************************************************************************
5959 * Gets the current PCI bus type, speed, and width of the hardware
5960 *
5961 * hw - Struct containing variables accessed by shared code
5962 *****************************************************************************/
5963void
5964e1000_get_bus_info(struct e1000_hw *hw)
5965{
5966 uint32_t status;
5967
5968 switch (hw->mac_type) {
5969 case e1000_82542_rev2_0:
5970 case e1000_82542_rev2_1:
5971 hw->bus_type = e1000_bus_type_unknown;
5972 hw->bus_speed = e1000_bus_speed_unknown;
5973 hw->bus_width = e1000_bus_width_unknown;
5974 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005975 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005976 case e1000_82573:
5977 hw->bus_type = e1000_bus_type_pci_express;
5978 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirsherfd803242005-12-13 00:06:22 -05005979 hw->bus_width = e1000_bus_width_pciex_1;
5980 break;
5981 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005982 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05005983 hw->bus_type = e1000_bus_type_pci_express;
5984 hw->bus_speed = e1000_bus_speed_2500;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005985 hw->bus_width = e1000_bus_width_pciex_4;
5986 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 default:
5988 status = E1000_READ_REG(hw, STATUS);
5989 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5990 e1000_bus_type_pcix : e1000_bus_type_pci;
5991
5992 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5993 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5994 e1000_bus_speed_66 : e1000_bus_speed_120;
5995 } else if(hw->bus_type == e1000_bus_type_pci) {
5996 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5997 e1000_bus_speed_66 : e1000_bus_speed_33;
5998 } else {
5999 switch (status & E1000_STATUS_PCIX_SPEED) {
6000 case E1000_STATUS_PCIX_SPEED_66:
6001 hw->bus_speed = e1000_bus_speed_66;
6002 break;
6003 case E1000_STATUS_PCIX_SPEED_100:
6004 hw->bus_speed = e1000_bus_speed_100;
6005 break;
6006 case E1000_STATUS_PCIX_SPEED_133:
6007 hw->bus_speed = e1000_bus_speed_133;
6008 break;
6009 default:
6010 hw->bus_speed = e1000_bus_speed_reserved;
6011 break;
6012 }
6013 }
6014 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6015 e1000_bus_width_64 : e1000_bus_width_32;
6016 break;
6017 }
6018}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006019
6020#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021/******************************************************************************
6022 * Reads a value from one of the devices registers using port I/O (as opposed
6023 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6024 *
6025 * hw - Struct containing variables accessed by shared code
6026 * offset - offset to read from
6027 *****************************************************************************/
6028uint32_t
6029e1000_read_reg_io(struct e1000_hw *hw,
6030 uint32_t offset)
6031{
6032 unsigned long io_addr = hw->io_base;
6033 unsigned long io_data = hw->io_base + 4;
6034
6035 e1000_io_write(hw, io_addr, offset);
6036 return e1000_io_read(hw, io_data);
6037}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006038#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039
6040/******************************************************************************
6041 * Writes a value to one of the devices registers using port I/O (as opposed to
6042 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6043 *
6044 * hw - Struct containing variables accessed by shared code
6045 * offset - offset to write to
6046 * value - value to write
6047 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006048static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049e1000_write_reg_io(struct e1000_hw *hw,
6050 uint32_t offset,
6051 uint32_t value)
6052{
6053 unsigned long io_addr = hw->io_base;
6054 unsigned long io_data = hw->io_base + 4;
6055
6056 e1000_io_write(hw, io_addr, offset);
6057 e1000_io_write(hw, io_data, value);
6058}
6059
6060
6061/******************************************************************************
6062 * Estimates the cable length.
6063 *
6064 * hw - Struct containing variables accessed by shared code
6065 * min_length - The estimated minimum length
6066 * max_length - The estimated maximum length
6067 *
6068 * returns: - E1000_ERR_XXX
6069 * E1000_SUCCESS
6070 *
6071 * This function always returns a ranged length (minimum & maximum).
6072 * So for M88 phy's, this function interprets the one value returned from the
6073 * register to the minimum and maximum range.
6074 * For IGP phy's, the function calculates the range by the AGC registers.
6075 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006076static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077e1000_get_cable_length(struct e1000_hw *hw,
6078 uint16_t *min_length,
6079 uint16_t *max_length)
6080{
6081 int32_t ret_val;
6082 uint16_t agc_value = 0;
6083 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006084 uint16_t max_agc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 uint16_t i, phy_data;
6086 uint16_t cable_length;
6087
6088 DEBUGFUNC("e1000_get_cable_length");
6089
6090 *min_length = *max_length = 0;
6091
6092 /* Use old method for Phy older than IGP */
6093 if(hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006094
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6096 &phy_data);
6097 if(ret_val)
6098 return ret_val;
6099 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6100 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6101
6102 /* Convert the enum value to ranged values */
6103 switch (cable_length) {
6104 case e1000_cable_length_50:
6105 *min_length = 0;
6106 *max_length = e1000_igp_cable_length_50;
6107 break;
6108 case e1000_cable_length_50_80:
6109 *min_length = e1000_igp_cable_length_50;
6110 *max_length = e1000_igp_cable_length_80;
6111 break;
6112 case e1000_cable_length_80_110:
6113 *min_length = e1000_igp_cable_length_80;
6114 *max_length = e1000_igp_cable_length_110;
6115 break;
6116 case e1000_cable_length_110_140:
6117 *min_length = e1000_igp_cable_length_110;
6118 *max_length = e1000_igp_cable_length_140;
6119 break;
6120 case e1000_cable_length_140:
6121 *min_length = e1000_igp_cable_length_140;
6122 *max_length = e1000_igp_cable_length_170;
6123 break;
6124 default:
6125 return -E1000_ERR_PHY;
6126 break;
6127 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006128 } else if (hw->phy_type == e1000_phy_gg82563) {
6129 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6130 &phy_data);
6131 if (ret_val)
6132 return ret_val;
6133 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6134
6135 switch (cable_length) {
6136 case e1000_gg_cable_length_60:
6137 *min_length = 0;
6138 *max_length = e1000_igp_cable_length_60;
6139 break;
6140 case e1000_gg_cable_length_60_115:
6141 *min_length = e1000_igp_cable_length_60;
6142 *max_length = e1000_igp_cable_length_115;
6143 break;
6144 case e1000_gg_cable_length_115_150:
6145 *min_length = e1000_igp_cable_length_115;
6146 *max_length = e1000_igp_cable_length_150;
6147 break;
6148 case e1000_gg_cable_length_150:
6149 *min_length = e1000_igp_cable_length_150;
6150 *max_length = e1000_igp_cable_length_180;
6151 break;
6152 default:
6153 return -E1000_ERR_PHY;
6154 break;
6155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6157 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6158 {IGP01E1000_PHY_AGC_A,
6159 IGP01E1000_PHY_AGC_B,
6160 IGP01E1000_PHY_AGC_C,
6161 IGP01E1000_PHY_AGC_D};
6162 /* Read the AGC registers for all channels */
6163 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6164
6165 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6166 if(ret_val)
6167 return ret_val;
6168
6169 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6170
6171 /* Array bound check. */
6172 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6173 (cur_agc == 0))
6174 return -E1000_ERR_PHY;
6175
6176 agc_value += cur_agc;
6177
6178 /* Update minimal AGC value. */
6179 if(min_agc > cur_agc)
6180 min_agc = cur_agc;
6181 }
6182
6183 /* Remove the minimal AGC result for length < 50m */
6184 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6185 agc_value -= min_agc;
6186
6187 /* Get the average length of the remaining 3 channels */
6188 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6189 } else {
6190 /* Get the average length of all the 4 channels. */
6191 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6192 }
6193
6194 /* Set the range of the calculated length. */
6195 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6196 IGP01E1000_AGC_RANGE) > 0) ?
6197 (e1000_igp_cable_length_table[agc_value] -
6198 IGP01E1000_AGC_RANGE) : 0;
6199 *max_length = e1000_igp_cable_length_table[agc_value] +
6200 IGP01E1000_AGC_RANGE;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006201 } else if (hw->phy_type == e1000_phy_igp_2) {
6202 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6203 {IGP02E1000_PHY_AGC_A,
6204 IGP02E1000_PHY_AGC_B,
6205 IGP02E1000_PHY_AGC_C,
6206 IGP02E1000_PHY_AGC_D};
6207 /* Read the AGC registers for all channels */
6208 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6209 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6210 if (ret_val)
6211 return ret_val;
6212
6213 /* Getting bits 15:9, which represent the combination of course and
6214 * fine gain values. The result is a number that can be put into
6215 * the lookup table to obtain the approximate cable length. */
6216 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6217 IGP02E1000_AGC_LENGTH_MASK;
6218
6219 /* Remove min & max AGC values from calculation. */
6220 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
6221 min_agc = cur_agc;
6222 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
6223 max_agc = cur_agc;
6224
6225 agc_value += e1000_igp_2_cable_length_table[cur_agc];
6226 }
6227
6228 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
6229 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6230
6231 /* Calculate cable length with the error range of +/- 10 meters. */
6232 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6233 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6234 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 }
6236
6237 return E1000_SUCCESS;
6238}
6239
6240/******************************************************************************
6241 * Check the cable polarity
6242 *
6243 * hw - Struct containing variables accessed by shared code
6244 * polarity - output parameter : 0 - Polarity is not reversed
6245 * 1 - Polarity is reversed.
6246 *
6247 * returns: - E1000_ERR_XXX
6248 * E1000_SUCCESS
6249 *
6250 * For phy's older then IGP, this function simply reads the polarity bit in the
6251 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6252 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6253 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6254 * IGP01E1000_PHY_PCS_INIT_REG.
6255 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006256static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257e1000_check_polarity(struct e1000_hw *hw,
6258 uint16_t *polarity)
6259{
6260 int32_t ret_val;
6261 uint16_t phy_data;
6262
6263 DEBUGFUNC("e1000_check_polarity");
6264
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006265 if ((hw->phy_type == e1000_phy_m88) ||
6266 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 /* return the Polarity bit in the Status register. */
6268 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6269 &phy_data);
6270 if(ret_val)
6271 return ret_val;
6272 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6273 M88E1000_PSSR_REV_POLARITY_SHIFT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006274 } else if(hw->phy_type == e1000_phy_igp ||
6275 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 /* Read the Status register to check the speed */
6277 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6278 &phy_data);
6279 if(ret_val)
6280 return ret_val;
6281
6282 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6283 * find the polarity status */
6284 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6285 IGP01E1000_PSSR_SPEED_1000MBPS) {
6286
6287 /* Read the GIG initialization PCS register (0x00B4) */
6288 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6289 &phy_data);
6290 if(ret_val)
6291 return ret_val;
6292
6293 /* Check the polarity bits */
6294 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6295 } else {
6296 /* For 10 Mbps, read the polarity bit in the status register. (for
6297 * 100 Mbps this bit is always 0) */
6298 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6299 }
6300 }
6301 return E1000_SUCCESS;
6302}
6303
6304/******************************************************************************
6305 * Check if Downshift occured
6306 *
6307 * hw - Struct containing variables accessed by shared code
6308 * downshift - output parameter : 0 - No Downshift ocured.
6309 * 1 - Downshift ocured.
6310 *
6311 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006312 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313 *
6314 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6315 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6316 * Link Health register. In IGP this bit is latched high, so the driver must
6317 * read it immediately after link is established.
6318 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006319static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320e1000_check_downshift(struct e1000_hw *hw)
6321{
6322 int32_t ret_val;
6323 uint16_t phy_data;
6324
6325 DEBUGFUNC("e1000_check_downshift");
6326
Auke Kok76c224b2006-05-23 13:36:06 -07006327 if(hw->phy_type == e1000_phy_igp ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006328 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6330 &phy_data);
6331 if(ret_val)
6332 return ret_val;
6333
6334 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006335 } else if ((hw->phy_type == e1000_phy_m88) ||
6336 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6338 &phy_data);
6339 if(ret_val)
6340 return ret_val;
6341
6342 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6343 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6344 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006345
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 return E1000_SUCCESS;
6347}
6348
6349/*****************************************************************************
6350 *
6351 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6352 * gigabit link is achieved to improve link quality.
6353 *
6354 * hw: Struct containing variables accessed by shared code
6355 *
6356 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6357 * E1000_SUCCESS at any other case.
6358 *
6359 ****************************************************************************/
6360
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006361static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6363 boolean_t link_up)
6364{
6365 int32_t ret_val;
6366 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6367 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6368 {IGP01E1000_PHY_AGC_PARAM_A,
6369 IGP01E1000_PHY_AGC_PARAM_B,
6370 IGP01E1000_PHY_AGC_PARAM_C,
6371 IGP01E1000_PHY_AGC_PARAM_D};
6372 uint16_t min_length, max_length;
6373
6374 DEBUGFUNC("e1000_config_dsp_after_link_change");
6375
6376 if(hw->phy_type != e1000_phy_igp)
6377 return E1000_SUCCESS;
6378
6379 if(link_up) {
6380 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
6381 if(ret_val) {
6382 DEBUGOUT("Error getting link speed and duplex\n");
6383 return ret_val;
6384 }
6385
6386 if(speed == SPEED_1000) {
6387
6388 e1000_get_cable_length(hw, &min_length, &max_length);
6389
6390 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6391 min_length >= e1000_igp_cable_length_50) {
6392
6393 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6394 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6395 &phy_data);
6396 if(ret_val)
6397 return ret_val;
6398
6399 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6400
6401 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
6402 phy_data);
6403 if(ret_val)
6404 return ret_val;
6405 }
6406 hw->dsp_config_state = e1000_dsp_config_activated;
6407 }
6408
6409 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
6410 (min_length < e1000_igp_cable_length_50)) {
6411
6412 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6413 uint32_t idle_errs = 0;
6414
6415 /* clear previous idle error counts */
6416 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6417 &phy_data);
6418 if(ret_val)
6419 return ret_val;
6420
6421 for(i = 0; i < ffe_idle_err_timeout; i++) {
6422 udelay(1000);
6423 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6424 &phy_data);
6425 if(ret_val)
6426 return ret_val;
6427
6428 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
6429 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
6430 hw->ffe_config_state = e1000_ffe_config_active;
6431
6432 ret_val = e1000_write_phy_reg(hw,
6433 IGP01E1000_PHY_DSP_FFE,
6434 IGP01E1000_PHY_DSP_FFE_CM_CP);
6435 if(ret_val)
6436 return ret_val;
6437 break;
6438 }
6439
6440 if(idle_errs)
6441 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6442 }
6443 }
6444 }
6445 } else {
6446 if(hw->dsp_config_state == e1000_dsp_config_activated) {
6447 /* Save off the current value of register 0x2F5B to be restored at
6448 * the end of the routines. */
6449 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6450
6451 if(ret_val)
6452 return ret_val;
6453
6454 /* Disable the PHY transmitter */
6455 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6456
6457 if(ret_val)
6458 return ret_val;
6459
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006460 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461
6462 ret_val = e1000_write_phy_reg(hw, 0x0000,
6463 IGP01E1000_IEEE_FORCE_GIGA);
6464 if(ret_val)
6465 return ret_val;
6466 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6467 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
6468 if(ret_val)
6469 return ret_val;
6470
6471 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6472 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6473
6474 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
6475 if(ret_val)
6476 return ret_val;
6477 }
6478
6479 ret_val = e1000_write_phy_reg(hw, 0x0000,
6480 IGP01E1000_IEEE_RESTART_AUTONEG);
6481 if(ret_val)
6482 return ret_val;
6483
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006484 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485
6486 /* Now enable the transmitter */
6487 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6488
6489 if(ret_val)
6490 return ret_val;
6491
6492 hw->dsp_config_state = e1000_dsp_config_enabled;
6493 }
6494
6495 if(hw->ffe_config_state == e1000_ffe_config_active) {
6496 /* Save off the current value of register 0x2F5B to be restored at
6497 * the end of the routines. */
6498 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6499
6500 if(ret_val)
6501 return ret_val;
6502
6503 /* Disable the PHY transmitter */
6504 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6505
6506 if(ret_val)
6507 return ret_val;
6508
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006509 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510
6511 ret_val = e1000_write_phy_reg(hw, 0x0000,
6512 IGP01E1000_IEEE_FORCE_GIGA);
6513 if(ret_val)
6514 return ret_val;
6515 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6516 IGP01E1000_PHY_DSP_FFE_DEFAULT);
6517 if(ret_val)
6518 return ret_val;
6519
6520 ret_val = e1000_write_phy_reg(hw, 0x0000,
6521 IGP01E1000_IEEE_RESTART_AUTONEG);
6522 if(ret_val)
6523 return ret_val;
6524
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006525 msec_delay_irq(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526
6527 /* Now enable the transmitter */
6528 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6529
6530 if(ret_val)
6531 return ret_val;
6532
6533 hw->ffe_config_state = e1000_ffe_config_enabled;
6534 }
6535 }
6536 return E1000_SUCCESS;
6537}
6538
6539/*****************************************************************************
6540 * Set PHY to class A mode
6541 * Assumes the following operations will follow to enable the new class mode.
6542 * 1. Do a PHY soft reset
6543 * 2. Restart auto-negotiation or force link.
6544 *
6545 * hw - Struct containing variables accessed by shared code
6546 ****************************************************************************/
6547static int32_t
6548e1000_set_phy_mode(struct e1000_hw *hw)
6549{
6550 int32_t ret_val;
6551 uint16_t eeprom_data;
6552
6553 DEBUGFUNC("e1000_set_phy_mode");
6554
6555 if((hw->mac_type == e1000_82545_rev_3) &&
6556 (hw->media_type == e1000_media_type_copper)) {
6557 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
6558 if(ret_val) {
6559 return ret_val;
6560 }
6561
6562 if((eeprom_data != EEPROM_RESERVED_WORD) &&
6563 (eeprom_data & EEPROM_PHY_CLASS_A)) {
6564 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
6565 if(ret_val)
6566 return ret_val;
6567 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
6568 if(ret_val)
6569 return ret_val;
6570
6571 hw->phy_reset_disable = FALSE;
6572 }
6573 }
6574
6575 return E1000_SUCCESS;
6576}
6577
6578/*****************************************************************************
6579 *
6580 * This function sets the lplu state according to the active flag. When
6581 * activating lplu this function also disables smart speed and vise versa.
6582 * lplu will not be activated unless the device autonegotiation advertisment
6583 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6584 * hw: Struct containing variables accessed by shared code
6585 * active - true to enable lplu false to disable lplu.
6586 *
6587 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6588 * E1000_SUCCESS at any other case.
6589 *
6590 ****************************************************************************/
6591
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006592static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593e1000_set_d3_lplu_state(struct e1000_hw *hw,
6594 boolean_t active)
6595{
6596 int32_t ret_val;
6597 uint16_t phy_data;
6598 DEBUGFUNC("e1000_set_d3_lplu_state");
6599
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006600 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 return E1000_SUCCESS;
6602
6603 /* During driver activity LPLU should not be used or it will attain link
6604 * from the lowest speeds starting from 10Mbps. The capability is used for
6605 * Dx transitions and states */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006606 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
6607 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 if(ret_val)
6609 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006610 } else {
6611 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6612 if(ret_val)
6613 return ret_val;
6614 }
6615
6616 if(!active) {
6617 if(hw->mac_type == e1000_82541_rev_2 ||
6618 hw->mac_type == e1000_82547_rev_2) {
6619 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
6620 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6621 if(ret_val)
6622 return ret_val;
6623 } else {
6624 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6625 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6626 phy_data);
6627 if (ret_val)
6628 return ret_val;
6629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630
6631 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6632 * Dx states where the power conservation is most important. During
6633 * driver activity we should enable SmartSpeed, so performance is
6634 * maintained. */
6635 if (hw->smart_speed == e1000_smart_speed_on) {
6636 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6637 &phy_data);
6638 if(ret_val)
6639 return ret_val;
6640
6641 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6642 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6643 phy_data);
6644 if(ret_val)
6645 return ret_val;
6646 } else if (hw->smart_speed == e1000_smart_speed_off) {
6647 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6648 &phy_data);
6649 if (ret_val)
6650 return ret_val;
6651
6652 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6653 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6654 phy_data);
6655 if(ret_val)
6656 return ret_val;
6657 }
6658
6659 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
6660 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
6661 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6662
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006663 if(hw->mac_type == e1000_82541_rev_2 ||
6664 hw->mac_type == e1000_82547_rev_2) {
6665 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6666 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6667 if(ret_val)
6668 return ret_val;
6669 } else {
6670 phy_data |= IGP02E1000_PM_D3_LPLU;
6671 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6672 phy_data);
6673 if (ret_val)
6674 return ret_val;
6675 }
6676
6677 /* When LPLU is enabled we should disable SmartSpeed */
6678 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 if(ret_val)
6680 return ret_val;
6681
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006682 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6683 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6684 if(ret_val)
6685 return ret_val;
6686
6687 }
6688 return E1000_SUCCESS;
6689}
6690
6691/*****************************************************************************
6692 *
6693 * This function sets the lplu d0 state according to the active flag. When
6694 * activating lplu this function also disables smart speed and vise versa.
6695 * lplu will not be activated unless the device autonegotiation advertisment
6696 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6697 * hw: Struct containing variables accessed by shared code
6698 * active - true to enable lplu false to disable lplu.
6699 *
6700 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6701 * E1000_SUCCESS at any other case.
6702 *
6703 ****************************************************************************/
6704
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006705static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006706e1000_set_d0_lplu_state(struct e1000_hw *hw,
6707 boolean_t active)
6708{
6709 int32_t ret_val;
6710 uint16_t phy_data;
6711 DEBUGFUNC("e1000_set_d0_lplu_state");
6712
6713 if(hw->mac_type <= e1000_82547_rev_2)
6714 return E1000_SUCCESS;
6715
6716 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6717 if(ret_val)
6718 return ret_val;
6719
6720 if (!active) {
6721 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6722 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6723 if (ret_val)
6724 return ret_val;
6725
6726 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6727 * Dx states where the power conservation is most important. During
6728 * driver activity we should enable SmartSpeed, so performance is
6729 * maintained. */
6730 if (hw->smart_speed == e1000_smart_speed_on) {
6731 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6732 &phy_data);
6733 if(ret_val)
6734 return ret_val;
6735
6736 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6737 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6738 phy_data);
6739 if(ret_val)
6740 return ret_val;
6741 } else if (hw->smart_speed == e1000_smart_speed_off) {
6742 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6743 &phy_data);
6744 if (ret_val)
6745 return ret_val;
6746
6747 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6748 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6749 phy_data);
6750 if(ret_val)
6751 return ret_val;
6752 }
6753
6754
6755 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07006756
6757 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006758 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6759 if (ret_val)
6760 return ret_val;
6761
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 /* When LPLU is enabled we should disable SmartSpeed */
6763 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6764 if(ret_val)
6765 return ret_val;
6766
6767 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6768 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6769 if(ret_val)
6770 return ret_val;
6771
6772 }
6773 return E1000_SUCCESS;
6774}
6775
6776/******************************************************************************
6777 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6778 *
6779 * hw - Struct containing variables accessed by shared code
6780 *****************************************************************************/
6781static int32_t
6782e1000_set_vco_speed(struct e1000_hw *hw)
6783{
6784 int32_t ret_val;
6785 uint16_t default_page = 0;
6786 uint16_t phy_data;
6787
6788 DEBUGFUNC("e1000_set_vco_speed");
6789
6790 switch(hw->mac_type) {
6791 case e1000_82545_rev_3:
6792 case e1000_82546_rev_3:
6793 break;
6794 default:
6795 return E1000_SUCCESS;
6796 }
6797
6798 /* Set PHY register 30, page 5, bit 8 to 0 */
6799
6800 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6801 if(ret_val)
6802 return ret_val;
6803
6804 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6805 if(ret_val)
6806 return ret_val;
6807
6808 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6809 if(ret_val)
6810 return ret_val;
6811
6812 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6813 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6814 if(ret_val)
6815 return ret_val;
6816
6817 /* Set PHY register 30, page 4, bit 11 to 1 */
6818
6819 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6820 if(ret_val)
6821 return ret_val;
6822
6823 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6824 if(ret_val)
6825 return ret_val;
6826
6827 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6828 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6829 if(ret_val)
6830 return ret_val;
6831
6832 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6833 if(ret_val)
6834 return ret_val;
6835
6836 return E1000_SUCCESS;
6837}
6838
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006839
6840/*****************************************************************************
6841 * This function reads the cookie from ARC ram.
6842 *
6843 * returns: - E1000_SUCCESS .
6844 ****************************************************************************/
6845int32_t
6846e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
6847{
6848 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07006849 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006850 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6851
6852 length = (length >> 2);
6853 offset = (offset >> 2);
6854
6855 for (i = 0; i < length; i++) {
6856 *((uint32_t *) buffer + i) =
6857 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6858 }
6859 return E1000_SUCCESS;
6860}
6861
6862
6863/*****************************************************************************
6864 * This function checks whether the HOST IF is enabled for command operaton
6865 * and also checks whether the previous command is completed.
6866 * It busy waits in case of previous command is not completed.
6867 *
Auke Kok76c224b2006-05-23 13:36:06 -07006868 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006869 * timeout
6870 * - E1000_SUCCESS for success.
6871 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006872static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006873e1000_mng_enable_host_if(struct e1000_hw * hw)
6874{
6875 uint32_t hicr;
6876 uint8_t i;
6877
6878 /* Check that the host interface is enabled. */
6879 hicr = E1000_READ_REG(hw, HICR);
6880 if ((hicr & E1000_HICR_EN) == 0) {
6881 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6882 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6883 }
6884 /* check the previous command is completed */
6885 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6886 hicr = E1000_READ_REG(hw, HICR);
6887 if (!(hicr & E1000_HICR_C))
6888 break;
6889 msec_delay_irq(1);
6890 }
6891
Auke Kok76c224b2006-05-23 13:36:06 -07006892 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006893 DEBUGOUT("Previous command timeout failed .\n");
6894 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6895 }
6896 return E1000_SUCCESS;
6897}
6898
6899/*****************************************************************************
6900 * This function writes the buffer content at the offset given on the host if.
6901 * It also does alignment considerations to do the writes in most efficient way.
6902 * Also fills up the sum of the buffer in *buffer parameter.
6903 *
6904 * returns - E1000_SUCCESS for success.
6905 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006906static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006907e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6908 uint16_t length, uint16_t offset, uint8_t *sum)
6909{
6910 uint8_t *tmp;
6911 uint8_t *bufptr = buffer;
6912 uint32_t data;
6913 uint16_t remaining, i, j, prev_bytes;
6914
6915 /* sum = only sum of the data and it is not checksum */
6916
6917 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6918 return -E1000_ERR_PARAM;
6919 }
6920
6921 tmp = (uint8_t *)&data;
6922 prev_bytes = offset & 0x3;
6923 offset &= 0xFFFC;
6924 offset >>= 2;
6925
6926 if (prev_bytes) {
6927 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6928 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6929 *(tmp + j) = *bufptr++;
6930 *sum += *(tmp + j);
6931 }
6932 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6933 length -= j - prev_bytes;
6934 offset++;
6935 }
6936
6937 remaining = length & 0x3;
6938 length -= remaining;
6939
6940 /* Calculate length in DWORDs */
6941 length >>= 2;
6942
6943 /* The device driver writes the relevant command block into the
6944 * ram area. */
6945 for (i = 0; i < length; i++) {
6946 for (j = 0; j < sizeof(uint32_t); j++) {
6947 *(tmp + j) = *bufptr++;
6948 *sum += *(tmp + j);
6949 }
6950
6951 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6952 }
6953 if (remaining) {
6954 for (j = 0; j < sizeof(uint32_t); j++) {
6955 if (j < remaining)
6956 *(tmp + j) = *bufptr++;
6957 else
6958 *(tmp + j) = 0;
6959
6960 *sum += *(tmp + j);
6961 }
6962 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6963 }
6964
6965 return E1000_SUCCESS;
6966}
6967
6968
6969/*****************************************************************************
6970 * This function writes the command header after does the checksum calculation.
6971 *
6972 * returns - E1000_SUCCESS for success.
6973 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006974static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006975e1000_mng_write_cmd_header(struct e1000_hw * hw,
6976 struct e1000_host_mng_command_header * hdr)
6977{
6978 uint16_t i;
6979 uint8_t sum;
6980 uint8_t *buffer;
6981
6982 /* Write the whole command header structure which includes sum of
6983 * the buffer */
6984
6985 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6986
6987 sum = hdr->checksum;
6988 hdr->checksum = 0;
6989
6990 buffer = (uint8_t *) hdr;
6991 i = length;
6992 while(i--)
6993 sum += buffer[i];
6994
6995 hdr->checksum = 0 - sum;
6996
6997 length >>= 2;
6998 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07006999 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007000 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007001 E1000_WRITE_FLUSH(hw);
7002 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007003
7004 return E1000_SUCCESS;
7005}
7006
7007
7008/*****************************************************************************
7009 * This function indicates to ARC that a new command is pending which completes
7010 * one write operation by the driver.
7011 *
7012 * returns - E1000_SUCCESS for success.
7013 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007014static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007015e1000_mng_write_commit(
7016 struct e1000_hw * hw)
7017{
7018 uint32_t hicr;
7019
7020 hicr = E1000_READ_REG(hw, HICR);
7021 /* Setting this bit tells the ARC that a new command is pending. */
7022 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7023
7024 return E1000_SUCCESS;
7025}
7026
7027
7028/*****************************************************************************
7029 * This function checks the mode of the firmware.
7030 *
7031 * returns - TRUE when the mode is IAMT or FALSE.
7032 ****************************************************************************/
7033boolean_t
7034e1000_check_mng_mode(
7035 struct e1000_hw *hw)
7036{
7037 uint32_t fwsm;
7038
7039 fwsm = E1000_READ_REG(hw, FWSM);
7040
7041 if((fwsm & E1000_FWSM_MODE_MASK) ==
7042 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7043 return TRUE;
7044
7045 return FALSE;
7046}
7047
7048
7049/*****************************************************************************
7050 * This function writes the dhcp info .
7051 ****************************************************************************/
7052int32_t
7053e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7054 uint16_t length)
7055{
7056 int32_t ret_val;
7057 struct e1000_host_mng_command_header hdr;
7058
7059 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7060 hdr.command_length = length;
7061 hdr.reserved1 = 0;
7062 hdr.reserved2 = 0;
7063 hdr.checksum = 0;
7064
7065 ret_val = e1000_mng_enable_host_if(hw);
7066 if (ret_val == E1000_SUCCESS) {
7067 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7068 &(hdr.checksum));
7069 if (ret_val == E1000_SUCCESS) {
7070 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7071 if (ret_val == E1000_SUCCESS)
7072 ret_val = e1000_mng_write_commit(hw);
7073 }
7074 }
7075 return ret_val;
7076}
7077
7078
7079/*****************************************************************************
7080 * This function calculates the checksum.
7081 *
7082 * returns - checksum of buffer contents.
7083 ****************************************************************************/
7084uint8_t
7085e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7086{
7087 uint8_t sum = 0;
7088 uint32_t i;
7089
7090 if (!buffer)
7091 return 0;
7092
7093 for (i=0; i < length; i++)
7094 sum += buffer[i];
7095
7096 return (uint8_t) (0 - sum);
7097}
7098
7099/*****************************************************************************
7100 * This function checks whether tx pkt filtering needs to be enabled or not.
7101 *
7102 * returns - TRUE for packet filtering or FALSE.
7103 ****************************************************************************/
7104boolean_t
7105e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7106{
7107 /* called in init as well as watchdog timer functions */
7108
7109 int32_t ret_val, checksum;
7110 boolean_t tx_filter = FALSE;
7111 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7112 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7113
7114 if (e1000_check_mng_mode(hw)) {
7115 ret_val = e1000_mng_enable_host_if(hw);
7116 if (ret_val == E1000_SUCCESS) {
7117 ret_val = e1000_host_if_read_cookie(hw, buffer);
7118 if (ret_val == E1000_SUCCESS) {
7119 checksum = hdr->checksum;
7120 hdr->checksum = 0;
7121 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7122 checksum == e1000_calculate_mng_checksum((char *)buffer,
7123 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7124 if (hdr->status &
7125 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7126 tx_filter = TRUE;
7127 } else
7128 tx_filter = TRUE;
7129 } else
7130 tx_filter = TRUE;
7131 }
7132 }
7133
7134 hw->tx_pkt_filtering = tx_filter;
7135 return tx_filter;
7136}
7137
7138/******************************************************************************
7139 * Verifies the hardware needs to allow ARPs to be processed by the host
7140 *
7141 * hw - Struct containing variables accessed by shared code
7142 *
7143 * returns: - TRUE/FALSE
7144 *
7145 *****************************************************************************/
7146uint32_t
7147e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7148{
7149 uint32_t manc;
7150 uint32_t fwsm, factps;
7151
7152 if (hw->asf_firmware_present) {
7153 manc = E1000_READ_REG(hw, MANC);
7154
7155 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7156 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7157 return FALSE;
7158 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7159 fwsm = E1000_READ_REG(hw, FWSM);
7160 factps = E1000_READ_REG(hw, FACTPS);
7161
7162 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7163 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7164 (factps & E1000_FACTPS_MNGCG))
7165 return TRUE;
7166 } else
7167 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7168 return TRUE;
7169 }
7170 return FALSE;
7171}
7172
Linus Torvalds1da177e2005-04-16 15:20:36 -07007173static int32_t
7174e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7175{
7176 int32_t ret_val;
7177 uint16_t mii_status_reg;
7178 uint16_t i;
7179
7180 /* Polarity reversal workaround for forced 10F/10H links. */
7181
7182 /* Disable the transmitter on the PHY */
7183
7184 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7185 if(ret_val)
7186 return ret_val;
7187 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7188 if(ret_val)
7189 return ret_val;
7190
7191 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7192 if(ret_val)
7193 return ret_val;
7194
7195 /* This loop will early-out if the NO link condition has been met. */
7196 for(i = PHY_FORCE_TIME; i > 0; i--) {
7197 /* Read the MII Status Register and wait for Link Status bit
7198 * to be clear.
7199 */
7200
7201 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7202 if(ret_val)
7203 return ret_val;
7204
7205 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7206 if(ret_val)
7207 return ret_val;
7208
7209 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7210 msec_delay_irq(100);
7211 }
7212
7213 /* Recommended delay time after link has been lost */
7214 msec_delay_irq(1000);
7215
7216 /* Now we will re-enable th transmitter on the PHY */
7217
7218 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7219 if(ret_val)
7220 return ret_val;
7221 msec_delay_irq(50);
7222 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
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, 0xFF00);
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, 0x0000);
7231 if(ret_val)
7232 return ret_val;
7233
7234 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7235 if(ret_val)
7236 return ret_val;
7237
7238 /* This loop will early-out if the link condition has been met. */
7239 for(i = PHY_FORCE_TIME; i > 0; i--) {
7240 /* Read the MII Status Register and wait for Link Status bit
7241 * to be set.
7242 */
7243
7244 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7245 if(ret_val)
7246 return ret_val;
7247
7248 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7249 if(ret_val)
7250 return ret_val;
7251
7252 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7253 msec_delay_irq(100);
7254 }
7255 return E1000_SUCCESS;
7256}
7257
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007258/***************************************************************************
7259 *
7260 * Disables PCI-Express master access.
7261 *
7262 * hw: Struct containing variables accessed by shared code
7263 *
7264 * returns: - none.
7265 *
7266 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007267static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007268e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7269{
7270 uint32_t ctrl;
7271
7272 DEBUGFUNC("e1000_set_pci_express_master_disable");
7273
7274 if (hw->bus_type != e1000_bus_type_pci_express)
7275 return;
7276
7277 ctrl = E1000_READ_REG(hw, CTRL);
7278 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7279 E1000_WRITE_REG(hw, CTRL, ctrl);
7280}
7281
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007282#if 0
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007283/***************************************************************************
7284 *
7285 * Enables PCI-Express master access.
7286 *
7287 * hw: Struct containing variables accessed by shared code
7288 *
7289 * returns: - none.
7290 *
7291 ***************************************************************************/
7292void
7293e1000_enable_pciex_master(struct e1000_hw *hw)
7294{
7295 uint32_t ctrl;
7296
7297 DEBUGFUNC("e1000_enable_pciex_master");
7298
7299 if (hw->bus_type != e1000_bus_type_pci_express)
7300 return;
7301
7302 ctrl = E1000_READ_REG(hw, CTRL);
7303 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7304 E1000_WRITE_REG(hw, CTRL, ctrl);
7305}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007306#endif /* 0 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007307
7308/*******************************************************************************
7309 *
7310 * Disables PCI-Express master access and verifies there are no pending requests
7311 *
7312 * hw: Struct containing variables accessed by shared code
7313 *
7314 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7315 * caused the master requests to be disabled.
7316 * E1000_SUCCESS master requests disabled.
7317 *
7318 ******************************************************************************/
7319int32_t
7320e1000_disable_pciex_master(struct e1000_hw *hw)
7321{
7322 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7323
7324 DEBUGFUNC("e1000_disable_pciex_master");
7325
7326 if (hw->bus_type != e1000_bus_type_pci_express)
7327 return E1000_SUCCESS;
7328
7329 e1000_set_pci_express_master_disable(hw);
7330
7331 while(timeout) {
7332 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7333 break;
7334 else
7335 udelay(100);
7336 timeout--;
7337 }
7338
7339 if(!timeout) {
7340 DEBUGOUT("Master requests are pending.\n");
7341 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7342 }
7343
7344 return E1000_SUCCESS;
7345}
7346
7347/*******************************************************************************
7348 *
7349 * Check for EEPROM Auto Read bit done.
7350 *
7351 * hw: Struct containing variables accessed by shared code
7352 *
7353 * returns: - E1000_ERR_RESET if fail to reset MAC
7354 * E1000_SUCCESS at any other case.
7355 *
7356 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007357static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007358e1000_get_auto_rd_done(struct e1000_hw *hw)
7359{
7360 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7361
7362 DEBUGFUNC("e1000_get_auto_rd_done");
7363
7364 switch (hw->mac_type) {
7365 default:
7366 msec_delay(5);
7367 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007368 case e1000_82571:
7369 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007370 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007371 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007372 while(timeout) {
7373 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
7374 else msec_delay(1);
7375 timeout--;
7376 }
7377
7378 if(!timeout) {
7379 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7380 return -E1000_ERR_RESET;
7381 }
7382 break;
7383 }
7384
Jeff Kirsherfd803242005-12-13 00:06:22 -05007385 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
7386 * Need to wait for PHY configuration completion before accessing NVM
7387 * and PHY. */
7388 if (hw->mac_type == e1000_82573)
7389 msec_delay(25);
7390
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007391 return E1000_SUCCESS;
7392}
7393
7394/***************************************************************************
7395 * Checks if the PHY configuration is done
7396 *
7397 * hw: Struct containing variables accessed by shared code
7398 *
7399 * returns: - E1000_ERR_RESET if fail to reset MAC
7400 * E1000_SUCCESS at any other case.
7401 *
7402 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007403static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007404e1000_get_phy_cfg_done(struct e1000_hw *hw)
7405{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007406 int32_t timeout = PHY_CFG_TIMEOUT;
7407 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
7408
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007409 DEBUGFUNC("e1000_get_phy_cfg_done");
7410
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007411 switch (hw->mac_type) {
7412 default:
7413 msec_delay(10);
7414 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007415 case e1000_80003es2lan:
7416 /* Separate *_CFG_DONE_* bit for each port */
7417 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
7418 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7419 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007420 case e1000_82571:
7421 case e1000_82572:
7422 while (timeout) {
7423 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
7424 break;
7425 else
7426 msec_delay(1);
7427 timeout--;
7428 }
7429
7430 if (!timeout) {
7431 DEBUGOUT("MNG configuration cycle has not completed.\n");
7432 return -E1000_ERR_RESET;
7433 }
7434 break;
7435 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007436
7437 return E1000_SUCCESS;
7438}
7439
7440/***************************************************************************
7441 *
7442 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
7443 * adapter or Eeprom access.
7444 *
7445 * hw: Struct containing variables accessed by shared code
7446 *
7447 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
7448 * E1000_SUCCESS at any other case.
7449 *
7450 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007451static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007452e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
7453{
7454 int32_t timeout;
7455 uint32_t swsm;
7456
7457 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
7458
7459 if(!hw->eeprom_semaphore_present)
7460 return E1000_SUCCESS;
7461
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007462 if (hw->mac_type == e1000_80003es2lan) {
7463 /* Get the SW semaphore. */
7464 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
7465 return -E1000_ERR_EEPROM;
7466 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007467
7468 /* Get the FW semaphore. */
7469 timeout = hw->eeprom.word_size + 1;
7470 while(timeout) {
7471 swsm = E1000_READ_REG(hw, SWSM);
7472 swsm |= E1000_SWSM_SWESMBI;
7473 E1000_WRITE_REG(hw, SWSM, swsm);
7474 /* if we managed to set the bit we got the semaphore. */
7475 swsm = E1000_READ_REG(hw, SWSM);
7476 if(swsm & E1000_SWSM_SWESMBI)
7477 break;
7478
7479 udelay(50);
7480 timeout--;
7481 }
7482
7483 if(!timeout) {
7484 /* Release semaphores */
7485 e1000_put_hw_eeprom_semaphore(hw);
7486 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7487 return -E1000_ERR_EEPROM;
7488 }
7489
7490 return E1000_SUCCESS;
7491}
7492
7493/***************************************************************************
7494 * This function clears HW semaphore bits.
7495 *
7496 * hw: Struct containing variables accessed by shared code
7497 *
7498 * returns: - None.
7499 *
7500 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007501static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007502e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
7503{
7504 uint32_t swsm;
7505
7506 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
7507
7508 if(!hw->eeprom_semaphore_present)
7509 return;
7510
7511 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007512 if (hw->mac_type == e1000_80003es2lan) {
7513 /* Release both semaphores. */
7514 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7515 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007516 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007517 E1000_WRITE_REG(hw, SWSM, swsm);
7518}
7519
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007520/***************************************************************************
7521 *
7522 * Obtaining software semaphore bit (SMBI) before resetting PHY.
7523 *
7524 * hw: Struct containing variables accessed by shared code
7525 *
7526 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
7527 * E1000_SUCCESS at any other case.
7528 *
7529 ***************************************************************************/
7530int32_t
7531e1000_get_software_semaphore(struct e1000_hw *hw)
7532{
7533 int32_t timeout = hw->eeprom.word_size + 1;
7534 uint32_t swsm;
7535
7536 DEBUGFUNC("e1000_get_software_semaphore");
7537
7538 if (hw->mac_type != e1000_80003es2lan)
7539 return E1000_SUCCESS;
7540
7541 while(timeout) {
7542 swsm = E1000_READ_REG(hw, SWSM);
7543 /* If SMBI bit cleared, it is now set and we hold the semaphore */
7544 if(!(swsm & E1000_SWSM_SMBI))
7545 break;
7546 msec_delay_irq(1);
7547 timeout--;
7548 }
7549
7550 if(!timeout) {
7551 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
7552 return -E1000_ERR_RESET;
7553 }
7554
7555 return E1000_SUCCESS;
7556}
7557
7558/***************************************************************************
7559 *
7560 * Release semaphore bit (SMBI).
7561 *
7562 * hw: Struct containing variables accessed by shared code
7563 *
7564 ***************************************************************************/
7565void
7566e1000_release_software_semaphore(struct e1000_hw *hw)
7567{
7568 uint32_t swsm;
7569
7570 DEBUGFUNC("e1000_release_software_semaphore");
7571
7572 if (hw->mac_type != e1000_80003es2lan)
7573 return;
7574
7575 swsm = E1000_READ_REG(hw, SWSM);
7576 /* Release the SW semaphores.*/
7577 swsm &= ~E1000_SWSM_SMBI;
7578 E1000_WRITE_REG(hw, SWSM, swsm);
7579}
7580
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007581/******************************************************************************
7582 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
7583 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
7584 * the caller to figure out how to deal with it.
7585 *
7586 * hw - Struct containing variables accessed by shared code
7587 *
7588 * returns: - E1000_BLK_PHY_RESET
7589 * E1000_SUCCESS
7590 *
7591 *****************************************************************************/
7592int32_t
7593e1000_check_phy_reset_block(struct e1000_hw *hw)
7594{
7595 uint32_t manc = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08007596
7597 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007598 manc = E1000_READ_REG(hw, MANC);
7599 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
7600 E1000_BLK_PHY_RESET : E1000_SUCCESS;
7601}
7602
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007603static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007604e1000_arc_subsystem_valid(struct e1000_hw *hw)
7605{
7606 uint32_t fwsm;
7607
7608 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
7609 * may not be provided a DMA clock when no manageability features are
7610 * enabled. We do not want to perform any reads/writes to these registers
7611 * if this is the case. We read FWSM to determine the manageability mode.
7612 */
7613 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007614 case e1000_82571:
7615 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007616 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007617 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007618 fwsm = E1000_READ_REG(hw, FWSM);
7619 if((fwsm & E1000_FWSM_MODE_MASK) != 0)
7620 return TRUE;
7621 break;
7622 default:
7623 break;
7624 }
7625 return FALSE;
7626}
7627
7628
7629