blob: 0e2ccf50d4d7c2fc13a7eddf571f0896117b2ccb [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:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400388 hw->mac_type = e1000_82571;
389 break;
390 case E1000_DEV_ID_82572EI_COPPER:
391 case E1000_DEV_ID_82572EI_FIBER:
392 case E1000_DEV_ID_82572EI_SERDES:
Auke Kokcd94dd02006-06-27 09:08:22 -0700393 case E1000_DEV_ID_82572EI:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400394 hw->mac_type = e1000_82572;
395 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700396 case E1000_DEV_ID_82573E:
397 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400398 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700399 hw->mac_type = e1000_82573;
400 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700401 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
402 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800403 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
404 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
405 hw->mac_type = e1000_80003es2lan;
406 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700407 case E1000_DEV_ID_ICH8_IGP_M_AMT:
408 case E1000_DEV_ID_ICH8_IGP_AMT:
409 case E1000_DEV_ID_ICH8_IGP_C:
410 case E1000_DEV_ID_ICH8_IFE:
411 case E1000_DEV_ID_ICH8_IGP_M:
412 hw->mac_type = e1000_ich8lan;
413 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 default:
415 /* Should never have loaded on this device */
416 return -E1000_ERR_MAC_TYPE;
417 }
418
Auke Kok8fc897b2006-08-28 14:56:16 -0700419 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700420 case e1000_ich8lan:
421 hw->swfwhw_semaphore_present = TRUE;
422 hw->asf_firmware_present = TRUE;
423 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800424 case e1000_80003es2lan:
425 hw->swfw_sync_present = TRUE;
426 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400427 case e1000_82571:
428 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700429 case e1000_82573:
430 hw->eeprom_semaphore_present = TRUE;
431 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 case e1000_82541:
433 case e1000_82547:
434 case e1000_82541_rev_2:
435 case e1000_82547_rev_2:
436 hw->asf_firmware_present = TRUE;
437 break;
438 default:
439 break;
440 }
441
442 return E1000_SUCCESS;
443}
444
445/*****************************************************************************
446 * Set media type and TBI compatibility.
447 *
448 * hw - Struct containing variables accessed by shared code
449 * **************************************************************************/
450void
451e1000_set_media_type(struct e1000_hw *hw)
452{
453 uint32_t status;
454
455 DEBUGFUNC("e1000_set_media_type");
456
Auke Kok8fc897b2006-08-28 14:56:16 -0700457 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /* tbi_compatibility is only valid on 82543 */
459 hw->tbi_compatibility_en = FALSE;
460 }
461
462 switch (hw->device_id) {
463 case E1000_DEV_ID_82545GM_SERDES:
464 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400465 case E1000_DEV_ID_82571EB_SERDES:
466 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800467 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 hw->media_type = e1000_media_type_internal_serdes;
469 break;
470 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700471 switch (hw->mac_type) {
472 case e1000_82542_rev2_0:
473 case e1000_82542_rev2_1:
474 hw->media_type = e1000_media_type_fiber;
475 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700476 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700477 case e1000_82573:
478 /* The STATUS_TBIMODE bit is reserved or reused for the this
479 * device.
480 */
481 hw->media_type = e1000_media_type_copper;
482 break;
483 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700485 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 hw->media_type = e1000_media_type_fiber;
487 /* tbi_compatibility not valid on fiber */
488 hw->tbi_compatibility_en = FALSE;
489 } else {
490 hw->media_type = e1000_media_type_copper;
491 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700492 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494 }
495}
496
497/******************************************************************************
498 * Reset the transmit and receive units; mask and clear all interrupts.
499 *
500 * hw - Struct containing variables accessed by shared code
501 *****************************************************************************/
502int32_t
503e1000_reset_hw(struct e1000_hw *hw)
504{
505 uint32_t ctrl;
506 uint32_t ctrl_ext;
507 uint32_t icr;
508 uint32_t manc;
509 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700510 uint32_t timeout;
511 uint32_t extcnf_ctrl;
512 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 DEBUGFUNC("e1000_reset_hw");
515
516 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700517 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
519 e1000_pci_clear_mwi(hw);
520 }
521
Auke Kok8fc897b2006-08-28 14:56:16 -0700522 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700523 /* Prevent the PCI-E bus from sticking if there is no TLP connection
524 * on the last TLP read/write transaction when MAC is reset.
525 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700526 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700527 DEBUGOUT("PCI-E Master disable polling has failed.\n");
528 }
529 }
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* Clear interrupt mask to stop board from generating interrupts */
532 DEBUGOUT("Masking off all interrupts\n");
533 E1000_WRITE_REG(hw, IMC, 0xffffffff);
534
535 /* Disable the Transmit and Receive units. Then delay to allow
536 * any pending transactions to complete before we hit the MAC with
537 * the global reset.
538 */
539 E1000_WRITE_REG(hw, RCTL, 0);
540 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
541 E1000_WRITE_FLUSH(hw);
542
543 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
544 hw->tbi_compatibility_on = FALSE;
545
546 /* Delay to allow any outstanding PCI transactions to complete before
547 * resetting the device
548 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400549 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 ctrl = E1000_READ_REG(hw, CTRL);
552
553 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700554 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700555 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400556 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700559 /* Must acquire the MDIO ownership before MAC reset.
560 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700561 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700562 timeout = 10;
563
564 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
565 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
566
567 do {
568 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
569 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
570
Auke Kok8fc897b2006-08-28 14:56:16 -0700571 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700572 break;
573 else
574 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
575
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400576 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700577 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700578 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700579 }
580
Auke Kokcd94dd02006-06-27 09:08:22 -0700581 /* Workaround for ICH8 bit corruption issue in FIFO memory */
582 if (hw->mac_type == e1000_ich8lan) {
583 /* Set Tx and Rx buffer allocation to 8k apiece. */
584 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
585 /* Set Packet Buffer Size to 16k. */
586 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
587 }
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 /* Issue a global reset to the MAC. This will reset the chip's
590 * transmit, receive, DMA, and link units. It will not effect
591 * the current PCI configuration. The global reset bit is self-
592 * clearing, and should clear within a microsecond.
593 */
594 DEBUGOUT("Issuing a global reset to MAC\n");
595
Auke Kok8fc897b2006-08-28 14:56:16 -0700596 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 case e1000_82544:
598 case e1000_82540:
599 case e1000_82545:
600 case e1000_82546:
601 case e1000_82541:
602 case e1000_82541_rev_2:
603 /* These controllers can't ack the 64-bit write when issuing the
604 * reset, so use IO-mapping as a workaround to issue the reset */
605 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
606 break;
607 case e1000_82545_rev_3:
608 case e1000_82546_rev_3:
609 /* Reset is performed on a shadow of the control register */
610 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
611 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700612 case e1000_ich8lan:
613 if (!hw->phy_reset_disable &&
614 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
615 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
616 * at the same time to make sure the interface between
617 * MAC and the external PHY is reset.
618 */
619 ctrl |= E1000_CTRL_PHY_RST;
620 }
621
622 e1000_get_software_flag(hw);
623 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400624 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700625 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 default:
627 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
628 break;
629 }
630
631 /* After MAC reset, force reload of EEPROM to restore power-on settings to
632 * device. Later controllers reload the EEPROM automatically, so just wait
633 * for reload to complete.
634 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700635 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 case e1000_82542_rev2_0:
637 case e1000_82542_rev2_1:
638 case e1000_82543:
639 case e1000_82544:
640 /* Wait for reset to complete */
641 udelay(10);
642 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
643 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
644 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
645 E1000_WRITE_FLUSH(hw);
646 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400647 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
649 case e1000_82541:
650 case e1000_82541_rev_2:
651 case e1000_82547:
652 case e1000_82547_rev_2:
653 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400654 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700656 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500657 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
658 udelay(10);
659 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
660 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
661 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
662 E1000_WRITE_FLUSH(hw);
663 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700664 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700665 default:
666 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700667 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700668 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700669 return ret_val;
670 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
673 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700674 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 manc = E1000_READ_REG(hw, MANC);
676 manc &= ~(E1000_MANC_ARP_EN);
677 E1000_WRITE_REG(hw, MANC, manc);
678 }
679
Auke Kok8fc897b2006-08-28 14:56:16 -0700680 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 e1000_phy_init_script(hw);
682
683 /* Configure activity LED after PHY reset */
684 led_ctrl = E1000_READ_REG(hw, LEDCTL);
685 led_ctrl &= IGP_ACTIVITY_LED_MASK;
686 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
687 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
688 }
689
690 /* Clear interrupt mask to stop board from generating interrupts */
691 DEBUGOUT("Masking off all interrupts\n");
692 E1000_WRITE_REG(hw, IMC, 0xffffffff);
693
694 /* Clear any pending interrupt events. */
695 icr = E1000_READ_REG(hw, ICR);
696
697 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700698 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400699 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 e1000_pci_set_mwi(hw);
701 }
702
Auke Kokcd94dd02006-06-27 09:08:22 -0700703 if (hw->mac_type == e1000_ich8lan) {
704 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
705 kab |= E1000_KABGTXD_BGSQLBIAS;
706 E1000_WRITE_REG(hw, KABGTXD, kab);
707 }
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 return E1000_SUCCESS;
710}
711
712/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700713 *
714 * Initialize a number of hardware-dependent bits
715 *
716 * hw: Struct containing variables accessed by shared code
717 *
718 * This function contains hardware limitation workarounds for PCI-E adapters
719 *
720 *****************************************************************************/
721static void
722e1000_initialize_hardware_bits(struct e1000_hw *hw)
723{
724 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
725 /* Settings common to all PCI-express silicon */
726 uint32_t reg_ctrl, reg_ctrl_ext;
727 uint32_t reg_tarc0, reg_tarc1;
728 uint32_t reg_tctl;
729 uint32_t reg_txdctl, reg_txdctl1;
730
731 /* link autonegotiation/sync workarounds */
732 reg_tarc0 = E1000_READ_REG(hw, TARC0);
733 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
734
735 /* Enable not-done TX descriptor counting */
736 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
737 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
738 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
739 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
740 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
741 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
742
743 switch (hw->mac_type) {
744 case e1000_82571:
745 case e1000_82572:
746 /* Clear PHY TX compatible mode bits */
747 reg_tarc1 = E1000_READ_REG(hw, TARC1);
748 reg_tarc1 &= ~((1 << 30)|(1 << 29));
749
750 /* link autonegotiation/sync workarounds */
751 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
752
753 /* TX ring control fixes */
754 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
755
756 /* Multiple read bit is reversed polarity */
757 reg_tctl = E1000_READ_REG(hw, TCTL);
758 if (reg_tctl & E1000_TCTL_MULR)
759 reg_tarc1 &= ~(1 << 28);
760 else
761 reg_tarc1 |= (1 << 28);
762
763 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
764 break;
765 case e1000_82573:
766 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
767 reg_ctrl_ext &= ~(1 << 23);
768 reg_ctrl_ext |= (1 << 22);
769
770 /* TX byte count fix */
771 reg_ctrl = E1000_READ_REG(hw, CTRL);
772 reg_ctrl &= ~(1 << 29);
773
774 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
775 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
776 break;
777 case e1000_80003es2lan:
778 /* improve small packet performace for fiber/serdes */
779 if ((hw->media_type == e1000_media_type_fiber) ||
780 (hw->media_type == e1000_media_type_internal_serdes)) {
781 reg_tarc0 &= ~(1 << 20);
782 }
783
784 /* Multiple read bit is reversed polarity */
785 reg_tctl = E1000_READ_REG(hw, TCTL);
786 reg_tarc1 = E1000_READ_REG(hw, TARC1);
787 if (reg_tctl & E1000_TCTL_MULR)
788 reg_tarc1 &= ~(1 << 28);
789 else
790 reg_tarc1 |= (1 << 28);
791
792 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
793 break;
794 case e1000_ich8lan:
795 /* Reduce concurrent DMA requests to 3 from 4 */
796 if ((hw->revision_id < 3) ||
797 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
798 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
799 reg_tarc0 |= ((1 << 29)|(1 << 28));
800
801 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
802 reg_ctrl_ext |= (1 << 22);
803 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
804
805 /* workaround TX hang with TSO=on */
806 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
807
808 /* Multiple read bit is reversed polarity */
809 reg_tctl = E1000_READ_REG(hw, TCTL);
810 reg_tarc1 = E1000_READ_REG(hw, TARC1);
811 if (reg_tctl & E1000_TCTL_MULR)
812 reg_tarc1 &= ~(1 << 28);
813 else
814 reg_tarc1 |= (1 << 28);
815
816 /* workaround TX hang with TSO=on */
817 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
818
819 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
820 break;
821 default:
822 break;
823 }
824
825 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
826 }
827}
828
829/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 * Performs basic configuration of the adapter.
831 *
832 * hw - Struct containing variables accessed by shared code
833 *
834 * Assumes that the controller has previously been reset and is in a
835 * post-reset uninitialized state. Initializes the receive address registers,
836 * multicast table, and VLAN filter table. Calls routines to setup link
837 * configuration and flow control settings. Clears all on-chip counters. Leaves
838 * the transmit and receive units disabled and uninitialized.
839 *****************************************************************************/
840int32_t
841e1000_init_hw(struct e1000_hw *hw)
842{
843 uint32_t ctrl;
844 uint32_t i;
845 int32_t ret_val;
846 uint16_t pcix_cmd_word;
847 uint16_t pcix_stat_hi_word;
848 uint16_t cmd_mmrbc;
849 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700850 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800851 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800852 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 DEBUGFUNC("e1000_init_hw");
855
Jeff Kirsher7820d422006-08-16 13:39:00 -0700856 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700857 if ((hw->mac_type == e1000_ich8lan) &&
858 ((hw->revision_id < 3) ||
859 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
860 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
861 reg_data = E1000_READ_REG(hw, STATUS);
862 reg_data &= ~0x80000000;
863 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700864 }
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 /* Initialize Identification LED */
867 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700868 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 DEBUGOUT("Error Initializing Identification LED\n");
870 return ret_val;
871 }
872
873 /* Set the media type and TBI compatibility */
874 e1000_set_media_type(hw);
875
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700876 /* Must be called after e1000_set_media_type because media_type is used */
877 e1000_initialize_hardware_bits(hw);
878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 /* Disabling VLAN filtering. */
880 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700881 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
882 if (hw->mac_type != e1000_ich8lan) {
883 if (hw->mac_type < e1000_82545_rev_3)
884 E1000_WRITE_REG(hw, VET, 0);
885 e1000_clear_vfta(hw);
886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700889 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
891 e1000_pci_clear_mwi(hw);
892 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
893 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400894 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 }
896
897 /* Setup the receive address. This involves initializing all of the Receive
898 * Address Registers (RARs 0 - 15).
899 */
900 e1000_init_rx_addrs(hw);
901
902 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700903 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 E1000_WRITE_REG(hw, RCTL, 0);
905 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400906 msleep(1);
907 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 e1000_pci_set_mwi(hw);
909 }
910
911 /* Zero out the Multicast HASH table */
912 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700913 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700914 if (hw->mac_type == e1000_ich8lan)
915 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700916 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700918 /* use write flush to prevent Memory Write Block (MWB) from
919 * occuring when accessing our register space */
920 E1000_WRITE_FLUSH(hw);
921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 /* Set the PCI priority bit correctly in the CTRL register. This
924 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700925 * gives equal priority to transmits and receives. Valid only on
926 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700928 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 ctrl = E1000_READ_REG(hw, CTRL);
930 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
931 }
932
Auke Kok8fc897b2006-08-28 14:56:16 -0700933 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 case e1000_82545_rev_3:
935 case e1000_82546_rev_3:
936 break;
937 default:
938 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700939 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
941 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
942 &pcix_stat_hi_word);
943 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
944 PCIX_COMMAND_MMRBC_SHIFT;
945 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
946 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700947 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700949 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
951 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
952 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
953 &pcix_cmd_word);
954 }
955 }
956 break;
957 }
958
Auke Kokcd94dd02006-06-27 09:08:22 -0700959 /* More time needed for PHY to initialize */
960 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400961 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 /* Call a subroutine to configure the link and setup flow control. */
964 ret_val = e1000_setup_link(hw);
965
966 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700967 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 ctrl = E1000_READ_REG(hw, TXDCTL);
969 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
970 E1000_WRITE_REG(hw, TXDCTL, ctrl);
971 }
972
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700973 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700974 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700975 }
976
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400977 switch (hw->mac_type) {
978 default:
979 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800980 case e1000_80003es2lan:
981 /* Enable retransmit on late collisions */
982 reg_data = E1000_READ_REG(hw, TCTL);
983 reg_data |= E1000_TCTL_RTLC;
984 E1000_WRITE_REG(hw, TCTL, reg_data);
985
986 /* Configure Gigabit Carry Extend Padding */
987 reg_data = E1000_READ_REG(hw, TCTL_EXT);
988 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
989 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
990 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
991
992 /* Configure Transmit Inter-Packet Gap */
993 reg_data = E1000_READ_REG(hw, TIPG);
994 reg_data &= ~E1000_TIPG_IPGT_MASK;
995 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
996 E1000_WRITE_REG(hw, TIPG, reg_data);
997
998 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
999 reg_data &= ~0x00100000;
1000 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1001 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001002 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001003 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001004 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001005 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001006 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001007 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1008 break;
1009 }
1010
1011
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001012 if (hw->mac_type == e1000_82573) {
1013 uint32_t gcr = E1000_READ_REG(hw, GCR);
1014 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1015 E1000_WRITE_REG(hw, GCR, gcr);
1016 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 /* Clear all of the statistics registers (clear on read). It is
1019 * important that we do this after we have tried to establish link
1020 * because the symbol error count will increment wildly if there
1021 * is no link.
1022 */
1023 e1000_clear_hw_cntrs(hw);
1024
Auke Kokcd94dd02006-06-27 09:08:22 -07001025 /* ICH8 No-snoop bits are opposite polarity.
1026 * Set to snoop by default after reset. */
1027 if (hw->mac_type == e1000_ich8lan)
1028 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1029
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001030 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1031 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1032 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1033 /* Relaxed ordering must be disabled to avoid a parity
1034 * error crash in a PCI slot. */
1035 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1036 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1037 }
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 return ret_val;
1040}
1041
1042/******************************************************************************
1043 * Adjust SERDES output amplitude based on EEPROM setting.
1044 *
1045 * hw - Struct containing variables accessed by shared code.
1046 *****************************************************************************/
1047static int32_t
1048e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1049{
1050 uint16_t eeprom_data;
1051 int32_t ret_val;
1052
1053 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1054
Auke Kok8fc897b2006-08-28 14:56:16 -07001055 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 return E1000_SUCCESS;
1057
Auke Kok8fc897b2006-08-28 14:56:16 -07001058 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 case e1000_82545_rev_3:
1060 case e1000_82546_rev_3:
1061 break;
1062 default:
1063 return E1000_SUCCESS;
1064 }
1065
1066 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1067 if (ret_val) {
1068 return ret_val;
1069 }
1070
Auke Kok8fc897b2006-08-28 14:56:16 -07001071 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001073 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001075 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return ret_val;
1077 }
1078
1079 return E1000_SUCCESS;
1080}
1081
1082/******************************************************************************
1083 * Configures flow control and link settings.
1084 *
1085 * hw - Struct containing variables accessed by shared code
1086 *
1087 * Determines which flow control settings to use. Calls the apropriate media-
1088 * specific link configuration function. Configures the flow control settings.
1089 * Assuming the adapter has a valid link partner, a valid link should be
1090 * established. Assumes the hardware has previously been reset and the
1091 * transmitter and receiver are not enabled.
1092 *****************************************************************************/
1093int32_t
1094e1000_setup_link(struct e1000_hw *hw)
1095{
1096 uint32_t ctrl_ext;
1097 int32_t ret_val;
1098 uint16_t eeprom_data;
1099
1100 DEBUGFUNC("e1000_setup_link");
1101
Jeff Kirsher526f9952006-01-12 16:50:46 -08001102 /* In the case of the phy reset being blocked, we already have a link.
1103 * We do not have to set it up again. */
1104 if (e1000_check_phy_reset_block(hw))
1105 return E1000_SUCCESS;
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 /* Read and store word 0x0F of the EEPROM. This word contains bits
1108 * that determine the hardware's default PAUSE (flow control) mode,
1109 * a bit that determines whether the HW defaults to enabling or
1110 * disabling auto-negotiation, and the direction of the
1111 * SW defined pins. If there is no SW over-ride of the flow
1112 * control setting, then the variable hw->fc will
1113 * be initialized based on a value in the EEPROM.
1114 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001115 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001116 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001117 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001118 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001119 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001120 break;
1121 default:
1122 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1123 1, &eeprom_data);
1124 if (ret_val) {
1125 DEBUGOUT("EEPROM Read Error\n");
1126 return -E1000_ERR_EEPROM;
1127 }
1128 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001129 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001130 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1131 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001132 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001133 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001134 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001135 break;
1136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 }
1138
1139 /* We want to save off the original Flow Control configuration just
1140 * in case we get disconnected and then reconnected into a different
1141 * hub or switch with different Flow Control capabilities.
1142 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001143 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001144 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Auke Kok8fc897b2006-08-28 14:56:16 -07001146 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001147 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 hw->original_fc = hw->fc;
1150
1151 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1152
1153 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1154 * polarity value for the SW controlled pins, and setup the
1155 * Extended Device Control reg with that info.
1156 * This is needed because one of the SW controlled pins is used for
1157 * signal detection. So this should be done before e1000_setup_pcs_link()
1158 * or e1000_phy_setup() is called.
1159 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001160 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001161 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1162 1, &eeprom_data);
1163 if (ret_val) {
1164 DEBUGOUT("EEPROM Read Error\n");
1165 return -E1000_ERR_EEPROM;
1166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1168 SWDPIO__EXT_SHIFT);
1169 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1170 }
1171
1172 /* Call the necessary subroutine to configure the link. */
1173 ret_val = (hw->media_type == e1000_media_type_copper) ?
1174 e1000_setup_copper_link(hw) :
1175 e1000_setup_fiber_serdes_link(hw);
1176
1177 /* Initialize the flow control address, type, and PAUSE timer
1178 * registers to their default values. This is done even if flow
1179 * control is disabled, because it does not hurt anything to
1180 * initialize these registers.
1181 */
1182 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1183
Auke Kokcd94dd02006-06-27 09:08:22 -07001184 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1185 if (hw->mac_type != e1000_ich8lan) {
1186 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1187 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1188 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1189 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1192
1193 /* Set the flow control receive threshold registers. Normally,
1194 * these registers will be set to a default threshold that may be
1195 * adjusted later by the driver's runtime code. However, if the
1196 * ability to transmit pause frames in not enabled, then these
1197 * registers will be set to 0.
1198 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001199 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 E1000_WRITE_REG(hw, FCRTL, 0);
1201 E1000_WRITE_REG(hw, FCRTH, 0);
1202 } else {
1203 /* We need to set up the Receive Threshold high and low water marks
1204 * as well as (optionally) enabling the transmission of XON frames.
1205 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001206 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1208 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1209 } else {
1210 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1211 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1212 }
1213 }
1214 return ret_val;
1215}
1216
1217/******************************************************************************
1218 * Sets up link for a fiber based or serdes based adapter
1219 *
1220 * hw - Struct containing variables accessed by shared code
1221 *
1222 * Manipulates Physical Coding Sublayer functions in order to configure
1223 * link. Assumes the hardware has been previously reset and the transmitter
1224 * and receiver are not enabled.
1225 *****************************************************************************/
1226static int32_t
1227e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1228{
1229 uint32_t ctrl;
1230 uint32_t status;
1231 uint32_t txcw = 0;
1232 uint32_t i;
1233 uint32_t signal = 0;
1234 int32_t ret_val;
1235
1236 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1237
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001238 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1239 * until explicitly turned off or a power cycle is performed. A read to
1240 * the register does not indicate its status. Therefore, we ensure
1241 * loopback mode is disabled during initialization.
1242 */
1243 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1244 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1245
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001246 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 * set when the optics detect a signal. On older adapters, it will be
1248 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001249 * If we're on serdes media, adjust the output amplitude to value
1250 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 */
1252 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001253 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1255
1256 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001257 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 return ret_val;
1259
1260 /* Take the link out of reset */
1261 ctrl &= ~(E1000_CTRL_LRST);
1262
1263 /* Adjust VCO speed to improve BER performance */
1264 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001265 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 return ret_val;
1267
1268 e1000_config_collision_dist(hw);
1269
1270 /* Check for a software override of the flow control settings, and setup
1271 * the device accordingly. If auto-negotiation is enabled, then software
1272 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1273 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1274 * auto-negotiation is disabled, then software will have to manually
1275 * configure the two flow control enable bits in the CTRL register.
1276 *
1277 * The possible values of the "fc" parameter are:
1278 * 0: Flow control is completely disabled
1279 * 1: Rx flow control is enabled (we can receive pause frames, but
1280 * not send pause frames).
1281 * 2: Tx flow control is enabled (we can send pause frames but we do
1282 * not support receiving pause frames).
1283 * 3: Both Rx and TX flow control (symmetric) are enabled.
1284 */
1285 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001286 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 /* Flow control is completely disabled by a software over-ride. */
1288 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1289 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001290 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 /* RX Flow control is enabled and TX Flow control is disabled by a
1292 * software over-ride. Since there really isn't a way to advertise
1293 * that we are capable of RX Pause ONLY, we will advertise that we
1294 * support both symmetric and asymmetric RX PAUSE. Later, we will
1295 * disable the adapter's ability to send PAUSE frames.
1296 */
1297 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1298 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001299 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1301 * software over-ride.
1302 */
1303 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1304 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001305 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1307 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1308 break;
1309 default:
1310 DEBUGOUT("Flow control param set incorrectly\n");
1311 return -E1000_ERR_CONFIG;
1312 break;
1313 }
1314
1315 /* Since auto-negotiation is enabled, take the link out of reset (the link
1316 * will be in reset, because we previously reset the chip). This will
1317 * restart auto-negotiation. If auto-neogtiation is successful then the
1318 * link-up status bit will be set and the flow control enable bits (RFCE
1319 * and TFCE) will be set according to their negotiated value.
1320 */
1321 DEBUGOUT("Auto-negotiation enabled\n");
1322
1323 E1000_WRITE_REG(hw, TXCW, txcw);
1324 E1000_WRITE_REG(hw, CTRL, ctrl);
1325 E1000_WRITE_FLUSH(hw);
1326
1327 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001328 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1331 * indication in the Device Status Register. Time-out if a link isn't
1332 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1333 * less than 500 milliseconds even if the other end is doing it in SW).
1334 * For internal serdes, we just assume a signal is present, then poll.
1335 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001336 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1338 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001339 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001340 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001342 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001344 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1346 hw->autoneg_failed = 1;
1347 /* AutoNeg failed to achieve a link, so we'll call
1348 * e1000_check_for_link. This routine will force the link up if
1349 * we detect a signal. This will allow us to communicate with
1350 * non-autonegotiating link partners.
1351 */
1352 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001353 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 DEBUGOUT("Error while checking for link\n");
1355 return ret_val;
1356 }
1357 hw->autoneg_failed = 0;
1358 } else {
1359 hw->autoneg_failed = 0;
1360 DEBUGOUT("Valid Link Found\n");
1361 }
1362 } else {
1363 DEBUGOUT("No Signal Detected\n");
1364 }
1365 return E1000_SUCCESS;
1366}
1367
1368/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001369* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370*
1371* hw - Struct containing variables accessed by shared code
1372******************************************************************************/
1373static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001374e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
1376 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 uint16_t phy_data;
1379
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001380 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 ctrl = E1000_READ_REG(hw, CTRL);
1383 /* With 82543, we need to force speed and duplex on the MAC equal to what
1384 * the PHY speed and duplex configuration is. In addition, we need to
1385 * perform a hardware reset on the PHY to take it out of reset.
1386 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001387 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 ctrl |= E1000_CTRL_SLU;
1389 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1390 E1000_WRITE_REG(hw, CTRL, ctrl);
1391 } else {
1392 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1393 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001394 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001395 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001396 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
1398
1399 /* Make sure we have a valid PHY */
1400 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001401 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 DEBUGOUT("Error, did not detect valid phy.\n");
1403 return ret_val;
1404 }
1405 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1406
1407 /* Set PHY to class A mode (if necessary) */
1408 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001409 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 return ret_val;
1411
Auke Kok8fc897b2006-08-28 14:56:16 -07001412 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 (hw->mac_type == e1000_82546_rev_3)) {
1414 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1415 phy_data |= 0x00000008;
1416 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1417 }
1418
Auke Kok8fc897b2006-08-28 14:56:16 -07001419 if (hw->mac_type <= e1000_82543 ||
1420 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1421 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 hw->phy_reset_disable = FALSE;
1423
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001424 return E1000_SUCCESS;
1425}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001428/********************************************************************
1429* Copper link setup for e1000_phy_igp series.
1430*
1431* hw - Struct containing variables accessed by shared code
1432*********************************************************************/
1433static int32_t
1434e1000_copper_link_igp_setup(struct e1000_hw *hw)
1435{
1436 uint32_t led_ctrl;
1437 int32_t ret_val;
1438 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001440 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001442 if (hw->phy_reset_disable)
1443 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001444
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001445 ret_val = e1000_phy_reset(hw);
1446 if (ret_val) {
1447 DEBUGOUT("Error Resetting the PHY\n");
1448 return ret_val;
1449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Auke Kok8fc897b2006-08-28 14:56:16 -07001451 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001452 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001453 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001454 /* Configure activity LED after PHY reset */
1455 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1456 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1457 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1458 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001459 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001460
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001461 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1462 if (hw->phy_type == e1000_phy_igp) {
1463 /* disable lplu d3 during driver init */
1464 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1465 if (ret_val) {
1466 DEBUGOUT("Error Disabling LPLU D3\n");
1467 return ret_val;
1468 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001469 }
1470
1471 /* disable lplu d0 during driver init */
1472 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1473 if (ret_val) {
1474 DEBUGOUT("Error Disabling LPLU D0\n");
1475 return ret_val;
1476 }
1477 /* Configure mdi-mdix settings */
1478 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1479 if (ret_val)
1480 return ret_val;
1481
1482 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1483 hw->dsp_config_state = e1000_dsp_config_disabled;
1484 /* Force MDI for earlier revs of the IGP PHY */
1485 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1486 hw->mdix = 1;
1487
1488 } else {
1489 hw->dsp_config_state = e1000_dsp_config_enabled;
1490 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1491
1492 switch (hw->mdix) {
1493 case 1:
1494 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1495 break;
1496 case 2:
1497 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1498 break;
1499 case 0:
1500 default:
1501 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1502 break;
1503 }
1504 }
1505 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001506 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001507 return ret_val;
1508
1509 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001510 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001511 e1000_ms_type phy_ms_setting = hw->master_slave;
1512
Auke Kok8fc897b2006-08-28 14:56:16 -07001513 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001514 hw->ffe_config_state = e1000_ffe_config_enabled;
1515
Auke Kok8fc897b2006-08-28 14:56:16 -07001516 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001517 hw->dsp_config_state = e1000_dsp_config_enabled;
1518
1519 /* when autonegotiation advertisment is only 1000Mbps then we
1520 * should disable SmartSpeed and enable Auto MasterSlave
1521 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001522 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001523 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001524 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1525 &phy_data);
1526 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001528 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001529 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1530 phy_data);
1531 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001533 /* Set auto Master/Slave resolution process */
1534 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001535 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001536 return ret_val;
1537 phy_data &= ~CR_1000T_MS_ENABLE;
1538 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001539 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001540 return ret_val;
1541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001543 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001544 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001545 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001547 /* load defaults for future use */
1548 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1549 ((phy_data & CR_1000T_MS_VALUE) ?
1550 e1000_ms_force_master :
1551 e1000_ms_force_slave) :
1552 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001554 switch (phy_ms_setting) {
1555 case e1000_ms_force_master:
1556 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1557 break;
1558 case e1000_ms_force_slave:
1559 phy_data |= CR_1000T_MS_ENABLE;
1560 phy_data &= ~(CR_1000T_MS_VALUE);
1561 break;
1562 case e1000_ms_auto:
1563 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001565 break;
1566 }
1567 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001568 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001569 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Malli Chilakala2b028932005-06-17 17:46:06 -07001572 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001573}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001575/********************************************************************
1576* Copper link setup for e1000_phy_gg82563 series.
1577*
1578* hw - Struct containing variables accessed by shared code
1579*********************************************************************/
1580static int32_t
1581e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1582{
1583 int32_t ret_val;
1584 uint16_t phy_data;
1585 uint32_t reg_data;
1586
1587 DEBUGFUNC("e1000_copper_link_ggp_setup");
1588
Auke Kok8fc897b2006-08-28 14:56:16 -07001589 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001590
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001591 /* Enable CRS on TX for half-duplex operation. */
1592 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1593 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001594 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001595 return ret_val;
1596
1597 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1598 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1599 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1600
1601 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1602 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001603 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001604 return ret_val;
1605
1606 /* Options:
1607 * MDI/MDI-X = 0 (default)
1608 * 0 - Auto for all speeds
1609 * 1 - MDI mode
1610 * 2 - MDI-X mode
1611 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1612 */
1613 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001614 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001615 return ret_val;
1616
1617 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1618
1619 switch (hw->mdix) {
1620 case 1:
1621 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1622 break;
1623 case 2:
1624 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1625 break;
1626 case 0:
1627 default:
1628 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1629 break;
1630 }
1631
1632 /* Options:
1633 * disable_polarity_correction = 0 (default)
1634 * Automatic Correction for Reversed Cable Polarity
1635 * 0 - Disabled
1636 * 1 - Enabled
1637 */
1638 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001639 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001640 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1641 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1642
Auke Kok8fc897b2006-08-28 14:56:16 -07001643 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001644 return ret_val;
1645
1646 /* SW Reset the PHY so all changes take effect */
1647 ret_val = e1000_phy_reset(hw);
1648 if (ret_val) {
1649 DEBUGOUT("Error Resetting the PHY\n");
1650 return ret_val;
1651 }
1652 } /* phy_reset_disable */
1653
1654 if (hw->mac_type == e1000_80003es2lan) {
1655 /* Bypass RX and TX FIFO's */
1656 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1657 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1658 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1659 if (ret_val)
1660 return ret_val;
1661
1662 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1663 if (ret_val)
1664 return ret_val;
1665
1666 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1667 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1668
1669 if (ret_val)
1670 return ret_val;
1671
1672 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1673 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1674 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1675
1676 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1677 &phy_data);
1678 if (ret_val)
1679 return ret_val;
1680
1681 /* Do not init these registers when the HW is in IAMT mode, since the
1682 * firmware will have already initialized them. We only initialize
1683 * them if the HW is not in IAMT mode.
1684 */
1685 if (e1000_check_mng_mode(hw) == FALSE) {
1686 /* Enable Electrical Idle on the PHY */
1687 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1688 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1689 phy_data);
1690 if (ret_val)
1691 return ret_val;
1692
1693 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1694 &phy_data);
1695 if (ret_val)
1696 return ret_val;
1697
Auke Kokcd94dd02006-06-27 09:08:22 -07001698 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001699 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1700 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001701
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001702 if (ret_val)
1703 return ret_val;
1704 }
1705
1706 /* Workaround: Disable padding in Kumeran interface in the MAC
1707 * and in the PHY to avoid CRC errors.
1708 */
1709 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1710 &phy_data);
1711 if (ret_val)
1712 return ret_val;
1713 phy_data |= GG82563_ICR_DIS_PADDING;
1714 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1715 phy_data);
1716 if (ret_val)
1717 return ret_val;
1718 }
1719
1720 return E1000_SUCCESS;
1721}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001723/********************************************************************
1724* Copper link setup for e1000_phy_m88 series.
1725*
1726* hw - Struct containing variables accessed by shared code
1727*********************************************************************/
1728static int32_t
1729e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1730{
1731 int32_t ret_val;
1732 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001734 DEBUGFUNC("e1000_copper_link_mgp_setup");
1735
Auke Kok8fc897b2006-08-28 14:56:16 -07001736 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001737 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001738
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001739 /* Enable CRS on TX. This must be set for half-duplex operation. */
1740 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001741 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001742 return ret_val;
1743
1744 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1745
1746 /* Options:
1747 * MDI/MDI-X = 0 (default)
1748 * 0 - Auto for all speeds
1749 * 1 - MDI mode
1750 * 2 - MDI-X mode
1751 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1752 */
1753 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1754
1755 switch (hw->mdix) {
1756 case 1:
1757 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1758 break;
1759 case 2:
1760 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1761 break;
1762 case 3:
1763 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1764 break;
1765 case 0:
1766 default:
1767 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1768 break;
1769 }
1770
1771 /* Options:
1772 * disable_polarity_correction = 0 (default)
1773 * Automatic Correction for Reversed Cable Polarity
1774 * 0 - Disabled
1775 * 1 - Enabled
1776 */
1777 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001778 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001779 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001780 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1781 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001782 return ret_val;
1783
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001784 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001785 /* Force TX_CLK in the Extended PHY Specific Control Register
1786 * to 25MHz clock.
1787 */
1788 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1789 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001790 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001791
1792 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1793
1794 if ((hw->phy_revision == E1000_REVISION_2) &&
1795 (hw->phy_id == M88E1111_I_PHY_ID)) {
1796 /* Vidalia Phy, set the downshift counter to 5x */
1797 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1798 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1799 ret_val = e1000_write_phy_reg(hw,
1800 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1801 if (ret_val)
1802 return ret_val;
1803 } else {
1804 /* Configure Master and Slave downshift values */
1805 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1806 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1807 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1808 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1809 ret_val = e1000_write_phy_reg(hw,
1810 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1811 if (ret_val)
1812 return ret_val;
1813 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001816 /* SW Reset the PHY so all changes take effect */
1817 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001818 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001819 DEBUGOUT("Error Resetting the PHY\n");
1820 return ret_val;
1821 }
1822
1823 return E1000_SUCCESS;
1824}
1825
1826/********************************************************************
1827* Setup auto-negotiation and flow control advertisements,
1828* and then perform auto-negotiation.
1829*
1830* hw - Struct containing variables accessed by shared code
1831*********************************************************************/
1832static int32_t
1833e1000_copper_link_autoneg(struct e1000_hw *hw)
1834{
1835 int32_t ret_val;
1836 uint16_t phy_data;
1837
1838 DEBUGFUNC("e1000_copper_link_autoneg");
1839
1840 /* Perform some bounds checking on the hw->autoneg_advertised
1841 * parameter. If this variable is zero, then set it to the default.
1842 */
1843 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1844
1845 /* If autoneg_advertised is zero, we assume it was not defaulted
1846 * by the calling code so we set to advertise full capability.
1847 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001848 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001849 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1850
Auke Kokcd94dd02006-06-27 09:08:22 -07001851 /* IFE phy only supports 10/100 */
1852 if (hw->phy_type == e1000_phy_ife)
1853 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1854
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001855 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1856 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001857 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001858 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1859 return ret_val;
1860 }
1861 DEBUGOUT("Restarting Auto-Neg\n");
1862
1863 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1864 * the Auto Neg Restart bit in the PHY control register.
1865 */
1866 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001867 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001868 return ret_val;
1869
1870 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1871 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001872 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001873 return ret_val;
1874
1875 /* Does the user want to wait for Auto-Neg to complete here, or
1876 * check at a later time (for example, callback routine).
1877 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001878 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001879 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001880 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001881 DEBUGOUT("Error while waiting for autoneg to complete\n");
1882 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001886 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001888 return E1000_SUCCESS;
1889}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001891/******************************************************************************
1892* Config the MAC and the PHY after link is up.
1893* 1) Set up the MAC to the current PHY speed/duplex
1894* if we are on 82543. If we
1895* are on newer silicon, we only need to configure
1896* collision distance in the Transmit Control Register.
1897* 2) Set up flow control on the MAC to that established with
1898* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001899* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001900*
1901* hw - Struct containing variables accessed by shared code
1902******************************************************************************/
1903static int32_t
1904e1000_copper_link_postconfig(struct e1000_hw *hw)
1905{
1906 int32_t ret_val;
1907 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001908
Auke Kok8fc897b2006-08-28 14:56:16 -07001909 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001910 e1000_config_collision_dist(hw);
1911 } else {
1912 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001913 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001914 DEBUGOUT("Error configuring MAC to PHY settings\n");
1915 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001917 }
1918 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001919 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001920 DEBUGOUT("Error Configuring Flow Control\n");
1921 return ret_val;
1922 }
1923
1924 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001925 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001926 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001927 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001928 DEBUGOUT("Error Configuring DSP after link up\n");
1929 return ret_val;
1930 }
1931 }
Auke Kok76c224b2006-05-23 13:36:06 -07001932
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001933 return E1000_SUCCESS;
1934}
1935
1936/******************************************************************************
1937* Detects which PHY is present and setup the speed and duplex
1938*
1939* hw - Struct containing variables accessed by shared code
1940******************************************************************************/
1941static int32_t
1942e1000_setup_copper_link(struct e1000_hw *hw)
1943{
1944 int32_t ret_val;
1945 uint16_t i;
1946 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001947 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001948
1949 DEBUGFUNC("e1000_setup_copper_link");
1950
Auke Kokcd94dd02006-06-27 09:08:22 -07001951 switch (hw->mac_type) {
1952 case e1000_80003es2lan:
1953 case e1000_ich8lan:
1954 /* Set the mac to wait the maximum time between each
1955 * iteration and increase the max iterations when
1956 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1957 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1958 if (ret_val)
1959 return ret_val;
1960 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1961 if (ret_val)
1962 return ret_val;
1963 reg_data |= 0x3F;
1964 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1965 if (ret_val)
1966 return ret_val;
1967 default:
1968 break;
1969 }
1970
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001971 /* Check if it is a valid PHY and set PHY mode if necessary. */
1972 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001973 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001974 return ret_val;
1975
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001976 switch (hw->mac_type) {
1977 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001978 /* Kumeran registers are written-only */
1979 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001980 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1981 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1982 reg_data);
1983 if (ret_val)
1984 return ret_val;
1985 break;
1986 default:
1987 break;
1988 }
1989
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001990 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07001991 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001992 hw->phy_type == e1000_phy_igp_2) {
1993 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001994 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001995 return ret_val;
1996 } else if (hw->phy_type == e1000_phy_m88) {
1997 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001998 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001999 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002000 } else if (hw->phy_type == e1000_phy_gg82563) {
2001 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002002 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002003 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002004 }
2005
Auke Kok8fc897b2006-08-28 14:56:16 -07002006 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002007 /* Setup autoneg and flow control advertisement
2008 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002009 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002010 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002011 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002012 } else {
2013 /* PHY will be set to 10H, 10F, 100H,or 100F
2014 * depending on value from forced_speed_duplex. */
2015 DEBUGOUT("Forcing speed and duplex\n");
2016 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002017 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002018 DEBUGOUT("Error Forcing Speed and Duplex\n");
2019 return ret_val;
2020 }
2021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
2023 /* Check link status. Wait up to 100 microseconds for link to become
2024 * valid.
2025 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002026 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002028 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 return ret_val;
2030 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
Auke Kok8fc897b2006-08-28 14:56:16 -07002034 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002035 /* Config the MAC and PHY after link is up */
2036 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002037 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 DEBUGOUT("Valid link established!!!\n");
2041 return E1000_SUCCESS;
2042 }
2043 udelay(10);
2044 }
2045
2046 DEBUGOUT("Unable to establish link!!!\n");
2047 return E1000_SUCCESS;
2048}
2049
2050/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002051* Configure the MAC-to-PHY interface for 10/100Mbps
2052*
2053* hw - Struct containing variables accessed by shared code
2054******************************************************************************/
2055static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002056e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002057{
2058 int32_t ret_val = E1000_SUCCESS;
2059 uint32_t tipg;
2060 uint16_t reg_data;
2061
2062 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2063
2064 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2065 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2066 reg_data);
2067 if (ret_val)
2068 return ret_val;
2069
2070 /* Configure Transmit Inter-Packet Gap */
2071 tipg = E1000_READ_REG(hw, TIPG);
2072 tipg &= ~E1000_TIPG_IPGT_MASK;
2073 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2074 E1000_WRITE_REG(hw, TIPG, tipg);
2075
Auke Kokcd94dd02006-06-27 09:08:22 -07002076 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2077
2078 if (ret_val)
2079 return ret_val;
2080
2081 if (duplex == HALF_DUPLEX)
2082 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2083 else
2084 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2085
2086 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2087
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002088 return ret_val;
2089}
2090
2091static int32_t
2092e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2093{
2094 int32_t ret_val = E1000_SUCCESS;
2095 uint16_t reg_data;
2096 uint32_t tipg;
2097
2098 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2099
2100 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2101 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2102 reg_data);
2103 if (ret_val)
2104 return ret_val;
2105
2106 /* Configure Transmit Inter-Packet Gap */
2107 tipg = E1000_READ_REG(hw, TIPG);
2108 tipg &= ~E1000_TIPG_IPGT_MASK;
2109 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2110 E1000_WRITE_REG(hw, TIPG, tipg);
2111
Auke Kokcd94dd02006-06-27 09:08:22 -07002112 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2113
2114 if (ret_val)
2115 return ret_val;
2116
2117 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2118 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2119
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002120 return ret_val;
2121}
2122
2123/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124* Configures PHY autoneg and flow control advertisement settings
2125*
2126* hw - Struct containing variables accessed by shared code
2127******************************************************************************/
2128int32_t
2129e1000_phy_setup_autoneg(struct e1000_hw *hw)
2130{
2131 int32_t ret_val;
2132 uint16_t mii_autoneg_adv_reg;
2133 uint16_t mii_1000t_ctrl_reg;
2134
2135 DEBUGFUNC("e1000_phy_setup_autoneg");
2136
2137 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2138 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002139 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 return ret_val;
2141
Auke Kokcd94dd02006-06-27 09:08:22 -07002142 if (hw->phy_type != e1000_phy_ife) {
2143 /* Read the MII 1000Base-T Control Register (Address 9). */
2144 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2145 if (ret_val)
2146 return ret_val;
2147 } else
2148 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
2150 /* Need to parse both autoneg_advertised and fc and set up
2151 * the appropriate PHY registers. First we will parse for
2152 * autoneg_advertised software override. Since we can advertise
2153 * a plethora of combinations, we need to check each bit
2154 * individually.
2155 */
2156
2157 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2158 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2159 * the 1000Base-T Control Register (Address 9).
2160 */
2161 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2162 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2163
2164 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2165
2166 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002167 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 DEBUGOUT("Advertise 10mb Half duplex\n");
2169 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2170 }
2171
2172 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002173 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 DEBUGOUT("Advertise 10mb Full duplex\n");
2175 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2176 }
2177
2178 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002179 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 DEBUGOUT("Advertise 100mb Half duplex\n");
2181 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2182 }
2183
2184 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002185 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 DEBUGOUT("Advertise 100mb Full duplex\n");
2187 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2188 }
2189
2190 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002191 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2193 }
2194
2195 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002196 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 DEBUGOUT("Advertise 1000mb Full duplex\n");
2198 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002199 if (hw->phy_type == e1000_phy_ife) {
2200 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
2203
2204 /* Check for a software override of the flow control settings, and
2205 * setup the PHY advertisement registers accordingly. If
2206 * auto-negotiation is enabled, then software will have to set the
2207 * "PAUSE" bits to the correct value in the Auto-Negotiation
2208 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2209 *
2210 * The possible values of the "fc" parameter are:
2211 * 0: Flow control is completely disabled
2212 * 1: Rx flow control is enabled (we can receive pause frames
2213 * but not send pause frames).
2214 * 2: Tx flow control is enabled (we can send pause frames
2215 * but we do not support receiving pause frames).
2216 * 3: Both Rx and TX flow control (symmetric) are enabled.
2217 * other: No software override. The flow control configuration
2218 * in the EEPROM is used.
2219 */
2220 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002221 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 /* Flow control (RX & TX) is completely disabled by a
2223 * software over-ride.
2224 */
2225 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2226 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002227 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 /* RX Flow control is enabled, and TX Flow control is
2229 * disabled, by a software over-ride.
2230 */
2231 /* Since there really isn't a way to advertise that we are
2232 * capable of RX Pause ONLY, we will advertise that we
2233 * support both symmetric and asymmetric RX PAUSE. Later
2234 * (in e1000_config_fc_after_link_up) we will disable the
2235 *hw's ability to send PAUSE frames.
2236 */
2237 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2238 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002239 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 /* TX Flow control is enabled, and RX Flow control is
2241 * disabled, by a software over-ride.
2242 */
2243 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2244 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2245 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002246 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 /* Flow control (both RX and TX) is enabled by a software
2248 * over-ride.
2249 */
2250 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2251 break;
2252 default:
2253 DEBUGOUT("Flow control param set incorrectly\n");
2254 return -E1000_ERR_CONFIG;
2255 }
2256
2257 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002258 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 return ret_val;
2260
2261 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2262
Auke Kokcd94dd02006-06-27 09:08:22 -07002263 if (hw->phy_type != e1000_phy_ife) {
2264 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2265 if (ret_val)
2266 return ret_val;
2267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269 return E1000_SUCCESS;
2270}
2271
2272/******************************************************************************
2273* Force PHY speed and duplex settings to hw->forced_speed_duplex
2274*
2275* hw - Struct containing variables accessed by shared code
2276******************************************************************************/
2277static int32_t
2278e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2279{
2280 uint32_t ctrl;
2281 int32_t ret_val;
2282 uint16_t mii_ctrl_reg;
2283 uint16_t mii_status_reg;
2284 uint16_t phy_data;
2285 uint16_t i;
2286
2287 DEBUGFUNC("e1000_phy_force_speed_duplex");
2288
2289 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002290 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2293
2294 /* Read the Device Control Register. */
2295 ctrl = E1000_READ_REG(hw, CTRL);
2296
2297 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2298 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2299 ctrl &= ~(DEVICE_SPEED_MASK);
2300
2301 /* Clear the Auto Speed Detect Enable bit. */
2302 ctrl &= ~E1000_CTRL_ASDE;
2303
2304 /* Read the MII Control Register. */
2305 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002306 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 return ret_val;
2308
2309 /* We need to disable autoneg in order to force link and duplex. */
2310
2311 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2312
2313 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002314 if (hw->forced_speed_duplex == e1000_100_full ||
2315 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 /* We want to force full duplex so we SET the full duplex bits in the
2317 * Device and MII Control Registers.
2318 */
2319 ctrl |= E1000_CTRL_FD;
2320 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2321 DEBUGOUT("Full Duplex\n");
2322 } else {
2323 /* We want to force half duplex so we CLEAR the full duplex bits in
2324 * the Device and MII Control Registers.
2325 */
2326 ctrl &= ~E1000_CTRL_FD;
2327 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2328 DEBUGOUT("Half Duplex\n");
2329 }
2330
2331 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002332 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 hw->forced_speed_duplex == e1000_100_half) {
2334 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2335 ctrl |= E1000_CTRL_SPD_100;
2336 mii_ctrl_reg |= MII_CR_SPEED_100;
2337 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2338 DEBUGOUT("Forcing 100mb ");
2339 } else {
2340 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2341 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2342 mii_ctrl_reg |= MII_CR_SPEED_10;
2343 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2344 DEBUGOUT("Forcing 10mb ");
2345 }
2346
2347 e1000_config_collision_dist(hw);
2348
2349 /* Write the configured values back to the Device Control Reg. */
2350 E1000_WRITE_REG(hw, CTRL, ctrl);
2351
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002352 if ((hw->phy_type == e1000_phy_m88) ||
2353 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002355 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 return ret_val;
2357
2358 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2359 * forced whenever speed are duplex are forced.
2360 */
2361 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2362 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002363 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 return ret_val;
2365
2366 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2367
2368 /* Need to reset the PHY or these changes will be ignored */
2369 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002370
Auke Kokcd94dd02006-06-27 09:08:22 -07002371 /* Disable MDI-X support for 10/100 */
2372 } else if (hw->phy_type == e1000_phy_ife) {
2373 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2374 if (ret_val)
2375 return ret_val;
2376
2377 phy_data &= ~IFE_PMC_AUTO_MDIX;
2378 phy_data &= ~IFE_PMC_FORCE_MDIX;
2379
2380 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2381 if (ret_val)
2382 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 } else {
2385 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2386 * forced whenever speed or duplex are forced.
2387 */
2388 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002389 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 return ret_val;
2391
2392 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2393 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2394
2395 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002396 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 return ret_val;
2398 }
2399
2400 /* Write back the modified PHY MII control register. */
2401 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002402 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return ret_val;
2404
2405 udelay(1);
2406
2407 /* The wait_autoneg_complete flag may be a little misleading here.
2408 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2409 * But we do want to delay for a period while forcing only so we
2410 * don't generate false No Link messages. So we will wait here
2411 * only if the user has set wait_autoneg_complete to 1, which is
2412 * the default.
2413 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002414 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 /* We will wait for autoneg to complete. */
2416 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2417 mii_status_reg = 0;
2418
2419 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002420 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2422 * to be set.
2423 */
2424 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002425 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 return ret_val;
2427
2428 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002429 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 return ret_val;
2431
Auke Kok8fc897b2006-08-28 14:56:16 -07002432 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002433 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002435 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002436 ((hw->phy_type == e1000_phy_m88) ||
2437 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 /* We didn't get link. Reset the DSP and wait again for link. */
2439 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002440 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 DEBUGOUT("Error Resetting PHY DSP\n");
2442 return ret_val;
2443 }
2444 }
2445 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002446 for (i = PHY_FORCE_TIME; i > 0; i--) {
2447 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002448 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2450 * to be set.
2451 */
2452 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002453 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 return ret_val;
2455
2456 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002457 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 return ret_val;
2459 }
2460 }
2461
2462 if (hw->phy_type == e1000_phy_m88) {
2463 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2464 * Extended PHY Specific Control Register to 25MHz clock. This value
2465 * defaults back to a 2.5MHz clock when the PHY is reset.
2466 */
2467 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002468 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 return ret_val;
2470
2471 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2472 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002473 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 return ret_val;
2475
2476 /* In addition, because of the s/w reset above, we need to enable CRS on
2477 * TX. This must be set for both full and half duplex operation.
2478 */
2479 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002480 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 return ret_val;
2482
2483 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2484 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002485 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 return ret_val;
2487
Auke Kok8fc897b2006-08-28 14:56:16 -07002488 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2489 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2490 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002492 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 return ret_val;
2494 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002495 } else if (hw->phy_type == e1000_phy_gg82563) {
2496 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2497 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2498 * we're not in a forced 10/duplex configuration. */
2499 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2500 if (ret_val)
2501 return ret_val;
2502
2503 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2504 if ((hw->forced_speed_duplex == e1000_10_full) ||
2505 (hw->forced_speed_duplex == e1000_10_half))
2506 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2507 else
2508 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2509
2510 /* Also due to the reset, we need to enable CRS on Tx. */
2511 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2512
2513 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2514 if (ret_val)
2515 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 }
2517 return E1000_SUCCESS;
2518}
2519
2520/******************************************************************************
2521* Sets the collision distance in the Transmit Control register
2522*
2523* hw - Struct containing variables accessed by shared code
2524*
2525* Link should have been established previously. Reads the speed and duplex
2526* information from the Device Status register.
2527******************************************************************************/
2528void
2529e1000_config_collision_dist(struct e1000_hw *hw)
2530{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002531 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
2533 DEBUGFUNC("e1000_config_collision_dist");
2534
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002535 if (hw->mac_type < e1000_82543)
2536 coll_dist = E1000_COLLISION_DISTANCE_82542;
2537 else
2538 coll_dist = E1000_COLLISION_DISTANCE;
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 tctl = E1000_READ_REG(hw, TCTL);
2541
2542 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002543 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
2545 E1000_WRITE_REG(hw, TCTL, tctl);
2546 E1000_WRITE_FLUSH(hw);
2547}
2548
2549/******************************************************************************
2550* Sets MAC speed and duplex settings to reflect the those in the PHY
2551*
2552* hw - Struct containing variables accessed by shared code
2553* mii_reg - data to write to the MII control register
2554*
2555* The contents of the PHY register containing the needed information need to
2556* be passed in.
2557******************************************************************************/
2558static int32_t
2559e1000_config_mac_to_phy(struct e1000_hw *hw)
2560{
2561 uint32_t ctrl;
2562 int32_t ret_val;
2563 uint16_t phy_data;
2564
2565 DEBUGFUNC("e1000_config_mac_to_phy");
2566
Auke Kok76c224b2006-05-23 13:36:06 -07002567 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002568 * MAC speed/duplex configuration.*/
2569 if (hw->mac_type >= e1000_82544)
2570 return E1000_SUCCESS;
2571
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 /* Read the Device Control Register and set the bits to Force Speed
2573 * and Duplex.
2574 */
2575 ctrl = E1000_READ_REG(hw, CTRL);
2576 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2577 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2578
2579 /* Set up duplex in the Device Control and Transmit Control
2580 * registers depending on negotiated values.
2581 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002582 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002583 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002584 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
Auke Kok8fc897b2006-08-28 14:56:16 -07002586 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002587 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002588 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002589 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002591 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002593 /* Set up speed in the Device Control register depending on
2594 * negotiated values.
2595 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002596 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002597 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002598 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002599 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 /* Write the configured values back to the Device Control Reg. */
2602 E1000_WRITE_REG(hw, CTRL, ctrl);
2603 return E1000_SUCCESS;
2604}
2605
2606/******************************************************************************
2607 * Forces the MAC's flow control settings.
2608 *
2609 * hw - Struct containing variables accessed by shared code
2610 *
2611 * Sets the TFCE and RFCE bits in the device control register to reflect
2612 * the adapter settings. TFCE and RFCE need to be explicitly set by
2613 * software when a Copper PHY is used because autonegotiation is managed
2614 * by the PHY rather than the MAC. Software must also configure these
2615 * bits when link is forced on a fiber connection.
2616 *****************************************************************************/
2617int32_t
2618e1000_force_mac_fc(struct e1000_hw *hw)
2619{
2620 uint32_t ctrl;
2621
2622 DEBUGFUNC("e1000_force_mac_fc");
2623
2624 /* Get the current configuration of the Device Control Register */
2625 ctrl = E1000_READ_REG(hw, CTRL);
2626
2627 /* Because we didn't get link via the internal auto-negotiation
2628 * mechanism (we either forced link or we got link via PHY
2629 * auto-neg), we have to manually enable/disable transmit an
2630 * receive flow control.
2631 *
2632 * The "Case" statement below enables/disable flow control
2633 * according to the "hw->fc" parameter.
2634 *
2635 * The possible values of the "fc" parameter are:
2636 * 0: Flow control is completely disabled
2637 * 1: Rx flow control is enabled (we can receive pause
2638 * frames but not send pause frames).
2639 * 2: Tx flow control is enabled (we can send pause frames
2640 * frames but we do not receive pause frames).
2641 * 3: Both Rx and TX flow control (symmetric) is enabled.
2642 * other: No other values should be possible at this point.
2643 */
2644
2645 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002646 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2648 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002649 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 ctrl &= (~E1000_CTRL_TFCE);
2651 ctrl |= E1000_CTRL_RFCE;
2652 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002653 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 ctrl &= (~E1000_CTRL_RFCE);
2655 ctrl |= E1000_CTRL_TFCE;
2656 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002657 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2659 break;
2660 default:
2661 DEBUGOUT("Flow control param set incorrectly\n");
2662 return -E1000_ERR_CONFIG;
2663 }
2664
2665 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002666 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 ctrl &= (~E1000_CTRL_TFCE);
2668
2669 E1000_WRITE_REG(hw, CTRL, ctrl);
2670 return E1000_SUCCESS;
2671}
2672
2673/******************************************************************************
2674 * Configures flow control settings after link is established
2675 *
2676 * hw - Struct containing variables accessed by shared code
2677 *
2678 * Should be called immediately after a valid link has been established.
2679 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2680 * and autonegotiation is enabled, the MAC flow control settings will be set
2681 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2682 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2683 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002684static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685e1000_config_fc_after_link_up(struct e1000_hw *hw)
2686{
2687 int32_t ret_val;
2688 uint16_t mii_status_reg;
2689 uint16_t mii_nway_adv_reg;
2690 uint16_t mii_nway_lp_ability_reg;
2691 uint16_t speed;
2692 uint16_t duplex;
2693
2694 DEBUGFUNC("e1000_config_fc_after_link_up");
2695
2696 /* Check for the case where we have fiber media and auto-neg failed
2697 * so we had to force link. In this case, we need to force the
2698 * configuration of the MAC to match the "fc" parameter.
2699 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002700 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2701 ((hw->media_type == e1000_media_type_internal_serdes) &&
2702 (hw->autoneg_failed)) ||
2703 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002705 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 DEBUGOUT("Error forcing flow control settings\n");
2707 return ret_val;
2708 }
2709 }
2710
2711 /* Check for the case where we have copper media and auto-neg is
2712 * enabled. In this case, we need to check and see if Auto-Neg
2713 * has completed, and if so, how the PHY and link partner has
2714 * flow control configured.
2715 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002716 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 /* Read the MII Status Register and check to see if AutoNeg
2718 * has completed. We read this twice because this reg has
2719 * some "sticky" (latched) bits.
2720 */
2721 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002722 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 return ret_val;
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
Auke Kok8fc897b2006-08-28 14:56:16 -07002728 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /* The AutoNeg process has completed, so we now need to
2730 * read both the Auto Negotiation Advertisement Register
2731 * (Address 4) and the Auto_Negotiation Base Page Ability
2732 * Register (Address 5) to determine how flow control was
2733 * negotiated.
2734 */
2735 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2736 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002737 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 return ret_val;
2739 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2740 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002741 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 return ret_val;
2743
2744 /* Two bits in the Auto Negotiation Advertisement Register
2745 * (Address 4) and two bits in the Auto Negotiation Base
2746 * Page Ability Register (Address 5) determine flow control
2747 * for both the PHY and the link partner. The following
2748 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2749 * 1999, describes these PAUSE resolution bits and how flow
2750 * control is determined based upon these settings.
2751 * NOTE: DC = Don't Care
2752 *
2753 * LOCAL DEVICE | LINK PARTNER
2754 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2755 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002756 * 0 | 0 | DC | DC | E1000_FC_NONE
2757 * 0 | 1 | 0 | DC | E1000_FC_NONE
2758 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2759 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2760 * 1 | 0 | 0 | DC | E1000_FC_NONE
2761 * 1 | DC | 1 | DC | E1000_FC_FULL
2762 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2763 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 *
2765 */
2766 /* Are both PAUSE bits set to 1? If so, this implies
2767 * Symmetric Flow Control is enabled at both ends. The
2768 * ASM_DIR bits are irrelevant per the spec.
2769 *
2770 * For Symmetric Flow Control:
2771 *
2772 * LOCAL DEVICE | LINK PARTNER
2773 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2774 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002775 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 *
2777 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002778 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2779 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 /* Now we need to check if the user selected RX ONLY
2781 * of pause frames. In this case, we had to advertise
2782 * FULL flow control because we could not advertise RX
2783 * ONLY. Hence, we must now check to see if we need to
2784 * turn OFF the TRANSMISSION of PAUSE frames.
2785 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002786 if (hw->original_fc == E1000_FC_FULL) {
2787 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002788 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002790 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002791 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
2793 }
2794 /* For receiving PAUSE frames ONLY.
2795 *
2796 * LOCAL DEVICE | LINK PARTNER
2797 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2798 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002799 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 *
2801 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002802 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2803 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2804 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2805 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002806 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002807 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 }
2809 /* For transmitting PAUSE frames ONLY.
2810 *
2811 * LOCAL DEVICE | LINK PARTNER
2812 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2813 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002814 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 *
2816 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002817 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2818 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2819 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2820 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002821 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002822 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 }
2824 /* Per the IEEE spec, at this point flow control should be
2825 * disabled. However, we want to consider that we could
2826 * be connected to a legacy switch that doesn't advertise
2827 * desired flow control, but can be forced on the link
2828 * partner. So if we advertised no flow control, that is
2829 * what we will resolve to. If we advertised some kind of
2830 * receive capability (Rx Pause Only or Full Flow Control)
2831 * and the link partner advertised none, we will configure
2832 * ourselves to enable Rx Flow Control only. We can do
2833 * this safely for two reasons: If the link partner really
2834 * didn't want flow control enabled, and we enable Rx, no
2835 * harm done since we won't be receiving any PAUSE frames
2836 * anyway. If the intent on the link partner was to have
2837 * flow control enabled, then by us enabling RX only, we
2838 * can at least receive pause frames and process them.
2839 * This is a good idea because in most cases, since we are
2840 * predominantly a server NIC, more times than not we will
2841 * be asked to delay transmission of packets than asking
2842 * our link partner to pause transmission of frames.
2843 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002844 else if ((hw->original_fc == E1000_FC_NONE ||
2845 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002846 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002847 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002848 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002850 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002851 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 }
2853
2854 /* Now we need to do one last check... If we auto-
2855 * negotiated to HALF DUPLEX, flow control should not be
2856 * enabled per IEEE 802.3 spec.
2857 */
2858 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002859 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 DEBUGOUT("Error getting link speed and duplex\n");
2861 return ret_val;
2862 }
2863
Auke Kok8fc897b2006-08-28 14:56:16 -07002864 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002865 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867 /* Now we call a subroutine to actually force the MAC
2868 * controller to use the correct flow control settings.
2869 */
2870 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002871 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 DEBUGOUT("Error forcing flow control settings\n");
2873 return ret_val;
2874 }
2875 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002876 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 }
2878 }
2879 return E1000_SUCCESS;
2880}
2881
2882/******************************************************************************
2883 * Checks to see if the link status of the hardware has changed.
2884 *
2885 * hw - Struct containing variables accessed by shared code
2886 *
2887 * Called by any function that needs to check the link status of the adapter.
2888 *****************************************************************************/
2889int32_t
2890e1000_check_for_link(struct e1000_hw *hw)
2891{
2892 uint32_t rxcw = 0;
2893 uint32_t ctrl;
2894 uint32_t status;
2895 uint32_t rctl;
2896 uint32_t icr;
2897 uint32_t signal = 0;
2898 int32_t ret_val;
2899 uint16_t phy_data;
2900
2901 DEBUGFUNC("e1000_check_for_link");
2902
2903 ctrl = E1000_READ_REG(hw, CTRL);
2904 status = E1000_READ_REG(hw, STATUS);
2905
2906 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2907 * set when the optics detect a signal. On older adapters, it will be
2908 * cleared when there is a signal. This applies to fiber media only.
2909 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002910 if ((hw->media_type == e1000_media_type_fiber) ||
2911 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 rxcw = E1000_READ_REG(hw, RXCW);
2913
Auke Kok8fc897b2006-08-28 14:56:16 -07002914 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002916 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 hw->get_link_status = FALSE;
2918 }
2919 }
2920
2921 /* If we have a copper PHY then we only want to go out to the PHY
2922 * registers to see if Auto-Neg has completed and/or if our link
2923 * status has changed. The get_link_status flag will be set if we
2924 * receive a Link Status Change interrupt or we have Rx Sequence
2925 * Errors.
2926 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002927 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 /* First we want to see if the MII Status Register reports
2929 * link. If so, then we want to get the current speed/duplex
2930 * of the PHY.
2931 * Read the register twice since the link bit is sticky.
2932 */
2933 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002934 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 return ret_val;
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
Auke Kok8fc897b2006-08-28 14:56:16 -07002940 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 hw->get_link_status = FALSE;
2942 /* Check if there was DownShift, must be checked immediately after
2943 * link-up */
2944 e1000_check_downshift(hw);
2945
2946 /* If we are on 82544 or 82543 silicon and speed/duplex
2947 * are forced to 10H or 10F, then we will implement the polarity
2948 * reversal workaround. We disable interrupts first, and upon
2949 * returning, place the devices interrupt state to its previous
2950 * value except for the link status change interrupt which will
2951 * happen due to the execution of this workaround.
2952 */
2953
Auke Kok8fc897b2006-08-28 14:56:16 -07002954 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2955 (!hw->autoneg) &&
2956 (hw->forced_speed_duplex == e1000_10_full ||
2957 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2959 ret_val = e1000_polarity_reversal_workaround(hw);
2960 icr = E1000_READ_REG(hw, ICR);
2961 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2962 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2963 }
2964
2965 } else {
2966 /* No link detected */
2967 e1000_config_dsp_after_link_change(hw, FALSE);
2968 return 0;
2969 }
2970
2971 /* If we are forcing speed/duplex, then we simply return since
2972 * we have already determined whether we have link or not.
2973 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002974 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
2976 /* optimize the dsp settings for the igp phy */
2977 e1000_config_dsp_after_link_change(hw, TRUE);
2978
2979 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2980 * have Si on board that is 82544 or newer, Auto
2981 * Speed Detection takes care of MAC speed/duplex
2982 * configuration. So we only need to configure Collision
2983 * Distance in the MAC. Otherwise, we need to force
2984 * speed/duplex on the MAC to the current PHY speed/duplex
2985 * settings.
2986 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002987 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 e1000_config_collision_dist(hw);
2989 else {
2990 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002991 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 DEBUGOUT("Error configuring MAC to PHY settings\n");
2993 return ret_val;
2994 }
2995 }
2996
2997 /* Configure Flow Control now that Auto-Neg has completed. First, we
2998 * need to restore the desired flow control settings because we may
2999 * have had to re-autoneg with a different link partner.
3000 */
3001 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003002 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 DEBUGOUT("Error configuring flow control\n");
3004 return ret_val;
3005 }
3006
3007 /* At this point we know that we are on copper and we have
3008 * auto-negotiated link. These are conditions for checking the link
3009 * partner capability register. We use the link speed to determine if
3010 * TBI compatibility needs to be turned on or off. If the link is not
3011 * at gigabit speed, then TBI compatibility is not needed. If we are
3012 * at gigabit speed, we turn on TBI compatibility.
3013 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003014 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003016 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3017 if (ret_val) {
3018 DEBUGOUT("Error getting link speed and duplex\n");
3019 return ret_val;
3020 }
3021 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 /* If link speed is not set to gigabit speed, we do not need
3023 * to enable TBI compatibility.
3024 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003025 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 /* If we previously were in the mode, turn it off. */
3027 rctl = E1000_READ_REG(hw, RCTL);
3028 rctl &= ~E1000_RCTL_SBP;
3029 E1000_WRITE_REG(hw, RCTL, rctl);
3030 hw->tbi_compatibility_on = FALSE;
3031 }
3032 } else {
3033 /* If TBI compatibility is was previously off, turn it on. For
3034 * compatibility with a TBI link partner, we will store bad
3035 * packets. Some frames have an additional byte on the end and
3036 * will look like CRC errors to to the hardware.
3037 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003038 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 hw->tbi_compatibility_on = TRUE;
3040 rctl = E1000_READ_REG(hw, RCTL);
3041 rctl |= E1000_RCTL_SBP;
3042 E1000_WRITE_REG(hw, RCTL, rctl);
3043 }
3044 }
3045 }
3046 }
3047 /* If we don't have link (auto-negotiation failed or link partner cannot
3048 * auto-negotiate), the cable is plugged in (we have signal), and our
3049 * link partner is not trying to auto-negotiate with us (we are receiving
3050 * idles or data), we need to force link up. We also need to give
3051 * auto-negotiation time to complete, in case the cable was just plugged
3052 * in. The autoneg_failed flag does this.
3053 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003054 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003056 (hw->media_type == e1000_media_type_internal_serdes)) &&
3057 (!(status & E1000_STATUS_LU)) &&
3058 (!(rxcw & E1000_RXCW_C))) {
3059 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 hw->autoneg_failed = 1;
3061 return 0;
3062 }
Auke Koka42a5072006-05-23 13:36:01 -07003063 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
3065 /* Disable auto-negotiation in the TXCW register */
3066 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3067
3068 /* Force link-up and also force full-duplex. */
3069 ctrl = E1000_READ_REG(hw, CTRL);
3070 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3071 E1000_WRITE_REG(hw, CTRL, ctrl);
3072
3073 /* Configure Flow Control after forcing link up. */
3074 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003075 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 DEBUGOUT("Error configuring flow control\n");
3077 return ret_val;
3078 }
3079 }
3080 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3081 * auto-negotiation in the TXCW register and disable forced link in the
3082 * Device Control register in an attempt to auto-negotiate with our link
3083 * partner.
3084 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003085 else if (((hw->media_type == e1000_media_type_fiber) ||
3086 (hw->media_type == e1000_media_type_internal_serdes)) &&
3087 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003088 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3090 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3091
3092 hw->serdes_link_down = FALSE;
3093 }
3094 /* If we force link for non-auto-negotiation switch, check link status
3095 * based on MAC synchronization for internal serdes media type.
3096 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003097 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3098 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 /* SYNCH bit and IV bit are sticky. */
3100 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003101 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3102 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 hw->serdes_link_down = FALSE;
3104 DEBUGOUT("SERDES: Link is up.\n");
3105 }
3106 } else {
3107 hw->serdes_link_down = TRUE;
3108 DEBUGOUT("SERDES: Link is down.\n");
3109 }
3110 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003111 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3112 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3114 }
3115 return E1000_SUCCESS;
3116}
3117
3118/******************************************************************************
3119 * Detects the current speed and duplex settings of the hardware.
3120 *
3121 * hw - Struct containing variables accessed by shared code
3122 * speed - Speed of the connection
3123 * duplex - Duplex setting of the connection
3124 *****************************************************************************/
3125int32_t
3126e1000_get_speed_and_duplex(struct e1000_hw *hw,
3127 uint16_t *speed,
3128 uint16_t *duplex)
3129{
3130 uint32_t status;
3131 int32_t ret_val;
3132 uint16_t phy_data;
3133
3134 DEBUGFUNC("e1000_get_speed_and_duplex");
3135
Auke Kok8fc897b2006-08-28 14:56:16 -07003136 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003138 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 *speed = SPEED_1000;
3140 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003141 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 *speed = SPEED_100;
3143 DEBUGOUT("100 Mbs, ");
3144 } else {
3145 *speed = SPEED_10;
3146 DEBUGOUT("10 Mbs, ");
3147 }
3148
Auke Kok8fc897b2006-08-28 14:56:16 -07003149 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003151 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 } else {
3153 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003154 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 }
3156 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003157 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 *speed = SPEED_1000;
3159 *duplex = FULL_DUPLEX;
3160 }
3161
3162 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3163 * if it is operating at half duplex. Here we set the duplex settings to
3164 * match the duplex in the link partner's capabilities.
3165 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003166 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003168 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 return ret_val;
3170
Auke Kok8fc897b2006-08-28 14:56:16 -07003171 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 *duplex = HALF_DUPLEX;
3173 else {
3174 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003175 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003177 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3179 *duplex = HALF_DUPLEX;
3180 }
3181 }
3182
Auke Kok76c224b2006-05-23 13:36:06 -07003183 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003184 (hw->media_type == e1000_media_type_copper)) {
3185 if (*speed == SPEED_1000)
3186 ret_val = e1000_configure_kmrn_for_1000(hw);
3187 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003188 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3189 if (ret_val)
3190 return ret_val;
3191 }
3192
3193 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3194 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003195 if (ret_val)
3196 return ret_val;
3197 }
3198
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 return E1000_SUCCESS;
3200}
3201
3202/******************************************************************************
3203* Blocks until autoneg completes or times out (~4.5 seconds)
3204*
3205* hw - Struct containing variables accessed by shared code
3206******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003207static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208e1000_wait_autoneg(struct e1000_hw *hw)
3209{
3210 int32_t ret_val;
3211 uint16_t i;
3212 uint16_t phy_data;
3213
3214 DEBUGFUNC("e1000_wait_autoneg");
3215 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3216
3217 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003218 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 /* Read the MII Status Register and wait for Auto-Neg
3220 * Complete bit to be set.
3221 */
3222 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003223 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 return ret_val;
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;
Auke Kok8fc897b2006-08-28 14:56:16 -07003228 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 return E1000_SUCCESS;
3230 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003231 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 }
3233 return E1000_SUCCESS;
3234}
3235
3236/******************************************************************************
3237* Raises the Management Data Clock
3238*
3239* hw - Struct containing variables accessed by shared code
3240* ctrl - Device control register's current value
3241******************************************************************************/
3242static void
3243e1000_raise_mdi_clk(struct e1000_hw *hw,
3244 uint32_t *ctrl)
3245{
3246 /* Raise the clock input to the Management Data Clock (by setting the MDC
3247 * bit), and then delay 10 microseconds.
3248 */
3249 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3250 E1000_WRITE_FLUSH(hw);
3251 udelay(10);
3252}
3253
3254/******************************************************************************
3255* Lowers the Management Data Clock
3256*
3257* hw - Struct containing variables accessed by shared code
3258* ctrl - Device control register's current value
3259******************************************************************************/
3260static void
3261e1000_lower_mdi_clk(struct e1000_hw *hw,
3262 uint32_t *ctrl)
3263{
3264 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3265 * bit), and then delay 10 microseconds.
3266 */
3267 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3268 E1000_WRITE_FLUSH(hw);
3269 udelay(10);
3270}
3271
3272/******************************************************************************
3273* Shifts data bits out to the PHY
3274*
3275* hw - Struct containing variables accessed by shared code
3276* data - Data to send out to the PHY
3277* count - Number of bits to shift out
3278*
3279* Bits are shifted out in MSB to LSB order.
3280******************************************************************************/
3281static void
3282e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3283 uint32_t data,
3284 uint16_t count)
3285{
3286 uint32_t ctrl;
3287 uint32_t mask;
3288
3289 /* We need to shift "count" number of bits out to the PHY. So, the value
3290 * in the "data" parameter will be shifted out to the PHY one bit at a
3291 * time. In order to do this, "data" must be broken down into bits.
3292 */
3293 mask = 0x01;
3294 mask <<= (count - 1);
3295
3296 ctrl = E1000_READ_REG(hw, CTRL);
3297
3298 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3299 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3300
Auke Kok8fc897b2006-08-28 14:56:16 -07003301 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3303 * then raising and lowering the Management Data Clock. A "0" is
3304 * shifted out to the PHY by setting the MDIO bit to "0" and then
3305 * raising and lowering the clock.
3306 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003307 if (data & mask)
3308 ctrl |= E1000_CTRL_MDIO;
3309 else
3310 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
3312 E1000_WRITE_REG(hw, CTRL, ctrl);
3313 E1000_WRITE_FLUSH(hw);
3314
3315 udelay(10);
3316
3317 e1000_raise_mdi_clk(hw, &ctrl);
3318 e1000_lower_mdi_clk(hw, &ctrl);
3319
3320 mask = mask >> 1;
3321 }
3322}
3323
3324/******************************************************************************
3325* Shifts data bits in from the PHY
3326*
3327* hw - Struct containing variables accessed by shared code
3328*
3329* Bits are shifted in in MSB to LSB order.
3330******************************************************************************/
3331static uint16_t
3332e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3333{
3334 uint32_t ctrl;
3335 uint16_t data = 0;
3336 uint8_t i;
3337
3338 /* In order to read a register from the PHY, we need to shift in a total
3339 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3340 * to avoid contention on the MDIO pin when a read operation is performed.
3341 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3342 * by raising the input to the Management Data Clock (setting the MDC bit),
3343 * and then reading the value of the MDIO bit.
3344 */
3345 ctrl = E1000_READ_REG(hw, CTRL);
3346
3347 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3348 ctrl &= ~E1000_CTRL_MDIO_DIR;
3349 ctrl &= ~E1000_CTRL_MDIO;
3350
3351 E1000_WRITE_REG(hw, CTRL, ctrl);
3352 E1000_WRITE_FLUSH(hw);
3353
3354 /* Raise and Lower the clock before reading in the data. This accounts for
3355 * the turnaround bits. The first clock occurred when we clocked out the
3356 * last bit of the Register Address.
3357 */
3358 e1000_raise_mdi_clk(hw, &ctrl);
3359 e1000_lower_mdi_clk(hw, &ctrl);
3360
Auke Kok8fc897b2006-08-28 14:56:16 -07003361 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 data = data << 1;
3363 e1000_raise_mdi_clk(hw, &ctrl);
3364 ctrl = E1000_READ_REG(hw, CTRL);
3365 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003366 if (ctrl & E1000_CTRL_MDIO)
3367 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 e1000_lower_mdi_clk(hw, &ctrl);
3369 }
3370
3371 e1000_raise_mdi_clk(hw, &ctrl);
3372 e1000_lower_mdi_clk(hw, &ctrl);
3373
3374 return data;
3375}
3376
Adrian Bunke4c780b2006-08-14 23:00:10 -07003377static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003378e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3379{
3380 uint32_t swfw_sync = 0;
3381 uint32_t swmask = mask;
3382 uint32_t fwmask = mask << 16;
3383 int32_t timeout = 200;
3384
3385 DEBUGFUNC("e1000_swfw_sync_acquire");
3386
Auke Kokcd94dd02006-06-27 09:08:22 -07003387 if (hw->swfwhw_semaphore_present)
3388 return e1000_get_software_flag(hw);
3389
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003390 if (!hw->swfw_sync_present)
3391 return e1000_get_hw_eeprom_semaphore(hw);
3392
Auke Kok8fc897b2006-08-28 14:56:16 -07003393 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003394 if (e1000_get_hw_eeprom_semaphore(hw))
3395 return -E1000_ERR_SWFW_SYNC;
3396
3397 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3398 if (!(swfw_sync & (fwmask | swmask))) {
3399 break;
3400 }
3401
3402 /* firmware currently using resource (fwmask) */
3403 /* or other software thread currently using resource (swmask) */
3404 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003405 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003406 timeout--;
3407 }
3408
3409 if (!timeout) {
3410 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3411 return -E1000_ERR_SWFW_SYNC;
3412 }
3413
3414 swfw_sync |= swmask;
3415 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3416
3417 e1000_put_hw_eeprom_semaphore(hw);
3418 return E1000_SUCCESS;
3419}
3420
Adrian Bunke4c780b2006-08-14 23:00:10 -07003421static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003422e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3423{
3424 uint32_t swfw_sync;
3425 uint32_t swmask = mask;
3426
3427 DEBUGFUNC("e1000_swfw_sync_release");
3428
Auke Kokcd94dd02006-06-27 09:08:22 -07003429 if (hw->swfwhw_semaphore_present) {
3430 e1000_release_software_flag(hw);
3431 return;
3432 }
3433
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003434 if (!hw->swfw_sync_present) {
3435 e1000_put_hw_eeprom_semaphore(hw);
3436 return;
3437 }
3438
3439 /* if (e1000_get_hw_eeprom_semaphore(hw))
3440 * return -E1000_ERR_SWFW_SYNC; */
3441 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3442 /* empty */
3443
3444 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3445 swfw_sync &= ~swmask;
3446 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3447
3448 e1000_put_hw_eeprom_semaphore(hw);
3449}
3450
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451/*****************************************************************************
3452* Reads the value from a PHY register, if the value is on a specific non zero
3453* page, sets the page first.
3454* hw - Struct containing variables accessed by shared code
3455* reg_addr - address of the PHY register to read
3456******************************************************************************/
3457int32_t
3458e1000_read_phy_reg(struct e1000_hw *hw,
3459 uint32_t reg_addr,
3460 uint16_t *phy_data)
3461{
3462 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003463 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
3465 DEBUGFUNC("e1000_read_phy_reg");
3466
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003467 if ((hw->mac_type == e1000_80003es2lan) &&
3468 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3469 swfw = E1000_SWFW_PHY1_SM;
3470 } else {
3471 swfw = E1000_SWFW_PHY0_SM;
3472 }
3473 if (e1000_swfw_sync_acquire(hw, swfw))
3474 return -E1000_ERR_SWFW_SYNC;
3475
Auke Kokcd94dd02006-06-27 09:08:22 -07003476 if ((hw->phy_type == e1000_phy_igp ||
3477 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003478 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3480 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3481 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003482 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003483 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 return ret_val;
3485 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003486 } else if (hw->phy_type == e1000_phy_gg82563) {
3487 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3488 (hw->mac_type == e1000_80003es2lan)) {
3489 /* Select Configuration Page */
3490 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3491 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3492 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3493 } else {
3494 /* Use Alternative Page Select register to access
3495 * registers 30 and 31
3496 */
3497 ret_val = e1000_write_phy_reg_ex(hw,
3498 GG82563_PHY_PAGE_SELECT_ALT,
3499 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3500 }
3501
3502 if (ret_val) {
3503 e1000_swfw_sync_release(hw, swfw);
3504 return ret_val;
3505 }
3506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 }
3508
3509 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3510 phy_data);
3511
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003512 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 return ret_val;
3514}
3515
Nicholas Nunley35574762006-09-27 12:53:34 -07003516static int32_t
3517e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 uint16_t *phy_data)
3519{
3520 uint32_t i;
3521 uint32_t mdic = 0;
3522 const uint32_t phy_addr = 1;
3523
3524 DEBUGFUNC("e1000_read_phy_reg_ex");
3525
Auke Kok8fc897b2006-08-28 14:56:16 -07003526 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3528 return -E1000_ERR_PARAM;
3529 }
3530
Auke Kok8fc897b2006-08-28 14:56:16 -07003531 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 /* Set up Op-code, Phy Address, and register address in the MDI
3533 * Control register. The MAC will take care of interfacing with the
3534 * PHY to retrieve the desired data.
3535 */
3536 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3537 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3538 (E1000_MDIC_OP_READ));
3539
3540 E1000_WRITE_REG(hw, MDIC, mdic);
3541
3542 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003543 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 udelay(50);
3545 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003546 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003548 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 DEBUGOUT("MDI Read did not complete\n");
3550 return -E1000_ERR_PHY;
3551 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003552 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 DEBUGOUT("MDI Error\n");
3554 return -E1000_ERR_PHY;
3555 }
3556 *phy_data = (uint16_t) mdic;
3557 } else {
3558 /* We must first send a preamble through the MDIO pin to signal the
3559 * beginning of an MII instruction. This is done by sending 32
3560 * consecutive "1" bits.
3561 */
3562 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3563
3564 /* Now combine the next few fields that are required for a read
3565 * operation. We use this method instead of calling the
3566 * e1000_shift_out_mdi_bits routine five different times. The format of
3567 * a MII read instruction consists of a shift out of 14 bits and is
3568 * defined as follows:
3569 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3570 * followed by a shift in of 18 bits. This first two bits shifted in
3571 * are TurnAround bits used to avoid contention on the MDIO pin when a
3572 * READ operation is performed. These two bits are thrown away
3573 * followed by a shift in of 16 bits which contains the desired data.
3574 */
3575 mdic = ((reg_addr) | (phy_addr << 5) |
3576 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3577
3578 e1000_shift_out_mdi_bits(hw, mdic, 14);
3579
3580 /* Now that we've shifted out the read command to the MII, we need to
3581 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3582 * register address.
3583 */
3584 *phy_data = e1000_shift_in_mdi_bits(hw);
3585 }
3586 return E1000_SUCCESS;
3587}
3588
3589/******************************************************************************
3590* Writes a value to a PHY register
3591*
3592* hw - Struct containing variables accessed by shared code
3593* reg_addr - address of the PHY register to write
3594* data - data to write to the PHY
3595******************************************************************************/
3596int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003597e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 uint16_t phy_data)
3599{
3600 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003601 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
3603 DEBUGFUNC("e1000_write_phy_reg");
3604
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003605 if ((hw->mac_type == e1000_80003es2lan) &&
3606 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3607 swfw = E1000_SWFW_PHY1_SM;
3608 } else {
3609 swfw = E1000_SWFW_PHY0_SM;
3610 }
3611 if (e1000_swfw_sync_acquire(hw, swfw))
3612 return -E1000_ERR_SWFW_SYNC;
3613
Auke Kokcd94dd02006-06-27 09:08:22 -07003614 if ((hw->phy_type == e1000_phy_igp ||
3615 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003616 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3618 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3619 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003620 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003621 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 return ret_val;
3623 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003624 } else if (hw->phy_type == e1000_phy_gg82563) {
3625 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3626 (hw->mac_type == e1000_80003es2lan)) {
3627 /* Select Configuration Page */
3628 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3629 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3630 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3631 } else {
3632 /* Use Alternative Page Select register to access
3633 * registers 30 and 31
3634 */
3635 ret_val = e1000_write_phy_reg_ex(hw,
3636 GG82563_PHY_PAGE_SELECT_ALT,
3637 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3638 }
3639
3640 if (ret_val) {
3641 e1000_swfw_sync_release(hw, swfw);
3642 return ret_val;
3643 }
3644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 }
3646
3647 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3648 phy_data);
3649
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003650 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 return ret_val;
3652}
3653
Nicholas Nunley35574762006-09-27 12:53:34 -07003654static int32_t
3655e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3656 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657{
3658 uint32_t i;
3659 uint32_t mdic = 0;
3660 const uint32_t phy_addr = 1;
3661
3662 DEBUGFUNC("e1000_write_phy_reg_ex");
3663
Auke Kok8fc897b2006-08-28 14:56:16 -07003664 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3666 return -E1000_ERR_PARAM;
3667 }
3668
Auke Kok8fc897b2006-08-28 14:56:16 -07003669 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 /* Set up Op-code, Phy Address, register address, and data intended
3671 * for the PHY register in the MDI Control register. The MAC will take
3672 * care of interfacing with the PHY to send the desired data.
3673 */
3674 mdic = (((uint32_t) phy_data) |
3675 (reg_addr << E1000_MDIC_REG_SHIFT) |
3676 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3677 (E1000_MDIC_OP_WRITE));
3678
3679 E1000_WRITE_REG(hw, MDIC, mdic);
3680
3681 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003682 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 udelay(5);
3684 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003685 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003687 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 DEBUGOUT("MDI Write did not complete\n");
3689 return -E1000_ERR_PHY;
3690 }
3691 } else {
3692 /* We'll need to use the SW defined pins to shift the write command
3693 * out to the PHY. We first send a preamble to the PHY to signal the
3694 * beginning of the MII instruction. This is done by sending 32
3695 * consecutive "1" bits.
3696 */
3697 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3698
3699 /* Now combine the remaining required fields that will indicate a
3700 * write operation. We use this method instead of calling the
3701 * e1000_shift_out_mdi_bits routine for each field in the command. The
3702 * format of a MII write instruction is as follows:
3703 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3704 */
3705 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3706 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3707 mdic <<= 16;
3708 mdic |= (uint32_t) phy_data;
3709
3710 e1000_shift_out_mdi_bits(hw, mdic, 32);
3711 }
3712
3713 return E1000_SUCCESS;
3714}
3715
Adrian Bunke4c780b2006-08-14 23:00:10 -07003716static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003717e1000_read_kmrn_reg(struct e1000_hw *hw,
3718 uint32_t reg_addr,
3719 uint16_t *data)
3720{
3721 uint32_t reg_val;
3722 uint16_t swfw;
3723 DEBUGFUNC("e1000_read_kmrn_reg");
3724
3725 if ((hw->mac_type == e1000_80003es2lan) &&
3726 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3727 swfw = E1000_SWFW_PHY1_SM;
3728 } else {
3729 swfw = E1000_SWFW_PHY0_SM;
3730 }
3731 if (e1000_swfw_sync_acquire(hw, swfw))
3732 return -E1000_ERR_SWFW_SYNC;
3733
3734 /* Write register address */
3735 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3736 E1000_KUMCTRLSTA_OFFSET) |
3737 E1000_KUMCTRLSTA_REN;
3738 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3739 udelay(2);
3740
3741 /* Read the data returned */
3742 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3743 *data = (uint16_t)reg_val;
3744
3745 e1000_swfw_sync_release(hw, swfw);
3746 return E1000_SUCCESS;
3747}
3748
Adrian Bunke4c780b2006-08-14 23:00:10 -07003749static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003750e1000_write_kmrn_reg(struct e1000_hw *hw,
3751 uint32_t reg_addr,
3752 uint16_t data)
3753{
3754 uint32_t reg_val;
3755 uint16_t swfw;
3756 DEBUGFUNC("e1000_write_kmrn_reg");
3757
3758 if ((hw->mac_type == e1000_80003es2lan) &&
3759 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3760 swfw = E1000_SWFW_PHY1_SM;
3761 } else {
3762 swfw = E1000_SWFW_PHY0_SM;
3763 }
3764 if (e1000_swfw_sync_acquire(hw, swfw))
3765 return -E1000_ERR_SWFW_SYNC;
3766
3767 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3768 E1000_KUMCTRLSTA_OFFSET) | data;
3769 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3770 udelay(2);
3771
3772 e1000_swfw_sync_release(hw, swfw);
3773 return E1000_SUCCESS;
3774}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003775
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776/******************************************************************************
3777* Returns the PHY to the power-on reset state
3778*
3779* hw - Struct containing variables accessed by shared code
3780******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003781int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782e1000_phy_hw_reset(struct e1000_hw *hw)
3783{
3784 uint32_t ctrl, ctrl_ext;
3785 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003786 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003787 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788
3789 DEBUGFUNC("e1000_phy_hw_reset");
3790
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003791 /* In the case of the phy reset being blocked, it's not an error, we
3792 * simply return success without performing the reset. */
3793 ret_val = e1000_check_phy_reset_block(hw);
3794 if (ret_val)
3795 return E1000_SUCCESS;
3796
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 DEBUGOUT("Resetting Phy...\n");
3798
Auke Kok8fc897b2006-08-28 14:56:16 -07003799 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003800 if ((hw->mac_type == e1000_80003es2lan) &&
3801 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3802 swfw = E1000_SWFW_PHY1_SM;
3803 } else {
3804 swfw = E1000_SWFW_PHY0_SM;
3805 }
3806 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003807 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003808 return -E1000_ERR_SWFW_SYNC;
3809 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3811 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003812 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003813 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003814 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 */
3816 ctrl = E1000_READ_REG(hw, CTRL);
3817 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3818 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003819
3820 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003821 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003822 else
3823 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003824
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 E1000_WRITE_REG(hw, CTRL, ctrl);
3826 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003827
Jeff Kirsherfd803242005-12-13 00:06:22 -05003828 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003829 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003830
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003831 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 } else {
3833 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3834 * bit to put the PHY into reset. Then, take it out of reset.
3835 */
3836 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3837 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3838 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3839 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3840 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003841 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3843 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3844 E1000_WRITE_FLUSH(hw);
3845 }
3846 udelay(150);
3847
Auke Kok8fc897b2006-08-28 14:56:16 -07003848 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 /* Configure activity LED after PHY reset */
3850 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3851 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3852 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3853 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3854 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003855
3856 /* Wait for FW to finish PHY configuration. */
3857 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003858 if (ret_val != E1000_SUCCESS)
3859 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003860 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003861
Auke Kok8fc897b2006-08-28 14:56:16 -07003862 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3863 ret_val = e1000_init_lcd_from_nvm(hw);
3864
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003865 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866}
3867
3868/******************************************************************************
3869* Resets the PHY
3870*
3871* hw - Struct containing variables accessed by shared code
3872*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003873* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874******************************************************************************/
3875int32_t
3876e1000_phy_reset(struct e1000_hw *hw)
3877{
3878 int32_t ret_val;
3879 uint16_t phy_data;
3880
3881 DEBUGFUNC("e1000_phy_reset");
3882
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003883 /* In the case of the phy reset being blocked, it's not an error, we
3884 * simply return success without performing the reset. */
3885 ret_val = e1000_check_phy_reset_block(hw);
3886 if (ret_val)
3887 return E1000_SUCCESS;
3888
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003889 switch (hw->phy_type) {
3890 case e1000_phy_igp:
3891 case e1000_phy_igp_2:
3892 case e1000_phy_igp_3:
3893 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003894 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003895 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003896 return ret_val;
3897 break;
3898 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003900 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 return ret_val;
3902
3903 phy_data |= MII_CR_RESET;
3904 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003905 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 return ret_val;
3907
3908 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003909 break;
3910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911
Auke Kok8fc897b2006-08-28 14:56:16 -07003912 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 e1000_phy_init_script(hw);
3914
3915 return E1000_SUCCESS;
3916}
3917
3918/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003919* Work-around for 82566 power-down: on D3 entry-
3920* 1) disable gigabit link
3921* 2) write VR power-down enable
3922* 3) read it back
3923* if successful continue, else issue LCD reset and repeat
3924*
3925* hw - struct containing variables accessed by shared code
3926******************************************************************************/
3927void
3928e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3929{
3930 int32_t reg;
3931 uint16_t phy_data;
3932 int32_t retry = 0;
3933
3934 DEBUGFUNC("e1000_phy_powerdown_workaround");
3935
3936 if (hw->phy_type != e1000_phy_igp_3)
3937 return;
3938
3939 do {
3940 /* Disable link */
3941 reg = E1000_READ_REG(hw, PHY_CTRL);
3942 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3943 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3944
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003945 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003946 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003947 phy_data |= (1 << 9);
3948 phy_data &= ~(1 << 8);
3949 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003950
3951 /* Read it back and test */
3952 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003953 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003954 break;
3955
3956 /* Issue PHY reset and repeat at most one more time */
3957 reg = E1000_READ_REG(hw, CTRL);
3958 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3959 retry++;
3960 } while (retry);
3961
3962 return;
3963
3964}
3965
3966/******************************************************************************
3967* Work-around for 82566 Kumeran PCS lock loss:
3968* On link status change (i.e. PCI reset, speed change) and link is up and
3969* speed is gigabit-
3970* 0) if workaround is optionally disabled do nothing
3971* 1) wait 1ms for Kumeran link to come up
3972* 2) check Kumeran Diagnostic register PCS lock loss bit
3973* 3) if not set the link is locked (all is good), otherwise...
3974* 4) reset the PHY
3975* 5) repeat up to 10 times
3976* Note: this is only called for IGP3 copper when speed is 1gb.
3977*
3978* hw - struct containing variables accessed by shared code
3979******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003980static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003981e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3982{
3983 int32_t ret_val;
3984 int32_t reg;
3985 int32_t cnt;
3986 uint16_t phy_data;
3987
3988 if (hw->kmrn_lock_loss_workaround_disabled)
3989 return E1000_SUCCESS;
3990
Auke Kok8fc897b2006-08-28 14:56:16 -07003991 /* Make sure link is up before proceeding. If not just return.
3992 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003993 * stability */
3994 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3995 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3996
3997 if (phy_data & MII_SR_LINK_STATUS) {
3998 for (cnt = 0; cnt < 10; cnt++) {
3999 /* read once to clear */
4000 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4001 if (ret_val)
4002 return ret_val;
4003 /* and again to get new status */
4004 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4005 if (ret_val)
4006 return ret_val;
4007
4008 /* check for PCS lock */
4009 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4010 return E1000_SUCCESS;
4011
4012 /* Issue PHY reset */
4013 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004014 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004015 }
4016 /* Disable GigE link negotiation */
4017 reg = E1000_READ_REG(hw, PHY_CTRL);
4018 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4019 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4020
4021 /* unable to acquire PCS lock */
4022 return E1000_ERR_PHY;
4023 }
4024
4025 return E1000_SUCCESS;
4026}
4027
4028/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029* Probes the expected PHY address for known PHY IDs
4030*
4031* hw - Struct containing variables accessed by shared code
4032******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004033static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034e1000_detect_gig_phy(struct e1000_hw *hw)
4035{
4036 int32_t phy_init_status, ret_val;
4037 uint16_t phy_id_high, phy_id_low;
4038 boolean_t match = FALSE;
4039
4040 DEBUGFUNC("e1000_detect_gig_phy");
4041
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004042 if (hw->phy_id != 0)
4043 return E1000_SUCCESS;
4044
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004045 /* The 82571 firmware may still be configuring the PHY. In this
4046 * case, we cannot access the PHY until the configuration is done. So
4047 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004048 if (hw->mac_type == e1000_82571 ||
4049 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004050 hw->phy_id = IGP01E1000_I_PHY_ID;
4051 hw->phy_type = e1000_phy_igp_2;
4052 return E1000_SUCCESS;
4053 }
4054
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004055 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4056 * around that forces PHY page 0 to be set or the reads fail. The rest of
4057 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4058 * So for ESB-2 we need to have this set so our reads won't fail. If the
4059 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4060 * this out as well. */
4061 if (hw->mac_type == e1000_80003es2lan)
4062 hw->phy_type = e1000_phy_gg82563;
4063
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 /* Read the PHY ID Registers to identify which PHY is onboard. */
4065 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004066 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 return ret_val;
4068
4069 hw->phy_id = (uint32_t) (phy_id_high << 16);
4070 udelay(20);
4071 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004072 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 return ret_val;
4074
4075 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4076 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4077
Auke Kok8fc897b2006-08-28 14:56:16 -07004078 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004080 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 break;
4082 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004083 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 break;
4085 case e1000_82540:
4086 case e1000_82545:
4087 case e1000_82545_rev_3:
4088 case e1000_82546:
4089 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004090 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 break;
4092 case e1000_82541:
4093 case e1000_82541_rev_2:
4094 case e1000_82547:
4095 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004096 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004098 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004099 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004100 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004101 case e1000_80003es2lan:
4102 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4103 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004104 case e1000_ich8lan:
4105 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4106 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4107 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4108 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4109 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 default:
4111 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4112 return -E1000_ERR_CONFIG;
4113 }
4114 phy_init_status = e1000_set_phy_type(hw);
4115
4116 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4117 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4118 return E1000_SUCCESS;
4119 }
4120 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4121 return -E1000_ERR_PHY;
4122}
4123
4124/******************************************************************************
4125* Resets the PHY's DSP
4126*
4127* hw - Struct containing variables accessed by shared code
4128******************************************************************************/
4129static int32_t
4130e1000_phy_reset_dsp(struct e1000_hw *hw)
4131{
4132 int32_t ret_val;
4133 DEBUGFUNC("e1000_phy_reset_dsp");
4134
4135 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004136 if (hw->phy_type != e1000_phy_gg82563) {
4137 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004138 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004141 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004143 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004145 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146
4147 return ret_val;
4148}
4149
4150/******************************************************************************
4151* Get PHY information from various PHY registers for igp PHY only.
4152*
4153* hw - Struct containing variables accessed by shared code
4154* phy_info - PHY information structure
4155******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004156static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157e1000_phy_igp_get_info(struct e1000_hw *hw,
4158 struct e1000_phy_info *phy_info)
4159{
4160 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004161 uint16_t phy_data, min_length, max_length, average;
4162 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163
4164 DEBUGFUNC("e1000_phy_igp_get_info");
4165
4166 /* The downshift status is checked only once, after link is established,
4167 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004168 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
4170 /* IGP01E1000 does not need to support it. */
4171 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4172
4173 /* IGP01E1000 always correct polarity reversal */
4174 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4175
4176 /* Check polarity status */
4177 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004178 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 return ret_val;
4180
4181 phy_info->cable_polarity = polarity;
4182
4183 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004184 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 return ret_val;
4186
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004187 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4188 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189
Auke Kok8fc897b2006-08-28 14:56:16 -07004190 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 IGP01E1000_PSSR_SPEED_1000MBPS) {
4192 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4193 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004194 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 return ret_val;
4196
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004197 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4198 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4199 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4200 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4201 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4202 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203
4204 /* Get cable length */
4205 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004206 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 return ret_val;
4208
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004209 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 average = (max_length + min_length) / 2;
4211
Auke Kok8fc897b2006-08-28 14:56:16 -07004212 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004214 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004216 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004218 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 phy_info->cable_length = e1000_cable_length_110_140;
4220 else
4221 phy_info->cable_length = e1000_cable_length_140;
4222 }
4223
4224 return E1000_SUCCESS;
4225}
4226
4227/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004228* Get PHY information from various PHY registers for ife PHY only.
4229*
4230* hw - Struct containing variables accessed by shared code
4231* phy_info - PHY information structure
4232******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004233static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004234e1000_phy_ife_get_info(struct e1000_hw *hw,
4235 struct e1000_phy_info *phy_info)
4236{
4237 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004238 uint16_t phy_data;
4239 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004240
4241 DEBUGFUNC("e1000_phy_ife_get_info");
4242
4243 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4244 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4245
4246 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4247 if (ret_val)
4248 return ret_val;
4249 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004250 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4251 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4252 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004253
4254 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4255 ret_val = e1000_check_polarity(hw, &polarity);
4256 if (ret_val)
4257 return ret_val;
4258 } else {
4259 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004260 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4261 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4262 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004263 }
4264 phy_info->cable_polarity = polarity;
4265
4266 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4267 if (ret_val)
4268 return ret_val;
4269
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004270 phy_info->mdix_mode = (e1000_auto_x_mode)
4271 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4272 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004273
4274 return E1000_SUCCESS;
4275}
4276
4277/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278* Get PHY information from various PHY registers fot m88 PHY only.
4279*
4280* hw - Struct containing variables accessed by shared code
4281* phy_info - PHY information structure
4282******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004283static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284e1000_phy_m88_get_info(struct e1000_hw *hw,
4285 struct e1000_phy_info *phy_info)
4286{
4287 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004288 uint16_t phy_data;
4289 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290
4291 DEBUGFUNC("e1000_phy_m88_get_info");
4292
4293 /* The downshift status is checked only once, after link is established,
4294 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004295 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296
4297 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004298 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 return ret_val;
4300
4301 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004302 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4303 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4304 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4305
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004307 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4308 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4309 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310
4311 /* Check polarity status */
4312 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004313 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004314 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 phy_info->cable_polarity = polarity;
4316
4317 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004318 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 return ret_val;
4320
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004321 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4322 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323
4324 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4325 /* Cable Length Estimation and Local/Remote Receiver Information
4326 * are only valid at 1000 Mbps.
4327 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004328 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004329 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004330 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4331 } else {
4332 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4333 &phy_data);
4334 if (ret_val)
4335 return ret_val;
4336
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004337 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339
4340 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004341 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 return ret_val;
4343
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004344 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4345 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4346 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4347 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4348 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4349 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 }
4352
4353 return E1000_SUCCESS;
4354}
4355
4356/******************************************************************************
4357* Get PHY information from various PHY registers
4358*
4359* hw - Struct containing variables accessed by shared code
4360* phy_info - PHY information structure
4361******************************************************************************/
4362int32_t
4363e1000_phy_get_info(struct e1000_hw *hw,
4364 struct e1000_phy_info *phy_info)
4365{
4366 int32_t ret_val;
4367 uint16_t phy_data;
4368
4369 DEBUGFUNC("e1000_phy_get_info");
4370
4371 phy_info->cable_length = e1000_cable_length_undefined;
4372 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4373 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4374 phy_info->downshift = e1000_downshift_undefined;
4375 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4376 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4377 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4378 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4379
Auke Kok8fc897b2006-08-28 14:56:16 -07004380 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 DEBUGOUT("PHY info is only valid for copper media\n");
4382 return -E1000_ERR_CONFIG;
4383 }
4384
4385 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004386 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 return ret_val;
4388
4389 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004390 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 return ret_val;
4392
Auke Kok8fc897b2006-08-28 14:56:16 -07004393 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 DEBUGOUT("PHY info is only valid if link is up\n");
4395 return -E1000_ERR_CONFIG;
4396 }
4397
Auke Kokcd94dd02006-06-27 09:08:22 -07004398 if (hw->phy_type == e1000_phy_igp ||
4399 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004400 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004402 else if (hw->phy_type == e1000_phy_ife)
4403 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 else
4405 return e1000_phy_m88_get_info(hw, phy_info);
4406}
4407
4408int32_t
4409e1000_validate_mdi_setting(struct e1000_hw *hw)
4410{
4411 DEBUGFUNC("e1000_validate_mdi_settings");
4412
Auke Kok8fc897b2006-08-28 14:56:16 -07004413 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 DEBUGOUT("Invalid MDI setting detected\n");
4415 hw->mdix = 1;
4416 return -E1000_ERR_CONFIG;
4417 }
4418 return E1000_SUCCESS;
4419}
4420
4421
4422/******************************************************************************
4423 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004424 * is configured. Additionally, if this is ICH8, the flash controller GbE
4425 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 *
4427 * hw - Struct containing variables accessed by shared code
4428 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004429int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430e1000_init_eeprom_params(struct e1000_hw *hw)
4431{
4432 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4433 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004434 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 uint16_t eeprom_size;
4436
4437 DEBUGFUNC("e1000_init_eeprom_params");
4438
4439 switch (hw->mac_type) {
4440 case e1000_82542_rev2_0:
4441 case e1000_82542_rev2_1:
4442 case e1000_82543:
4443 case e1000_82544:
4444 eeprom->type = e1000_eeprom_microwire;
4445 eeprom->word_size = 64;
4446 eeprom->opcode_bits = 3;
4447 eeprom->address_bits = 6;
4448 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004449 eeprom->use_eerd = FALSE;
4450 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 break;
4452 case e1000_82540:
4453 case e1000_82545:
4454 case e1000_82545_rev_3:
4455 case e1000_82546:
4456 case e1000_82546_rev_3:
4457 eeprom->type = e1000_eeprom_microwire;
4458 eeprom->opcode_bits = 3;
4459 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004460 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 eeprom->word_size = 256;
4462 eeprom->address_bits = 8;
4463 } else {
4464 eeprom->word_size = 64;
4465 eeprom->address_bits = 6;
4466 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004467 eeprom->use_eerd = FALSE;
4468 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 break;
4470 case e1000_82541:
4471 case e1000_82541_rev_2:
4472 case e1000_82547:
4473 case e1000_82547_rev_2:
4474 if (eecd & E1000_EECD_TYPE) {
4475 eeprom->type = e1000_eeprom_spi;
4476 eeprom->opcode_bits = 8;
4477 eeprom->delay_usec = 1;
4478 if (eecd & E1000_EECD_ADDR_BITS) {
4479 eeprom->page_size = 32;
4480 eeprom->address_bits = 16;
4481 } else {
4482 eeprom->page_size = 8;
4483 eeprom->address_bits = 8;
4484 }
4485 } else {
4486 eeprom->type = e1000_eeprom_microwire;
4487 eeprom->opcode_bits = 3;
4488 eeprom->delay_usec = 50;
4489 if (eecd & E1000_EECD_ADDR_BITS) {
4490 eeprom->word_size = 256;
4491 eeprom->address_bits = 8;
4492 } else {
4493 eeprom->word_size = 64;
4494 eeprom->address_bits = 6;
4495 }
4496 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004497 eeprom->use_eerd = FALSE;
4498 eeprom->use_eewr = FALSE;
4499 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004500 case e1000_82571:
4501 case e1000_82572:
4502 eeprom->type = e1000_eeprom_spi;
4503 eeprom->opcode_bits = 8;
4504 eeprom->delay_usec = 1;
4505 if (eecd & E1000_EECD_ADDR_BITS) {
4506 eeprom->page_size = 32;
4507 eeprom->address_bits = 16;
4508 } else {
4509 eeprom->page_size = 8;
4510 eeprom->address_bits = 8;
4511 }
4512 eeprom->use_eerd = FALSE;
4513 eeprom->use_eewr = FALSE;
4514 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004515 case e1000_82573:
4516 eeprom->type = e1000_eeprom_spi;
4517 eeprom->opcode_bits = 8;
4518 eeprom->delay_usec = 1;
4519 if (eecd & E1000_EECD_ADDR_BITS) {
4520 eeprom->page_size = 32;
4521 eeprom->address_bits = 16;
4522 } else {
4523 eeprom->page_size = 8;
4524 eeprom->address_bits = 8;
4525 }
4526 eeprom->use_eerd = TRUE;
4527 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004528 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004529 eeprom->type = e1000_eeprom_flash;
4530 eeprom->word_size = 2048;
4531
4532 /* Ensure that the Autonomous FLASH update bit is cleared due to
4533 * Flash update issue on parts which use a FLASH for NVM. */
4534 eecd &= ~E1000_EECD_AUPDEN;
4535 E1000_WRITE_REG(hw, EECD, eecd);
4536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004538 case e1000_80003es2lan:
4539 eeprom->type = e1000_eeprom_spi;
4540 eeprom->opcode_bits = 8;
4541 eeprom->delay_usec = 1;
4542 if (eecd & E1000_EECD_ADDR_BITS) {
4543 eeprom->page_size = 32;
4544 eeprom->address_bits = 16;
4545 } else {
4546 eeprom->page_size = 8;
4547 eeprom->address_bits = 8;
4548 }
4549 eeprom->use_eerd = TRUE;
4550 eeprom->use_eewr = FALSE;
4551 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004552 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004553 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004554 int32_t i = 0;
4555 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4556
4557 eeprom->type = e1000_eeprom_ich8;
4558 eeprom->use_eerd = FALSE;
4559 eeprom->use_eewr = FALSE;
4560 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4561
4562 /* Zero the shadow RAM structure. But don't load it from NVM
4563 * so as to save time for driver init */
4564 if (hw->eeprom_shadow_ram != NULL) {
4565 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4566 hw->eeprom_shadow_ram[i].modified = FALSE;
4567 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4568 }
4569 }
4570
4571 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4572 ICH8_FLASH_SECTOR_SIZE;
4573
4574 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4575 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4576 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4577 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4578
4579 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 default:
4582 break;
4583 }
4584
4585 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004586 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4587 * 32KB (incremented by powers of 2).
4588 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004589 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004590 /* Set to default value for initial eeprom read. */
4591 eeprom->word_size = 64;
4592 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004593 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004594 return ret_val;
4595 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4596 /* 256B eeprom size was not supported in earlier hardware, so we
4597 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4598 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004599 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004600 eeprom_size++;
4601 } else {
4602 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4603 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004605
4606 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004608 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609}
4610
4611/******************************************************************************
4612 * Raises the EEPROM's clock input.
4613 *
4614 * hw - Struct containing variables accessed by shared code
4615 * eecd - EECD's current value
4616 *****************************************************************************/
4617static void
4618e1000_raise_ee_clk(struct e1000_hw *hw,
4619 uint32_t *eecd)
4620{
4621 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4622 * wait <delay> microseconds.
4623 */
4624 *eecd = *eecd | E1000_EECD_SK;
4625 E1000_WRITE_REG(hw, EECD, *eecd);
4626 E1000_WRITE_FLUSH(hw);
4627 udelay(hw->eeprom.delay_usec);
4628}
4629
4630/******************************************************************************
4631 * Lowers the EEPROM's clock input.
4632 *
4633 * hw - Struct containing variables accessed by shared code
4634 * eecd - EECD's current value
4635 *****************************************************************************/
4636static void
4637e1000_lower_ee_clk(struct e1000_hw *hw,
4638 uint32_t *eecd)
4639{
4640 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4641 * wait 50 microseconds.
4642 */
4643 *eecd = *eecd & ~E1000_EECD_SK;
4644 E1000_WRITE_REG(hw, EECD, *eecd);
4645 E1000_WRITE_FLUSH(hw);
4646 udelay(hw->eeprom.delay_usec);
4647}
4648
4649/******************************************************************************
4650 * Shift data bits out to the EEPROM.
4651 *
4652 * hw - Struct containing variables accessed by shared code
4653 * data - data to send to the EEPROM
4654 * count - number of bits to shift out
4655 *****************************************************************************/
4656static void
4657e1000_shift_out_ee_bits(struct e1000_hw *hw,
4658 uint16_t data,
4659 uint16_t count)
4660{
4661 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4662 uint32_t eecd;
4663 uint32_t mask;
4664
4665 /* We need to shift "count" bits out to the EEPROM. So, value in the
4666 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4667 * In order to do this, "data" must be broken down into bits.
4668 */
4669 mask = 0x01 << (count - 1);
4670 eecd = E1000_READ_REG(hw, EECD);
4671 if (eeprom->type == e1000_eeprom_microwire) {
4672 eecd &= ~E1000_EECD_DO;
4673 } else if (eeprom->type == e1000_eeprom_spi) {
4674 eecd |= E1000_EECD_DO;
4675 }
4676 do {
4677 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4678 * and then raising and then lowering the clock (the SK bit controls
4679 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4680 * by setting "DI" to "0" and then raising and then lowering the clock.
4681 */
4682 eecd &= ~E1000_EECD_DI;
4683
Auke Kok8fc897b2006-08-28 14:56:16 -07004684 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 eecd |= E1000_EECD_DI;
4686
4687 E1000_WRITE_REG(hw, EECD, eecd);
4688 E1000_WRITE_FLUSH(hw);
4689
4690 udelay(eeprom->delay_usec);
4691
4692 e1000_raise_ee_clk(hw, &eecd);
4693 e1000_lower_ee_clk(hw, &eecd);
4694
4695 mask = mask >> 1;
4696
Auke Kok8fc897b2006-08-28 14:56:16 -07004697 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698
4699 /* We leave the "DI" bit set to "0" when we leave this routine. */
4700 eecd &= ~E1000_EECD_DI;
4701 E1000_WRITE_REG(hw, EECD, eecd);
4702}
4703
4704/******************************************************************************
4705 * Shift data bits in from the EEPROM
4706 *
4707 * hw - Struct containing variables accessed by shared code
4708 *****************************************************************************/
4709static uint16_t
4710e1000_shift_in_ee_bits(struct e1000_hw *hw,
4711 uint16_t count)
4712{
4713 uint32_t eecd;
4714 uint32_t i;
4715 uint16_t data;
4716
4717 /* In order to read a register from the EEPROM, we need to shift 'count'
4718 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4719 * input to the EEPROM (setting the SK bit), and then reading the value of
4720 * the "DO" bit. During this "shifting in" process the "DI" bit should
4721 * always be clear.
4722 */
4723
4724 eecd = E1000_READ_REG(hw, EECD);
4725
4726 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4727 data = 0;
4728
Auke Kok8fc897b2006-08-28 14:56:16 -07004729 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 data = data << 1;
4731 e1000_raise_ee_clk(hw, &eecd);
4732
4733 eecd = E1000_READ_REG(hw, EECD);
4734
4735 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004736 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 data |= 1;
4738
4739 e1000_lower_ee_clk(hw, &eecd);
4740 }
4741
4742 return data;
4743}
4744
4745/******************************************************************************
4746 * Prepares EEPROM for access
4747 *
4748 * hw - Struct containing variables accessed by shared code
4749 *
4750 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4751 * function should be called before issuing a command to the EEPROM.
4752 *****************************************************************************/
4753static int32_t
4754e1000_acquire_eeprom(struct e1000_hw *hw)
4755{
4756 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4757 uint32_t eecd, i=0;
4758
4759 DEBUGFUNC("e1000_acquire_eeprom");
4760
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004761 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4762 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 eecd = E1000_READ_REG(hw, EECD);
4764
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004765 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004766 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004767 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004768 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004770 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004771 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004772 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4773 i++;
4774 udelay(5);
4775 eecd = E1000_READ_REG(hw, EECD);
4776 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004777 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004778 eecd &= ~E1000_EECD_REQ;
4779 E1000_WRITE_REG(hw, EECD, eecd);
4780 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004781 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004782 return -E1000_ERR_EEPROM;
4783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 }
4785 }
4786
4787 /* Setup EEPROM for Read/Write */
4788
4789 if (eeprom->type == e1000_eeprom_microwire) {
4790 /* Clear SK and DI */
4791 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4792 E1000_WRITE_REG(hw, EECD, eecd);
4793
4794 /* Set CS */
4795 eecd |= E1000_EECD_CS;
4796 E1000_WRITE_REG(hw, EECD, eecd);
4797 } else if (eeprom->type == e1000_eeprom_spi) {
4798 /* Clear SK and CS */
4799 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4800 E1000_WRITE_REG(hw, EECD, eecd);
4801 udelay(1);
4802 }
4803
4804 return E1000_SUCCESS;
4805}
4806
4807/******************************************************************************
4808 * Returns EEPROM to a "standby" state
4809 *
4810 * hw - Struct containing variables accessed by shared code
4811 *****************************************************************************/
4812static void
4813e1000_standby_eeprom(struct e1000_hw *hw)
4814{
4815 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4816 uint32_t eecd;
4817
4818 eecd = E1000_READ_REG(hw, EECD);
4819
Auke Kok8fc897b2006-08-28 14:56:16 -07004820 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4822 E1000_WRITE_REG(hw, EECD, eecd);
4823 E1000_WRITE_FLUSH(hw);
4824 udelay(eeprom->delay_usec);
4825
4826 /* Clock high */
4827 eecd |= E1000_EECD_SK;
4828 E1000_WRITE_REG(hw, EECD, eecd);
4829 E1000_WRITE_FLUSH(hw);
4830 udelay(eeprom->delay_usec);
4831
4832 /* Select EEPROM */
4833 eecd |= E1000_EECD_CS;
4834 E1000_WRITE_REG(hw, EECD, eecd);
4835 E1000_WRITE_FLUSH(hw);
4836 udelay(eeprom->delay_usec);
4837
4838 /* Clock low */
4839 eecd &= ~E1000_EECD_SK;
4840 E1000_WRITE_REG(hw, EECD, eecd);
4841 E1000_WRITE_FLUSH(hw);
4842 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004843 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 /* Toggle CS to flush commands */
4845 eecd |= E1000_EECD_CS;
4846 E1000_WRITE_REG(hw, EECD, eecd);
4847 E1000_WRITE_FLUSH(hw);
4848 udelay(eeprom->delay_usec);
4849 eecd &= ~E1000_EECD_CS;
4850 E1000_WRITE_REG(hw, EECD, eecd);
4851 E1000_WRITE_FLUSH(hw);
4852 udelay(eeprom->delay_usec);
4853 }
4854}
4855
4856/******************************************************************************
4857 * Terminates a command by inverting the EEPROM's chip select pin
4858 *
4859 * hw - Struct containing variables accessed by shared code
4860 *****************************************************************************/
4861static void
4862e1000_release_eeprom(struct e1000_hw *hw)
4863{
4864 uint32_t eecd;
4865
4866 DEBUGFUNC("e1000_release_eeprom");
4867
4868 eecd = E1000_READ_REG(hw, EECD);
4869
4870 if (hw->eeprom.type == e1000_eeprom_spi) {
4871 eecd |= E1000_EECD_CS; /* Pull CS high */
4872 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4873
4874 E1000_WRITE_REG(hw, EECD, eecd);
4875
4876 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004877 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 /* cleanup eeprom */
4879
4880 /* CS on Microwire is active-high */
4881 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4882
4883 E1000_WRITE_REG(hw, EECD, eecd);
4884
4885 /* Rising edge of clock */
4886 eecd |= E1000_EECD_SK;
4887 E1000_WRITE_REG(hw, EECD, eecd);
4888 E1000_WRITE_FLUSH(hw);
4889 udelay(hw->eeprom.delay_usec);
4890
4891 /* Falling edge of clock */
4892 eecd &= ~E1000_EECD_SK;
4893 E1000_WRITE_REG(hw, EECD, eecd);
4894 E1000_WRITE_FLUSH(hw);
4895 udelay(hw->eeprom.delay_usec);
4896 }
4897
4898 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004899 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 eecd &= ~E1000_EECD_REQ;
4901 E1000_WRITE_REG(hw, EECD, eecd);
4902 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004903
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004904 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905}
4906
4907/******************************************************************************
4908 * Reads a 16 bit word from the EEPROM.
4909 *
4910 * hw - Struct containing variables accessed by shared code
4911 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004912static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913e1000_spi_eeprom_ready(struct e1000_hw *hw)
4914{
4915 uint16_t retry_count = 0;
4916 uint8_t spi_stat_reg;
4917
4918 DEBUGFUNC("e1000_spi_eeprom_ready");
4919
4920 /* Read "Status Register" repeatedly until the LSB is cleared. The
4921 * EEPROM will signal that the command has been completed by clearing
4922 * bit 0 of the internal status register. If it's not cleared within
4923 * 5 milliseconds, then error out.
4924 */
4925 retry_count = 0;
4926 do {
4927 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4928 hw->eeprom.opcode_bits);
4929 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4930 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4931 break;
4932
4933 udelay(5);
4934 retry_count += 5;
4935
4936 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004937 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938
4939 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4940 * only 0-5mSec on 5V devices)
4941 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004942 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943 DEBUGOUT("SPI EEPROM Status error\n");
4944 return -E1000_ERR_EEPROM;
4945 }
4946
4947 return E1000_SUCCESS;
4948}
4949
4950/******************************************************************************
4951 * Reads a 16 bit word from the EEPROM.
4952 *
4953 * hw - Struct containing variables accessed by shared code
4954 * offset - offset of word in the EEPROM to read
4955 * data - word read from the EEPROM
4956 * words - number of words to read
4957 *****************************************************************************/
4958int32_t
4959e1000_read_eeprom(struct e1000_hw *hw,
4960 uint16_t offset,
4961 uint16_t words,
4962 uint16_t *data)
4963{
4964 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4965 uint32_t i = 0;
4966
4967 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004968
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004969 /* If eeprom is not yet detected, do so now */
4970 if (eeprom->word_size == 0)
4971 e1000_init_eeprom_params(hw);
4972
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 /* A check for invalid values: offset too large, too many words, and not
4974 * enough words.
4975 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004976 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004978 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 return -E1000_ERR_EEPROM;
4980 }
4981
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004982 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4983 * directly. In this case, we need to acquire the EEPROM so that
4984 * FW or other port software does not interrupt.
4985 */
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004986 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004987 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004988 /* Prepare the EEPROM for bit-bang reading */
4989 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4990 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004991 }
4992
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004993 /* Eerd register EEPROM access requires no eeprom aquire/release */
4994 if (eeprom->use_eerd == TRUE)
4995 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004997 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07004998 if (eeprom->type == e1000_eeprom_ich8)
4999 return e1000_read_eeprom_ich8(hw, offset, words, data);
5000
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005001 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5002 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07005003 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 uint16_t word_in;
5005 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5006
Auke Kok8fc897b2006-08-28 14:56:16 -07005007 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 e1000_release_eeprom(hw);
5009 return -E1000_ERR_EEPROM;
5010 }
5011
5012 e1000_standby_eeprom(hw);
5013
5014 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005015 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016 read_opcode |= EEPROM_A8_OPCODE_SPI;
5017
5018 /* Send the READ command (opcode + addr) */
5019 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5020 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5021
5022 /* Read the data. The address of the eeprom internally increments with
5023 * each byte (spi) being read, saving on the overhead of eeprom setup
5024 * and tear-down. The address counter will roll over if reading beyond
5025 * the size of the eeprom, thus allowing the entire memory to be read
5026 * starting from any offset. */
5027 for (i = 0; i < words; i++) {
5028 word_in = e1000_shift_in_ee_bits(hw, 16);
5029 data[i] = (word_in >> 8) | (word_in << 8);
5030 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005031 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 for (i = 0; i < words; i++) {
5033 /* Send the READ command (opcode + addr) */
5034 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5035 eeprom->opcode_bits);
5036 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5037 eeprom->address_bits);
5038
5039 /* Read the data. For microwire, each word requires the overhead
5040 * of eeprom setup and tear-down. */
5041 data[i] = e1000_shift_in_ee_bits(hw, 16);
5042 e1000_standby_eeprom(hw);
5043 }
5044 }
5045
5046 /* End this read operation */
5047 e1000_release_eeprom(hw);
5048
5049 return E1000_SUCCESS;
5050}
5051
5052/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005053 * Reads a 16 bit word from the EEPROM using the EERD register.
5054 *
5055 * hw - Struct containing variables accessed by shared code
5056 * offset - offset of word in the EEPROM to read
5057 * data - word read from the EEPROM
5058 * words - number of words to read
5059 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005060static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005061e1000_read_eeprom_eerd(struct e1000_hw *hw,
5062 uint16_t offset,
5063 uint16_t words,
5064 uint16_t *data)
5065{
5066 uint32_t i, eerd = 0;
5067 int32_t error = 0;
5068
5069 for (i = 0; i < words; i++) {
5070 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5071 E1000_EEPROM_RW_REG_START;
5072
5073 E1000_WRITE_REG(hw, EERD, eerd);
5074 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005075
Auke Kok8fc897b2006-08-28 14:56:16 -07005076 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005077 break;
5078 }
5079 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005080
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005081 }
Auke Kok76c224b2006-05-23 13:36:06 -07005082
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005083 return error;
5084}
5085
5086/******************************************************************************
5087 * Writes a 16 bit word from the EEPROM using the EEWR register.
5088 *
5089 * hw - Struct containing variables accessed by shared code
5090 * offset - offset of word in the EEPROM to read
5091 * data - word read from the EEPROM
5092 * words - number of words to read
5093 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005094static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005095e1000_write_eeprom_eewr(struct e1000_hw *hw,
5096 uint16_t offset,
5097 uint16_t words,
5098 uint16_t *data)
5099{
5100 uint32_t register_value = 0;
5101 uint32_t i = 0;
5102 int32_t error = 0;
5103
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005104 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5105 return -E1000_ERR_SWFW_SYNC;
5106
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005107 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005108 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5109 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005110 E1000_EEPROM_RW_REG_START;
5111
5112 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005113 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005114 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005115 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005116
5117 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005118
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005119 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005120
Auke Kok8fc897b2006-08-28 14:56:16 -07005121 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005122 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005123 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005124 }
Auke Kok76c224b2006-05-23 13:36:06 -07005125
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005126 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005127 return error;
5128}
5129
5130/******************************************************************************
5131 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5132 *
5133 * hw - Struct containing variables accessed by shared code
5134 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005135static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005136e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5137{
5138 uint32_t attempts = 100000;
5139 uint32_t i, reg = 0;
5140 int32_t done = E1000_ERR_EEPROM;
5141
Auke Kok8fc897b2006-08-28 14:56:16 -07005142 for (i = 0; i < attempts; i++) {
5143 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005144 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005145 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005146 reg = E1000_READ_REG(hw, EEWR);
5147
Auke Kok8fc897b2006-08-28 14:56:16 -07005148 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005149 done = E1000_SUCCESS;
5150 break;
5151 }
5152 udelay(5);
5153 }
5154
5155 return done;
5156}
5157
5158/***************************************************************************
5159* Description: Determines if the onboard NVM is FLASH or EEPROM.
5160*
5161* hw - Struct containing variables accessed by shared code
5162****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005163static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005164e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5165{
5166 uint32_t eecd = 0;
5167
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005168 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5169
Auke Kokcd94dd02006-06-27 09:08:22 -07005170 if (hw->mac_type == e1000_ich8lan)
5171 return FALSE;
5172
5173 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005174 eecd = E1000_READ_REG(hw, EECD);
5175
5176 /* Isolate bits 15 & 16 */
5177 eecd = ((eecd >> 15) & 0x03);
5178
5179 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005180 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005181 return FALSE;
5182 }
5183 }
5184 return TRUE;
5185}
5186
5187/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188 * Verifies that the EEPROM has a valid checksum
5189 *
5190 * hw - Struct containing variables accessed by shared code
5191 *
5192 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5193 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5194 * valid.
5195 *****************************************************************************/
5196int32_t
5197e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5198{
5199 uint16_t checksum = 0;
5200 uint16_t i, eeprom_data;
5201
5202 DEBUGFUNC("e1000_validate_eeprom_checksum");
5203
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005204 if ((hw->mac_type == e1000_82573) &&
5205 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5206 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5207 * 10h-12h. Checksum may need to be fixed. */
5208 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5209 if ((eeprom_data & 0x10) == 0) {
5210 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5211 * has already been fixed. If the checksum is still wrong and this
5212 * bit is a 1, we need to return bad checksum. Otherwise, we need
5213 * to set this bit to a 1 and update the checksum. */
5214 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5215 if ((eeprom_data & 0x8000) == 0) {
5216 eeprom_data |= 0x8000;
5217 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5218 e1000_update_eeprom_checksum(hw);
5219 }
5220 }
5221 }
5222
Auke Kokcd94dd02006-06-27 09:08:22 -07005223 if (hw->mac_type == e1000_ich8lan) {
5224 /* Drivers must allocate the shadow ram structure for the
5225 * EEPROM checksum to be updated. Otherwise, this bit as well
5226 * as the checksum must both be set correctly for this
5227 * validation to pass.
5228 */
5229 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5230 if ((eeprom_data & 0x40) == 0) {
5231 eeprom_data |= 0x40;
5232 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5233 e1000_update_eeprom_checksum(hw);
5234 }
5235 }
5236
5237 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5238 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 DEBUGOUT("EEPROM Read Error\n");
5240 return -E1000_ERR_EEPROM;
5241 }
5242 checksum += eeprom_data;
5243 }
5244
Auke Kok8fc897b2006-08-28 14:56:16 -07005245 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 return E1000_SUCCESS;
5247 else {
5248 DEBUGOUT("EEPROM Checksum Invalid\n");
5249 return -E1000_ERR_EEPROM;
5250 }
5251}
5252
5253/******************************************************************************
5254 * Calculates the EEPROM checksum and writes it to the EEPROM
5255 *
5256 * hw - Struct containing variables accessed by shared code
5257 *
5258 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5259 * Writes the difference to word offset 63 of the EEPROM.
5260 *****************************************************************************/
5261int32_t
5262e1000_update_eeprom_checksum(struct e1000_hw *hw)
5263{
Auke Kokcd94dd02006-06-27 09:08:22 -07005264 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 uint16_t checksum = 0;
5266 uint16_t i, eeprom_data;
5267
5268 DEBUGFUNC("e1000_update_eeprom_checksum");
5269
Auke Kok8fc897b2006-08-28 14:56:16 -07005270 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5271 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 DEBUGOUT("EEPROM Read Error\n");
5273 return -E1000_ERR_EEPROM;
5274 }
5275 checksum += eeprom_data;
5276 }
5277 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005278 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 DEBUGOUT("EEPROM Write Error\n");
5280 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005281 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5282 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005283 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5284 e1000_commit_shadow_ram(hw);
5285 /* Reload the EEPROM, or else modifications will not appear
5286 * until after next adapter reset. */
5287 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5288 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5289 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005290 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 }
5292 return E1000_SUCCESS;
5293}
5294
5295/******************************************************************************
5296 * Parent function for writing words to the different EEPROM types.
5297 *
5298 * hw - Struct containing variables accessed by shared code
5299 * offset - offset within the EEPROM to be written to
5300 * words - number of words to write
5301 * data - 16 bit word to be written to the EEPROM
5302 *
5303 * If e1000_update_eeprom_checksum is not called after this function, the
5304 * EEPROM will most likely contain an invalid checksum.
5305 *****************************************************************************/
5306int32_t
5307e1000_write_eeprom(struct e1000_hw *hw,
5308 uint16_t offset,
5309 uint16_t words,
5310 uint16_t *data)
5311{
5312 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5313 int32_t status = 0;
5314
5315 DEBUGFUNC("e1000_write_eeprom");
5316
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005317 /* If eeprom is not yet detected, do so now */
5318 if (eeprom->word_size == 0)
5319 e1000_init_eeprom_params(hw);
5320
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 /* A check for invalid values: offset too large, too many words, and not
5322 * enough words.
5323 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005324 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 (words == 0)) {
5326 DEBUGOUT("\"words\" parameter out of bounds\n");
5327 return -E1000_ERR_EEPROM;
5328 }
5329
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005330 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005331 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005332 return e1000_write_eeprom_eewr(hw, offset, words, data);
5333
Auke Kokcd94dd02006-06-27 09:08:22 -07005334 if (eeprom->type == e1000_eeprom_ich8)
5335 return e1000_write_eeprom_ich8(hw, offset, words, data);
5336
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337 /* Prepare the EEPROM for writing */
5338 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5339 return -E1000_ERR_EEPROM;
5340
Auke Kok8fc897b2006-08-28 14:56:16 -07005341 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5343 } else {
5344 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005345 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346 }
5347
5348 /* Done with writing */
5349 e1000_release_eeprom(hw);
5350
5351 return status;
5352}
5353
5354/******************************************************************************
5355 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5356 *
5357 * hw - Struct containing variables accessed by shared code
5358 * offset - offset within the EEPROM to be written to
5359 * words - number of words to write
5360 * data - pointer to array of 8 bit words to be written to the EEPROM
5361 *
5362 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005363static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364e1000_write_eeprom_spi(struct e1000_hw *hw,
5365 uint16_t offset,
5366 uint16_t words,
5367 uint16_t *data)
5368{
5369 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5370 uint16_t widx = 0;
5371
5372 DEBUGFUNC("e1000_write_eeprom_spi");
5373
5374 while (widx < words) {
5375 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5376
Auke Kok8fc897b2006-08-28 14:56:16 -07005377 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378
5379 e1000_standby_eeprom(hw);
5380
5381 /* Send the WRITE ENABLE command (8 bit opcode ) */
5382 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5383 eeprom->opcode_bits);
5384
5385 e1000_standby_eeprom(hw);
5386
5387 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005388 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 write_opcode |= EEPROM_A8_OPCODE_SPI;
5390
5391 /* Send the Write command (8-bit opcode + addr) */
5392 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5393
5394 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5395 eeprom->address_bits);
5396
5397 /* Send the data */
5398
5399 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5400 while (widx < words) {
5401 uint16_t word_out = data[widx];
5402 word_out = (word_out >> 8) | (word_out << 8);
5403 e1000_shift_out_ee_bits(hw, word_out, 16);
5404 widx++;
5405
5406 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5407 * operation, while the smaller eeproms are capable of an 8-byte
5408 * PAGE WRITE operation. Break the inner loop to pass new address
5409 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005410 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411 e1000_standby_eeprom(hw);
5412 break;
5413 }
5414 }
5415 }
5416
5417 return E1000_SUCCESS;
5418}
5419
5420/******************************************************************************
5421 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5422 *
5423 * hw - Struct containing variables accessed by shared code
5424 * offset - offset within the EEPROM to be written to
5425 * words - number of words to write
5426 * data - pointer to array of 16 bit words to be written to the EEPROM
5427 *
5428 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005429static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430e1000_write_eeprom_microwire(struct e1000_hw *hw,
5431 uint16_t offset,
5432 uint16_t words,
5433 uint16_t *data)
5434{
5435 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5436 uint32_t eecd;
5437 uint16_t words_written = 0;
5438 uint16_t i = 0;
5439
5440 DEBUGFUNC("e1000_write_eeprom_microwire");
5441
5442 /* Send the write enable command to the EEPROM (3-bit opcode plus
5443 * 6/8-bit dummy address beginning with 11). It's less work to include
5444 * the 11 of the dummy address as part of the opcode than it is to shift
5445 * it over the correct number of bits for the address. This puts the
5446 * EEPROM into write/erase mode.
5447 */
5448 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5449 (uint16_t)(eeprom->opcode_bits + 2));
5450
5451 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5452
5453 /* Prepare the EEPROM */
5454 e1000_standby_eeprom(hw);
5455
5456 while (words_written < words) {
5457 /* Send the Write command (3-bit opcode + addr) */
5458 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5459 eeprom->opcode_bits);
5460
5461 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5462 eeprom->address_bits);
5463
5464 /* Send the data */
5465 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5466
5467 /* Toggle the CS line. This in effect tells the EEPROM to execute
5468 * the previous command.
5469 */
5470 e1000_standby_eeprom(hw);
5471
5472 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5473 * signal that the command has been completed by raising the DO signal.
5474 * If DO does not go high in 10 milliseconds, then error out.
5475 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005476 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005478 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479 udelay(50);
5480 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005481 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482 DEBUGOUT("EEPROM Write did not complete\n");
5483 return -E1000_ERR_EEPROM;
5484 }
5485
5486 /* Recover from write */
5487 e1000_standby_eeprom(hw);
5488
5489 words_written++;
5490 }
5491
5492 /* Send the write disable command to the EEPROM (3-bit opcode plus
5493 * 6/8-bit dummy address beginning with 10). It's less work to include
5494 * the 10 of the dummy address as part of the opcode than it is to shift
5495 * it over the correct number of bits for the address. This takes the
5496 * EEPROM out of write/erase mode.
5497 */
5498 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5499 (uint16_t)(eeprom->opcode_bits + 2));
5500
5501 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5502
5503 return E1000_SUCCESS;
5504}
5505
5506/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005507 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5508 * in the eeprom cache and the non modified values in the currently active bank
5509 * to the new bank.
5510 *
5511 * hw - Struct containing variables accessed by shared code
5512 * offset - offset of word in the EEPROM to read
5513 * data - word read from the EEPROM
5514 * words - number of words to read
5515 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005516static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005517e1000_commit_shadow_ram(struct e1000_hw *hw)
5518{
5519 uint32_t attempts = 100000;
5520 uint32_t eecd = 0;
5521 uint32_t flop = 0;
5522 uint32_t i = 0;
5523 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005524 uint32_t old_bank_offset = 0;
5525 uint32_t new_bank_offset = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005526 uint8_t low_byte = 0;
5527 uint8_t high_byte = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005528 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005529
5530 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005531 /* The flop register will be used to determine if flash type is STM */
5532 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005533 for (i=0; i < attempts; i++) {
5534 eecd = E1000_READ_REG(hw, EECD);
5535 if ((eecd & E1000_EECD_FLUPD) == 0) {
5536 break;
5537 }
5538 udelay(5);
5539 }
5540
5541 if (i == attempts) {
5542 return -E1000_ERR_EEPROM;
5543 }
5544
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005545 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005546 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5547 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5548 }
5549
5550 /* Perform the flash update */
5551 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5552
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005553 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005554 eecd = E1000_READ_REG(hw, EECD);
5555 if ((eecd & E1000_EECD_FLUPD) == 0) {
5556 break;
5557 }
5558 udelay(5);
5559 }
5560
5561 if (i == attempts) {
5562 return -E1000_ERR_EEPROM;
5563 }
5564 }
5565
Auke Kokcd94dd02006-06-27 09:08:22 -07005566 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5567 /* We're writing to the opposite bank so if we're on bank 1,
5568 * write to bank 0 etc. We also need to erase the segment that
5569 * is going to be written */
5570 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5571 new_bank_offset = hw->flash_bank_size * 2;
5572 old_bank_offset = 0;
5573 e1000_erase_ich8_4k_segment(hw, 1);
5574 } else {
5575 old_bank_offset = hw->flash_bank_size * 2;
5576 new_bank_offset = 0;
5577 e1000_erase_ich8_4k_segment(hw, 0);
5578 }
5579
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005580 sector_write_failed = FALSE;
5581 /* Loop for every byte in the shadow RAM,
5582 * which is in units of words. */
5583 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5584 /* Determine whether to write the value stored
5585 * in the other NVM bank or a modified value stored
5586 * in the shadow RAM */
5587 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5588 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5589 udelay(100);
5590 error = e1000_verify_write_ich8_byte(hw,
5591 (i << 1) + new_bank_offset, low_byte);
5592
5593 if (error != E1000_SUCCESS)
5594 sector_write_failed = TRUE;
5595 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005596 high_byte =
5597 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005598 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005599 }
5600 } else {
5601 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5602 &low_byte);
5603 udelay(100);
5604 error = e1000_verify_write_ich8_byte(hw,
5605 (i << 1) + new_bank_offset, low_byte);
5606
5607 if (error != E1000_SUCCESS)
5608 sector_write_failed = TRUE;
5609 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005610 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5611 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005612 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005613 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005614 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005615
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005616 /* If the write of the low byte was successful, go ahread and
5617 * write the high byte while checking to make sure that if it
5618 * is the signature byte, then it is handled properly */
5619 if (sector_write_failed == FALSE) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005620 /* If the word is 0x13, then make sure the signature bits
5621 * (15:14) are 11b until the commit has completed.
5622 * This will allow us to write 10b which indicates the
5623 * signature is valid. We want to do this after the write
5624 * has completed so that we don't mark the segment valid
5625 * while the write is still in progress */
5626 if (i == E1000_ICH8_NVM_SIG_WORD)
5627 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5628
5629 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005630 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005631 if (error != E1000_SUCCESS)
5632 sector_write_failed = TRUE;
5633
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005634 } else {
5635 /* If the write failed then break from the loop and
5636 * return an error */
5637 break;
5638 }
5639 }
5640
5641 /* Don't bother writing the segment valid bits if sector
5642 * programming failed. */
5643 if (sector_write_failed == FALSE) {
5644 /* Finally validate the new segment by setting bit 15:14
5645 * to 10b in word 0x13 , this can be done without an
5646 * erase as well since these bits are 11 to start with
5647 * and we need to change bit 14 to 0b */
5648 e1000_read_ich8_byte(hw,
5649 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5650 &high_byte);
5651 high_byte &= 0xBF;
5652 error = e1000_verify_write_ich8_byte(hw,
5653 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5654 /* And invalidate the previously valid segment by setting
5655 * its signature word (0x13) high_byte to 0b. This can be
5656 * done without an erase because flash erase sets all bits
5657 * to 1's. We can write 1's to 0's without an erase */
5658 if (error == E1000_SUCCESS) {
5659 error = e1000_verify_write_ich8_byte(hw,
5660 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005661 }
5662
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005663 /* Clear the now not used entry in the cache */
5664 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5665 hw->eeprom_shadow_ram[i].modified = FALSE;
5666 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005667 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005668 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005669 }
5670
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005671 return error;
5672}
5673
5674/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005675 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5676 * second function of dual function devices
5677 *
5678 * hw - Struct containing variables accessed by shared code
5679 *****************************************************************************/
5680int32_t
5681e1000_read_mac_addr(struct e1000_hw * hw)
5682{
5683 uint16_t offset;
5684 uint16_t eeprom_data, i;
5685
5686 DEBUGFUNC("e1000_read_mac_addr");
5687
Auke Kok8fc897b2006-08-28 14:56:16 -07005688 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005689 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005690 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691 DEBUGOUT("EEPROM Read Error\n");
5692 return -E1000_ERR_EEPROM;
5693 }
5694 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5695 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5696 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005697
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005698 switch (hw->mac_type) {
5699 default:
5700 break;
5701 case e1000_82546:
5702 case e1000_82546_rev_3:
5703 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005704 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005705 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005707 break;
5708 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709
Auke Kok8fc897b2006-08-28 14:56:16 -07005710 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 hw->mac_addr[i] = hw->perm_mac_addr[i];
5712 return E1000_SUCCESS;
5713}
5714
5715/******************************************************************************
5716 * Initializes receive address filters.
5717 *
5718 * hw - Struct containing variables accessed by shared code
5719 *
5720 * Places the MAC address in receive address register 0 and clears the rest
5721 * of the receive addresss registers. Clears the multicast table. Assumes
5722 * the receiver is in reset when the routine is called.
5723 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005724static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725e1000_init_rx_addrs(struct e1000_hw *hw)
5726{
5727 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005728 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729
5730 DEBUGFUNC("e1000_init_rx_addrs");
5731
5732 /* Setup the receive address. */
5733 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5734
5735 e1000_rar_set(hw, hw->mac_addr, 0);
5736
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005737 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005738
5739 /* Reserve a spot for the Locally Administered Address to work around
5740 * an 82571 issue in which a reset on one port will reload the MAC on
5741 * the other port. */
5742 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5743 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005744 if (hw->mac_type == e1000_ich8lan)
5745 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5746
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 /* Zero out the other 15 receive addresses. */
5748 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005749 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005751 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005753 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754 }
5755}
5756
5757/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 * Hashes an address to determine its location in the multicast table
5759 *
5760 * hw - Struct containing variables accessed by shared code
5761 * mc_addr - the multicast address to hash
5762 *****************************************************************************/
5763uint32_t
5764e1000_hash_mc_addr(struct e1000_hw *hw,
5765 uint8_t *mc_addr)
5766{
5767 uint32_t hash_value = 0;
5768
5769 /* The portion of the address that is used for the hash table is
5770 * determined by the mc_filter_type setting.
5771 */
5772 switch (hw->mc_filter_type) {
5773 /* [0] [1] [2] [3] [4] [5]
5774 * 01 AA 00 12 34 56
5775 * LSB MSB
5776 */
5777 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005778 if (hw->mac_type == e1000_ich8lan) {
5779 /* [47:38] i.e. 0x158 for above example address */
5780 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5781 } else {
5782 /* [47:36] i.e. 0x563 for above example address */
5783 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005785 break;
5786 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005787 if (hw->mac_type == e1000_ich8lan) {
5788 /* [46:37] i.e. 0x2B1 for above example address */
5789 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5790 } else {
5791 /* [46:35] i.e. 0xAC6 for above example address */
5792 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5793 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 break;
5795 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005796 if (hw->mac_type == e1000_ich8lan) {
5797 /*[45:36] i.e. 0x163 for above example address */
5798 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5799 } else {
5800 /* [45:34] i.e. 0x5D8 for above example address */
5801 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803 break;
5804 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005805 if (hw->mac_type == e1000_ich8lan) {
5806 /* [43:34] i.e. 0x18D for above example address */
5807 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5808 } else {
5809 /* [43:32] i.e. 0x634 for above example address */
5810 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812 break;
5813 }
5814
5815 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005816 if (hw->mac_type == e1000_ich8lan)
5817 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005818
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 return hash_value;
5820}
5821
5822/******************************************************************************
5823 * Sets the bit in the multicast table corresponding to the hash value.
5824 *
5825 * hw - Struct containing variables accessed by shared code
5826 * hash_value - Multicast address hash value
5827 *****************************************************************************/
5828void
5829e1000_mta_set(struct e1000_hw *hw,
5830 uint32_t hash_value)
5831{
5832 uint32_t hash_bit, hash_reg;
5833 uint32_t mta;
5834 uint32_t temp;
5835
5836 /* The MTA is a register array of 128 32-bit registers.
5837 * It is treated like an array of 4096 bits. We want to set
5838 * bit BitArray[hash_value]. So we figure out what register
5839 * the bit is in, read it, OR in the new bit, then write
5840 * back the new value. The register is determined by the
5841 * upper 7 bits of the hash value and the bit within that
5842 * register are determined by the lower 5 bits of the value.
5843 */
5844 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005845 if (hw->mac_type == e1000_ich8lan)
5846 hash_reg &= 0x1F;
Auke Kok90fb5132006-11-01 08:47:30 -08005847
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 hash_bit = hash_value & 0x1F;
5849
5850 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5851
5852 mta |= (1 << hash_bit);
5853
5854 /* If we are on an 82544 and we are trying to write an odd offset
5855 * in the MTA, save off the previous entry before writing and
5856 * restore the old value after writing.
5857 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005858 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5860 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005861 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005863 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 } else {
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 }
5868}
5869
5870/******************************************************************************
5871 * Puts an ethernet address into a receive address register.
5872 *
5873 * hw - Struct containing variables accessed by shared code
5874 * addr - Address to put into receive address register
5875 * index - Receive address register to write
5876 *****************************************************************************/
5877void
5878e1000_rar_set(struct e1000_hw *hw,
5879 uint8_t *addr,
5880 uint32_t index)
5881{
5882 uint32_t rar_low, rar_high;
5883
5884 /* HW expects these in little endian so we reverse the byte order
5885 * from network order (big endian) to little endian
5886 */
5887 rar_low = ((uint32_t) addr[0] |
5888 ((uint32_t) addr[1] << 8) |
5889 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005890 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005892 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5893 * unit hang.
5894 *
5895 * Description:
5896 * If there are any Rx frames queued up or otherwise present in the HW
5897 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5898 * hang. To work around this issue, we have to disable receives and
5899 * flush out all Rx frames before we enable RSS. To do so, we modify we
5900 * redirect all Rx traffic to manageability and then reset the HW.
5901 * This flushes away Rx frames, and (since the redirections to
5902 * manageability persists across resets) keeps new ones from coming in
5903 * while we work. Then, we clear the Address Valid AV bit for all MAC
5904 * addresses and undo the re-direction to manageability.
5905 * Now, frames are coming in again, but the MAC won't accept them, so
5906 * far so good. We now proceed to initialize RSS (if necessary) and
5907 * configure the Rx unit. Last, we re-enable the AV bits and continue
5908 * on our merry way.
5909 */
5910 switch (hw->mac_type) {
5911 case e1000_82571:
5912 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005913 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005914 if (hw->leave_av_bit_off == TRUE)
5915 break;
5916 default:
5917 /* Indicate to hardware the Address is Valid. */
5918 rar_high |= E1000_RAH_AV;
5919 break;
5920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921
5922 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005923 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005925 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926}
5927
5928/******************************************************************************
5929 * Writes a value to the specified offset in the VLAN filter table.
5930 *
5931 * hw - Struct containing variables accessed by shared code
5932 * offset - Offset in VLAN filer table to write
5933 * value - Value to write into VLAN filter table
5934 *****************************************************************************/
5935void
5936e1000_write_vfta(struct e1000_hw *hw,
5937 uint32_t offset,
5938 uint32_t value)
5939{
5940 uint32_t temp;
5941
Auke Kokcd94dd02006-06-27 09:08:22 -07005942 if (hw->mac_type == e1000_ich8lan)
5943 return;
5944
5945 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5947 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005948 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005950 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 } else {
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 }
5955}
5956
5957/******************************************************************************
5958 * Clears the VLAN filer table
5959 *
5960 * hw - Struct containing variables accessed by shared code
5961 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005962static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963e1000_clear_vfta(struct e1000_hw *hw)
5964{
5965 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005966 uint32_t vfta_value = 0;
5967 uint32_t vfta_offset = 0;
5968 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969
Auke Kokcd94dd02006-06-27 09:08:22 -07005970 if (hw->mac_type == e1000_ich8lan)
5971 return;
5972
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005973 if (hw->mac_type == e1000_82573) {
5974 if (hw->mng_cookie.vlan_id != 0) {
5975 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5976 * ID. The following operations determine which 32b entry
5977 * (i.e. offset) into the array we want to set the VLAN ID
5978 * (i.e. bit) of the manageability unit. */
5979 vfta_offset = (hw->mng_cookie.vlan_id >>
5980 E1000_VFTA_ENTRY_SHIFT) &
5981 E1000_VFTA_ENTRY_MASK;
5982 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5983 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5984 }
5985 }
5986 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5987 /* If the offset we want to clear is the same offset of the
5988 * manageability VLAN ID, then clear all bits except that of the
5989 * manageability unit */
5990 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5991 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005992 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994}
5995
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005996static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997e1000_id_led_init(struct e1000_hw * hw)
5998{
5999 uint32_t ledctl;
6000 const uint32_t ledctl_mask = 0x000000FF;
6001 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6002 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6003 uint16_t eeprom_data, i, temp;
6004 const uint16_t led_mask = 0x0F;
6005
6006 DEBUGFUNC("e1000_id_led_init");
6007
Auke Kok8fc897b2006-08-28 14:56:16 -07006008 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009 /* Nothing to do */
6010 return E1000_SUCCESS;
6011 }
6012
6013 ledctl = E1000_READ_REG(hw, LEDCTL);
6014 hw->ledctl_default = ledctl;
6015 hw->ledctl_mode1 = hw->ledctl_default;
6016 hw->ledctl_mode2 = hw->ledctl_default;
6017
Auke Kok8fc897b2006-08-28 14:56:16 -07006018 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 DEBUGOUT("EEPROM Read Error\n");
6020 return -E1000_ERR_EEPROM;
6021 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006022
6023 if ((hw->mac_type == e1000_82573) &&
6024 (eeprom_data == ID_LED_RESERVED_82573))
6025 eeprom_data = ID_LED_DEFAULT_82573;
6026 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6027 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6028 if (hw->mac_type == e1000_ich8lan)
6029 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6030 else
6031 eeprom_data = ID_LED_DEFAULT;
6032 }
Auke Kok90fb5132006-11-01 08:47:30 -08006033
Auke Kokcd94dd02006-06-27 09:08:22 -07006034 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006036 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 case ID_LED_ON1_DEF2:
6038 case ID_LED_ON1_ON2:
6039 case ID_LED_ON1_OFF2:
6040 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6041 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6042 break;
6043 case ID_LED_OFF1_DEF2:
6044 case ID_LED_OFF1_ON2:
6045 case ID_LED_OFF1_OFF2:
6046 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6047 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6048 break;
6049 default:
6050 /* Do nothing */
6051 break;
6052 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006053 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 case ID_LED_DEF1_ON2:
6055 case ID_LED_ON1_ON2:
6056 case ID_LED_OFF1_ON2:
6057 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6058 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6059 break;
6060 case ID_LED_DEF1_OFF2:
6061 case ID_LED_ON1_OFF2:
6062 case ID_LED_OFF1_OFF2:
6063 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6064 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6065 break;
6066 default:
6067 /* Do nothing */
6068 break;
6069 }
6070 }
6071 return E1000_SUCCESS;
6072}
6073
6074/******************************************************************************
6075 * Prepares SW controlable LED for use and saves the current state of the LED.
6076 *
6077 * hw - Struct containing variables accessed by shared code
6078 *****************************************************************************/
6079int32_t
6080e1000_setup_led(struct e1000_hw *hw)
6081{
6082 uint32_t ledctl;
6083 int32_t ret_val = E1000_SUCCESS;
6084
6085 DEBUGFUNC("e1000_setup_led");
6086
Auke Kok8fc897b2006-08-28 14:56:16 -07006087 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088 case e1000_82542_rev2_0:
6089 case e1000_82542_rev2_1:
6090 case e1000_82543:
6091 case e1000_82544:
6092 /* No setup necessary */
6093 break;
6094 case e1000_82541:
6095 case e1000_82547:
6096 case e1000_82541_rev_2:
6097 case e1000_82547_rev_2:
6098 /* Turn off PHY Smart Power Down (if enabled) */
6099 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6100 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006101 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 return ret_val;
6103 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6104 (uint16_t)(hw->phy_spd_default &
6105 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006106 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 return ret_val;
6108 /* Fall Through */
6109 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006110 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111 ledctl = E1000_READ_REG(hw, LEDCTL);
6112 /* Save current LEDCTL settings */
6113 hw->ledctl_default = ledctl;
6114 /* Turn off LED0 */
6115 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6116 E1000_LEDCTL_LED0_BLINK |
6117 E1000_LEDCTL_LED0_MODE_MASK);
6118 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6119 E1000_LEDCTL_LED0_MODE_SHIFT);
6120 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006121 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6123 break;
6124 }
6125
6126 return E1000_SUCCESS;
6127}
6128
Auke Kok8fc897b2006-08-28 14:56:16 -07006129
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006131 * Used on 82571 and later Si that has LED blink bits.
6132 * Callers must use their own timer and should have already called
6133 * e1000_id_led_init()
6134 * Call e1000_cleanup led() to stop blinking
6135 *
6136 * hw - Struct containing variables accessed by shared code
6137 *****************************************************************************/
6138int32_t
6139e1000_blink_led_start(struct e1000_hw *hw)
6140{
6141 int16_t i;
6142 uint32_t ledctl_blink = 0;
6143
6144 DEBUGFUNC("e1000_id_led_blink_on");
6145
6146 if (hw->mac_type < e1000_82571) {
6147 /* Nothing to do */
6148 return E1000_SUCCESS;
6149 }
6150 if (hw->media_type == e1000_media_type_fiber) {
6151 /* always blink LED0 for PCI-E fiber */
6152 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6153 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6154 } else {
6155 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6156 ledctl_blink = hw->ledctl_mode2;
6157 for (i=0; i < 4; i++)
6158 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6159 E1000_LEDCTL_MODE_LED_ON)
6160 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6161 }
6162
6163 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6164
6165 return E1000_SUCCESS;
6166}
6167
6168/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169 * Restores the saved state of the SW controlable LED.
6170 *
6171 * hw - Struct containing variables accessed by shared code
6172 *****************************************************************************/
6173int32_t
6174e1000_cleanup_led(struct e1000_hw *hw)
6175{
6176 int32_t ret_val = E1000_SUCCESS;
6177
6178 DEBUGFUNC("e1000_cleanup_led");
6179
Auke Kok8fc897b2006-08-28 14:56:16 -07006180 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 case e1000_82542_rev2_0:
6182 case e1000_82542_rev2_1:
6183 case e1000_82543:
6184 case e1000_82544:
6185 /* No cleanup necessary */
6186 break;
6187 case e1000_82541:
6188 case e1000_82547:
6189 case e1000_82541_rev_2:
6190 case e1000_82547_rev_2:
6191 /* Turn on PHY Smart Power Down (if previously enabled) */
6192 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6193 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006194 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 return ret_val;
6196 /* Fall Through */
6197 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006198 if (hw->phy_type == e1000_phy_ife) {
6199 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6200 break;
6201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 /* Restore LEDCTL settings */
6203 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6204 break;
6205 }
6206
6207 return E1000_SUCCESS;
6208}
6209
6210/******************************************************************************
6211 * Turns on the software controllable LED
6212 *
6213 * hw - Struct containing variables accessed by shared code
6214 *****************************************************************************/
6215int32_t
6216e1000_led_on(struct e1000_hw *hw)
6217{
6218 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6219
6220 DEBUGFUNC("e1000_led_on");
6221
Auke Kok8fc897b2006-08-28 14:56:16 -07006222 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223 case e1000_82542_rev2_0:
6224 case e1000_82542_rev2_1:
6225 case e1000_82543:
6226 /* Set SW Defineable Pin 0 to turn on the LED */
6227 ctrl |= E1000_CTRL_SWDPIN0;
6228 ctrl |= E1000_CTRL_SWDPIO0;
6229 break;
6230 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006231 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 /* Set SW Defineable Pin 0 to turn on the LED */
6233 ctrl |= E1000_CTRL_SWDPIN0;
6234 ctrl |= E1000_CTRL_SWDPIO0;
6235 } else {
6236 /* Clear SW Defineable Pin 0 to turn on the LED */
6237 ctrl &= ~E1000_CTRL_SWDPIN0;
6238 ctrl |= E1000_CTRL_SWDPIO0;
6239 }
6240 break;
6241 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006242 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 /* Clear SW Defineable Pin 0 to turn on the LED */
6244 ctrl &= ~E1000_CTRL_SWDPIN0;
6245 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006246 } else if (hw->phy_type == e1000_phy_ife) {
6247 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6248 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6249 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6251 return E1000_SUCCESS;
6252 }
6253 break;
6254 }
6255
6256 E1000_WRITE_REG(hw, CTRL, ctrl);
6257
6258 return E1000_SUCCESS;
6259}
6260
6261/******************************************************************************
6262 * Turns off the software controllable LED
6263 *
6264 * hw - Struct containing variables accessed by shared code
6265 *****************************************************************************/
6266int32_t
6267e1000_led_off(struct e1000_hw *hw)
6268{
6269 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6270
6271 DEBUGFUNC("e1000_led_off");
6272
Auke Kok8fc897b2006-08-28 14:56:16 -07006273 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274 case e1000_82542_rev2_0:
6275 case e1000_82542_rev2_1:
6276 case e1000_82543:
6277 /* Clear SW Defineable Pin 0 to turn off the LED */
6278 ctrl &= ~E1000_CTRL_SWDPIN0;
6279 ctrl |= E1000_CTRL_SWDPIO0;
6280 break;
6281 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006282 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283 /* Clear SW Defineable Pin 0 to turn off the LED */
6284 ctrl &= ~E1000_CTRL_SWDPIN0;
6285 ctrl |= E1000_CTRL_SWDPIO0;
6286 } else {
6287 /* Set SW Defineable Pin 0 to turn off the LED */
6288 ctrl |= E1000_CTRL_SWDPIN0;
6289 ctrl |= E1000_CTRL_SWDPIO0;
6290 }
6291 break;
6292 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006293 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 /* Set SW Defineable Pin 0 to turn off the LED */
6295 ctrl |= E1000_CTRL_SWDPIN0;
6296 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006297 } else if (hw->phy_type == e1000_phy_ife) {
6298 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6299 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6300 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6302 return E1000_SUCCESS;
6303 }
6304 break;
6305 }
6306
6307 E1000_WRITE_REG(hw, CTRL, ctrl);
6308
6309 return E1000_SUCCESS;
6310}
6311
6312/******************************************************************************
6313 * Clears all hardware statistics counters.
6314 *
6315 * hw - Struct containing variables accessed by shared code
6316 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006317static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318e1000_clear_hw_cntrs(struct e1000_hw *hw)
6319{
6320 volatile uint32_t temp;
6321
6322 temp = E1000_READ_REG(hw, CRCERRS);
6323 temp = E1000_READ_REG(hw, SYMERRS);
6324 temp = E1000_READ_REG(hw, MPC);
6325 temp = E1000_READ_REG(hw, SCC);
6326 temp = E1000_READ_REG(hw, ECOL);
6327 temp = E1000_READ_REG(hw, MCC);
6328 temp = E1000_READ_REG(hw, LATECOL);
6329 temp = E1000_READ_REG(hw, COLC);
6330 temp = E1000_READ_REG(hw, DC);
6331 temp = E1000_READ_REG(hw, SEC);
6332 temp = E1000_READ_REG(hw, RLEC);
6333 temp = E1000_READ_REG(hw, XONRXC);
6334 temp = E1000_READ_REG(hw, XONTXC);
6335 temp = E1000_READ_REG(hw, XOFFRXC);
6336 temp = E1000_READ_REG(hw, XOFFTXC);
6337 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006338
6339 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 temp = E1000_READ_REG(hw, PRC64);
6341 temp = E1000_READ_REG(hw, PRC127);
6342 temp = E1000_READ_REG(hw, PRC255);
6343 temp = E1000_READ_REG(hw, PRC511);
6344 temp = E1000_READ_REG(hw, PRC1023);
6345 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006346 }
6347
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 temp = E1000_READ_REG(hw, GPRC);
6349 temp = E1000_READ_REG(hw, BPRC);
6350 temp = E1000_READ_REG(hw, MPRC);
6351 temp = E1000_READ_REG(hw, GPTC);
6352 temp = E1000_READ_REG(hw, GORCL);
6353 temp = E1000_READ_REG(hw, GORCH);
6354 temp = E1000_READ_REG(hw, GOTCL);
6355 temp = E1000_READ_REG(hw, GOTCH);
6356 temp = E1000_READ_REG(hw, RNBC);
6357 temp = E1000_READ_REG(hw, RUC);
6358 temp = E1000_READ_REG(hw, RFC);
6359 temp = E1000_READ_REG(hw, ROC);
6360 temp = E1000_READ_REG(hw, RJC);
6361 temp = E1000_READ_REG(hw, TORL);
6362 temp = E1000_READ_REG(hw, TORH);
6363 temp = E1000_READ_REG(hw, TOTL);
6364 temp = E1000_READ_REG(hw, TOTH);
6365 temp = E1000_READ_REG(hw, TPR);
6366 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006367
6368 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 temp = E1000_READ_REG(hw, PTC64);
6370 temp = E1000_READ_REG(hw, PTC127);
6371 temp = E1000_READ_REG(hw, PTC255);
6372 temp = E1000_READ_REG(hw, PTC511);
6373 temp = E1000_READ_REG(hw, PTC1023);
6374 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006375 }
6376
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 temp = E1000_READ_REG(hw, MPTC);
6378 temp = E1000_READ_REG(hw, BPTC);
6379
Auke Kok8fc897b2006-08-28 14:56:16 -07006380 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381
6382 temp = E1000_READ_REG(hw, ALGNERRC);
6383 temp = E1000_READ_REG(hw, RXERRC);
6384 temp = E1000_READ_REG(hw, TNCRS);
6385 temp = E1000_READ_REG(hw, CEXTERR);
6386 temp = E1000_READ_REG(hw, TSCTC);
6387 temp = E1000_READ_REG(hw, TSCTFC);
6388
Auke Kok8fc897b2006-08-28 14:56:16 -07006389 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390
6391 temp = E1000_READ_REG(hw, MGTPRC);
6392 temp = E1000_READ_REG(hw, MGTPDC);
6393 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006394
Auke Kok8fc897b2006-08-28 14:56:16 -07006395 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006396
6397 temp = E1000_READ_REG(hw, IAC);
6398 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006399
6400 if (hw->mac_type == e1000_ich8lan) return;
6401
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006402 temp = E1000_READ_REG(hw, ICRXPTC);
6403 temp = E1000_READ_REG(hw, ICRXATC);
6404 temp = E1000_READ_REG(hw, ICTXPTC);
6405 temp = E1000_READ_REG(hw, ICTXATC);
6406 temp = E1000_READ_REG(hw, ICTXQEC);
6407 temp = E1000_READ_REG(hw, ICTXQMTC);
6408 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409}
6410
6411/******************************************************************************
6412 * Resets Adaptive IFS to its default state.
6413 *
6414 * hw - Struct containing variables accessed by shared code
6415 *
6416 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6417 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6418 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6419 * before calling this function.
6420 *****************************************************************************/
6421void
6422e1000_reset_adaptive(struct e1000_hw *hw)
6423{
6424 DEBUGFUNC("e1000_reset_adaptive");
6425
Auke Kok8fc897b2006-08-28 14:56:16 -07006426 if (hw->adaptive_ifs) {
6427 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428 hw->current_ifs_val = 0;
6429 hw->ifs_min_val = IFS_MIN;
6430 hw->ifs_max_val = IFS_MAX;
6431 hw->ifs_step_size = IFS_STEP;
6432 hw->ifs_ratio = IFS_RATIO;
6433 }
6434 hw->in_ifs_mode = FALSE;
6435 E1000_WRITE_REG(hw, AIT, 0);
6436 } else {
6437 DEBUGOUT("Not in Adaptive IFS mode!\n");
6438 }
6439}
6440
6441/******************************************************************************
6442 * Called during the callback/watchdog routine to update IFS value based on
6443 * the ratio of transmits to collisions.
6444 *
6445 * hw - Struct containing variables accessed by shared code
6446 * tx_packets - Number of transmits since last callback
6447 * total_collisions - Number of collisions since last callback
6448 *****************************************************************************/
6449void
6450e1000_update_adaptive(struct e1000_hw *hw)
6451{
6452 DEBUGFUNC("e1000_update_adaptive");
6453
Auke Kok8fc897b2006-08-28 14:56:16 -07006454 if (hw->adaptive_ifs) {
6455 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6456 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006458 if (hw->current_ifs_val < hw->ifs_max_val) {
6459 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 hw->current_ifs_val = hw->ifs_min_val;
6461 else
6462 hw->current_ifs_val += hw->ifs_step_size;
6463 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6464 }
6465 }
6466 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006467 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 hw->current_ifs_val = 0;
6469 hw->in_ifs_mode = FALSE;
6470 E1000_WRITE_REG(hw, AIT, 0);
6471 }
6472 }
6473 } else {
6474 DEBUGOUT("Not in Adaptive IFS mode!\n");
6475 }
6476}
6477
6478/******************************************************************************
6479 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6480 *
6481 * hw - Struct containing variables accessed by shared code
6482 * frame_len - The length of the frame in question
6483 * mac_addr - The Ethernet destination address of the frame in question
6484 *****************************************************************************/
6485void
6486e1000_tbi_adjust_stats(struct e1000_hw *hw,
6487 struct e1000_hw_stats *stats,
6488 uint32_t frame_len,
6489 uint8_t *mac_addr)
6490{
6491 uint64_t carry_bit;
6492
6493 /* First adjust the frame length. */
6494 frame_len--;
6495 /* We need to adjust the statistics counters, since the hardware
6496 * counters overcount this packet as a CRC error and undercount
6497 * the packet as a good packet
6498 */
6499 /* This packet should not be counted as a CRC error. */
6500 stats->crcerrs--;
6501 /* This packet does count as a Good Packet Received. */
6502 stats->gprc++;
6503
6504 /* Adjust the Good Octets received counters */
6505 carry_bit = 0x80000000 & stats->gorcl;
6506 stats->gorcl += frame_len;
6507 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6508 * Received Count) was one before the addition,
6509 * AND it is zero after, then we lost the carry out,
6510 * need to add one to Gorch (Good Octets Received Count High).
6511 * This could be simplified if all environments supported
6512 * 64-bit integers.
6513 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006514 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 stats->gorch++;
6516 /* Is this a broadcast or multicast? Check broadcast first,
6517 * since the test for a multicast frame will test positive on
6518 * a broadcast frame.
6519 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006520 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 /* Broadcast packet */
6522 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006523 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 /* Multicast packet */
6525 stats->mprc++;
6526
Auke Kok8fc897b2006-08-28 14:56:16 -07006527 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528 /* In this case, the hardware has overcounted the number of
6529 * oversize frames.
6530 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006531 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 stats->roc--;
6533 }
6534
6535 /* Adjust the bin counters when the extra byte put the frame in the
6536 * wrong bin. Remember that the frame_len was adjusted above.
6537 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006538 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 stats->prc64++;
6540 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006541 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 stats->prc127++;
6543 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006544 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 stats->prc255++;
6546 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006547 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 stats->prc511++;
6549 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006550 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 stats->prc1023++;
6552 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006553 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 stats->prc1522++;
6555 }
6556}
6557
6558/******************************************************************************
6559 * Gets the current PCI bus type, speed, and width of the hardware
6560 *
6561 * hw - Struct containing variables accessed by shared code
6562 *****************************************************************************/
6563void
6564e1000_get_bus_info(struct e1000_hw *hw)
6565{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006566 int32_t ret_val;
6567 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 uint32_t status;
6569
6570 switch (hw->mac_type) {
6571 case e1000_82542_rev2_0:
6572 case e1000_82542_rev2_1:
6573 hw->bus_type = e1000_bus_type_unknown;
6574 hw->bus_speed = e1000_bus_speed_unknown;
6575 hw->bus_width = e1000_bus_width_unknown;
6576 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006577 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006578 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006579 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006580 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006581 hw->bus_type = e1000_bus_type_pci_express;
6582 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006583 ret_val = e1000_read_pcie_cap_reg(hw,
6584 PCI_EX_LINK_STATUS,
6585 &pci_ex_link_status);
6586 if (ret_val)
6587 hw->bus_width = e1000_bus_width_unknown;
6588 else
6589 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6590 PCI_EX_LINK_WIDTH_SHIFT;
6591 break;
6592 case e1000_ich8lan:
6593 hw->bus_type = e1000_bus_type_pci_express;
6594 hw->bus_speed = e1000_bus_speed_2500;
6595 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006596 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 default:
6598 status = E1000_READ_REG(hw, STATUS);
6599 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6600 e1000_bus_type_pcix : e1000_bus_type_pci;
6601
Auke Kok8fc897b2006-08-28 14:56:16 -07006602 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6604 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006605 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6607 e1000_bus_speed_66 : e1000_bus_speed_33;
6608 } else {
6609 switch (status & E1000_STATUS_PCIX_SPEED) {
6610 case E1000_STATUS_PCIX_SPEED_66:
6611 hw->bus_speed = e1000_bus_speed_66;
6612 break;
6613 case E1000_STATUS_PCIX_SPEED_100:
6614 hw->bus_speed = e1000_bus_speed_100;
6615 break;
6616 case E1000_STATUS_PCIX_SPEED_133:
6617 hw->bus_speed = e1000_bus_speed_133;
6618 break;
6619 default:
6620 hw->bus_speed = e1000_bus_speed_reserved;
6621 break;
6622 }
6623 }
6624 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6625 e1000_bus_width_64 : e1000_bus_width_32;
6626 break;
6627 }
6628}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629
6630/******************************************************************************
6631 * Writes a value to one of the devices registers using port I/O (as opposed to
6632 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6633 *
6634 * hw - Struct containing variables accessed by shared code
6635 * offset - offset to write to
6636 * value - value to write
6637 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006638static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639e1000_write_reg_io(struct e1000_hw *hw,
6640 uint32_t offset,
6641 uint32_t value)
6642{
6643 unsigned long io_addr = hw->io_base;
6644 unsigned long io_data = hw->io_base + 4;
6645
6646 e1000_io_write(hw, io_addr, offset);
6647 e1000_io_write(hw, io_data, value);
6648}
6649
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650/******************************************************************************
6651 * Estimates the cable length.
6652 *
6653 * hw - Struct containing variables accessed by shared code
6654 * min_length - The estimated minimum length
6655 * max_length - The estimated maximum length
6656 *
6657 * returns: - E1000_ERR_XXX
6658 * E1000_SUCCESS
6659 *
6660 * This function always returns a ranged length (minimum & maximum).
6661 * So for M88 phy's, this function interprets the one value returned from the
6662 * register to the minimum and maximum range.
6663 * For IGP phy's, the function calculates the range by the AGC registers.
6664 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006665static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666e1000_get_cable_length(struct e1000_hw *hw,
6667 uint16_t *min_length,
6668 uint16_t *max_length)
6669{
6670 int32_t ret_val;
6671 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 uint16_t i, phy_data;
6673 uint16_t cable_length;
6674
6675 DEBUGFUNC("e1000_get_cable_length");
6676
6677 *min_length = *max_length = 0;
6678
6679 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006680 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006681
Linus Torvalds1da177e2005-04-16 15:20:36 -07006682 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6683 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006684 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 return ret_val;
6686 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6687 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6688
6689 /* Convert the enum value to ranged values */
6690 switch (cable_length) {
6691 case e1000_cable_length_50:
6692 *min_length = 0;
6693 *max_length = e1000_igp_cable_length_50;
6694 break;
6695 case e1000_cable_length_50_80:
6696 *min_length = e1000_igp_cable_length_50;
6697 *max_length = e1000_igp_cable_length_80;
6698 break;
6699 case e1000_cable_length_80_110:
6700 *min_length = e1000_igp_cable_length_80;
6701 *max_length = e1000_igp_cable_length_110;
6702 break;
6703 case e1000_cable_length_110_140:
6704 *min_length = e1000_igp_cable_length_110;
6705 *max_length = e1000_igp_cable_length_140;
6706 break;
6707 case e1000_cable_length_140:
6708 *min_length = e1000_igp_cable_length_140;
6709 *max_length = e1000_igp_cable_length_170;
6710 break;
6711 default:
6712 return -E1000_ERR_PHY;
6713 break;
6714 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006715 } else if (hw->phy_type == e1000_phy_gg82563) {
6716 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6717 &phy_data);
6718 if (ret_val)
6719 return ret_val;
6720 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6721
6722 switch (cable_length) {
6723 case e1000_gg_cable_length_60:
6724 *min_length = 0;
6725 *max_length = e1000_igp_cable_length_60;
6726 break;
6727 case e1000_gg_cable_length_60_115:
6728 *min_length = e1000_igp_cable_length_60;
6729 *max_length = e1000_igp_cable_length_115;
6730 break;
6731 case e1000_gg_cable_length_115_150:
6732 *min_length = e1000_igp_cable_length_115;
6733 *max_length = e1000_igp_cable_length_150;
6734 break;
6735 case e1000_gg_cable_length_150:
6736 *min_length = e1000_igp_cable_length_150;
6737 *max_length = e1000_igp_cable_length_180;
6738 break;
6739 default:
6740 return -E1000_ERR_PHY;
6741 break;
6742 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006743 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006744 uint16_t cur_agc_value;
6745 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6747 {IGP01E1000_PHY_AGC_A,
6748 IGP01E1000_PHY_AGC_B,
6749 IGP01E1000_PHY_AGC_C,
6750 IGP01E1000_PHY_AGC_D};
6751 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006752 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753
6754 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006755 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756 return ret_val;
6757
Auke Kokcd94dd02006-06-27 09:08:22 -07006758 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759
Auke Kokcd94dd02006-06-27 09:08:22 -07006760 /* Value bound check. */
6761 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6762 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 return -E1000_ERR_PHY;
6764
Auke Kokcd94dd02006-06-27 09:08:22 -07006765 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766
6767 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006768 if (min_agc_value > cur_agc_value)
6769 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770 }
6771
6772 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006773 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6774 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775
6776 /* Get the average length of the remaining 3 channels */
6777 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6778 } else {
6779 /* Get the average length of all the 4 channels. */
6780 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6781 }
6782
6783 /* Set the range of the calculated length. */
6784 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6785 IGP01E1000_AGC_RANGE) > 0) ?
6786 (e1000_igp_cable_length_table[agc_value] -
6787 IGP01E1000_AGC_RANGE) : 0;
6788 *max_length = e1000_igp_cable_length_table[agc_value] +
6789 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006790 } else if (hw->phy_type == e1000_phy_igp_2 ||
6791 hw->phy_type == e1000_phy_igp_3) {
6792 uint16_t cur_agc_index, max_agc_index = 0;
6793 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006794 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6795 {IGP02E1000_PHY_AGC_A,
6796 IGP02E1000_PHY_AGC_B,
6797 IGP02E1000_PHY_AGC_C,
6798 IGP02E1000_PHY_AGC_D};
6799 /* Read the AGC registers for all channels */
6800 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6801 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6802 if (ret_val)
6803 return ret_val;
6804
Auke Kok8fc897b2006-08-28 14:56:16 -07006805 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006806 * fine gain values. The result is a number that can be put into
6807 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006808 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6809 IGP02E1000_AGC_LENGTH_MASK;
6810
6811 /* Array index bound check. */
6812 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6813 (cur_agc_index == 0))
6814 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006815
6816 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006817 if (e1000_igp_2_cable_length_table[min_agc_index] >
6818 e1000_igp_2_cable_length_table[cur_agc_index])
6819 min_agc_index = cur_agc_index;
6820 if (e1000_igp_2_cable_length_table[max_agc_index] <
6821 e1000_igp_2_cable_length_table[cur_agc_index])
6822 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006823
Auke Kokcd94dd02006-06-27 09:08:22 -07006824 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006825 }
6826
Auke Kokcd94dd02006-06-27 09:08:22 -07006827 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6828 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006829 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6830
6831 /* Calculate cable length with the error range of +/- 10 meters. */
6832 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6833 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6834 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006835 }
6836
6837 return E1000_SUCCESS;
6838}
6839
6840/******************************************************************************
6841 * Check the cable polarity
6842 *
6843 * hw - Struct containing variables accessed by shared code
6844 * polarity - output parameter : 0 - Polarity is not reversed
6845 * 1 - Polarity is reversed.
6846 *
6847 * returns: - E1000_ERR_XXX
6848 * E1000_SUCCESS
6849 *
6850 * For phy's older then IGP, this function simply reads the polarity bit in the
6851 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6852 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6853 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6854 * IGP01E1000_PHY_PCS_INIT_REG.
6855 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006856static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006858 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859{
6860 int32_t ret_val;
6861 uint16_t phy_data;
6862
6863 DEBUGFUNC("e1000_check_polarity");
6864
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006865 if ((hw->phy_type == e1000_phy_m88) ||
6866 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867 /* return the Polarity bit in the Status register. */
6868 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6869 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006870 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006872 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6873 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6874 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6875
Auke Kokcd94dd02006-06-27 09:08:22 -07006876 } else if (hw->phy_type == e1000_phy_igp ||
6877 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006878 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 /* Read the Status register to check the speed */
6880 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6881 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006882 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006883 return ret_val;
6884
6885 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6886 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006887 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888 IGP01E1000_PSSR_SPEED_1000MBPS) {
6889
6890 /* Read the GIG initialization PCS register (0x00B4) */
6891 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6892 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006893 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894 return ret_val;
6895
6896 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006897 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6898 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 } else {
6900 /* For 10 Mbps, read the polarity bit in the status register. (for
6901 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006902 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6903 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006905 } else if (hw->phy_type == e1000_phy_ife) {
6906 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6907 &phy_data);
6908 if (ret_val)
6909 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006910 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6911 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6912 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913 }
6914 return E1000_SUCCESS;
6915}
6916
6917/******************************************************************************
6918 * Check if Downshift occured
6919 *
6920 * hw - Struct containing variables accessed by shared code
6921 * downshift - output parameter : 0 - No Downshift ocured.
6922 * 1 - Downshift ocured.
6923 *
6924 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006925 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006926 *
6927 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6928 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6929 * Link Health register. In IGP this bit is latched high, so the driver must
6930 * read it immediately after link is established.
6931 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006932static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933e1000_check_downshift(struct e1000_hw *hw)
6934{
6935 int32_t ret_val;
6936 uint16_t phy_data;
6937
6938 DEBUGFUNC("e1000_check_downshift");
6939
Auke Kokcd94dd02006-06-27 09:08:22 -07006940 if (hw->phy_type == e1000_phy_igp ||
6941 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006942 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6944 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006945 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006946 return ret_val;
6947
6948 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006949 } else if ((hw->phy_type == e1000_phy_m88) ||
6950 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006951 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6952 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006953 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 return ret_val;
6955
6956 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6957 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006958 } else if (hw->phy_type == e1000_phy_ife) {
6959 /* e1000_phy_ife supports 10/100 speed only */
6960 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006962
Linus Torvalds1da177e2005-04-16 15:20:36 -07006963 return E1000_SUCCESS;
6964}
6965
6966/*****************************************************************************
6967 *
6968 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6969 * gigabit link is achieved to improve link quality.
6970 *
6971 * hw: Struct containing variables accessed by shared code
6972 *
6973 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6974 * E1000_SUCCESS at any other case.
6975 *
6976 ****************************************************************************/
6977
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006978static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006979e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6980 boolean_t link_up)
6981{
6982 int32_t ret_val;
6983 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6984 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6985 {IGP01E1000_PHY_AGC_PARAM_A,
6986 IGP01E1000_PHY_AGC_PARAM_B,
6987 IGP01E1000_PHY_AGC_PARAM_C,
6988 IGP01E1000_PHY_AGC_PARAM_D};
6989 uint16_t min_length, max_length;
6990
6991 DEBUGFUNC("e1000_config_dsp_after_link_change");
6992
Auke Kok8fc897b2006-08-28 14:56:16 -07006993 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006994 return E1000_SUCCESS;
6995
Auke Kok8fc897b2006-08-28 14:56:16 -07006996 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07006998 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999 DEBUGOUT("Error getting link speed and duplex\n");
7000 return ret_val;
7001 }
7002
Auke Kok8fc897b2006-08-28 14:56:16 -07007003 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007004
Auke Kokcd94dd02006-06-27 09:08:22 -07007005 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7006 if (ret_val)
7007 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008
Auke Kok8fc897b2006-08-28 14:56:16 -07007009 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010 min_length >= e1000_igp_cable_length_50) {
7011
Auke Kok8fc897b2006-08-28 14:56:16 -07007012 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7014 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007015 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016 return ret_val;
7017
7018 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7019
7020 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7021 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007022 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023 return ret_val;
7024 }
7025 hw->dsp_config_state = e1000_dsp_config_activated;
7026 }
7027
Auke Kok8fc897b2006-08-28 14:56:16 -07007028 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007029 (min_length < e1000_igp_cable_length_50)) {
7030
7031 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7032 uint32_t idle_errs = 0;
7033
7034 /* clear previous idle error counts */
7035 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7036 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007037 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038 return ret_val;
7039
Auke Kok8fc897b2006-08-28 14:56:16 -07007040 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041 udelay(1000);
7042 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7043 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007044 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045 return ret_val;
7046
7047 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007048 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049 hw->ffe_config_state = e1000_ffe_config_active;
7050
7051 ret_val = e1000_write_phy_reg(hw,
7052 IGP01E1000_PHY_DSP_FFE,
7053 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007054 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007055 return ret_val;
7056 break;
7057 }
7058
Auke Kok8fc897b2006-08-28 14:56:16 -07007059 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007060 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7061 }
7062 }
7063 }
7064 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007065 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007066 /* Save off the current value of register 0x2F5B to be restored at
7067 * the end of the routines. */
7068 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7069
Auke Kok8fc897b2006-08-28 14:56:16 -07007070 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071 return ret_val;
7072
7073 /* Disable the PHY transmitter */
7074 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7075
Auke Kok8fc897b2006-08-28 14:56:16 -07007076 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077 return ret_val;
7078
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007079 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080
7081 ret_val = e1000_write_phy_reg(hw, 0x0000,
7082 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007083 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007085 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007087 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007088 return ret_val;
7089
7090 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7091 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7092
7093 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007094 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095 return ret_val;
7096 }
7097
7098 ret_val = e1000_write_phy_reg(hw, 0x0000,
7099 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007100 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007101 return ret_val;
7102
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007103 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007104
7105 /* Now enable the transmitter */
7106 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7107
Auke Kok8fc897b2006-08-28 14:56:16 -07007108 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007109 return ret_val;
7110
7111 hw->dsp_config_state = e1000_dsp_config_enabled;
7112 }
7113
Auke Kok8fc897b2006-08-28 14:56:16 -07007114 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007115 /* Save off the current value of register 0x2F5B to be restored at
7116 * the end of the routines. */
7117 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7118
Auke Kok8fc897b2006-08-28 14:56:16 -07007119 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007120 return ret_val;
7121
7122 /* Disable the PHY transmitter */
7123 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7124
Auke Kok8fc897b2006-08-28 14:56:16 -07007125 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007126 return ret_val;
7127
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007128 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007129
7130 ret_val = e1000_write_phy_reg(hw, 0x0000,
7131 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007132 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007133 return ret_val;
7134 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7135 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007136 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007137 return ret_val;
7138
7139 ret_val = e1000_write_phy_reg(hw, 0x0000,
7140 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007141 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007142 return ret_val;
7143
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007144 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007145
7146 /* Now enable the transmitter */
7147 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7148
Auke Kok8fc897b2006-08-28 14:56:16 -07007149 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007150 return ret_val;
7151
7152 hw->ffe_config_state = e1000_ffe_config_enabled;
7153 }
7154 }
7155 return E1000_SUCCESS;
7156}
7157
7158/*****************************************************************************
7159 * Set PHY to class A mode
7160 * Assumes the following operations will follow to enable the new class mode.
7161 * 1. Do a PHY soft reset
7162 * 2. Restart auto-negotiation or force link.
7163 *
7164 * hw - Struct containing variables accessed by shared code
7165 ****************************************************************************/
7166static int32_t
7167e1000_set_phy_mode(struct e1000_hw *hw)
7168{
7169 int32_t ret_val;
7170 uint16_t eeprom_data;
7171
7172 DEBUGFUNC("e1000_set_phy_mode");
7173
Auke Kok8fc897b2006-08-28 14:56:16 -07007174 if ((hw->mac_type == e1000_82545_rev_3) &&
7175 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007176 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007177 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007178 return ret_val;
7179 }
7180
Auke Kok8fc897b2006-08-28 14:56:16 -07007181 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7182 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007184 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007185 return ret_val;
7186 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007187 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 return ret_val;
7189
7190 hw->phy_reset_disable = FALSE;
7191 }
7192 }
7193
7194 return E1000_SUCCESS;
7195}
7196
7197/*****************************************************************************
7198 *
7199 * This function sets the lplu state according to the active flag. When
7200 * activating lplu this function also disables smart speed and vise versa.
7201 * lplu will not be activated unless the device autonegotiation advertisment
7202 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7203 * hw: Struct containing variables accessed by shared code
7204 * active - true to enable lplu false to disable lplu.
7205 *
7206 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7207 * E1000_SUCCESS at any other case.
7208 *
7209 ****************************************************************************/
7210
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007211static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007212e1000_set_d3_lplu_state(struct e1000_hw *hw,
7213 boolean_t active)
7214{
Auke Kokcd94dd02006-06-27 09:08:22 -07007215 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007216 int32_t ret_val;
7217 uint16_t phy_data;
7218 DEBUGFUNC("e1000_set_d3_lplu_state");
7219
Auke Kokcd94dd02006-06-27 09:08:22 -07007220 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7221 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007222 return E1000_SUCCESS;
7223
7224 /* During driver activity LPLU should not be used or it will attain link
7225 * from the lowest speeds starting from 10Mbps. The capability is used for
7226 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007227 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007228 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007229 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007230 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007231 } else if (hw->mac_type == e1000_ich8lan) {
7232 /* MAC writes into PHY register based on the state transition
7233 * and start auto-negotiation. SW driver can overwrite the settings
7234 * in CSR PHY power control E1000_PHY_CTRL register. */
7235 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007236 } else {
7237 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007238 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007239 return ret_val;
7240 }
7241
Auke Kok8fc897b2006-08-28 14:56:16 -07007242 if (!active) {
7243 if (hw->mac_type == e1000_82541_rev_2 ||
7244 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007245 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7246 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007247 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007248 return ret_val;
7249 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007250 if (hw->mac_type == e1000_ich8lan) {
7251 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7252 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7253 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007254 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7255 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7256 phy_data);
7257 if (ret_val)
7258 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007259 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007261
7262 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7263 * Dx states where the power conservation is most important. During
7264 * driver activity we should enable SmartSpeed, so performance is
7265 * maintained. */
7266 if (hw->smart_speed == e1000_smart_speed_on) {
7267 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7268 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007269 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007270 return ret_val;
7271
7272 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7273 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7274 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007275 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007276 return ret_val;
7277 } else if (hw->smart_speed == e1000_smart_speed_off) {
7278 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7279 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007280 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007281 return ret_val;
7282
7283 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7284 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7285 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007286 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007287 return ret_val;
7288 }
7289
Auke Kok8fc897b2006-08-28 14:56:16 -07007290 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7291 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7292 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007293
Auke Kok8fc897b2006-08-28 14:56:16 -07007294 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007295 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007296 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7297 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007298 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007299 return ret_val;
7300 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007301 if (hw->mac_type == e1000_ich8lan) {
7302 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7303 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7304 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007305 phy_data |= IGP02E1000_PM_D3_LPLU;
7306 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7307 phy_data);
7308 if (ret_val)
7309 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007310 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007311 }
7312
7313 /* When LPLU is enabled we should disable SmartSpeed */
7314 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007315 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007316 return ret_val;
7317
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007318 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7319 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007320 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007321 return ret_val;
7322
7323 }
7324 return E1000_SUCCESS;
7325}
7326
7327/*****************************************************************************
7328 *
7329 * This function sets the lplu d0 state according to the active flag. When
7330 * activating lplu this function also disables smart speed and vise versa.
7331 * lplu will not be activated unless the device autonegotiation advertisment
7332 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7333 * hw: Struct containing variables accessed by shared code
7334 * active - true to enable lplu false to disable lplu.
7335 *
7336 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7337 * E1000_SUCCESS at any other case.
7338 *
7339 ****************************************************************************/
7340
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007341static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007342e1000_set_d0_lplu_state(struct e1000_hw *hw,
7343 boolean_t active)
7344{
Auke Kokcd94dd02006-06-27 09:08:22 -07007345 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007346 int32_t ret_val;
7347 uint16_t phy_data;
7348 DEBUGFUNC("e1000_set_d0_lplu_state");
7349
Auke Kok8fc897b2006-08-28 14:56:16 -07007350 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007351 return E1000_SUCCESS;
7352
Auke Kokcd94dd02006-06-27 09:08:22 -07007353 if (hw->mac_type == e1000_ich8lan) {
7354 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7355 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007356 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007357 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007358 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007359 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007360
7361 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007362 if (hw->mac_type == e1000_ich8lan) {
7363 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7364 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7365 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007366 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7367 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7368 if (ret_val)
7369 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007370 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007371
7372 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7373 * Dx states where the power conservation is most important. During
7374 * driver activity we should enable SmartSpeed, so performance is
7375 * maintained. */
7376 if (hw->smart_speed == e1000_smart_speed_on) {
7377 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7378 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007379 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007380 return ret_val;
7381
7382 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7383 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7384 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007385 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007386 return ret_val;
7387 } else if (hw->smart_speed == e1000_smart_speed_off) {
7388 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7389 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007390 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007391 return ret_val;
7392
7393 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7394 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7395 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007396 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007397 return ret_val;
7398 }
7399
7400
7401 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007402
Auke Kokcd94dd02006-06-27 09:08:22 -07007403 if (hw->mac_type == e1000_ich8lan) {
7404 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7405 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7406 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007407 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007408 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7409 if (ret_val)
7410 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007411 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007412
Linus Torvalds1da177e2005-04-16 15:20:36 -07007413 /* When LPLU is enabled we should disable SmartSpeed */
7414 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007415 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007416 return ret_val;
7417
7418 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7419 ret_val = e1000_write_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 }
7424 return E1000_SUCCESS;
7425}
7426
7427/******************************************************************************
7428 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7429 *
7430 * hw - Struct containing variables accessed by shared code
7431 *****************************************************************************/
7432static int32_t
7433e1000_set_vco_speed(struct e1000_hw *hw)
7434{
7435 int32_t ret_val;
7436 uint16_t default_page = 0;
7437 uint16_t phy_data;
7438
7439 DEBUGFUNC("e1000_set_vco_speed");
7440
Auke Kok8fc897b2006-08-28 14:56:16 -07007441 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007442 case e1000_82545_rev_3:
7443 case e1000_82546_rev_3:
7444 break;
7445 default:
7446 return E1000_SUCCESS;
7447 }
7448
7449 /* Set PHY register 30, page 5, bit 8 to 0 */
7450
7451 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007452 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007453 return ret_val;
7454
7455 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007456 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457 return ret_val;
7458
7459 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007460 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007461 return ret_val;
7462
7463 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7464 ret_val = e1000_write_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 /* Set PHY register 30, page 4, bit 11 to 1 */
7469
7470 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007471 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007472 return ret_val;
7473
7474 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007475 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007476 return ret_val;
7477
7478 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7479 ret_val = e1000_write_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 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007484 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007485 return ret_val;
7486
7487 return E1000_SUCCESS;
7488}
7489
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007490
7491/*****************************************************************************
7492 * This function reads the cookie from ARC ram.
7493 *
7494 * returns: - E1000_SUCCESS .
7495 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007496static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007497e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7498{
7499 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007500 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007501 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7502
7503 length = (length >> 2);
7504 offset = (offset >> 2);
7505
7506 for (i = 0; i < length; i++) {
7507 *((uint32_t *) buffer + i) =
7508 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7509 }
7510 return E1000_SUCCESS;
7511}
7512
7513
7514/*****************************************************************************
7515 * This function checks whether the HOST IF is enabled for command operaton
7516 * and also checks whether the previous command is completed.
7517 * It busy waits in case of previous command is not completed.
7518 *
Auke Kok76c224b2006-05-23 13:36:06 -07007519 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007520 * timeout
7521 * - E1000_SUCCESS for success.
7522 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007523static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007524e1000_mng_enable_host_if(struct e1000_hw * hw)
7525{
7526 uint32_t hicr;
7527 uint8_t i;
7528
7529 /* Check that the host interface is enabled. */
7530 hicr = E1000_READ_REG(hw, HICR);
7531 if ((hicr & E1000_HICR_EN) == 0) {
7532 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7533 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7534 }
7535 /* check the previous command is completed */
7536 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7537 hicr = E1000_READ_REG(hw, HICR);
7538 if (!(hicr & E1000_HICR_C))
7539 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007540 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007541 }
7542
Auke Kok76c224b2006-05-23 13:36:06 -07007543 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007544 DEBUGOUT("Previous command timeout failed .\n");
7545 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7546 }
7547 return E1000_SUCCESS;
7548}
7549
7550/*****************************************************************************
7551 * This function writes the buffer content at the offset given on the host if.
7552 * It also does alignment considerations to do the writes in most efficient way.
7553 * Also fills up the sum of the buffer in *buffer parameter.
7554 *
7555 * returns - E1000_SUCCESS for success.
7556 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007557static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007558e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7559 uint16_t length, uint16_t offset, uint8_t *sum)
7560{
7561 uint8_t *tmp;
7562 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007563 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007564 uint16_t remaining, i, j, prev_bytes;
7565
7566 /* sum = only sum of the data and it is not checksum */
7567
7568 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7569 return -E1000_ERR_PARAM;
7570 }
7571
7572 tmp = (uint8_t *)&data;
7573 prev_bytes = offset & 0x3;
7574 offset &= 0xFFFC;
7575 offset >>= 2;
7576
7577 if (prev_bytes) {
7578 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7579 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7580 *(tmp + j) = *bufptr++;
7581 *sum += *(tmp + j);
7582 }
7583 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7584 length -= j - prev_bytes;
7585 offset++;
7586 }
7587
7588 remaining = length & 0x3;
7589 length -= remaining;
7590
7591 /* Calculate length in DWORDs */
7592 length >>= 2;
7593
7594 /* The device driver writes the relevant command block into the
7595 * ram area. */
7596 for (i = 0; i < length; i++) {
7597 for (j = 0; j < sizeof(uint32_t); j++) {
7598 *(tmp + j) = *bufptr++;
7599 *sum += *(tmp + j);
7600 }
7601
7602 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7603 }
7604 if (remaining) {
7605 for (j = 0; j < sizeof(uint32_t); j++) {
7606 if (j < remaining)
7607 *(tmp + j) = *bufptr++;
7608 else
7609 *(tmp + j) = 0;
7610
7611 *sum += *(tmp + j);
7612 }
7613 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7614 }
7615
7616 return E1000_SUCCESS;
7617}
7618
7619
7620/*****************************************************************************
7621 * This function writes the command header after does the checksum calculation.
7622 *
7623 * returns - E1000_SUCCESS for success.
7624 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007625static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007626e1000_mng_write_cmd_header(struct e1000_hw * hw,
7627 struct e1000_host_mng_command_header * hdr)
7628{
7629 uint16_t i;
7630 uint8_t sum;
7631 uint8_t *buffer;
7632
7633 /* Write the whole command header structure which includes sum of
7634 * the buffer */
7635
7636 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7637
7638 sum = hdr->checksum;
7639 hdr->checksum = 0;
7640
7641 buffer = (uint8_t *) hdr;
7642 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007643 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007644 sum += buffer[i];
7645
7646 hdr->checksum = 0 - sum;
7647
7648 length >>= 2;
7649 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007650 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007651 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007652 E1000_WRITE_FLUSH(hw);
7653 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007654
7655 return E1000_SUCCESS;
7656}
7657
7658
7659/*****************************************************************************
7660 * This function indicates to ARC that a new command is pending which completes
7661 * one write operation by the driver.
7662 *
7663 * returns - E1000_SUCCESS for success.
7664 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007665static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007666e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007667{
7668 uint32_t hicr;
7669
7670 hicr = E1000_READ_REG(hw, HICR);
7671 /* Setting this bit tells the ARC that a new command is pending. */
7672 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7673
7674 return E1000_SUCCESS;
7675}
7676
7677
7678/*****************************************************************************
7679 * This function checks the mode of the firmware.
7680 *
7681 * returns - TRUE when the mode is IAMT or FALSE.
7682 ****************************************************************************/
7683boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007684e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007685{
7686 uint32_t fwsm;
7687
7688 fwsm = E1000_READ_REG(hw, FWSM);
7689
Auke Kokcd94dd02006-06-27 09:08:22 -07007690 if (hw->mac_type == e1000_ich8lan) {
7691 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7692 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7693 return TRUE;
7694 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7695 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007696 return TRUE;
7697
7698 return FALSE;
7699}
7700
7701
7702/*****************************************************************************
7703 * This function writes the dhcp info .
7704 ****************************************************************************/
7705int32_t
7706e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007707 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007708{
7709 int32_t ret_val;
7710 struct e1000_host_mng_command_header hdr;
7711
7712 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7713 hdr.command_length = length;
7714 hdr.reserved1 = 0;
7715 hdr.reserved2 = 0;
7716 hdr.checksum = 0;
7717
7718 ret_val = e1000_mng_enable_host_if(hw);
7719 if (ret_val == E1000_SUCCESS) {
7720 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7721 &(hdr.checksum));
7722 if (ret_val == E1000_SUCCESS) {
7723 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7724 if (ret_val == E1000_SUCCESS)
7725 ret_val = e1000_mng_write_commit(hw);
7726 }
7727 }
7728 return ret_val;
7729}
7730
7731
7732/*****************************************************************************
7733 * This function calculates the checksum.
7734 *
7735 * returns - checksum of buffer contents.
7736 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007737static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007738e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7739{
7740 uint8_t sum = 0;
7741 uint32_t i;
7742
7743 if (!buffer)
7744 return 0;
7745
7746 for (i=0; i < length; i++)
7747 sum += buffer[i];
7748
7749 return (uint8_t) (0 - sum);
7750}
7751
7752/*****************************************************************************
7753 * This function checks whether tx pkt filtering needs to be enabled or not.
7754 *
7755 * returns - TRUE for packet filtering or FALSE.
7756 ****************************************************************************/
7757boolean_t
7758e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7759{
7760 /* called in init as well as watchdog timer functions */
7761
7762 int32_t ret_val, checksum;
7763 boolean_t tx_filter = FALSE;
7764 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7765 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7766
7767 if (e1000_check_mng_mode(hw)) {
7768 ret_val = e1000_mng_enable_host_if(hw);
7769 if (ret_val == E1000_SUCCESS) {
7770 ret_val = e1000_host_if_read_cookie(hw, buffer);
7771 if (ret_val == E1000_SUCCESS) {
7772 checksum = hdr->checksum;
7773 hdr->checksum = 0;
7774 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7775 checksum == e1000_calculate_mng_checksum((char *)buffer,
7776 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7777 if (hdr->status &
7778 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7779 tx_filter = TRUE;
7780 } else
7781 tx_filter = TRUE;
7782 } else
7783 tx_filter = TRUE;
7784 }
7785 }
7786
7787 hw->tx_pkt_filtering = tx_filter;
7788 return tx_filter;
7789}
7790
7791/******************************************************************************
7792 * Verifies the hardware needs to allow ARPs to be processed by the host
7793 *
7794 * hw - Struct containing variables accessed by shared code
7795 *
7796 * returns: - TRUE/FALSE
7797 *
7798 *****************************************************************************/
7799uint32_t
7800e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7801{
7802 uint32_t manc;
7803 uint32_t fwsm, factps;
7804
7805 if (hw->asf_firmware_present) {
7806 manc = E1000_READ_REG(hw, MANC);
7807
7808 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7809 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7810 return FALSE;
7811 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7812 fwsm = E1000_READ_REG(hw, FWSM);
7813 factps = E1000_READ_REG(hw, FACTPS);
7814
7815 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7816 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7817 (factps & E1000_FACTPS_MNGCG))
7818 return TRUE;
7819 } else
7820 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7821 return TRUE;
7822 }
7823 return FALSE;
7824}
7825
Linus Torvalds1da177e2005-04-16 15:20:36 -07007826static int32_t
7827e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7828{
7829 int32_t ret_val;
7830 uint16_t mii_status_reg;
7831 uint16_t i;
7832
7833 /* Polarity reversal workaround for forced 10F/10H links. */
7834
7835 /* Disable the transmitter on the PHY */
7836
7837 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007838 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007839 return ret_val;
7840 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007841 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007842 return ret_val;
7843
7844 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007845 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007846 return ret_val;
7847
7848 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007849 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007850 /* Read the MII Status Register and wait for Link Status bit
7851 * to be clear.
7852 */
7853
7854 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007855 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007856 return ret_val;
7857
7858 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007859 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007860 return ret_val;
7861
Auke Kok8fc897b2006-08-28 14:56:16 -07007862 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007863 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007864 }
7865
7866 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007867 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007868
7869 /* Now we will re-enable th transmitter on the PHY */
7870
7871 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007872 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007873 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007874 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007875 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007876 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007877 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007878 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007879 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007880 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007881 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007882 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007883 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007884 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007885 return ret_val;
7886
7887 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007888 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007889 return ret_val;
7890
7891 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007892 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007893 /* Read the MII Status Register and wait for Link Status bit
7894 * to be set.
7895 */
7896
7897 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007898 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007899 return ret_val;
7900
7901 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007902 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007903 return ret_val;
7904
Auke Kok8fc897b2006-08-28 14:56:16 -07007905 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007906 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007907 }
7908 return E1000_SUCCESS;
7909}
7910
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007911/***************************************************************************
7912 *
7913 * Disables PCI-Express master access.
7914 *
7915 * hw: Struct containing variables accessed by shared code
7916 *
7917 * returns: - none.
7918 *
7919 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007920static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007921e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7922{
7923 uint32_t ctrl;
7924
7925 DEBUGFUNC("e1000_set_pci_express_master_disable");
7926
7927 if (hw->bus_type != e1000_bus_type_pci_express)
7928 return;
7929
7930 ctrl = E1000_READ_REG(hw, CTRL);
7931 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7932 E1000_WRITE_REG(hw, CTRL, ctrl);
7933}
7934
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007935/*******************************************************************************
7936 *
7937 * Disables PCI-Express master access and verifies there are no pending requests
7938 *
7939 * hw: Struct containing variables accessed by shared code
7940 *
7941 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7942 * caused the master requests to be disabled.
7943 * E1000_SUCCESS master requests disabled.
7944 *
7945 ******************************************************************************/
7946int32_t
7947e1000_disable_pciex_master(struct e1000_hw *hw)
7948{
7949 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7950
7951 DEBUGFUNC("e1000_disable_pciex_master");
7952
7953 if (hw->bus_type != e1000_bus_type_pci_express)
7954 return E1000_SUCCESS;
7955
7956 e1000_set_pci_express_master_disable(hw);
7957
Auke Kok8fc897b2006-08-28 14:56:16 -07007958 while (timeout) {
7959 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007960 break;
7961 else
7962 udelay(100);
7963 timeout--;
7964 }
7965
Auke Kok8fc897b2006-08-28 14:56:16 -07007966 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007967 DEBUGOUT("Master requests are pending.\n");
7968 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7969 }
7970
7971 return E1000_SUCCESS;
7972}
7973
7974/*******************************************************************************
7975 *
7976 * Check for EEPROM Auto Read bit done.
7977 *
7978 * hw: Struct containing variables accessed by shared code
7979 *
7980 * returns: - E1000_ERR_RESET if fail to reset MAC
7981 * E1000_SUCCESS at any other case.
7982 *
7983 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007984static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007985e1000_get_auto_rd_done(struct e1000_hw *hw)
7986{
7987 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7988
7989 DEBUGFUNC("e1000_get_auto_rd_done");
7990
7991 switch (hw->mac_type) {
7992 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007993 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007994 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007995 case e1000_82571:
7996 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007997 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007998 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07007999 case e1000_ich8lan:
8000 while (timeout) {
8001 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8002 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008003 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008004 timeout--;
8005 }
8006
Auke Kok8fc897b2006-08-28 14:56:16 -07008007 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008008 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8009 return -E1000_ERR_RESET;
8010 }
8011 break;
8012 }
8013
Jeff Kirsherfd803242005-12-13 00:06:22 -05008014 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8015 * Need to wait for PHY configuration completion before accessing NVM
8016 * and PHY. */
8017 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008018 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008019
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008020 return E1000_SUCCESS;
8021}
8022
8023/***************************************************************************
8024 * Checks if the PHY configuration is done
8025 *
8026 * hw: Struct containing variables accessed by shared code
8027 *
8028 * returns: - E1000_ERR_RESET if fail to reset MAC
8029 * E1000_SUCCESS at any other case.
8030 *
8031 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008032static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008033e1000_get_phy_cfg_done(struct e1000_hw *hw)
8034{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008035 int32_t timeout = PHY_CFG_TIMEOUT;
8036 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8037
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008038 DEBUGFUNC("e1000_get_phy_cfg_done");
8039
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008040 switch (hw->mac_type) {
8041 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008042 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008043 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008044 case e1000_80003es2lan:
8045 /* Separate *_CFG_DONE_* bit for each port */
8046 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8047 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8048 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008049 case e1000_82571:
8050 case e1000_82572:
8051 while (timeout) {
8052 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8053 break;
8054 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008055 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008056 timeout--;
8057 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008058 if (!timeout) {
8059 DEBUGOUT("MNG configuration cycle has not completed.\n");
8060 return -E1000_ERR_RESET;
8061 }
8062 break;
8063 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008064
8065 return E1000_SUCCESS;
8066}
8067
8068/***************************************************************************
8069 *
8070 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8071 * adapter or Eeprom access.
8072 *
8073 * hw: Struct containing variables accessed by shared code
8074 *
8075 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8076 * E1000_SUCCESS at any other case.
8077 *
8078 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008079static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008080e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8081{
8082 int32_t timeout;
8083 uint32_t swsm;
8084
8085 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8086
Auke Kok8fc897b2006-08-28 14:56:16 -07008087 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008088 return E1000_SUCCESS;
8089
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008090 if (hw->mac_type == e1000_80003es2lan) {
8091 /* Get the SW semaphore. */
8092 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8093 return -E1000_ERR_EEPROM;
8094 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008095
8096 /* Get the FW semaphore. */
8097 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008098 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008099 swsm = E1000_READ_REG(hw, SWSM);
8100 swsm |= E1000_SWSM_SWESMBI;
8101 E1000_WRITE_REG(hw, SWSM, swsm);
8102 /* if we managed to set the bit we got the semaphore. */
8103 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008104 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008105 break;
8106
8107 udelay(50);
8108 timeout--;
8109 }
8110
Auke Kok8fc897b2006-08-28 14:56:16 -07008111 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008112 /* Release semaphores */
8113 e1000_put_hw_eeprom_semaphore(hw);
8114 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8115 return -E1000_ERR_EEPROM;
8116 }
8117
8118 return E1000_SUCCESS;
8119}
8120
8121/***************************************************************************
8122 * This function clears HW semaphore bits.
8123 *
8124 * hw: Struct containing variables accessed by shared code
8125 *
8126 * returns: - None.
8127 *
8128 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008129static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008130e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8131{
8132 uint32_t swsm;
8133
8134 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8135
Auke Kok8fc897b2006-08-28 14:56:16 -07008136 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008137 return;
8138
8139 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008140 if (hw->mac_type == e1000_80003es2lan) {
8141 /* Release both semaphores. */
8142 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8143 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008144 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008145 E1000_WRITE_REG(hw, SWSM, swsm);
8146}
8147
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008148/***************************************************************************
8149 *
8150 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8151 *
8152 * hw: Struct containing variables accessed by shared code
8153 *
8154 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8155 * E1000_SUCCESS at any other case.
8156 *
8157 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008158static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008159e1000_get_software_semaphore(struct e1000_hw *hw)
8160{
8161 int32_t timeout = hw->eeprom.word_size + 1;
8162 uint32_t swsm;
8163
8164 DEBUGFUNC("e1000_get_software_semaphore");
8165
Nicholas Nunley35574762006-09-27 12:53:34 -07008166 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008167 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008168 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008169
Auke Kok8fc897b2006-08-28 14:56:16 -07008170 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008171 swsm = E1000_READ_REG(hw, SWSM);
8172 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008173 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008174 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008175 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008176 timeout--;
8177 }
8178
Auke Kok8fc897b2006-08-28 14:56:16 -07008179 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008180 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8181 return -E1000_ERR_RESET;
8182 }
8183
8184 return E1000_SUCCESS;
8185}
8186
8187/***************************************************************************
8188 *
8189 * Release semaphore bit (SMBI).
8190 *
8191 * hw: Struct containing variables accessed by shared code
8192 *
8193 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008194static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008195e1000_release_software_semaphore(struct e1000_hw *hw)
8196{
8197 uint32_t swsm;
8198
8199 DEBUGFUNC("e1000_release_software_semaphore");
8200
Nicholas Nunley35574762006-09-27 12:53:34 -07008201 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008202 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008203 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008204
8205 swsm = E1000_READ_REG(hw, SWSM);
8206 /* Release the SW semaphores.*/
8207 swsm &= ~E1000_SWSM_SMBI;
8208 E1000_WRITE_REG(hw, SWSM, swsm);
8209}
8210
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008211/******************************************************************************
8212 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8213 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8214 * the caller to figure out how to deal with it.
8215 *
8216 * hw - Struct containing variables accessed by shared code
8217 *
8218 * returns: - E1000_BLK_PHY_RESET
8219 * E1000_SUCCESS
8220 *
8221 *****************************************************************************/
8222int32_t
8223e1000_check_phy_reset_block(struct e1000_hw *hw)
8224{
8225 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008226 uint32_t fwsm = 0;
8227
8228 if (hw->mac_type == e1000_ich8lan) {
8229 fwsm = E1000_READ_REG(hw, FWSM);
8230 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8231 : E1000_BLK_PHY_RESET;
8232 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008233
8234 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008235 manc = E1000_READ_REG(hw, MANC);
8236 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008237 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008238}
8239
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008240static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008241e1000_arc_subsystem_valid(struct e1000_hw *hw)
8242{
8243 uint32_t fwsm;
8244
8245 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8246 * may not be provided a DMA clock when no manageability features are
8247 * enabled. We do not want to perform any reads/writes to these registers
8248 * if this is the case. We read FWSM to determine the manageability mode.
8249 */
8250 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008251 case e1000_82571:
8252 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008253 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008254 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008255 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008256 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008257 return TRUE;
8258 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008259 case e1000_ich8lan:
8260 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008261 default:
8262 break;
8263 }
8264 return FALSE;
8265}
8266
8267
Auke Kokd37ea5d2006-06-27 09:08:17 -07008268/******************************************************************************
8269 * Configure PCI-Ex no-snoop
8270 *
8271 * hw - Struct containing variables accessed by shared code.
8272 * no_snoop - Bitmap of no-snoop events.
8273 *
8274 * returns: E1000_SUCCESS
8275 *
8276 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008277static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008278e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8279{
8280 uint32_t gcr_reg = 0;
8281
8282 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8283
8284 if (hw->bus_type == e1000_bus_type_unknown)
8285 e1000_get_bus_info(hw);
8286
8287 if (hw->bus_type != e1000_bus_type_pci_express)
8288 return E1000_SUCCESS;
8289
8290 if (no_snoop) {
8291 gcr_reg = E1000_READ_REG(hw, GCR);
8292 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8293 gcr_reg |= no_snoop;
8294 E1000_WRITE_REG(hw, GCR, gcr_reg);
8295 }
8296 if (hw->mac_type == e1000_ich8lan) {
8297 uint32_t ctrl_ext;
8298
8299 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8300
8301 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8302 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8303 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8304 }
8305
8306 return E1000_SUCCESS;
8307}
8308
8309/***************************************************************************
8310 *
8311 * Get software semaphore FLAG bit (SWFLAG).
8312 * SWFLAG is used to synchronize the access to all shared resource between
8313 * SW, FW and HW.
8314 *
8315 * hw: Struct containing variables accessed by shared code
8316 *
8317 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008318static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008319e1000_get_software_flag(struct e1000_hw *hw)
8320{
8321 int32_t timeout = PHY_CFG_TIMEOUT;
8322 uint32_t extcnf_ctrl;
8323
8324 DEBUGFUNC("e1000_get_software_flag");
8325
8326 if (hw->mac_type == e1000_ich8lan) {
8327 while (timeout) {
8328 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8329 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8330 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8331
8332 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8333 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8334 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008335 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008336 timeout--;
8337 }
8338
8339 if (!timeout) {
8340 DEBUGOUT("FW or HW locks the resource too long.\n");
8341 return -E1000_ERR_CONFIG;
8342 }
8343 }
8344
8345 return E1000_SUCCESS;
8346}
8347
8348/***************************************************************************
8349 *
8350 * Release software semaphore FLAG bit (SWFLAG).
8351 * SWFLAG is used to synchronize the access to all shared resource between
8352 * SW, FW and HW.
8353 *
8354 * hw: Struct containing variables accessed by shared code
8355 *
8356 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008357static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008358e1000_release_software_flag(struct e1000_hw *hw)
8359{
8360 uint32_t extcnf_ctrl;
8361
8362 DEBUGFUNC("e1000_release_software_flag");
8363
8364 if (hw->mac_type == e1000_ich8lan) {
8365 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8366 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8367 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8368 }
8369
8370 return;
8371}
8372
Auke Kokd37ea5d2006-06-27 09:08:17 -07008373/******************************************************************************
8374 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8375 * register.
8376 *
8377 * hw - Struct containing variables accessed by shared code
8378 * offset - offset of word in the EEPROM to read
8379 * data - word read from the EEPROM
8380 * words - number of words to read
8381 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008382static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008383e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8384 uint16_t *data)
8385{
8386 int32_t error = E1000_SUCCESS;
8387 uint32_t flash_bank = 0;
8388 uint32_t act_offset = 0;
8389 uint32_t bank_offset = 0;
8390 uint16_t word = 0;
8391 uint16_t i = 0;
8392
8393 /* We need to know which is the valid flash bank. In the event
8394 * that we didn't allocate eeprom_shadow_ram, we may not be
8395 * managing flash_bank. So it cannot be trusted and needs
8396 * to be updated with each read.
8397 */
8398 /* Value of bit 22 corresponds to the flash bank we're on. */
8399 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8400
8401 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8402 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8403
8404 error = e1000_get_software_flag(hw);
8405 if (error != E1000_SUCCESS)
8406 return error;
8407
8408 for (i = 0; i < words; i++) {
8409 if (hw->eeprom_shadow_ram != NULL &&
8410 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8411 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8412 } else {
8413 /* The NVM part needs a byte offset, hence * 2 */
8414 act_offset = bank_offset + ((offset + i) * 2);
8415 error = e1000_read_ich8_word(hw, act_offset, &word);
8416 if (error != E1000_SUCCESS)
8417 break;
8418 data[i] = word;
8419 }
8420 }
8421
8422 e1000_release_software_flag(hw);
8423
8424 return error;
8425}
8426
8427/******************************************************************************
8428 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8429 * register. Actually, writes are written to the shadow ram cache in the hw
8430 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8431 * the NVM, which occurs when the NVM checksum is updated.
8432 *
8433 * hw - Struct containing variables accessed by shared code
8434 * offset - offset of word in the EEPROM to write
8435 * words - number of words to write
8436 * data - words to write to the EEPROM
8437 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008438static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008439e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8440 uint16_t *data)
8441{
8442 uint32_t i = 0;
8443 int32_t error = E1000_SUCCESS;
8444
8445 error = e1000_get_software_flag(hw);
8446 if (error != E1000_SUCCESS)
8447 return error;
8448
8449 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8450 * allocated. Subsequent reads to the modified words are read from
8451 * this cached structure as well. Writes will only go into this
8452 * cached structure unless it's followed by a call to
8453 * e1000_update_eeprom_checksum() where it will commit the changes
8454 * and clear the "modified" field.
8455 */
8456 if (hw->eeprom_shadow_ram != NULL) {
8457 for (i = 0; i < words; i++) {
8458 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8459 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8460 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8461 } else {
8462 error = -E1000_ERR_EEPROM;
8463 break;
8464 }
8465 }
8466 } else {
8467 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8468 * as they don't perform any NVM writes. An attempt in doing so
8469 * will result in this error.
8470 */
8471 error = -E1000_ERR_EEPROM;
8472 }
8473
8474 e1000_release_software_flag(hw);
8475
8476 return error;
8477}
8478
8479/******************************************************************************
8480 * This function does initial flash setup so that a new read/write/erase cycle
8481 * can be started.
8482 *
8483 * hw - The pointer to the hw structure
8484 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008485static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008486e1000_ich8_cycle_init(struct e1000_hw *hw)
8487{
8488 union ich8_hws_flash_status hsfsts;
8489 int32_t error = E1000_ERR_EEPROM;
8490 int32_t i = 0;
8491
8492 DEBUGFUNC("e1000_ich8_cycle_init");
8493
8494 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8495
8496 /* May be check the Flash Des Valid bit in Hw status */
8497 if (hsfsts.hsf_status.fldesvalid == 0) {
8498 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8499 return error;
8500 }
8501
8502 /* Clear FCERR in Hw status by writing 1 */
8503 /* Clear DAEL in Hw status by writing a 1 */
8504 hsfsts.hsf_status.flcerr = 1;
8505 hsfsts.hsf_status.dael = 1;
8506
8507 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8508
8509 /* Either we should have a hardware SPI cycle in progress bit to check
8510 * against, in order to start a new cycle or FDONE bit should be changed
8511 * in the hardware so that it is 1 after harware reset, which can then be
8512 * used as an indication whether a cycle is in progress or has been
8513 * completed .. we should also have some software semaphore mechanism to
8514 * guard FDONE or the cycle in progress bit so that two threads access to
8515 * those bits can be sequentiallized or a way so that 2 threads dont
8516 * start the cycle at the same time */
8517
8518 if (hsfsts.hsf_status.flcinprog == 0) {
8519 /* There is no cycle running at present, so we can start a cycle */
8520 /* Begin by setting Flash Cycle Done. */
8521 hsfsts.hsf_status.flcdone = 1;
8522 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8523 error = E1000_SUCCESS;
8524 } else {
8525 /* otherwise poll for sometime so the current cycle has a chance
8526 * to end before giving up. */
8527 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8528 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8529 if (hsfsts.hsf_status.flcinprog == 0) {
8530 error = E1000_SUCCESS;
8531 break;
8532 }
8533 udelay(1);
8534 }
8535 if (error == E1000_SUCCESS) {
8536 /* Successful in waiting for previous cycle to timeout,
8537 * now set the Flash Cycle Done. */
8538 hsfsts.hsf_status.flcdone = 1;
8539 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8540 } else {
8541 DEBUGOUT("Flash controller busy, cannot get access");
8542 }
8543 }
8544 return error;
8545}
8546
8547/******************************************************************************
8548 * This function starts a flash cycle and waits for its completion
8549 *
8550 * hw - The pointer to the hw structure
8551 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008552static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008553e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8554{
8555 union ich8_hws_flash_ctrl hsflctl;
8556 union ich8_hws_flash_status hsfsts;
8557 int32_t error = E1000_ERR_EEPROM;
8558 uint32_t i = 0;
8559
8560 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8561 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8562 hsflctl.hsf_ctrl.flcgo = 1;
8563 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8564
8565 /* wait till FDONE bit is set to 1 */
8566 do {
8567 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8568 if (hsfsts.hsf_status.flcdone == 1)
8569 break;
8570 udelay(1);
8571 i++;
8572 } while (i < timeout);
8573 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8574 error = E1000_SUCCESS;
8575 }
8576 return error;
8577}
8578
8579/******************************************************************************
8580 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8581 *
8582 * hw - The pointer to the hw structure
8583 * index - The index of the byte or word to read.
8584 * size - Size of data to read, 1=byte 2=word
8585 * data - Pointer to the word to store the value read.
8586 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008587static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008588e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8589 uint32_t size, uint16_t* data)
8590{
8591 union ich8_hws_flash_status hsfsts;
8592 union ich8_hws_flash_ctrl hsflctl;
8593 uint32_t flash_linear_address;
8594 uint32_t flash_data = 0;
8595 int32_t error = -E1000_ERR_EEPROM;
8596 int32_t count = 0;
8597
8598 DEBUGFUNC("e1000_read_ich8_data");
8599
8600 if (size < 1 || size > 2 || data == 0x0 ||
8601 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8602 return error;
8603
8604 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8605 hw->flash_base_addr;
8606
8607 do {
8608 udelay(1);
8609 /* Steps */
8610 error = e1000_ich8_cycle_init(hw);
8611 if (error != E1000_SUCCESS)
8612 break;
8613
8614 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8615 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8616 hsflctl.hsf_ctrl.fldbcount = size - 1;
8617 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8618 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8619
8620 /* Write the last 24 bits of index into Flash Linear address field in
8621 * Flash Address */
8622 /* TODO: TBD maybe check the index against the size of flash */
8623
8624 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8625
8626 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8627
8628 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8629 * sequence a few more times, else read in (shift in) the Flash Data0,
8630 * the order is least significant byte first msb to lsb */
8631 if (error == E1000_SUCCESS) {
8632 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8633 if (size == 1) {
8634 *data = (uint8_t)(flash_data & 0x000000FF);
8635 } else if (size == 2) {
8636 *data = (uint16_t)(flash_data & 0x0000FFFF);
8637 }
8638 break;
8639 } else {
8640 /* If we've gotten here, then things are probably completely hosed,
8641 * but if the error condition is detected, it won't hurt to give
8642 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8643 */
8644 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8645 if (hsfsts.hsf_status.flcerr == 1) {
8646 /* Repeat for some time before giving up. */
8647 continue;
8648 } else if (hsfsts.hsf_status.flcdone == 0) {
8649 DEBUGOUT("Timeout error - flash cycle did not complete.");
8650 break;
8651 }
8652 }
8653 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8654
8655 return error;
8656}
8657
8658/******************************************************************************
8659 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8660 *
8661 * hw - The pointer to the hw structure
8662 * index - The index of the byte/word to read.
8663 * size - Size of data to read, 1=byte 2=word
8664 * data - The byte(s) to write to the NVM.
8665 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008666static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008667e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8668 uint16_t data)
8669{
8670 union ich8_hws_flash_status hsfsts;
8671 union ich8_hws_flash_ctrl hsflctl;
8672 uint32_t flash_linear_address;
8673 uint32_t flash_data = 0;
8674 int32_t error = -E1000_ERR_EEPROM;
8675 int32_t count = 0;
8676
8677 DEBUGFUNC("e1000_write_ich8_data");
8678
8679 if (size < 1 || size > 2 || data > size * 0xff ||
8680 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8681 return error;
8682
8683 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8684 hw->flash_base_addr;
8685
8686 do {
8687 udelay(1);
8688 /* Steps */
8689 error = e1000_ich8_cycle_init(hw);
8690 if (error != E1000_SUCCESS)
8691 break;
8692
8693 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8694 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8695 hsflctl.hsf_ctrl.fldbcount = size -1;
8696 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8697 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8698
8699 /* Write the last 24 bits of index into Flash Linear address field in
8700 * Flash Address */
8701 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8702
8703 if (size == 1)
8704 flash_data = (uint32_t)data & 0x00FF;
8705 else
8706 flash_data = (uint32_t)data;
8707
8708 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8709
8710 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8711 * sequence a few more times else done */
8712 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8713 if (error == E1000_SUCCESS) {
8714 break;
8715 } else {
8716 /* If we're here, then things are most likely completely hosed,
8717 * but if the error condition is detected, it won't hurt to give
8718 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8719 */
8720 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8721 if (hsfsts.hsf_status.flcerr == 1) {
8722 /* Repeat for some time before giving up. */
8723 continue;
8724 } else if (hsfsts.hsf_status.flcdone == 0) {
8725 DEBUGOUT("Timeout error - flash cycle did not complete.");
8726 break;
8727 }
8728 }
8729 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8730
8731 return error;
8732}
8733
8734/******************************************************************************
8735 * Reads a single byte from the NVM using the ICH8 flash access registers.
8736 *
8737 * hw - pointer to e1000_hw structure
8738 * index - The index of the byte to read.
8739 * data - Pointer to a byte to store the value read.
8740 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008741static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008742e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8743{
8744 int32_t status = E1000_SUCCESS;
8745 uint16_t word = 0;
8746
8747 status = e1000_read_ich8_data(hw, index, 1, &word);
8748 if (status == E1000_SUCCESS) {
8749 *data = (uint8_t)word;
8750 }
8751
8752 return status;
8753}
8754
8755/******************************************************************************
8756 * Writes a single byte to the NVM using the ICH8 flash access registers.
8757 * Performs verification by reading back the value and then going through
8758 * a retry algorithm before giving up.
8759 *
8760 * hw - pointer to e1000_hw structure
8761 * index - The index of the byte to write.
8762 * byte - The byte to write to the NVM.
8763 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008764static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008765e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8766{
8767 int32_t error = E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008768 int32_t program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008769
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008770 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008771
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008772 error = e1000_write_ich8_byte(hw, index, byte);
8773
8774 if (error != E1000_SUCCESS) {
8775 for (program_retries = 0; program_retries < 100; program_retries++) {
8776 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8777 error = e1000_write_ich8_byte(hw, index, byte);
8778 udelay(100);
8779 if (error == E1000_SUCCESS)
8780 break;
8781 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008782 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008783
Auke Kokd37ea5d2006-06-27 09:08:17 -07008784 if (program_retries == 100)
8785 error = E1000_ERR_EEPROM;
8786
8787 return error;
8788}
8789
8790/******************************************************************************
8791 * Writes a single byte to the NVM using the ICH8 flash access registers.
8792 *
8793 * hw - pointer to e1000_hw structure
8794 * index - The index of the byte to read.
8795 * data - The byte to write to the NVM.
8796 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008797static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008798e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8799{
8800 int32_t status = E1000_SUCCESS;
8801 uint16_t word = (uint16_t)data;
8802
8803 status = e1000_write_ich8_data(hw, index, 1, word);
8804
8805 return status;
8806}
8807
8808/******************************************************************************
8809 * Reads a word from the NVM using the ICH8 flash access registers.
8810 *
8811 * hw - pointer to e1000_hw structure
8812 * index - The starting byte index of the word to read.
8813 * data - Pointer to a word to store the value read.
8814 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008815static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008816e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8817{
8818 int32_t status = E1000_SUCCESS;
8819 status = e1000_read_ich8_data(hw, index, 2, data);
8820 return status;
8821}
8822
8823/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008824 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8825 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008826 *
8827 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008828 * bank - 0 for first bank, 1 for second bank
8829 *
8830 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8831 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8832 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008833 *****************************************************************************/
8834int32_t
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008835e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008836{
8837 union ich8_hws_flash_status hsfsts;
8838 union ich8_hws_flash_ctrl hsflctl;
8839 uint32_t flash_linear_address;
8840 int32_t count = 0;
8841 int32_t error = E1000_ERR_EEPROM;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008842 int32_t iteration;
8843 int32_t sub_sector_size = 0;
8844 int32_t bank_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008845 int32_t j = 0;
8846 int32_t error_flag = 0;
8847
8848 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8849
8850 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8851 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8852 * consecutive sectors. The start index for the nth Hw sector can be
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008853 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008854 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8855 * The start index for the nth Hw sector can be calculated
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008856 * as bank * 4096
8857 * 10: The HW sector is 8K bytes
8858 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008859 if (hsfsts.hsf_status.berasesz == 0x0) {
8860 /* Hw sector size 256 */
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008861 sub_sector_size = ICH8_FLASH_SEG_SIZE_256;
8862 bank_size = ICH8_FLASH_SECTOR_SIZE;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008863 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8864 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008865 bank_size = ICH8_FLASH_SEG_SIZE_4K;
8866 iteration = 1;
8867 } else if (hw->mac_type != e1000_ich8lan &&
8868 hsfsts.hsf_status.berasesz == 0x2) {
8869 /* 8K erase size invalid for ICH8 - added in for ICH9 */
8870 bank_size = ICH9_FLASH_SEG_SIZE_8K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008871 iteration = 1;
8872 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008873 bank_size = ICH8_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 */
8891 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8892 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8893 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8894
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 Kirsher2a88c172006-09-27 12:54:05 -07008901 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008902
8903 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8904
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008905 error = e1000_ich8_flash_cycle(hw, ICH8_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 {
8911 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8912 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 }
8920 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8921 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