blob: 3655d902b0bd0f4e978db6757319c5326c79f182 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Nicholas Nunley35574762006-09-27 12:53:34 -070036static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
43static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static int32_t e1000_check_downshift(struct e1000_hw *hw);
45static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47static void e1000_clear_vfta(struct e1000_hw *hw);
48static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60static int32_t e1000_id_led_init(struct e1000_hw *hw);
61static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63static void e1000_init_rx_addrs(struct e1000_hw *hw);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -070064static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070065static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86static void e1000_release_software_flag(struct e1000_hw *hw);
87static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94static void e1000_phy_init_script(struct e1000_hw *hw);
95static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
103 uint16_t count);
104static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
110 uint16_t *data);
111static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
115 uint16_t count);
116static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
117 uint16_t phy_data);
118static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
119 uint16_t *phy_data);
120static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122static void e1000_release_eeprom(struct e1000_hw *hw);
123static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700127static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Auke Kokcd94dd02006-06-27 09:08:22 -0700129static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
130 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800131static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* IGP cable length table */
134static const
135uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
144
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700145static const
146uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/******************************************************************************
157 * Set the phy type member in the hw struct.
158 *
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -0700161static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162e1000_set_phy_type(struct e1000_hw *hw)
163{
164 DEBUGFUNC("e1000_set_phy_type");
165
Auke Kok8fc897b2006-08-28 14:56:16 -0700166 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700167 return -E1000_ERR_PHY_TYPE;
168
Auke Kok8fc897b2006-08-28 14:56:16 -0700169 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700173 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 hw->phy_type = e1000_phy_m88;
175 break;
176 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 hw->phy_type = e1000_phy_igp;
182 break;
183 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
186 break;
187 case IFE_E_PHY_ID:
188 case IFE_PLUS_E_PHY_ID:
189 case IFE_C_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
191 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* Fall Through */
198 default:
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
202 }
203
204 return E1000_SUCCESS;
205}
206
207/******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
209 *
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
212static void
213e1000_phy_init_script(struct e1000_hw *hw)
214{
215 uint32_t ret_val;
216 uint16_t phy_saved_data;
217
218 DEBUGFUNC("e1000_phy_init_script");
219
Auke Kok8fc897b2006-08-28 14:56:16 -0700220 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400221 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
226
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
229
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400230 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 e1000_write_phy_reg(hw,0x0000,0x0140);
233
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400234 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Auke Kok8fc897b2006-08-28 14:56:16 -0700236 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 case e1000_82541:
238 case e1000_82547:
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
240
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
242
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
244
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
246
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
248
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
250
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
252
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
254
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
256 break;
257
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
261 break;
262 default:
263 break;
264 }
265
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
267
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400268 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
272
Auke Kok8fc897b2006-08-28 14:56:16 -0700273 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 uint16_t fused, fine, coarse;
275
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
278
Auke Kok8fc897b2006-08-28 14:56:16 -0700279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
281
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
284
Auke Kok8fc897b2006-08-28 14:56:16 -0700285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
290
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
294
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
298 }
299 }
300 }
301}
302
303/******************************************************************************
304 * Set the mac type member in the hw struct.
305 *
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
308int32_t
309e1000_set_mac_type(struct e1000_hw *hw)
310{
311 DEBUGFUNC("e1000_set_mac_type");
312
313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
318 break;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
321 break;
322 default:
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
325 }
326 break;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
330 break;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
336 break;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
343 break;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
347 break;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
352 break;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
357 break;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 hw->mac_type = e1000_82546_rev_3;
365 break;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
Auke Kokcd94dd02006-06-27 09:08:22 -0700368 case E1000_DEV_ID_82541ER_LOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 hw->mac_type = e1000_82541;
370 break;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
376 break;
377 case E1000_DEV_ID_82547EI:
Auke Kokcd94dd02006-06-27 09:08:22 -0700378 case E1000_DEV_ID_82547EI_MOBILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 hw->mac_type = e1000_82547;
380 break;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
383 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokfc2307d2006-11-01 08:47:56 -0800388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400389 hw->mac_type = e1000_82571;
390 break;
391 case E1000_DEV_ID_82572EI_COPPER:
392 case E1000_DEV_ID_82572EI_FIBER:
393 case E1000_DEV_ID_82572EI_SERDES:
Auke Kokcd94dd02006-06-27 09:08:22 -0700394 case E1000_DEV_ID_82572EI:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400395 hw->mac_type = e1000_82572;
396 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700397 case E1000_DEV_ID_82573E:
398 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400399 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700400 hw->mac_type = e1000_82573;
401 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
406 hw->mac_type = e1000_80003es2lan;
407 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700408 case E1000_DEV_ID_ICH8_IGP_M_AMT:
409 case E1000_DEV_ID_ICH8_IGP_AMT:
410 case E1000_DEV_ID_ICH8_IGP_C:
411 case E1000_DEV_ID_ICH8_IFE:
Auke Kokfc2307d2006-11-01 08:47:56 -0800412 case E1000_DEV_ID_ICH8_IFE_GT:
413 case E1000_DEV_ID_ICH8_IFE_G:
Auke Kokcd94dd02006-06-27 09:08:22 -0700414 case E1000_DEV_ID_ICH8_IGP_M:
415 hw->mac_type = e1000_ich8lan;
416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 default:
418 /* Should never have loaded on this device */
419 return -E1000_ERR_MAC_TYPE;
420 }
421
Auke Kok8fc897b2006-08-28 14:56:16 -0700422 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700423 case e1000_ich8lan:
424 hw->swfwhw_semaphore_present = TRUE;
425 hw->asf_firmware_present = TRUE;
426 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800427 case e1000_80003es2lan:
428 hw->swfw_sync_present = TRUE;
429 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400430 case e1000_82571:
431 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700432 case e1000_82573:
433 hw->eeprom_semaphore_present = TRUE;
434 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 case e1000_82541:
436 case e1000_82547:
437 case e1000_82541_rev_2:
438 case e1000_82547_rev_2:
439 hw->asf_firmware_present = TRUE;
440 break;
441 default:
442 break;
443 }
444
445 return E1000_SUCCESS;
446}
447
448/*****************************************************************************
449 * Set media type and TBI compatibility.
450 *
451 * hw - Struct containing variables accessed by shared code
452 * **************************************************************************/
453void
454e1000_set_media_type(struct e1000_hw *hw)
455{
456 uint32_t status;
457
458 DEBUGFUNC("e1000_set_media_type");
459
Auke Kok8fc897b2006-08-28 14:56:16 -0700460 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 /* tbi_compatibility is only valid on 82543 */
462 hw->tbi_compatibility_en = FALSE;
463 }
464
465 switch (hw->device_id) {
466 case E1000_DEV_ID_82545GM_SERDES:
467 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400468 case E1000_DEV_ID_82571EB_SERDES:
469 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800470 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 hw->media_type = e1000_media_type_internal_serdes;
472 break;
473 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700474 switch (hw->mac_type) {
475 case e1000_82542_rev2_0:
476 case e1000_82542_rev2_1:
477 hw->media_type = e1000_media_type_fiber;
478 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700479 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700480 case e1000_82573:
481 /* The STATUS_TBIMODE bit is reserved or reused for the this
482 * device.
483 */
484 hw->media_type = e1000_media_type_copper;
485 break;
486 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700488 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 hw->media_type = e1000_media_type_fiber;
490 /* tbi_compatibility not valid on fiber */
491 hw->tbi_compatibility_en = FALSE;
492 } else {
493 hw->media_type = e1000_media_type_copper;
494 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700495 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497 }
498}
499
500/******************************************************************************
501 * Reset the transmit and receive units; mask and clear all interrupts.
502 *
503 * hw - Struct containing variables accessed by shared code
504 *****************************************************************************/
505int32_t
506e1000_reset_hw(struct e1000_hw *hw)
507{
508 uint32_t ctrl;
509 uint32_t ctrl_ext;
510 uint32_t icr;
511 uint32_t manc;
512 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700513 uint32_t timeout;
514 uint32_t extcnf_ctrl;
515 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 DEBUGFUNC("e1000_reset_hw");
518
519 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700520 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
522 e1000_pci_clear_mwi(hw);
523 }
524
Auke Kok8fc897b2006-08-28 14:56:16 -0700525 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700526 /* Prevent the PCI-E bus from sticking if there is no TLP connection
527 * on the last TLP read/write transaction when MAC is reset.
528 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700529 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700530 DEBUGOUT("PCI-E Master disable polling has failed.\n");
531 }
532 }
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /* Clear interrupt mask to stop board from generating interrupts */
535 DEBUGOUT("Masking off all interrupts\n");
536 E1000_WRITE_REG(hw, IMC, 0xffffffff);
537
538 /* Disable the Transmit and Receive units. Then delay to allow
539 * any pending transactions to complete before we hit the MAC with
540 * the global reset.
541 */
542 E1000_WRITE_REG(hw, RCTL, 0);
543 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
544 E1000_WRITE_FLUSH(hw);
545
546 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
547 hw->tbi_compatibility_on = FALSE;
548
549 /* Delay to allow any outstanding PCI transactions to complete before
550 * resetting the device
551 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400552 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 ctrl = E1000_READ_REG(hw, CTRL);
555
556 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700557 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700558 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400559 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700562 /* Must acquire the MDIO ownership before MAC reset.
563 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700564 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700565 timeout = 10;
566
567 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
568 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
569
570 do {
571 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
572 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
573
Auke Kok8fc897b2006-08-28 14:56:16 -0700574 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700575 break;
576 else
577 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
578
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400579 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700580 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700581 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700582 }
583
Auke Kokcd94dd02006-06-27 09:08:22 -0700584 /* Workaround for ICH8 bit corruption issue in FIFO memory */
585 if (hw->mac_type == e1000_ich8lan) {
586 /* Set Tx and Rx buffer allocation to 8k apiece. */
587 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
588 /* Set Packet Buffer Size to 16k. */
589 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
590 }
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 /* Issue a global reset to the MAC. This will reset the chip's
593 * transmit, receive, DMA, and link units. It will not effect
594 * the current PCI configuration. The global reset bit is self-
595 * clearing, and should clear within a microsecond.
596 */
597 DEBUGOUT("Issuing a global reset to MAC\n");
598
Auke Kok8fc897b2006-08-28 14:56:16 -0700599 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 case e1000_82544:
601 case e1000_82540:
602 case e1000_82545:
603 case e1000_82546:
604 case e1000_82541:
605 case e1000_82541_rev_2:
606 /* These controllers can't ack the 64-bit write when issuing the
607 * reset, so use IO-mapping as a workaround to issue the reset */
608 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
609 break;
610 case e1000_82545_rev_3:
611 case e1000_82546_rev_3:
612 /* Reset is performed on a shadow of the control register */
613 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
614 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700615 case e1000_ich8lan:
616 if (!hw->phy_reset_disable &&
617 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
618 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
619 * at the same time to make sure the interface between
620 * MAC and the external PHY is reset.
621 */
622 ctrl |= E1000_CTRL_PHY_RST;
623 }
624
625 e1000_get_software_flag(hw);
626 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400627 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700628 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 default:
630 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
631 break;
632 }
633
634 /* After MAC reset, force reload of EEPROM to restore power-on settings to
635 * device. Later controllers reload the EEPROM automatically, so just wait
636 * for reload to complete.
637 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700638 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 case e1000_82542_rev2_0:
640 case e1000_82542_rev2_1:
641 case e1000_82543:
642 case e1000_82544:
643 /* Wait for reset to complete */
644 udelay(10);
645 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
646 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
647 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
648 E1000_WRITE_FLUSH(hw);
649 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400650 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
652 case e1000_82541:
653 case e1000_82541_rev_2:
654 case e1000_82547:
655 case e1000_82547_rev_2:
656 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400657 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700659 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500660 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
661 udelay(10);
662 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
663 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
664 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
665 E1000_WRITE_FLUSH(hw);
666 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700667 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700668 default:
669 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700670 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700671 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700672 return ret_val;
673 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
675
676 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700677 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 manc = E1000_READ_REG(hw, MANC);
679 manc &= ~(E1000_MANC_ARP_EN);
680 E1000_WRITE_REG(hw, MANC, manc);
681 }
682
Auke Kok8fc897b2006-08-28 14:56:16 -0700683 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 e1000_phy_init_script(hw);
685
686 /* Configure activity LED after PHY reset */
687 led_ctrl = E1000_READ_REG(hw, LEDCTL);
688 led_ctrl &= IGP_ACTIVITY_LED_MASK;
689 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
690 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
691 }
692
693 /* Clear interrupt mask to stop board from generating interrupts */
694 DEBUGOUT("Masking off all interrupts\n");
695 E1000_WRITE_REG(hw, IMC, 0xffffffff);
696
697 /* Clear any pending interrupt events. */
698 icr = E1000_READ_REG(hw, ICR);
699
700 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700701 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400702 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 e1000_pci_set_mwi(hw);
704 }
705
Auke Kokcd94dd02006-06-27 09:08:22 -0700706 if (hw->mac_type == e1000_ich8lan) {
707 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
708 kab |= E1000_KABGTXD_BGSQLBIAS;
709 E1000_WRITE_REG(hw, KABGTXD, kab);
710 }
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 return E1000_SUCCESS;
713}
714
715/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700716 *
717 * Initialize a number of hardware-dependent bits
718 *
719 * hw: Struct containing variables accessed by shared code
720 *
721 * This function contains hardware limitation workarounds for PCI-E adapters
722 *
723 *****************************************************************************/
724static void
725e1000_initialize_hardware_bits(struct e1000_hw *hw)
726{
727 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
728 /* Settings common to all PCI-express silicon */
729 uint32_t reg_ctrl, reg_ctrl_ext;
730 uint32_t reg_tarc0, reg_tarc1;
731 uint32_t reg_tctl;
732 uint32_t reg_txdctl, reg_txdctl1;
733
734 /* link autonegotiation/sync workarounds */
735 reg_tarc0 = E1000_READ_REG(hw, TARC0);
736 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
737
738 /* Enable not-done TX descriptor counting */
739 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
740 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
741 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
742 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
743 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
744 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
745
746 switch (hw->mac_type) {
747 case e1000_82571:
748 case e1000_82572:
749 /* Clear PHY TX compatible mode bits */
750 reg_tarc1 = E1000_READ_REG(hw, TARC1);
751 reg_tarc1 &= ~((1 << 30)|(1 << 29));
752
753 /* link autonegotiation/sync workarounds */
754 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
755
756 /* TX ring control fixes */
757 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
758
759 /* Multiple read bit is reversed polarity */
760 reg_tctl = E1000_READ_REG(hw, TCTL);
761 if (reg_tctl & E1000_TCTL_MULR)
762 reg_tarc1 &= ~(1 << 28);
763 else
764 reg_tarc1 |= (1 << 28);
765
766 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
767 break;
768 case e1000_82573:
769 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
770 reg_ctrl_ext &= ~(1 << 23);
771 reg_ctrl_ext |= (1 << 22);
772
773 /* TX byte count fix */
774 reg_ctrl = E1000_READ_REG(hw, CTRL);
775 reg_ctrl &= ~(1 << 29);
776
777 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
778 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
779 break;
780 case e1000_80003es2lan:
781 /* improve small packet performace for fiber/serdes */
782 if ((hw->media_type == e1000_media_type_fiber) ||
783 (hw->media_type == e1000_media_type_internal_serdes)) {
784 reg_tarc0 &= ~(1 << 20);
785 }
786
787 /* Multiple read bit is reversed polarity */
788 reg_tctl = E1000_READ_REG(hw, TCTL);
789 reg_tarc1 = E1000_READ_REG(hw, TARC1);
790 if (reg_tctl & E1000_TCTL_MULR)
791 reg_tarc1 &= ~(1 << 28);
792 else
793 reg_tarc1 |= (1 << 28);
794
795 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
796 break;
797 case e1000_ich8lan:
798 /* Reduce concurrent DMA requests to 3 from 4 */
799 if ((hw->revision_id < 3) ||
800 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
801 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
802 reg_tarc0 |= ((1 << 29)|(1 << 28));
803
804 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
805 reg_ctrl_ext |= (1 << 22);
806 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
807
808 /* workaround TX hang with TSO=on */
809 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
810
811 /* Multiple read bit is reversed polarity */
812 reg_tctl = E1000_READ_REG(hw, TCTL);
813 reg_tarc1 = E1000_READ_REG(hw, TARC1);
814 if (reg_tctl & E1000_TCTL_MULR)
815 reg_tarc1 &= ~(1 << 28);
816 else
817 reg_tarc1 |= (1 << 28);
818
819 /* workaround TX hang with TSO=on */
820 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
821
822 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
823 break;
824 default:
825 break;
826 }
827
828 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
829 }
830}
831
832/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 * Performs basic configuration of the adapter.
834 *
835 * hw - Struct containing variables accessed by shared code
836 *
837 * Assumes that the controller has previously been reset and is in a
838 * post-reset uninitialized state. Initializes the receive address registers,
839 * multicast table, and VLAN filter table. Calls routines to setup link
840 * configuration and flow control settings. Clears all on-chip counters. Leaves
841 * the transmit and receive units disabled and uninitialized.
842 *****************************************************************************/
843int32_t
844e1000_init_hw(struct e1000_hw *hw)
845{
846 uint32_t ctrl;
847 uint32_t i;
848 int32_t ret_val;
849 uint16_t pcix_cmd_word;
850 uint16_t pcix_stat_hi_word;
851 uint16_t cmd_mmrbc;
852 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700853 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800854 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800855 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 DEBUGFUNC("e1000_init_hw");
858
Jeff Kirsher7820d422006-08-16 13:39:00 -0700859 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700860 if ((hw->mac_type == e1000_ich8lan) &&
861 ((hw->revision_id < 3) ||
862 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
863 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
864 reg_data = E1000_READ_REG(hw, STATUS);
865 reg_data &= ~0x80000000;
866 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700867 }
868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 /* Initialize Identification LED */
870 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700871 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 DEBUGOUT("Error Initializing Identification LED\n");
873 return ret_val;
874 }
875
876 /* Set the media type and TBI compatibility */
877 e1000_set_media_type(hw);
878
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700879 /* Must be called after e1000_set_media_type because media_type is used */
880 e1000_initialize_hardware_bits(hw);
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /* Disabling VLAN filtering. */
883 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700884 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
885 if (hw->mac_type != e1000_ich8lan) {
886 if (hw->mac_type < e1000_82545_rev_3)
887 E1000_WRITE_REG(hw, VET, 0);
888 e1000_clear_vfta(hw);
889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700892 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
894 e1000_pci_clear_mwi(hw);
895 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
896 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400897 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
900 /* Setup the receive address. This involves initializing all of the Receive
901 * Address Registers (RARs 0 - 15).
902 */
903 e1000_init_rx_addrs(hw);
904
905 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700906 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 E1000_WRITE_REG(hw, RCTL, 0);
908 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400909 msleep(1);
910 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 e1000_pci_set_mwi(hw);
912 }
913
914 /* Zero out the Multicast HASH table */
915 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700916 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700917 if (hw->mac_type == e1000_ich8lan)
918 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700919 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700921 /* use write flush to prevent Memory Write Block (MWB) from
922 * occuring when accessing our register space */
923 E1000_WRITE_FLUSH(hw);
924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /* Set the PCI priority bit correctly in the CTRL register. This
927 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700928 * gives equal priority to transmits and receives. Valid only on
929 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700931 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 ctrl = E1000_READ_REG(hw, CTRL);
933 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
934 }
935
Auke Kok8fc897b2006-08-28 14:56:16 -0700936 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 case e1000_82545_rev_3:
938 case e1000_82546_rev_3:
939 break;
940 default:
941 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700942 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
944 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
945 &pcix_stat_hi_word);
946 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
947 PCIX_COMMAND_MMRBC_SHIFT;
948 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
949 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700950 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700952 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
954 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
955 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
956 &pcix_cmd_word);
957 }
958 }
959 break;
960 }
961
Auke Kokcd94dd02006-06-27 09:08:22 -0700962 /* More time needed for PHY to initialize */
963 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400964 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 /* Call a subroutine to configure the link and setup flow control. */
967 ret_val = e1000_setup_link(hw);
968
969 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700970 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 ctrl = E1000_READ_REG(hw, TXDCTL);
972 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
973 E1000_WRITE_REG(hw, TXDCTL, ctrl);
974 }
975
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700976 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700977 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700978 }
979
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400980 switch (hw->mac_type) {
981 default:
982 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800983 case e1000_80003es2lan:
984 /* Enable retransmit on late collisions */
985 reg_data = E1000_READ_REG(hw, TCTL);
986 reg_data |= E1000_TCTL_RTLC;
987 E1000_WRITE_REG(hw, TCTL, reg_data);
988
989 /* Configure Gigabit Carry Extend Padding */
990 reg_data = E1000_READ_REG(hw, TCTL_EXT);
991 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
992 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
993 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
994
995 /* Configure Transmit Inter-Packet Gap */
996 reg_data = E1000_READ_REG(hw, TIPG);
997 reg_data &= ~E1000_TIPG_IPGT_MASK;
998 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
999 E1000_WRITE_REG(hw, TIPG, reg_data);
1000
1001 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1002 reg_data &= ~0x00100000;
1003 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1004 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001005 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001006 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001007 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001008 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001009 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001010 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1011 break;
1012 }
1013
1014
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001015 if (hw->mac_type == e1000_82573) {
1016 uint32_t gcr = E1000_READ_REG(hw, GCR);
1017 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1018 E1000_WRITE_REG(hw, GCR, gcr);
1019 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 /* Clear all of the statistics registers (clear on read). It is
1022 * important that we do this after we have tried to establish link
1023 * because the symbol error count will increment wildly if there
1024 * is no link.
1025 */
1026 e1000_clear_hw_cntrs(hw);
1027
Auke Kokcd94dd02006-06-27 09:08:22 -07001028 /* ICH8 No-snoop bits are opposite polarity.
1029 * Set to snoop by default after reset. */
1030 if (hw->mac_type == e1000_ich8lan)
1031 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1032
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001033 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1034 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1035 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1036 /* Relaxed ordering must be disabled to avoid a parity
1037 * error crash in a PCI slot. */
1038 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1039 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1040 }
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return ret_val;
1043}
1044
1045/******************************************************************************
1046 * Adjust SERDES output amplitude based on EEPROM setting.
1047 *
1048 * hw - Struct containing variables accessed by shared code.
1049 *****************************************************************************/
1050static int32_t
1051e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1052{
1053 uint16_t eeprom_data;
1054 int32_t ret_val;
1055
1056 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1057
Auke Kok8fc897b2006-08-28 14:56:16 -07001058 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 return E1000_SUCCESS;
1060
Auke Kok8fc897b2006-08-28 14:56:16 -07001061 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 case e1000_82545_rev_3:
1063 case e1000_82546_rev_3:
1064 break;
1065 default:
1066 return E1000_SUCCESS;
1067 }
1068
1069 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1070 if (ret_val) {
1071 return ret_val;
1072 }
1073
Auke Kok8fc897b2006-08-28 14:56:16 -07001074 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001076 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001078 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 return ret_val;
1080 }
1081
1082 return E1000_SUCCESS;
1083}
1084
1085/******************************************************************************
1086 * Configures flow control and link settings.
1087 *
1088 * hw - Struct containing variables accessed by shared code
1089 *
1090 * Determines which flow control settings to use. Calls the apropriate media-
1091 * specific link configuration function. Configures the flow control settings.
1092 * Assuming the adapter has a valid link partner, a valid link should be
1093 * established. Assumes the hardware has previously been reset and the
1094 * transmitter and receiver are not enabled.
1095 *****************************************************************************/
1096int32_t
1097e1000_setup_link(struct e1000_hw *hw)
1098{
1099 uint32_t ctrl_ext;
1100 int32_t ret_val;
1101 uint16_t eeprom_data;
1102
1103 DEBUGFUNC("e1000_setup_link");
1104
Jeff Kirsher526f9952006-01-12 16:50:46 -08001105 /* In the case of the phy reset being blocked, we already have a link.
1106 * We do not have to set it up again. */
1107 if (e1000_check_phy_reset_block(hw))
1108 return E1000_SUCCESS;
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /* Read and store word 0x0F of the EEPROM. This word contains bits
1111 * that determine the hardware's default PAUSE (flow control) mode,
1112 * a bit that determines whether the HW defaults to enabling or
1113 * disabling auto-negotiation, and the direction of the
1114 * SW defined pins. If there is no SW over-ride of the flow
1115 * control setting, then the variable hw->fc will
1116 * be initialized based on a value in the EEPROM.
1117 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001118 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001119 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001120 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001121 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001122 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001123 break;
1124 default:
1125 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1126 1, &eeprom_data);
1127 if (ret_val) {
1128 DEBUGOUT("EEPROM Read Error\n");
1129 return -E1000_ERR_EEPROM;
1130 }
1131 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001132 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001133 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1134 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001135 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001136 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001137 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001138 break;
1139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141
1142 /* We want to save off the original Flow Control configuration just
1143 * in case we get disconnected and then reconnected into a different
1144 * hub or switch with different Flow Control capabilities.
1145 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001146 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001147 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Auke Kok8fc897b2006-08-28 14:56:16 -07001149 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001150 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 hw->original_fc = hw->fc;
1153
1154 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1155
1156 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1157 * polarity value for the SW controlled pins, and setup the
1158 * Extended Device Control reg with that info.
1159 * This is needed because one of the SW controlled pins is used for
1160 * signal detection. So this should be done before e1000_setup_pcs_link()
1161 * or e1000_phy_setup() is called.
1162 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001163 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001164 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1165 1, &eeprom_data);
1166 if (ret_val) {
1167 DEBUGOUT("EEPROM Read Error\n");
1168 return -E1000_ERR_EEPROM;
1169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1171 SWDPIO__EXT_SHIFT);
1172 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1173 }
1174
1175 /* Call the necessary subroutine to configure the link. */
1176 ret_val = (hw->media_type == e1000_media_type_copper) ?
1177 e1000_setup_copper_link(hw) :
1178 e1000_setup_fiber_serdes_link(hw);
1179
1180 /* Initialize the flow control address, type, and PAUSE timer
1181 * registers to their default values. This is done even if flow
1182 * control is disabled, because it does not hurt anything to
1183 * initialize these registers.
1184 */
1185 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1186
Auke Kokcd94dd02006-06-27 09:08:22 -07001187 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1188 if (hw->mac_type != e1000_ich8lan) {
1189 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1190 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1191 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1192 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1195
1196 /* Set the flow control receive threshold registers. Normally,
1197 * these registers will be set to a default threshold that may be
1198 * adjusted later by the driver's runtime code. However, if the
1199 * ability to transmit pause frames in not enabled, then these
1200 * registers will be set to 0.
1201 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001202 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 E1000_WRITE_REG(hw, FCRTL, 0);
1204 E1000_WRITE_REG(hw, FCRTH, 0);
1205 } else {
1206 /* We need to set up the Receive Threshold high and low water marks
1207 * as well as (optionally) enabling the transmission of XON frames.
1208 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001209 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1211 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1212 } else {
1213 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1214 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1215 }
1216 }
1217 return ret_val;
1218}
1219
1220/******************************************************************************
1221 * Sets up link for a fiber based or serdes based adapter
1222 *
1223 * hw - Struct containing variables accessed by shared code
1224 *
1225 * Manipulates Physical Coding Sublayer functions in order to configure
1226 * link. Assumes the hardware has been previously reset and the transmitter
1227 * and receiver are not enabled.
1228 *****************************************************************************/
1229static int32_t
1230e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1231{
1232 uint32_t ctrl;
1233 uint32_t status;
1234 uint32_t txcw = 0;
1235 uint32_t i;
1236 uint32_t signal = 0;
1237 int32_t ret_val;
1238
1239 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1240
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001241 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1242 * until explicitly turned off or a power cycle is performed. A read to
1243 * the register does not indicate its status. Therefore, we ensure
1244 * loopback mode is disabled during initialization.
1245 */
1246 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1247 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1248
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001249 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 * set when the optics detect a signal. On older adapters, it will be
1251 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001252 * If we're on serdes media, adjust the output amplitude to value
1253 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 */
1255 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001256 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1258
1259 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001260 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 return ret_val;
1262
1263 /* Take the link out of reset */
1264 ctrl &= ~(E1000_CTRL_LRST);
1265
1266 /* Adjust VCO speed to improve BER performance */
1267 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return ret_val;
1270
1271 e1000_config_collision_dist(hw);
1272
1273 /* Check for a software override of the flow control settings, and setup
1274 * the device accordingly. If auto-negotiation is enabled, then software
1275 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1276 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1277 * auto-negotiation is disabled, then software will have to manually
1278 * configure the two flow control enable bits in the CTRL register.
1279 *
1280 * The possible values of the "fc" parameter are:
1281 * 0: Flow control is completely disabled
1282 * 1: Rx flow control is enabled (we can receive pause frames, but
1283 * not send pause frames).
1284 * 2: Tx flow control is enabled (we can send pause frames but we do
1285 * not support receiving pause frames).
1286 * 3: Both Rx and TX flow control (symmetric) are enabled.
1287 */
1288 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001289 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 /* Flow control is completely disabled by a software over-ride. */
1291 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1292 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001293 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 /* RX Flow control is enabled and TX Flow control is disabled by a
1295 * software over-ride. Since there really isn't a way to advertise
1296 * that we are capable of RX Pause ONLY, we will advertise that we
1297 * support both symmetric and asymmetric RX PAUSE. Later, we will
1298 * disable the adapter's ability to send PAUSE frames.
1299 */
1300 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1301 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001302 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1304 * software over-ride.
1305 */
1306 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1307 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001308 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1310 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1311 break;
1312 default:
1313 DEBUGOUT("Flow control param set incorrectly\n");
1314 return -E1000_ERR_CONFIG;
1315 break;
1316 }
1317
1318 /* Since auto-negotiation is enabled, take the link out of reset (the link
1319 * will be in reset, because we previously reset the chip). This will
1320 * restart auto-negotiation. If auto-neogtiation is successful then the
1321 * link-up status bit will be set and the flow control enable bits (RFCE
1322 * and TFCE) will be set according to their negotiated value.
1323 */
1324 DEBUGOUT("Auto-negotiation enabled\n");
1325
1326 E1000_WRITE_REG(hw, TXCW, txcw);
1327 E1000_WRITE_REG(hw, CTRL, ctrl);
1328 E1000_WRITE_FLUSH(hw);
1329
1330 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001331 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1334 * indication in the Device Status Register. Time-out if a link isn't
1335 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1336 * less than 500 milliseconds even if the other end is doing it in SW).
1337 * For internal serdes, we just assume a signal is present, then poll.
1338 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001339 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1341 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001342 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001343 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001345 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001347 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1349 hw->autoneg_failed = 1;
1350 /* AutoNeg failed to achieve a link, so we'll call
1351 * e1000_check_for_link. This routine will force the link up if
1352 * we detect a signal. This will allow us to communicate with
1353 * non-autonegotiating link partners.
1354 */
1355 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001356 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 DEBUGOUT("Error while checking for link\n");
1358 return ret_val;
1359 }
1360 hw->autoneg_failed = 0;
1361 } else {
1362 hw->autoneg_failed = 0;
1363 DEBUGOUT("Valid Link Found\n");
1364 }
1365 } else {
1366 DEBUGOUT("No Signal Detected\n");
1367 }
1368 return E1000_SUCCESS;
1369}
1370
1371/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001372* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373*
1374* hw - Struct containing variables accessed by shared code
1375******************************************************************************/
1376static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001377e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 uint16_t phy_data;
1382
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001383 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 ctrl = E1000_READ_REG(hw, CTRL);
1386 /* With 82543, we need to force speed and duplex on the MAC equal to what
1387 * the PHY speed and duplex configuration is. In addition, we need to
1388 * perform a hardware reset on the PHY to take it out of reset.
1389 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001390 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 ctrl |= E1000_CTRL_SLU;
1392 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1393 E1000_WRITE_REG(hw, CTRL, ctrl);
1394 } else {
1395 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1396 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001397 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001398 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001399 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 }
1401
1402 /* Make sure we have a valid PHY */
1403 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001404 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 DEBUGOUT("Error, did not detect valid phy.\n");
1406 return ret_val;
1407 }
1408 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1409
1410 /* Set PHY to class A mode (if necessary) */
1411 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001412 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 return ret_val;
1414
Auke Kok8fc897b2006-08-28 14:56:16 -07001415 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 (hw->mac_type == e1000_82546_rev_3)) {
1417 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1418 phy_data |= 0x00000008;
1419 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1420 }
1421
Auke Kok8fc897b2006-08-28 14:56:16 -07001422 if (hw->mac_type <= e1000_82543 ||
1423 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1424 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 hw->phy_reset_disable = FALSE;
1426
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001427 return E1000_SUCCESS;
1428}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001431/********************************************************************
1432* Copper link setup for e1000_phy_igp series.
1433*
1434* hw - Struct containing variables accessed by shared code
1435*********************************************************************/
1436static int32_t
1437e1000_copper_link_igp_setup(struct e1000_hw *hw)
1438{
1439 uint32_t led_ctrl;
1440 int32_t ret_val;
1441 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001443 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001445 if (hw->phy_reset_disable)
1446 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001447
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001448 ret_val = e1000_phy_reset(hw);
1449 if (ret_val) {
1450 DEBUGOUT("Error Resetting the PHY\n");
1451 return ret_val;
1452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Auke Kok8fc897b2006-08-28 14:56:16 -07001454 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001455 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001456 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001457 /* Configure activity LED after PHY reset */
1458 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1459 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1460 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1461 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001462 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001463
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001464 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1465 if (hw->phy_type == e1000_phy_igp) {
1466 /* disable lplu d3 during driver init */
1467 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1468 if (ret_val) {
1469 DEBUGOUT("Error Disabling LPLU D3\n");
1470 return ret_val;
1471 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001472 }
1473
1474 /* disable lplu d0 during driver init */
1475 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1476 if (ret_val) {
1477 DEBUGOUT("Error Disabling LPLU D0\n");
1478 return ret_val;
1479 }
1480 /* Configure mdi-mdix settings */
1481 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1482 if (ret_val)
1483 return ret_val;
1484
1485 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1486 hw->dsp_config_state = e1000_dsp_config_disabled;
1487 /* Force MDI for earlier revs of the IGP PHY */
1488 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1489 hw->mdix = 1;
1490
1491 } else {
1492 hw->dsp_config_state = e1000_dsp_config_enabled;
1493 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1494
1495 switch (hw->mdix) {
1496 case 1:
1497 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1498 break;
1499 case 2:
1500 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1501 break;
1502 case 0:
1503 default:
1504 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1505 break;
1506 }
1507 }
1508 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001509 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001510 return ret_val;
1511
1512 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001513 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001514 e1000_ms_type phy_ms_setting = hw->master_slave;
1515
Auke Kok8fc897b2006-08-28 14:56:16 -07001516 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001517 hw->ffe_config_state = e1000_ffe_config_enabled;
1518
Auke Kok8fc897b2006-08-28 14:56:16 -07001519 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001520 hw->dsp_config_state = e1000_dsp_config_enabled;
1521
1522 /* when autonegotiation advertisment is only 1000Mbps then we
1523 * should disable SmartSpeed and enable Auto MasterSlave
1524 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001525 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001526 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001527 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1528 &phy_data);
1529 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001531 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001532 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1533 phy_data);
1534 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001536 /* Set auto Master/Slave resolution process */
1537 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001538 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001539 return ret_val;
1540 phy_data &= ~CR_1000T_MS_ENABLE;
1541 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001542 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001543 return ret_val;
1544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001546 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001547 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001548 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001550 /* load defaults for future use */
1551 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1552 ((phy_data & CR_1000T_MS_VALUE) ?
1553 e1000_ms_force_master :
1554 e1000_ms_force_slave) :
1555 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001557 switch (phy_ms_setting) {
1558 case e1000_ms_force_master:
1559 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1560 break;
1561 case e1000_ms_force_slave:
1562 phy_data |= CR_1000T_MS_ENABLE;
1563 phy_data &= ~(CR_1000T_MS_VALUE);
1564 break;
1565 case e1000_ms_auto:
1566 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001568 break;
1569 }
1570 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001571 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001572 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Malli Chilakala2b028932005-06-17 17:46:06 -07001575 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001576}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001578/********************************************************************
1579* Copper link setup for e1000_phy_gg82563 series.
1580*
1581* hw - Struct containing variables accessed by shared code
1582*********************************************************************/
1583static int32_t
1584e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1585{
1586 int32_t ret_val;
1587 uint16_t phy_data;
1588 uint32_t reg_data;
1589
1590 DEBUGFUNC("e1000_copper_link_ggp_setup");
1591
Auke Kok8fc897b2006-08-28 14:56:16 -07001592 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001593
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001594 /* Enable CRS on TX for half-duplex operation. */
1595 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1596 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001597 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001598 return ret_val;
1599
1600 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1601 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1602 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1603
1604 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1605 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001606 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001607 return ret_val;
1608
1609 /* Options:
1610 * MDI/MDI-X = 0 (default)
1611 * 0 - Auto for all speeds
1612 * 1 - MDI mode
1613 * 2 - MDI-X mode
1614 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1615 */
1616 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001617 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001618 return ret_val;
1619
1620 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1621
1622 switch (hw->mdix) {
1623 case 1:
1624 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1625 break;
1626 case 2:
1627 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1628 break;
1629 case 0:
1630 default:
1631 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1632 break;
1633 }
1634
1635 /* Options:
1636 * disable_polarity_correction = 0 (default)
1637 * Automatic Correction for Reversed Cable Polarity
1638 * 0 - Disabled
1639 * 1 - Enabled
1640 */
1641 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001642 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001643 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1644 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1645
Auke Kok8fc897b2006-08-28 14:56:16 -07001646 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001647 return ret_val;
1648
1649 /* SW Reset the PHY so all changes take effect */
1650 ret_val = e1000_phy_reset(hw);
1651 if (ret_val) {
1652 DEBUGOUT("Error Resetting the PHY\n");
1653 return ret_val;
1654 }
1655 } /* phy_reset_disable */
1656
1657 if (hw->mac_type == e1000_80003es2lan) {
1658 /* Bypass RX and TX FIFO's */
1659 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1660 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1661 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1662 if (ret_val)
1663 return ret_val;
1664
1665 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1666 if (ret_val)
1667 return ret_val;
1668
1669 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1670 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1671
1672 if (ret_val)
1673 return ret_val;
1674
1675 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1676 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1677 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1678
1679 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1680 &phy_data);
1681 if (ret_val)
1682 return ret_val;
1683
1684 /* Do not init these registers when the HW is in IAMT mode, since the
1685 * firmware will have already initialized them. We only initialize
1686 * them if the HW is not in IAMT mode.
1687 */
1688 if (e1000_check_mng_mode(hw) == FALSE) {
1689 /* Enable Electrical Idle on the PHY */
1690 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1691 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1692 phy_data);
1693 if (ret_val)
1694 return ret_val;
1695
1696 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1697 &phy_data);
1698 if (ret_val)
1699 return ret_val;
1700
Auke Kokcd94dd02006-06-27 09:08:22 -07001701 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001702 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1703 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001704
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001705 if (ret_val)
1706 return ret_val;
1707 }
1708
1709 /* Workaround: Disable padding in Kumeran interface in the MAC
1710 * and in the PHY to avoid CRC errors.
1711 */
1712 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1713 &phy_data);
1714 if (ret_val)
1715 return ret_val;
1716 phy_data |= GG82563_ICR_DIS_PADDING;
1717 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1718 phy_data);
1719 if (ret_val)
1720 return ret_val;
1721 }
1722
1723 return E1000_SUCCESS;
1724}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001726/********************************************************************
1727* Copper link setup for e1000_phy_m88 series.
1728*
1729* hw - Struct containing variables accessed by shared code
1730*********************************************************************/
1731static int32_t
1732e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1733{
1734 int32_t ret_val;
1735 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001737 DEBUGFUNC("e1000_copper_link_mgp_setup");
1738
Auke Kok8fc897b2006-08-28 14:56:16 -07001739 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001740 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001741
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001742 /* Enable CRS on TX. This must be set for half-duplex operation. */
1743 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001744 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001745 return ret_val;
1746
1747 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1748
1749 /* Options:
1750 * MDI/MDI-X = 0 (default)
1751 * 0 - Auto for all speeds
1752 * 1 - MDI mode
1753 * 2 - MDI-X mode
1754 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1755 */
1756 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1757
1758 switch (hw->mdix) {
1759 case 1:
1760 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1761 break;
1762 case 2:
1763 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1764 break;
1765 case 3:
1766 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1767 break;
1768 case 0:
1769 default:
1770 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1771 break;
1772 }
1773
1774 /* Options:
1775 * disable_polarity_correction = 0 (default)
1776 * Automatic Correction for Reversed Cable Polarity
1777 * 0 - Disabled
1778 * 1 - Enabled
1779 */
1780 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001781 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001782 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001783 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1784 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001785 return ret_val;
1786
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001787 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001788 /* Force TX_CLK in the Extended PHY Specific Control Register
1789 * to 25MHz clock.
1790 */
1791 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1792 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001793 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001794
1795 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1796
1797 if ((hw->phy_revision == E1000_REVISION_2) &&
1798 (hw->phy_id == M88E1111_I_PHY_ID)) {
1799 /* Vidalia Phy, set the downshift counter to 5x */
1800 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1801 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1802 ret_val = e1000_write_phy_reg(hw,
1803 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1804 if (ret_val)
1805 return ret_val;
1806 } else {
1807 /* Configure Master and Slave downshift values */
1808 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1809 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1810 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1811 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1812 ret_val = e1000_write_phy_reg(hw,
1813 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1814 if (ret_val)
1815 return ret_val;
1816 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001819 /* SW Reset the PHY so all changes take effect */
1820 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001821 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001822 DEBUGOUT("Error Resetting the PHY\n");
1823 return ret_val;
1824 }
1825
1826 return E1000_SUCCESS;
1827}
1828
1829/********************************************************************
1830* Setup auto-negotiation and flow control advertisements,
1831* and then perform auto-negotiation.
1832*
1833* hw - Struct containing variables accessed by shared code
1834*********************************************************************/
1835static int32_t
1836e1000_copper_link_autoneg(struct e1000_hw *hw)
1837{
1838 int32_t ret_val;
1839 uint16_t phy_data;
1840
1841 DEBUGFUNC("e1000_copper_link_autoneg");
1842
1843 /* Perform some bounds checking on the hw->autoneg_advertised
1844 * parameter. If this variable is zero, then set it to the default.
1845 */
1846 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1847
1848 /* If autoneg_advertised is zero, we assume it was not defaulted
1849 * by the calling code so we set to advertise full capability.
1850 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001851 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001852 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1853
Auke Kokcd94dd02006-06-27 09:08:22 -07001854 /* IFE phy only supports 10/100 */
1855 if (hw->phy_type == e1000_phy_ife)
1856 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1857
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001858 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1859 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001860 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001861 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1862 return ret_val;
1863 }
1864 DEBUGOUT("Restarting Auto-Neg\n");
1865
1866 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1867 * the Auto Neg Restart bit in the PHY control register.
1868 */
1869 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001870 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001871 return ret_val;
1872
1873 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1874 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001875 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001876 return ret_val;
1877
1878 /* Does the user want to wait for Auto-Neg to complete here, or
1879 * check at a later time (for example, callback routine).
1880 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001881 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001882 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001883 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001884 DEBUGOUT("Error while waiting for autoneg to complete\n");
1885 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001889 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001891 return E1000_SUCCESS;
1892}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001894/******************************************************************************
1895* Config the MAC and the PHY after link is up.
1896* 1) Set up the MAC to the current PHY speed/duplex
1897* if we are on 82543. If we
1898* are on newer silicon, we only need to configure
1899* collision distance in the Transmit Control Register.
1900* 2) Set up flow control on the MAC to that established with
1901* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001902* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001903*
1904* hw - Struct containing variables accessed by shared code
1905******************************************************************************/
1906static int32_t
1907e1000_copper_link_postconfig(struct e1000_hw *hw)
1908{
1909 int32_t ret_val;
1910 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001911
Auke Kok8fc897b2006-08-28 14:56:16 -07001912 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001913 e1000_config_collision_dist(hw);
1914 } else {
1915 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001916 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001917 DEBUGOUT("Error configuring MAC to PHY settings\n");
1918 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001920 }
1921 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001922 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001923 DEBUGOUT("Error Configuring Flow Control\n");
1924 return ret_val;
1925 }
1926
1927 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001928 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001929 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001930 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001931 DEBUGOUT("Error Configuring DSP after link up\n");
1932 return ret_val;
1933 }
1934 }
Auke Kok76c224b2006-05-23 13:36:06 -07001935
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001936 return E1000_SUCCESS;
1937}
1938
1939/******************************************************************************
1940* Detects which PHY is present and setup the speed and duplex
1941*
1942* hw - Struct containing variables accessed by shared code
1943******************************************************************************/
1944static int32_t
1945e1000_setup_copper_link(struct e1000_hw *hw)
1946{
1947 int32_t ret_val;
1948 uint16_t i;
1949 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001950 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001951
1952 DEBUGFUNC("e1000_setup_copper_link");
1953
Auke Kokcd94dd02006-06-27 09:08:22 -07001954 switch (hw->mac_type) {
1955 case e1000_80003es2lan:
1956 case e1000_ich8lan:
1957 /* Set the mac to wait the maximum time between each
1958 * iteration and increase the max iterations when
1959 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1960 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1961 if (ret_val)
1962 return ret_val;
1963 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1964 if (ret_val)
1965 return ret_val;
1966 reg_data |= 0x3F;
1967 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1968 if (ret_val)
1969 return ret_val;
1970 default:
1971 break;
1972 }
1973
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001974 /* Check if it is a valid PHY and set PHY mode if necessary. */
1975 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001976 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001977 return ret_val;
1978
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001979 switch (hw->mac_type) {
1980 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001981 /* Kumeran registers are written-only */
1982 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001983 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1984 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1985 reg_data);
1986 if (ret_val)
1987 return ret_val;
1988 break;
1989 default:
1990 break;
1991 }
1992
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001993 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07001994 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001995 hw->phy_type == e1000_phy_igp_2) {
1996 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001997 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001998 return ret_val;
1999 } else if (hw->phy_type == e1000_phy_m88) {
2000 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002001 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002002 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002003 } else if (hw->phy_type == e1000_phy_gg82563) {
2004 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002005 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002006 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002007 }
2008
Auke Kok8fc897b2006-08-28 14:56:16 -07002009 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002010 /* Setup autoneg and flow control advertisement
2011 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002012 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002013 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002014 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002015 } else {
2016 /* PHY will be set to 10H, 10F, 100H,or 100F
2017 * depending on value from forced_speed_duplex. */
2018 DEBUGOUT("Forcing speed and duplex\n");
2019 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002020 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002021 DEBUGOUT("Error Forcing Speed and Duplex\n");
2022 return ret_val;
2023 }
2024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
2026 /* Check link status. Wait up to 100 microseconds for link to become
2027 * valid.
2028 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002029 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002031 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 return ret_val;
2033 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002034 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 return ret_val;
2036
Auke Kok8fc897b2006-08-28 14:56:16 -07002037 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002038 /* Config the MAC and PHY after link is up */
2039 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002040 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 DEBUGOUT("Valid link established!!!\n");
2044 return E1000_SUCCESS;
2045 }
2046 udelay(10);
2047 }
2048
2049 DEBUGOUT("Unable to establish link!!!\n");
2050 return E1000_SUCCESS;
2051}
2052
2053/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002054* Configure the MAC-to-PHY interface for 10/100Mbps
2055*
2056* hw - Struct containing variables accessed by shared code
2057******************************************************************************/
2058static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002059e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002060{
2061 int32_t ret_val = E1000_SUCCESS;
2062 uint32_t tipg;
2063 uint16_t reg_data;
2064
2065 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2066
2067 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2068 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2069 reg_data);
2070 if (ret_val)
2071 return ret_val;
2072
2073 /* Configure Transmit Inter-Packet Gap */
2074 tipg = E1000_READ_REG(hw, TIPG);
2075 tipg &= ~E1000_TIPG_IPGT_MASK;
2076 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2077 E1000_WRITE_REG(hw, TIPG, tipg);
2078
Auke Kokcd94dd02006-06-27 09:08:22 -07002079 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2080
2081 if (ret_val)
2082 return ret_val;
2083
2084 if (duplex == HALF_DUPLEX)
2085 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2086 else
2087 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2088
2089 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2090
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002091 return ret_val;
2092}
2093
2094static int32_t
2095e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2096{
2097 int32_t ret_val = E1000_SUCCESS;
2098 uint16_t reg_data;
2099 uint32_t tipg;
2100
2101 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2102
2103 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2104 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2105 reg_data);
2106 if (ret_val)
2107 return ret_val;
2108
2109 /* Configure Transmit Inter-Packet Gap */
2110 tipg = E1000_READ_REG(hw, TIPG);
2111 tipg &= ~E1000_TIPG_IPGT_MASK;
2112 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2113 E1000_WRITE_REG(hw, TIPG, tipg);
2114
Auke Kokcd94dd02006-06-27 09:08:22 -07002115 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2116
2117 if (ret_val)
2118 return ret_val;
2119
2120 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2121 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2122
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002123 return ret_val;
2124}
2125
2126/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127* Configures PHY autoneg and flow control advertisement settings
2128*
2129* hw - Struct containing variables accessed by shared code
2130******************************************************************************/
2131int32_t
2132e1000_phy_setup_autoneg(struct e1000_hw *hw)
2133{
2134 int32_t ret_val;
2135 uint16_t mii_autoneg_adv_reg;
2136 uint16_t mii_1000t_ctrl_reg;
2137
2138 DEBUGFUNC("e1000_phy_setup_autoneg");
2139
2140 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2141 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002142 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 return ret_val;
2144
Auke Kokcd94dd02006-06-27 09:08:22 -07002145 if (hw->phy_type != e1000_phy_ife) {
2146 /* Read the MII 1000Base-T Control Register (Address 9). */
2147 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2148 if (ret_val)
2149 return ret_val;
2150 } else
2151 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 /* Need to parse both autoneg_advertised and fc and set up
2154 * the appropriate PHY registers. First we will parse for
2155 * autoneg_advertised software override. Since we can advertise
2156 * a plethora of combinations, we need to check each bit
2157 * individually.
2158 */
2159
2160 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2161 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2162 * the 1000Base-T Control Register (Address 9).
2163 */
2164 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2165 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2166
2167 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2168
2169 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002170 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 DEBUGOUT("Advertise 10mb Half duplex\n");
2172 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2173 }
2174
2175 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002176 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 DEBUGOUT("Advertise 10mb Full duplex\n");
2178 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2179 }
2180
2181 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002182 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 DEBUGOUT("Advertise 100mb Half duplex\n");
2184 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2185 }
2186
2187 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002188 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 DEBUGOUT("Advertise 100mb Full duplex\n");
2190 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2191 }
2192
2193 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002194 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2196 }
2197
2198 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002199 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 DEBUGOUT("Advertise 1000mb Full duplex\n");
2201 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002202 if (hw->phy_type == e1000_phy_ife) {
2203 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 }
2206
2207 /* Check for a software override of the flow control settings, and
2208 * setup the PHY advertisement registers accordingly. If
2209 * auto-negotiation is enabled, then software will have to set the
2210 * "PAUSE" bits to the correct value in the Auto-Negotiation
2211 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2212 *
2213 * The possible values of the "fc" parameter are:
2214 * 0: Flow control is completely disabled
2215 * 1: Rx flow control is enabled (we can receive pause frames
2216 * but not send pause frames).
2217 * 2: Tx flow control is enabled (we can send pause frames
2218 * but we do not support receiving pause frames).
2219 * 3: Both Rx and TX flow control (symmetric) are enabled.
2220 * other: No software override. The flow control configuration
2221 * in the EEPROM is used.
2222 */
2223 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002224 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 /* Flow control (RX & TX) is completely disabled by a
2226 * software over-ride.
2227 */
2228 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2229 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002230 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 /* RX Flow control is enabled, and TX Flow control is
2232 * disabled, by a software over-ride.
2233 */
2234 /* Since there really isn't a way to advertise that we are
2235 * capable of RX Pause ONLY, we will advertise that we
2236 * support both symmetric and asymmetric RX PAUSE. Later
2237 * (in e1000_config_fc_after_link_up) we will disable the
2238 *hw's ability to send PAUSE frames.
2239 */
2240 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2241 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002242 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 /* TX Flow control is enabled, and RX Flow control is
2244 * disabled, by a software over-ride.
2245 */
2246 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2247 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2248 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002249 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 /* Flow control (both RX and TX) is enabled by a software
2251 * over-ride.
2252 */
2253 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2254 break;
2255 default:
2256 DEBUGOUT("Flow control param set incorrectly\n");
2257 return -E1000_ERR_CONFIG;
2258 }
2259
2260 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002261 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return ret_val;
2263
2264 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2265
Auke Kokcd94dd02006-06-27 09:08:22 -07002266 if (hw->phy_type != e1000_phy_ife) {
2267 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2268 if (ret_val)
2269 return ret_val;
2270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
2272 return E1000_SUCCESS;
2273}
2274
2275/******************************************************************************
2276* Force PHY speed and duplex settings to hw->forced_speed_duplex
2277*
2278* hw - Struct containing variables accessed by shared code
2279******************************************************************************/
2280static int32_t
2281e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2282{
2283 uint32_t ctrl;
2284 int32_t ret_val;
2285 uint16_t mii_ctrl_reg;
2286 uint16_t mii_status_reg;
2287 uint16_t phy_data;
2288 uint16_t i;
2289
2290 DEBUGFUNC("e1000_phy_force_speed_duplex");
2291
2292 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002293 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2296
2297 /* Read the Device Control Register. */
2298 ctrl = E1000_READ_REG(hw, CTRL);
2299
2300 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2301 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2302 ctrl &= ~(DEVICE_SPEED_MASK);
2303
2304 /* Clear the Auto Speed Detect Enable bit. */
2305 ctrl &= ~E1000_CTRL_ASDE;
2306
2307 /* Read the MII Control Register. */
2308 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002309 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 return ret_val;
2311
2312 /* We need to disable autoneg in order to force link and duplex. */
2313
2314 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2315
2316 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002317 if (hw->forced_speed_duplex == e1000_100_full ||
2318 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 /* We want to force full duplex so we SET the full duplex bits in the
2320 * Device and MII Control Registers.
2321 */
2322 ctrl |= E1000_CTRL_FD;
2323 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2324 DEBUGOUT("Full Duplex\n");
2325 } else {
2326 /* We want to force half duplex so we CLEAR the full duplex bits in
2327 * the Device and MII Control Registers.
2328 */
2329 ctrl &= ~E1000_CTRL_FD;
2330 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2331 DEBUGOUT("Half Duplex\n");
2332 }
2333
2334 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002335 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 hw->forced_speed_duplex == e1000_100_half) {
2337 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2338 ctrl |= E1000_CTRL_SPD_100;
2339 mii_ctrl_reg |= MII_CR_SPEED_100;
2340 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2341 DEBUGOUT("Forcing 100mb ");
2342 } else {
2343 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2344 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2345 mii_ctrl_reg |= MII_CR_SPEED_10;
2346 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2347 DEBUGOUT("Forcing 10mb ");
2348 }
2349
2350 e1000_config_collision_dist(hw);
2351
2352 /* Write the configured values back to the Device Control Reg. */
2353 E1000_WRITE_REG(hw, CTRL, ctrl);
2354
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002355 if ((hw->phy_type == e1000_phy_m88) ||
2356 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002358 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 return ret_val;
2360
2361 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2362 * forced whenever speed are duplex are forced.
2363 */
2364 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2365 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002366 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 return ret_val;
2368
2369 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2370
2371 /* Need to reset the PHY or these changes will be ignored */
2372 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002373
Auke Kokcd94dd02006-06-27 09:08:22 -07002374 /* Disable MDI-X support for 10/100 */
2375 } else if (hw->phy_type == e1000_phy_ife) {
2376 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2377 if (ret_val)
2378 return ret_val;
2379
2380 phy_data &= ~IFE_PMC_AUTO_MDIX;
2381 phy_data &= ~IFE_PMC_FORCE_MDIX;
2382
2383 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2384 if (ret_val)
2385 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 } else {
2388 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2389 * forced whenever speed or duplex are forced.
2390 */
2391 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002392 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 return ret_val;
2394
2395 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2396 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2397
2398 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002399 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 return ret_val;
2401 }
2402
2403 /* Write back the modified PHY MII control register. */
2404 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002405 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 return ret_val;
2407
2408 udelay(1);
2409
2410 /* The wait_autoneg_complete flag may be a little misleading here.
2411 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2412 * But we do want to delay for a period while forcing only so we
2413 * don't generate false No Link messages. So we will wait here
2414 * only if the user has set wait_autoneg_complete to 1, which is
2415 * the default.
2416 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002417 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 /* We will wait for autoneg to complete. */
2419 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2420 mii_status_reg = 0;
2421
2422 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002423 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2425 * to be set.
2426 */
2427 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002428 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 return ret_val;
2430
2431 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002432 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 return ret_val;
2434
Auke Kok8fc897b2006-08-28 14:56:16 -07002435 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002436 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002438 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002439 ((hw->phy_type == e1000_phy_m88) ||
2440 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 /* We didn't get link. Reset the DSP and wait again for link. */
2442 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002443 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 DEBUGOUT("Error Resetting PHY DSP\n");
2445 return ret_val;
2446 }
2447 }
2448 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002449 for (i = PHY_FORCE_TIME; i > 0; i--) {
2450 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002451 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2453 * to be set.
2454 */
2455 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002456 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 return ret_val;
2458
2459 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002460 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 return ret_val;
2462 }
2463 }
2464
2465 if (hw->phy_type == e1000_phy_m88) {
2466 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2467 * Extended PHY Specific Control Register to 25MHz clock. This value
2468 * defaults back to a 2.5MHz clock when the PHY is reset.
2469 */
2470 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002471 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 return ret_val;
2473
2474 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2475 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002476 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 return ret_val;
2478
2479 /* In addition, because of the s/w reset above, we need to enable CRS on
2480 * TX. This must be set for both full and half duplex operation.
2481 */
2482 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002483 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return ret_val;
2485
2486 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2487 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002488 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 return ret_val;
2490
Auke Kok8fc897b2006-08-28 14:56:16 -07002491 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2492 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2493 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002495 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return ret_val;
2497 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002498 } else if (hw->phy_type == e1000_phy_gg82563) {
2499 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2500 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2501 * we're not in a forced 10/duplex configuration. */
2502 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2503 if (ret_val)
2504 return ret_val;
2505
2506 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2507 if ((hw->forced_speed_duplex == e1000_10_full) ||
2508 (hw->forced_speed_duplex == e1000_10_half))
2509 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2510 else
2511 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2512
2513 /* Also due to the reset, we need to enable CRS on Tx. */
2514 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2515
2516 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2517 if (ret_val)
2518 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 }
2520 return E1000_SUCCESS;
2521}
2522
2523/******************************************************************************
2524* Sets the collision distance in the Transmit Control register
2525*
2526* hw - Struct containing variables accessed by shared code
2527*
2528* Link should have been established previously. Reads the speed and duplex
2529* information from the Device Status register.
2530******************************************************************************/
2531void
2532e1000_config_collision_dist(struct e1000_hw *hw)
2533{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002534 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
2536 DEBUGFUNC("e1000_config_collision_dist");
2537
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002538 if (hw->mac_type < e1000_82543)
2539 coll_dist = E1000_COLLISION_DISTANCE_82542;
2540 else
2541 coll_dist = E1000_COLLISION_DISTANCE;
2542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 tctl = E1000_READ_REG(hw, TCTL);
2544
2545 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002546 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 E1000_WRITE_REG(hw, TCTL, tctl);
2549 E1000_WRITE_FLUSH(hw);
2550}
2551
2552/******************************************************************************
2553* Sets MAC speed and duplex settings to reflect the those in the PHY
2554*
2555* hw - Struct containing variables accessed by shared code
2556* mii_reg - data to write to the MII control register
2557*
2558* The contents of the PHY register containing the needed information need to
2559* be passed in.
2560******************************************************************************/
2561static int32_t
2562e1000_config_mac_to_phy(struct e1000_hw *hw)
2563{
2564 uint32_t ctrl;
2565 int32_t ret_val;
2566 uint16_t phy_data;
2567
2568 DEBUGFUNC("e1000_config_mac_to_phy");
2569
Auke Kok76c224b2006-05-23 13:36:06 -07002570 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002571 * MAC speed/duplex configuration.*/
2572 if (hw->mac_type >= e1000_82544)
2573 return E1000_SUCCESS;
2574
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 /* Read the Device Control Register and set the bits to Force Speed
2576 * and Duplex.
2577 */
2578 ctrl = E1000_READ_REG(hw, CTRL);
2579 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2580 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2581
2582 /* Set up duplex in the Device Control and Transmit Control
2583 * registers depending on negotiated values.
2584 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002585 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002586 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002587 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Auke Kok8fc897b2006-08-28 14:56:16 -07002589 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002590 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002591 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002592 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002594 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002596 /* Set up speed in the Device Control register depending on
2597 * negotiated values.
2598 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002599 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002600 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002601 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002602 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 /* Write the configured values back to the Device Control Reg. */
2605 E1000_WRITE_REG(hw, CTRL, ctrl);
2606 return E1000_SUCCESS;
2607}
2608
2609/******************************************************************************
2610 * Forces the MAC's flow control settings.
2611 *
2612 * hw - Struct containing variables accessed by shared code
2613 *
2614 * Sets the TFCE and RFCE bits in the device control register to reflect
2615 * the adapter settings. TFCE and RFCE need to be explicitly set by
2616 * software when a Copper PHY is used because autonegotiation is managed
2617 * by the PHY rather than the MAC. Software must also configure these
2618 * bits when link is forced on a fiber connection.
2619 *****************************************************************************/
2620int32_t
2621e1000_force_mac_fc(struct e1000_hw *hw)
2622{
2623 uint32_t ctrl;
2624
2625 DEBUGFUNC("e1000_force_mac_fc");
2626
2627 /* Get the current configuration of the Device Control Register */
2628 ctrl = E1000_READ_REG(hw, CTRL);
2629
2630 /* Because we didn't get link via the internal auto-negotiation
2631 * mechanism (we either forced link or we got link via PHY
2632 * auto-neg), we have to manually enable/disable transmit an
2633 * receive flow control.
2634 *
2635 * The "Case" statement below enables/disable flow control
2636 * according to the "hw->fc" parameter.
2637 *
2638 * The possible values of the "fc" parameter are:
2639 * 0: Flow control is completely disabled
2640 * 1: Rx flow control is enabled (we can receive pause
2641 * frames but not send pause frames).
2642 * 2: Tx flow control is enabled (we can send pause frames
2643 * frames but we do not receive pause frames).
2644 * 3: Both Rx and TX flow control (symmetric) is enabled.
2645 * other: No other values should be possible at this point.
2646 */
2647
2648 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002649 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2651 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002652 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 ctrl &= (~E1000_CTRL_TFCE);
2654 ctrl |= E1000_CTRL_RFCE;
2655 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002656 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 ctrl &= (~E1000_CTRL_RFCE);
2658 ctrl |= E1000_CTRL_TFCE;
2659 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002660 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2662 break;
2663 default:
2664 DEBUGOUT("Flow control param set incorrectly\n");
2665 return -E1000_ERR_CONFIG;
2666 }
2667
2668 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002669 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 ctrl &= (~E1000_CTRL_TFCE);
2671
2672 E1000_WRITE_REG(hw, CTRL, ctrl);
2673 return E1000_SUCCESS;
2674}
2675
2676/******************************************************************************
2677 * Configures flow control settings after link is established
2678 *
2679 * hw - Struct containing variables accessed by shared code
2680 *
2681 * Should be called immediately after a valid link has been established.
2682 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2683 * and autonegotiation is enabled, the MAC flow control settings will be set
2684 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2685 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2686 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002687static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688e1000_config_fc_after_link_up(struct e1000_hw *hw)
2689{
2690 int32_t ret_val;
2691 uint16_t mii_status_reg;
2692 uint16_t mii_nway_adv_reg;
2693 uint16_t mii_nway_lp_ability_reg;
2694 uint16_t speed;
2695 uint16_t duplex;
2696
2697 DEBUGFUNC("e1000_config_fc_after_link_up");
2698
2699 /* Check for the case where we have fiber media and auto-neg failed
2700 * so we had to force link. In this case, we need to force the
2701 * configuration of the MAC to match the "fc" parameter.
2702 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002703 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2704 ((hw->media_type == e1000_media_type_internal_serdes) &&
2705 (hw->autoneg_failed)) ||
2706 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002708 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 DEBUGOUT("Error forcing flow control settings\n");
2710 return ret_val;
2711 }
2712 }
2713
2714 /* Check for the case where we have copper media and auto-neg is
2715 * enabled. In this case, we need to check and see if Auto-Neg
2716 * has completed, and if so, how the PHY and link partner has
2717 * flow control configured.
2718 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002719 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 /* Read the MII Status Register and check to see if AutoNeg
2721 * has completed. We read this twice because this reg has
2722 * some "sticky" (latched) bits.
2723 */
2724 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002725 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 return ret_val;
2727 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002728 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 return ret_val;
2730
Auke Kok8fc897b2006-08-28 14:56:16 -07002731 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 /* The AutoNeg process has completed, so we now need to
2733 * read both the Auto Negotiation Advertisement Register
2734 * (Address 4) and the Auto_Negotiation Base Page Ability
2735 * Register (Address 5) to determine how flow control was
2736 * negotiated.
2737 */
2738 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2739 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002740 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 return ret_val;
2742 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2743 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002744 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return ret_val;
2746
2747 /* Two bits in the Auto Negotiation Advertisement Register
2748 * (Address 4) and two bits in the Auto Negotiation Base
2749 * Page Ability Register (Address 5) determine flow control
2750 * for both the PHY and the link partner. The following
2751 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2752 * 1999, describes these PAUSE resolution bits and how flow
2753 * control is determined based upon these settings.
2754 * NOTE: DC = Don't Care
2755 *
2756 * LOCAL DEVICE | LINK PARTNER
2757 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2758 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002759 * 0 | 0 | DC | DC | E1000_FC_NONE
2760 * 0 | 1 | 0 | DC | E1000_FC_NONE
2761 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2762 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2763 * 1 | 0 | 0 | DC | E1000_FC_NONE
2764 * 1 | DC | 1 | DC | E1000_FC_FULL
2765 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2766 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 *
2768 */
2769 /* Are both PAUSE bits set to 1? If so, this implies
2770 * Symmetric Flow Control is enabled at both ends. The
2771 * ASM_DIR bits are irrelevant per the spec.
2772 *
2773 * For Symmetric Flow Control:
2774 *
2775 * LOCAL DEVICE | LINK PARTNER
2776 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2777 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002778 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 *
2780 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002781 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2782 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 /* Now we need to check if the user selected RX ONLY
2784 * of pause frames. In this case, we had to advertise
2785 * FULL flow control because we could not advertise RX
2786 * ONLY. Hence, we must now check to see if we need to
2787 * turn OFF the TRANSMISSION of PAUSE frames.
2788 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002789 if (hw->original_fc == E1000_FC_FULL) {
2790 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002791 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002793 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002794 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
2796 }
2797 /* For receiving PAUSE frames ONLY.
2798 *
2799 * LOCAL DEVICE | LINK PARTNER
2800 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2801 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002802 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 *
2804 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002805 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2806 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2807 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2808 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002809 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002810 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 }
2812 /* For transmitting PAUSE frames ONLY.
2813 *
2814 * LOCAL DEVICE | LINK PARTNER
2815 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2816 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002817 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 *
2819 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002820 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2821 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2822 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2823 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002824 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002825 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
2827 /* Per the IEEE spec, at this point flow control should be
2828 * disabled. However, we want to consider that we could
2829 * be connected to a legacy switch that doesn't advertise
2830 * desired flow control, but can be forced on the link
2831 * partner. So if we advertised no flow control, that is
2832 * what we will resolve to. If we advertised some kind of
2833 * receive capability (Rx Pause Only or Full Flow Control)
2834 * and the link partner advertised none, we will configure
2835 * ourselves to enable Rx Flow Control only. We can do
2836 * this safely for two reasons: If the link partner really
2837 * didn't want flow control enabled, and we enable Rx, no
2838 * harm done since we won't be receiving any PAUSE frames
2839 * anyway. If the intent on the link partner was to have
2840 * flow control enabled, then by us enabling RX only, we
2841 * can at least receive pause frames and process them.
2842 * This is a good idea because in most cases, since we are
2843 * predominantly a server NIC, more times than not we will
2844 * be asked to delay transmission of packets than asking
2845 * our link partner to pause transmission of frames.
2846 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002847 else if ((hw->original_fc == E1000_FC_NONE ||
2848 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002849 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002850 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002851 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002853 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002854 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 }
2856
2857 /* Now we need to do one last check... If we auto-
2858 * negotiated to HALF DUPLEX, flow control should not be
2859 * enabled per IEEE 802.3 spec.
2860 */
2861 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002862 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 DEBUGOUT("Error getting link speed and duplex\n");
2864 return ret_val;
2865 }
2866
Auke Kok8fc897b2006-08-28 14:56:16 -07002867 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002868 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
2870 /* Now we call a subroutine to actually force the MAC
2871 * controller to use the correct flow control settings.
2872 */
2873 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002874 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 DEBUGOUT("Error forcing flow control settings\n");
2876 return ret_val;
2877 }
2878 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002879 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 }
2881 }
2882 return E1000_SUCCESS;
2883}
2884
2885/******************************************************************************
2886 * Checks to see if the link status of the hardware has changed.
2887 *
2888 * hw - Struct containing variables accessed by shared code
2889 *
2890 * Called by any function that needs to check the link status of the adapter.
2891 *****************************************************************************/
2892int32_t
2893e1000_check_for_link(struct e1000_hw *hw)
2894{
2895 uint32_t rxcw = 0;
2896 uint32_t ctrl;
2897 uint32_t status;
2898 uint32_t rctl;
2899 uint32_t icr;
2900 uint32_t signal = 0;
2901 int32_t ret_val;
2902 uint16_t phy_data;
2903
2904 DEBUGFUNC("e1000_check_for_link");
2905
2906 ctrl = E1000_READ_REG(hw, CTRL);
2907 status = E1000_READ_REG(hw, STATUS);
2908
2909 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2910 * set when the optics detect a signal. On older adapters, it will be
2911 * cleared when there is a signal. This applies to fiber media only.
2912 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002913 if ((hw->media_type == e1000_media_type_fiber) ||
2914 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 rxcw = E1000_READ_REG(hw, RXCW);
2916
Auke Kok8fc897b2006-08-28 14:56:16 -07002917 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002919 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 hw->get_link_status = FALSE;
2921 }
2922 }
2923
2924 /* If we have a copper PHY then we only want to go out to the PHY
2925 * registers to see if Auto-Neg has completed and/or if our link
2926 * status has changed. The get_link_status flag will be set if we
2927 * receive a Link Status Change interrupt or we have Rx Sequence
2928 * Errors.
2929 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002930 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 /* First we want to see if the MII Status Register reports
2932 * link. If so, then we want to get the current speed/duplex
2933 * of the PHY.
2934 * Read the register twice since the link bit is sticky.
2935 */
2936 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002937 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 return ret_val;
2939 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002940 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 return ret_val;
2942
Auke Kok8fc897b2006-08-28 14:56:16 -07002943 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 hw->get_link_status = FALSE;
2945 /* Check if there was DownShift, must be checked immediately after
2946 * link-up */
2947 e1000_check_downshift(hw);
2948
2949 /* If we are on 82544 or 82543 silicon and speed/duplex
2950 * are forced to 10H or 10F, then we will implement the polarity
2951 * reversal workaround. We disable interrupts first, and upon
2952 * returning, place the devices interrupt state to its previous
2953 * value except for the link status change interrupt which will
2954 * happen due to the execution of this workaround.
2955 */
2956
Auke Kok8fc897b2006-08-28 14:56:16 -07002957 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2958 (!hw->autoneg) &&
2959 (hw->forced_speed_duplex == e1000_10_full ||
2960 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2962 ret_val = e1000_polarity_reversal_workaround(hw);
2963 icr = E1000_READ_REG(hw, ICR);
2964 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2965 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2966 }
2967
2968 } else {
2969 /* No link detected */
2970 e1000_config_dsp_after_link_change(hw, FALSE);
2971 return 0;
2972 }
2973
2974 /* If we are forcing speed/duplex, then we simply return since
2975 * we have already determined whether we have link or not.
2976 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002977 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
2979 /* optimize the dsp settings for the igp phy */
2980 e1000_config_dsp_after_link_change(hw, TRUE);
2981
2982 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2983 * have Si on board that is 82544 or newer, Auto
2984 * Speed Detection takes care of MAC speed/duplex
2985 * configuration. So we only need to configure Collision
2986 * Distance in the MAC. Otherwise, we need to force
2987 * speed/duplex on the MAC to the current PHY speed/duplex
2988 * settings.
2989 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002990 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 e1000_config_collision_dist(hw);
2992 else {
2993 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002994 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 DEBUGOUT("Error configuring MAC to PHY settings\n");
2996 return ret_val;
2997 }
2998 }
2999
3000 /* Configure Flow Control now that Auto-Neg has completed. First, we
3001 * need to restore the desired flow control settings because we may
3002 * have had to re-autoneg with a different link partner.
3003 */
3004 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003005 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 DEBUGOUT("Error configuring flow control\n");
3007 return ret_val;
3008 }
3009
3010 /* At this point we know that we are on copper and we have
3011 * auto-negotiated link. These are conditions for checking the link
3012 * partner capability register. We use the link speed to determine if
3013 * TBI compatibility needs to be turned on or off. If the link is not
3014 * at gigabit speed, then TBI compatibility is not needed. If we are
3015 * at gigabit speed, we turn on TBI compatibility.
3016 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003017 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003019 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3020 if (ret_val) {
3021 DEBUGOUT("Error getting link speed and duplex\n");
3022 return ret_val;
3023 }
3024 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 /* If link speed is not set to gigabit speed, we do not need
3026 * to enable TBI compatibility.
3027 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003028 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 /* If we previously were in the mode, turn it off. */
3030 rctl = E1000_READ_REG(hw, RCTL);
3031 rctl &= ~E1000_RCTL_SBP;
3032 E1000_WRITE_REG(hw, RCTL, rctl);
3033 hw->tbi_compatibility_on = FALSE;
3034 }
3035 } else {
3036 /* If TBI compatibility is was previously off, turn it on. For
3037 * compatibility with a TBI link partner, we will store bad
3038 * packets. Some frames have an additional byte on the end and
3039 * will look like CRC errors to to the hardware.
3040 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003041 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 hw->tbi_compatibility_on = TRUE;
3043 rctl = E1000_READ_REG(hw, RCTL);
3044 rctl |= E1000_RCTL_SBP;
3045 E1000_WRITE_REG(hw, RCTL, rctl);
3046 }
3047 }
3048 }
3049 }
3050 /* If we don't have link (auto-negotiation failed or link partner cannot
3051 * auto-negotiate), the cable is plugged in (we have signal), and our
3052 * link partner is not trying to auto-negotiate with us (we are receiving
3053 * idles or data), we need to force link up. We also need to give
3054 * auto-negotiation time to complete, in case the cable was just plugged
3055 * in. The autoneg_failed flag does this.
3056 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003057 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003059 (hw->media_type == e1000_media_type_internal_serdes)) &&
3060 (!(status & E1000_STATUS_LU)) &&
3061 (!(rxcw & E1000_RXCW_C))) {
3062 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 hw->autoneg_failed = 1;
3064 return 0;
3065 }
Auke Koka42a5072006-05-23 13:36:01 -07003066 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068 /* Disable auto-negotiation in the TXCW register */
3069 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3070
3071 /* Force link-up and also force full-duplex. */
3072 ctrl = E1000_READ_REG(hw, CTRL);
3073 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3074 E1000_WRITE_REG(hw, CTRL, ctrl);
3075
3076 /* Configure Flow Control after forcing link up. */
3077 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003078 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 DEBUGOUT("Error configuring flow control\n");
3080 return ret_val;
3081 }
3082 }
3083 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3084 * auto-negotiation in the TXCW register and disable forced link in the
3085 * Device Control register in an attempt to auto-negotiate with our link
3086 * partner.
3087 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003088 else if (((hw->media_type == e1000_media_type_fiber) ||
3089 (hw->media_type == e1000_media_type_internal_serdes)) &&
3090 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003091 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3093 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3094
3095 hw->serdes_link_down = FALSE;
3096 }
3097 /* If we force link for non-auto-negotiation switch, check link status
3098 * based on MAC synchronization for internal serdes media type.
3099 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003100 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3101 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 /* SYNCH bit and IV bit are sticky. */
3103 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003104 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3105 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 hw->serdes_link_down = FALSE;
3107 DEBUGOUT("SERDES: Link is up.\n");
3108 }
3109 } else {
3110 hw->serdes_link_down = TRUE;
3111 DEBUGOUT("SERDES: Link is down.\n");
3112 }
3113 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003114 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3115 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3117 }
3118 return E1000_SUCCESS;
3119}
3120
3121/******************************************************************************
3122 * Detects the current speed and duplex settings of the hardware.
3123 *
3124 * hw - Struct containing variables accessed by shared code
3125 * speed - Speed of the connection
3126 * duplex - Duplex setting of the connection
3127 *****************************************************************************/
3128int32_t
3129e1000_get_speed_and_duplex(struct e1000_hw *hw,
3130 uint16_t *speed,
3131 uint16_t *duplex)
3132{
3133 uint32_t status;
3134 int32_t ret_val;
3135 uint16_t phy_data;
3136
3137 DEBUGFUNC("e1000_get_speed_and_duplex");
3138
Auke Kok8fc897b2006-08-28 14:56:16 -07003139 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003141 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 *speed = SPEED_1000;
3143 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003144 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 *speed = SPEED_100;
3146 DEBUGOUT("100 Mbs, ");
3147 } else {
3148 *speed = SPEED_10;
3149 DEBUGOUT("10 Mbs, ");
3150 }
3151
Auke Kok8fc897b2006-08-28 14:56:16 -07003152 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003154 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 } else {
3156 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003157 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 }
3159 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003160 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 *speed = SPEED_1000;
3162 *duplex = FULL_DUPLEX;
3163 }
3164
3165 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3166 * if it is operating at half duplex. Here we set the duplex settings to
3167 * match the duplex in the link partner's capabilities.
3168 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003169 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003171 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return ret_val;
3173
Auke Kok8fc897b2006-08-28 14:56:16 -07003174 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 *duplex = HALF_DUPLEX;
3176 else {
3177 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003178 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003180 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3182 *duplex = HALF_DUPLEX;
3183 }
3184 }
3185
Auke Kok76c224b2006-05-23 13:36:06 -07003186 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003187 (hw->media_type == e1000_media_type_copper)) {
3188 if (*speed == SPEED_1000)
3189 ret_val = e1000_configure_kmrn_for_1000(hw);
3190 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003191 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3192 if (ret_val)
3193 return ret_val;
3194 }
3195
3196 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3197 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003198 if (ret_val)
3199 return ret_val;
3200 }
3201
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 return E1000_SUCCESS;
3203}
3204
3205/******************************************************************************
3206* Blocks until autoneg completes or times out (~4.5 seconds)
3207*
3208* hw - Struct containing variables accessed by shared code
3209******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003210static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211e1000_wait_autoneg(struct e1000_hw *hw)
3212{
3213 int32_t ret_val;
3214 uint16_t i;
3215 uint16_t phy_data;
3216
3217 DEBUGFUNC("e1000_wait_autoneg");
3218 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3219
3220 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003221 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 /* Read the MII Status Register and wait for Auto-Neg
3223 * Complete bit to be set.
3224 */
3225 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003226 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return ret_val;
3228 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003229 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003231 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 return E1000_SUCCESS;
3233 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003234 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 }
3236 return E1000_SUCCESS;
3237}
3238
3239/******************************************************************************
3240* Raises the Management Data Clock
3241*
3242* hw - Struct containing variables accessed by shared code
3243* ctrl - Device control register's current value
3244******************************************************************************/
3245static void
3246e1000_raise_mdi_clk(struct e1000_hw *hw,
3247 uint32_t *ctrl)
3248{
3249 /* Raise the clock input to the Management Data Clock (by setting the MDC
3250 * bit), and then delay 10 microseconds.
3251 */
3252 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3253 E1000_WRITE_FLUSH(hw);
3254 udelay(10);
3255}
3256
3257/******************************************************************************
3258* Lowers the Management Data Clock
3259*
3260* hw - Struct containing variables accessed by shared code
3261* ctrl - Device control register's current value
3262******************************************************************************/
3263static void
3264e1000_lower_mdi_clk(struct e1000_hw *hw,
3265 uint32_t *ctrl)
3266{
3267 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3268 * bit), and then delay 10 microseconds.
3269 */
3270 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3271 E1000_WRITE_FLUSH(hw);
3272 udelay(10);
3273}
3274
3275/******************************************************************************
3276* Shifts data bits out to the PHY
3277*
3278* hw - Struct containing variables accessed by shared code
3279* data - Data to send out to the PHY
3280* count - Number of bits to shift out
3281*
3282* Bits are shifted out in MSB to LSB order.
3283******************************************************************************/
3284static void
3285e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3286 uint32_t data,
3287 uint16_t count)
3288{
3289 uint32_t ctrl;
3290 uint32_t mask;
3291
3292 /* We need to shift "count" number of bits out to the PHY. So, the value
3293 * in the "data" parameter will be shifted out to the PHY one bit at a
3294 * time. In order to do this, "data" must be broken down into bits.
3295 */
3296 mask = 0x01;
3297 mask <<= (count - 1);
3298
3299 ctrl = E1000_READ_REG(hw, CTRL);
3300
3301 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3302 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3303
Auke Kok8fc897b2006-08-28 14:56:16 -07003304 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3306 * then raising and lowering the Management Data Clock. A "0" is
3307 * shifted out to the PHY by setting the MDIO bit to "0" and then
3308 * raising and lowering the clock.
3309 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003310 if (data & mask)
3311 ctrl |= E1000_CTRL_MDIO;
3312 else
3313 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
3315 E1000_WRITE_REG(hw, CTRL, ctrl);
3316 E1000_WRITE_FLUSH(hw);
3317
3318 udelay(10);
3319
3320 e1000_raise_mdi_clk(hw, &ctrl);
3321 e1000_lower_mdi_clk(hw, &ctrl);
3322
3323 mask = mask >> 1;
3324 }
3325}
3326
3327/******************************************************************************
3328* Shifts data bits in from the PHY
3329*
3330* hw - Struct containing variables accessed by shared code
3331*
3332* Bits are shifted in in MSB to LSB order.
3333******************************************************************************/
3334static uint16_t
3335e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3336{
3337 uint32_t ctrl;
3338 uint16_t data = 0;
3339 uint8_t i;
3340
3341 /* In order to read a register from the PHY, we need to shift in a total
3342 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3343 * to avoid contention on the MDIO pin when a read operation is performed.
3344 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3345 * by raising the input to the Management Data Clock (setting the MDC bit),
3346 * and then reading the value of the MDIO bit.
3347 */
3348 ctrl = E1000_READ_REG(hw, CTRL);
3349
3350 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3351 ctrl &= ~E1000_CTRL_MDIO_DIR;
3352 ctrl &= ~E1000_CTRL_MDIO;
3353
3354 E1000_WRITE_REG(hw, CTRL, ctrl);
3355 E1000_WRITE_FLUSH(hw);
3356
3357 /* Raise and Lower the clock before reading in the data. This accounts for
3358 * the turnaround bits. The first clock occurred when we clocked out the
3359 * last bit of the Register Address.
3360 */
3361 e1000_raise_mdi_clk(hw, &ctrl);
3362 e1000_lower_mdi_clk(hw, &ctrl);
3363
Auke Kok8fc897b2006-08-28 14:56:16 -07003364 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 data = data << 1;
3366 e1000_raise_mdi_clk(hw, &ctrl);
3367 ctrl = E1000_READ_REG(hw, CTRL);
3368 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003369 if (ctrl & E1000_CTRL_MDIO)
3370 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 e1000_lower_mdi_clk(hw, &ctrl);
3372 }
3373
3374 e1000_raise_mdi_clk(hw, &ctrl);
3375 e1000_lower_mdi_clk(hw, &ctrl);
3376
3377 return data;
3378}
3379
Adrian Bunke4c780b2006-08-14 23:00:10 -07003380static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003381e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3382{
3383 uint32_t swfw_sync = 0;
3384 uint32_t swmask = mask;
3385 uint32_t fwmask = mask << 16;
3386 int32_t timeout = 200;
3387
3388 DEBUGFUNC("e1000_swfw_sync_acquire");
3389
Auke Kokcd94dd02006-06-27 09:08:22 -07003390 if (hw->swfwhw_semaphore_present)
3391 return e1000_get_software_flag(hw);
3392
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003393 if (!hw->swfw_sync_present)
3394 return e1000_get_hw_eeprom_semaphore(hw);
3395
Auke Kok8fc897b2006-08-28 14:56:16 -07003396 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003397 if (e1000_get_hw_eeprom_semaphore(hw))
3398 return -E1000_ERR_SWFW_SYNC;
3399
3400 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3401 if (!(swfw_sync & (fwmask | swmask))) {
3402 break;
3403 }
3404
3405 /* firmware currently using resource (fwmask) */
3406 /* or other software thread currently using resource (swmask) */
3407 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003408 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003409 timeout--;
3410 }
3411
3412 if (!timeout) {
3413 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3414 return -E1000_ERR_SWFW_SYNC;
3415 }
3416
3417 swfw_sync |= swmask;
3418 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3419
3420 e1000_put_hw_eeprom_semaphore(hw);
3421 return E1000_SUCCESS;
3422}
3423
Adrian Bunke4c780b2006-08-14 23:00:10 -07003424static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003425e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3426{
3427 uint32_t swfw_sync;
3428 uint32_t swmask = mask;
3429
3430 DEBUGFUNC("e1000_swfw_sync_release");
3431
Auke Kokcd94dd02006-06-27 09:08:22 -07003432 if (hw->swfwhw_semaphore_present) {
3433 e1000_release_software_flag(hw);
3434 return;
3435 }
3436
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003437 if (!hw->swfw_sync_present) {
3438 e1000_put_hw_eeprom_semaphore(hw);
3439 return;
3440 }
3441
3442 /* if (e1000_get_hw_eeprom_semaphore(hw))
3443 * return -E1000_ERR_SWFW_SYNC; */
3444 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3445 /* empty */
3446
3447 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3448 swfw_sync &= ~swmask;
3449 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3450
3451 e1000_put_hw_eeprom_semaphore(hw);
3452}
3453
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454/*****************************************************************************
3455* Reads the value from a PHY register, if the value is on a specific non zero
3456* page, sets the page first.
3457* hw - Struct containing variables accessed by shared code
3458* reg_addr - address of the PHY register to read
3459******************************************************************************/
3460int32_t
3461e1000_read_phy_reg(struct e1000_hw *hw,
3462 uint32_t reg_addr,
3463 uint16_t *phy_data)
3464{
3465 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003466 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467
3468 DEBUGFUNC("e1000_read_phy_reg");
3469
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003470 if ((hw->mac_type == e1000_80003es2lan) &&
3471 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3472 swfw = E1000_SWFW_PHY1_SM;
3473 } else {
3474 swfw = E1000_SWFW_PHY0_SM;
3475 }
3476 if (e1000_swfw_sync_acquire(hw, swfw))
3477 return -E1000_ERR_SWFW_SYNC;
3478
Auke Kokcd94dd02006-06-27 09:08:22 -07003479 if ((hw->phy_type == e1000_phy_igp ||
3480 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003481 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3483 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3484 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003485 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003486 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 return ret_val;
3488 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003489 } else if (hw->phy_type == e1000_phy_gg82563) {
3490 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3491 (hw->mac_type == e1000_80003es2lan)) {
3492 /* Select Configuration Page */
3493 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3494 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3495 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3496 } else {
3497 /* Use Alternative Page Select register to access
3498 * registers 30 and 31
3499 */
3500 ret_val = e1000_write_phy_reg_ex(hw,
3501 GG82563_PHY_PAGE_SELECT_ALT,
3502 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3503 }
3504
3505 if (ret_val) {
3506 e1000_swfw_sync_release(hw, swfw);
3507 return ret_val;
3508 }
3509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 }
3511
3512 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3513 phy_data);
3514
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003515 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 return ret_val;
3517}
3518
Nicholas Nunley35574762006-09-27 12:53:34 -07003519static int32_t
3520e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 uint16_t *phy_data)
3522{
3523 uint32_t i;
3524 uint32_t mdic = 0;
3525 const uint32_t phy_addr = 1;
3526
3527 DEBUGFUNC("e1000_read_phy_reg_ex");
3528
Auke Kok8fc897b2006-08-28 14:56:16 -07003529 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3531 return -E1000_ERR_PARAM;
3532 }
3533
Auke Kok8fc897b2006-08-28 14:56:16 -07003534 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 /* Set up Op-code, Phy Address, and register address in the MDI
3536 * Control register. The MAC will take care of interfacing with the
3537 * PHY to retrieve the desired data.
3538 */
3539 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3540 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3541 (E1000_MDIC_OP_READ));
3542
3543 E1000_WRITE_REG(hw, MDIC, mdic);
3544
3545 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003546 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 udelay(50);
3548 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003549 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003551 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 DEBUGOUT("MDI Read did not complete\n");
3553 return -E1000_ERR_PHY;
3554 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003555 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 DEBUGOUT("MDI Error\n");
3557 return -E1000_ERR_PHY;
3558 }
3559 *phy_data = (uint16_t) mdic;
3560 } else {
3561 /* We must first send a preamble through the MDIO pin to signal the
3562 * beginning of an MII instruction. This is done by sending 32
3563 * consecutive "1" bits.
3564 */
3565 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3566
3567 /* Now combine the next few fields that are required for a read
3568 * operation. We use this method instead of calling the
3569 * e1000_shift_out_mdi_bits routine five different times. The format of
3570 * a MII read instruction consists of a shift out of 14 bits and is
3571 * defined as follows:
3572 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3573 * followed by a shift in of 18 bits. This first two bits shifted in
3574 * are TurnAround bits used to avoid contention on the MDIO pin when a
3575 * READ operation is performed. These two bits are thrown away
3576 * followed by a shift in of 16 bits which contains the desired data.
3577 */
3578 mdic = ((reg_addr) | (phy_addr << 5) |
3579 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3580
3581 e1000_shift_out_mdi_bits(hw, mdic, 14);
3582
3583 /* Now that we've shifted out the read command to the MII, we need to
3584 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3585 * register address.
3586 */
3587 *phy_data = e1000_shift_in_mdi_bits(hw);
3588 }
3589 return E1000_SUCCESS;
3590}
3591
3592/******************************************************************************
3593* Writes a value to a PHY register
3594*
3595* hw - Struct containing variables accessed by shared code
3596* reg_addr - address of the PHY register to write
3597* data - data to write to the PHY
3598******************************************************************************/
3599int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003600e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 uint16_t phy_data)
3602{
3603 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003604 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
3606 DEBUGFUNC("e1000_write_phy_reg");
3607
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003608 if ((hw->mac_type == e1000_80003es2lan) &&
3609 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3610 swfw = E1000_SWFW_PHY1_SM;
3611 } else {
3612 swfw = E1000_SWFW_PHY0_SM;
3613 }
3614 if (e1000_swfw_sync_acquire(hw, swfw))
3615 return -E1000_ERR_SWFW_SYNC;
3616
Auke Kokcd94dd02006-06-27 09:08:22 -07003617 if ((hw->phy_type == e1000_phy_igp ||
3618 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003619 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3621 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3622 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003623 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003624 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 return ret_val;
3626 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003627 } else if (hw->phy_type == e1000_phy_gg82563) {
3628 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3629 (hw->mac_type == e1000_80003es2lan)) {
3630 /* Select Configuration Page */
3631 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3632 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3633 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3634 } else {
3635 /* Use Alternative Page Select register to access
3636 * registers 30 and 31
3637 */
3638 ret_val = e1000_write_phy_reg_ex(hw,
3639 GG82563_PHY_PAGE_SELECT_ALT,
3640 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3641 }
3642
3643 if (ret_val) {
3644 e1000_swfw_sync_release(hw, swfw);
3645 return ret_val;
3646 }
3647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 }
3649
3650 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3651 phy_data);
3652
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003653 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 return ret_val;
3655}
3656
Nicholas Nunley35574762006-09-27 12:53:34 -07003657static int32_t
3658e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3659 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660{
3661 uint32_t i;
3662 uint32_t mdic = 0;
3663 const uint32_t phy_addr = 1;
3664
3665 DEBUGFUNC("e1000_write_phy_reg_ex");
3666
Auke Kok8fc897b2006-08-28 14:56:16 -07003667 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3669 return -E1000_ERR_PARAM;
3670 }
3671
Auke Kok8fc897b2006-08-28 14:56:16 -07003672 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 /* Set up Op-code, Phy Address, register address, and data intended
3674 * for the PHY register in the MDI Control register. The MAC will take
3675 * care of interfacing with the PHY to send the desired data.
3676 */
3677 mdic = (((uint32_t) phy_data) |
3678 (reg_addr << E1000_MDIC_REG_SHIFT) |
3679 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3680 (E1000_MDIC_OP_WRITE));
3681
3682 E1000_WRITE_REG(hw, MDIC, mdic);
3683
3684 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003685 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 udelay(5);
3687 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003688 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003690 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 DEBUGOUT("MDI Write did not complete\n");
3692 return -E1000_ERR_PHY;
3693 }
3694 } else {
3695 /* We'll need to use the SW defined pins to shift the write command
3696 * out to the PHY. We first send a preamble to the PHY to signal the
3697 * beginning of the MII instruction. This is done by sending 32
3698 * consecutive "1" bits.
3699 */
3700 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3701
3702 /* Now combine the remaining required fields that will indicate a
3703 * write operation. We use this method instead of calling the
3704 * e1000_shift_out_mdi_bits routine for each field in the command. The
3705 * format of a MII write instruction is as follows:
3706 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3707 */
3708 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3709 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3710 mdic <<= 16;
3711 mdic |= (uint32_t) phy_data;
3712
3713 e1000_shift_out_mdi_bits(hw, mdic, 32);
3714 }
3715
3716 return E1000_SUCCESS;
3717}
3718
Adrian Bunke4c780b2006-08-14 23:00:10 -07003719static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003720e1000_read_kmrn_reg(struct e1000_hw *hw,
3721 uint32_t reg_addr,
3722 uint16_t *data)
3723{
3724 uint32_t reg_val;
3725 uint16_t swfw;
3726 DEBUGFUNC("e1000_read_kmrn_reg");
3727
3728 if ((hw->mac_type == e1000_80003es2lan) &&
3729 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3730 swfw = E1000_SWFW_PHY1_SM;
3731 } else {
3732 swfw = E1000_SWFW_PHY0_SM;
3733 }
3734 if (e1000_swfw_sync_acquire(hw, swfw))
3735 return -E1000_ERR_SWFW_SYNC;
3736
3737 /* Write register address */
3738 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3739 E1000_KUMCTRLSTA_OFFSET) |
3740 E1000_KUMCTRLSTA_REN;
3741 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3742 udelay(2);
3743
3744 /* Read the data returned */
3745 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3746 *data = (uint16_t)reg_val;
3747
3748 e1000_swfw_sync_release(hw, swfw);
3749 return E1000_SUCCESS;
3750}
3751
Adrian Bunke4c780b2006-08-14 23:00:10 -07003752static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003753e1000_write_kmrn_reg(struct e1000_hw *hw,
3754 uint32_t reg_addr,
3755 uint16_t data)
3756{
3757 uint32_t reg_val;
3758 uint16_t swfw;
3759 DEBUGFUNC("e1000_write_kmrn_reg");
3760
3761 if ((hw->mac_type == e1000_80003es2lan) &&
3762 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3763 swfw = E1000_SWFW_PHY1_SM;
3764 } else {
3765 swfw = E1000_SWFW_PHY0_SM;
3766 }
3767 if (e1000_swfw_sync_acquire(hw, swfw))
3768 return -E1000_ERR_SWFW_SYNC;
3769
3770 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3771 E1000_KUMCTRLSTA_OFFSET) | data;
3772 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3773 udelay(2);
3774
3775 e1000_swfw_sync_release(hw, swfw);
3776 return E1000_SUCCESS;
3777}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003778
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779/******************************************************************************
3780* Returns the PHY to the power-on reset state
3781*
3782* hw - Struct containing variables accessed by shared code
3783******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003784int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785e1000_phy_hw_reset(struct e1000_hw *hw)
3786{
3787 uint32_t ctrl, ctrl_ext;
3788 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003789 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003790 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
3792 DEBUGFUNC("e1000_phy_hw_reset");
3793
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003794 /* In the case of the phy reset being blocked, it's not an error, we
3795 * simply return success without performing the reset. */
3796 ret_val = e1000_check_phy_reset_block(hw);
3797 if (ret_val)
3798 return E1000_SUCCESS;
3799
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 DEBUGOUT("Resetting Phy...\n");
3801
Auke Kok8fc897b2006-08-28 14:56:16 -07003802 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003803 if ((hw->mac_type == e1000_80003es2lan) &&
3804 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3805 swfw = E1000_SWFW_PHY1_SM;
3806 } else {
3807 swfw = E1000_SWFW_PHY0_SM;
3808 }
3809 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003810 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003811 return -E1000_ERR_SWFW_SYNC;
3812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3814 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003815 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003816 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003817 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 */
3819 ctrl = E1000_READ_REG(hw, CTRL);
3820 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3821 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003822
3823 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003824 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003825 else
3826 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003827
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 E1000_WRITE_REG(hw, CTRL, ctrl);
3829 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003830
Jeff Kirsherfd803242005-12-13 00:06:22 -05003831 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003832 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003833
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003834 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 } else {
3836 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3837 * bit to put the PHY into reset. Then, take it out of reset.
3838 */
3839 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3840 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3841 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3842 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3843 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003844 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3846 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3847 E1000_WRITE_FLUSH(hw);
3848 }
3849 udelay(150);
3850
Auke Kok8fc897b2006-08-28 14:56:16 -07003851 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 /* Configure activity LED after PHY reset */
3853 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3854 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3855 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3856 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3857 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003858
3859 /* Wait for FW to finish PHY configuration. */
3860 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003861 if (ret_val != E1000_SUCCESS)
3862 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003863 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003864
Auke Kok8fc897b2006-08-28 14:56:16 -07003865 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3866 ret_val = e1000_init_lcd_from_nvm(hw);
3867
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003868 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869}
3870
3871/******************************************************************************
3872* Resets the PHY
3873*
3874* hw - Struct containing variables accessed by shared code
3875*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003876* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877******************************************************************************/
3878int32_t
3879e1000_phy_reset(struct e1000_hw *hw)
3880{
3881 int32_t ret_val;
3882 uint16_t phy_data;
3883
3884 DEBUGFUNC("e1000_phy_reset");
3885
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003886 /* In the case of the phy reset being blocked, it's not an error, we
3887 * simply return success without performing the reset. */
3888 ret_val = e1000_check_phy_reset_block(hw);
3889 if (ret_val)
3890 return E1000_SUCCESS;
3891
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003892 switch (hw->phy_type) {
3893 case e1000_phy_igp:
3894 case e1000_phy_igp_2:
3895 case e1000_phy_igp_3:
3896 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003897 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003898 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003899 return ret_val;
3900 break;
3901 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003903 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 return ret_val;
3905
3906 phy_data |= MII_CR_RESET;
3907 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003908 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 return ret_val;
3910
3911 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003912 break;
3913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914
Auke Kok8fc897b2006-08-28 14:56:16 -07003915 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 e1000_phy_init_script(hw);
3917
3918 return E1000_SUCCESS;
3919}
3920
3921/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003922* Work-around for 82566 power-down: on D3 entry-
3923* 1) disable gigabit link
3924* 2) write VR power-down enable
3925* 3) read it back
3926* if successful continue, else issue LCD reset and repeat
3927*
3928* hw - struct containing variables accessed by shared code
3929******************************************************************************/
3930void
3931e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3932{
3933 int32_t reg;
3934 uint16_t phy_data;
3935 int32_t retry = 0;
3936
3937 DEBUGFUNC("e1000_phy_powerdown_workaround");
3938
3939 if (hw->phy_type != e1000_phy_igp_3)
3940 return;
3941
3942 do {
3943 /* Disable link */
3944 reg = E1000_READ_REG(hw, PHY_CTRL);
3945 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3946 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3947
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003948 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003949 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003950 phy_data |= (1 << 9);
3951 phy_data &= ~(1 << 8);
3952 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003953
3954 /* Read it back and test */
3955 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003956 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003957 break;
3958
3959 /* Issue PHY reset and repeat at most one more time */
3960 reg = E1000_READ_REG(hw, CTRL);
3961 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3962 retry++;
3963 } while (retry);
3964
3965 return;
3966
3967}
3968
3969/******************************************************************************
3970* Work-around for 82566 Kumeran PCS lock loss:
3971* On link status change (i.e. PCI reset, speed change) and link is up and
3972* speed is gigabit-
3973* 0) if workaround is optionally disabled do nothing
3974* 1) wait 1ms for Kumeran link to come up
3975* 2) check Kumeran Diagnostic register PCS lock loss bit
3976* 3) if not set the link is locked (all is good), otherwise...
3977* 4) reset the PHY
3978* 5) repeat up to 10 times
3979* Note: this is only called for IGP3 copper when speed is 1gb.
3980*
3981* hw - struct containing variables accessed by shared code
3982******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003983static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003984e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3985{
3986 int32_t ret_val;
3987 int32_t reg;
3988 int32_t cnt;
3989 uint16_t phy_data;
3990
3991 if (hw->kmrn_lock_loss_workaround_disabled)
3992 return E1000_SUCCESS;
3993
Auke Kok8fc897b2006-08-28 14:56:16 -07003994 /* Make sure link is up before proceeding. If not just return.
3995 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003996 * stability */
3997 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3998 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3999
4000 if (phy_data & MII_SR_LINK_STATUS) {
4001 for (cnt = 0; cnt < 10; cnt++) {
4002 /* read once to clear */
4003 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4004 if (ret_val)
4005 return ret_val;
4006 /* and again to get new status */
4007 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4008 if (ret_val)
4009 return ret_val;
4010
4011 /* check for PCS lock */
4012 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4013 return E1000_SUCCESS;
4014
4015 /* Issue PHY reset */
4016 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004017 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004018 }
4019 /* Disable GigE link negotiation */
4020 reg = E1000_READ_REG(hw, PHY_CTRL);
4021 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4022 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4023
4024 /* unable to acquire PCS lock */
4025 return E1000_ERR_PHY;
4026 }
4027
4028 return E1000_SUCCESS;
4029}
4030
4031/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032* Probes the expected PHY address for known PHY IDs
4033*
4034* hw - Struct containing variables accessed by shared code
4035******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004036static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037e1000_detect_gig_phy(struct e1000_hw *hw)
4038{
4039 int32_t phy_init_status, ret_val;
4040 uint16_t phy_id_high, phy_id_low;
4041 boolean_t match = FALSE;
4042
4043 DEBUGFUNC("e1000_detect_gig_phy");
4044
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004045 if (hw->phy_id != 0)
4046 return E1000_SUCCESS;
4047
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004048 /* The 82571 firmware may still be configuring the PHY. In this
4049 * case, we cannot access the PHY until the configuration is done. So
4050 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004051 if (hw->mac_type == e1000_82571 ||
4052 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004053 hw->phy_id = IGP01E1000_I_PHY_ID;
4054 hw->phy_type = e1000_phy_igp_2;
4055 return E1000_SUCCESS;
4056 }
4057
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004058 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4059 * around that forces PHY page 0 to be set or the reads fail. The rest of
4060 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4061 * So for ESB-2 we need to have this set so our reads won't fail. If the
4062 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4063 * this out as well. */
4064 if (hw->mac_type == e1000_80003es2lan)
4065 hw->phy_type = e1000_phy_gg82563;
4066
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 /* Read the PHY ID Registers to identify which PHY is onboard. */
4068 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004069 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 return ret_val;
4071
4072 hw->phy_id = (uint32_t) (phy_id_high << 16);
4073 udelay(20);
4074 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004075 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 return ret_val;
4077
4078 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4079 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4080
Auke Kok8fc897b2006-08-28 14:56:16 -07004081 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004083 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 break;
4085 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004086 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 break;
4088 case e1000_82540:
4089 case e1000_82545:
4090 case e1000_82545_rev_3:
4091 case e1000_82546:
4092 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004093 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 break;
4095 case e1000_82541:
4096 case e1000_82541_rev_2:
4097 case e1000_82547:
4098 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004099 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004101 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004102 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004103 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004104 case e1000_80003es2lan:
4105 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4106 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004107 case e1000_ich8lan:
4108 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4109 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4110 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4111 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4112 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 default:
4114 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4115 return -E1000_ERR_CONFIG;
4116 }
4117 phy_init_status = e1000_set_phy_type(hw);
4118
4119 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4120 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4121 return E1000_SUCCESS;
4122 }
4123 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4124 return -E1000_ERR_PHY;
4125}
4126
4127/******************************************************************************
4128* Resets the PHY's DSP
4129*
4130* hw - Struct containing variables accessed by shared code
4131******************************************************************************/
4132static int32_t
4133e1000_phy_reset_dsp(struct e1000_hw *hw)
4134{
4135 int32_t ret_val;
4136 DEBUGFUNC("e1000_phy_reset_dsp");
4137
4138 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004139 if (hw->phy_type != e1000_phy_gg82563) {
4140 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004141 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004144 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004146 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004148 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149
4150 return ret_val;
4151}
4152
4153/******************************************************************************
4154* Get PHY information from various PHY registers for igp PHY only.
4155*
4156* hw - Struct containing variables accessed by shared code
4157* phy_info - PHY information structure
4158******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004159static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160e1000_phy_igp_get_info(struct e1000_hw *hw,
4161 struct e1000_phy_info *phy_info)
4162{
4163 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004164 uint16_t phy_data, min_length, max_length, average;
4165 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
4167 DEBUGFUNC("e1000_phy_igp_get_info");
4168
4169 /* The downshift status is checked only once, after link is established,
4170 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004171 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172
4173 /* IGP01E1000 does not need to support it. */
4174 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4175
4176 /* IGP01E1000 always correct polarity reversal */
4177 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4178
4179 /* Check polarity status */
4180 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004181 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 return ret_val;
4183
4184 phy_info->cable_polarity = polarity;
4185
4186 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004187 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 return ret_val;
4189
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004190 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4191 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Auke Kok8fc897b2006-08-28 14:56:16 -07004193 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 IGP01E1000_PSSR_SPEED_1000MBPS) {
4195 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4196 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004197 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 return ret_val;
4199
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004200 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4201 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4202 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4203 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4204 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4205 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206
4207 /* Get cable length */
4208 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004209 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 return ret_val;
4211
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004212 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 average = (max_length + min_length) / 2;
4214
Auke Kok8fc897b2006-08-28 14:56:16 -07004215 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004217 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004219 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004221 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 phy_info->cable_length = e1000_cable_length_110_140;
4223 else
4224 phy_info->cable_length = e1000_cable_length_140;
4225 }
4226
4227 return E1000_SUCCESS;
4228}
4229
4230/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004231* Get PHY information from various PHY registers for ife PHY only.
4232*
4233* hw - Struct containing variables accessed by shared code
4234* phy_info - PHY information structure
4235******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004236static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004237e1000_phy_ife_get_info(struct e1000_hw *hw,
4238 struct e1000_phy_info *phy_info)
4239{
4240 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004241 uint16_t phy_data;
4242 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004243
4244 DEBUGFUNC("e1000_phy_ife_get_info");
4245
4246 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4247 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4248
4249 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4250 if (ret_val)
4251 return ret_val;
4252 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004253 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4254 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4255 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004256
4257 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4258 ret_val = e1000_check_polarity(hw, &polarity);
4259 if (ret_val)
4260 return ret_val;
4261 } else {
4262 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004263 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4264 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4265 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004266 }
4267 phy_info->cable_polarity = polarity;
4268
4269 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4270 if (ret_val)
4271 return ret_val;
4272
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004273 phy_info->mdix_mode = (e1000_auto_x_mode)
4274 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4275 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004276
4277 return E1000_SUCCESS;
4278}
4279
4280/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281* Get PHY information from various PHY registers fot m88 PHY only.
4282*
4283* hw - Struct containing variables accessed by shared code
4284* phy_info - PHY information structure
4285******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004286static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287e1000_phy_m88_get_info(struct e1000_hw *hw,
4288 struct e1000_phy_info *phy_info)
4289{
4290 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004291 uint16_t phy_data;
4292 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293
4294 DEBUGFUNC("e1000_phy_m88_get_info");
4295
4296 /* The downshift status is checked only once, after link is established,
4297 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004298 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299
4300 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004301 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 return ret_val;
4303
4304 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004305 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4306 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4307 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4308
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004310 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4311 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4312 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313
4314 /* Check polarity status */
4315 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004316 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004317 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 phy_info->cable_polarity = polarity;
4319
4320 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004321 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 return ret_val;
4323
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004324 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4325 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326
4327 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4328 /* Cable Length Estimation and Local/Remote Receiver Information
4329 * are only valid at 1000 Mbps.
4330 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004331 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004332 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004333 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4334 } else {
4335 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4336 &phy_data);
4337 if (ret_val)
4338 return ret_val;
4339
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004340 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342
4343 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004344 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 return ret_val;
4346
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004347 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4348 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4349 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4350 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4351 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4352 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 }
4355
4356 return E1000_SUCCESS;
4357}
4358
4359/******************************************************************************
4360* Get PHY information from various PHY registers
4361*
4362* hw - Struct containing variables accessed by shared code
4363* phy_info - PHY information structure
4364******************************************************************************/
4365int32_t
4366e1000_phy_get_info(struct e1000_hw *hw,
4367 struct e1000_phy_info *phy_info)
4368{
4369 int32_t ret_val;
4370 uint16_t phy_data;
4371
4372 DEBUGFUNC("e1000_phy_get_info");
4373
4374 phy_info->cable_length = e1000_cable_length_undefined;
4375 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4376 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4377 phy_info->downshift = e1000_downshift_undefined;
4378 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4379 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4380 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4381 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4382
Auke Kok8fc897b2006-08-28 14:56:16 -07004383 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 DEBUGOUT("PHY info is only valid for copper media\n");
4385 return -E1000_ERR_CONFIG;
4386 }
4387
4388 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004389 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 return ret_val;
4391
4392 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004393 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 return ret_val;
4395
Auke Kok8fc897b2006-08-28 14:56:16 -07004396 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 DEBUGOUT("PHY info is only valid if link is up\n");
4398 return -E1000_ERR_CONFIG;
4399 }
4400
Auke Kokcd94dd02006-06-27 09:08:22 -07004401 if (hw->phy_type == e1000_phy_igp ||
4402 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004403 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004405 else if (hw->phy_type == e1000_phy_ife)
4406 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 else
4408 return e1000_phy_m88_get_info(hw, phy_info);
4409}
4410
4411int32_t
4412e1000_validate_mdi_setting(struct e1000_hw *hw)
4413{
4414 DEBUGFUNC("e1000_validate_mdi_settings");
4415
Auke Kok8fc897b2006-08-28 14:56:16 -07004416 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 DEBUGOUT("Invalid MDI setting detected\n");
4418 hw->mdix = 1;
4419 return -E1000_ERR_CONFIG;
4420 }
4421 return E1000_SUCCESS;
4422}
4423
4424
4425/******************************************************************************
4426 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004427 * is configured. Additionally, if this is ICH8, the flash controller GbE
4428 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 *
4430 * hw - Struct containing variables accessed by shared code
4431 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004432int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433e1000_init_eeprom_params(struct e1000_hw *hw)
4434{
4435 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4436 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004437 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 uint16_t eeprom_size;
4439
4440 DEBUGFUNC("e1000_init_eeprom_params");
4441
4442 switch (hw->mac_type) {
4443 case e1000_82542_rev2_0:
4444 case e1000_82542_rev2_1:
4445 case e1000_82543:
4446 case e1000_82544:
4447 eeprom->type = e1000_eeprom_microwire;
4448 eeprom->word_size = 64;
4449 eeprom->opcode_bits = 3;
4450 eeprom->address_bits = 6;
4451 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004452 eeprom->use_eerd = FALSE;
4453 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 break;
4455 case e1000_82540:
4456 case e1000_82545:
4457 case e1000_82545_rev_3:
4458 case e1000_82546:
4459 case e1000_82546_rev_3:
4460 eeprom->type = e1000_eeprom_microwire;
4461 eeprom->opcode_bits = 3;
4462 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004463 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 eeprom->word_size = 256;
4465 eeprom->address_bits = 8;
4466 } else {
4467 eeprom->word_size = 64;
4468 eeprom->address_bits = 6;
4469 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004470 eeprom->use_eerd = FALSE;
4471 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 break;
4473 case e1000_82541:
4474 case e1000_82541_rev_2:
4475 case e1000_82547:
4476 case e1000_82547_rev_2:
4477 if (eecd & E1000_EECD_TYPE) {
4478 eeprom->type = e1000_eeprom_spi;
4479 eeprom->opcode_bits = 8;
4480 eeprom->delay_usec = 1;
4481 if (eecd & E1000_EECD_ADDR_BITS) {
4482 eeprom->page_size = 32;
4483 eeprom->address_bits = 16;
4484 } else {
4485 eeprom->page_size = 8;
4486 eeprom->address_bits = 8;
4487 }
4488 } else {
4489 eeprom->type = e1000_eeprom_microwire;
4490 eeprom->opcode_bits = 3;
4491 eeprom->delay_usec = 50;
4492 if (eecd & E1000_EECD_ADDR_BITS) {
4493 eeprom->word_size = 256;
4494 eeprom->address_bits = 8;
4495 } else {
4496 eeprom->word_size = 64;
4497 eeprom->address_bits = 6;
4498 }
4499 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004500 eeprom->use_eerd = FALSE;
4501 eeprom->use_eewr = FALSE;
4502 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004503 case e1000_82571:
4504 case e1000_82572:
4505 eeprom->type = e1000_eeprom_spi;
4506 eeprom->opcode_bits = 8;
4507 eeprom->delay_usec = 1;
4508 if (eecd & E1000_EECD_ADDR_BITS) {
4509 eeprom->page_size = 32;
4510 eeprom->address_bits = 16;
4511 } else {
4512 eeprom->page_size = 8;
4513 eeprom->address_bits = 8;
4514 }
4515 eeprom->use_eerd = FALSE;
4516 eeprom->use_eewr = FALSE;
4517 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004518 case e1000_82573:
4519 eeprom->type = e1000_eeprom_spi;
4520 eeprom->opcode_bits = 8;
4521 eeprom->delay_usec = 1;
4522 if (eecd & E1000_EECD_ADDR_BITS) {
4523 eeprom->page_size = 32;
4524 eeprom->address_bits = 16;
4525 } else {
4526 eeprom->page_size = 8;
4527 eeprom->address_bits = 8;
4528 }
4529 eeprom->use_eerd = TRUE;
4530 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004531 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004532 eeprom->type = e1000_eeprom_flash;
4533 eeprom->word_size = 2048;
4534
4535 /* Ensure that the Autonomous FLASH update bit is cleared due to
4536 * Flash update issue on parts which use a FLASH for NVM. */
4537 eecd &= ~E1000_EECD_AUPDEN;
4538 E1000_WRITE_REG(hw, EECD, eecd);
4539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004541 case e1000_80003es2lan:
4542 eeprom->type = e1000_eeprom_spi;
4543 eeprom->opcode_bits = 8;
4544 eeprom->delay_usec = 1;
4545 if (eecd & E1000_EECD_ADDR_BITS) {
4546 eeprom->page_size = 32;
4547 eeprom->address_bits = 16;
4548 } else {
4549 eeprom->page_size = 8;
4550 eeprom->address_bits = 8;
4551 }
4552 eeprom->use_eerd = TRUE;
4553 eeprom->use_eewr = FALSE;
4554 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004555 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004556 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004557 int32_t i = 0;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004558 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
Auke Kokcd94dd02006-06-27 09:08:22 -07004559
4560 eeprom->type = e1000_eeprom_ich8;
4561 eeprom->use_eerd = FALSE;
4562 eeprom->use_eewr = FALSE;
4563 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4564
4565 /* Zero the shadow RAM structure. But don't load it from NVM
4566 * so as to save time for driver init */
4567 if (hw->eeprom_shadow_ram != NULL) {
4568 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4569 hw->eeprom_shadow_ram[i].modified = FALSE;
4570 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4571 }
4572 }
4573
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004574 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4575 ICH_FLASH_SECTOR_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -07004576
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004577 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4578 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4579
4580 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4581
Auke Kokcd94dd02006-06-27 09:08:22 -07004582 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4583
4584 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 default:
4587 break;
4588 }
4589
4590 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004591 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4592 * 32KB (incremented by powers of 2).
4593 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004594 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004595 /* Set to default value for initial eeprom read. */
4596 eeprom->word_size = 64;
4597 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004598 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004599 return ret_val;
4600 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4601 /* 256B eeprom size was not supported in earlier hardware, so we
4602 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4603 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004604 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004605 eeprom_size++;
4606 } else {
4607 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4608 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004610
4611 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004613 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614}
4615
4616/******************************************************************************
4617 * Raises the EEPROM's clock input.
4618 *
4619 * hw - Struct containing variables accessed by shared code
4620 * eecd - EECD's current value
4621 *****************************************************************************/
4622static void
4623e1000_raise_ee_clk(struct e1000_hw *hw,
4624 uint32_t *eecd)
4625{
4626 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4627 * wait <delay> microseconds.
4628 */
4629 *eecd = *eecd | E1000_EECD_SK;
4630 E1000_WRITE_REG(hw, EECD, *eecd);
4631 E1000_WRITE_FLUSH(hw);
4632 udelay(hw->eeprom.delay_usec);
4633}
4634
4635/******************************************************************************
4636 * Lowers the EEPROM's clock input.
4637 *
4638 * hw - Struct containing variables accessed by shared code
4639 * eecd - EECD's current value
4640 *****************************************************************************/
4641static void
4642e1000_lower_ee_clk(struct e1000_hw *hw,
4643 uint32_t *eecd)
4644{
4645 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4646 * wait 50 microseconds.
4647 */
4648 *eecd = *eecd & ~E1000_EECD_SK;
4649 E1000_WRITE_REG(hw, EECD, *eecd);
4650 E1000_WRITE_FLUSH(hw);
4651 udelay(hw->eeprom.delay_usec);
4652}
4653
4654/******************************************************************************
4655 * Shift data bits out to the EEPROM.
4656 *
4657 * hw - Struct containing variables accessed by shared code
4658 * data - data to send to the EEPROM
4659 * count - number of bits to shift out
4660 *****************************************************************************/
4661static void
4662e1000_shift_out_ee_bits(struct e1000_hw *hw,
4663 uint16_t data,
4664 uint16_t count)
4665{
4666 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4667 uint32_t eecd;
4668 uint32_t mask;
4669
4670 /* We need to shift "count" bits out to the EEPROM. So, value in the
4671 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4672 * In order to do this, "data" must be broken down into bits.
4673 */
4674 mask = 0x01 << (count - 1);
4675 eecd = E1000_READ_REG(hw, EECD);
4676 if (eeprom->type == e1000_eeprom_microwire) {
4677 eecd &= ~E1000_EECD_DO;
4678 } else if (eeprom->type == e1000_eeprom_spi) {
4679 eecd |= E1000_EECD_DO;
4680 }
4681 do {
4682 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4683 * and then raising and then lowering the clock (the SK bit controls
4684 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4685 * by setting "DI" to "0" and then raising and then lowering the clock.
4686 */
4687 eecd &= ~E1000_EECD_DI;
4688
Auke Kok8fc897b2006-08-28 14:56:16 -07004689 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690 eecd |= E1000_EECD_DI;
4691
4692 E1000_WRITE_REG(hw, EECD, eecd);
4693 E1000_WRITE_FLUSH(hw);
4694
4695 udelay(eeprom->delay_usec);
4696
4697 e1000_raise_ee_clk(hw, &eecd);
4698 e1000_lower_ee_clk(hw, &eecd);
4699
4700 mask = mask >> 1;
4701
Auke Kok8fc897b2006-08-28 14:56:16 -07004702 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703
4704 /* We leave the "DI" bit set to "0" when we leave this routine. */
4705 eecd &= ~E1000_EECD_DI;
4706 E1000_WRITE_REG(hw, EECD, eecd);
4707}
4708
4709/******************************************************************************
4710 * Shift data bits in from the EEPROM
4711 *
4712 * hw - Struct containing variables accessed by shared code
4713 *****************************************************************************/
4714static uint16_t
4715e1000_shift_in_ee_bits(struct e1000_hw *hw,
4716 uint16_t count)
4717{
4718 uint32_t eecd;
4719 uint32_t i;
4720 uint16_t data;
4721
4722 /* In order to read a register from the EEPROM, we need to shift 'count'
4723 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4724 * input to the EEPROM (setting the SK bit), and then reading the value of
4725 * the "DO" bit. During this "shifting in" process the "DI" bit should
4726 * always be clear.
4727 */
4728
4729 eecd = E1000_READ_REG(hw, EECD);
4730
4731 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4732 data = 0;
4733
Auke Kok8fc897b2006-08-28 14:56:16 -07004734 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 data = data << 1;
4736 e1000_raise_ee_clk(hw, &eecd);
4737
4738 eecd = E1000_READ_REG(hw, EECD);
4739
4740 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004741 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 data |= 1;
4743
4744 e1000_lower_ee_clk(hw, &eecd);
4745 }
4746
4747 return data;
4748}
4749
4750/******************************************************************************
4751 * Prepares EEPROM for access
4752 *
4753 * hw - Struct containing variables accessed by shared code
4754 *
4755 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4756 * function should be called before issuing a command to the EEPROM.
4757 *****************************************************************************/
4758static int32_t
4759e1000_acquire_eeprom(struct e1000_hw *hw)
4760{
4761 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4762 uint32_t eecd, i=0;
4763
4764 DEBUGFUNC("e1000_acquire_eeprom");
4765
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004766 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4767 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 eecd = E1000_READ_REG(hw, EECD);
4769
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004770 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004771 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004772 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004773 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004775 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004776 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004777 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4778 i++;
4779 udelay(5);
4780 eecd = E1000_READ_REG(hw, EECD);
4781 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004782 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004783 eecd &= ~E1000_EECD_REQ;
4784 E1000_WRITE_REG(hw, EECD, eecd);
4785 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004786 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004787 return -E1000_ERR_EEPROM;
4788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 }
4790 }
4791
4792 /* Setup EEPROM for Read/Write */
4793
4794 if (eeprom->type == e1000_eeprom_microwire) {
4795 /* Clear SK and DI */
4796 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4797 E1000_WRITE_REG(hw, EECD, eecd);
4798
4799 /* Set CS */
4800 eecd |= E1000_EECD_CS;
4801 E1000_WRITE_REG(hw, EECD, eecd);
4802 } else if (eeprom->type == e1000_eeprom_spi) {
4803 /* Clear SK and CS */
4804 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4805 E1000_WRITE_REG(hw, EECD, eecd);
4806 udelay(1);
4807 }
4808
4809 return E1000_SUCCESS;
4810}
4811
4812/******************************************************************************
4813 * Returns EEPROM to a "standby" state
4814 *
4815 * hw - Struct containing variables accessed by shared code
4816 *****************************************************************************/
4817static void
4818e1000_standby_eeprom(struct e1000_hw *hw)
4819{
4820 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4821 uint32_t eecd;
4822
4823 eecd = E1000_READ_REG(hw, EECD);
4824
Auke Kok8fc897b2006-08-28 14:56:16 -07004825 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4827 E1000_WRITE_REG(hw, EECD, eecd);
4828 E1000_WRITE_FLUSH(hw);
4829 udelay(eeprom->delay_usec);
4830
4831 /* Clock high */
4832 eecd |= E1000_EECD_SK;
4833 E1000_WRITE_REG(hw, EECD, eecd);
4834 E1000_WRITE_FLUSH(hw);
4835 udelay(eeprom->delay_usec);
4836
4837 /* Select EEPROM */
4838 eecd |= E1000_EECD_CS;
4839 E1000_WRITE_REG(hw, EECD, eecd);
4840 E1000_WRITE_FLUSH(hw);
4841 udelay(eeprom->delay_usec);
4842
4843 /* Clock low */
4844 eecd &= ~E1000_EECD_SK;
4845 E1000_WRITE_REG(hw, EECD, eecd);
4846 E1000_WRITE_FLUSH(hw);
4847 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004848 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 /* Toggle CS to flush commands */
4850 eecd |= E1000_EECD_CS;
4851 E1000_WRITE_REG(hw, EECD, eecd);
4852 E1000_WRITE_FLUSH(hw);
4853 udelay(eeprom->delay_usec);
4854 eecd &= ~E1000_EECD_CS;
4855 E1000_WRITE_REG(hw, EECD, eecd);
4856 E1000_WRITE_FLUSH(hw);
4857 udelay(eeprom->delay_usec);
4858 }
4859}
4860
4861/******************************************************************************
4862 * Terminates a command by inverting the EEPROM's chip select pin
4863 *
4864 * hw - Struct containing variables accessed by shared code
4865 *****************************************************************************/
4866static void
4867e1000_release_eeprom(struct e1000_hw *hw)
4868{
4869 uint32_t eecd;
4870
4871 DEBUGFUNC("e1000_release_eeprom");
4872
4873 eecd = E1000_READ_REG(hw, EECD);
4874
4875 if (hw->eeprom.type == e1000_eeprom_spi) {
4876 eecd |= E1000_EECD_CS; /* Pull CS high */
4877 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4878
4879 E1000_WRITE_REG(hw, EECD, eecd);
4880
4881 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004882 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 /* cleanup eeprom */
4884
4885 /* CS on Microwire is active-high */
4886 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4887
4888 E1000_WRITE_REG(hw, EECD, eecd);
4889
4890 /* Rising edge of clock */
4891 eecd |= E1000_EECD_SK;
4892 E1000_WRITE_REG(hw, EECD, eecd);
4893 E1000_WRITE_FLUSH(hw);
4894 udelay(hw->eeprom.delay_usec);
4895
4896 /* Falling edge of clock */
4897 eecd &= ~E1000_EECD_SK;
4898 E1000_WRITE_REG(hw, EECD, eecd);
4899 E1000_WRITE_FLUSH(hw);
4900 udelay(hw->eeprom.delay_usec);
4901 }
4902
4903 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004904 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 eecd &= ~E1000_EECD_REQ;
4906 E1000_WRITE_REG(hw, EECD, eecd);
4907 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004908
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004909 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910}
4911
4912/******************************************************************************
4913 * Reads a 16 bit word from the EEPROM.
4914 *
4915 * hw - Struct containing variables accessed by shared code
4916 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004917static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918e1000_spi_eeprom_ready(struct e1000_hw *hw)
4919{
4920 uint16_t retry_count = 0;
4921 uint8_t spi_stat_reg;
4922
4923 DEBUGFUNC("e1000_spi_eeprom_ready");
4924
4925 /* Read "Status Register" repeatedly until the LSB is cleared. The
4926 * EEPROM will signal that the command has been completed by clearing
4927 * bit 0 of the internal status register. If it's not cleared within
4928 * 5 milliseconds, then error out.
4929 */
4930 retry_count = 0;
4931 do {
4932 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4933 hw->eeprom.opcode_bits);
4934 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4935 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4936 break;
4937
4938 udelay(5);
4939 retry_count += 5;
4940
4941 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004942 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943
4944 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4945 * only 0-5mSec on 5V devices)
4946 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004947 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 DEBUGOUT("SPI EEPROM Status error\n");
4949 return -E1000_ERR_EEPROM;
4950 }
4951
4952 return E1000_SUCCESS;
4953}
4954
4955/******************************************************************************
4956 * Reads a 16 bit word from the EEPROM.
4957 *
4958 * hw - Struct containing variables accessed by shared code
4959 * offset - offset of word in the EEPROM to read
4960 * data - word read from the EEPROM
4961 * words - number of words to read
4962 *****************************************************************************/
4963int32_t
4964e1000_read_eeprom(struct e1000_hw *hw,
4965 uint16_t offset,
4966 uint16_t words,
4967 uint16_t *data)
4968{
4969 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4970 uint32_t i = 0;
4971
4972 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004973
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004974 /* If eeprom is not yet detected, do so now */
4975 if (eeprom->word_size == 0)
4976 e1000_init_eeprom_params(hw);
4977
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 /* A check for invalid values: offset too large, too many words, and not
4979 * enough words.
4980 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004981 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004983 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 return -E1000_ERR_EEPROM;
4985 }
4986
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004987 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4988 * directly. In this case, we need to acquire the EEPROM so that
4989 * FW or other port software does not interrupt.
4990 */
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004991 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004992 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004993 /* Prepare the EEPROM for bit-bang reading */
4994 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4995 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004996 }
4997
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004998 /* Eerd register EEPROM access requires no eeprom aquire/release */
4999 if (eeprom->use_eerd == TRUE)
5000 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005002 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07005003 if (eeprom->type == e1000_eeprom_ich8)
5004 return e1000_read_eeprom_ich8(hw, offset, words, data);
5005
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005006 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5007 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07005008 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 uint16_t word_in;
5010 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5011
Auke Kok8fc897b2006-08-28 14:56:16 -07005012 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 e1000_release_eeprom(hw);
5014 return -E1000_ERR_EEPROM;
5015 }
5016
5017 e1000_standby_eeprom(hw);
5018
5019 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005020 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 read_opcode |= EEPROM_A8_OPCODE_SPI;
5022
5023 /* Send the READ command (opcode + addr) */
5024 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5025 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5026
5027 /* Read the data. The address of the eeprom internally increments with
5028 * each byte (spi) being read, saving on the overhead of eeprom setup
5029 * and tear-down. The address counter will roll over if reading beyond
5030 * the size of the eeprom, thus allowing the entire memory to be read
5031 * starting from any offset. */
5032 for (i = 0; i < words; i++) {
5033 word_in = e1000_shift_in_ee_bits(hw, 16);
5034 data[i] = (word_in >> 8) | (word_in << 8);
5035 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005036 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 for (i = 0; i < words; i++) {
5038 /* Send the READ command (opcode + addr) */
5039 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5040 eeprom->opcode_bits);
5041 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5042 eeprom->address_bits);
5043
5044 /* Read the data. For microwire, each word requires the overhead
5045 * of eeprom setup and tear-down. */
5046 data[i] = e1000_shift_in_ee_bits(hw, 16);
5047 e1000_standby_eeprom(hw);
5048 }
5049 }
5050
5051 /* End this read operation */
5052 e1000_release_eeprom(hw);
5053
5054 return E1000_SUCCESS;
5055}
5056
5057/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005058 * Reads a 16 bit word from the EEPROM using the EERD register.
5059 *
5060 * hw - Struct containing variables accessed by shared code
5061 * offset - offset of word in the EEPROM to read
5062 * data - word read from the EEPROM
5063 * words - number of words to read
5064 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005065static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005066e1000_read_eeprom_eerd(struct e1000_hw *hw,
5067 uint16_t offset,
5068 uint16_t words,
5069 uint16_t *data)
5070{
5071 uint32_t i, eerd = 0;
5072 int32_t error = 0;
5073
5074 for (i = 0; i < words; i++) {
5075 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5076 E1000_EEPROM_RW_REG_START;
5077
5078 E1000_WRITE_REG(hw, EERD, eerd);
5079 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005080
Auke Kok8fc897b2006-08-28 14:56:16 -07005081 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005082 break;
5083 }
5084 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005085
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005086 }
Auke Kok76c224b2006-05-23 13:36:06 -07005087
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005088 return error;
5089}
5090
5091/******************************************************************************
5092 * Writes a 16 bit word from the EEPROM using the EEWR register.
5093 *
5094 * hw - Struct containing variables accessed by shared code
5095 * offset - offset of word in the EEPROM to read
5096 * data - word read from the EEPROM
5097 * words - number of words to read
5098 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005099static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005100e1000_write_eeprom_eewr(struct e1000_hw *hw,
5101 uint16_t offset,
5102 uint16_t words,
5103 uint16_t *data)
5104{
5105 uint32_t register_value = 0;
5106 uint32_t i = 0;
5107 int32_t error = 0;
5108
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005109 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5110 return -E1000_ERR_SWFW_SYNC;
5111
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005112 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005113 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5114 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005115 E1000_EEPROM_RW_REG_START;
5116
5117 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005118 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005119 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005120 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005121
5122 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005123
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005124 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005125
Auke Kok8fc897b2006-08-28 14:56:16 -07005126 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005127 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005128 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005129 }
Auke Kok76c224b2006-05-23 13:36:06 -07005130
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005131 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005132 return error;
5133}
5134
5135/******************************************************************************
5136 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5137 *
5138 * hw - Struct containing variables accessed by shared code
5139 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005140static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005141e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5142{
5143 uint32_t attempts = 100000;
5144 uint32_t i, reg = 0;
5145 int32_t done = E1000_ERR_EEPROM;
5146
Auke Kok8fc897b2006-08-28 14:56:16 -07005147 for (i = 0; i < attempts; i++) {
5148 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005149 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005150 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005151 reg = E1000_READ_REG(hw, EEWR);
5152
Auke Kok8fc897b2006-08-28 14:56:16 -07005153 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005154 done = E1000_SUCCESS;
5155 break;
5156 }
5157 udelay(5);
5158 }
5159
5160 return done;
5161}
5162
5163/***************************************************************************
5164* Description: Determines if the onboard NVM is FLASH or EEPROM.
5165*
5166* hw - Struct containing variables accessed by shared code
5167****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005168static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005169e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5170{
5171 uint32_t eecd = 0;
5172
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005173 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5174
Auke Kokcd94dd02006-06-27 09:08:22 -07005175 if (hw->mac_type == e1000_ich8lan)
5176 return FALSE;
5177
5178 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005179 eecd = E1000_READ_REG(hw, EECD);
5180
5181 /* Isolate bits 15 & 16 */
5182 eecd = ((eecd >> 15) & 0x03);
5183
5184 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005185 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005186 return FALSE;
5187 }
5188 }
5189 return TRUE;
5190}
5191
5192/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193 * Verifies that the EEPROM has a valid checksum
5194 *
5195 * hw - Struct containing variables accessed by shared code
5196 *
5197 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5198 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5199 * valid.
5200 *****************************************************************************/
5201int32_t
5202e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5203{
5204 uint16_t checksum = 0;
5205 uint16_t i, eeprom_data;
5206
5207 DEBUGFUNC("e1000_validate_eeprom_checksum");
5208
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005209 if ((hw->mac_type == e1000_82573) &&
5210 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5211 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5212 * 10h-12h. Checksum may need to be fixed. */
5213 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5214 if ((eeprom_data & 0x10) == 0) {
5215 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5216 * has already been fixed. If the checksum is still wrong and this
5217 * bit is a 1, we need to return bad checksum. Otherwise, we need
5218 * to set this bit to a 1 and update the checksum. */
5219 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5220 if ((eeprom_data & 0x8000) == 0) {
5221 eeprom_data |= 0x8000;
5222 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5223 e1000_update_eeprom_checksum(hw);
5224 }
5225 }
5226 }
5227
Auke Kokcd94dd02006-06-27 09:08:22 -07005228 if (hw->mac_type == e1000_ich8lan) {
5229 /* Drivers must allocate the shadow ram structure for the
5230 * EEPROM checksum to be updated. Otherwise, this bit as well
5231 * as the checksum must both be set correctly for this
5232 * validation to pass.
5233 */
5234 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5235 if ((eeprom_data & 0x40) == 0) {
5236 eeprom_data |= 0x40;
5237 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5238 e1000_update_eeprom_checksum(hw);
5239 }
5240 }
5241
5242 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5243 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244 DEBUGOUT("EEPROM Read Error\n");
5245 return -E1000_ERR_EEPROM;
5246 }
5247 checksum += eeprom_data;
5248 }
5249
Auke Kok8fc897b2006-08-28 14:56:16 -07005250 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 return E1000_SUCCESS;
5252 else {
5253 DEBUGOUT("EEPROM Checksum Invalid\n");
5254 return -E1000_ERR_EEPROM;
5255 }
5256}
5257
5258/******************************************************************************
5259 * Calculates the EEPROM checksum and writes it to the EEPROM
5260 *
5261 * hw - Struct containing variables accessed by shared code
5262 *
5263 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5264 * Writes the difference to word offset 63 of the EEPROM.
5265 *****************************************************************************/
5266int32_t
5267e1000_update_eeprom_checksum(struct e1000_hw *hw)
5268{
Auke Kokcd94dd02006-06-27 09:08:22 -07005269 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 uint16_t checksum = 0;
5271 uint16_t i, eeprom_data;
5272
5273 DEBUGFUNC("e1000_update_eeprom_checksum");
5274
Auke Kok8fc897b2006-08-28 14:56:16 -07005275 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5276 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 DEBUGOUT("EEPROM Read Error\n");
5278 return -E1000_ERR_EEPROM;
5279 }
5280 checksum += eeprom_data;
5281 }
5282 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005283 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 DEBUGOUT("EEPROM Write Error\n");
5285 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005286 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5287 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005288 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5289 e1000_commit_shadow_ram(hw);
5290 /* Reload the EEPROM, or else modifications will not appear
5291 * until after next adapter reset. */
5292 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5293 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5294 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005295 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 }
5297 return E1000_SUCCESS;
5298}
5299
5300/******************************************************************************
5301 * Parent function for writing words to the different EEPROM types.
5302 *
5303 * hw - Struct containing variables accessed by shared code
5304 * offset - offset within the EEPROM to be written to
5305 * words - number of words to write
5306 * data - 16 bit word to be written to the EEPROM
5307 *
5308 * If e1000_update_eeprom_checksum is not called after this function, the
5309 * EEPROM will most likely contain an invalid checksum.
5310 *****************************************************************************/
5311int32_t
5312e1000_write_eeprom(struct e1000_hw *hw,
5313 uint16_t offset,
5314 uint16_t words,
5315 uint16_t *data)
5316{
5317 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5318 int32_t status = 0;
5319
5320 DEBUGFUNC("e1000_write_eeprom");
5321
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005322 /* If eeprom is not yet detected, do so now */
5323 if (eeprom->word_size == 0)
5324 e1000_init_eeprom_params(hw);
5325
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326 /* A check for invalid values: offset too large, too many words, and not
5327 * enough words.
5328 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005329 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 (words == 0)) {
5331 DEBUGOUT("\"words\" parameter out of bounds\n");
5332 return -E1000_ERR_EEPROM;
5333 }
5334
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005335 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005336 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005337 return e1000_write_eeprom_eewr(hw, offset, words, data);
5338
Auke Kokcd94dd02006-06-27 09:08:22 -07005339 if (eeprom->type == e1000_eeprom_ich8)
5340 return e1000_write_eeprom_ich8(hw, offset, words, data);
5341
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 /* Prepare the EEPROM for writing */
5343 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5344 return -E1000_ERR_EEPROM;
5345
Auke Kok8fc897b2006-08-28 14:56:16 -07005346 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5348 } else {
5349 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005350 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 }
5352
5353 /* Done with writing */
5354 e1000_release_eeprom(hw);
5355
5356 return status;
5357}
5358
5359/******************************************************************************
5360 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5361 *
5362 * hw - Struct containing variables accessed by shared code
5363 * offset - offset within the EEPROM to be written to
5364 * words - number of words to write
5365 * data - pointer to array of 8 bit words to be written to the EEPROM
5366 *
5367 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005368static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369e1000_write_eeprom_spi(struct e1000_hw *hw,
5370 uint16_t offset,
5371 uint16_t words,
5372 uint16_t *data)
5373{
5374 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5375 uint16_t widx = 0;
5376
5377 DEBUGFUNC("e1000_write_eeprom_spi");
5378
5379 while (widx < words) {
5380 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5381
Auke Kok8fc897b2006-08-28 14:56:16 -07005382 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383
5384 e1000_standby_eeprom(hw);
5385
5386 /* Send the WRITE ENABLE command (8 bit opcode ) */
5387 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5388 eeprom->opcode_bits);
5389
5390 e1000_standby_eeprom(hw);
5391
5392 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005393 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 write_opcode |= EEPROM_A8_OPCODE_SPI;
5395
5396 /* Send the Write command (8-bit opcode + addr) */
5397 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5398
5399 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5400 eeprom->address_bits);
5401
5402 /* Send the data */
5403
5404 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5405 while (widx < words) {
5406 uint16_t word_out = data[widx];
5407 word_out = (word_out >> 8) | (word_out << 8);
5408 e1000_shift_out_ee_bits(hw, word_out, 16);
5409 widx++;
5410
5411 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5412 * operation, while the smaller eeproms are capable of an 8-byte
5413 * PAGE WRITE operation. Break the inner loop to pass new address
5414 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005415 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416 e1000_standby_eeprom(hw);
5417 break;
5418 }
5419 }
5420 }
5421
5422 return E1000_SUCCESS;
5423}
5424
5425/******************************************************************************
5426 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5427 *
5428 * hw - Struct containing variables accessed by shared code
5429 * offset - offset within the EEPROM to be written to
5430 * words - number of words to write
5431 * data - pointer to array of 16 bit words to be written to the EEPROM
5432 *
5433 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005434static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435e1000_write_eeprom_microwire(struct e1000_hw *hw,
5436 uint16_t offset,
5437 uint16_t words,
5438 uint16_t *data)
5439{
5440 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5441 uint32_t eecd;
5442 uint16_t words_written = 0;
5443 uint16_t i = 0;
5444
5445 DEBUGFUNC("e1000_write_eeprom_microwire");
5446
5447 /* Send the write enable command to the EEPROM (3-bit opcode plus
5448 * 6/8-bit dummy address beginning with 11). It's less work to include
5449 * the 11 of the dummy address as part of the opcode than it is to shift
5450 * it over the correct number of bits for the address. This puts the
5451 * EEPROM into write/erase mode.
5452 */
5453 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5454 (uint16_t)(eeprom->opcode_bits + 2));
5455
5456 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5457
5458 /* Prepare the EEPROM */
5459 e1000_standby_eeprom(hw);
5460
5461 while (words_written < words) {
5462 /* Send the Write command (3-bit opcode + addr) */
5463 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5464 eeprom->opcode_bits);
5465
5466 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5467 eeprom->address_bits);
5468
5469 /* Send the data */
5470 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5471
5472 /* Toggle the CS line. This in effect tells the EEPROM to execute
5473 * the previous command.
5474 */
5475 e1000_standby_eeprom(hw);
5476
5477 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5478 * signal that the command has been completed by raising the DO signal.
5479 * If DO does not go high in 10 milliseconds, then error out.
5480 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005481 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005483 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484 udelay(50);
5485 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005486 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 DEBUGOUT("EEPROM Write did not complete\n");
5488 return -E1000_ERR_EEPROM;
5489 }
5490
5491 /* Recover from write */
5492 e1000_standby_eeprom(hw);
5493
5494 words_written++;
5495 }
5496
5497 /* Send the write disable command to the EEPROM (3-bit opcode plus
5498 * 6/8-bit dummy address beginning with 10). It's less work to include
5499 * the 10 of the dummy address as part of the opcode than it is to shift
5500 * it over the correct number of bits for the address. This takes the
5501 * EEPROM out of write/erase mode.
5502 */
5503 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5504 (uint16_t)(eeprom->opcode_bits + 2));
5505
5506 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5507
5508 return E1000_SUCCESS;
5509}
5510
5511/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005512 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5513 * in the eeprom cache and the non modified values in the currently active bank
5514 * to the new bank.
5515 *
5516 * hw - Struct containing variables accessed by shared code
5517 * offset - offset of word in the EEPROM to read
5518 * data - word read from the EEPROM
5519 * words - number of words to read
5520 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005521static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005522e1000_commit_shadow_ram(struct e1000_hw *hw)
5523{
5524 uint32_t attempts = 100000;
5525 uint32_t eecd = 0;
5526 uint32_t flop = 0;
5527 uint32_t i = 0;
5528 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005529 uint32_t old_bank_offset = 0;
5530 uint32_t new_bank_offset = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005531 uint8_t low_byte = 0;
5532 uint8_t high_byte = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005533 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005534
5535 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005536 /* The flop register will be used to determine if flash type is STM */
5537 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005538 for (i=0; i < attempts; i++) {
5539 eecd = E1000_READ_REG(hw, EECD);
5540 if ((eecd & E1000_EECD_FLUPD) == 0) {
5541 break;
5542 }
5543 udelay(5);
5544 }
5545
5546 if (i == attempts) {
5547 return -E1000_ERR_EEPROM;
5548 }
5549
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005550 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005551 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5552 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5553 }
5554
5555 /* Perform the flash update */
5556 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5557
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005558 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005559 eecd = E1000_READ_REG(hw, EECD);
5560 if ((eecd & E1000_EECD_FLUPD) == 0) {
5561 break;
5562 }
5563 udelay(5);
5564 }
5565
5566 if (i == attempts) {
5567 return -E1000_ERR_EEPROM;
5568 }
5569 }
5570
Auke Kokcd94dd02006-06-27 09:08:22 -07005571 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5572 /* We're writing to the opposite bank so if we're on bank 1,
5573 * write to bank 0 etc. We also need to erase the segment that
5574 * is going to be written */
5575 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5576 new_bank_offset = hw->flash_bank_size * 2;
5577 old_bank_offset = 0;
5578 e1000_erase_ich8_4k_segment(hw, 1);
5579 } else {
5580 old_bank_offset = hw->flash_bank_size * 2;
5581 new_bank_offset = 0;
5582 e1000_erase_ich8_4k_segment(hw, 0);
5583 }
5584
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005585 sector_write_failed = FALSE;
5586 /* Loop for every byte in the shadow RAM,
5587 * which is in units of words. */
5588 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5589 /* Determine whether to write the value stored
5590 * in the other NVM bank or a modified value stored
5591 * in the shadow RAM */
5592 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5593 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5594 udelay(100);
5595 error = e1000_verify_write_ich8_byte(hw,
5596 (i << 1) + new_bank_offset, low_byte);
5597
5598 if (error != E1000_SUCCESS)
5599 sector_write_failed = TRUE;
5600 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005601 high_byte =
5602 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005603 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005604 }
5605 } else {
5606 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5607 &low_byte);
5608 udelay(100);
5609 error = e1000_verify_write_ich8_byte(hw,
5610 (i << 1) + new_bank_offset, low_byte);
5611
5612 if (error != E1000_SUCCESS)
5613 sector_write_failed = TRUE;
5614 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005615 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5616 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005617 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005618 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005619 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005620
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005621 /* If the write of the low byte was successful, go ahread and
5622 * write the high byte while checking to make sure that if it
5623 * is the signature byte, then it is handled properly */
5624 if (sector_write_failed == FALSE) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005625 /* If the word is 0x13, then make sure the signature bits
5626 * (15:14) are 11b until the commit has completed.
5627 * This will allow us to write 10b which indicates the
5628 * signature is valid. We want to do this after the write
5629 * has completed so that we don't mark the segment valid
5630 * while the write is still in progress */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005631 if (i == E1000_ICH_NVM_SIG_WORD)
5632 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
Auke Kokcd94dd02006-06-27 09:08:22 -07005633
5634 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005635 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005636 if (error != E1000_SUCCESS)
5637 sector_write_failed = TRUE;
5638
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005639 } else {
5640 /* If the write failed then break from the loop and
5641 * return an error */
5642 break;
5643 }
5644 }
5645
5646 /* Don't bother writing the segment valid bits if sector
5647 * programming failed. */
5648 if (sector_write_failed == FALSE) {
5649 /* Finally validate the new segment by setting bit 15:14
5650 * to 10b in word 0x13 , this can be done without an
5651 * erase as well since these bits are 11 to start with
5652 * and we need to change bit 14 to 0b */
5653 e1000_read_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005654 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005655 &high_byte);
5656 high_byte &= 0xBF;
5657 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005658 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005659 /* And invalidate the previously valid segment by setting
5660 * its signature word (0x13) high_byte to 0b. This can be
5661 * done without an erase because flash erase sets all bits
5662 * to 1's. We can write 1's to 0's without an erase */
5663 if (error == E1000_SUCCESS) {
5664 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005665 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005666 }
5667
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005668 /* Clear the now not used entry in the cache */
5669 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5670 hw->eeprom_shadow_ram[i].modified = FALSE;
5671 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005672 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005673 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005674 }
5675
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005676 return error;
5677}
5678
5679/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5681 * second function of dual function devices
5682 *
5683 * hw - Struct containing variables accessed by shared code
5684 *****************************************************************************/
5685int32_t
5686e1000_read_mac_addr(struct e1000_hw * hw)
5687{
5688 uint16_t offset;
5689 uint16_t eeprom_data, i;
5690
5691 DEBUGFUNC("e1000_read_mac_addr");
5692
Auke Kok8fc897b2006-08-28 14:56:16 -07005693 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005695 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696 DEBUGOUT("EEPROM Read Error\n");
5697 return -E1000_ERR_EEPROM;
5698 }
5699 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5700 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5701 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005702
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005703 switch (hw->mac_type) {
5704 default:
5705 break;
5706 case e1000_82546:
5707 case e1000_82546_rev_3:
5708 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005709 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005710 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005712 break;
5713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714
Auke Kok8fc897b2006-08-28 14:56:16 -07005715 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716 hw->mac_addr[i] = hw->perm_mac_addr[i];
5717 return E1000_SUCCESS;
5718}
5719
5720/******************************************************************************
5721 * Initializes receive address filters.
5722 *
5723 * hw - Struct containing variables accessed by shared code
5724 *
5725 * Places the MAC address in receive address register 0 and clears the rest
5726 * of the receive addresss registers. Clears the multicast table. Assumes
5727 * the receiver is in reset when the routine is called.
5728 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005729static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730e1000_init_rx_addrs(struct e1000_hw *hw)
5731{
5732 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005733 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734
5735 DEBUGFUNC("e1000_init_rx_addrs");
5736
5737 /* Setup the receive address. */
5738 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5739
5740 e1000_rar_set(hw, hw->mac_addr, 0);
5741
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005742 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005743
5744 /* Reserve a spot for the Locally Administered Address to work around
5745 * an 82571 issue in which a reset on one port will reload the MAC on
5746 * the other port. */
5747 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5748 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005749 if (hw->mac_type == e1000_ich8lan)
5750 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5751
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752 /* Zero out the other 15 receive addresses. */
5753 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005754 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005756 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005758 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 }
5760}
5761
5762/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 * Hashes an address to determine its location in the multicast table
5764 *
5765 * hw - Struct containing variables accessed by shared code
5766 * mc_addr - the multicast address to hash
5767 *****************************************************************************/
5768uint32_t
5769e1000_hash_mc_addr(struct e1000_hw *hw,
5770 uint8_t *mc_addr)
5771{
5772 uint32_t hash_value = 0;
5773
5774 /* The portion of the address that is used for the hash table is
5775 * determined by the mc_filter_type setting.
5776 */
5777 switch (hw->mc_filter_type) {
5778 /* [0] [1] [2] [3] [4] [5]
5779 * 01 AA 00 12 34 56
5780 * LSB MSB
5781 */
5782 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005783 if (hw->mac_type == e1000_ich8lan) {
5784 /* [47:38] i.e. 0x158 for above example address */
5785 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5786 } else {
5787 /* [47:36] i.e. 0x563 for above example address */
5788 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 break;
5791 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005792 if (hw->mac_type == e1000_ich8lan) {
5793 /* [46:37] i.e. 0x2B1 for above example address */
5794 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5795 } else {
5796 /* [46:35] i.e. 0xAC6 for above example address */
5797 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 break;
5800 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005801 if (hw->mac_type == e1000_ich8lan) {
5802 /*[45:36] i.e. 0x163 for above example address */
5803 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5804 } else {
5805 /* [45:34] i.e. 0x5D8 for above example address */
5806 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808 break;
5809 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005810 if (hw->mac_type == e1000_ich8lan) {
5811 /* [43:34] i.e. 0x18D for above example address */
5812 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5813 } else {
5814 /* [43:32] i.e. 0x634 for above example address */
5815 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 break;
5818 }
5819
5820 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005821 if (hw->mac_type == e1000_ich8lan)
5822 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005823
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 return hash_value;
5825}
5826
5827/******************************************************************************
5828 * Sets the bit in the multicast table corresponding to the hash value.
5829 *
5830 * hw - Struct containing variables accessed by shared code
5831 * hash_value - Multicast address hash value
5832 *****************************************************************************/
5833void
5834e1000_mta_set(struct e1000_hw *hw,
5835 uint32_t hash_value)
5836{
5837 uint32_t hash_bit, hash_reg;
5838 uint32_t mta;
5839 uint32_t temp;
5840
5841 /* The MTA is a register array of 128 32-bit registers.
5842 * It is treated like an array of 4096 bits. We want to set
5843 * bit BitArray[hash_value]. So we figure out what register
5844 * the bit is in, read it, OR in the new bit, then write
5845 * back the new value. The register is determined by the
5846 * upper 7 bits of the hash value and the bit within that
5847 * register are determined by the lower 5 bits of the value.
5848 */
5849 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005850 if (hw->mac_type == e1000_ich8lan)
5851 hash_reg &= 0x1F;
Auke Kok90fb5132006-11-01 08:47:30 -08005852
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 hash_bit = hash_value & 0x1F;
5854
5855 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5856
5857 mta |= (1 << hash_bit);
5858
5859 /* If we are on an 82544 and we are trying to write an odd offset
5860 * in the MTA, save off the previous entry before writing and
5861 * restore the old value after writing.
5862 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005863 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5865 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005866 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005868 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869 } else {
5870 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005871 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872 }
5873}
5874
5875/******************************************************************************
5876 * Puts an ethernet address into a receive address register.
5877 *
5878 * hw - Struct containing variables accessed by shared code
5879 * addr - Address to put into receive address register
5880 * index - Receive address register to write
5881 *****************************************************************************/
5882void
5883e1000_rar_set(struct e1000_hw *hw,
5884 uint8_t *addr,
5885 uint32_t index)
5886{
5887 uint32_t rar_low, rar_high;
5888
5889 /* HW expects these in little endian so we reverse the byte order
5890 * from network order (big endian) to little endian
5891 */
5892 rar_low = ((uint32_t) addr[0] |
5893 ((uint32_t) addr[1] << 8) |
5894 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005895 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005897 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5898 * unit hang.
5899 *
5900 * Description:
5901 * If there are any Rx frames queued up or otherwise present in the HW
5902 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5903 * hang. To work around this issue, we have to disable receives and
5904 * flush out all Rx frames before we enable RSS. To do so, we modify we
5905 * redirect all Rx traffic to manageability and then reset the HW.
5906 * This flushes away Rx frames, and (since the redirections to
5907 * manageability persists across resets) keeps new ones from coming in
5908 * while we work. Then, we clear the Address Valid AV bit for all MAC
5909 * addresses and undo the re-direction to manageability.
5910 * Now, frames are coming in again, but the MAC won't accept them, so
5911 * far so good. We now proceed to initialize RSS (if necessary) and
5912 * configure the Rx unit. Last, we re-enable the AV bits and continue
5913 * on our merry way.
5914 */
5915 switch (hw->mac_type) {
5916 case e1000_82571:
5917 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005918 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005919 if (hw->leave_av_bit_off == TRUE)
5920 break;
5921 default:
5922 /* Indicate to hardware the Address is Valid. */
5923 rar_high |= E1000_RAH_AV;
5924 break;
5925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926
5927 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005928 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005930 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931}
5932
5933/******************************************************************************
5934 * Writes a value to the specified offset in the VLAN filter table.
5935 *
5936 * hw - Struct containing variables accessed by shared code
5937 * offset - Offset in VLAN filer table to write
5938 * value - Value to write into VLAN filter table
5939 *****************************************************************************/
5940void
5941e1000_write_vfta(struct e1000_hw *hw,
5942 uint32_t offset,
5943 uint32_t value)
5944{
5945 uint32_t temp;
5946
Auke Kokcd94dd02006-06-27 09:08:22 -07005947 if (hw->mac_type == e1000_ich8lan)
5948 return;
5949
5950 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5952 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005953 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005955 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 } else {
5957 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005958 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 }
5960}
5961
5962/******************************************************************************
5963 * Clears the VLAN filer table
5964 *
5965 * hw - Struct containing variables accessed by shared code
5966 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005967static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968e1000_clear_vfta(struct e1000_hw *hw)
5969{
5970 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005971 uint32_t vfta_value = 0;
5972 uint32_t vfta_offset = 0;
5973 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974
Auke Kokcd94dd02006-06-27 09:08:22 -07005975 if (hw->mac_type == e1000_ich8lan)
5976 return;
5977
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005978 if (hw->mac_type == e1000_82573) {
5979 if (hw->mng_cookie.vlan_id != 0) {
5980 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5981 * ID. The following operations determine which 32b entry
5982 * (i.e. offset) into the array we want to set the VLAN ID
5983 * (i.e. bit) of the manageability unit. */
5984 vfta_offset = (hw->mng_cookie.vlan_id >>
5985 E1000_VFTA_ENTRY_SHIFT) &
5986 E1000_VFTA_ENTRY_MASK;
5987 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5988 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5989 }
5990 }
5991 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5992 /* If the offset we want to clear is the same offset of the
5993 * manageability VLAN ID, then clear all bits except that of the
5994 * manageability unit */
5995 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5996 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005997 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999}
6000
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006001static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002e1000_id_led_init(struct e1000_hw * hw)
6003{
6004 uint32_t ledctl;
6005 const uint32_t ledctl_mask = 0x000000FF;
6006 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6007 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6008 uint16_t eeprom_data, i, temp;
6009 const uint16_t led_mask = 0x0F;
6010
6011 DEBUGFUNC("e1000_id_led_init");
6012
Auke Kok8fc897b2006-08-28 14:56:16 -07006013 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 /* Nothing to do */
6015 return E1000_SUCCESS;
6016 }
6017
6018 ledctl = E1000_READ_REG(hw, LEDCTL);
6019 hw->ledctl_default = ledctl;
6020 hw->ledctl_mode1 = hw->ledctl_default;
6021 hw->ledctl_mode2 = hw->ledctl_default;
6022
Auke Kok8fc897b2006-08-28 14:56:16 -07006023 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 DEBUGOUT("EEPROM Read Error\n");
6025 return -E1000_ERR_EEPROM;
6026 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006027
6028 if ((hw->mac_type == e1000_82573) &&
6029 (eeprom_data == ID_LED_RESERVED_82573))
6030 eeprom_data = ID_LED_DEFAULT_82573;
6031 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6032 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6033 if (hw->mac_type == e1000_ich8lan)
6034 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6035 else
6036 eeprom_data = ID_LED_DEFAULT;
6037 }
Auke Kok90fb5132006-11-01 08:47:30 -08006038
Auke Kokcd94dd02006-06-27 09:08:22 -07006039 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006041 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 case ID_LED_ON1_DEF2:
6043 case ID_LED_ON1_ON2:
6044 case ID_LED_ON1_OFF2:
6045 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6046 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6047 break;
6048 case ID_LED_OFF1_DEF2:
6049 case ID_LED_OFF1_ON2:
6050 case ID_LED_OFF1_OFF2:
6051 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6052 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6053 break;
6054 default:
6055 /* Do nothing */
6056 break;
6057 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006058 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 case ID_LED_DEF1_ON2:
6060 case ID_LED_ON1_ON2:
6061 case ID_LED_OFF1_ON2:
6062 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6063 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6064 break;
6065 case ID_LED_DEF1_OFF2:
6066 case ID_LED_ON1_OFF2:
6067 case ID_LED_OFF1_OFF2:
6068 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6069 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6070 break;
6071 default:
6072 /* Do nothing */
6073 break;
6074 }
6075 }
6076 return E1000_SUCCESS;
6077}
6078
6079/******************************************************************************
6080 * Prepares SW controlable LED for use and saves the current state of the LED.
6081 *
6082 * hw - Struct containing variables accessed by shared code
6083 *****************************************************************************/
6084int32_t
6085e1000_setup_led(struct e1000_hw *hw)
6086{
6087 uint32_t ledctl;
6088 int32_t ret_val = E1000_SUCCESS;
6089
6090 DEBUGFUNC("e1000_setup_led");
6091
Auke Kok8fc897b2006-08-28 14:56:16 -07006092 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 case e1000_82542_rev2_0:
6094 case e1000_82542_rev2_1:
6095 case e1000_82543:
6096 case e1000_82544:
6097 /* No setup necessary */
6098 break;
6099 case e1000_82541:
6100 case e1000_82547:
6101 case e1000_82541_rev_2:
6102 case e1000_82547_rev_2:
6103 /* Turn off PHY Smart Power Down (if enabled) */
6104 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6105 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006106 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 return ret_val;
6108 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6109 (uint16_t)(hw->phy_spd_default &
6110 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006111 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 return ret_val;
6113 /* Fall Through */
6114 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006115 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 ledctl = E1000_READ_REG(hw, LEDCTL);
6117 /* Save current LEDCTL settings */
6118 hw->ledctl_default = ledctl;
6119 /* Turn off LED0 */
6120 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6121 E1000_LEDCTL_LED0_BLINK |
6122 E1000_LEDCTL_LED0_MODE_MASK);
6123 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6124 E1000_LEDCTL_LED0_MODE_SHIFT);
6125 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006126 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6128 break;
6129 }
6130
6131 return E1000_SUCCESS;
6132}
6133
Auke Kok8fc897b2006-08-28 14:56:16 -07006134
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006136 * Used on 82571 and later Si that has LED blink bits.
6137 * Callers must use their own timer and should have already called
6138 * e1000_id_led_init()
6139 * Call e1000_cleanup led() to stop blinking
6140 *
6141 * hw - Struct containing variables accessed by shared code
6142 *****************************************************************************/
6143int32_t
6144e1000_blink_led_start(struct e1000_hw *hw)
6145{
6146 int16_t i;
6147 uint32_t ledctl_blink = 0;
6148
6149 DEBUGFUNC("e1000_id_led_blink_on");
6150
6151 if (hw->mac_type < e1000_82571) {
6152 /* Nothing to do */
6153 return E1000_SUCCESS;
6154 }
6155 if (hw->media_type == e1000_media_type_fiber) {
6156 /* always blink LED0 for PCI-E fiber */
6157 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6158 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6159 } else {
6160 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6161 ledctl_blink = hw->ledctl_mode2;
6162 for (i=0; i < 4; i++)
6163 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6164 E1000_LEDCTL_MODE_LED_ON)
6165 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6166 }
6167
6168 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6169
6170 return E1000_SUCCESS;
6171}
6172
6173/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 * Restores the saved state of the SW controlable LED.
6175 *
6176 * hw - Struct containing variables accessed by shared code
6177 *****************************************************************************/
6178int32_t
6179e1000_cleanup_led(struct e1000_hw *hw)
6180{
6181 int32_t ret_val = E1000_SUCCESS;
6182
6183 DEBUGFUNC("e1000_cleanup_led");
6184
Auke Kok8fc897b2006-08-28 14:56:16 -07006185 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186 case e1000_82542_rev2_0:
6187 case e1000_82542_rev2_1:
6188 case e1000_82543:
6189 case e1000_82544:
6190 /* No cleanup necessary */
6191 break;
6192 case e1000_82541:
6193 case e1000_82547:
6194 case e1000_82541_rev_2:
6195 case e1000_82547_rev_2:
6196 /* Turn on PHY Smart Power Down (if previously enabled) */
6197 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6198 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006199 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 return ret_val;
6201 /* Fall Through */
6202 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006203 if (hw->phy_type == e1000_phy_ife) {
6204 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6205 break;
6206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 /* Restore LEDCTL settings */
6208 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6209 break;
6210 }
6211
6212 return E1000_SUCCESS;
6213}
6214
6215/******************************************************************************
6216 * Turns on the software controllable LED
6217 *
6218 * hw - Struct containing variables accessed by shared code
6219 *****************************************************************************/
6220int32_t
6221e1000_led_on(struct e1000_hw *hw)
6222{
6223 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6224
6225 DEBUGFUNC("e1000_led_on");
6226
Auke Kok8fc897b2006-08-28 14:56:16 -07006227 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 case e1000_82542_rev2_0:
6229 case e1000_82542_rev2_1:
6230 case e1000_82543:
6231 /* Set SW Defineable Pin 0 to turn on the LED */
6232 ctrl |= E1000_CTRL_SWDPIN0;
6233 ctrl |= E1000_CTRL_SWDPIO0;
6234 break;
6235 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006236 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 /* Set SW Defineable Pin 0 to turn on the LED */
6238 ctrl |= E1000_CTRL_SWDPIN0;
6239 ctrl |= E1000_CTRL_SWDPIO0;
6240 } else {
6241 /* Clear SW Defineable Pin 0 to turn on the LED */
6242 ctrl &= ~E1000_CTRL_SWDPIN0;
6243 ctrl |= E1000_CTRL_SWDPIO0;
6244 }
6245 break;
6246 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006247 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248 /* Clear SW Defineable Pin 0 to turn on the LED */
6249 ctrl &= ~E1000_CTRL_SWDPIN0;
6250 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006251 } else if (hw->phy_type == e1000_phy_ife) {
6252 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6253 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6254 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6256 return E1000_SUCCESS;
6257 }
6258 break;
6259 }
6260
6261 E1000_WRITE_REG(hw, CTRL, ctrl);
6262
6263 return E1000_SUCCESS;
6264}
6265
6266/******************************************************************************
6267 * Turns off the software controllable LED
6268 *
6269 * hw - Struct containing variables accessed by shared code
6270 *****************************************************************************/
6271int32_t
6272e1000_led_off(struct e1000_hw *hw)
6273{
6274 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6275
6276 DEBUGFUNC("e1000_led_off");
6277
Auke Kok8fc897b2006-08-28 14:56:16 -07006278 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 case e1000_82542_rev2_0:
6280 case e1000_82542_rev2_1:
6281 case e1000_82543:
6282 /* Clear SW Defineable Pin 0 to turn off the LED */
6283 ctrl &= ~E1000_CTRL_SWDPIN0;
6284 ctrl |= E1000_CTRL_SWDPIO0;
6285 break;
6286 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006287 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 /* Clear SW Defineable Pin 0 to turn off the LED */
6289 ctrl &= ~E1000_CTRL_SWDPIN0;
6290 ctrl |= E1000_CTRL_SWDPIO0;
6291 } else {
6292 /* Set SW Defineable Pin 0 to turn off the LED */
6293 ctrl |= E1000_CTRL_SWDPIN0;
6294 ctrl |= E1000_CTRL_SWDPIO0;
6295 }
6296 break;
6297 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006298 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 /* Set SW Defineable Pin 0 to turn off the LED */
6300 ctrl |= E1000_CTRL_SWDPIN0;
6301 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006302 } else if (hw->phy_type == e1000_phy_ife) {
6303 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6304 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6305 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6307 return E1000_SUCCESS;
6308 }
6309 break;
6310 }
6311
6312 E1000_WRITE_REG(hw, CTRL, ctrl);
6313
6314 return E1000_SUCCESS;
6315}
6316
6317/******************************************************************************
6318 * Clears all hardware statistics counters.
6319 *
6320 * hw - Struct containing variables accessed by shared code
6321 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006322static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323e1000_clear_hw_cntrs(struct e1000_hw *hw)
6324{
6325 volatile uint32_t temp;
6326
6327 temp = E1000_READ_REG(hw, CRCERRS);
6328 temp = E1000_READ_REG(hw, SYMERRS);
6329 temp = E1000_READ_REG(hw, MPC);
6330 temp = E1000_READ_REG(hw, SCC);
6331 temp = E1000_READ_REG(hw, ECOL);
6332 temp = E1000_READ_REG(hw, MCC);
6333 temp = E1000_READ_REG(hw, LATECOL);
6334 temp = E1000_READ_REG(hw, COLC);
6335 temp = E1000_READ_REG(hw, DC);
6336 temp = E1000_READ_REG(hw, SEC);
6337 temp = E1000_READ_REG(hw, RLEC);
6338 temp = E1000_READ_REG(hw, XONRXC);
6339 temp = E1000_READ_REG(hw, XONTXC);
6340 temp = E1000_READ_REG(hw, XOFFRXC);
6341 temp = E1000_READ_REG(hw, XOFFTXC);
6342 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006343
6344 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 temp = E1000_READ_REG(hw, PRC64);
6346 temp = E1000_READ_REG(hw, PRC127);
6347 temp = E1000_READ_REG(hw, PRC255);
6348 temp = E1000_READ_REG(hw, PRC511);
6349 temp = E1000_READ_REG(hw, PRC1023);
6350 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006351 }
6352
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 temp = E1000_READ_REG(hw, GPRC);
6354 temp = E1000_READ_REG(hw, BPRC);
6355 temp = E1000_READ_REG(hw, MPRC);
6356 temp = E1000_READ_REG(hw, GPTC);
6357 temp = E1000_READ_REG(hw, GORCL);
6358 temp = E1000_READ_REG(hw, GORCH);
6359 temp = E1000_READ_REG(hw, GOTCL);
6360 temp = E1000_READ_REG(hw, GOTCH);
6361 temp = E1000_READ_REG(hw, RNBC);
6362 temp = E1000_READ_REG(hw, RUC);
6363 temp = E1000_READ_REG(hw, RFC);
6364 temp = E1000_READ_REG(hw, ROC);
6365 temp = E1000_READ_REG(hw, RJC);
6366 temp = E1000_READ_REG(hw, TORL);
6367 temp = E1000_READ_REG(hw, TORH);
6368 temp = E1000_READ_REG(hw, TOTL);
6369 temp = E1000_READ_REG(hw, TOTH);
6370 temp = E1000_READ_REG(hw, TPR);
6371 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006372
6373 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374 temp = E1000_READ_REG(hw, PTC64);
6375 temp = E1000_READ_REG(hw, PTC127);
6376 temp = E1000_READ_REG(hw, PTC255);
6377 temp = E1000_READ_REG(hw, PTC511);
6378 temp = E1000_READ_REG(hw, PTC1023);
6379 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006380 }
6381
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 temp = E1000_READ_REG(hw, MPTC);
6383 temp = E1000_READ_REG(hw, BPTC);
6384
Auke Kok8fc897b2006-08-28 14:56:16 -07006385 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386
6387 temp = E1000_READ_REG(hw, ALGNERRC);
6388 temp = E1000_READ_REG(hw, RXERRC);
6389 temp = E1000_READ_REG(hw, TNCRS);
6390 temp = E1000_READ_REG(hw, CEXTERR);
6391 temp = E1000_READ_REG(hw, TSCTC);
6392 temp = E1000_READ_REG(hw, TSCTFC);
6393
Auke Kok8fc897b2006-08-28 14:56:16 -07006394 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395
6396 temp = E1000_READ_REG(hw, MGTPRC);
6397 temp = E1000_READ_REG(hw, MGTPDC);
6398 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006399
Auke Kok8fc897b2006-08-28 14:56:16 -07006400 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006401
6402 temp = E1000_READ_REG(hw, IAC);
6403 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006404
6405 if (hw->mac_type == e1000_ich8lan) return;
6406
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006407 temp = E1000_READ_REG(hw, ICRXPTC);
6408 temp = E1000_READ_REG(hw, ICRXATC);
6409 temp = E1000_READ_REG(hw, ICTXPTC);
6410 temp = E1000_READ_REG(hw, ICTXATC);
6411 temp = E1000_READ_REG(hw, ICTXQEC);
6412 temp = E1000_READ_REG(hw, ICTXQMTC);
6413 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414}
6415
6416/******************************************************************************
6417 * Resets Adaptive IFS to its default state.
6418 *
6419 * hw - Struct containing variables accessed by shared code
6420 *
6421 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6422 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6423 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6424 * before calling this function.
6425 *****************************************************************************/
6426void
6427e1000_reset_adaptive(struct e1000_hw *hw)
6428{
6429 DEBUGFUNC("e1000_reset_adaptive");
6430
Auke Kok8fc897b2006-08-28 14:56:16 -07006431 if (hw->adaptive_ifs) {
6432 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433 hw->current_ifs_val = 0;
6434 hw->ifs_min_val = IFS_MIN;
6435 hw->ifs_max_val = IFS_MAX;
6436 hw->ifs_step_size = IFS_STEP;
6437 hw->ifs_ratio = IFS_RATIO;
6438 }
6439 hw->in_ifs_mode = FALSE;
6440 E1000_WRITE_REG(hw, AIT, 0);
6441 } else {
6442 DEBUGOUT("Not in Adaptive IFS mode!\n");
6443 }
6444}
6445
6446/******************************************************************************
6447 * Called during the callback/watchdog routine to update IFS value based on
6448 * the ratio of transmits to collisions.
6449 *
6450 * hw - Struct containing variables accessed by shared code
6451 * tx_packets - Number of transmits since last callback
6452 * total_collisions - Number of collisions since last callback
6453 *****************************************************************************/
6454void
6455e1000_update_adaptive(struct e1000_hw *hw)
6456{
6457 DEBUGFUNC("e1000_update_adaptive");
6458
Auke Kok8fc897b2006-08-28 14:56:16 -07006459 if (hw->adaptive_ifs) {
6460 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6461 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006463 if (hw->current_ifs_val < hw->ifs_max_val) {
6464 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 hw->current_ifs_val = hw->ifs_min_val;
6466 else
6467 hw->current_ifs_val += hw->ifs_step_size;
6468 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6469 }
6470 }
6471 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006472 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 hw->current_ifs_val = 0;
6474 hw->in_ifs_mode = FALSE;
6475 E1000_WRITE_REG(hw, AIT, 0);
6476 }
6477 }
6478 } else {
6479 DEBUGOUT("Not in Adaptive IFS mode!\n");
6480 }
6481}
6482
6483/******************************************************************************
6484 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6485 *
6486 * hw - Struct containing variables accessed by shared code
6487 * frame_len - The length of the frame in question
6488 * mac_addr - The Ethernet destination address of the frame in question
6489 *****************************************************************************/
6490void
6491e1000_tbi_adjust_stats(struct e1000_hw *hw,
6492 struct e1000_hw_stats *stats,
6493 uint32_t frame_len,
6494 uint8_t *mac_addr)
6495{
6496 uint64_t carry_bit;
6497
6498 /* First adjust the frame length. */
6499 frame_len--;
6500 /* We need to adjust the statistics counters, since the hardware
6501 * counters overcount this packet as a CRC error and undercount
6502 * the packet as a good packet
6503 */
6504 /* This packet should not be counted as a CRC error. */
6505 stats->crcerrs--;
6506 /* This packet does count as a Good Packet Received. */
6507 stats->gprc++;
6508
6509 /* Adjust the Good Octets received counters */
6510 carry_bit = 0x80000000 & stats->gorcl;
6511 stats->gorcl += frame_len;
6512 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6513 * Received Count) was one before the addition,
6514 * AND it is zero after, then we lost the carry out,
6515 * need to add one to Gorch (Good Octets Received Count High).
6516 * This could be simplified if all environments supported
6517 * 64-bit integers.
6518 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006519 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 stats->gorch++;
6521 /* Is this a broadcast or multicast? Check broadcast first,
6522 * since the test for a multicast frame will test positive on
6523 * a broadcast frame.
6524 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006525 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 /* Broadcast packet */
6527 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006528 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 /* Multicast packet */
6530 stats->mprc++;
6531
Auke Kok8fc897b2006-08-28 14:56:16 -07006532 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 /* In this case, the hardware has overcounted the number of
6534 * oversize frames.
6535 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006536 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 stats->roc--;
6538 }
6539
6540 /* Adjust the bin counters when the extra byte put the frame in the
6541 * wrong bin. Remember that the frame_len was adjusted above.
6542 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006543 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 stats->prc64++;
6545 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006546 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 stats->prc127++;
6548 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006549 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 stats->prc255++;
6551 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006552 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 stats->prc511++;
6554 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006555 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 stats->prc1023++;
6557 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006558 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 stats->prc1522++;
6560 }
6561}
6562
6563/******************************************************************************
6564 * Gets the current PCI bus type, speed, and width of the hardware
6565 *
6566 * hw - Struct containing variables accessed by shared code
6567 *****************************************************************************/
6568void
6569e1000_get_bus_info(struct e1000_hw *hw)
6570{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006571 int32_t ret_val;
6572 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 uint32_t status;
6574
6575 switch (hw->mac_type) {
6576 case e1000_82542_rev2_0:
6577 case e1000_82542_rev2_1:
6578 hw->bus_type = e1000_bus_type_unknown;
6579 hw->bus_speed = e1000_bus_speed_unknown;
6580 hw->bus_width = e1000_bus_width_unknown;
6581 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006582 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006583 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006584 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006585 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006586 hw->bus_type = e1000_bus_type_pci_express;
6587 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006588 ret_val = e1000_read_pcie_cap_reg(hw,
6589 PCI_EX_LINK_STATUS,
6590 &pci_ex_link_status);
6591 if (ret_val)
6592 hw->bus_width = e1000_bus_width_unknown;
6593 else
6594 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6595 PCI_EX_LINK_WIDTH_SHIFT;
6596 break;
6597 case e1000_ich8lan:
6598 hw->bus_type = e1000_bus_type_pci_express;
6599 hw->bus_speed = e1000_bus_speed_2500;
6600 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006601 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 default:
6603 status = E1000_READ_REG(hw, STATUS);
6604 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6605 e1000_bus_type_pcix : e1000_bus_type_pci;
6606
Auke Kok8fc897b2006-08-28 14:56:16 -07006607 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6609 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006610 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6612 e1000_bus_speed_66 : e1000_bus_speed_33;
6613 } else {
6614 switch (status & E1000_STATUS_PCIX_SPEED) {
6615 case E1000_STATUS_PCIX_SPEED_66:
6616 hw->bus_speed = e1000_bus_speed_66;
6617 break;
6618 case E1000_STATUS_PCIX_SPEED_100:
6619 hw->bus_speed = e1000_bus_speed_100;
6620 break;
6621 case E1000_STATUS_PCIX_SPEED_133:
6622 hw->bus_speed = e1000_bus_speed_133;
6623 break;
6624 default:
6625 hw->bus_speed = e1000_bus_speed_reserved;
6626 break;
6627 }
6628 }
6629 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6630 e1000_bus_width_64 : e1000_bus_width_32;
6631 break;
6632 }
6633}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634
6635/******************************************************************************
6636 * Writes a value to one of the devices registers using port I/O (as opposed to
6637 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6638 *
6639 * hw - Struct containing variables accessed by shared code
6640 * offset - offset to write to
6641 * value - value to write
6642 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006643static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644e1000_write_reg_io(struct e1000_hw *hw,
6645 uint32_t offset,
6646 uint32_t value)
6647{
6648 unsigned long io_addr = hw->io_base;
6649 unsigned long io_data = hw->io_base + 4;
6650
6651 e1000_io_write(hw, io_addr, offset);
6652 e1000_io_write(hw, io_data, value);
6653}
6654
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655/******************************************************************************
6656 * Estimates the cable length.
6657 *
6658 * hw - Struct containing variables accessed by shared code
6659 * min_length - The estimated minimum length
6660 * max_length - The estimated maximum length
6661 *
6662 * returns: - E1000_ERR_XXX
6663 * E1000_SUCCESS
6664 *
6665 * This function always returns a ranged length (minimum & maximum).
6666 * So for M88 phy's, this function interprets the one value returned from the
6667 * register to the minimum and maximum range.
6668 * For IGP phy's, the function calculates the range by the AGC registers.
6669 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006670static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671e1000_get_cable_length(struct e1000_hw *hw,
6672 uint16_t *min_length,
6673 uint16_t *max_length)
6674{
6675 int32_t ret_val;
6676 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 uint16_t i, phy_data;
6678 uint16_t cable_length;
6679
6680 DEBUGFUNC("e1000_get_cable_length");
6681
6682 *min_length = *max_length = 0;
6683
6684 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006685 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006686
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6688 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006689 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690 return ret_val;
6691 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6692 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6693
6694 /* Convert the enum value to ranged values */
6695 switch (cable_length) {
6696 case e1000_cable_length_50:
6697 *min_length = 0;
6698 *max_length = e1000_igp_cable_length_50;
6699 break;
6700 case e1000_cable_length_50_80:
6701 *min_length = e1000_igp_cable_length_50;
6702 *max_length = e1000_igp_cable_length_80;
6703 break;
6704 case e1000_cable_length_80_110:
6705 *min_length = e1000_igp_cable_length_80;
6706 *max_length = e1000_igp_cable_length_110;
6707 break;
6708 case e1000_cable_length_110_140:
6709 *min_length = e1000_igp_cable_length_110;
6710 *max_length = e1000_igp_cable_length_140;
6711 break;
6712 case e1000_cable_length_140:
6713 *min_length = e1000_igp_cable_length_140;
6714 *max_length = e1000_igp_cable_length_170;
6715 break;
6716 default:
6717 return -E1000_ERR_PHY;
6718 break;
6719 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006720 } else if (hw->phy_type == e1000_phy_gg82563) {
6721 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6722 &phy_data);
6723 if (ret_val)
6724 return ret_val;
6725 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6726
6727 switch (cable_length) {
6728 case e1000_gg_cable_length_60:
6729 *min_length = 0;
6730 *max_length = e1000_igp_cable_length_60;
6731 break;
6732 case e1000_gg_cable_length_60_115:
6733 *min_length = e1000_igp_cable_length_60;
6734 *max_length = e1000_igp_cable_length_115;
6735 break;
6736 case e1000_gg_cable_length_115_150:
6737 *min_length = e1000_igp_cable_length_115;
6738 *max_length = e1000_igp_cable_length_150;
6739 break;
6740 case e1000_gg_cable_length_150:
6741 *min_length = e1000_igp_cable_length_150;
6742 *max_length = e1000_igp_cable_length_180;
6743 break;
6744 default:
6745 return -E1000_ERR_PHY;
6746 break;
6747 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006748 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006749 uint16_t cur_agc_value;
6750 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6752 {IGP01E1000_PHY_AGC_A,
6753 IGP01E1000_PHY_AGC_B,
6754 IGP01E1000_PHY_AGC_C,
6755 IGP01E1000_PHY_AGC_D};
6756 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006757 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758
6759 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006760 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 return ret_val;
6762
Auke Kokcd94dd02006-06-27 09:08:22 -07006763 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764
Auke Kokcd94dd02006-06-27 09:08:22 -07006765 /* Value bound check. */
6766 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6767 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 return -E1000_ERR_PHY;
6769
Auke Kokcd94dd02006-06-27 09:08:22 -07006770 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771
6772 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006773 if (min_agc_value > cur_agc_value)
6774 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775 }
6776
6777 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006778 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6779 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780
6781 /* Get the average length of the remaining 3 channels */
6782 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6783 } else {
6784 /* Get the average length of all the 4 channels. */
6785 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6786 }
6787
6788 /* Set the range of the calculated length. */
6789 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6790 IGP01E1000_AGC_RANGE) > 0) ?
6791 (e1000_igp_cable_length_table[agc_value] -
6792 IGP01E1000_AGC_RANGE) : 0;
6793 *max_length = e1000_igp_cable_length_table[agc_value] +
6794 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006795 } else if (hw->phy_type == e1000_phy_igp_2 ||
6796 hw->phy_type == e1000_phy_igp_3) {
6797 uint16_t cur_agc_index, max_agc_index = 0;
6798 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006799 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6800 {IGP02E1000_PHY_AGC_A,
6801 IGP02E1000_PHY_AGC_B,
6802 IGP02E1000_PHY_AGC_C,
6803 IGP02E1000_PHY_AGC_D};
6804 /* Read the AGC registers for all channels */
6805 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6806 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6807 if (ret_val)
6808 return ret_val;
6809
Auke Kok8fc897b2006-08-28 14:56:16 -07006810 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006811 * fine gain values. The result is a number that can be put into
6812 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006813 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6814 IGP02E1000_AGC_LENGTH_MASK;
6815
6816 /* Array index bound check. */
6817 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6818 (cur_agc_index == 0))
6819 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006820
6821 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006822 if (e1000_igp_2_cable_length_table[min_agc_index] >
6823 e1000_igp_2_cable_length_table[cur_agc_index])
6824 min_agc_index = cur_agc_index;
6825 if (e1000_igp_2_cable_length_table[max_agc_index] <
6826 e1000_igp_2_cable_length_table[cur_agc_index])
6827 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006828
Auke Kokcd94dd02006-06-27 09:08:22 -07006829 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006830 }
6831
Auke Kokcd94dd02006-06-27 09:08:22 -07006832 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6833 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006834 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6835
6836 /* Calculate cable length with the error range of +/- 10 meters. */
6837 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6838 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6839 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 }
6841
6842 return E1000_SUCCESS;
6843}
6844
6845/******************************************************************************
6846 * Check the cable polarity
6847 *
6848 * hw - Struct containing variables accessed by shared code
6849 * polarity - output parameter : 0 - Polarity is not reversed
6850 * 1 - Polarity is reversed.
6851 *
6852 * returns: - E1000_ERR_XXX
6853 * E1000_SUCCESS
6854 *
6855 * For phy's older then IGP, this function simply reads the polarity bit in the
6856 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6857 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6858 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6859 * IGP01E1000_PHY_PCS_INIT_REG.
6860 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006861static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006863 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864{
6865 int32_t ret_val;
6866 uint16_t phy_data;
6867
6868 DEBUGFUNC("e1000_check_polarity");
6869
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006870 if ((hw->phy_type == e1000_phy_m88) ||
6871 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872 /* return the Polarity bit in the Status register. */
6873 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6874 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006875 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006876 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006877 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6878 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6879 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6880
Auke Kokcd94dd02006-06-27 09:08:22 -07006881 } else if (hw->phy_type == e1000_phy_igp ||
6882 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006883 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006884 /* Read the Status register to check the speed */
6885 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6886 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006887 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888 return ret_val;
6889
6890 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6891 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006892 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893 IGP01E1000_PSSR_SPEED_1000MBPS) {
6894
6895 /* Read the GIG initialization PCS register (0x00B4) */
6896 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6897 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006898 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 return ret_val;
6900
6901 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006902 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6903 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904 } else {
6905 /* For 10 Mbps, read the polarity bit in the status register. (for
6906 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006907 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6908 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006909 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006910 } else if (hw->phy_type == e1000_phy_ife) {
6911 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6912 &phy_data);
6913 if (ret_val)
6914 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006915 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6916 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6917 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006918 }
6919 return E1000_SUCCESS;
6920}
6921
6922/******************************************************************************
6923 * Check if Downshift occured
6924 *
6925 * hw - Struct containing variables accessed by shared code
6926 * downshift - output parameter : 0 - No Downshift ocured.
6927 * 1 - Downshift ocured.
6928 *
6929 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006930 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006931 *
6932 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6933 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6934 * Link Health register. In IGP this bit is latched high, so the driver must
6935 * read it immediately after link is established.
6936 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006937static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938e1000_check_downshift(struct e1000_hw *hw)
6939{
6940 int32_t ret_val;
6941 uint16_t phy_data;
6942
6943 DEBUGFUNC("e1000_check_downshift");
6944
Auke Kokcd94dd02006-06-27 09:08:22 -07006945 if (hw->phy_type == e1000_phy_igp ||
6946 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006947 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006948 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6949 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006950 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006951 return ret_val;
6952
6953 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006954 } else if ((hw->phy_type == e1000_phy_m88) ||
6955 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006956 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6957 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006958 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959 return ret_val;
6960
6961 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6962 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006963 } else if (hw->phy_type == e1000_phy_ife) {
6964 /* e1000_phy_ife supports 10/100 speed only */
6965 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006967
Linus Torvalds1da177e2005-04-16 15:20:36 -07006968 return E1000_SUCCESS;
6969}
6970
6971/*****************************************************************************
6972 *
6973 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6974 * gigabit link is achieved to improve link quality.
6975 *
6976 * hw: Struct containing variables accessed by shared code
6977 *
6978 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6979 * E1000_SUCCESS at any other case.
6980 *
6981 ****************************************************************************/
6982
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006983static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6985 boolean_t link_up)
6986{
6987 int32_t ret_val;
6988 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6989 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6990 {IGP01E1000_PHY_AGC_PARAM_A,
6991 IGP01E1000_PHY_AGC_PARAM_B,
6992 IGP01E1000_PHY_AGC_PARAM_C,
6993 IGP01E1000_PHY_AGC_PARAM_D};
6994 uint16_t min_length, max_length;
6995
6996 DEBUGFUNC("e1000_config_dsp_after_link_change");
6997
Auke Kok8fc897b2006-08-28 14:56:16 -07006998 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999 return E1000_SUCCESS;
7000
Auke Kok8fc897b2006-08-28 14:56:16 -07007001 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07007003 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007004 DEBUGOUT("Error getting link speed and duplex\n");
7005 return ret_val;
7006 }
7007
Auke Kok8fc897b2006-08-28 14:56:16 -07007008 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007009
Auke Kokcd94dd02006-06-27 09:08:22 -07007010 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7011 if (ret_val)
7012 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013
Auke Kok8fc897b2006-08-28 14:56:16 -07007014 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007015 min_length >= e1000_igp_cable_length_50) {
7016
Auke Kok8fc897b2006-08-28 14:56:16 -07007017 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007018 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7019 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007020 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007021 return ret_val;
7022
7023 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7024
7025 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7026 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007027 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007028 return ret_val;
7029 }
7030 hw->dsp_config_state = e1000_dsp_config_activated;
7031 }
7032
Auke Kok8fc897b2006-08-28 14:56:16 -07007033 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034 (min_length < e1000_igp_cable_length_50)) {
7035
7036 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7037 uint32_t idle_errs = 0;
7038
7039 /* clear previous idle error counts */
7040 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7041 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007042 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 return ret_val;
7044
Auke Kok8fc897b2006-08-28 14:56:16 -07007045 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007046 udelay(1000);
7047 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7048 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007049 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007050 return ret_val;
7051
7052 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007053 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007054 hw->ffe_config_state = e1000_ffe_config_active;
7055
7056 ret_val = e1000_write_phy_reg(hw,
7057 IGP01E1000_PHY_DSP_FFE,
7058 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007059 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007060 return ret_val;
7061 break;
7062 }
7063
Auke Kok8fc897b2006-08-28 14:56:16 -07007064 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007065 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7066 }
7067 }
7068 }
7069 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007070 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071 /* Save off the current value of register 0x2F5B to be restored at
7072 * the end of the routines. */
7073 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7074
Auke Kok8fc897b2006-08-28 14:56:16 -07007075 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007076 return ret_val;
7077
7078 /* Disable the PHY transmitter */
7079 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7080
Auke Kok8fc897b2006-08-28 14:56:16 -07007081 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082 return ret_val;
7083
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007084 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085
7086 ret_val = e1000_write_phy_reg(hw, 0x0000,
7087 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007088 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007089 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007090 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007091 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007092 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007093 return ret_val;
7094
7095 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7096 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7097
7098 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007099 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007100 return ret_val;
7101 }
7102
7103 ret_val = e1000_write_phy_reg(hw, 0x0000,
7104 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007105 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007106 return ret_val;
7107
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007108 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007109
7110 /* Now enable the transmitter */
7111 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7112
Auke Kok8fc897b2006-08-28 14:56:16 -07007113 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007114 return ret_val;
7115
7116 hw->dsp_config_state = e1000_dsp_config_enabled;
7117 }
7118
Auke Kok8fc897b2006-08-28 14:56:16 -07007119 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007120 /* Save off the current value of register 0x2F5B to be restored at
7121 * the end of the routines. */
7122 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7123
Auke Kok8fc897b2006-08-28 14:56:16 -07007124 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007125 return ret_val;
7126
7127 /* Disable the PHY transmitter */
7128 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7129
Auke Kok8fc897b2006-08-28 14:56:16 -07007130 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007131 return ret_val;
7132
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007133 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007134
7135 ret_val = e1000_write_phy_reg(hw, 0x0000,
7136 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007137 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007138 return ret_val;
7139 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7140 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007141 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007142 return ret_val;
7143
7144 ret_val = e1000_write_phy_reg(hw, 0x0000,
7145 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007146 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007147 return ret_val;
7148
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007149 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007150
7151 /* Now enable the transmitter */
7152 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7153
Auke Kok8fc897b2006-08-28 14:56:16 -07007154 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007155 return ret_val;
7156
7157 hw->ffe_config_state = e1000_ffe_config_enabled;
7158 }
7159 }
7160 return E1000_SUCCESS;
7161}
7162
7163/*****************************************************************************
7164 * Set PHY to class A mode
7165 * Assumes the following operations will follow to enable the new class mode.
7166 * 1. Do a PHY soft reset
7167 * 2. Restart auto-negotiation or force link.
7168 *
7169 * hw - Struct containing variables accessed by shared code
7170 ****************************************************************************/
7171static int32_t
7172e1000_set_phy_mode(struct e1000_hw *hw)
7173{
7174 int32_t ret_val;
7175 uint16_t eeprom_data;
7176
7177 DEBUGFUNC("e1000_set_phy_mode");
7178
Auke Kok8fc897b2006-08-28 14:56:16 -07007179 if ((hw->mac_type == e1000_82545_rev_3) &&
7180 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007182 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183 return ret_val;
7184 }
7185
Auke Kok8fc897b2006-08-28 14:56:16 -07007186 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7187 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007189 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007190 return ret_val;
7191 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007192 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007193 return ret_val;
7194
7195 hw->phy_reset_disable = FALSE;
7196 }
7197 }
7198
7199 return E1000_SUCCESS;
7200}
7201
7202/*****************************************************************************
7203 *
7204 * This function sets the lplu state according to the active flag. When
7205 * activating lplu this function also disables smart speed and vise versa.
7206 * lplu will not be activated unless the device autonegotiation advertisment
7207 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7208 * hw: Struct containing variables accessed by shared code
7209 * active - true to enable lplu false to disable lplu.
7210 *
7211 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7212 * E1000_SUCCESS at any other case.
7213 *
7214 ****************************************************************************/
7215
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007216static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007217e1000_set_d3_lplu_state(struct e1000_hw *hw,
7218 boolean_t active)
7219{
Auke Kokcd94dd02006-06-27 09:08:22 -07007220 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007221 int32_t ret_val;
7222 uint16_t phy_data;
7223 DEBUGFUNC("e1000_set_d3_lplu_state");
7224
Auke Kokcd94dd02006-06-27 09:08:22 -07007225 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7226 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007227 return E1000_SUCCESS;
7228
7229 /* During driver activity LPLU should not be used or it will attain link
7230 * from the lowest speeds starting from 10Mbps. The capability is used for
7231 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007232 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007233 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007234 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007235 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007236 } else if (hw->mac_type == e1000_ich8lan) {
7237 /* MAC writes into PHY register based on the state transition
7238 * and start auto-negotiation. SW driver can overwrite the settings
7239 * in CSR PHY power control E1000_PHY_CTRL register. */
7240 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007241 } else {
7242 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007243 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007244 return ret_val;
7245 }
7246
Auke Kok8fc897b2006-08-28 14:56:16 -07007247 if (!active) {
7248 if (hw->mac_type == e1000_82541_rev_2 ||
7249 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007250 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7251 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007252 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007253 return ret_val;
7254 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007255 if (hw->mac_type == e1000_ich8lan) {
7256 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7257 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7258 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007259 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7260 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7261 phy_data);
7262 if (ret_val)
7263 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007264 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007266
7267 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7268 * Dx states where the power conservation is most important. During
7269 * driver activity we should enable SmartSpeed, so performance is
7270 * maintained. */
7271 if (hw->smart_speed == e1000_smart_speed_on) {
7272 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7273 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007274 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007275 return ret_val;
7276
7277 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7278 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7279 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007280 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007281 return ret_val;
7282 } else if (hw->smart_speed == e1000_smart_speed_off) {
7283 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7284 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007285 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007286 return ret_val;
7287
7288 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7289 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7290 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007291 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007292 return ret_val;
7293 }
7294
Auke Kok8fc897b2006-08-28 14:56:16 -07007295 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7296 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7297 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298
Auke Kok8fc897b2006-08-28 14:56:16 -07007299 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007300 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007301 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7302 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007303 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007304 return ret_val;
7305 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007306 if (hw->mac_type == e1000_ich8lan) {
7307 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7308 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7309 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007310 phy_data |= IGP02E1000_PM_D3_LPLU;
7311 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7312 phy_data);
7313 if (ret_val)
7314 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007315 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007316 }
7317
7318 /* When LPLU is enabled we should disable SmartSpeed */
7319 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007320 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007321 return ret_val;
7322
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007323 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7324 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007325 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007326 return ret_val;
7327
7328 }
7329 return E1000_SUCCESS;
7330}
7331
7332/*****************************************************************************
7333 *
7334 * This function sets the lplu d0 state according to the active flag. When
7335 * activating lplu this function also disables smart speed and vise versa.
7336 * lplu will not be activated unless the device autonegotiation advertisment
7337 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7338 * hw: Struct containing variables accessed by shared code
7339 * active - true to enable lplu false to disable lplu.
7340 *
7341 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7342 * E1000_SUCCESS at any other case.
7343 *
7344 ****************************************************************************/
7345
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007346static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007347e1000_set_d0_lplu_state(struct e1000_hw *hw,
7348 boolean_t active)
7349{
Auke Kokcd94dd02006-06-27 09:08:22 -07007350 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007351 int32_t ret_val;
7352 uint16_t phy_data;
7353 DEBUGFUNC("e1000_set_d0_lplu_state");
7354
Auke Kok8fc897b2006-08-28 14:56:16 -07007355 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007356 return E1000_SUCCESS;
7357
Auke Kokcd94dd02006-06-27 09:08:22 -07007358 if (hw->mac_type == e1000_ich8lan) {
7359 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7360 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007361 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007362 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007363 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007364 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007365
7366 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007367 if (hw->mac_type == e1000_ich8lan) {
7368 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7369 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7370 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007371 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7372 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7373 if (ret_val)
7374 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007375 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007376
7377 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7378 * Dx states where the power conservation is most important. During
7379 * driver activity we should enable SmartSpeed, so performance is
7380 * maintained. */
7381 if (hw->smart_speed == e1000_smart_speed_on) {
7382 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7383 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007384 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007385 return ret_val;
7386
7387 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7388 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7389 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007390 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007391 return ret_val;
7392 } else if (hw->smart_speed == e1000_smart_speed_off) {
7393 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7394 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007395 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007396 return ret_val;
7397
7398 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7399 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7400 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007401 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007402 return ret_val;
7403 }
7404
7405
7406 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007407
Auke Kokcd94dd02006-06-27 09:08:22 -07007408 if (hw->mac_type == e1000_ich8lan) {
7409 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7410 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7411 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007412 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007413 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7414 if (ret_val)
7415 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007416 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007417
Linus Torvalds1da177e2005-04-16 15:20:36 -07007418 /* When LPLU is enabled we should disable SmartSpeed */
7419 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007420 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007421 return ret_val;
7422
7423 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7424 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007425 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007426 return ret_val;
7427
7428 }
7429 return E1000_SUCCESS;
7430}
7431
7432/******************************************************************************
7433 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7434 *
7435 * hw - Struct containing variables accessed by shared code
7436 *****************************************************************************/
7437static int32_t
7438e1000_set_vco_speed(struct e1000_hw *hw)
7439{
7440 int32_t ret_val;
7441 uint16_t default_page = 0;
7442 uint16_t phy_data;
7443
7444 DEBUGFUNC("e1000_set_vco_speed");
7445
Auke Kok8fc897b2006-08-28 14:56:16 -07007446 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007447 case e1000_82545_rev_3:
7448 case e1000_82546_rev_3:
7449 break;
7450 default:
7451 return E1000_SUCCESS;
7452 }
7453
7454 /* Set PHY register 30, page 5, bit 8 to 0 */
7455
7456 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007457 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007458 return ret_val;
7459
7460 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007461 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007462 return ret_val;
7463
7464 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007465 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007466 return ret_val;
7467
7468 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7469 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007470 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007471 return ret_val;
7472
7473 /* Set PHY register 30, page 4, bit 11 to 1 */
7474
7475 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007476 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007477 return ret_val;
7478
7479 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007480 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007481 return ret_val;
7482
7483 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7484 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007485 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007486 return ret_val;
7487
7488 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007489 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007490 return ret_val;
7491
7492 return E1000_SUCCESS;
7493}
7494
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007495
7496/*****************************************************************************
7497 * This function reads the cookie from ARC ram.
7498 *
7499 * returns: - E1000_SUCCESS .
7500 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007501static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007502e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7503{
7504 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007505 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007506 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7507
7508 length = (length >> 2);
7509 offset = (offset >> 2);
7510
7511 for (i = 0; i < length; i++) {
7512 *((uint32_t *) buffer + i) =
7513 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7514 }
7515 return E1000_SUCCESS;
7516}
7517
7518
7519/*****************************************************************************
7520 * This function checks whether the HOST IF is enabled for command operaton
7521 * and also checks whether the previous command is completed.
7522 * It busy waits in case of previous command is not completed.
7523 *
Auke Kok76c224b2006-05-23 13:36:06 -07007524 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007525 * timeout
7526 * - E1000_SUCCESS for success.
7527 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007528static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007529e1000_mng_enable_host_if(struct e1000_hw * hw)
7530{
7531 uint32_t hicr;
7532 uint8_t i;
7533
7534 /* Check that the host interface is enabled. */
7535 hicr = E1000_READ_REG(hw, HICR);
7536 if ((hicr & E1000_HICR_EN) == 0) {
7537 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7538 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7539 }
7540 /* check the previous command is completed */
7541 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7542 hicr = E1000_READ_REG(hw, HICR);
7543 if (!(hicr & E1000_HICR_C))
7544 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007545 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007546 }
7547
Auke Kok76c224b2006-05-23 13:36:06 -07007548 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007549 DEBUGOUT("Previous command timeout failed .\n");
7550 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7551 }
7552 return E1000_SUCCESS;
7553}
7554
7555/*****************************************************************************
7556 * This function writes the buffer content at the offset given on the host if.
7557 * It also does alignment considerations to do the writes in most efficient way.
7558 * Also fills up the sum of the buffer in *buffer parameter.
7559 *
7560 * returns - E1000_SUCCESS for success.
7561 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007562static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007563e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7564 uint16_t length, uint16_t offset, uint8_t *sum)
7565{
7566 uint8_t *tmp;
7567 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007568 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007569 uint16_t remaining, i, j, prev_bytes;
7570
7571 /* sum = only sum of the data and it is not checksum */
7572
7573 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7574 return -E1000_ERR_PARAM;
7575 }
7576
7577 tmp = (uint8_t *)&data;
7578 prev_bytes = offset & 0x3;
7579 offset &= 0xFFFC;
7580 offset >>= 2;
7581
7582 if (prev_bytes) {
7583 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7584 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7585 *(tmp + j) = *bufptr++;
7586 *sum += *(tmp + j);
7587 }
7588 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7589 length -= j - prev_bytes;
7590 offset++;
7591 }
7592
7593 remaining = length & 0x3;
7594 length -= remaining;
7595
7596 /* Calculate length in DWORDs */
7597 length >>= 2;
7598
7599 /* The device driver writes the relevant command block into the
7600 * ram area. */
7601 for (i = 0; i < length; i++) {
7602 for (j = 0; j < sizeof(uint32_t); j++) {
7603 *(tmp + j) = *bufptr++;
7604 *sum += *(tmp + j);
7605 }
7606
7607 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7608 }
7609 if (remaining) {
7610 for (j = 0; j < sizeof(uint32_t); j++) {
7611 if (j < remaining)
7612 *(tmp + j) = *bufptr++;
7613 else
7614 *(tmp + j) = 0;
7615
7616 *sum += *(tmp + j);
7617 }
7618 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7619 }
7620
7621 return E1000_SUCCESS;
7622}
7623
7624
7625/*****************************************************************************
7626 * This function writes the command header after does the checksum calculation.
7627 *
7628 * returns - E1000_SUCCESS for success.
7629 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007630static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007631e1000_mng_write_cmd_header(struct e1000_hw * hw,
7632 struct e1000_host_mng_command_header * hdr)
7633{
7634 uint16_t i;
7635 uint8_t sum;
7636 uint8_t *buffer;
7637
7638 /* Write the whole command header structure which includes sum of
7639 * the buffer */
7640
7641 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7642
7643 sum = hdr->checksum;
7644 hdr->checksum = 0;
7645
7646 buffer = (uint8_t *) hdr;
7647 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007648 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007649 sum += buffer[i];
7650
7651 hdr->checksum = 0 - sum;
7652
7653 length >>= 2;
7654 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007655 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007656 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007657 E1000_WRITE_FLUSH(hw);
7658 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007659
7660 return E1000_SUCCESS;
7661}
7662
7663
7664/*****************************************************************************
7665 * This function indicates to ARC that a new command is pending which completes
7666 * one write operation by the driver.
7667 *
7668 * returns - E1000_SUCCESS for success.
7669 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007670static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007671e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007672{
7673 uint32_t hicr;
7674
7675 hicr = E1000_READ_REG(hw, HICR);
7676 /* Setting this bit tells the ARC that a new command is pending. */
7677 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7678
7679 return E1000_SUCCESS;
7680}
7681
7682
7683/*****************************************************************************
7684 * This function checks the mode of the firmware.
7685 *
7686 * returns - TRUE when the mode is IAMT or FALSE.
7687 ****************************************************************************/
7688boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007689e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007690{
7691 uint32_t fwsm;
7692
7693 fwsm = E1000_READ_REG(hw, FWSM);
7694
Auke Kokcd94dd02006-06-27 09:08:22 -07007695 if (hw->mac_type == e1000_ich8lan) {
7696 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7697 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7698 return TRUE;
7699 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7700 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007701 return TRUE;
7702
7703 return FALSE;
7704}
7705
7706
7707/*****************************************************************************
7708 * This function writes the dhcp info .
7709 ****************************************************************************/
7710int32_t
7711e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007712 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007713{
7714 int32_t ret_val;
7715 struct e1000_host_mng_command_header hdr;
7716
7717 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7718 hdr.command_length = length;
7719 hdr.reserved1 = 0;
7720 hdr.reserved2 = 0;
7721 hdr.checksum = 0;
7722
7723 ret_val = e1000_mng_enable_host_if(hw);
7724 if (ret_val == E1000_SUCCESS) {
7725 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7726 &(hdr.checksum));
7727 if (ret_val == E1000_SUCCESS) {
7728 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7729 if (ret_val == E1000_SUCCESS)
7730 ret_val = e1000_mng_write_commit(hw);
7731 }
7732 }
7733 return ret_val;
7734}
7735
7736
7737/*****************************************************************************
7738 * This function calculates the checksum.
7739 *
7740 * returns - checksum of buffer contents.
7741 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007742static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007743e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7744{
7745 uint8_t sum = 0;
7746 uint32_t i;
7747
7748 if (!buffer)
7749 return 0;
7750
7751 for (i=0; i < length; i++)
7752 sum += buffer[i];
7753
7754 return (uint8_t) (0 - sum);
7755}
7756
7757/*****************************************************************************
7758 * This function checks whether tx pkt filtering needs to be enabled or not.
7759 *
7760 * returns - TRUE for packet filtering or FALSE.
7761 ****************************************************************************/
7762boolean_t
7763e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7764{
7765 /* called in init as well as watchdog timer functions */
7766
7767 int32_t ret_val, checksum;
7768 boolean_t tx_filter = FALSE;
7769 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7770 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7771
7772 if (e1000_check_mng_mode(hw)) {
7773 ret_val = e1000_mng_enable_host_if(hw);
7774 if (ret_val == E1000_SUCCESS) {
7775 ret_val = e1000_host_if_read_cookie(hw, buffer);
7776 if (ret_val == E1000_SUCCESS) {
7777 checksum = hdr->checksum;
7778 hdr->checksum = 0;
7779 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7780 checksum == e1000_calculate_mng_checksum((char *)buffer,
7781 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7782 if (hdr->status &
7783 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7784 tx_filter = TRUE;
7785 } else
7786 tx_filter = TRUE;
7787 } else
7788 tx_filter = TRUE;
7789 }
7790 }
7791
7792 hw->tx_pkt_filtering = tx_filter;
7793 return tx_filter;
7794}
7795
7796/******************************************************************************
7797 * Verifies the hardware needs to allow ARPs to be processed by the host
7798 *
7799 * hw - Struct containing variables accessed by shared code
7800 *
7801 * returns: - TRUE/FALSE
7802 *
7803 *****************************************************************************/
7804uint32_t
7805e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7806{
7807 uint32_t manc;
7808 uint32_t fwsm, factps;
7809
7810 if (hw->asf_firmware_present) {
7811 manc = E1000_READ_REG(hw, MANC);
7812
7813 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7814 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7815 return FALSE;
7816 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7817 fwsm = E1000_READ_REG(hw, FWSM);
7818 factps = E1000_READ_REG(hw, FACTPS);
7819
7820 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7821 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7822 (factps & E1000_FACTPS_MNGCG))
7823 return TRUE;
7824 } else
7825 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7826 return TRUE;
7827 }
7828 return FALSE;
7829}
7830
Linus Torvalds1da177e2005-04-16 15:20:36 -07007831static int32_t
7832e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7833{
7834 int32_t ret_val;
7835 uint16_t mii_status_reg;
7836 uint16_t i;
7837
7838 /* Polarity reversal workaround for forced 10F/10H links. */
7839
7840 /* Disable the transmitter on the PHY */
7841
7842 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007843 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007844 return ret_val;
7845 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007846 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007847 return ret_val;
7848
7849 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007850 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007851 return ret_val;
7852
7853 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007854 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007855 /* Read the MII Status Register and wait for Link Status bit
7856 * to be clear.
7857 */
7858
7859 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007860 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007861 return ret_val;
7862
7863 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007864 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007865 return ret_val;
7866
Auke Kok8fc897b2006-08-28 14:56:16 -07007867 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007868 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007869 }
7870
7871 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007872 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007873
7874 /* Now we will re-enable th transmitter on the PHY */
7875
7876 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007877 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007878 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007879 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007880 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007881 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007882 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007883 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007884 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007885 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007886 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007887 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007888 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007889 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007890 return ret_val;
7891
7892 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007893 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007894 return ret_val;
7895
7896 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007897 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007898 /* Read the MII Status Register and wait for Link Status bit
7899 * to be set.
7900 */
7901
7902 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007903 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007904 return ret_val;
7905
7906 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007907 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007908 return ret_val;
7909
Auke Kok8fc897b2006-08-28 14:56:16 -07007910 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007911 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007912 }
7913 return E1000_SUCCESS;
7914}
7915
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007916/***************************************************************************
7917 *
7918 * Disables PCI-Express master access.
7919 *
7920 * hw: Struct containing variables accessed by shared code
7921 *
7922 * returns: - none.
7923 *
7924 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007925static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007926e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7927{
7928 uint32_t ctrl;
7929
7930 DEBUGFUNC("e1000_set_pci_express_master_disable");
7931
7932 if (hw->bus_type != e1000_bus_type_pci_express)
7933 return;
7934
7935 ctrl = E1000_READ_REG(hw, CTRL);
7936 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7937 E1000_WRITE_REG(hw, CTRL, ctrl);
7938}
7939
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007940/*******************************************************************************
7941 *
7942 * Disables PCI-Express master access and verifies there are no pending requests
7943 *
7944 * hw: Struct containing variables accessed by shared code
7945 *
7946 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7947 * caused the master requests to be disabled.
7948 * E1000_SUCCESS master requests disabled.
7949 *
7950 ******************************************************************************/
7951int32_t
7952e1000_disable_pciex_master(struct e1000_hw *hw)
7953{
7954 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7955
7956 DEBUGFUNC("e1000_disable_pciex_master");
7957
7958 if (hw->bus_type != e1000_bus_type_pci_express)
7959 return E1000_SUCCESS;
7960
7961 e1000_set_pci_express_master_disable(hw);
7962
Auke Kok8fc897b2006-08-28 14:56:16 -07007963 while (timeout) {
7964 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007965 break;
7966 else
7967 udelay(100);
7968 timeout--;
7969 }
7970
Auke Kok8fc897b2006-08-28 14:56:16 -07007971 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007972 DEBUGOUT("Master requests are pending.\n");
7973 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7974 }
7975
7976 return E1000_SUCCESS;
7977}
7978
7979/*******************************************************************************
7980 *
7981 * Check for EEPROM Auto Read bit done.
7982 *
7983 * hw: Struct containing variables accessed by shared code
7984 *
7985 * returns: - E1000_ERR_RESET if fail to reset MAC
7986 * E1000_SUCCESS at any other case.
7987 *
7988 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007989static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007990e1000_get_auto_rd_done(struct e1000_hw *hw)
7991{
7992 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7993
7994 DEBUGFUNC("e1000_get_auto_rd_done");
7995
7996 switch (hw->mac_type) {
7997 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007998 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007999 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008000 case e1000_82571:
8001 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008002 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008003 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008004 case e1000_ich8lan:
8005 while (timeout) {
8006 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8007 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008008 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008009 timeout--;
8010 }
8011
Auke Kok8fc897b2006-08-28 14:56:16 -07008012 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008013 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8014 return -E1000_ERR_RESET;
8015 }
8016 break;
8017 }
8018
Jeff Kirsherfd803242005-12-13 00:06:22 -05008019 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8020 * Need to wait for PHY configuration completion before accessing NVM
8021 * and PHY. */
8022 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008023 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008024
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008025 return E1000_SUCCESS;
8026}
8027
8028/***************************************************************************
8029 * Checks if the PHY configuration is done
8030 *
8031 * hw: Struct containing variables accessed by shared code
8032 *
8033 * returns: - E1000_ERR_RESET if fail to reset MAC
8034 * E1000_SUCCESS at any other case.
8035 *
8036 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008037static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008038e1000_get_phy_cfg_done(struct e1000_hw *hw)
8039{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008040 int32_t timeout = PHY_CFG_TIMEOUT;
8041 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8042
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008043 DEBUGFUNC("e1000_get_phy_cfg_done");
8044
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008045 switch (hw->mac_type) {
8046 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008047 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008048 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008049 case e1000_80003es2lan:
8050 /* Separate *_CFG_DONE_* bit for each port */
8051 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8052 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8053 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008054 case e1000_82571:
8055 case e1000_82572:
8056 while (timeout) {
8057 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8058 break;
8059 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008060 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008061 timeout--;
8062 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008063 if (!timeout) {
8064 DEBUGOUT("MNG configuration cycle has not completed.\n");
8065 return -E1000_ERR_RESET;
8066 }
8067 break;
8068 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008069
8070 return E1000_SUCCESS;
8071}
8072
8073/***************************************************************************
8074 *
8075 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8076 * adapter or Eeprom access.
8077 *
8078 * hw: Struct containing variables accessed by shared code
8079 *
8080 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8081 * E1000_SUCCESS at any other case.
8082 *
8083 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008084static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008085e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8086{
8087 int32_t timeout;
8088 uint32_t swsm;
8089
8090 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8091
Auke Kok8fc897b2006-08-28 14:56:16 -07008092 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008093 return E1000_SUCCESS;
8094
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008095 if (hw->mac_type == e1000_80003es2lan) {
8096 /* Get the SW semaphore. */
8097 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8098 return -E1000_ERR_EEPROM;
8099 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008100
8101 /* Get the FW semaphore. */
8102 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008103 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008104 swsm = E1000_READ_REG(hw, SWSM);
8105 swsm |= E1000_SWSM_SWESMBI;
8106 E1000_WRITE_REG(hw, SWSM, swsm);
8107 /* if we managed to set the bit we got the semaphore. */
8108 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008109 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008110 break;
8111
8112 udelay(50);
8113 timeout--;
8114 }
8115
Auke Kok8fc897b2006-08-28 14:56:16 -07008116 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008117 /* Release semaphores */
8118 e1000_put_hw_eeprom_semaphore(hw);
8119 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8120 return -E1000_ERR_EEPROM;
8121 }
8122
8123 return E1000_SUCCESS;
8124}
8125
8126/***************************************************************************
8127 * This function clears HW semaphore bits.
8128 *
8129 * hw: Struct containing variables accessed by shared code
8130 *
8131 * returns: - None.
8132 *
8133 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008134static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008135e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8136{
8137 uint32_t swsm;
8138
8139 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8140
Auke Kok8fc897b2006-08-28 14:56:16 -07008141 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008142 return;
8143
8144 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008145 if (hw->mac_type == e1000_80003es2lan) {
8146 /* Release both semaphores. */
8147 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8148 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008149 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008150 E1000_WRITE_REG(hw, SWSM, swsm);
8151}
8152
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008153/***************************************************************************
8154 *
8155 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8156 *
8157 * hw: Struct containing variables accessed by shared code
8158 *
8159 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8160 * E1000_SUCCESS at any other case.
8161 *
8162 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008163static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008164e1000_get_software_semaphore(struct e1000_hw *hw)
8165{
8166 int32_t timeout = hw->eeprom.word_size + 1;
8167 uint32_t swsm;
8168
8169 DEBUGFUNC("e1000_get_software_semaphore");
8170
Nicholas Nunley35574762006-09-27 12:53:34 -07008171 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008172 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008173 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008174
Auke Kok8fc897b2006-08-28 14:56:16 -07008175 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008176 swsm = E1000_READ_REG(hw, SWSM);
8177 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008178 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008179 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008180 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008181 timeout--;
8182 }
8183
Auke Kok8fc897b2006-08-28 14:56:16 -07008184 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008185 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8186 return -E1000_ERR_RESET;
8187 }
8188
8189 return E1000_SUCCESS;
8190}
8191
8192/***************************************************************************
8193 *
8194 * Release semaphore bit (SMBI).
8195 *
8196 * hw: Struct containing variables accessed by shared code
8197 *
8198 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008199static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008200e1000_release_software_semaphore(struct e1000_hw *hw)
8201{
8202 uint32_t swsm;
8203
8204 DEBUGFUNC("e1000_release_software_semaphore");
8205
Nicholas Nunley35574762006-09-27 12:53:34 -07008206 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008207 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008208 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008209
8210 swsm = E1000_READ_REG(hw, SWSM);
8211 /* Release the SW semaphores.*/
8212 swsm &= ~E1000_SWSM_SMBI;
8213 E1000_WRITE_REG(hw, SWSM, swsm);
8214}
8215
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008216/******************************************************************************
8217 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8218 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8219 * the caller to figure out how to deal with it.
8220 *
8221 * hw - Struct containing variables accessed by shared code
8222 *
8223 * returns: - E1000_BLK_PHY_RESET
8224 * E1000_SUCCESS
8225 *
8226 *****************************************************************************/
8227int32_t
8228e1000_check_phy_reset_block(struct e1000_hw *hw)
8229{
8230 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008231 uint32_t fwsm = 0;
8232
8233 if (hw->mac_type == e1000_ich8lan) {
8234 fwsm = E1000_READ_REG(hw, FWSM);
8235 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8236 : E1000_BLK_PHY_RESET;
8237 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008238
8239 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008240 manc = E1000_READ_REG(hw, MANC);
8241 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008242 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008243}
8244
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008245static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008246e1000_arc_subsystem_valid(struct e1000_hw *hw)
8247{
8248 uint32_t fwsm;
8249
8250 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8251 * may not be provided a DMA clock when no manageability features are
8252 * enabled. We do not want to perform any reads/writes to these registers
8253 * if this is the case. We read FWSM to determine the manageability mode.
8254 */
8255 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008256 case e1000_82571:
8257 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008258 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008259 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008260 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008261 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008262 return TRUE;
8263 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008264 case e1000_ich8lan:
8265 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008266 default:
8267 break;
8268 }
8269 return FALSE;
8270}
8271
8272
Auke Kokd37ea5d2006-06-27 09:08:17 -07008273/******************************************************************************
8274 * Configure PCI-Ex no-snoop
8275 *
8276 * hw - Struct containing variables accessed by shared code.
8277 * no_snoop - Bitmap of no-snoop events.
8278 *
8279 * returns: E1000_SUCCESS
8280 *
8281 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008282static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008283e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8284{
8285 uint32_t gcr_reg = 0;
8286
8287 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8288
8289 if (hw->bus_type == e1000_bus_type_unknown)
8290 e1000_get_bus_info(hw);
8291
8292 if (hw->bus_type != e1000_bus_type_pci_express)
8293 return E1000_SUCCESS;
8294
8295 if (no_snoop) {
8296 gcr_reg = E1000_READ_REG(hw, GCR);
8297 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8298 gcr_reg |= no_snoop;
8299 E1000_WRITE_REG(hw, GCR, gcr_reg);
8300 }
8301 if (hw->mac_type == e1000_ich8lan) {
8302 uint32_t ctrl_ext;
8303
8304 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8305
8306 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8307 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8308 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8309 }
8310
8311 return E1000_SUCCESS;
8312}
8313
8314/***************************************************************************
8315 *
8316 * Get software semaphore FLAG bit (SWFLAG).
8317 * SWFLAG is used to synchronize the access to all shared resource between
8318 * SW, FW and HW.
8319 *
8320 * hw: Struct containing variables accessed by shared code
8321 *
8322 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008323static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008324e1000_get_software_flag(struct e1000_hw *hw)
8325{
8326 int32_t timeout = PHY_CFG_TIMEOUT;
8327 uint32_t extcnf_ctrl;
8328
8329 DEBUGFUNC("e1000_get_software_flag");
8330
8331 if (hw->mac_type == e1000_ich8lan) {
8332 while (timeout) {
8333 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8334 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8335 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8336
8337 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8338 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8339 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008340 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008341 timeout--;
8342 }
8343
8344 if (!timeout) {
8345 DEBUGOUT("FW or HW locks the resource too long.\n");
8346 return -E1000_ERR_CONFIG;
8347 }
8348 }
8349
8350 return E1000_SUCCESS;
8351}
8352
8353/***************************************************************************
8354 *
8355 * Release software semaphore FLAG bit (SWFLAG).
8356 * SWFLAG is used to synchronize the access to all shared resource between
8357 * SW, FW and HW.
8358 *
8359 * hw: Struct containing variables accessed by shared code
8360 *
8361 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008362static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008363e1000_release_software_flag(struct e1000_hw *hw)
8364{
8365 uint32_t extcnf_ctrl;
8366
8367 DEBUGFUNC("e1000_release_software_flag");
8368
8369 if (hw->mac_type == e1000_ich8lan) {
8370 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8371 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8372 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8373 }
8374
8375 return;
8376}
8377
Auke Kokd37ea5d2006-06-27 09:08:17 -07008378/******************************************************************************
8379 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8380 * register.
8381 *
8382 * hw - Struct containing variables accessed by shared code
8383 * offset - offset of word in the EEPROM to read
8384 * data - word read from the EEPROM
8385 * words - number of words to read
8386 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008387static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008388e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8389 uint16_t *data)
8390{
8391 int32_t error = E1000_SUCCESS;
8392 uint32_t flash_bank = 0;
8393 uint32_t act_offset = 0;
8394 uint32_t bank_offset = 0;
8395 uint16_t word = 0;
8396 uint16_t i = 0;
8397
8398 /* We need to know which is the valid flash bank. In the event
8399 * that we didn't allocate eeprom_shadow_ram, we may not be
8400 * managing flash_bank. So it cannot be trusted and needs
8401 * to be updated with each read.
8402 */
8403 /* Value of bit 22 corresponds to the flash bank we're on. */
8404 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8405
8406 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8407 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8408
8409 error = e1000_get_software_flag(hw);
8410 if (error != E1000_SUCCESS)
8411 return error;
8412
8413 for (i = 0; i < words; i++) {
8414 if (hw->eeprom_shadow_ram != NULL &&
8415 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8416 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8417 } else {
8418 /* The NVM part needs a byte offset, hence * 2 */
8419 act_offset = bank_offset + ((offset + i) * 2);
8420 error = e1000_read_ich8_word(hw, act_offset, &word);
8421 if (error != E1000_SUCCESS)
8422 break;
8423 data[i] = word;
8424 }
8425 }
8426
8427 e1000_release_software_flag(hw);
8428
8429 return error;
8430}
8431
8432/******************************************************************************
8433 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8434 * register. Actually, writes are written to the shadow ram cache in the hw
8435 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8436 * the NVM, which occurs when the NVM checksum is updated.
8437 *
8438 * hw - Struct containing variables accessed by shared code
8439 * offset - offset of word in the EEPROM to write
8440 * words - number of words to write
8441 * data - words to write to the EEPROM
8442 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008443static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008444e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8445 uint16_t *data)
8446{
8447 uint32_t i = 0;
8448 int32_t error = E1000_SUCCESS;
8449
8450 error = e1000_get_software_flag(hw);
8451 if (error != E1000_SUCCESS)
8452 return error;
8453
8454 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8455 * allocated. Subsequent reads to the modified words are read from
8456 * this cached structure as well. Writes will only go into this
8457 * cached structure unless it's followed by a call to
8458 * e1000_update_eeprom_checksum() where it will commit the changes
8459 * and clear the "modified" field.
8460 */
8461 if (hw->eeprom_shadow_ram != NULL) {
8462 for (i = 0; i < words; i++) {
8463 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8464 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8465 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8466 } else {
8467 error = -E1000_ERR_EEPROM;
8468 break;
8469 }
8470 }
8471 } else {
8472 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8473 * as they don't perform any NVM writes. An attempt in doing so
8474 * will result in this error.
8475 */
8476 error = -E1000_ERR_EEPROM;
8477 }
8478
8479 e1000_release_software_flag(hw);
8480
8481 return error;
8482}
8483
8484/******************************************************************************
8485 * This function does initial flash setup so that a new read/write/erase cycle
8486 * can be started.
8487 *
8488 * hw - The pointer to the hw structure
8489 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008490static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008491e1000_ich8_cycle_init(struct e1000_hw *hw)
8492{
8493 union ich8_hws_flash_status hsfsts;
8494 int32_t error = E1000_ERR_EEPROM;
8495 int32_t i = 0;
8496
8497 DEBUGFUNC("e1000_ich8_cycle_init");
8498
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008499 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008500
8501 /* May be check the Flash Des Valid bit in Hw status */
8502 if (hsfsts.hsf_status.fldesvalid == 0) {
8503 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8504 return error;
8505 }
8506
8507 /* Clear FCERR in Hw status by writing 1 */
8508 /* Clear DAEL in Hw status by writing a 1 */
8509 hsfsts.hsf_status.flcerr = 1;
8510 hsfsts.hsf_status.dael = 1;
8511
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008512 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008513
8514 /* Either we should have a hardware SPI cycle in progress bit to check
8515 * against, in order to start a new cycle or FDONE bit should be changed
8516 * in the hardware so that it is 1 after harware reset, which can then be
8517 * used as an indication whether a cycle is in progress or has been
8518 * completed .. we should also have some software semaphore mechanism to
8519 * guard FDONE or the cycle in progress bit so that two threads access to
8520 * those bits can be sequentiallized or a way so that 2 threads dont
8521 * start the cycle at the same time */
8522
8523 if (hsfsts.hsf_status.flcinprog == 0) {
8524 /* There is no cycle running at present, so we can start a cycle */
8525 /* Begin by setting Flash Cycle Done. */
8526 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008527 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008528 error = E1000_SUCCESS;
8529 } else {
8530 /* otherwise poll for sometime so the current cycle has a chance
8531 * to end before giving up. */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008532 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8533 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008534 if (hsfsts.hsf_status.flcinprog == 0) {
8535 error = E1000_SUCCESS;
8536 break;
8537 }
8538 udelay(1);
8539 }
8540 if (error == E1000_SUCCESS) {
8541 /* Successful in waiting for previous cycle to timeout,
8542 * now set the Flash Cycle Done. */
8543 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008544 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008545 } else {
8546 DEBUGOUT("Flash controller busy, cannot get access");
8547 }
8548 }
8549 return error;
8550}
8551
8552/******************************************************************************
8553 * This function starts a flash cycle and waits for its completion
8554 *
8555 * hw - The pointer to the hw structure
8556 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008557static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008558e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8559{
8560 union ich8_hws_flash_ctrl hsflctl;
8561 union ich8_hws_flash_status hsfsts;
8562 int32_t error = E1000_ERR_EEPROM;
8563 uint32_t i = 0;
8564
8565 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008566 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008567 hsflctl.hsf_ctrl.flcgo = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008568 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008569
8570 /* wait till FDONE bit is set to 1 */
8571 do {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008572 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008573 if (hsfsts.hsf_status.flcdone == 1)
8574 break;
8575 udelay(1);
8576 i++;
8577 } while (i < timeout);
8578 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8579 error = E1000_SUCCESS;
8580 }
8581 return error;
8582}
8583
8584/******************************************************************************
8585 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8586 *
8587 * hw - The pointer to the hw structure
8588 * index - The index of the byte or word to read.
8589 * size - Size of data to read, 1=byte 2=word
8590 * data - Pointer to the word to store the value read.
8591 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008592static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008593e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8594 uint32_t size, uint16_t* data)
8595{
8596 union ich8_hws_flash_status hsfsts;
8597 union ich8_hws_flash_ctrl hsflctl;
8598 uint32_t flash_linear_address;
8599 uint32_t flash_data = 0;
8600 int32_t error = -E1000_ERR_EEPROM;
8601 int32_t count = 0;
8602
8603 DEBUGFUNC("e1000_read_ich8_data");
8604
8605 if (size < 1 || size > 2 || data == 0x0 ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008606 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008607 return error;
8608
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008609 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008610 hw->flash_base_addr;
8611
8612 do {
8613 udelay(1);
8614 /* Steps */
8615 error = e1000_ich8_cycle_init(hw);
8616 if (error != E1000_SUCCESS)
8617 break;
8618
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008619 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008620 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8621 hsflctl.hsf_ctrl.fldbcount = size - 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008622 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8623 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008624
8625 /* Write the last 24 bits of index into Flash Linear address field in
8626 * Flash Address */
8627 /* TODO: TBD maybe check the index against the size of flash */
8628
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008629 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008630
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008631 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008632
8633 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8634 * sequence a few more times, else read in (shift in) the Flash Data0,
8635 * the order is least significant byte first msb to lsb */
8636 if (error == E1000_SUCCESS) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008637 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008638 if (size == 1) {
8639 *data = (uint8_t)(flash_data & 0x000000FF);
8640 } else if (size == 2) {
8641 *data = (uint16_t)(flash_data & 0x0000FFFF);
8642 }
8643 break;
8644 } else {
8645 /* If we've gotten here, then things are probably completely hosed,
8646 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008647 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008648 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008649 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008650 if (hsfsts.hsf_status.flcerr == 1) {
8651 /* Repeat for some time before giving up. */
8652 continue;
8653 } else if (hsfsts.hsf_status.flcdone == 0) {
8654 DEBUGOUT("Timeout error - flash cycle did not complete.");
8655 break;
8656 }
8657 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008658 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008659
8660 return error;
8661}
8662
8663/******************************************************************************
8664 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8665 *
8666 * hw - The pointer to the hw structure
8667 * index - The index of the byte/word to read.
8668 * size - Size of data to read, 1=byte 2=word
8669 * data - The byte(s) to write to the NVM.
8670 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008671static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008672e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8673 uint16_t data)
8674{
8675 union ich8_hws_flash_status hsfsts;
8676 union ich8_hws_flash_ctrl hsflctl;
8677 uint32_t flash_linear_address;
8678 uint32_t flash_data = 0;
8679 int32_t error = -E1000_ERR_EEPROM;
8680 int32_t count = 0;
8681
8682 DEBUGFUNC("e1000_write_ich8_data");
8683
8684 if (size < 1 || size > 2 || data > size * 0xff ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008685 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008686 return error;
8687
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008688 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008689 hw->flash_base_addr;
8690
8691 do {
8692 udelay(1);
8693 /* Steps */
8694 error = e1000_ich8_cycle_init(hw);
8695 if (error != E1000_SUCCESS)
8696 break;
8697
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008698 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008699 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8700 hsflctl.hsf_ctrl.fldbcount = size -1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008701 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8702 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008703
8704 /* Write the last 24 bits of index into Flash Linear address field in
8705 * Flash Address */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008706 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008707
8708 if (size == 1)
8709 flash_data = (uint32_t)data & 0x00FF;
8710 else
8711 flash_data = (uint32_t)data;
8712
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008713 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008714
8715 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8716 * sequence a few more times else done */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008717 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008718 if (error == E1000_SUCCESS) {
8719 break;
8720 } else {
8721 /* If we're here, then things are most likely completely hosed,
8722 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008723 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008724 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008725 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008726 if (hsfsts.hsf_status.flcerr == 1) {
8727 /* Repeat for some time before giving up. */
8728 continue;
8729 } else if (hsfsts.hsf_status.flcdone == 0) {
8730 DEBUGOUT("Timeout error - flash cycle did not complete.");
8731 break;
8732 }
8733 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008734 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008735
8736 return error;
8737}
8738
8739/******************************************************************************
8740 * Reads a single byte from the NVM using the ICH8 flash access registers.
8741 *
8742 * hw - pointer to e1000_hw structure
8743 * index - The index of the byte to read.
8744 * data - Pointer to a byte to store the value read.
8745 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008746static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008747e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8748{
8749 int32_t status = E1000_SUCCESS;
8750 uint16_t word = 0;
8751
8752 status = e1000_read_ich8_data(hw, index, 1, &word);
8753 if (status == E1000_SUCCESS) {
8754 *data = (uint8_t)word;
8755 }
8756
8757 return status;
8758}
8759
8760/******************************************************************************
8761 * Writes a single byte to the NVM using the ICH8 flash access registers.
8762 * Performs verification by reading back the value and then going through
8763 * a retry algorithm before giving up.
8764 *
8765 * hw - pointer to e1000_hw structure
8766 * index - The index of the byte to write.
8767 * byte - The byte to write to the NVM.
8768 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008769static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008770e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8771{
8772 int32_t error = E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008773 int32_t program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008774
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008775 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008776
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008777 error = e1000_write_ich8_byte(hw, index, byte);
8778
8779 if (error != E1000_SUCCESS) {
8780 for (program_retries = 0; program_retries < 100; program_retries++) {
8781 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8782 error = e1000_write_ich8_byte(hw, index, byte);
8783 udelay(100);
8784 if (error == E1000_SUCCESS)
8785 break;
8786 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008787 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008788
Auke Kokd37ea5d2006-06-27 09:08:17 -07008789 if (program_retries == 100)
8790 error = E1000_ERR_EEPROM;
8791
8792 return error;
8793}
8794
8795/******************************************************************************
8796 * Writes a single byte to the NVM using the ICH8 flash access registers.
8797 *
8798 * hw - pointer to e1000_hw structure
8799 * index - The index of the byte to read.
8800 * data - The byte to write to the NVM.
8801 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008802static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008803e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8804{
8805 int32_t status = E1000_SUCCESS;
8806 uint16_t word = (uint16_t)data;
8807
8808 status = e1000_write_ich8_data(hw, index, 1, word);
8809
8810 return status;
8811}
8812
8813/******************************************************************************
8814 * Reads a word from the NVM using the ICH8 flash access registers.
8815 *
8816 * hw - pointer to e1000_hw structure
8817 * index - The starting byte index of the word to read.
8818 * data - Pointer to a word to store the value read.
8819 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008820static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008821e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8822{
8823 int32_t status = E1000_SUCCESS;
8824 status = e1000_read_ich8_data(hw, index, 2, data);
8825 return status;
8826}
8827
8828/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008829 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8830 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008831 *
8832 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008833 * bank - 0 for first bank, 1 for second bank
8834 *
8835 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8836 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8837 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008838 *****************************************************************************/
8839int32_t
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008840e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008841{
8842 union ich8_hws_flash_status hsfsts;
8843 union ich8_hws_flash_ctrl hsflctl;
8844 uint32_t flash_linear_address;
8845 int32_t count = 0;
8846 int32_t error = E1000_ERR_EEPROM;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008847 int32_t iteration;
8848 int32_t sub_sector_size = 0;
8849 int32_t bank_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008850 int32_t j = 0;
8851 int32_t error_flag = 0;
8852
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008853 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008854
8855 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8856 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8857 * consecutive sectors. The start index for the nth Hw sector can be
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008858 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008859 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8860 * The start index for the nth Hw sector can be calculated
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008861 * as bank * 4096
8862 * 10: The HW sector is 8K bytes
8863 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008864 if (hsfsts.hsf_status.berasesz == 0x0) {
8865 /* Hw sector size 256 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008866 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8867 bank_size = ICH_FLASH_SECTOR_SIZE;
8868 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008869 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008870 bank_size = ICH_FLASH_SEG_SIZE_4K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008871 iteration = 1;
8872 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008873 bank_size = ICH_FLASH_SEG_SIZE_64K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008874 iteration = 1;
8875 } else {
8876 return error;
8877 }
8878
8879 for (j = 0; j < iteration ; j++) {
8880 do {
8881 count++;
8882 /* Steps */
8883 error = e1000_ich8_cycle_init(hw);
8884 if (error != E1000_SUCCESS) {
8885 error_flag = 1;
8886 break;
8887 }
8888
8889 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8890 * Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008891 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8892 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8893 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008894
8895 /* Write the last 24 bits of an index within the block into Flash
8896 * Linear address field in Flash Address. This probably needs to
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008897 * be calculated here based off the on-chip erase sector size and
8898 * the software bank size (4, 8 or 64 KBytes) */
8899 flash_linear_address = bank * bank_size + j * sub_sector_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008900 flash_linear_address += hw->flash_base_addr;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008901 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008902
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008903 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008904
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008905 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008906 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8907 * sequence a few more times else Done */
8908 if (error == E1000_SUCCESS) {
8909 break;
8910 } else {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008911 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008912 if (hsfsts.hsf_status.flcerr == 1) {
8913 /* repeat for some time before giving up */
8914 continue;
8915 } else if (hsfsts.hsf_status.flcdone == 0) {
8916 error_flag = 1;
8917 break;
8918 }
8919 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008920 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008921 if (error_flag == 1)
8922 break;
8923 }
8924 if (error_flag != 1)
8925 error = E1000_SUCCESS;
8926 return error;
8927}
8928
Adrian Bunke4c780b2006-08-14 23:00:10 -07008929static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008930e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8931 uint32_t cnf_base_addr, uint32_t cnf_size)
8932{
8933 uint32_t ret_val = E1000_SUCCESS;
8934 uint16_t word_addr, reg_data, reg_addr;
8935 uint16_t i;
8936
8937 /* cnf_base_addr is in DWORD */
8938 word_addr = (uint16_t)(cnf_base_addr << 1);
8939
8940 /* cnf_size is returned in size of dwords */
8941 for (i = 0; i < cnf_size; i++) {
8942 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8943 if (ret_val)
8944 return ret_val;
8945
8946 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8947 if (ret_val)
8948 return ret_val;
8949
8950 ret_val = e1000_get_software_flag(hw);
8951 if (ret_val != E1000_SUCCESS)
8952 return ret_val;
8953
8954 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8955
8956 e1000_release_software_flag(hw);
8957 }
8958
8959 return ret_val;
8960}
8961
8962
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008963/******************************************************************************
8964 * This function initializes the PHY from the NVM on ICH8 platforms. This
8965 * is needed due to an issue where the NVM configuration is not properly
8966 * autoloaded after power transitions. Therefore, after each PHY reset, we
8967 * will load the configuration data out of the NVM manually.
8968 *
8969 * hw: Struct containing variables accessed by shared code
8970 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008971static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008972e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8973{
8974 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8975
8976 if (hw->phy_type != e1000_phy_igp_3)
8977 return E1000_SUCCESS;
8978
8979 /* Check if SW needs configure the PHY */
8980 reg_data = E1000_READ_REG(hw, FEXTNVM);
8981 if (!(reg_data & FEXTNVM_SW_CONFIG))
8982 return E1000_SUCCESS;
8983
8984 /* Wait for basic configuration completes before proceeding*/
8985 loop = 0;
8986 do {
8987 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8988 udelay(100);
8989 loop++;
8990 } while ((!reg_data) && (loop < 50));
8991
8992 /* Clear the Init Done bit for the next init event */
8993 reg_data = E1000_READ_REG(hw, STATUS);
8994 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
8995 E1000_WRITE_REG(hw, STATUS, reg_data);
8996
8997 /* Make sure HW does not configure LCD from PHY extended configuration
8998 before SW configuration */
8999 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9000 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9001 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9002 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9003 cnf_size >>= 16;
9004 if (cnf_size) {
9005 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9006 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9007 /* cnf_base_addr is in DWORD */
9008 cnf_base_addr >>= 16;
9009
9010 /* Configure LCD from extended configuration region. */
9011 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9012 cnf_size);
9013 if (ret_val)
9014 return ret_val;
9015 }
9016 }
9017
9018 return E1000_SUCCESS;
9019}
9020