blob: 8604adbe351cc07dc2b004896af8c4cd338d9331 [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{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500311 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500313 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:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3;
365 break;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM:
369 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:
378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547;
380 break;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
383 break;
384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
Auke Kokce57a022007-08-09 14:09:34 -0700387 case E1000_DEV_ID_82571EB_SERDES_DUAL:
388 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500389 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokf4ec7f92007-08-30 11:23:58 -0700390 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -0700391 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500392 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
393 hw->mac_type = e1000_82571;
394 break;
395 case E1000_DEV_ID_82572EI_COPPER:
396 case E1000_DEV_ID_82572EI_FIBER:
397 case E1000_DEV_ID_82572EI_SERDES:
398 case E1000_DEV_ID_82572EI:
399 hw->mac_type = e1000_82572;
400 break;
401 case E1000_DEV_ID_82573E:
402 case E1000_DEV_ID_82573E_IAMT:
403 case E1000_DEV_ID_82573L:
404 hw->mac_type = e1000_82573;
405 break;
406 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
407 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
408 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
409 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
410 hw->mac_type = e1000_80003es2lan;
411 break;
412 case E1000_DEV_ID_ICH8_IGP_M_AMT:
413 case E1000_DEV_ID_ICH8_IGP_AMT:
414 case E1000_DEV_ID_ICH8_IGP_C:
415 case E1000_DEV_ID_ICH8_IFE:
416 case E1000_DEV_ID_ICH8_IFE_GT:
417 case E1000_DEV_ID_ICH8_IFE_G:
418 case E1000_DEV_ID_ICH8_IGP_M:
419 hw->mac_type = e1000_ich8lan;
420 break;
421 default:
422 /* Should never have loaded on this device */
423 return -E1000_ERR_MAC_TYPE;
424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500426 switch (hw->mac_type) {
427 case e1000_ich8lan:
428 hw->swfwhw_semaphore_present = TRUE;
429 hw->asf_firmware_present = TRUE;
430 break;
431 case e1000_80003es2lan:
432 hw->swfw_sync_present = TRUE;
433 /* fall through */
434 case e1000_82571:
435 case e1000_82572:
436 case e1000_82573:
437 hw->eeprom_semaphore_present = TRUE;
438 /* fall through */
439 case e1000_82541:
440 case e1000_82547:
441 case e1000_82541_rev_2:
442 case e1000_82547_rev_2:
443 hw->asf_firmware_present = TRUE;
444 break;
445 default:
446 break;
447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Jeff Garzik167fb282006-12-15 10:41:15 -0500449 /* The 82543 chip does not count tx_carrier_errors properly in
450 * FD mode
451 */
452 if (hw->mac_type == e1000_82543)
453 hw->bad_tx_carr_stats_fd = TRUE;
454
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500455 /* capable of receiving management packets to the host */
456 if (hw->mac_type >= e1000_82571)
457 hw->has_manc2h = TRUE;
458
Jeff Garzikbb8e3312006-12-15 11:06:17 -0500459 /* In rare occasions, ESB2 systems would end up started without
460 * the RX unit being turned on.
461 */
462 if (hw->mac_type == e1000_80003es2lan)
463 hw->rx_needs_kicking = TRUE;
464
Jeff Garzik15e376b2006-12-15 11:16:33 -0500465 if (hw->mac_type > e1000_82544)
466 hw->has_smbus = TRUE;
467
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500468 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
471/*****************************************************************************
472 * Set media type and TBI compatibility.
473 *
474 * hw - Struct containing variables accessed by shared code
475 * **************************************************************************/
476void
477e1000_set_media_type(struct e1000_hw *hw)
478{
479 uint32_t status;
480
481 DEBUGFUNC("e1000_set_media_type");
482
Auke Kok8fc897b2006-08-28 14:56:16 -0700483 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* tbi_compatibility is only valid on 82543 */
485 hw->tbi_compatibility_en = FALSE;
486 }
487
488 switch (hw->device_id) {
489 case E1000_DEV_ID_82545GM_SERDES:
490 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400491 case E1000_DEV_ID_82571EB_SERDES:
Auke Kokce57a022007-08-09 14:09:34 -0700492 case E1000_DEV_ID_82571EB_SERDES_DUAL:
493 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400494 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800495 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 hw->media_type = e1000_media_type_internal_serdes;
497 break;
498 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700499 switch (hw->mac_type) {
500 case e1000_82542_rev2_0:
501 case e1000_82542_rev2_1:
502 hw->media_type = e1000_media_type_fiber;
503 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700504 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700505 case e1000_82573:
506 /* The STATUS_TBIMODE bit is reserved or reused for the this
507 * device.
508 */
509 hw->media_type = e1000_media_type_copper;
510 break;
511 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700513 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 hw->media_type = e1000_media_type_fiber;
515 /* tbi_compatibility not valid on fiber */
516 hw->tbi_compatibility_en = FALSE;
517 } else {
518 hw->media_type = e1000_media_type_copper;
519 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700520 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522 }
523}
524
525/******************************************************************************
526 * Reset the transmit and receive units; mask and clear all interrupts.
527 *
528 * hw - Struct containing variables accessed by shared code
529 *****************************************************************************/
530int32_t
531e1000_reset_hw(struct e1000_hw *hw)
532{
533 uint32_t ctrl;
534 uint32_t ctrl_ext;
535 uint32_t icr;
536 uint32_t manc;
537 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700538 uint32_t timeout;
539 uint32_t extcnf_ctrl;
540 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 DEBUGFUNC("e1000_reset_hw");
543
544 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700545 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
547 e1000_pci_clear_mwi(hw);
548 }
549
Auke Kok8fc897b2006-08-28 14:56:16 -0700550 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700551 /* Prevent the PCI-E bus from sticking if there is no TLP connection
552 * on the last TLP read/write transaction when MAC is reset.
553 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700554 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700555 DEBUGOUT("PCI-E Master disable polling has failed.\n");
556 }
557 }
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 /* Clear interrupt mask to stop board from generating interrupts */
560 DEBUGOUT("Masking off all interrupts\n");
561 E1000_WRITE_REG(hw, IMC, 0xffffffff);
562
563 /* Disable the Transmit and Receive units. Then delay to allow
564 * any pending transactions to complete before we hit the MAC with
565 * the global reset.
566 */
567 E1000_WRITE_REG(hw, RCTL, 0);
568 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
569 E1000_WRITE_FLUSH(hw);
570
571 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
572 hw->tbi_compatibility_on = FALSE;
573
574 /* Delay to allow any outstanding PCI transactions to complete before
575 * resetting the device
576 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400577 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 ctrl = E1000_READ_REG(hw, CTRL);
580
581 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700582 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700583 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400584 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700587 /* Must acquire the MDIO ownership before MAC reset.
588 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700589 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700590 timeout = 10;
591
592 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
593 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
594
595 do {
596 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
597 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
598
Auke Kok8fc897b2006-08-28 14:56:16 -0700599 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700600 break;
601 else
602 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
603
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400604 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700605 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700606 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700607 }
608
Auke Kokcd94dd02006-06-27 09:08:22 -0700609 /* Workaround for ICH8 bit corruption issue in FIFO memory */
610 if (hw->mac_type == e1000_ich8lan) {
611 /* Set Tx and Rx buffer allocation to 8k apiece. */
612 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
613 /* Set Packet Buffer Size to 16k. */
614 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
615 }
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 /* Issue a global reset to the MAC. This will reset the chip's
618 * transmit, receive, DMA, and link units. It will not effect
619 * the current PCI configuration. The global reset bit is self-
620 * clearing, and should clear within a microsecond.
621 */
622 DEBUGOUT("Issuing a global reset to MAC\n");
623
Auke Kok8fc897b2006-08-28 14:56:16 -0700624 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 case e1000_82544:
626 case e1000_82540:
627 case e1000_82545:
628 case e1000_82546:
629 case e1000_82541:
630 case e1000_82541_rev_2:
631 /* These controllers can't ack the 64-bit write when issuing the
632 * reset, so use IO-mapping as a workaround to issue the reset */
633 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
634 break;
635 case e1000_82545_rev_3:
636 case e1000_82546_rev_3:
637 /* Reset is performed on a shadow of the control register */
638 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
639 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700640 case e1000_ich8lan:
641 if (!hw->phy_reset_disable &&
642 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
643 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
644 * at the same time to make sure the interface between
645 * MAC and the external PHY is reset.
646 */
647 ctrl |= E1000_CTRL_PHY_RST;
648 }
649
650 e1000_get_software_flag(hw);
651 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400652 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700653 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 default:
655 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
656 break;
657 }
658
659 /* After MAC reset, force reload of EEPROM to restore power-on settings to
660 * device. Later controllers reload the EEPROM automatically, so just wait
661 * for reload to complete.
662 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700663 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 case e1000_82542_rev2_0:
665 case e1000_82542_rev2_1:
666 case e1000_82543:
667 case e1000_82544:
668 /* Wait for reset to complete */
669 udelay(10);
670 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
671 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
672 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
673 E1000_WRITE_FLUSH(hw);
674 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400675 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 break;
677 case e1000_82541:
678 case e1000_82541_rev_2:
679 case e1000_82547:
680 case e1000_82547_rev_2:
681 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400682 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700684 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500685 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
686 udelay(10);
687 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
688 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
689 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
690 E1000_WRITE_FLUSH(hw);
691 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700692 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700693 default:
694 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700695 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700696 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700697 return ret_val;
698 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700702 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 manc = E1000_READ_REG(hw, MANC);
704 manc &= ~(E1000_MANC_ARP_EN);
705 E1000_WRITE_REG(hw, MANC, manc);
706 }
707
Auke Kok8fc897b2006-08-28 14:56:16 -0700708 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 e1000_phy_init_script(hw);
710
711 /* Configure activity LED after PHY reset */
712 led_ctrl = E1000_READ_REG(hw, LEDCTL);
713 led_ctrl &= IGP_ACTIVITY_LED_MASK;
714 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
715 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
716 }
717
718 /* Clear interrupt mask to stop board from generating interrupts */
719 DEBUGOUT("Masking off all interrupts\n");
720 E1000_WRITE_REG(hw, IMC, 0xffffffff);
721
722 /* Clear any pending interrupt events. */
723 icr = E1000_READ_REG(hw, ICR);
724
725 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700726 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400727 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 e1000_pci_set_mwi(hw);
729 }
730
Auke Kokcd94dd02006-06-27 09:08:22 -0700731 if (hw->mac_type == e1000_ich8lan) {
732 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
733 kab |= E1000_KABGTXD_BGSQLBIAS;
734 E1000_WRITE_REG(hw, KABGTXD, kab);
735 }
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return E1000_SUCCESS;
738}
739
740/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700741 *
742 * Initialize a number of hardware-dependent bits
743 *
744 * hw: Struct containing variables accessed by shared code
745 *
746 * This function contains hardware limitation workarounds for PCI-E adapters
747 *
748 *****************************************************************************/
749static void
750e1000_initialize_hardware_bits(struct e1000_hw *hw)
751{
752 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
753 /* Settings common to all PCI-express silicon */
754 uint32_t reg_ctrl, reg_ctrl_ext;
755 uint32_t reg_tarc0, reg_tarc1;
756 uint32_t reg_tctl;
757 uint32_t reg_txdctl, reg_txdctl1;
758
759 /* link autonegotiation/sync workarounds */
760 reg_tarc0 = E1000_READ_REG(hw, TARC0);
761 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
762
763 /* Enable not-done TX descriptor counting */
764 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
765 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
766 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
767 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
768 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
769 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
770
771 switch (hw->mac_type) {
772 case e1000_82571:
773 case e1000_82572:
774 /* Clear PHY TX compatible mode bits */
775 reg_tarc1 = E1000_READ_REG(hw, TARC1);
776 reg_tarc1 &= ~((1 << 30)|(1 << 29));
777
778 /* link autonegotiation/sync workarounds */
779 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
780
781 /* TX ring control fixes */
782 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
783
784 /* Multiple read bit is reversed polarity */
785 reg_tctl = E1000_READ_REG(hw, TCTL);
786 if (reg_tctl & E1000_TCTL_MULR)
787 reg_tarc1 &= ~(1 << 28);
788 else
789 reg_tarc1 |= (1 << 28);
790
791 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
792 break;
793 case e1000_82573:
794 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
795 reg_ctrl_ext &= ~(1 << 23);
796 reg_ctrl_ext |= (1 << 22);
797
798 /* TX byte count fix */
799 reg_ctrl = E1000_READ_REG(hw, CTRL);
800 reg_ctrl &= ~(1 << 29);
801
802 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
803 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
804 break;
805 case e1000_80003es2lan:
806 /* improve small packet performace for fiber/serdes */
807 if ((hw->media_type == e1000_media_type_fiber) ||
808 (hw->media_type == e1000_media_type_internal_serdes)) {
809 reg_tarc0 &= ~(1 << 20);
810 }
811
812 /* Multiple read bit is reversed polarity */
813 reg_tctl = E1000_READ_REG(hw, TCTL);
814 reg_tarc1 = E1000_READ_REG(hw, TARC1);
815 if (reg_tctl & E1000_TCTL_MULR)
816 reg_tarc1 &= ~(1 << 28);
817 else
818 reg_tarc1 |= (1 << 28);
819
820 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
821 break;
822 case e1000_ich8lan:
823 /* Reduce concurrent DMA requests to 3 from 4 */
824 if ((hw->revision_id < 3) ||
825 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
826 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
827 reg_tarc0 |= ((1 << 29)|(1 << 28));
828
829 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
830 reg_ctrl_ext |= (1 << 22);
831 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
832
833 /* workaround TX hang with TSO=on */
834 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
835
836 /* Multiple read bit is reversed polarity */
837 reg_tctl = E1000_READ_REG(hw, TCTL);
838 reg_tarc1 = E1000_READ_REG(hw, TARC1);
839 if (reg_tctl & E1000_TCTL_MULR)
840 reg_tarc1 &= ~(1 << 28);
841 else
842 reg_tarc1 |= (1 << 28);
843
844 /* workaround TX hang with TSO=on */
845 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
846
847 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
848 break;
849 default:
850 break;
851 }
852
853 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
854 }
855}
856
857/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 * Performs basic configuration of the adapter.
859 *
860 * hw - Struct containing variables accessed by shared code
861 *
862 * Assumes that the controller has previously been reset and is in a
863 * post-reset uninitialized state. Initializes the receive address registers,
864 * multicast table, and VLAN filter table. Calls routines to setup link
865 * configuration and flow control settings. Clears all on-chip counters. Leaves
866 * the transmit and receive units disabled and uninitialized.
867 *****************************************************************************/
868int32_t
869e1000_init_hw(struct e1000_hw *hw)
870{
871 uint32_t ctrl;
872 uint32_t i;
873 int32_t ret_val;
874 uint16_t pcix_cmd_word;
875 uint16_t pcix_stat_hi_word;
876 uint16_t cmd_mmrbc;
877 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700878 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800879 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800880 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 DEBUGFUNC("e1000_init_hw");
883
Jeff Kirsher7820d422006-08-16 13:39:00 -0700884 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700885 if ((hw->mac_type == e1000_ich8lan) &&
886 ((hw->revision_id < 3) ||
887 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
888 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
889 reg_data = E1000_READ_REG(hw, STATUS);
890 reg_data &= ~0x80000000;
891 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700892 }
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /* Initialize Identification LED */
895 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700896 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 DEBUGOUT("Error Initializing Identification LED\n");
898 return ret_val;
899 }
900
901 /* Set the media type and TBI compatibility */
902 e1000_set_media_type(hw);
903
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700904 /* Must be called after e1000_set_media_type because media_type is used */
905 e1000_initialize_hardware_bits(hw);
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 /* Disabling VLAN filtering. */
908 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700909 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
910 if (hw->mac_type != e1000_ich8lan) {
911 if (hw->mac_type < e1000_82545_rev_3)
912 E1000_WRITE_REG(hw, VET, 0);
913 e1000_clear_vfta(hw);
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700917 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
919 e1000_pci_clear_mwi(hw);
920 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
921 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400922 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 }
924
925 /* Setup the receive address. This involves initializing all of the Receive
926 * Address Registers (RARs 0 - 15).
927 */
928 e1000_init_rx_addrs(hw);
929
930 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700931 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 E1000_WRITE_REG(hw, RCTL, 0);
933 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400934 msleep(1);
935 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 e1000_pci_set_mwi(hw);
937 }
938
939 /* Zero out the Multicast HASH table */
940 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700941 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700942 if (hw->mac_type == e1000_ich8lan)
943 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700944 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700946 /* use write flush to prevent Memory Write Block (MWB) from
947 * occuring when accessing our register space */
948 E1000_WRITE_FLUSH(hw);
949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 /* Set the PCI priority bit correctly in the CTRL register. This
952 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700953 * gives equal priority to transmits and receives. Valid only on
954 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700956 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 ctrl = E1000_READ_REG(hw, CTRL);
958 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
959 }
960
Auke Kok8fc897b2006-08-28 14:56:16 -0700961 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 case e1000_82545_rev_3:
963 case e1000_82546_rev_3:
964 break;
965 default:
966 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700967 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
969 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
970 &pcix_stat_hi_word);
971 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
972 PCIX_COMMAND_MMRBC_SHIFT;
973 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
974 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700975 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700977 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
979 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
980 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
981 &pcix_cmd_word);
982 }
983 }
984 break;
985 }
986
Auke Kokcd94dd02006-06-27 09:08:22 -0700987 /* More time needed for PHY to initialize */
988 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400989 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 /* Call a subroutine to configure the link and setup flow control. */
992 ret_val = e1000_setup_link(hw);
993
994 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700995 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 ctrl = E1000_READ_REG(hw, TXDCTL);
997 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
998 E1000_WRITE_REG(hw, TXDCTL, ctrl);
999 }
1000
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001001 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -07001002 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001003 }
1004
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001005 switch (hw->mac_type) {
1006 default:
1007 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001008 case e1000_80003es2lan:
1009 /* Enable retransmit on late collisions */
1010 reg_data = E1000_READ_REG(hw, TCTL);
1011 reg_data |= E1000_TCTL_RTLC;
1012 E1000_WRITE_REG(hw, TCTL, reg_data);
1013
1014 /* Configure Gigabit Carry Extend Padding */
1015 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1016 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1017 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1018 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1019
1020 /* Configure Transmit Inter-Packet Gap */
1021 reg_data = E1000_READ_REG(hw, TIPG);
1022 reg_data &= ~E1000_TIPG_IPGT_MASK;
1023 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1024 E1000_WRITE_REG(hw, TIPG, reg_data);
1025
1026 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1027 reg_data &= ~0x00100000;
1028 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1029 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001030 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001031 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001032 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001033 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001034 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001035 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1036 break;
1037 }
1038
1039
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001040 if (hw->mac_type == e1000_82573) {
1041 uint32_t gcr = E1000_READ_REG(hw, GCR);
1042 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1043 E1000_WRITE_REG(hw, GCR, gcr);
1044 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 /* Clear all of the statistics registers (clear on read). It is
1047 * important that we do this after we have tried to establish link
1048 * because the symbol error count will increment wildly if there
1049 * is no link.
1050 */
1051 e1000_clear_hw_cntrs(hw);
1052
Auke Kokcd94dd02006-06-27 09:08:22 -07001053 /* ICH8 No-snoop bits are opposite polarity.
1054 * Set to snoop by default after reset. */
1055 if (hw->mac_type == e1000_ich8lan)
1056 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1057
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001058 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1059 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1060 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1061 /* Relaxed ordering must be disabled to avoid a parity
1062 * error crash in a PCI slot. */
1063 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1064 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1065 }
1066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return ret_val;
1068}
1069
1070/******************************************************************************
1071 * Adjust SERDES output amplitude based on EEPROM setting.
1072 *
1073 * hw - Struct containing variables accessed by shared code.
1074 *****************************************************************************/
1075static int32_t
1076e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1077{
1078 uint16_t eeprom_data;
1079 int32_t ret_val;
1080
1081 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1082
Auke Kok8fc897b2006-08-28 14:56:16 -07001083 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 return E1000_SUCCESS;
1085
Auke Kok8fc897b2006-08-28 14:56:16 -07001086 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 case e1000_82545_rev_3:
1088 case e1000_82546_rev_3:
1089 break;
1090 default:
1091 return E1000_SUCCESS;
1092 }
1093
1094 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1095 if (ret_val) {
1096 return ret_val;
1097 }
1098
Auke Kok8fc897b2006-08-28 14:56:16 -07001099 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001101 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001103 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 return ret_val;
1105 }
1106
1107 return E1000_SUCCESS;
1108}
1109
1110/******************************************************************************
1111 * Configures flow control and link settings.
1112 *
1113 * hw - Struct containing variables accessed by shared code
1114 *
1115 * Determines which flow control settings to use. Calls the apropriate media-
1116 * specific link configuration function. Configures the flow control settings.
1117 * Assuming the adapter has a valid link partner, a valid link should be
1118 * established. Assumes the hardware has previously been reset and the
1119 * transmitter and receiver are not enabled.
1120 *****************************************************************************/
1121int32_t
1122e1000_setup_link(struct e1000_hw *hw)
1123{
1124 uint32_t ctrl_ext;
1125 int32_t ret_val;
1126 uint16_t eeprom_data;
1127
1128 DEBUGFUNC("e1000_setup_link");
1129
Jeff Kirsher526f9952006-01-12 16:50:46 -08001130 /* In the case of the phy reset being blocked, we already have a link.
1131 * We do not have to set it up again. */
1132 if (e1000_check_phy_reset_block(hw))
1133 return E1000_SUCCESS;
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 /* Read and store word 0x0F of the EEPROM. This word contains bits
1136 * that determine the hardware's default PAUSE (flow control) mode,
1137 * a bit that determines whether the HW defaults to enabling or
1138 * disabling auto-negotiation, and the direction of the
1139 * SW defined pins. If there is no SW over-ride of the flow
1140 * control setting, then the variable hw->fc will
1141 * be initialized based on a value in the EEPROM.
1142 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001143 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001144 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001145 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001146 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001147 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001148 break;
1149 default:
1150 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1151 1, &eeprom_data);
1152 if (ret_val) {
1153 DEBUGOUT("EEPROM Read Error\n");
1154 return -E1000_ERR_EEPROM;
1155 }
1156 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001157 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001158 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1159 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001160 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001161 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001162 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001163 break;
1164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166
1167 /* We want to save off the original Flow Control configuration just
1168 * in case we get disconnected and then reconnected into a different
1169 * hub or switch with different Flow Control capabilities.
1170 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001171 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001172 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Auke Kok8fc897b2006-08-28 14:56:16 -07001174 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001175 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 hw->original_fc = hw->fc;
1178
1179 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1180
1181 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1182 * polarity value for the SW controlled pins, and setup the
1183 * Extended Device Control reg with that info.
1184 * This is needed because one of the SW controlled pins is used for
1185 * signal detection. So this should be done before e1000_setup_pcs_link()
1186 * or e1000_phy_setup() is called.
1187 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001188 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001189 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1190 1, &eeprom_data);
1191 if (ret_val) {
1192 DEBUGOUT("EEPROM Read Error\n");
1193 return -E1000_ERR_EEPROM;
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1196 SWDPIO__EXT_SHIFT);
1197 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1198 }
1199
1200 /* Call the necessary subroutine to configure the link. */
1201 ret_val = (hw->media_type == e1000_media_type_copper) ?
1202 e1000_setup_copper_link(hw) :
1203 e1000_setup_fiber_serdes_link(hw);
1204
1205 /* Initialize the flow control address, type, and PAUSE timer
1206 * registers to their default values. This is done even if flow
1207 * control is disabled, because it does not hurt anything to
1208 * initialize these registers.
1209 */
1210 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1211
Auke Kokcd94dd02006-06-27 09:08:22 -07001212 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1213 if (hw->mac_type != e1000_ich8lan) {
1214 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1215 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1216 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1217 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1220
1221 /* Set the flow control receive threshold registers. Normally,
1222 * these registers will be set to a default threshold that may be
1223 * adjusted later by the driver's runtime code. However, if the
1224 * ability to transmit pause frames in not enabled, then these
1225 * registers will be set to 0.
1226 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001227 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 E1000_WRITE_REG(hw, FCRTL, 0);
1229 E1000_WRITE_REG(hw, FCRTH, 0);
1230 } else {
1231 /* We need to set up the Receive Threshold high and low water marks
1232 * as well as (optionally) enabling the transmission of XON frames.
1233 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001234 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1236 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1237 } else {
1238 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1239 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1240 }
1241 }
1242 return ret_val;
1243}
1244
1245/******************************************************************************
1246 * Sets up link for a fiber based or serdes based adapter
1247 *
1248 * hw - Struct containing variables accessed by shared code
1249 *
1250 * Manipulates Physical Coding Sublayer functions in order to configure
1251 * link. Assumes the hardware has been previously reset and the transmitter
1252 * and receiver are not enabled.
1253 *****************************************************************************/
1254static int32_t
1255e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1256{
1257 uint32_t ctrl;
1258 uint32_t status;
1259 uint32_t txcw = 0;
1260 uint32_t i;
1261 uint32_t signal = 0;
1262 int32_t ret_val;
1263
1264 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1265
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001266 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1267 * until explicitly turned off or a power cycle is performed. A read to
1268 * the register does not indicate its status. Therefore, we ensure
1269 * loopback mode is disabled during initialization.
1270 */
1271 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1272 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1273
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001274 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 * set when the optics detect a signal. On older adapters, it will be
1276 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001277 * If we're on serdes media, adjust the output amplitude to value
1278 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 */
1280 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001281 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1283
1284 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001285 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 return ret_val;
1287
1288 /* Take the link out of reset */
1289 ctrl &= ~(E1000_CTRL_LRST);
1290
1291 /* Adjust VCO speed to improve BER performance */
1292 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001293 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 return ret_val;
1295
1296 e1000_config_collision_dist(hw);
1297
1298 /* Check for a software override of the flow control settings, and setup
1299 * the device accordingly. If auto-negotiation is enabled, then software
1300 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1301 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1302 * auto-negotiation is disabled, then software will have to manually
1303 * configure the two flow control enable bits in the CTRL register.
1304 *
1305 * The possible values of the "fc" parameter are:
1306 * 0: Flow control is completely disabled
1307 * 1: Rx flow control is enabled (we can receive pause frames, but
1308 * not send pause frames).
1309 * 2: Tx flow control is enabled (we can send pause frames but we do
1310 * not support receiving pause frames).
1311 * 3: Both Rx and TX flow control (symmetric) are enabled.
1312 */
1313 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001314 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /* Flow control is completely disabled by a software over-ride. */
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1317 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001318 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 /* RX Flow control is enabled and TX Flow control is disabled by a
1320 * software over-ride. Since there really isn't a way to advertise
1321 * that we are capable of RX Pause ONLY, we will advertise that we
1322 * support both symmetric and asymmetric RX PAUSE. Later, we will
1323 * disable the adapter's ability to send PAUSE frames.
1324 */
1325 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1326 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001327 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1329 * software over-ride.
1330 */
1331 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1332 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001333 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1335 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1336 break;
1337 default:
1338 DEBUGOUT("Flow control param set incorrectly\n");
1339 return -E1000_ERR_CONFIG;
1340 break;
1341 }
1342
1343 /* Since auto-negotiation is enabled, take the link out of reset (the link
1344 * will be in reset, because we previously reset the chip). This will
1345 * restart auto-negotiation. If auto-neogtiation is successful then the
1346 * link-up status bit will be set and the flow control enable bits (RFCE
1347 * and TFCE) will be set according to their negotiated value.
1348 */
1349 DEBUGOUT("Auto-negotiation enabled\n");
1350
1351 E1000_WRITE_REG(hw, TXCW, txcw);
1352 E1000_WRITE_REG(hw, CTRL, ctrl);
1353 E1000_WRITE_FLUSH(hw);
1354
1355 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001356 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1359 * indication in the Device Status Register. Time-out if a link isn't
1360 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1361 * less than 500 milliseconds even if the other end is doing it in SW).
1362 * For internal serdes, we just assume a signal is present, then poll.
1363 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001364 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1366 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001367 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001368 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001370 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001372 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1374 hw->autoneg_failed = 1;
1375 /* AutoNeg failed to achieve a link, so we'll call
1376 * e1000_check_for_link. This routine will force the link up if
1377 * we detect a signal. This will allow us to communicate with
1378 * non-autonegotiating link partners.
1379 */
1380 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001381 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 DEBUGOUT("Error while checking for link\n");
1383 return ret_val;
1384 }
1385 hw->autoneg_failed = 0;
1386 } else {
1387 hw->autoneg_failed = 0;
1388 DEBUGOUT("Valid Link Found\n");
1389 }
1390 } else {
1391 DEBUGOUT("No Signal Detected\n");
1392 }
1393 return E1000_SUCCESS;
1394}
1395
1396/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001397* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398*
1399* hw - Struct containing variables accessed by shared code
1400******************************************************************************/
1401static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001402e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
1404 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 uint16_t phy_data;
1407
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001408 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 ctrl = E1000_READ_REG(hw, CTRL);
1411 /* With 82543, we need to force speed and duplex on the MAC equal to what
1412 * the PHY speed and duplex configuration is. In addition, we need to
1413 * perform a hardware reset on the PHY to take it out of reset.
1414 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001415 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 ctrl |= E1000_CTRL_SLU;
1417 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1418 E1000_WRITE_REG(hw, CTRL, ctrl);
1419 } else {
1420 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1421 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001422 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001423 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001424 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
1426
1427 /* Make sure we have a valid PHY */
1428 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001429 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 DEBUGOUT("Error, did not detect valid phy.\n");
1431 return ret_val;
1432 }
1433 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1434
1435 /* Set PHY to class A mode (if necessary) */
1436 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001437 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 return ret_val;
1439
Auke Kok8fc897b2006-08-28 14:56:16 -07001440 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 (hw->mac_type == e1000_82546_rev_3)) {
1442 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1443 phy_data |= 0x00000008;
1444 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1445 }
1446
Auke Kok8fc897b2006-08-28 14:56:16 -07001447 if (hw->mac_type <= e1000_82543 ||
1448 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1449 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 hw->phy_reset_disable = FALSE;
1451
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001452 return E1000_SUCCESS;
1453}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001456/********************************************************************
1457* Copper link setup for e1000_phy_igp series.
1458*
1459* hw - Struct containing variables accessed by shared code
1460*********************************************************************/
1461static int32_t
1462e1000_copper_link_igp_setup(struct e1000_hw *hw)
1463{
1464 uint32_t led_ctrl;
1465 int32_t ret_val;
1466 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001468 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001470 if (hw->phy_reset_disable)
1471 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001472
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001473 ret_val = e1000_phy_reset(hw);
1474 if (ret_val) {
1475 DEBUGOUT("Error Resetting the PHY\n");
1476 return ret_val;
1477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Auke Kok8fc897b2006-08-28 14:56:16 -07001479 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001480 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001481 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001482 /* Configure activity LED after PHY reset */
1483 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1484 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1485 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1486 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001487 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001488
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001489 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1490 if (hw->phy_type == e1000_phy_igp) {
1491 /* disable lplu d3 during driver init */
1492 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1493 if (ret_val) {
1494 DEBUGOUT("Error Disabling LPLU D3\n");
1495 return ret_val;
1496 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001497 }
1498
1499 /* disable lplu d0 during driver init */
1500 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1501 if (ret_val) {
1502 DEBUGOUT("Error Disabling LPLU D0\n");
1503 return ret_val;
1504 }
1505 /* Configure mdi-mdix settings */
1506 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1507 if (ret_val)
1508 return ret_val;
1509
1510 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1511 hw->dsp_config_state = e1000_dsp_config_disabled;
1512 /* Force MDI for earlier revs of the IGP PHY */
1513 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1514 hw->mdix = 1;
1515
1516 } else {
1517 hw->dsp_config_state = e1000_dsp_config_enabled;
1518 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1519
1520 switch (hw->mdix) {
1521 case 1:
1522 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1523 break;
1524 case 2:
1525 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1526 break;
1527 case 0:
1528 default:
1529 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1530 break;
1531 }
1532 }
1533 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001534 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001535 return ret_val;
1536
1537 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001538 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001539 e1000_ms_type phy_ms_setting = hw->master_slave;
1540
Auke Kok8fc897b2006-08-28 14:56:16 -07001541 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001542 hw->ffe_config_state = e1000_ffe_config_enabled;
1543
Auke Kok8fc897b2006-08-28 14:56:16 -07001544 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001545 hw->dsp_config_state = e1000_dsp_config_enabled;
1546
1547 /* when autonegotiation advertisment is only 1000Mbps then we
1548 * should disable SmartSpeed and enable Auto MasterSlave
1549 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001550 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001551 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001552 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1553 &phy_data);
1554 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001556 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001557 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1558 phy_data);
1559 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001561 /* Set auto Master/Slave resolution process */
1562 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001563 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001564 return ret_val;
1565 phy_data &= ~CR_1000T_MS_ENABLE;
1566 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001567 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001568 return ret_val;
1569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001571 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001572 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001573 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001575 /* load defaults for future use */
1576 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1577 ((phy_data & CR_1000T_MS_VALUE) ?
1578 e1000_ms_force_master :
1579 e1000_ms_force_slave) :
1580 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001582 switch (phy_ms_setting) {
1583 case e1000_ms_force_master:
1584 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1585 break;
1586 case e1000_ms_force_slave:
1587 phy_data |= CR_1000T_MS_ENABLE;
1588 phy_data &= ~(CR_1000T_MS_VALUE);
1589 break;
1590 case e1000_ms_auto:
1591 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001593 break;
1594 }
1595 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001596 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001597 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Malli Chilakala2b028932005-06-17 17:46:06 -07001600 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001601}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001603/********************************************************************
1604* Copper link setup for e1000_phy_gg82563 series.
1605*
1606* hw - Struct containing variables accessed by shared code
1607*********************************************************************/
1608static int32_t
1609e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1610{
1611 int32_t ret_val;
1612 uint16_t phy_data;
1613 uint32_t reg_data;
1614
1615 DEBUGFUNC("e1000_copper_link_ggp_setup");
1616
Auke Kok8fc897b2006-08-28 14:56:16 -07001617 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001618
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001619 /* Enable CRS on TX for half-duplex operation. */
1620 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1621 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001622 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001623 return ret_val;
1624
1625 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1626 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1627 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1628
1629 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1630 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001631 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001632 return ret_val;
1633
1634 /* Options:
1635 * MDI/MDI-X = 0 (default)
1636 * 0 - Auto for all speeds
1637 * 1 - MDI mode
1638 * 2 - MDI-X mode
1639 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1640 */
1641 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001642 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001643 return ret_val;
1644
1645 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1646
1647 switch (hw->mdix) {
1648 case 1:
1649 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1650 break;
1651 case 2:
1652 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1653 break;
1654 case 0:
1655 default:
1656 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1657 break;
1658 }
1659
1660 /* Options:
1661 * disable_polarity_correction = 0 (default)
1662 * Automatic Correction for Reversed Cable Polarity
1663 * 0 - Disabled
1664 * 1 - Enabled
1665 */
1666 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001667 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001668 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1669 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1670
Auke Kok8fc897b2006-08-28 14:56:16 -07001671 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001672 return ret_val;
1673
1674 /* SW Reset the PHY so all changes take effect */
1675 ret_val = e1000_phy_reset(hw);
1676 if (ret_val) {
1677 DEBUGOUT("Error Resetting the PHY\n");
1678 return ret_val;
1679 }
1680 } /* phy_reset_disable */
1681
1682 if (hw->mac_type == e1000_80003es2lan) {
1683 /* Bypass RX and TX FIFO's */
1684 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1685 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1686 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1687 if (ret_val)
1688 return ret_val;
1689
1690 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1691 if (ret_val)
1692 return ret_val;
1693
1694 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1695 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1696
1697 if (ret_val)
1698 return ret_val;
1699
1700 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1701 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1702 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1703
1704 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1705 &phy_data);
1706 if (ret_val)
1707 return ret_val;
1708
1709 /* Do not init these registers when the HW is in IAMT mode, since the
1710 * firmware will have already initialized them. We only initialize
1711 * them if the HW is not in IAMT mode.
1712 */
1713 if (e1000_check_mng_mode(hw) == FALSE) {
1714 /* Enable Electrical Idle on the PHY */
1715 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1716 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1717 phy_data);
1718 if (ret_val)
1719 return ret_val;
1720
1721 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1722 &phy_data);
1723 if (ret_val)
1724 return ret_val;
1725
Auke Kokcd94dd02006-06-27 09:08:22 -07001726 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001727 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1728 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001729
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001730 if (ret_val)
1731 return ret_val;
1732 }
1733
1734 /* Workaround: Disable padding in Kumeran interface in the MAC
1735 * and in the PHY to avoid CRC errors.
1736 */
1737 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1738 &phy_data);
1739 if (ret_val)
1740 return ret_val;
1741 phy_data |= GG82563_ICR_DIS_PADDING;
1742 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1743 phy_data);
1744 if (ret_val)
1745 return ret_val;
1746 }
1747
1748 return E1000_SUCCESS;
1749}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001751/********************************************************************
1752* Copper link setup for e1000_phy_m88 series.
1753*
1754* hw - Struct containing variables accessed by shared code
1755*********************************************************************/
1756static int32_t
1757e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1758{
1759 int32_t ret_val;
1760 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001762 DEBUGFUNC("e1000_copper_link_mgp_setup");
1763
Auke Kok8fc897b2006-08-28 14:56:16 -07001764 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001765 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001766
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001767 /* Enable CRS on TX. This must be set for half-duplex operation. */
1768 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001769 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001770 return ret_val;
1771
1772 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1773
1774 /* Options:
1775 * MDI/MDI-X = 0 (default)
1776 * 0 - Auto for all speeds
1777 * 1 - MDI mode
1778 * 2 - MDI-X mode
1779 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1780 */
1781 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1782
1783 switch (hw->mdix) {
1784 case 1:
1785 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1786 break;
1787 case 2:
1788 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1789 break;
1790 case 3:
1791 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1792 break;
1793 case 0:
1794 default:
1795 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1796 break;
1797 }
1798
1799 /* Options:
1800 * disable_polarity_correction = 0 (default)
1801 * Automatic Correction for Reversed Cable Polarity
1802 * 0 - Disabled
1803 * 1 - Enabled
1804 */
1805 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001806 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001807 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001808 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1809 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001810 return ret_val;
1811
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001812 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001813 /* Force TX_CLK in the Extended PHY Specific Control Register
1814 * to 25MHz clock.
1815 */
1816 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1817 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001818 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001819
1820 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1821
1822 if ((hw->phy_revision == E1000_REVISION_2) &&
1823 (hw->phy_id == M88E1111_I_PHY_ID)) {
1824 /* Vidalia Phy, set the downshift counter to 5x */
1825 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1826 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1827 ret_val = e1000_write_phy_reg(hw,
1828 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1829 if (ret_val)
1830 return ret_val;
1831 } else {
1832 /* Configure Master and Slave downshift values */
1833 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1834 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1835 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1836 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1837 ret_val = e1000_write_phy_reg(hw,
1838 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1839 if (ret_val)
1840 return ret_val;
1841 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001844 /* SW Reset the PHY so all changes take effect */
1845 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001846 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001847 DEBUGOUT("Error Resetting the PHY\n");
1848 return ret_val;
1849 }
1850
1851 return E1000_SUCCESS;
1852}
1853
1854/********************************************************************
1855* Setup auto-negotiation and flow control advertisements,
1856* and then perform auto-negotiation.
1857*
1858* hw - Struct containing variables accessed by shared code
1859*********************************************************************/
1860static int32_t
1861e1000_copper_link_autoneg(struct e1000_hw *hw)
1862{
1863 int32_t ret_val;
1864 uint16_t phy_data;
1865
1866 DEBUGFUNC("e1000_copper_link_autoneg");
1867
1868 /* Perform some bounds checking on the hw->autoneg_advertised
1869 * parameter. If this variable is zero, then set it to the default.
1870 */
1871 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1872
1873 /* If autoneg_advertised is zero, we assume it was not defaulted
1874 * by the calling code so we set to advertise full capability.
1875 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001876 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001877 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1878
Auke Kokcd94dd02006-06-27 09:08:22 -07001879 /* IFE phy only supports 10/100 */
1880 if (hw->phy_type == e1000_phy_ife)
1881 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1882
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001883 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1884 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001885 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001886 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1887 return ret_val;
1888 }
1889 DEBUGOUT("Restarting Auto-Neg\n");
1890
1891 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1892 * the Auto Neg Restart bit in the PHY control register.
1893 */
1894 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001895 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001896 return ret_val;
1897
1898 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1899 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001900 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001901 return ret_val;
1902
1903 /* Does the user want to wait for Auto-Neg to complete here, or
1904 * check at a later time (for example, callback routine).
1905 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001906 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001907 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001908 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001909 DEBUGOUT("Error while waiting for autoneg to complete\n");
1910 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001914 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001916 return E1000_SUCCESS;
1917}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001919/******************************************************************************
1920* Config the MAC and the PHY after link is up.
1921* 1) Set up the MAC to the current PHY speed/duplex
1922* if we are on 82543. If we
1923* are on newer silicon, we only need to configure
1924* collision distance in the Transmit Control Register.
1925* 2) Set up flow control on the MAC to that established with
1926* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001927* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001928*
1929* hw - Struct containing variables accessed by shared code
1930******************************************************************************/
1931static int32_t
1932e1000_copper_link_postconfig(struct e1000_hw *hw)
1933{
1934 int32_t ret_val;
1935 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001936
Auke Kok8fc897b2006-08-28 14:56:16 -07001937 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001938 e1000_config_collision_dist(hw);
1939 } else {
1940 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001941 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001942 DEBUGOUT("Error configuring MAC to PHY settings\n");
1943 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001945 }
1946 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001947 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001948 DEBUGOUT("Error Configuring Flow Control\n");
1949 return ret_val;
1950 }
1951
1952 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001953 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001954 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001955 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001956 DEBUGOUT("Error Configuring DSP after link up\n");
1957 return ret_val;
1958 }
1959 }
Auke Kok76c224b2006-05-23 13:36:06 -07001960
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001961 return E1000_SUCCESS;
1962}
1963
1964/******************************************************************************
1965* Detects which PHY is present and setup the speed and duplex
1966*
1967* hw - Struct containing variables accessed by shared code
1968******************************************************************************/
1969static int32_t
1970e1000_setup_copper_link(struct e1000_hw *hw)
1971{
1972 int32_t ret_val;
1973 uint16_t i;
1974 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001975 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001976
1977 DEBUGFUNC("e1000_setup_copper_link");
1978
Auke Kokcd94dd02006-06-27 09:08:22 -07001979 switch (hw->mac_type) {
1980 case e1000_80003es2lan:
1981 case e1000_ich8lan:
1982 /* Set the mac to wait the maximum time between each
1983 * iteration and increase the max iterations when
1984 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1985 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1986 if (ret_val)
1987 return ret_val;
1988 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1989 if (ret_val)
1990 return ret_val;
1991 reg_data |= 0x3F;
1992 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1993 if (ret_val)
1994 return ret_val;
1995 default:
1996 break;
1997 }
1998
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001999 /* Check if it is a valid PHY and set PHY mode if necessary. */
2000 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002001 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002002 return ret_val;
2003
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002004 switch (hw->mac_type) {
2005 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07002006 /* Kumeran registers are written-only */
2007 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002008 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2009 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2010 reg_data);
2011 if (ret_val)
2012 return ret_val;
2013 break;
2014 default:
2015 break;
2016 }
2017
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002018 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07002019 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002020 hw->phy_type == e1000_phy_igp_2) {
2021 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002022 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002023 return ret_val;
2024 } else if (hw->phy_type == e1000_phy_m88) {
2025 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002026 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002027 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002028 } else if (hw->phy_type == e1000_phy_gg82563) {
2029 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002030 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002031 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002032 }
2033
Auke Kok8fc897b2006-08-28 14:56:16 -07002034 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002035 /* Setup autoneg and flow control advertisement
2036 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002037 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002038 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002039 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002040 } else {
2041 /* PHY will be set to 10H, 10F, 100H,or 100F
2042 * depending on value from forced_speed_duplex. */
2043 DEBUGOUT("Forcing speed and duplex\n");
2044 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002045 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002046 DEBUGOUT("Error Forcing Speed and Duplex\n");
2047 return ret_val;
2048 }
2049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 /* Check link status. Wait up to 100 microseconds for link to become
2052 * valid.
2053 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002054 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002056 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 return ret_val;
2058 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002059 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 return ret_val;
2061
Auke Kok8fc897b2006-08-28 14:56:16 -07002062 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002063 /* Config the MAC and PHY after link is up */
2064 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002065 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 DEBUGOUT("Valid link established!!!\n");
2069 return E1000_SUCCESS;
2070 }
2071 udelay(10);
2072 }
2073
2074 DEBUGOUT("Unable to establish link!!!\n");
2075 return E1000_SUCCESS;
2076}
2077
2078/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002079* Configure the MAC-to-PHY interface for 10/100Mbps
2080*
2081* hw - Struct containing variables accessed by shared code
2082******************************************************************************/
2083static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002084e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002085{
2086 int32_t ret_val = E1000_SUCCESS;
2087 uint32_t tipg;
2088 uint16_t reg_data;
2089
2090 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2091
2092 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2093 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2094 reg_data);
2095 if (ret_val)
2096 return ret_val;
2097
2098 /* Configure Transmit Inter-Packet Gap */
2099 tipg = E1000_READ_REG(hw, TIPG);
2100 tipg &= ~E1000_TIPG_IPGT_MASK;
2101 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2102 E1000_WRITE_REG(hw, TIPG, tipg);
2103
Auke Kokcd94dd02006-06-27 09:08:22 -07002104 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2105
2106 if (ret_val)
2107 return ret_val;
2108
2109 if (duplex == HALF_DUPLEX)
2110 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2111 else
2112 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2113
2114 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2115
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002116 return ret_val;
2117}
2118
2119static int32_t
2120e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2121{
2122 int32_t ret_val = E1000_SUCCESS;
2123 uint16_t reg_data;
2124 uint32_t tipg;
2125
2126 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2127
2128 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2129 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2130 reg_data);
2131 if (ret_val)
2132 return ret_val;
2133
2134 /* Configure Transmit Inter-Packet Gap */
2135 tipg = E1000_READ_REG(hw, TIPG);
2136 tipg &= ~E1000_TIPG_IPGT_MASK;
2137 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2138 E1000_WRITE_REG(hw, TIPG, tipg);
2139
Auke Kokcd94dd02006-06-27 09:08:22 -07002140 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2141
2142 if (ret_val)
2143 return ret_val;
2144
2145 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2146 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2147
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002148 return ret_val;
2149}
2150
2151/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152* Configures PHY autoneg and flow control advertisement settings
2153*
2154* hw - Struct containing variables accessed by shared code
2155******************************************************************************/
2156int32_t
2157e1000_phy_setup_autoneg(struct e1000_hw *hw)
2158{
2159 int32_t ret_val;
2160 uint16_t mii_autoneg_adv_reg;
2161 uint16_t mii_1000t_ctrl_reg;
2162
2163 DEBUGFUNC("e1000_phy_setup_autoneg");
2164
2165 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2166 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002167 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 return ret_val;
2169
Auke Kokcd94dd02006-06-27 09:08:22 -07002170 if (hw->phy_type != e1000_phy_ife) {
2171 /* Read the MII 1000Base-T Control Register (Address 9). */
2172 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2173 if (ret_val)
2174 return ret_val;
2175 } else
2176 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178 /* Need to parse both autoneg_advertised and fc and set up
2179 * the appropriate PHY registers. First we will parse for
2180 * autoneg_advertised software override. Since we can advertise
2181 * a plethora of combinations, we need to check each bit
2182 * individually.
2183 */
2184
2185 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2186 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2187 * the 1000Base-T Control Register (Address 9).
2188 */
2189 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2190 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2191
2192 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2193
2194 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002195 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 DEBUGOUT("Advertise 10mb Half duplex\n");
2197 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2198 }
2199
2200 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002201 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 DEBUGOUT("Advertise 10mb Full duplex\n");
2203 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2204 }
2205
2206 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002207 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 DEBUGOUT("Advertise 100mb Half duplex\n");
2209 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2210 }
2211
2212 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002213 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 DEBUGOUT("Advertise 100mb Full duplex\n");
2215 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2216 }
2217
2218 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002219 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2221 }
2222
2223 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002224 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 DEBUGOUT("Advertise 1000mb Full duplex\n");
2226 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002227 if (hw->phy_type == e1000_phy_ife) {
2228 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 }
2231
2232 /* Check for a software override of the flow control settings, and
2233 * setup the PHY advertisement registers accordingly. If
2234 * auto-negotiation is enabled, then software will have to set the
2235 * "PAUSE" bits to the correct value in the Auto-Negotiation
2236 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2237 *
2238 * The possible values of the "fc" parameter are:
2239 * 0: Flow control is completely disabled
2240 * 1: Rx flow control is enabled (we can receive pause frames
2241 * but not send pause frames).
2242 * 2: Tx flow control is enabled (we can send pause frames
2243 * but we do not support receiving pause frames).
2244 * 3: Both Rx and TX flow control (symmetric) are enabled.
2245 * other: No software override. The flow control configuration
2246 * in the EEPROM is used.
2247 */
2248 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002249 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 /* Flow control (RX & TX) is completely disabled by a
2251 * software over-ride.
2252 */
2253 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2254 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002255 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 /* RX Flow control is enabled, and TX Flow control is
2257 * disabled, by a software over-ride.
2258 */
2259 /* Since there really isn't a way to advertise that we are
2260 * capable of RX Pause ONLY, we will advertise that we
2261 * support both symmetric and asymmetric RX PAUSE. Later
2262 * (in e1000_config_fc_after_link_up) we will disable the
2263 *hw's ability to send PAUSE frames.
2264 */
2265 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2266 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002267 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 /* TX Flow control is enabled, and RX Flow control is
2269 * disabled, by a software over-ride.
2270 */
2271 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2272 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2273 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002274 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 /* Flow control (both RX and TX) is enabled by a software
2276 * over-ride.
2277 */
2278 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2279 break;
2280 default:
2281 DEBUGOUT("Flow control param set incorrectly\n");
2282 return -E1000_ERR_CONFIG;
2283 }
2284
2285 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002286 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 return ret_val;
2288
2289 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2290
Auke Kokcd94dd02006-06-27 09:08:22 -07002291 if (hw->phy_type != e1000_phy_ife) {
2292 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2293 if (ret_val)
2294 return ret_val;
2295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
2297 return E1000_SUCCESS;
2298}
2299
2300/******************************************************************************
2301* Force PHY speed and duplex settings to hw->forced_speed_duplex
2302*
2303* hw - Struct containing variables accessed by shared code
2304******************************************************************************/
2305static int32_t
2306e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2307{
2308 uint32_t ctrl;
2309 int32_t ret_val;
2310 uint16_t mii_ctrl_reg;
2311 uint16_t mii_status_reg;
2312 uint16_t phy_data;
2313 uint16_t i;
2314
2315 DEBUGFUNC("e1000_phy_force_speed_duplex");
2316
2317 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002318 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
2320 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2321
2322 /* Read the Device Control Register. */
2323 ctrl = E1000_READ_REG(hw, CTRL);
2324
2325 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2326 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2327 ctrl &= ~(DEVICE_SPEED_MASK);
2328
2329 /* Clear the Auto Speed Detect Enable bit. */
2330 ctrl &= ~E1000_CTRL_ASDE;
2331
2332 /* Read the MII Control Register. */
2333 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002334 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 return ret_val;
2336
2337 /* We need to disable autoneg in order to force link and duplex. */
2338
2339 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2340
2341 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002342 if (hw->forced_speed_duplex == e1000_100_full ||
2343 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 /* We want to force full duplex so we SET the full duplex bits in the
2345 * Device and MII Control Registers.
2346 */
2347 ctrl |= E1000_CTRL_FD;
2348 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2349 DEBUGOUT("Full Duplex\n");
2350 } else {
2351 /* We want to force half duplex so we CLEAR the full duplex bits in
2352 * the Device and MII Control Registers.
2353 */
2354 ctrl &= ~E1000_CTRL_FD;
2355 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2356 DEBUGOUT("Half Duplex\n");
2357 }
2358
2359 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002360 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 hw->forced_speed_duplex == e1000_100_half) {
2362 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2363 ctrl |= E1000_CTRL_SPD_100;
2364 mii_ctrl_reg |= MII_CR_SPEED_100;
2365 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2366 DEBUGOUT("Forcing 100mb ");
2367 } else {
2368 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2369 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2370 mii_ctrl_reg |= MII_CR_SPEED_10;
2371 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2372 DEBUGOUT("Forcing 10mb ");
2373 }
2374
2375 e1000_config_collision_dist(hw);
2376
2377 /* Write the configured values back to the Device Control Reg. */
2378 E1000_WRITE_REG(hw, CTRL, ctrl);
2379
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002380 if ((hw->phy_type == e1000_phy_m88) ||
2381 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002383 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 return ret_val;
2385
2386 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2387 * forced whenever speed are duplex are forced.
2388 */
2389 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2390 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002391 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 return ret_val;
2393
2394 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2395
2396 /* Need to reset the PHY or these changes will be ignored */
2397 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002398
Auke Kokcd94dd02006-06-27 09:08:22 -07002399 /* Disable MDI-X support for 10/100 */
2400 } else if (hw->phy_type == e1000_phy_ife) {
2401 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2402 if (ret_val)
2403 return ret_val;
2404
2405 phy_data &= ~IFE_PMC_AUTO_MDIX;
2406 phy_data &= ~IFE_PMC_FORCE_MDIX;
2407
2408 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2409 if (ret_val)
2410 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002411
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 } else {
2413 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2414 * forced whenever speed or duplex are forced.
2415 */
2416 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002417 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 return ret_val;
2419
2420 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2421 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2422
2423 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002424 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 return ret_val;
2426 }
2427
2428 /* Write back the modified PHY MII control register. */
2429 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002430 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 return ret_val;
2432
2433 udelay(1);
2434
2435 /* The wait_autoneg_complete flag may be a little misleading here.
2436 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2437 * But we do want to delay for a period while forcing only so we
2438 * don't generate false No Link messages. So we will wait here
2439 * only if the user has set wait_autoneg_complete to 1, which is
2440 * the default.
2441 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002442 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 /* We will wait for autoneg to complete. */
2444 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2445 mii_status_reg = 0;
2446
2447 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002448 for (i = PHY_FORCE_TIME; i > 0; i--) {
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
Auke Kok8fc897b2006-08-28 14:56:16 -07002460 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002461 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002463 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002464 ((hw->phy_type == e1000_phy_m88) ||
2465 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 /* We didn't get link. Reset the DSP and wait again for link. */
2467 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002468 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 DEBUGOUT("Error Resetting PHY DSP\n");
2470 return ret_val;
2471 }
2472 }
2473 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002474 for (i = PHY_FORCE_TIME; i > 0; i--) {
2475 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002476 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2478 * to be set.
2479 */
2480 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002481 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 return ret_val;
2483
2484 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002485 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 return ret_val;
2487 }
2488 }
2489
2490 if (hw->phy_type == e1000_phy_m88) {
2491 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2492 * Extended PHY Specific Control Register to 25MHz clock. This value
2493 * defaults back to a 2.5MHz clock when the PHY is reset.
2494 */
2495 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002496 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 return ret_val;
2498
2499 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2500 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002501 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 return ret_val;
2503
2504 /* In addition, because of the s/w reset above, we need to enable CRS on
2505 * TX. This must be set for both full and half duplex operation.
2506 */
2507 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002508 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 return ret_val;
2510
2511 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2512 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002513 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 return ret_val;
2515
Auke Kok8fc897b2006-08-28 14:56:16 -07002516 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2517 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2518 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002520 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 return ret_val;
2522 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002523 } else if (hw->phy_type == e1000_phy_gg82563) {
2524 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2525 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2526 * we're not in a forced 10/duplex configuration. */
2527 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2528 if (ret_val)
2529 return ret_val;
2530
2531 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2532 if ((hw->forced_speed_duplex == e1000_10_full) ||
2533 (hw->forced_speed_duplex == e1000_10_half))
2534 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2535 else
2536 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2537
2538 /* Also due to the reset, we need to enable CRS on Tx. */
2539 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2540
2541 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2542 if (ret_val)
2543 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 }
2545 return E1000_SUCCESS;
2546}
2547
2548/******************************************************************************
2549* Sets the collision distance in the Transmit Control register
2550*
2551* hw - Struct containing variables accessed by shared code
2552*
2553* Link should have been established previously. Reads the speed and duplex
2554* information from the Device Status register.
2555******************************************************************************/
2556void
2557e1000_config_collision_dist(struct e1000_hw *hw)
2558{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002559 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 DEBUGFUNC("e1000_config_collision_dist");
2562
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002563 if (hw->mac_type < e1000_82543)
2564 coll_dist = E1000_COLLISION_DISTANCE_82542;
2565 else
2566 coll_dist = E1000_COLLISION_DISTANCE;
2567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 tctl = E1000_READ_REG(hw, TCTL);
2569
2570 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002571 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572
2573 E1000_WRITE_REG(hw, TCTL, tctl);
2574 E1000_WRITE_FLUSH(hw);
2575}
2576
2577/******************************************************************************
2578* Sets MAC speed and duplex settings to reflect the those in the PHY
2579*
2580* hw - Struct containing variables accessed by shared code
2581* mii_reg - data to write to the MII control register
2582*
2583* The contents of the PHY register containing the needed information need to
2584* be passed in.
2585******************************************************************************/
2586static int32_t
2587e1000_config_mac_to_phy(struct e1000_hw *hw)
2588{
2589 uint32_t ctrl;
2590 int32_t ret_val;
2591 uint16_t phy_data;
2592
2593 DEBUGFUNC("e1000_config_mac_to_phy");
2594
Auke Kok76c224b2006-05-23 13:36:06 -07002595 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002596 * MAC speed/duplex configuration.*/
2597 if (hw->mac_type >= e1000_82544)
2598 return E1000_SUCCESS;
2599
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 /* Read the Device Control Register and set the bits to Force Speed
2601 * and Duplex.
2602 */
2603 ctrl = E1000_READ_REG(hw, CTRL);
2604 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2605 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2606
2607 /* Set up duplex in the Device Control and Transmit Control
2608 * registers depending on negotiated values.
2609 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002610 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002611 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002612 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Auke Kok8fc897b2006-08-28 14:56:16 -07002614 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002615 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002616 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002617 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002619 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002621 /* Set up speed in the Device Control register depending on
2622 * negotiated values.
2623 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002624 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002625 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002626 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002627 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 /* Write the configured values back to the Device Control Reg. */
2630 E1000_WRITE_REG(hw, CTRL, ctrl);
2631 return E1000_SUCCESS;
2632}
2633
2634/******************************************************************************
2635 * Forces the MAC's flow control settings.
2636 *
2637 * hw - Struct containing variables accessed by shared code
2638 *
2639 * Sets the TFCE and RFCE bits in the device control register to reflect
2640 * the adapter settings. TFCE and RFCE need to be explicitly set by
2641 * software when a Copper PHY is used because autonegotiation is managed
2642 * by the PHY rather than the MAC. Software must also configure these
2643 * bits when link is forced on a fiber connection.
2644 *****************************************************************************/
2645int32_t
2646e1000_force_mac_fc(struct e1000_hw *hw)
2647{
2648 uint32_t ctrl;
2649
2650 DEBUGFUNC("e1000_force_mac_fc");
2651
2652 /* Get the current configuration of the Device Control Register */
2653 ctrl = E1000_READ_REG(hw, CTRL);
2654
2655 /* Because we didn't get link via the internal auto-negotiation
2656 * mechanism (we either forced link or we got link via PHY
2657 * auto-neg), we have to manually enable/disable transmit an
2658 * receive flow control.
2659 *
2660 * The "Case" statement below enables/disable flow control
2661 * according to the "hw->fc" parameter.
2662 *
2663 * The possible values of the "fc" parameter are:
2664 * 0: Flow control is completely disabled
2665 * 1: Rx flow control is enabled (we can receive pause
2666 * frames but not send pause frames).
2667 * 2: Tx flow control is enabled (we can send pause frames
2668 * frames but we do not receive pause frames).
2669 * 3: Both Rx and TX flow control (symmetric) is enabled.
2670 * other: No other values should be possible at this point.
2671 */
2672
2673 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002674 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2676 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002677 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 ctrl &= (~E1000_CTRL_TFCE);
2679 ctrl |= E1000_CTRL_RFCE;
2680 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002681 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 ctrl &= (~E1000_CTRL_RFCE);
2683 ctrl |= E1000_CTRL_TFCE;
2684 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002685 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2687 break;
2688 default:
2689 DEBUGOUT("Flow control param set incorrectly\n");
2690 return -E1000_ERR_CONFIG;
2691 }
2692
2693 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002694 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 ctrl &= (~E1000_CTRL_TFCE);
2696
2697 E1000_WRITE_REG(hw, CTRL, ctrl);
2698 return E1000_SUCCESS;
2699}
2700
2701/******************************************************************************
2702 * Configures flow control settings after link is established
2703 *
2704 * hw - Struct containing variables accessed by shared code
2705 *
2706 * Should be called immediately after a valid link has been established.
2707 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2708 * and autonegotiation is enabled, the MAC flow control settings will be set
2709 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2710 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2711 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002712static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713e1000_config_fc_after_link_up(struct e1000_hw *hw)
2714{
2715 int32_t ret_val;
2716 uint16_t mii_status_reg;
2717 uint16_t mii_nway_adv_reg;
2718 uint16_t mii_nway_lp_ability_reg;
2719 uint16_t speed;
2720 uint16_t duplex;
2721
2722 DEBUGFUNC("e1000_config_fc_after_link_up");
2723
2724 /* Check for the case where we have fiber media and auto-neg failed
2725 * so we had to force link. In this case, we need to force the
2726 * configuration of the MAC to match the "fc" parameter.
2727 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002728 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2729 ((hw->media_type == e1000_media_type_internal_serdes) &&
2730 (hw->autoneg_failed)) ||
2731 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002733 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 DEBUGOUT("Error forcing flow control settings\n");
2735 return ret_val;
2736 }
2737 }
2738
2739 /* Check for the case where we have copper media and auto-neg is
2740 * enabled. In this case, we need to check and see if Auto-Neg
2741 * has completed, and if so, how the PHY and link partner has
2742 * flow control configured.
2743 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002744 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 /* Read the MII Status Register and check to see if AutoNeg
2746 * has completed. We read this twice because this reg has
2747 * some "sticky" (latched) bits.
2748 */
2749 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002750 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 return ret_val;
2752 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002753 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return ret_val;
2755
Auke Kok8fc897b2006-08-28 14:56:16 -07002756 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 /* The AutoNeg process has completed, so we now need to
2758 * read both the Auto Negotiation Advertisement Register
2759 * (Address 4) and the Auto_Negotiation Base Page Ability
2760 * Register (Address 5) to determine how flow control was
2761 * negotiated.
2762 */
2763 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2764 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002765 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 return ret_val;
2767 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2768 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002769 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 return ret_val;
2771
2772 /* Two bits in the Auto Negotiation Advertisement Register
2773 * (Address 4) and two bits in the Auto Negotiation Base
2774 * Page Ability Register (Address 5) determine flow control
2775 * for both the PHY and the link partner. The following
2776 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2777 * 1999, describes these PAUSE resolution bits and how flow
2778 * control is determined based upon these settings.
2779 * NOTE: DC = Don't Care
2780 *
2781 * LOCAL DEVICE | LINK PARTNER
2782 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2783 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002784 * 0 | 0 | DC | DC | E1000_FC_NONE
2785 * 0 | 1 | 0 | DC | E1000_FC_NONE
2786 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2787 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2788 * 1 | 0 | 0 | DC | E1000_FC_NONE
2789 * 1 | DC | 1 | DC | E1000_FC_FULL
2790 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2791 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 *
2793 */
2794 /* Are both PAUSE bits set to 1? If so, this implies
2795 * Symmetric Flow Control is enabled at both ends. The
2796 * ASM_DIR bits are irrelevant per the spec.
2797 *
2798 * For Symmetric Flow Control:
2799 *
2800 * LOCAL DEVICE | LINK PARTNER
2801 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2802 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002803 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 *
2805 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002806 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2807 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 /* Now we need to check if the user selected RX ONLY
2809 * of pause frames. In this case, we had to advertise
2810 * FULL flow control because we could not advertise RX
2811 * ONLY. Hence, we must now check to see if we need to
2812 * turn OFF the TRANSMISSION of PAUSE frames.
2813 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002814 if (hw->original_fc == E1000_FC_FULL) {
2815 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002816 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002818 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002819 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 }
2821 }
2822 /* For receiving PAUSE frames ONLY.
2823 *
2824 * LOCAL DEVICE | LINK PARTNER
2825 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2826 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002827 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 *
2829 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002830 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2831 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2832 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2833 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002834 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002835 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 }
2837 /* For transmitting PAUSE frames ONLY.
2838 *
2839 * LOCAL DEVICE | LINK PARTNER
2840 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2841 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002842 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 *
2844 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002845 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2846 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2847 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2848 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002849 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002850 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 }
2852 /* Per the IEEE spec, at this point flow control should be
2853 * disabled. However, we want to consider that we could
2854 * be connected to a legacy switch that doesn't advertise
2855 * desired flow control, but can be forced on the link
2856 * partner. So if we advertised no flow control, that is
2857 * what we will resolve to. If we advertised some kind of
2858 * receive capability (Rx Pause Only or Full Flow Control)
2859 * and the link partner advertised none, we will configure
2860 * ourselves to enable Rx Flow Control only. We can do
2861 * this safely for two reasons: If the link partner really
2862 * didn't want flow control enabled, and we enable Rx, no
2863 * harm done since we won't be receiving any PAUSE frames
2864 * anyway. If the intent on the link partner was to have
2865 * flow control enabled, then by us enabling RX only, we
2866 * can at least receive pause frames and process them.
2867 * This is a good idea because in most cases, since we are
2868 * predominantly a server NIC, more times than not we will
2869 * be asked to delay transmission of packets than asking
2870 * our link partner to pause transmission of frames.
2871 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002872 else if ((hw->original_fc == E1000_FC_NONE ||
2873 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002874 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002875 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002876 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002878 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002879 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 }
2881
2882 /* Now we need to do one last check... If we auto-
2883 * negotiated to HALF DUPLEX, flow control should not be
2884 * enabled per IEEE 802.3 spec.
2885 */
2886 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002887 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 DEBUGOUT("Error getting link speed and duplex\n");
2889 return ret_val;
2890 }
2891
Auke Kok8fc897b2006-08-28 14:56:16 -07002892 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002893 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
2895 /* Now we call a subroutine to actually force the MAC
2896 * controller to use the correct flow control settings.
2897 */
2898 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002899 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 DEBUGOUT("Error forcing flow control settings\n");
2901 return ret_val;
2902 }
2903 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002904 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 }
2906 }
2907 return E1000_SUCCESS;
2908}
2909
2910/******************************************************************************
2911 * Checks to see if the link status of the hardware has changed.
2912 *
2913 * hw - Struct containing variables accessed by shared code
2914 *
2915 * Called by any function that needs to check the link status of the adapter.
2916 *****************************************************************************/
2917int32_t
2918e1000_check_for_link(struct e1000_hw *hw)
2919{
2920 uint32_t rxcw = 0;
2921 uint32_t ctrl;
2922 uint32_t status;
2923 uint32_t rctl;
2924 uint32_t icr;
2925 uint32_t signal = 0;
2926 int32_t ret_val;
2927 uint16_t phy_data;
2928
2929 DEBUGFUNC("e1000_check_for_link");
2930
2931 ctrl = E1000_READ_REG(hw, CTRL);
2932 status = E1000_READ_REG(hw, STATUS);
2933
2934 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2935 * set when the optics detect a signal. On older adapters, it will be
2936 * cleared when there is a signal. This applies to fiber media only.
2937 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002938 if ((hw->media_type == e1000_media_type_fiber) ||
2939 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 rxcw = E1000_READ_REG(hw, RXCW);
2941
Auke Kok8fc897b2006-08-28 14:56:16 -07002942 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002944 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 hw->get_link_status = FALSE;
2946 }
2947 }
2948
2949 /* If we have a copper PHY then we only want to go out to the PHY
2950 * registers to see if Auto-Neg has completed and/or if our link
2951 * status has changed. The get_link_status flag will be set if we
2952 * receive a Link Status Change interrupt or we have Rx Sequence
2953 * Errors.
2954 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002955 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 /* First we want to see if the MII Status Register reports
2957 * link. If so, then we want to get the current speed/duplex
2958 * of the PHY.
2959 * Read the register twice since the link bit is sticky.
2960 */
2961 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002962 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 return ret_val;
2964 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002965 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 return ret_val;
2967
Auke Kok8fc897b2006-08-28 14:56:16 -07002968 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 hw->get_link_status = FALSE;
2970 /* Check if there was DownShift, must be checked immediately after
2971 * link-up */
2972 e1000_check_downshift(hw);
2973
2974 /* If we are on 82544 or 82543 silicon and speed/duplex
2975 * are forced to 10H or 10F, then we will implement the polarity
2976 * reversal workaround. We disable interrupts first, and upon
2977 * returning, place the devices interrupt state to its previous
2978 * value except for the link status change interrupt which will
2979 * happen due to the execution of this workaround.
2980 */
2981
Auke Kok8fc897b2006-08-28 14:56:16 -07002982 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2983 (!hw->autoneg) &&
2984 (hw->forced_speed_duplex == e1000_10_full ||
2985 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2987 ret_val = e1000_polarity_reversal_workaround(hw);
2988 icr = E1000_READ_REG(hw, ICR);
2989 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2990 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2991 }
2992
2993 } else {
2994 /* No link detected */
2995 e1000_config_dsp_after_link_change(hw, FALSE);
2996 return 0;
2997 }
2998
2999 /* If we are forcing speed/duplex, then we simply return since
3000 * we have already determined whether we have link or not.
3001 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003002 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
3004 /* optimize the dsp settings for the igp phy */
3005 e1000_config_dsp_after_link_change(hw, TRUE);
3006
3007 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3008 * have Si on board that is 82544 or newer, Auto
3009 * Speed Detection takes care of MAC speed/duplex
3010 * configuration. So we only need to configure Collision
3011 * Distance in the MAC. Otherwise, we need to force
3012 * speed/duplex on the MAC to the current PHY speed/duplex
3013 * settings.
3014 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003015 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 e1000_config_collision_dist(hw);
3017 else {
3018 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003019 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 DEBUGOUT("Error configuring MAC to PHY settings\n");
3021 return ret_val;
3022 }
3023 }
3024
3025 /* Configure Flow Control now that Auto-Neg has completed. First, we
3026 * need to restore the desired flow control settings because we may
3027 * have had to re-autoneg with a different link partner.
3028 */
3029 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003030 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 DEBUGOUT("Error configuring flow control\n");
3032 return ret_val;
3033 }
3034
3035 /* At this point we know that we are on copper and we have
3036 * auto-negotiated link. These are conditions for checking the link
3037 * partner capability register. We use the link speed to determine if
3038 * TBI compatibility needs to be turned on or off. If the link is not
3039 * at gigabit speed, then TBI compatibility is not needed. If we are
3040 * at gigabit speed, we turn on TBI compatibility.
3041 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003042 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003044 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3045 if (ret_val) {
3046 DEBUGOUT("Error getting link speed and duplex\n");
3047 return ret_val;
3048 }
3049 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 /* If link speed is not set to gigabit speed, we do not need
3051 * to enable TBI compatibility.
3052 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003053 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 /* If we previously were in the mode, turn it off. */
3055 rctl = E1000_READ_REG(hw, RCTL);
3056 rctl &= ~E1000_RCTL_SBP;
3057 E1000_WRITE_REG(hw, RCTL, rctl);
3058 hw->tbi_compatibility_on = FALSE;
3059 }
3060 } else {
3061 /* If TBI compatibility is was previously off, turn it on. For
3062 * compatibility with a TBI link partner, we will store bad
3063 * packets. Some frames have an additional byte on the end and
3064 * will look like CRC errors to to the hardware.
3065 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003066 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 hw->tbi_compatibility_on = TRUE;
3068 rctl = E1000_READ_REG(hw, RCTL);
3069 rctl |= E1000_RCTL_SBP;
3070 E1000_WRITE_REG(hw, RCTL, rctl);
3071 }
3072 }
3073 }
3074 }
3075 /* If we don't have link (auto-negotiation failed or link partner cannot
3076 * auto-negotiate), the cable is plugged in (we have signal), and our
3077 * link partner is not trying to auto-negotiate with us (we are receiving
3078 * idles or data), we need to force link up. We also need to give
3079 * auto-negotiation time to complete, in case the cable was just plugged
3080 * in. The autoneg_failed flag does this.
3081 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003082 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003084 (hw->media_type == e1000_media_type_internal_serdes)) &&
3085 (!(status & E1000_STATUS_LU)) &&
3086 (!(rxcw & E1000_RXCW_C))) {
3087 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 hw->autoneg_failed = 1;
3089 return 0;
3090 }
Auke Koka42a5072006-05-23 13:36:01 -07003091 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092
3093 /* Disable auto-negotiation in the TXCW register */
3094 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3095
3096 /* Force link-up and also force full-duplex. */
3097 ctrl = E1000_READ_REG(hw, CTRL);
3098 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3099 E1000_WRITE_REG(hw, CTRL, ctrl);
3100
3101 /* Configure Flow Control after forcing link up. */
3102 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003103 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 DEBUGOUT("Error configuring flow control\n");
3105 return ret_val;
3106 }
3107 }
3108 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3109 * auto-negotiation in the TXCW register and disable forced link in the
3110 * Device Control register in an attempt to auto-negotiate with our link
3111 * partner.
3112 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003113 else if (((hw->media_type == e1000_media_type_fiber) ||
3114 (hw->media_type == e1000_media_type_internal_serdes)) &&
3115 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003116 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3118 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3119
3120 hw->serdes_link_down = FALSE;
3121 }
3122 /* If we force link for non-auto-negotiation switch, check link status
3123 * based on MAC synchronization for internal serdes media type.
3124 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003125 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3126 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 /* SYNCH bit and IV bit are sticky. */
3128 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003129 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3130 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 hw->serdes_link_down = FALSE;
3132 DEBUGOUT("SERDES: Link is up.\n");
3133 }
3134 } else {
3135 hw->serdes_link_down = TRUE;
3136 DEBUGOUT("SERDES: Link is down.\n");
3137 }
3138 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003139 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3140 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3142 }
3143 return E1000_SUCCESS;
3144}
3145
3146/******************************************************************************
3147 * Detects the current speed and duplex settings of the hardware.
3148 *
3149 * hw - Struct containing variables accessed by shared code
3150 * speed - Speed of the connection
3151 * duplex - Duplex setting of the connection
3152 *****************************************************************************/
3153int32_t
3154e1000_get_speed_and_duplex(struct e1000_hw *hw,
3155 uint16_t *speed,
3156 uint16_t *duplex)
3157{
3158 uint32_t status;
3159 int32_t ret_val;
3160 uint16_t phy_data;
3161
3162 DEBUGFUNC("e1000_get_speed_and_duplex");
3163
Auke Kok8fc897b2006-08-28 14:56:16 -07003164 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003166 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 *speed = SPEED_1000;
3168 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003169 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 *speed = SPEED_100;
3171 DEBUGOUT("100 Mbs, ");
3172 } else {
3173 *speed = SPEED_10;
3174 DEBUGOUT("10 Mbs, ");
3175 }
3176
Auke Kok8fc897b2006-08-28 14:56:16 -07003177 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003179 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 } else {
3181 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003182 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 }
3184 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003185 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 *speed = SPEED_1000;
3187 *duplex = FULL_DUPLEX;
3188 }
3189
3190 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3191 * if it is operating at half duplex. Here we set the duplex settings to
3192 * match the duplex in the link partner's capabilities.
3193 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003194 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003196 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 return ret_val;
3198
Auke Kok8fc897b2006-08-28 14:56:16 -07003199 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 *duplex = HALF_DUPLEX;
3201 else {
3202 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003203 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003205 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3207 *duplex = HALF_DUPLEX;
3208 }
3209 }
3210
Auke Kok76c224b2006-05-23 13:36:06 -07003211 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003212 (hw->media_type == e1000_media_type_copper)) {
3213 if (*speed == SPEED_1000)
3214 ret_val = e1000_configure_kmrn_for_1000(hw);
3215 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003216 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3217 if (ret_val)
3218 return ret_val;
3219 }
3220
3221 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3222 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003223 if (ret_val)
3224 return ret_val;
3225 }
3226
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return E1000_SUCCESS;
3228}
3229
3230/******************************************************************************
3231* Blocks until autoneg completes or times out (~4.5 seconds)
3232*
3233* hw - Struct containing variables accessed by shared code
3234******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003235static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236e1000_wait_autoneg(struct e1000_hw *hw)
3237{
3238 int32_t ret_val;
3239 uint16_t i;
3240 uint16_t phy_data;
3241
3242 DEBUGFUNC("e1000_wait_autoneg");
3243 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3244
3245 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003246 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 /* Read the MII Status Register and wait for Auto-Neg
3248 * Complete bit to be set.
3249 */
3250 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003251 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 return ret_val;
3253 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003254 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003256 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return E1000_SUCCESS;
3258 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003259 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 }
3261 return E1000_SUCCESS;
3262}
3263
3264/******************************************************************************
3265* Raises the Management Data Clock
3266*
3267* hw - Struct containing variables accessed by shared code
3268* ctrl - Device control register's current value
3269******************************************************************************/
3270static void
3271e1000_raise_mdi_clk(struct e1000_hw *hw,
3272 uint32_t *ctrl)
3273{
3274 /* Raise the clock input to the Management Data Clock (by setting the MDC
3275 * bit), and then delay 10 microseconds.
3276 */
3277 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3278 E1000_WRITE_FLUSH(hw);
3279 udelay(10);
3280}
3281
3282/******************************************************************************
3283* Lowers the Management Data Clock
3284*
3285* hw - Struct containing variables accessed by shared code
3286* ctrl - Device control register's current value
3287******************************************************************************/
3288static void
3289e1000_lower_mdi_clk(struct e1000_hw *hw,
3290 uint32_t *ctrl)
3291{
3292 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3293 * bit), and then delay 10 microseconds.
3294 */
3295 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3296 E1000_WRITE_FLUSH(hw);
3297 udelay(10);
3298}
3299
3300/******************************************************************************
3301* Shifts data bits out to the PHY
3302*
3303* hw - Struct containing variables accessed by shared code
3304* data - Data to send out to the PHY
3305* count - Number of bits to shift out
3306*
3307* Bits are shifted out in MSB to LSB order.
3308******************************************************************************/
3309static void
3310e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3311 uint32_t data,
3312 uint16_t count)
3313{
3314 uint32_t ctrl;
3315 uint32_t mask;
3316
3317 /* We need to shift "count" number of bits out to the PHY. So, the value
3318 * in the "data" parameter will be shifted out to the PHY one bit at a
3319 * time. In order to do this, "data" must be broken down into bits.
3320 */
3321 mask = 0x01;
3322 mask <<= (count - 1);
3323
3324 ctrl = E1000_READ_REG(hw, CTRL);
3325
3326 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3327 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3328
Auke Kok8fc897b2006-08-28 14:56:16 -07003329 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3331 * then raising and lowering the Management Data Clock. A "0" is
3332 * shifted out to the PHY by setting the MDIO bit to "0" and then
3333 * raising and lowering the clock.
3334 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003335 if (data & mask)
3336 ctrl |= E1000_CTRL_MDIO;
3337 else
3338 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 E1000_WRITE_REG(hw, CTRL, ctrl);
3341 E1000_WRITE_FLUSH(hw);
3342
3343 udelay(10);
3344
3345 e1000_raise_mdi_clk(hw, &ctrl);
3346 e1000_lower_mdi_clk(hw, &ctrl);
3347
3348 mask = mask >> 1;
3349 }
3350}
3351
3352/******************************************************************************
3353* Shifts data bits in from the PHY
3354*
3355* hw - Struct containing variables accessed by shared code
3356*
3357* Bits are shifted in in MSB to LSB order.
3358******************************************************************************/
3359static uint16_t
3360e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3361{
3362 uint32_t ctrl;
3363 uint16_t data = 0;
3364 uint8_t i;
3365
3366 /* In order to read a register from the PHY, we need to shift in a total
3367 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3368 * to avoid contention on the MDIO pin when a read operation is performed.
3369 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3370 * by raising the input to the Management Data Clock (setting the MDC bit),
3371 * and then reading the value of the MDIO bit.
3372 */
3373 ctrl = E1000_READ_REG(hw, CTRL);
3374
3375 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3376 ctrl &= ~E1000_CTRL_MDIO_DIR;
3377 ctrl &= ~E1000_CTRL_MDIO;
3378
3379 E1000_WRITE_REG(hw, CTRL, ctrl);
3380 E1000_WRITE_FLUSH(hw);
3381
3382 /* Raise and Lower the clock before reading in the data. This accounts for
3383 * the turnaround bits. The first clock occurred when we clocked out the
3384 * last bit of the Register Address.
3385 */
3386 e1000_raise_mdi_clk(hw, &ctrl);
3387 e1000_lower_mdi_clk(hw, &ctrl);
3388
Auke Kok8fc897b2006-08-28 14:56:16 -07003389 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 data = data << 1;
3391 e1000_raise_mdi_clk(hw, &ctrl);
3392 ctrl = E1000_READ_REG(hw, CTRL);
3393 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003394 if (ctrl & E1000_CTRL_MDIO)
3395 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 e1000_lower_mdi_clk(hw, &ctrl);
3397 }
3398
3399 e1000_raise_mdi_clk(hw, &ctrl);
3400 e1000_lower_mdi_clk(hw, &ctrl);
3401
3402 return data;
3403}
3404
Adrian Bunke4c780b2006-08-14 23:00:10 -07003405static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003406e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3407{
3408 uint32_t swfw_sync = 0;
3409 uint32_t swmask = mask;
3410 uint32_t fwmask = mask << 16;
3411 int32_t timeout = 200;
3412
3413 DEBUGFUNC("e1000_swfw_sync_acquire");
3414
Auke Kokcd94dd02006-06-27 09:08:22 -07003415 if (hw->swfwhw_semaphore_present)
3416 return e1000_get_software_flag(hw);
3417
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003418 if (!hw->swfw_sync_present)
3419 return e1000_get_hw_eeprom_semaphore(hw);
3420
Auke Kok8fc897b2006-08-28 14:56:16 -07003421 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003422 if (e1000_get_hw_eeprom_semaphore(hw))
3423 return -E1000_ERR_SWFW_SYNC;
3424
3425 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3426 if (!(swfw_sync & (fwmask | swmask))) {
3427 break;
3428 }
3429
3430 /* firmware currently using resource (fwmask) */
3431 /* or other software thread currently using resource (swmask) */
3432 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003433 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003434 timeout--;
3435 }
3436
3437 if (!timeout) {
3438 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3439 return -E1000_ERR_SWFW_SYNC;
3440 }
3441
3442 swfw_sync |= swmask;
3443 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3444
3445 e1000_put_hw_eeprom_semaphore(hw);
3446 return E1000_SUCCESS;
3447}
3448
Adrian Bunke4c780b2006-08-14 23:00:10 -07003449static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003450e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3451{
3452 uint32_t swfw_sync;
3453 uint32_t swmask = mask;
3454
3455 DEBUGFUNC("e1000_swfw_sync_release");
3456
Auke Kokcd94dd02006-06-27 09:08:22 -07003457 if (hw->swfwhw_semaphore_present) {
3458 e1000_release_software_flag(hw);
3459 return;
3460 }
3461
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003462 if (!hw->swfw_sync_present) {
3463 e1000_put_hw_eeprom_semaphore(hw);
3464 return;
3465 }
3466
3467 /* if (e1000_get_hw_eeprom_semaphore(hw))
3468 * return -E1000_ERR_SWFW_SYNC; */
3469 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3470 /* empty */
3471
3472 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3473 swfw_sync &= ~swmask;
3474 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3475
3476 e1000_put_hw_eeprom_semaphore(hw);
3477}
3478
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479/*****************************************************************************
3480* Reads the value from a PHY register, if the value is on a specific non zero
3481* page, sets the page first.
3482* hw - Struct containing variables accessed by shared code
3483* reg_addr - address of the PHY register to read
3484******************************************************************************/
3485int32_t
3486e1000_read_phy_reg(struct e1000_hw *hw,
3487 uint32_t reg_addr,
3488 uint16_t *phy_data)
3489{
3490 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003491 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
3493 DEBUGFUNC("e1000_read_phy_reg");
3494
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003495 if ((hw->mac_type == e1000_80003es2lan) &&
3496 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3497 swfw = E1000_SWFW_PHY1_SM;
3498 } else {
3499 swfw = E1000_SWFW_PHY0_SM;
3500 }
3501 if (e1000_swfw_sync_acquire(hw, swfw))
3502 return -E1000_ERR_SWFW_SYNC;
3503
Auke Kokcd94dd02006-06-27 09:08:22 -07003504 if ((hw->phy_type == e1000_phy_igp ||
3505 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003506 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3508 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3509 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003510 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003511 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 return ret_val;
3513 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003514 } else if (hw->phy_type == e1000_phy_gg82563) {
3515 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3516 (hw->mac_type == e1000_80003es2lan)) {
3517 /* Select Configuration Page */
3518 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3519 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3520 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3521 } else {
3522 /* Use Alternative Page Select register to access
3523 * registers 30 and 31
3524 */
3525 ret_val = e1000_write_phy_reg_ex(hw,
3526 GG82563_PHY_PAGE_SELECT_ALT,
3527 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3528 }
3529
3530 if (ret_val) {
3531 e1000_swfw_sync_release(hw, swfw);
3532 return ret_val;
3533 }
3534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 }
3536
3537 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3538 phy_data);
3539
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003540 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 return ret_val;
3542}
3543
Nicholas Nunley35574762006-09-27 12:53:34 -07003544static int32_t
3545e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 uint16_t *phy_data)
3547{
3548 uint32_t i;
3549 uint32_t mdic = 0;
3550 const uint32_t phy_addr = 1;
3551
3552 DEBUGFUNC("e1000_read_phy_reg_ex");
3553
Auke Kok8fc897b2006-08-28 14:56:16 -07003554 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3556 return -E1000_ERR_PARAM;
3557 }
3558
Auke Kok8fc897b2006-08-28 14:56:16 -07003559 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 /* Set up Op-code, Phy Address, and register address in the MDI
3561 * Control register. The MAC will take care of interfacing with the
3562 * PHY to retrieve the desired data.
3563 */
3564 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3565 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3566 (E1000_MDIC_OP_READ));
3567
3568 E1000_WRITE_REG(hw, MDIC, mdic);
3569
3570 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003571 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 udelay(50);
3573 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003574 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003576 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 DEBUGOUT("MDI Read did not complete\n");
3578 return -E1000_ERR_PHY;
3579 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003580 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 DEBUGOUT("MDI Error\n");
3582 return -E1000_ERR_PHY;
3583 }
3584 *phy_data = (uint16_t) mdic;
3585 } else {
3586 /* We must first send a preamble through the MDIO pin to signal the
3587 * beginning of an MII instruction. This is done by sending 32
3588 * consecutive "1" bits.
3589 */
3590 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3591
3592 /* Now combine the next few fields that are required for a read
3593 * operation. We use this method instead of calling the
3594 * e1000_shift_out_mdi_bits routine five different times. The format of
3595 * a MII read instruction consists of a shift out of 14 bits and is
3596 * defined as follows:
3597 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3598 * followed by a shift in of 18 bits. This first two bits shifted in
3599 * are TurnAround bits used to avoid contention on the MDIO pin when a
3600 * READ operation is performed. These two bits are thrown away
3601 * followed by a shift in of 16 bits which contains the desired data.
3602 */
3603 mdic = ((reg_addr) | (phy_addr << 5) |
3604 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3605
3606 e1000_shift_out_mdi_bits(hw, mdic, 14);
3607
3608 /* Now that we've shifted out the read command to the MII, we need to
3609 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3610 * register address.
3611 */
3612 *phy_data = e1000_shift_in_mdi_bits(hw);
3613 }
3614 return E1000_SUCCESS;
3615}
3616
3617/******************************************************************************
3618* Writes a value to a PHY register
3619*
3620* hw - Struct containing variables accessed by shared code
3621* reg_addr - address of the PHY register to write
3622* data - data to write to the PHY
3623******************************************************************************/
3624int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003625e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 uint16_t phy_data)
3627{
3628 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003629 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
3631 DEBUGFUNC("e1000_write_phy_reg");
3632
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003633 if ((hw->mac_type == e1000_80003es2lan) &&
3634 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3635 swfw = E1000_SWFW_PHY1_SM;
3636 } else {
3637 swfw = E1000_SWFW_PHY0_SM;
3638 }
3639 if (e1000_swfw_sync_acquire(hw, swfw))
3640 return -E1000_ERR_SWFW_SYNC;
3641
Auke Kokcd94dd02006-06-27 09:08:22 -07003642 if ((hw->phy_type == e1000_phy_igp ||
3643 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003644 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3646 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3647 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003648 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003649 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 return ret_val;
3651 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003652 } else if (hw->phy_type == e1000_phy_gg82563) {
3653 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3654 (hw->mac_type == e1000_80003es2lan)) {
3655 /* Select Configuration Page */
3656 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3657 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3658 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3659 } else {
3660 /* Use Alternative Page Select register to access
3661 * registers 30 and 31
3662 */
3663 ret_val = e1000_write_phy_reg_ex(hw,
3664 GG82563_PHY_PAGE_SELECT_ALT,
3665 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3666 }
3667
3668 if (ret_val) {
3669 e1000_swfw_sync_release(hw, swfw);
3670 return ret_val;
3671 }
3672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 }
3674
3675 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3676 phy_data);
3677
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003678 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 return ret_val;
3680}
3681
Nicholas Nunley35574762006-09-27 12:53:34 -07003682static int32_t
3683e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3684 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685{
3686 uint32_t i;
3687 uint32_t mdic = 0;
3688 const uint32_t phy_addr = 1;
3689
3690 DEBUGFUNC("e1000_write_phy_reg_ex");
3691
Auke Kok8fc897b2006-08-28 14:56:16 -07003692 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3694 return -E1000_ERR_PARAM;
3695 }
3696
Auke Kok8fc897b2006-08-28 14:56:16 -07003697 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 /* Set up Op-code, Phy Address, register address, and data intended
3699 * for the PHY register in the MDI Control register. The MAC will take
3700 * care of interfacing with the PHY to send the desired data.
3701 */
3702 mdic = (((uint32_t) phy_data) |
3703 (reg_addr << E1000_MDIC_REG_SHIFT) |
3704 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3705 (E1000_MDIC_OP_WRITE));
3706
3707 E1000_WRITE_REG(hw, MDIC, mdic);
3708
3709 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003710 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 udelay(5);
3712 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003713 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003715 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 DEBUGOUT("MDI Write did not complete\n");
3717 return -E1000_ERR_PHY;
3718 }
3719 } else {
3720 /* We'll need to use the SW defined pins to shift the write command
3721 * out to the PHY. We first send a preamble to the PHY to signal the
3722 * beginning of the MII instruction. This is done by sending 32
3723 * consecutive "1" bits.
3724 */
3725 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3726
3727 /* Now combine the remaining required fields that will indicate a
3728 * write operation. We use this method instead of calling the
3729 * e1000_shift_out_mdi_bits routine for each field in the command. The
3730 * format of a MII write instruction is as follows:
3731 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3732 */
3733 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3734 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3735 mdic <<= 16;
3736 mdic |= (uint32_t) phy_data;
3737
3738 e1000_shift_out_mdi_bits(hw, mdic, 32);
3739 }
3740
3741 return E1000_SUCCESS;
3742}
3743
Adrian Bunke4c780b2006-08-14 23:00:10 -07003744static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003745e1000_read_kmrn_reg(struct e1000_hw *hw,
3746 uint32_t reg_addr,
3747 uint16_t *data)
3748{
3749 uint32_t reg_val;
3750 uint16_t swfw;
3751 DEBUGFUNC("e1000_read_kmrn_reg");
3752
3753 if ((hw->mac_type == e1000_80003es2lan) &&
3754 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3755 swfw = E1000_SWFW_PHY1_SM;
3756 } else {
3757 swfw = E1000_SWFW_PHY0_SM;
3758 }
3759 if (e1000_swfw_sync_acquire(hw, swfw))
3760 return -E1000_ERR_SWFW_SYNC;
3761
3762 /* Write register address */
3763 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3764 E1000_KUMCTRLSTA_OFFSET) |
3765 E1000_KUMCTRLSTA_REN;
3766 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3767 udelay(2);
3768
3769 /* Read the data returned */
3770 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3771 *data = (uint16_t)reg_val;
3772
3773 e1000_swfw_sync_release(hw, swfw);
3774 return E1000_SUCCESS;
3775}
3776
Adrian Bunke4c780b2006-08-14 23:00:10 -07003777static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003778e1000_write_kmrn_reg(struct e1000_hw *hw,
3779 uint32_t reg_addr,
3780 uint16_t data)
3781{
3782 uint32_t reg_val;
3783 uint16_t swfw;
3784 DEBUGFUNC("e1000_write_kmrn_reg");
3785
3786 if ((hw->mac_type == e1000_80003es2lan) &&
3787 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3788 swfw = E1000_SWFW_PHY1_SM;
3789 } else {
3790 swfw = E1000_SWFW_PHY0_SM;
3791 }
3792 if (e1000_swfw_sync_acquire(hw, swfw))
3793 return -E1000_ERR_SWFW_SYNC;
3794
3795 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3796 E1000_KUMCTRLSTA_OFFSET) | data;
3797 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3798 udelay(2);
3799
3800 e1000_swfw_sync_release(hw, swfw);
3801 return E1000_SUCCESS;
3802}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003803
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804/******************************************************************************
3805* Returns the PHY to the power-on reset state
3806*
3807* hw - Struct containing variables accessed by shared code
3808******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003809int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810e1000_phy_hw_reset(struct e1000_hw *hw)
3811{
3812 uint32_t ctrl, ctrl_ext;
3813 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003814 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003815 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
3817 DEBUGFUNC("e1000_phy_hw_reset");
3818
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003819 /* In the case of the phy reset being blocked, it's not an error, we
3820 * simply return success without performing the reset. */
3821 ret_val = e1000_check_phy_reset_block(hw);
3822 if (ret_val)
3823 return E1000_SUCCESS;
3824
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 DEBUGOUT("Resetting Phy...\n");
3826
Auke Kok8fc897b2006-08-28 14:56:16 -07003827 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003828 if ((hw->mac_type == e1000_80003es2lan) &&
3829 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3830 swfw = E1000_SWFW_PHY1_SM;
3831 } else {
3832 swfw = E1000_SWFW_PHY0_SM;
3833 }
3834 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003835 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003836 return -E1000_ERR_SWFW_SYNC;
3837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3839 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003840 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003841 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003842 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 */
3844 ctrl = E1000_READ_REG(hw, CTRL);
3845 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3846 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003847
3848 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003849 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003850 else
3851 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003852
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 E1000_WRITE_REG(hw, CTRL, ctrl);
3854 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003855
Jeff Kirsherfd803242005-12-13 00:06:22 -05003856 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003857 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003858
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003859 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 } else {
3861 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3862 * bit to put the PHY into reset. Then, take it out of reset.
3863 */
3864 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3865 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3866 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3867 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3868 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003869 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3871 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3872 E1000_WRITE_FLUSH(hw);
3873 }
3874 udelay(150);
3875
Auke Kok8fc897b2006-08-28 14:56:16 -07003876 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 /* Configure activity LED after PHY reset */
3878 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3879 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3880 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3881 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3882 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003883
3884 /* Wait for FW to finish PHY configuration. */
3885 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003886 if (ret_val != E1000_SUCCESS)
3887 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003888 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003889
Auke Kok8fc897b2006-08-28 14:56:16 -07003890 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3891 ret_val = e1000_init_lcd_from_nvm(hw);
3892
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003893 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894}
3895
3896/******************************************************************************
3897* Resets the PHY
3898*
3899* hw - Struct containing variables accessed by shared code
3900*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003901* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902******************************************************************************/
3903int32_t
3904e1000_phy_reset(struct e1000_hw *hw)
3905{
3906 int32_t ret_val;
3907 uint16_t phy_data;
3908
3909 DEBUGFUNC("e1000_phy_reset");
3910
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003911 /* In the case of the phy reset being blocked, it's not an error, we
3912 * simply return success without performing the reset. */
3913 ret_val = e1000_check_phy_reset_block(hw);
3914 if (ret_val)
3915 return E1000_SUCCESS;
3916
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003917 switch (hw->phy_type) {
3918 case e1000_phy_igp:
3919 case e1000_phy_igp_2:
3920 case e1000_phy_igp_3:
3921 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003922 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003923 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003924 return ret_val;
3925 break;
3926 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003928 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 return ret_val;
3930
3931 phy_data |= MII_CR_RESET;
3932 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003933 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 return ret_val;
3935
3936 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003937 break;
3938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939
Auke Kok8fc897b2006-08-28 14:56:16 -07003940 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 e1000_phy_init_script(hw);
3942
3943 return E1000_SUCCESS;
3944}
3945
3946/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003947* Work-around for 82566 power-down: on D3 entry-
3948* 1) disable gigabit link
3949* 2) write VR power-down enable
3950* 3) read it back
3951* if successful continue, else issue LCD reset and repeat
3952*
3953* hw - struct containing variables accessed by shared code
3954******************************************************************************/
3955void
3956e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3957{
3958 int32_t reg;
3959 uint16_t phy_data;
3960 int32_t retry = 0;
3961
3962 DEBUGFUNC("e1000_phy_powerdown_workaround");
3963
3964 if (hw->phy_type != e1000_phy_igp_3)
3965 return;
3966
3967 do {
3968 /* Disable link */
3969 reg = E1000_READ_REG(hw, PHY_CTRL);
3970 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3971 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3972
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003973 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003974 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003975 phy_data |= (1 << 9);
3976 phy_data &= ~(1 << 8);
3977 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003978
3979 /* Read it back and test */
3980 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003981 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003982 break;
3983
3984 /* Issue PHY reset and repeat at most one more time */
3985 reg = E1000_READ_REG(hw, CTRL);
3986 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3987 retry++;
3988 } while (retry);
3989
3990 return;
3991
3992}
3993
3994/******************************************************************************
3995* Work-around for 82566 Kumeran PCS lock loss:
3996* On link status change (i.e. PCI reset, speed change) and link is up and
3997* speed is gigabit-
3998* 0) if workaround is optionally disabled do nothing
3999* 1) wait 1ms for Kumeran link to come up
4000* 2) check Kumeran Diagnostic register PCS lock loss bit
4001* 3) if not set the link is locked (all is good), otherwise...
4002* 4) reset the PHY
4003* 5) repeat up to 10 times
4004* Note: this is only called for IGP3 copper when speed is 1gb.
4005*
4006* hw - struct containing variables accessed by shared code
4007******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004008static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004009e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
4010{
4011 int32_t ret_val;
4012 int32_t reg;
4013 int32_t cnt;
4014 uint16_t phy_data;
4015
4016 if (hw->kmrn_lock_loss_workaround_disabled)
4017 return E1000_SUCCESS;
4018
Auke Kok8fc897b2006-08-28 14:56:16 -07004019 /* Make sure link is up before proceeding. If not just return.
4020 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07004021 * stability */
4022 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4023 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4024
4025 if (phy_data & MII_SR_LINK_STATUS) {
4026 for (cnt = 0; cnt < 10; cnt++) {
4027 /* read once to clear */
4028 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4029 if (ret_val)
4030 return ret_val;
4031 /* and again to get new status */
4032 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4033 if (ret_val)
4034 return ret_val;
4035
4036 /* check for PCS lock */
4037 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4038 return E1000_SUCCESS;
4039
4040 /* Issue PHY reset */
4041 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004042 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004043 }
4044 /* Disable GigE link negotiation */
4045 reg = E1000_READ_REG(hw, PHY_CTRL);
4046 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4047 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4048
4049 /* unable to acquire PCS lock */
4050 return E1000_ERR_PHY;
4051 }
4052
4053 return E1000_SUCCESS;
4054}
4055
4056/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057* Probes the expected PHY address for known PHY IDs
4058*
4059* hw - Struct containing variables accessed by shared code
4060******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004061static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062e1000_detect_gig_phy(struct e1000_hw *hw)
4063{
4064 int32_t phy_init_status, ret_val;
4065 uint16_t phy_id_high, phy_id_low;
4066 boolean_t match = FALSE;
4067
4068 DEBUGFUNC("e1000_detect_gig_phy");
4069
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004070 if (hw->phy_id != 0)
4071 return E1000_SUCCESS;
4072
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004073 /* The 82571 firmware may still be configuring the PHY. In this
4074 * case, we cannot access the PHY until the configuration is done. So
4075 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004076 if (hw->mac_type == e1000_82571 ||
4077 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004078 hw->phy_id = IGP01E1000_I_PHY_ID;
4079 hw->phy_type = e1000_phy_igp_2;
4080 return E1000_SUCCESS;
4081 }
4082
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004083 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4084 * around that forces PHY page 0 to be set or the reads fail. The rest of
4085 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4086 * So for ESB-2 we need to have this set so our reads won't fail. If the
4087 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4088 * this out as well. */
4089 if (hw->mac_type == e1000_80003es2lan)
4090 hw->phy_type = e1000_phy_gg82563;
4091
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 /* Read the PHY ID Registers to identify which PHY is onboard. */
4093 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004094 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 return ret_val;
4096
4097 hw->phy_id = (uint32_t) (phy_id_high << 16);
4098 udelay(20);
4099 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004100 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 return ret_val;
4102
4103 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4104 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4105
Auke Kok8fc897b2006-08-28 14:56:16 -07004106 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004108 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 break;
4110 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004111 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 break;
4113 case e1000_82540:
4114 case e1000_82545:
4115 case e1000_82545_rev_3:
4116 case e1000_82546:
4117 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004118 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 break;
4120 case e1000_82541:
4121 case e1000_82541_rev_2:
4122 case e1000_82547:
4123 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004124 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004126 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004127 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004128 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004129 case e1000_80003es2lan:
4130 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4131 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004132 case e1000_ich8lan:
4133 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4134 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4135 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4136 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4137 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 default:
4139 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4140 return -E1000_ERR_CONFIG;
4141 }
4142 phy_init_status = e1000_set_phy_type(hw);
4143
4144 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4145 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4146 return E1000_SUCCESS;
4147 }
4148 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4149 return -E1000_ERR_PHY;
4150}
4151
4152/******************************************************************************
4153* Resets the PHY's DSP
4154*
4155* hw - Struct containing variables accessed by shared code
4156******************************************************************************/
4157static int32_t
4158e1000_phy_reset_dsp(struct e1000_hw *hw)
4159{
4160 int32_t ret_val;
4161 DEBUGFUNC("e1000_phy_reset_dsp");
4162
4163 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004164 if (hw->phy_type != e1000_phy_gg82563) {
4165 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004166 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004169 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004171 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004173 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174
4175 return ret_val;
4176}
4177
4178/******************************************************************************
4179* Get PHY information from various PHY registers for igp PHY only.
4180*
4181* hw - Struct containing variables accessed by shared code
4182* phy_info - PHY information structure
4183******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004184static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185e1000_phy_igp_get_info(struct e1000_hw *hw,
4186 struct e1000_phy_info *phy_info)
4187{
4188 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004189 uint16_t phy_data, min_length, max_length, average;
4190 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
4192 DEBUGFUNC("e1000_phy_igp_get_info");
4193
4194 /* The downshift status is checked only once, after link is established,
4195 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004196 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197
4198 /* IGP01E1000 does not need to support it. */
4199 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4200
4201 /* IGP01E1000 always correct polarity reversal */
4202 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4203
4204 /* Check polarity status */
4205 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004206 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 return ret_val;
4208
4209 phy_info->cable_polarity = polarity;
4210
4211 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004212 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 return ret_val;
4214
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004215 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4216 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217
Auke Kok8fc897b2006-08-28 14:56:16 -07004218 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 IGP01E1000_PSSR_SPEED_1000MBPS) {
4220 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4221 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004222 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 return ret_val;
4224
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004225 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4226 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4227 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4228 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4229 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4230 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231
4232 /* Get cable length */
4233 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004234 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 return ret_val;
4236
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004237 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 average = (max_length + min_length) / 2;
4239
Auke Kok8fc897b2006-08-28 14:56:16 -07004240 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004242 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004244 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004246 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 phy_info->cable_length = e1000_cable_length_110_140;
4248 else
4249 phy_info->cable_length = e1000_cable_length_140;
4250 }
4251
4252 return E1000_SUCCESS;
4253}
4254
4255/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004256* Get PHY information from various PHY registers for ife PHY only.
4257*
4258* hw - Struct containing variables accessed by shared code
4259* phy_info - PHY information structure
4260******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004261static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004262e1000_phy_ife_get_info(struct e1000_hw *hw,
4263 struct e1000_phy_info *phy_info)
4264{
4265 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004266 uint16_t phy_data;
4267 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004268
4269 DEBUGFUNC("e1000_phy_ife_get_info");
4270
4271 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4272 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4273
4274 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4275 if (ret_val)
4276 return ret_val;
4277 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004278 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4279 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4280 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004281
4282 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4283 ret_val = e1000_check_polarity(hw, &polarity);
4284 if (ret_val)
4285 return ret_val;
4286 } else {
4287 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004288 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4289 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4290 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004291 }
4292 phy_info->cable_polarity = polarity;
4293
4294 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4295 if (ret_val)
4296 return ret_val;
4297
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004298 phy_info->mdix_mode = (e1000_auto_x_mode)
4299 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4300 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004301
4302 return E1000_SUCCESS;
4303}
4304
4305/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306* Get PHY information from various PHY registers fot m88 PHY only.
4307*
4308* hw - Struct containing variables accessed by shared code
4309* phy_info - PHY information structure
4310******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004311static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312e1000_phy_m88_get_info(struct e1000_hw *hw,
4313 struct e1000_phy_info *phy_info)
4314{
4315 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004316 uint16_t phy_data;
4317 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318
4319 DEBUGFUNC("e1000_phy_m88_get_info");
4320
4321 /* The downshift status is checked only once, after link is established,
4322 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004323 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
4325 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004326 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 return ret_val;
4328
4329 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004330 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4331 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4332 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4333
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004335 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4336 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4337 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338
4339 /* Check polarity status */
4340 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004341 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004342 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 phy_info->cable_polarity = polarity;
4344
4345 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004346 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 return ret_val;
4348
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004349 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4350 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351
4352 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4353 /* Cable Length Estimation and Local/Remote Receiver Information
4354 * are only valid at 1000 Mbps.
4355 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004356 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004357 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004358 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4359 } else {
4360 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4361 &phy_data);
4362 if (ret_val)
4363 return ret_val;
4364
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004365 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367
4368 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004369 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 return ret_val;
4371
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004372 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4373 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4374 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4375 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4376 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4377 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 }
4380
4381 return E1000_SUCCESS;
4382}
4383
4384/******************************************************************************
4385* Get PHY information from various PHY registers
4386*
4387* hw - Struct containing variables accessed by shared code
4388* phy_info - PHY information structure
4389******************************************************************************/
4390int32_t
4391e1000_phy_get_info(struct e1000_hw *hw,
4392 struct e1000_phy_info *phy_info)
4393{
4394 int32_t ret_val;
4395 uint16_t phy_data;
4396
4397 DEBUGFUNC("e1000_phy_get_info");
4398
4399 phy_info->cable_length = e1000_cable_length_undefined;
4400 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4401 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4402 phy_info->downshift = e1000_downshift_undefined;
4403 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4404 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4405 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4406 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4407
Auke Kok8fc897b2006-08-28 14:56:16 -07004408 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 DEBUGOUT("PHY info is only valid for copper media\n");
4410 return -E1000_ERR_CONFIG;
4411 }
4412
4413 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004414 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 return ret_val;
4416
4417 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004418 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 return ret_val;
4420
Auke Kok8fc897b2006-08-28 14:56:16 -07004421 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 DEBUGOUT("PHY info is only valid if link is up\n");
4423 return -E1000_ERR_CONFIG;
4424 }
4425
Auke Kokcd94dd02006-06-27 09:08:22 -07004426 if (hw->phy_type == e1000_phy_igp ||
4427 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004428 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004430 else if (hw->phy_type == e1000_phy_ife)
4431 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 else
4433 return e1000_phy_m88_get_info(hw, phy_info);
4434}
4435
4436int32_t
4437e1000_validate_mdi_setting(struct e1000_hw *hw)
4438{
4439 DEBUGFUNC("e1000_validate_mdi_settings");
4440
Auke Kok8fc897b2006-08-28 14:56:16 -07004441 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 DEBUGOUT("Invalid MDI setting detected\n");
4443 hw->mdix = 1;
4444 return -E1000_ERR_CONFIG;
4445 }
4446 return E1000_SUCCESS;
4447}
4448
4449
4450/******************************************************************************
4451 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004452 * is configured. Additionally, if this is ICH8, the flash controller GbE
4453 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 *
4455 * hw - Struct containing variables accessed by shared code
4456 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004457int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458e1000_init_eeprom_params(struct e1000_hw *hw)
4459{
4460 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4461 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004462 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 uint16_t eeprom_size;
4464
4465 DEBUGFUNC("e1000_init_eeprom_params");
4466
4467 switch (hw->mac_type) {
4468 case e1000_82542_rev2_0:
4469 case e1000_82542_rev2_1:
4470 case e1000_82543:
4471 case e1000_82544:
4472 eeprom->type = e1000_eeprom_microwire;
4473 eeprom->word_size = 64;
4474 eeprom->opcode_bits = 3;
4475 eeprom->address_bits = 6;
4476 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004477 eeprom->use_eerd = FALSE;
4478 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 break;
4480 case e1000_82540:
4481 case e1000_82545:
4482 case e1000_82545_rev_3:
4483 case e1000_82546:
4484 case e1000_82546_rev_3:
4485 eeprom->type = e1000_eeprom_microwire;
4486 eeprom->opcode_bits = 3;
4487 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004488 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 eeprom->word_size = 256;
4490 eeprom->address_bits = 8;
4491 } else {
4492 eeprom->word_size = 64;
4493 eeprom->address_bits = 6;
4494 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004495 eeprom->use_eerd = FALSE;
4496 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 break;
4498 case e1000_82541:
4499 case e1000_82541_rev_2:
4500 case e1000_82547:
4501 case e1000_82547_rev_2:
4502 if (eecd & E1000_EECD_TYPE) {
4503 eeprom->type = e1000_eeprom_spi;
4504 eeprom->opcode_bits = 8;
4505 eeprom->delay_usec = 1;
4506 if (eecd & E1000_EECD_ADDR_BITS) {
4507 eeprom->page_size = 32;
4508 eeprom->address_bits = 16;
4509 } else {
4510 eeprom->page_size = 8;
4511 eeprom->address_bits = 8;
4512 }
4513 } else {
4514 eeprom->type = e1000_eeprom_microwire;
4515 eeprom->opcode_bits = 3;
4516 eeprom->delay_usec = 50;
4517 if (eecd & E1000_EECD_ADDR_BITS) {
4518 eeprom->word_size = 256;
4519 eeprom->address_bits = 8;
4520 } else {
4521 eeprom->word_size = 64;
4522 eeprom->address_bits = 6;
4523 }
4524 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004525 eeprom->use_eerd = FALSE;
4526 eeprom->use_eewr = FALSE;
4527 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004528 case e1000_82571:
4529 case e1000_82572:
4530 eeprom->type = e1000_eeprom_spi;
4531 eeprom->opcode_bits = 8;
4532 eeprom->delay_usec = 1;
4533 if (eecd & E1000_EECD_ADDR_BITS) {
4534 eeprom->page_size = 32;
4535 eeprom->address_bits = 16;
4536 } else {
4537 eeprom->page_size = 8;
4538 eeprom->address_bits = 8;
4539 }
4540 eeprom->use_eerd = FALSE;
4541 eeprom->use_eewr = FALSE;
4542 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004543 case e1000_82573:
4544 eeprom->type = e1000_eeprom_spi;
4545 eeprom->opcode_bits = 8;
4546 eeprom->delay_usec = 1;
4547 if (eecd & E1000_EECD_ADDR_BITS) {
4548 eeprom->page_size = 32;
4549 eeprom->address_bits = 16;
4550 } else {
4551 eeprom->page_size = 8;
4552 eeprom->address_bits = 8;
4553 }
4554 eeprom->use_eerd = TRUE;
4555 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004556 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004557 eeprom->type = e1000_eeprom_flash;
4558 eeprom->word_size = 2048;
4559
4560 /* Ensure that the Autonomous FLASH update bit is cleared due to
4561 * Flash update issue on parts which use a FLASH for NVM. */
4562 eecd &= ~E1000_EECD_AUPDEN;
4563 E1000_WRITE_REG(hw, EECD, eecd);
4564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004566 case e1000_80003es2lan:
4567 eeprom->type = e1000_eeprom_spi;
4568 eeprom->opcode_bits = 8;
4569 eeprom->delay_usec = 1;
4570 if (eecd & E1000_EECD_ADDR_BITS) {
4571 eeprom->page_size = 32;
4572 eeprom->address_bits = 16;
4573 } else {
4574 eeprom->page_size = 8;
4575 eeprom->address_bits = 8;
4576 }
4577 eeprom->use_eerd = TRUE;
4578 eeprom->use_eewr = FALSE;
4579 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004580 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004581 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004582 int32_t i = 0;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004583 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
Auke Kokcd94dd02006-06-27 09:08:22 -07004584
4585 eeprom->type = e1000_eeprom_ich8;
4586 eeprom->use_eerd = FALSE;
4587 eeprom->use_eewr = FALSE;
4588 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4589
4590 /* Zero the shadow RAM structure. But don't load it from NVM
4591 * so as to save time for driver init */
4592 if (hw->eeprom_shadow_ram != NULL) {
4593 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4594 hw->eeprom_shadow_ram[i].modified = FALSE;
4595 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4596 }
4597 }
4598
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004599 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4600 ICH_FLASH_SECTOR_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -07004601
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004602 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4603 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4604
4605 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4606
Auke Kokcd94dd02006-06-27 09:08:22 -07004607 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4608
4609 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 default:
4612 break;
4613 }
4614
4615 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004616 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4617 * 32KB (incremented by powers of 2).
4618 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004619 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004620 /* Set to default value for initial eeprom read. */
4621 eeprom->word_size = 64;
4622 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004623 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004624 return ret_val;
4625 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4626 /* 256B eeprom size was not supported in earlier hardware, so we
4627 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4628 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004629 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004630 eeprom_size++;
4631 } else {
4632 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4633 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004635
4636 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004638 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639}
4640
4641/******************************************************************************
4642 * Raises the EEPROM's clock input.
4643 *
4644 * hw - Struct containing variables accessed by shared code
4645 * eecd - EECD's current value
4646 *****************************************************************************/
4647static void
4648e1000_raise_ee_clk(struct e1000_hw *hw,
4649 uint32_t *eecd)
4650{
4651 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4652 * wait <delay> microseconds.
4653 */
4654 *eecd = *eecd | E1000_EECD_SK;
4655 E1000_WRITE_REG(hw, EECD, *eecd);
4656 E1000_WRITE_FLUSH(hw);
4657 udelay(hw->eeprom.delay_usec);
4658}
4659
4660/******************************************************************************
4661 * Lowers the EEPROM's clock input.
4662 *
4663 * hw - Struct containing variables accessed by shared code
4664 * eecd - EECD's current value
4665 *****************************************************************************/
4666static void
4667e1000_lower_ee_clk(struct e1000_hw *hw,
4668 uint32_t *eecd)
4669{
4670 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4671 * wait 50 microseconds.
4672 */
4673 *eecd = *eecd & ~E1000_EECD_SK;
4674 E1000_WRITE_REG(hw, EECD, *eecd);
4675 E1000_WRITE_FLUSH(hw);
4676 udelay(hw->eeprom.delay_usec);
4677}
4678
4679/******************************************************************************
4680 * Shift data bits out to the EEPROM.
4681 *
4682 * hw - Struct containing variables accessed by shared code
4683 * data - data to send to the EEPROM
4684 * count - number of bits to shift out
4685 *****************************************************************************/
4686static void
4687e1000_shift_out_ee_bits(struct e1000_hw *hw,
4688 uint16_t data,
4689 uint16_t count)
4690{
4691 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4692 uint32_t eecd;
4693 uint32_t mask;
4694
4695 /* We need to shift "count" bits out to the EEPROM. So, value in the
4696 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4697 * In order to do this, "data" must be broken down into bits.
4698 */
4699 mask = 0x01 << (count - 1);
4700 eecd = E1000_READ_REG(hw, EECD);
4701 if (eeprom->type == e1000_eeprom_microwire) {
4702 eecd &= ~E1000_EECD_DO;
4703 } else if (eeprom->type == e1000_eeprom_spi) {
4704 eecd |= E1000_EECD_DO;
4705 }
4706 do {
4707 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4708 * and then raising and then lowering the clock (the SK bit controls
4709 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4710 * by setting "DI" to "0" and then raising and then lowering the clock.
4711 */
4712 eecd &= ~E1000_EECD_DI;
4713
Auke Kok8fc897b2006-08-28 14:56:16 -07004714 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 eecd |= E1000_EECD_DI;
4716
4717 E1000_WRITE_REG(hw, EECD, eecd);
4718 E1000_WRITE_FLUSH(hw);
4719
4720 udelay(eeprom->delay_usec);
4721
4722 e1000_raise_ee_clk(hw, &eecd);
4723 e1000_lower_ee_clk(hw, &eecd);
4724
4725 mask = mask >> 1;
4726
Auke Kok8fc897b2006-08-28 14:56:16 -07004727 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728
4729 /* We leave the "DI" bit set to "0" when we leave this routine. */
4730 eecd &= ~E1000_EECD_DI;
4731 E1000_WRITE_REG(hw, EECD, eecd);
4732}
4733
4734/******************************************************************************
4735 * Shift data bits in from the EEPROM
4736 *
4737 * hw - Struct containing variables accessed by shared code
4738 *****************************************************************************/
4739static uint16_t
4740e1000_shift_in_ee_bits(struct e1000_hw *hw,
4741 uint16_t count)
4742{
4743 uint32_t eecd;
4744 uint32_t i;
4745 uint16_t data;
4746
4747 /* In order to read a register from the EEPROM, we need to shift 'count'
4748 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4749 * input to the EEPROM (setting the SK bit), and then reading the value of
4750 * the "DO" bit. During this "shifting in" process the "DI" bit should
4751 * always be clear.
4752 */
4753
4754 eecd = E1000_READ_REG(hw, EECD);
4755
4756 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4757 data = 0;
4758
Auke Kok8fc897b2006-08-28 14:56:16 -07004759 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 data = data << 1;
4761 e1000_raise_ee_clk(hw, &eecd);
4762
4763 eecd = E1000_READ_REG(hw, EECD);
4764
4765 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004766 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 data |= 1;
4768
4769 e1000_lower_ee_clk(hw, &eecd);
4770 }
4771
4772 return data;
4773}
4774
4775/******************************************************************************
4776 * Prepares EEPROM for access
4777 *
4778 * hw - Struct containing variables accessed by shared code
4779 *
4780 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4781 * function should be called before issuing a command to the EEPROM.
4782 *****************************************************************************/
4783static int32_t
4784e1000_acquire_eeprom(struct e1000_hw *hw)
4785{
4786 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4787 uint32_t eecd, i=0;
4788
4789 DEBUGFUNC("e1000_acquire_eeprom");
4790
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004791 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4792 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 eecd = E1000_READ_REG(hw, EECD);
4794
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004795 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004796 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004797 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004798 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004800 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004801 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004802 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4803 i++;
4804 udelay(5);
4805 eecd = E1000_READ_REG(hw, EECD);
4806 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004807 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004808 eecd &= ~E1000_EECD_REQ;
4809 E1000_WRITE_REG(hw, EECD, eecd);
4810 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004811 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004812 return -E1000_ERR_EEPROM;
4813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 }
4815 }
4816
4817 /* Setup EEPROM for Read/Write */
4818
4819 if (eeprom->type == e1000_eeprom_microwire) {
4820 /* Clear SK and DI */
4821 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4822 E1000_WRITE_REG(hw, EECD, eecd);
4823
4824 /* Set CS */
4825 eecd |= E1000_EECD_CS;
4826 E1000_WRITE_REG(hw, EECD, eecd);
4827 } else if (eeprom->type == e1000_eeprom_spi) {
4828 /* Clear SK and CS */
4829 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4830 E1000_WRITE_REG(hw, EECD, eecd);
4831 udelay(1);
4832 }
4833
4834 return E1000_SUCCESS;
4835}
4836
4837/******************************************************************************
4838 * Returns EEPROM to a "standby" state
4839 *
4840 * hw - Struct containing variables accessed by shared code
4841 *****************************************************************************/
4842static void
4843e1000_standby_eeprom(struct e1000_hw *hw)
4844{
4845 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4846 uint32_t eecd;
4847
4848 eecd = E1000_READ_REG(hw, EECD);
4849
Auke Kok8fc897b2006-08-28 14:56:16 -07004850 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4852 E1000_WRITE_REG(hw, EECD, eecd);
4853 E1000_WRITE_FLUSH(hw);
4854 udelay(eeprom->delay_usec);
4855
4856 /* Clock high */
4857 eecd |= E1000_EECD_SK;
4858 E1000_WRITE_REG(hw, EECD, eecd);
4859 E1000_WRITE_FLUSH(hw);
4860 udelay(eeprom->delay_usec);
4861
4862 /* Select EEPROM */
4863 eecd |= E1000_EECD_CS;
4864 E1000_WRITE_REG(hw, EECD, eecd);
4865 E1000_WRITE_FLUSH(hw);
4866 udelay(eeprom->delay_usec);
4867
4868 /* Clock low */
4869 eecd &= ~E1000_EECD_SK;
4870 E1000_WRITE_REG(hw, EECD, eecd);
4871 E1000_WRITE_FLUSH(hw);
4872 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004873 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 /* Toggle CS to flush commands */
4875 eecd |= E1000_EECD_CS;
4876 E1000_WRITE_REG(hw, EECD, eecd);
4877 E1000_WRITE_FLUSH(hw);
4878 udelay(eeprom->delay_usec);
4879 eecd &= ~E1000_EECD_CS;
4880 E1000_WRITE_REG(hw, EECD, eecd);
4881 E1000_WRITE_FLUSH(hw);
4882 udelay(eeprom->delay_usec);
4883 }
4884}
4885
4886/******************************************************************************
4887 * Terminates a command by inverting the EEPROM's chip select pin
4888 *
4889 * hw - Struct containing variables accessed by shared code
4890 *****************************************************************************/
4891static void
4892e1000_release_eeprom(struct e1000_hw *hw)
4893{
4894 uint32_t eecd;
4895
4896 DEBUGFUNC("e1000_release_eeprom");
4897
4898 eecd = E1000_READ_REG(hw, EECD);
4899
4900 if (hw->eeprom.type == e1000_eeprom_spi) {
4901 eecd |= E1000_EECD_CS; /* Pull CS high */
4902 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4903
4904 E1000_WRITE_REG(hw, EECD, eecd);
4905
4906 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004907 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 /* cleanup eeprom */
4909
4910 /* CS on Microwire is active-high */
4911 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4912
4913 E1000_WRITE_REG(hw, EECD, eecd);
4914
4915 /* Rising edge of clock */
4916 eecd |= E1000_EECD_SK;
4917 E1000_WRITE_REG(hw, EECD, eecd);
4918 E1000_WRITE_FLUSH(hw);
4919 udelay(hw->eeprom.delay_usec);
4920
4921 /* Falling edge of clock */
4922 eecd &= ~E1000_EECD_SK;
4923 E1000_WRITE_REG(hw, EECD, eecd);
4924 E1000_WRITE_FLUSH(hw);
4925 udelay(hw->eeprom.delay_usec);
4926 }
4927
4928 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004929 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 eecd &= ~E1000_EECD_REQ;
4931 E1000_WRITE_REG(hw, EECD, eecd);
4932 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004933
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004934 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935}
4936
4937/******************************************************************************
4938 * Reads a 16 bit word from the EEPROM.
4939 *
4940 * hw - Struct containing variables accessed by shared code
4941 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004942static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943e1000_spi_eeprom_ready(struct e1000_hw *hw)
4944{
4945 uint16_t retry_count = 0;
4946 uint8_t spi_stat_reg;
4947
4948 DEBUGFUNC("e1000_spi_eeprom_ready");
4949
4950 /* Read "Status Register" repeatedly until the LSB is cleared. The
4951 * EEPROM will signal that the command has been completed by clearing
4952 * bit 0 of the internal status register. If it's not cleared within
4953 * 5 milliseconds, then error out.
4954 */
4955 retry_count = 0;
4956 do {
4957 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4958 hw->eeprom.opcode_bits);
4959 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4960 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4961 break;
4962
4963 udelay(5);
4964 retry_count += 5;
4965
4966 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004967 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968
4969 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4970 * only 0-5mSec on 5V devices)
4971 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004972 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 DEBUGOUT("SPI EEPROM Status error\n");
4974 return -E1000_ERR_EEPROM;
4975 }
4976
4977 return E1000_SUCCESS;
4978}
4979
4980/******************************************************************************
4981 * Reads a 16 bit word from the EEPROM.
4982 *
4983 * hw - Struct containing variables accessed by shared code
4984 * offset - offset of word in the EEPROM to read
4985 * data - word read from the EEPROM
4986 * words - number of words to read
4987 *****************************************************************************/
4988int32_t
4989e1000_read_eeprom(struct e1000_hw *hw,
4990 uint16_t offset,
4991 uint16_t words,
4992 uint16_t *data)
4993{
4994 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4995 uint32_t i = 0;
4996
4997 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004998
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004999 /* If eeprom is not yet detected, do so now */
5000 if (eeprom->word_size == 0)
5001 e1000_init_eeprom_params(hw);
5002
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 /* A check for invalid values: offset too large, too many words, and not
5004 * enough words.
5005 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005006 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005008 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 return -E1000_ERR_EEPROM;
5010 }
5011
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005012 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
5013 * directly. In this case, we need to acquire the EEPROM so that
5014 * FW or other port software does not interrupt.
5015 */
Jeff Kirsher4d3518582006-01-12 16:50:48 -08005016 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07005017 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005018 /* Prepare the EEPROM for bit-bang reading */
5019 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5020 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005021 }
5022
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005023 /* Eerd register EEPROM access requires no eeprom aquire/release */
5024 if (eeprom->use_eerd == TRUE)
5025 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005027 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07005028 if (eeprom->type == e1000_eeprom_ich8)
5029 return e1000_read_eeprom_ich8(hw, offset, words, data);
5030
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005031 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5032 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07005033 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 uint16_t word_in;
5035 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5036
Auke Kok8fc897b2006-08-28 14:56:16 -07005037 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 e1000_release_eeprom(hw);
5039 return -E1000_ERR_EEPROM;
5040 }
5041
5042 e1000_standby_eeprom(hw);
5043
5044 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005045 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 read_opcode |= EEPROM_A8_OPCODE_SPI;
5047
5048 /* Send the READ command (opcode + addr) */
5049 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5050 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5051
5052 /* Read the data. The address of the eeprom internally increments with
5053 * each byte (spi) being read, saving on the overhead of eeprom setup
5054 * and tear-down. The address counter will roll over if reading beyond
5055 * the size of the eeprom, thus allowing the entire memory to be read
5056 * starting from any offset. */
5057 for (i = 0; i < words; i++) {
5058 word_in = e1000_shift_in_ee_bits(hw, 16);
5059 data[i] = (word_in >> 8) | (word_in << 8);
5060 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005061 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 for (i = 0; i < words; i++) {
5063 /* Send the READ command (opcode + addr) */
5064 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5065 eeprom->opcode_bits);
5066 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5067 eeprom->address_bits);
5068
5069 /* Read the data. For microwire, each word requires the overhead
5070 * of eeprom setup and tear-down. */
5071 data[i] = e1000_shift_in_ee_bits(hw, 16);
5072 e1000_standby_eeprom(hw);
5073 }
5074 }
5075
5076 /* End this read operation */
5077 e1000_release_eeprom(hw);
5078
5079 return E1000_SUCCESS;
5080}
5081
5082/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005083 * Reads a 16 bit word from the EEPROM using the EERD register.
5084 *
5085 * hw - Struct containing variables accessed by shared code
5086 * offset - offset of word in the EEPROM to read
5087 * data - word read from the EEPROM
5088 * words - number of words to read
5089 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005090static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005091e1000_read_eeprom_eerd(struct e1000_hw *hw,
5092 uint16_t offset,
5093 uint16_t words,
5094 uint16_t *data)
5095{
5096 uint32_t i, eerd = 0;
5097 int32_t error = 0;
5098
5099 for (i = 0; i < words; i++) {
5100 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5101 E1000_EEPROM_RW_REG_START;
5102
5103 E1000_WRITE_REG(hw, EERD, eerd);
5104 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005105
Auke Kok8fc897b2006-08-28 14:56:16 -07005106 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005107 break;
5108 }
5109 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005110
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005111 }
Auke Kok76c224b2006-05-23 13:36:06 -07005112
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005113 return error;
5114}
5115
5116/******************************************************************************
5117 * Writes a 16 bit word from the EEPROM using the EEWR register.
5118 *
5119 * hw - Struct containing variables accessed by shared code
5120 * offset - offset of word in the EEPROM to read
5121 * data - word read from the EEPROM
5122 * words - number of words to read
5123 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005124static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005125e1000_write_eeprom_eewr(struct e1000_hw *hw,
5126 uint16_t offset,
5127 uint16_t words,
5128 uint16_t *data)
5129{
5130 uint32_t register_value = 0;
5131 uint32_t i = 0;
5132 int32_t error = 0;
5133
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005134 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5135 return -E1000_ERR_SWFW_SYNC;
5136
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005137 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005138 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5139 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005140 E1000_EEPROM_RW_REG_START;
5141
5142 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005143 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005144 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005145 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005146
5147 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005148
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005149 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005150
Auke Kok8fc897b2006-08-28 14:56:16 -07005151 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005152 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005153 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005154 }
Auke Kok76c224b2006-05-23 13:36:06 -07005155
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005156 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005157 return error;
5158}
5159
5160/******************************************************************************
5161 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5162 *
5163 * hw - Struct containing variables accessed by shared code
5164 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005165static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005166e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5167{
5168 uint32_t attempts = 100000;
5169 uint32_t i, reg = 0;
5170 int32_t done = E1000_ERR_EEPROM;
5171
Auke Kok8fc897b2006-08-28 14:56:16 -07005172 for (i = 0; i < attempts; i++) {
5173 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005174 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005175 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005176 reg = E1000_READ_REG(hw, EEWR);
5177
Auke Kok8fc897b2006-08-28 14:56:16 -07005178 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005179 done = E1000_SUCCESS;
5180 break;
5181 }
5182 udelay(5);
5183 }
5184
5185 return done;
5186}
5187
5188/***************************************************************************
5189* Description: Determines if the onboard NVM is FLASH or EEPROM.
5190*
5191* hw - Struct containing variables accessed by shared code
5192****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005193static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005194e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5195{
5196 uint32_t eecd = 0;
5197
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005198 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5199
Auke Kokcd94dd02006-06-27 09:08:22 -07005200 if (hw->mac_type == e1000_ich8lan)
5201 return FALSE;
5202
5203 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005204 eecd = E1000_READ_REG(hw, EECD);
5205
5206 /* Isolate bits 15 & 16 */
5207 eecd = ((eecd >> 15) & 0x03);
5208
5209 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005210 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005211 return FALSE;
5212 }
5213 }
5214 return TRUE;
5215}
5216
5217/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 * Verifies that the EEPROM has a valid checksum
5219 *
5220 * hw - Struct containing variables accessed by shared code
5221 *
5222 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5223 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5224 * valid.
5225 *****************************************************************************/
5226int32_t
5227e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5228{
5229 uint16_t checksum = 0;
5230 uint16_t i, eeprom_data;
5231
5232 DEBUGFUNC("e1000_validate_eeprom_checksum");
5233
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005234 if ((hw->mac_type == e1000_82573) &&
5235 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5236 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5237 * 10h-12h. Checksum may need to be fixed. */
5238 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5239 if ((eeprom_data & 0x10) == 0) {
5240 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5241 * has already been fixed. If the checksum is still wrong and this
5242 * bit is a 1, we need to return bad checksum. Otherwise, we need
5243 * to set this bit to a 1 and update the checksum. */
5244 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5245 if ((eeprom_data & 0x8000) == 0) {
5246 eeprom_data |= 0x8000;
5247 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5248 e1000_update_eeprom_checksum(hw);
5249 }
5250 }
5251 }
5252
Auke Kokcd94dd02006-06-27 09:08:22 -07005253 if (hw->mac_type == e1000_ich8lan) {
5254 /* Drivers must allocate the shadow ram structure for the
5255 * EEPROM checksum to be updated. Otherwise, this bit as well
5256 * as the checksum must both be set correctly for this
5257 * validation to pass.
5258 */
5259 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5260 if ((eeprom_data & 0x40) == 0) {
5261 eeprom_data |= 0x40;
5262 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5263 e1000_update_eeprom_checksum(hw);
5264 }
5265 }
5266
5267 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5268 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 DEBUGOUT("EEPROM Read Error\n");
5270 return -E1000_ERR_EEPROM;
5271 }
5272 checksum += eeprom_data;
5273 }
5274
Auke Kok8fc897b2006-08-28 14:56:16 -07005275 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 return E1000_SUCCESS;
5277 else {
5278 DEBUGOUT("EEPROM Checksum Invalid\n");
5279 return -E1000_ERR_EEPROM;
5280 }
5281}
5282
5283/******************************************************************************
5284 * Calculates the EEPROM checksum and writes it to the EEPROM
5285 *
5286 * hw - Struct containing variables accessed by shared code
5287 *
5288 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5289 * Writes the difference to word offset 63 of the EEPROM.
5290 *****************************************************************************/
5291int32_t
5292e1000_update_eeprom_checksum(struct e1000_hw *hw)
5293{
Auke Kokcd94dd02006-06-27 09:08:22 -07005294 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005295 uint16_t checksum = 0;
5296 uint16_t i, eeprom_data;
5297
5298 DEBUGFUNC("e1000_update_eeprom_checksum");
5299
Auke Kok8fc897b2006-08-28 14:56:16 -07005300 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5301 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 DEBUGOUT("EEPROM Read Error\n");
5303 return -E1000_ERR_EEPROM;
5304 }
5305 checksum += eeprom_data;
5306 }
5307 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005308 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 DEBUGOUT("EEPROM Write Error\n");
5310 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005311 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5312 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005313 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5314 e1000_commit_shadow_ram(hw);
5315 /* Reload the EEPROM, or else modifications will not appear
5316 * until after next adapter reset. */
5317 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5318 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5319 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005320 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 }
5322 return E1000_SUCCESS;
5323}
5324
5325/******************************************************************************
5326 * Parent function for writing words to the different EEPROM types.
5327 *
5328 * hw - Struct containing variables accessed by shared code
5329 * offset - offset within the EEPROM to be written to
5330 * words - number of words to write
5331 * data - 16 bit word to be written to the EEPROM
5332 *
5333 * If e1000_update_eeprom_checksum is not called after this function, the
5334 * EEPROM will most likely contain an invalid checksum.
5335 *****************************************************************************/
5336int32_t
5337e1000_write_eeprom(struct e1000_hw *hw,
5338 uint16_t offset,
5339 uint16_t words,
5340 uint16_t *data)
5341{
5342 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5343 int32_t status = 0;
5344
5345 DEBUGFUNC("e1000_write_eeprom");
5346
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005347 /* If eeprom is not yet detected, do so now */
5348 if (eeprom->word_size == 0)
5349 e1000_init_eeprom_params(hw);
5350
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 /* A check for invalid values: offset too large, too many words, and not
5352 * enough words.
5353 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005354 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355 (words == 0)) {
5356 DEBUGOUT("\"words\" parameter out of bounds\n");
5357 return -E1000_ERR_EEPROM;
5358 }
5359
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005360 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005361 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005362 return e1000_write_eeprom_eewr(hw, offset, words, data);
5363
Auke Kokcd94dd02006-06-27 09:08:22 -07005364 if (eeprom->type == e1000_eeprom_ich8)
5365 return e1000_write_eeprom_ich8(hw, offset, words, data);
5366
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367 /* Prepare the EEPROM for writing */
5368 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5369 return -E1000_ERR_EEPROM;
5370
Auke Kok8fc897b2006-08-28 14:56:16 -07005371 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5373 } else {
5374 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005375 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376 }
5377
5378 /* Done with writing */
5379 e1000_release_eeprom(hw);
5380
5381 return status;
5382}
5383
5384/******************************************************************************
5385 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5386 *
5387 * hw - Struct containing variables accessed by shared code
5388 * offset - offset within the EEPROM to be written to
5389 * words - number of words to write
5390 * data - pointer to array of 8 bit words to be written to the EEPROM
5391 *
5392 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005393static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394e1000_write_eeprom_spi(struct e1000_hw *hw,
5395 uint16_t offset,
5396 uint16_t words,
5397 uint16_t *data)
5398{
5399 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5400 uint16_t widx = 0;
5401
5402 DEBUGFUNC("e1000_write_eeprom_spi");
5403
5404 while (widx < words) {
5405 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5406
Auke Kok8fc897b2006-08-28 14:56:16 -07005407 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408
5409 e1000_standby_eeprom(hw);
5410
5411 /* Send the WRITE ENABLE command (8 bit opcode ) */
5412 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5413 eeprom->opcode_bits);
5414
5415 e1000_standby_eeprom(hw);
5416
5417 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005418 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005419 write_opcode |= EEPROM_A8_OPCODE_SPI;
5420
5421 /* Send the Write command (8-bit opcode + addr) */
5422 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5423
5424 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5425 eeprom->address_bits);
5426
5427 /* Send the data */
5428
5429 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5430 while (widx < words) {
5431 uint16_t word_out = data[widx];
5432 word_out = (word_out >> 8) | (word_out << 8);
5433 e1000_shift_out_ee_bits(hw, word_out, 16);
5434 widx++;
5435
5436 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5437 * operation, while the smaller eeproms are capable of an 8-byte
5438 * PAGE WRITE operation. Break the inner loop to pass new address
5439 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005440 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441 e1000_standby_eeprom(hw);
5442 break;
5443 }
5444 }
5445 }
5446
5447 return E1000_SUCCESS;
5448}
5449
5450/******************************************************************************
5451 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5452 *
5453 * hw - Struct containing variables accessed by shared code
5454 * offset - offset within the EEPROM to be written to
5455 * words - number of words to write
5456 * data - pointer to array of 16 bit words to be written to the EEPROM
5457 *
5458 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005459static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460e1000_write_eeprom_microwire(struct e1000_hw *hw,
5461 uint16_t offset,
5462 uint16_t words,
5463 uint16_t *data)
5464{
5465 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5466 uint32_t eecd;
5467 uint16_t words_written = 0;
5468 uint16_t i = 0;
5469
5470 DEBUGFUNC("e1000_write_eeprom_microwire");
5471
5472 /* Send the write enable command to the EEPROM (3-bit opcode plus
5473 * 6/8-bit dummy address beginning with 11). It's less work to include
5474 * the 11 of the dummy address as part of the opcode than it is to shift
5475 * it over the correct number of bits for the address. This puts the
5476 * EEPROM into write/erase mode.
5477 */
5478 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5479 (uint16_t)(eeprom->opcode_bits + 2));
5480
5481 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5482
5483 /* Prepare the EEPROM */
5484 e1000_standby_eeprom(hw);
5485
5486 while (words_written < words) {
5487 /* Send the Write command (3-bit opcode + addr) */
5488 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5489 eeprom->opcode_bits);
5490
5491 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5492 eeprom->address_bits);
5493
5494 /* Send the data */
5495 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5496
5497 /* Toggle the CS line. This in effect tells the EEPROM to execute
5498 * the previous command.
5499 */
5500 e1000_standby_eeprom(hw);
5501
5502 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5503 * signal that the command has been completed by raising the DO signal.
5504 * If DO does not go high in 10 milliseconds, then error out.
5505 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005506 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005508 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509 udelay(50);
5510 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005511 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512 DEBUGOUT("EEPROM Write did not complete\n");
5513 return -E1000_ERR_EEPROM;
5514 }
5515
5516 /* Recover from write */
5517 e1000_standby_eeprom(hw);
5518
5519 words_written++;
5520 }
5521
5522 /* Send the write disable command to the EEPROM (3-bit opcode plus
5523 * 6/8-bit dummy address beginning with 10). It's less work to include
5524 * the 10 of the dummy address as part of the opcode than it is to shift
5525 * it over the correct number of bits for the address. This takes the
5526 * EEPROM out of write/erase mode.
5527 */
5528 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5529 (uint16_t)(eeprom->opcode_bits + 2));
5530
5531 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5532
5533 return E1000_SUCCESS;
5534}
5535
5536/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005537 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5538 * in the eeprom cache and the non modified values in the currently active bank
5539 * to the new bank.
5540 *
5541 * hw - Struct containing variables accessed by shared code
5542 * offset - offset of word in the EEPROM to read
5543 * data - word read from the EEPROM
5544 * words - number of words to read
5545 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005546static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005547e1000_commit_shadow_ram(struct e1000_hw *hw)
5548{
5549 uint32_t attempts = 100000;
5550 uint32_t eecd = 0;
5551 uint32_t flop = 0;
5552 uint32_t i = 0;
5553 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005554 uint32_t old_bank_offset = 0;
5555 uint32_t new_bank_offset = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005556 uint8_t low_byte = 0;
5557 uint8_t high_byte = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005558 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005559
5560 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005561 /* The flop register will be used to determine if flash type is STM */
5562 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005563 for (i=0; i < attempts; i++) {
5564 eecd = E1000_READ_REG(hw, EECD);
5565 if ((eecd & E1000_EECD_FLUPD) == 0) {
5566 break;
5567 }
5568 udelay(5);
5569 }
5570
5571 if (i == attempts) {
5572 return -E1000_ERR_EEPROM;
5573 }
5574
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005575 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005576 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5577 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5578 }
5579
5580 /* Perform the flash update */
5581 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5582
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005583 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005584 eecd = E1000_READ_REG(hw, EECD);
5585 if ((eecd & E1000_EECD_FLUPD) == 0) {
5586 break;
5587 }
5588 udelay(5);
5589 }
5590
5591 if (i == attempts) {
5592 return -E1000_ERR_EEPROM;
5593 }
5594 }
5595
Auke Kokcd94dd02006-06-27 09:08:22 -07005596 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5597 /* We're writing to the opposite bank so if we're on bank 1,
5598 * write to bank 0 etc. We also need to erase the segment that
5599 * is going to be written */
5600 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5601 new_bank_offset = hw->flash_bank_size * 2;
5602 old_bank_offset = 0;
5603 e1000_erase_ich8_4k_segment(hw, 1);
5604 } else {
5605 old_bank_offset = hw->flash_bank_size * 2;
5606 new_bank_offset = 0;
5607 e1000_erase_ich8_4k_segment(hw, 0);
5608 }
5609
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005610 sector_write_failed = FALSE;
5611 /* Loop for every byte in the shadow RAM,
5612 * which is in units of words. */
5613 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5614 /* Determine whether to write the value stored
5615 * in the other NVM bank or a modified value stored
5616 * in the shadow RAM */
5617 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5618 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5619 udelay(100);
5620 error = e1000_verify_write_ich8_byte(hw,
5621 (i << 1) + new_bank_offset, low_byte);
5622
5623 if (error != E1000_SUCCESS)
5624 sector_write_failed = TRUE;
5625 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005626 high_byte =
5627 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005628 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005629 }
5630 } else {
5631 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5632 &low_byte);
5633 udelay(100);
5634 error = e1000_verify_write_ich8_byte(hw,
5635 (i << 1) + new_bank_offset, low_byte);
5636
5637 if (error != E1000_SUCCESS)
5638 sector_write_failed = TRUE;
5639 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005640 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5641 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005642 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005643 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005644 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005645
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005646 /* If the write of the low byte was successful, go ahread and
5647 * write the high byte while checking to make sure that if it
5648 * is the signature byte, then it is handled properly */
5649 if (sector_write_failed == FALSE) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005650 /* If the word is 0x13, then make sure the signature bits
5651 * (15:14) are 11b until the commit has completed.
5652 * This will allow us to write 10b which indicates the
5653 * signature is valid. We want to do this after the write
5654 * has completed so that we don't mark the segment valid
5655 * while the write is still in progress */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005656 if (i == E1000_ICH_NVM_SIG_WORD)
5657 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
Auke Kokcd94dd02006-06-27 09:08:22 -07005658
5659 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005660 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005661 if (error != E1000_SUCCESS)
5662 sector_write_failed = TRUE;
5663
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005664 } else {
5665 /* If the write failed then break from the loop and
5666 * return an error */
5667 break;
5668 }
5669 }
5670
5671 /* Don't bother writing the segment valid bits if sector
5672 * programming failed. */
5673 if (sector_write_failed == FALSE) {
5674 /* Finally validate the new segment by setting bit 15:14
5675 * to 10b in word 0x13 , this can be done without an
5676 * erase as well since these bits are 11 to start with
5677 * and we need to change bit 14 to 0b */
5678 e1000_read_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005679 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005680 &high_byte);
5681 high_byte &= 0xBF;
5682 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005683 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005684 /* And invalidate the previously valid segment by setting
5685 * its signature word (0x13) high_byte to 0b. This can be
5686 * done without an erase because flash erase sets all bits
5687 * to 1's. We can write 1's to 0's without an erase */
5688 if (error == E1000_SUCCESS) {
5689 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005690 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005691 }
5692
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005693 /* Clear the now not used entry in the cache */
5694 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5695 hw->eeprom_shadow_ram[i].modified = FALSE;
5696 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005697 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005698 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005699 }
5700
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005701 return error;
5702}
5703
5704/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5706 * second function of dual function devices
5707 *
5708 * hw - Struct containing variables accessed by shared code
5709 *****************************************************************************/
5710int32_t
5711e1000_read_mac_addr(struct e1000_hw * hw)
5712{
5713 uint16_t offset;
5714 uint16_t eeprom_data, i;
5715
5716 DEBUGFUNC("e1000_read_mac_addr");
5717
Auke Kok8fc897b2006-08-28 14:56:16 -07005718 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005720 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721 DEBUGOUT("EEPROM Read Error\n");
5722 return -E1000_ERR_EEPROM;
5723 }
5724 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5725 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5726 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005727
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005728 switch (hw->mac_type) {
5729 default:
5730 break;
5731 case e1000_82546:
5732 case e1000_82546_rev_3:
5733 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005734 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005735 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005737 break;
5738 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739
Auke Kok8fc897b2006-08-28 14:56:16 -07005740 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741 hw->mac_addr[i] = hw->perm_mac_addr[i];
5742 return E1000_SUCCESS;
5743}
5744
5745/******************************************************************************
5746 * Initializes receive address filters.
5747 *
5748 * hw - Struct containing variables accessed by shared code
5749 *
5750 * Places the MAC address in receive address register 0 and clears the rest
5751 * of the receive addresss registers. Clears the multicast table. Assumes
5752 * the receiver is in reset when the routine is called.
5753 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005754static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755e1000_init_rx_addrs(struct e1000_hw *hw)
5756{
5757 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005758 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759
5760 DEBUGFUNC("e1000_init_rx_addrs");
5761
5762 /* Setup the receive address. */
5763 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5764
5765 e1000_rar_set(hw, hw->mac_addr, 0);
5766
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005767 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005768
5769 /* Reserve a spot for the Locally Administered Address to work around
5770 * an 82571 issue in which a reset on one port will reload the MAC on
5771 * the other port. */
5772 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5773 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005774 if (hw->mac_type == e1000_ich8lan)
5775 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5776
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777 /* Zero out the other 15 receive addresses. */
5778 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005779 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005781 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005783 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784 }
5785}
5786
5787/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 * Hashes an address to determine its location in the multicast table
5789 *
5790 * hw - Struct containing variables accessed by shared code
5791 * mc_addr - the multicast address to hash
5792 *****************************************************************************/
5793uint32_t
5794e1000_hash_mc_addr(struct e1000_hw *hw,
5795 uint8_t *mc_addr)
5796{
5797 uint32_t hash_value = 0;
5798
5799 /* The portion of the address that is used for the hash table is
5800 * determined by the mc_filter_type setting.
5801 */
5802 switch (hw->mc_filter_type) {
5803 /* [0] [1] [2] [3] [4] [5]
5804 * 01 AA 00 12 34 56
5805 * LSB MSB
5806 */
5807 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005808 if (hw->mac_type == e1000_ich8lan) {
5809 /* [47:38] i.e. 0x158 for above example address */
5810 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5811 } else {
5812 /* [47:36] i.e. 0x563 for above example address */
5813 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815 break;
5816 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005817 if (hw->mac_type == e1000_ich8lan) {
5818 /* [46:37] i.e. 0x2B1 for above example address */
5819 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5820 } else {
5821 /* [46:35] i.e. 0xAC6 for above example address */
5822 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 break;
5825 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005826 if (hw->mac_type == e1000_ich8lan) {
5827 /*[45:36] i.e. 0x163 for above example address */
5828 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5829 } else {
5830 /* [45:34] i.e. 0x5D8 for above example address */
5831 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 break;
5834 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005835 if (hw->mac_type == e1000_ich8lan) {
5836 /* [43:34] i.e. 0x18D for above example address */
5837 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5838 } else {
5839 /* [43:32] i.e. 0x634 for above example address */
5840 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 break;
5843 }
5844
5845 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005846 if (hw->mac_type == e1000_ich8lan)
5847 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005848
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849 return hash_value;
5850}
5851
5852/******************************************************************************
5853 * Sets the bit in the multicast table corresponding to the hash value.
5854 *
5855 * hw - Struct containing variables accessed by shared code
5856 * hash_value - Multicast address hash value
5857 *****************************************************************************/
5858void
5859e1000_mta_set(struct e1000_hw *hw,
5860 uint32_t hash_value)
5861{
5862 uint32_t hash_bit, hash_reg;
5863 uint32_t mta;
5864 uint32_t temp;
5865
5866 /* The MTA is a register array of 128 32-bit registers.
5867 * It is treated like an array of 4096 bits. We want to set
5868 * bit BitArray[hash_value]. So we figure out what register
5869 * the bit is in, read it, OR in the new bit, then write
5870 * back the new value. The register is determined by the
5871 * upper 7 bits of the hash value and the bit within that
5872 * register are determined by the lower 5 bits of the value.
5873 */
5874 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005875 if (hw->mac_type == e1000_ich8lan)
5876 hash_reg &= 0x1F;
Auke Kok90fb5132006-11-01 08:47:30 -08005877
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 hash_bit = hash_value & 0x1F;
5879
5880 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5881
5882 mta |= (1 << hash_bit);
5883
5884 /* If we are on an 82544 and we are trying to write an odd offset
5885 * in the MTA, save off the previous entry before writing and
5886 * restore the old value after writing.
5887 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005888 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5890 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005891 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005893 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 } else {
5895 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005896 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 }
5898}
5899
5900/******************************************************************************
5901 * Puts an ethernet address into a receive address register.
5902 *
5903 * hw - Struct containing variables accessed by shared code
5904 * addr - Address to put into receive address register
5905 * index - Receive address register to write
5906 *****************************************************************************/
5907void
5908e1000_rar_set(struct e1000_hw *hw,
5909 uint8_t *addr,
5910 uint32_t index)
5911{
5912 uint32_t rar_low, rar_high;
5913
5914 /* HW expects these in little endian so we reverse the byte order
5915 * from network order (big endian) to little endian
5916 */
5917 rar_low = ((uint32_t) addr[0] |
5918 ((uint32_t) addr[1] << 8) |
5919 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005920 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005922 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5923 * unit hang.
5924 *
5925 * Description:
5926 * If there are any Rx frames queued up or otherwise present in the HW
5927 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5928 * hang. To work around this issue, we have to disable receives and
5929 * flush out all Rx frames before we enable RSS. To do so, we modify we
5930 * redirect all Rx traffic to manageability and then reset the HW.
5931 * This flushes away Rx frames, and (since the redirections to
5932 * manageability persists across resets) keeps new ones from coming in
5933 * while we work. Then, we clear the Address Valid AV bit for all MAC
5934 * addresses and undo the re-direction to manageability.
5935 * Now, frames are coming in again, but the MAC won't accept them, so
5936 * far so good. We now proceed to initialize RSS (if necessary) and
5937 * configure the Rx unit. Last, we re-enable the AV bits and continue
5938 * on our merry way.
5939 */
5940 switch (hw->mac_type) {
5941 case e1000_82571:
5942 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005943 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005944 if (hw->leave_av_bit_off == TRUE)
5945 break;
5946 default:
5947 /* Indicate to hardware the Address is Valid. */
5948 rar_high |= E1000_RAH_AV;
5949 break;
5950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951
5952 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005953 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005955 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956}
5957
5958/******************************************************************************
5959 * Writes a value to the specified offset in the VLAN filter table.
5960 *
5961 * hw - Struct containing variables accessed by shared code
5962 * offset - Offset in VLAN filer table to write
5963 * value - Value to write into VLAN filter table
5964 *****************************************************************************/
5965void
5966e1000_write_vfta(struct e1000_hw *hw,
5967 uint32_t offset,
5968 uint32_t value)
5969{
5970 uint32_t temp;
5971
Auke Kokcd94dd02006-06-27 09:08:22 -07005972 if (hw->mac_type == e1000_ich8lan)
5973 return;
5974
5975 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5977 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005978 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005980 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981 } else {
5982 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005983 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984 }
5985}
5986
5987/******************************************************************************
5988 * Clears the VLAN filer table
5989 *
5990 * hw - Struct containing variables accessed by shared code
5991 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005992static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993e1000_clear_vfta(struct e1000_hw *hw)
5994{
5995 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005996 uint32_t vfta_value = 0;
5997 uint32_t vfta_offset = 0;
5998 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999
Auke Kokcd94dd02006-06-27 09:08:22 -07006000 if (hw->mac_type == e1000_ich8lan)
6001 return;
6002
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006003 if (hw->mac_type == e1000_82573) {
6004 if (hw->mng_cookie.vlan_id != 0) {
6005 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
6006 * ID. The following operations determine which 32b entry
6007 * (i.e. offset) into the array we want to set the VLAN ID
6008 * (i.e. bit) of the manageability unit. */
6009 vfta_offset = (hw->mng_cookie.vlan_id >>
6010 E1000_VFTA_ENTRY_SHIFT) &
6011 E1000_VFTA_ENTRY_MASK;
6012 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
6013 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
6014 }
6015 }
6016 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
6017 /* If the offset we want to clear is the same offset of the
6018 * manageability VLAN ID, then clear all bits except that of the
6019 * manageability unit */
6020 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6021 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07006022 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024}
6025
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006026static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027e1000_id_led_init(struct e1000_hw * hw)
6028{
6029 uint32_t ledctl;
6030 const uint32_t ledctl_mask = 0x000000FF;
6031 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6032 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6033 uint16_t eeprom_data, i, temp;
6034 const uint16_t led_mask = 0x0F;
6035
6036 DEBUGFUNC("e1000_id_led_init");
6037
Auke Kok8fc897b2006-08-28 14:56:16 -07006038 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 /* Nothing to do */
6040 return E1000_SUCCESS;
6041 }
6042
6043 ledctl = E1000_READ_REG(hw, LEDCTL);
6044 hw->ledctl_default = ledctl;
6045 hw->ledctl_mode1 = hw->ledctl_default;
6046 hw->ledctl_mode2 = hw->ledctl_default;
6047
Auke Kok8fc897b2006-08-28 14:56:16 -07006048 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049 DEBUGOUT("EEPROM Read Error\n");
6050 return -E1000_ERR_EEPROM;
6051 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006052
6053 if ((hw->mac_type == e1000_82573) &&
6054 (eeprom_data == ID_LED_RESERVED_82573))
6055 eeprom_data = ID_LED_DEFAULT_82573;
6056 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6057 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6058 if (hw->mac_type == e1000_ich8lan)
6059 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6060 else
6061 eeprom_data = ID_LED_DEFAULT;
6062 }
Auke Kok90fb5132006-11-01 08:47:30 -08006063
Auke Kokcd94dd02006-06-27 09:08:22 -07006064 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006066 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 case ID_LED_ON1_DEF2:
6068 case ID_LED_ON1_ON2:
6069 case ID_LED_ON1_OFF2:
6070 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6071 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6072 break;
6073 case ID_LED_OFF1_DEF2:
6074 case ID_LED_OFF1_ON2:
6075 case ID_LED_OFF1_OFF2:
6076 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6077 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6078 break;
6079 default:
6080 /* Do nothing */
6081 break;
6082 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006083 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 case ID_LED_DEF1_ON2:
6085 case ID_LED_ON1_ON2:
6086 case ID_LED_OFF1_ON2:
6087 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6088 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6089 break;
6090 case ID_LED_DEF1_OFF2:
6091 case ID_LED_ON1_OFF2:
6092 case ID_LED_OFF1_OFF2:
6093 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6094 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6095 break;
6096 default:
6097 /* Do nothing */
6098 break;
6099 }
6100 }
6101 return E1000_SUCCESS;
6102}
6103
6104/******************************************************************************
6105 * Prepares SW controlable LED for use and saves the current state of the LED.
6106 *
6107 * hw - Struct containing variables accessed by shared code
6108 *****************************************************************************/
6109int32_t
6110e1000_setup_led(struct e1000_hw *hw)
6111{
6112 uint32_t ledctl;
6113 int32_t ret_val = E1000_SUCCESS;
6114
6115 DEBUGFUNC("e1000_setup_led");
6116
Auke Kok8fc897b2006-08-28 14:56:16 -07006117 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 case e1000_82542_rev2_0:
6119 case e1000_82542_rev2_1:
6120 case e1000_82543:
6121 case e1000_82544:
6122 /* No setup necessary */
6123 break;
6124 case e1000_82541:
6125 case e1000_82547:
6126 case e1000_82541_rev_2:
6127 case e1000_82547_rev_2:
6128 /* Turn off PHY Smart Power Down (if enabled) */
6129 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6130 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006131 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132 return ret_val;
6133 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6134 (uint16_t)(hw->phy_spd_default &
6135 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006136 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 return ret_val;
6138 /* Fall Through */
6139 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006140 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 ledctl = E1000_READ_REG(hw, LEDCTL);
6142 /* Save current LEDCTL settings */
6143 hw->ledctl_default = ledctl;
6144 /* Turn off LED0 */
6145 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6146 E1000_LEDCTL_LED0_BLINK |
6147 E1000_LEDCTL_LED0_MODE_MASK);
6148 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6149 E1000_LEDCTL_LED0_MODE_SHIFT);
6150 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006151 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6153 break;
6154 }
6155
6156 return E1000_SUCCESS;
6157}
6158
Auke Kok8fc897b2006-08-28 14:56:16 -07006159
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006161 * Used on 82571 and later Si that has LED blink bits.
6162 * Callers must use their own timer and should have already called
6163 * e1000_id_led_init()
6164 * Call e1000_cleanup led() to stop blinking
6165 *
6166 * hw - Struct containing variables accessed by shared code
6167 *****************************************************************************/
6168int32_t
6169e1000_blink_led_start(struct e1000_hw *hw)
6170{
6171 int16_t i;
6172 uint32_t ledctl_blink = 0;
6173
6174 DEBUGFUNC("e1000_id_led_blink_on");
6175
6176 if (hw->mac_type < e1000_82571) {
6177 /* Nothing to do */
6178 return E1000_SUCCESS;
6179 }
6180 if (hw->media_type == e1000_media_type_fiber) {
6181 /* always blink LED0 for PCI-E fiber */
6182 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6183 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6184 } else {
6185 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6186 ledctl_blink = hw->ledctl_mode2;
6187 for (i=0; i < 4; i++)
6188 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6189 E1000_LEDCTL_MODE_LED_ON)
6190 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6191 }
6192
6193 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6194
6195 return E1000_SUCCESS;
6196}
6197
6198/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199 * Restores the saved state of the SW controlable LED.
6200 *
6201 * hw - Struct containing variables accessed by shared code
6202 *****************************************************************************/
6203int32_t
6204e1000_cleanup_led(struct e1000_hw *hw)
6205{
6206 int32_t ret_val = E1000_SUCCESS;
6207
6208 DEBUGFUNC("e1000_cleanup_led");
6209
Auke Kok8fc897b2006-08-28 14:56:16 -07006210 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 case e1000_82542_rev2_0:
6212 case e1000_82542_rev2_1:
6213 case e1000_82543:
6214 case e1000_82544:
6215 /* No cleanup necessary */
6216 break;
6217 case e1000_82541:
6218 case e1000_82547:
6219 case e1000_82541_rev_2:
6220 case e1000_82547_rev_2:
6221 /* Turn on PHY Smart Power Down (if previously enabled) */
6222 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6223 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006224 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 return ret_val;
6226 /* Fall Through */
6227 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006228 if (hw->phy_type == e1000_phy_ife) {
6229 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6230 break;
6231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 /* Restore LEDCTL settings */
6233 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6234 break;
6235 }
6236
6237 return E1000_SUCCESS;
6238}
6239
6240/******************************************************************************
6241 * Turns on the software controllable LED
6242 *
6243 * hw - Struct containing variables accessed by shared code
6244 *****************************************************************************/
6245int32_t
6246e1000_led_on(struct e1000_hw *hw)
6247{
6248 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6249
6250 DEBUGFUNC("e1000_led_on");
6251
Auke Kok8fc897b2006-08-28 14:56:16 -07006252 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 case e1000_82542_rev2_0:
6254 case e1000_82542_rev2_1:
6255 case e1000_82543:
6256 /* Set SW Defineable Pin 0 to turn on the LED */
6257 ctrl |= E1000_CTRL_SWDPIN0;
6258 ctrl |= E1000_CTRL_SWDPIO0;
6259 break;
6260 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006261 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262 /* Set SW Defineable Pin 0 to turn on the LED */
6263 ctrl |= E1000_CTRL_SWDPIN0;
6264 ctrl |= E1000_CTRL_SWDPIO0;
6265 } else {
6266 /* Clear SW Defineable Pin 0 to turn on the LED */
6267 ctrl &= ~E1000_CTRL_SWDPIN0;
6268 ctrl |= E1000_CTRL_SWDPIO0;
6269 }
6270 break;
6271 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006272 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 /* Clear SW Defineable Pin 0 to turn on the LED */
6274 ctrl &= ~E1000_CTRL_SWDPIN0;
6275 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006276 } else if (hw->phy_type == e1000_phy_ife) {
6277 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6278 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6279 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6281 return E1000_SUCCESS;
6282 }
6283 break;
6284 }
6285
6286 E1000_WRITE_REG(hw, CTRL, ctrl);
6287
6288 return E1000_SUCCESS;
6289}
6290
6291/******************************************************************************
6292 * Turns off the software controllable LED
6293 *
6294 * hw - Struct containing variables accessed by shared code
6295 *****************************************************************************/
6296int32_t
6297e1000_led_off(struct e1000_hw *hw)
6298{
6299 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6300
6301 DEBUGFUNC("e1000_led_off");
6302
Auke Kok8fc897b2006-08-28 14:56:16 -07006303 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304 case e1000_82542_rev2_0:
6305 case e1000_82542_rev2_1:
6306 case e1000_82543:
6307 /* Clear SW Defineable Pin 0 to turn off the LED */
6308 ctrl &= ~E1000_CTRL_SWDPIN0;
6309 ctrl |= E1000_CTRL_SWDPIO0;
6310 break;
6311 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006312 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313 /* Clear SW Defineable Pin 0 to turn off the LED */
6314 ctrl &= ~E1000_CTRL_SWDPIN0;
6315 ctrl |= E1000_CTRL_SWDPIO0;
6316 } else {
6317 /* Set SW Defineable Pin 0 to turn off the LED */
6318 ctrl |= E1000_CTRL_SWDPIN0;
6319 ctrl |= E1000_CTRL_SWDPIO0;
6320 }
6321 break;
6322 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006323 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 /* Set SW Defineable Pin 0 to turn off the LED */
6325 ctrl |= E1000_CTRL_SWDPIN0;
6326 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006327 } else if (hw->phy_type == e1000_phy_ife) {
6328 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6329 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6330 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6332 return E1000_SUCCESS;
6333 }
6334 break;
6335 }
6336
6337 E1000_WRITE_REG(hw, CTRL, ctrl);
6338
6339 return E1000_SUCCESS;
6340}
6341
6342/******************************************************************************
6343 * Clears all hardware statistics counters.
6344 *
6345 * hw - Struct containing variables accessed by shared code
6346 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006347static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348e1000_clear_hw_cntrs(struct e1000_hw *hw)
6349{
6350 volatile uint32_t temp;
6351
6352 temp = E1000_READ_REG(hw, CRCERRS);
6353 temp = E1000_READ_REG(hw, SYMERRS);
6354 temp = E1000_READ_REG(hw, MPC);
6355 temp = E1000_READ_REG(hw, SCC);
6356 temp = E1000_READ_REG(hw, ECOL);
6357 temp = E1000_READ_REG(hw, MCC);
6358 temp = E1000_READ_REG(hw, LATECOL);
6359 temp = E1000_READ_REG(hw, COLC);
6360 temp = E1000_READ_REG(hw, DC);
6361 temp = E1000_READ_REG(hw, SEC);
6362 temp = E1000_READ_REG(hw, RLEC);
6363 temp = E1000_READ_REG(hw, XONRXC);
6364 temp = E1000_READ_REG(hw, XONTXC);
6365 temp = E1000_READ_REG(hw, XOFFRXC);
6366 temp = E1000_READ_REG(hw, XOFFTXC);
6367 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006368
6369 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370 temp = E1000_READ_REG(hw, PRC64);
6371 temp = E1000_READ_REG(hw, PRC127);
6372 temp = E1000_READ_REG(hw, PRC255);
6373 temp = E1000_READ_REG(hw, PRC511);
6374 temp = E1000_READ_REG(hw, PRC1023);
6375 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006376 }
6377
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 temp = E1000_READ_REG(hw, GPRC);
6379 temp = E1000_READ_REG(hw, BPRC);
6380 temp = E1000_READ_REG(hw, MPRC);
6381 temp = E1000_READ_REG(hw, GPTC);
6382 temp = E1000_READ_REG(hw, GORCL);
6383 temp = E1000_READ_REG(hw, GORCH);
6384 temp = E1000_READ_REG(hw, GOTCL);
6385 temp = E1000_READ_REG(hw, GOTCH);
6386 temp = E1000_READ_REG(hw, RNBC);
6387 temp = E1000_READ_REG(hw, RUC);
6388 temp = E1000_READ_REG(hw, RFC);
6389 temp = E1000_READ_REG(hw, ROC);
6390 temp = E1000_READ_REG(hw, RJC);
6391 temp = E1000_READ_REG(hw, TORL);
6392 temp = E1000_READ_REG(hw, TORH);
6393 temp = E1000_READ_REG(hw, TOTL);
6394 temp = E1000_READ_REG(hw, TOTH);
6395 temp = E1000_READ_REG(hw, TPR);
6396 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006397
6398 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399 temp = E1000_READ_REG(hw, PTC64);
6400 temp = E1000_READ_REG(hw, PTC127);
6401 temp = E1000_READ_REG(hw, PTC255);
6402 temp = E1000_READ_REG(hw, PTC511);
6403 temp = E1000_READ_REG(hw, PTC1023);
6404 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006405 }
6406
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 temp = E1000_READ_REG(hw, MPTC);
6408 temp = E1000_READ_REG(hw, BPTC);
6409
Auke Kok8fc897b2006-08-28 14:56:16 -07006410 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411
6412 temp = E1000_READ_REG(hw, ALGNERRC);
6413 temp = E1000_READ_REG(hw, RXERRC);
6414 temp = E1000_READ_REG(hw, TNCRS);
6415 temp = E1000_READ_REG(hw, CEXTERR);
6416 temp = E1000_READ_REG(hw, TSCTC);
6417 temp = E1000_READ_REG(hw, TSCTFC);
6418
Auke Kok8fc897b2006-08-28 14:56:16 -07006419 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420
6421 temp = E1000_READ_REG(hw, MGTPRC);
6422 temp = E1000_READ_REG(hw, MGTPDC);
6423 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006424
Auke Kok8fc897b2006-08-28 14:56:16 -07006425 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006426
6427 temp = E1000_READ_REG(hw, IAC);
6428 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006429
6430 if (hw->mac_type == e1000_ich8lan) return;
6431
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006432 temp = E1000_READ_REG(hw, ICRXPTC);
6433 temp = E1000_READ_REG(hw, ICRXATC);
6434 temp = E1000_READ_REG(hw, ICTXPTC);
6435 temp = E1000_READ_REG(hw, ICTXATC);
6436 temp = E1000_READ_REG(hw, ICTXQEC);
6437 temp = E1000_READ_REG(hw, ICTXQMTC);
6438 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439}
6440
6441/******************************************************************************
6442 * Resets Adaptive IFS to its default state.
6443 *
6444 * hw - Struct containing variables accessed by shared code
6445 *
6446 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6447 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6448 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6449 * before calling this function.
6450 *****************************************************************************/
6451void
6452e1000_reset_adaptive(struct e1000_hw *hw)
6453{
6454 DEBUGFUNC("e1000_reset_adaptive");
6455
Auke Kok8fc897b2006-08-28 14:56:16 -07006456 if (hw->adaptive_ifs) {
6457 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 hw->current_ifs_val = 0;
6459 hw->ifs_min_val = IFS_MIN;
6460 hw->ifs_max_val = IFS_MAX;
6461 hw->ifs_step_size = IFS_STEP;
6462 hw->ifs_ratio = IFS_RATIO;
6463 }
6464 hw->in_ifs_mode = FALSE;
6465 E1000_WRITE_REG(hw, AIT, 0);
6466 } else {
6467 DEBUGOUT("Not in Adaptive IFS mode!\n");
6468 }
6469}
6470
6471/******************************************************************************
6472 * Called during the callback/watchdog routine to update IFS value based on
6473 * the ratio of transmits to collisions.
6474 *
6475 * hw - Struct containing variables accessed by shared code
6476 * tx_packets - Number of transmits since last callback
6477 * total_collisions - Number of collisions since last callback
6478 *****************************************************************************/
6479void
6480e1000_update_adaptive(struct e1000_hw *hw)
6481{
6482 DEBUGFUNC("e1000_update_adaptive");
6483
Auke Kok8fc897b2006-08-28 14:56:16 -07006484 if (hw->adaptive_ifs) {
6485 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6486 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006488 if (hw->current_ifs_val < hw->ifs_max_val) {
6489 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 hw->current_ifs_val = hw->ifs_min_val;
6491 else
6492 hw->current_ifs_val += hw->ifs_step_size;
6493 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6494 }
6495 }
6496 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006497 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 hw->current_ifs_val = 0;
6499 hw->in_ifs_mode = FALSE;
6500 E1000_WRITE_REG(hw, AIT, 0);
6501 }
6502 }
6503 } else {
6504 DEBUGOUT("Not in Adaptive IFS mode!\n");
6505 }
6506}
6507
6508/******************************************************************************
6509 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6510 *
6511 * hw - Struct containing variables accessed by shared code
6512 * frame_len - The length of the frame in question
6513 * mac_addr - The Ethernet destination address of the frame in question
6514 *****************************************************************************/
6515void
6516e1000_tbi_adjust_stats(struct e1000_hw *hw,
6517 struct e1000_hw_stats *stats,
6518 uint32_t frame_len,
6519 uint8_t *mac_addr)
6520{
6521 uint64_t carry_bit;
6522
6523 /* First adjust the frame length. */
6524 frame_len--;
6525 /* We need to adjust the statistics counters, since the hardware
6526 * counters overcount this packet as a CRC error and undercount
6527 * the packet as a good packet
6528 */
6529 /* This packet should not be counted as a CRC error. */
6530 stats->crcerrs--;
6531 /* This packet does count as a Good Packet Received. */
6532 stats->gprc++;
6533
6534 /* Adjust the Good Octets received counters */
6535 carry_bit = 0x80000000 & stats->gorcl;
6536 stats->gorcl += frame_len;
6537 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6538 * Received Count) was one before the addition,
6539 * AND it is zero after, then we lost the carry out,
6540 * need to add one to Gorch (Good Octets Received Count High).
6541 * This could be simplified if all environments supported
6542 * 64-bit integers.
6543 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006544 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 stats->gorch++;
6546 /* Is this a broadcast or multicast? Check broadcast first,
6547 * since the test for a multicast frame will test positive on
6548 * a broadcast frame.
6549 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006550 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 /* Broadcast packet */
6552 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006553 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 /* Multicast packet */
6555 stats->mprc++;
6556
Auke Kok8fc897b2006-08-28 14:56:16 -07006557 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558 /* In this case, the hardware has overcounted the number of
6559 * oversize frames.
6560 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006561 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 stats->roc--;
6563 }
6564
6565 /* Adjust the bin counters when the extra byte put the frame in the
6566 * wrong bin. Remember that the frame_len was adjusted above.
6567 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006568 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 stats->prc64++;
6570 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006571 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 stats->prc127++;
6573 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006574 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 stats->prc255++;
6576 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006577 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 stats->prc511++;
6579 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006580 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581 stats->prc1023++;
6582 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006583 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 stats->prc1522++;
6585 }
6586}
6587
6588/******************************************************************************
6589 * Gets the current PCI bus type, speed, and width of the hardware
6590 *
6591 * hw - Struct containing variables accessed by shared code
6592 *****************************************************************************/
6593void
6594e1000_get_bus_info(struct e1000_hw *hw)
6595{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006596 int32_t ret_val;
6597 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 uint32_t status;
6599
6600 switch (hw->mac_type) {
6601 case e1000_82542_rev2_0:
6602 case e1000_82542_rev2_1:
Jeff Kirsherc3813ae2006-12-15 10:37:32 +01006603 hw->bus_type = e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 hw->bus_speed = e1000_bus_speed_unknown;
6605 hw->bus_width = e1000_bus_width_unknown;
6606 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006607 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006608 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006609 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006610 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006611 hw->bus_type = e1000_bus_type_pci_express;
6612 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006613 ret_val = e1000_read_pcie_cap_reg(hw,
6614 PCI_EX_LINK_STATUS,
6615 &pci_ex_link_status);
6616 if (ret_val)
6617 hw->bus_width = e1000_bus_width_unknown;
6618 else
6619 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6620 PCI_EX_LINK_WIDTH_SHIFT;
6621 break;
6622 case e1000_ich8lan:
6623 hw->bus_type = e1000_bus_type_pci_express;
6624 hw->bus_speed = e1000_bus_speed_2500;
6625 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006626 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 default:
6628 status = E1000_READ_REG(hw, STATUS);
6629 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6630 e1000_bus_type_pcix : e1000_bus_type_pci;
6631
Auke Kok8fc897b2006-08-28 14:56:16 -07006632 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6634 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006635 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6637 e1000_bus_speed_66 : e1000_bus_speed_33;
6638 } else {
6639 switch (status & E1000_STATUS_PCIX_SPEED) {
6640 case E1000_STATUS_PCIX_SPEED_66:
6641 hw->bus_speed = e1000_bus_speed_66;
6642 break;
6643 case E1000_STATUS_PCIX_SPEED_100:
6644 hw->bus_speed = e1000_bus_speed_100;
6645 break;
6646 case E1000_STATUS_PCIX_SPEED_133:
6647 hw->bus_speed = e1000_bus_speed_133;
6648 break;
6649 default:
6650 hw->bus_speed = e1000_bus_speed_reserved;
6651 break;
6652 }
6653 }
6654 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6655 e1000_bus_width_64 : e1000_bus_width_32;
6656 break;
6657 }
6658}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659
6660/******************************************************************************
6661 * Writes a value to one of the devices registers using port I/O (as opposed to
6662 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6663 *
6664 * hw - Struct containing variables accessed by shared code
6665 * offset - offset to write to
6666 * value - value to write
6667 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006668static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669e1000_write_reg_io(struct e1000_hw *hw,
6670 uint32_t offset,
6671 uint32_t value)
6672{
6673 unsigned long io_addr = hw->io_base;
6674 unsigned long io_data = hw->io_base + 4;
6675
6676 e1000_io_write(hw, io_addr, offset);
6677 e1000_io_write(hw, io_data, value);
6678}
6679
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680/******************************************************************************
6681 * Estimates the cable length.
6682 *
6683 * hw - Struct containing variables accessed by shared code
6684 * min_length - The estimated minimum length
6685 * max_length - The estimated maximum length
6686 *
6687 * returns: - E1000_ERR_XXX
6688 * E1000_SUCCESS
6689 *
6690 * This function always returns a ranged length (minimum & maximum).
6691 * So for M88 phy's, this function interprets the one value returned from the
6692 * register to the minimum and maximum range.
6693 * For IGP phy's, the function calculates the range by the AGC registers.
6694 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006695static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696e1000_get_cable_length(struct e1000_hw *hw,
6697 uint16_t *min_length,
6698 uint16_t *max_length)
6699{
6700 int32_t ret_val;
6701 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 uint16_t i, phy_data;
6703 uint16_t cable_length;
6704
6705 DEBUGFUNC("e1000_get_cable_length");
6706
6707 *min_length = *max_length = 0;
6708
6709 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006710 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006711
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6713 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006714 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 return ret_val;
6716 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6717 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6718
6719 /* Convert the enum value to ranged values */
6720 switch (cable_length) {
6721 case e1000_cable_length_50:
6722 *min_length = 0;
6723 *max_length = e1000_igp_cable_length_50;
6724 break;
6725 case e1000_cable_length_50_80:
6726 *min_length = e1000_igp_cable_length_50;
6727 *max_length = e1000_igp_cable_length_80;
6728 break;
6729 case e1000_cable_length_80_110:
6730 *min_length = e1000_igp_cable_length_80;
6731 *max_length = e1000_igp_cable_length_110;
6732 break;
6733 case e1000_cable_length_110_140:
6734 *min_length = e1000_igp_cable_length_110;
6735 *max_length = e1000_igp_cable_length_140;
6736 break;
6737 case e1000_cable_length_140:
6738 *min_length = e1000_igp_cable_length_140;
6739 *max_length = e1000_igp_cable_length_170;
6740 break;
6741 default:
6742 return -E1000_ERR_PHY;
6743 break;
6744 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006745 } else if (hw->phy_type == e1000_phy_gg82563) {
6746 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6747 &phy_data);
6748 if (ret_val)
6749 return ret_val;
6750 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6751
6752 switch (cable_length) {
6753 case e1000_gg_cable_length_60:
6754 *min_length = 0;
6755 *max_length = e1000_igp_cable_length_60;
6756 break;
6757 case e1000_gg_cable_length_60_115:
6758 *min_length = e1000_igp_cable_length_60;
6759 *max_length = e1000_igp_cable_length_115;
6760 break;
6761 case e1000_gg_cable_length_115_150:
6762 *min_length = e1000_igp_cable_length_115;
6763 *max_length = e1000_igp_cable_length_150;
6764 break;
6765 case e1000_gg_cable_length_150:
6766 *min_length = e1000_igp_cable_length_150;
6767 *max_length = e1000_igp_cable_length_180;
6768 break;
6769 default:
6770 return -E1000_ERR_PHY;
6771 break;
6772 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006773 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006774 uint16_t cur_agc_value;
6775 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6777 {IGP01E1000_PHY_AGC_A,
6778 IGP01E1000_PHY_AGC_B,
6779 IGP01E1000_PHY_AGC_C,
6780 IGP01E1000_PHY_AGC_D};
6781 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006782 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783
6784 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006785 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 return ret_val;
6787
Auke Kokcd94dd02006-06-27 09:08:22 -07006788 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789
Auke Kokcd94dd02006-06-27 09:08:22 -07006790 /* Value bound check. */
6791 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6792 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006793 return -E1000_ERR_PHY;
6794
Auke Kokcd94dd02006-06-27 09:08:22 -07006795 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796
6797 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006798 if (min_agc_value > cur_agc_value)
6799 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800 }
6801
6802 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006803 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6804 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805
6806 /* Get the average length of the remaining 3 channels */
6807 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6808 } else {
6809 /* Get the average length of all the 4 channels. */
6810 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6811 }
6812
6813 /* Set the range of the calculated length. */
6814 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6815 IGP01E1000_AGC_RANGE) > 0) ?
6816 (e1000_igp_cable_length_table[agc_value] -
6817 IGP01E1000_AGC_RANGE) : 0;
6818 *max_length = e1000_igp_cable_length_table[agc_value] +
6819 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006820 } else if (hw->phy_type == e1000_phy_igp_2 ||
6821 hw->phy_type == e1000_phy_igp_3) {
6822 uint16_t cur_agc_index, max_agc_index = 0;
6823 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006824 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6825 {IGP02E1000_PHY_AGC_A,
6826 IGP02E1000_PHY_AGC_B,
6827 IGP02E1000_PHY_AGC_C,
6828 IGP02E1000_PHY_AGC_D};
6829 /* Read the AGC registers for all channels */
6830 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6831 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6832 if (ret_val)
6833 return ret_val;
6834
Auke Kok8fc897b2006-08-28 14:56:16 -07006835 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006836 * fine gain values. The result is a number that can be put into
6837 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006838 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6839 IGP02E1000_AGC_LENGTH_MASK;
6840
6841 /* Array index bound check. */
6842 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6843 (cur_agc_index == 0))
6844 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006845
6846 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006847 if (e1000_igp_2_cable_length_table[min_agc_index] >
6848 e1000_igp_2_cable_length_table[cur_agc_index])
6849 min_agc_index = cur_agc_index;
6850 if (e1000_igp_2_cable_length_table[max_agc_index] <
6851 e1000_igp_2_cable_length_table[cur_agc_index])
6852 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006853
Auke Kokcd94dd02006-06-27 09:08:22 -07006854 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006855 }
6856
Auke Kokcd94dd02006-06-27 09:08:22 -07006857 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6858 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006859 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6860
6861 /* Calculate cable length with the error range of +/- 10 meters. */
6862 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6863 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6864 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865 }
6866
6867 return E1000_SUCCESS;
6868}
6869
6870/******************************************************************************
6871 * Check the cable polarity
6872 *
6873 * hw - Struct containing variables accessed by shared code
6874 * polarity - output parameter : 0 - Polarity is not reversed
6875 * 1 - Polarity is reversed.
6876 *
6877 * returns: - E1000_ERR_XXX
6878 * E1000_SUCCESS
6879 *
6880 * For phy's older then IGP, this function simply reads the polarity bit in the
6881 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6882 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6883 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6884 * IGP01E1000_PHY_PCS_INIT_REG.
6885 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006886static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006887e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006888 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889{
6890 int32_t ret_val;
6891 uint16_t phy_data;
6892
6893 DEBUGFUNC("e1000_check_polarity");
6894
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006895 if ((hw->phy_type == e1000_phy_m88) ||
6896 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 /* return the Polarity bit in the Status register. */
6898 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6899 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006900 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006901 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006902 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6903 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6904 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6905
Auke Kokcd94dd02006-06-27 09:08:22 -07006906 } else if (hw->phy_type == e1000_phy_igp ||
6907 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006908 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006909 /* Read the Status register to check the speed */
6910 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6911 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006912 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913 return ret_val;
6914
6915 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6916 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006917 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006918 IGP01E1000_PSSR_SPEED_1000MBPS) {
6919
6920 /* Read the GIG initialization PCS register (0x00B4) */
6921 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6922 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006923 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 return ret_val;
6925
6926 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006927 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6928 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929 } else {
6930 /* For 10 Mbps, read the polarity bit in the status register. (for
6931 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006932 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6933 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006934 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006935 } else if (hw->phy_type == e1000_phy_ife) {
6936 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6937 &phy_data);
6938 if (ret_val)
6939 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006940 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6941 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6942 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943 }
6944 return E1000_SUCCESS;
6945}
6946
6947/******************************************************************************
6948 * Check if Downshift occured
6949 *
6950 * hw - Struct containing variables accessed by shared code
6951 * downshift - output parameter : 0 - No Downshift ocured.
6952 * 1 - Downshift ocured.
6953 *
6954 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006955 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006956 *
6957 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6958 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6959 * Link Health register. In IGP this bit is latched high, so the driver must
6960 * read it immediately after link is established.
6961 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006962static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006963e1000_check_downshift(struct e1000_hw *hw)
6964{
6965 int32_t ret_val;
6966 uint16_t phy_data;
6967
6968 DEBUGFUNC("e1000_check_downshift");
6969
Auke Kokcd94dd02006-06-27 09:08:22 -07006970 if (hw->phy_type == e1000_phy_igp ||
6971 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006972 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006973 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6974 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006975 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 return ret_val;
6977
6978 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006979 } else if ((hw->phy_type == e1000_phy_m88) ||
6980 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006981 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6982 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006983 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984 return ret_val;
6985
6986 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6987 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006988 } else if (hw->phy_type == e1000_phy_ife) {
6989 /* e1000_phy_ife supports 10/100 speed only */
6990 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006992
Linus Torvalds1da177e2005-04-16 15:20:36 -07006993 return E1000_SUCCESS;
6994}
6995
6996/*****************************************************************************
6997 *
6998 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6999 * gigabit link is achieved to improve link quality.
7000 *
7001 * hw: Struct containing variables accessed by shared code
7002 *
7003 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7004 * E1000_SUCCESS at any other case.
7005 *
7006 ****************************************************************************/
7007
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007008static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007009e1000_config_dsp_after_link_change(struct e1000_hw *hw,
7010 boolean_t link_up)
7011{
7012 int32_t ret_val;
7013 uint16_t phy_data, phy_saved_data, speed, duplex, i;
7014 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
7015 {IGP01E1000_PHY_AGC_PARAM_A,
7016 IGP01E1000_PHY_AGC_PARAM_B,
7017 IGP01E1000_PHY_AGC_PARAM_C,
7018 IGP01E1000_PHY_AGC_PARAM_D};
7019 uint16_t min_length, max_length;
7020
7021 DEBUGFUNC("e1000_config_dsp_after_link_change");
7022
Auke Kok8fc897b2006-08-28 14:56:16 -07007023 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 return E1000_SUCCESS;
7025
Auke Kok8fc897b2006-08-28 14:56:16 -07007026 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007027 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07007028 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007029 DEBUGOUT("Error getting link speed and duplex\n");
7030 return ret_val;
7031 }
7032
Auke Kok8fc897b2006-08-28 14:56:16 -07007033 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034
Auke Kokcd94dd02006-06-27 09:08:22 -07007035 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7036 if (ret_val)
7037 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038
Auke Kok8fc897b2006-08-28 14:56:16 -07007039 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 min_length >= e1000_igp_cable_length_50) {
7041
Auke Kok8fc897b2006-08-28 14:56:16 -07007042 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7044 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007045 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007046 return ret_val;
7047
7048 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7049
7050 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7051 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007052 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 return ret_val;
7054 }
7055 hw->dsp_config_state = e1000_dsp_config_activated;
7056 }
7057
Auke Kok8fc897b2006-08-28 14:56:16 -07007058 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 (min_length < e1000_igp_cable_length_50)) {
7060
7061 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7062 uint32_t idle_errs = 0;
7063
7064 /* clear previous idle error counts */
7065 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7066 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007067 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068 return ret_val;
7069
Auke Kok8fc897b2006-08-28 14:56:16 -07007070 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071 udelay(1000);
7072 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7073 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007074 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075 return ret_val;
7076
7077 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007078 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007079 hw->ffe_config_state = e1000_ffe_config_active;
7080
7081 ret_val = e1000_write_phy_reg(hw,
7082 IGP01E1000_PHY_DSP_FFE,
7083 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007084 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085 return ret_val;
7086 break;
7087 }
7088
Auke Kok8fc897b2006-08-28 14:56:16 -07007089 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007090 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7091 }
7092 }
7093 }
7094 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007095 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007096 /* Save off the current value of register 0x2F5B to be restored at
7097 * the end of the routines. */
7098 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7099
Auke Kok8fc897b2006-08-28 14:56:16 -07007100 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007101 return ret_val;
7102
7103 /* Disable the PHY transmitter */
7104 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7105
Auke Kok8fc897b2006-08-28 14:56:16 -07007106 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007107 return ret_val;
7108
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007109 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110
7111 ret_val = e1000_write_phy_reg(hw, 0x0000,
7112 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007113 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007114 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007115 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007116 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007117 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007118 return ret_val;
7119
7120 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7121 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7122
7123 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007124 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007125 return ret_val;
7126 }
7127
7128 ret_val = e1000_write_phy_reg(hw, 0x0000,
7129 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007130 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007131 return ret_val;
7132
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007133 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007134
7135 /* Now enable the transmitter */
7136 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7137
Auke Kok8fc897b2006-08-28 14:56:16 -07007138 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139 return ret_val;
7140
7141 hw->dsp_config_state = e1000_dsp_config_enabled;
7142 }
7143
Auke Kok8fc897b2006-08-28 14:56:16 -07007144 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007145 /* Save off the current value of register 0x2F5B to be restored at
7146 * the end of the routines. */
7147 ret_val = e1000_read_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 /* Disable the PHY transmitter */
7153 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7154
Auke Kok8fc897b2006-08-28 14:56:16 -07007155 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007156 return ret_val;
7157
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007158 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007159
7160 ret_val = e1000_write_phy_reg(hw, 0x0000,
7161 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007162 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007163 return ret_val;
7164 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7165 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007166 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007167 return ret_val;
7168
7169 ret_val = e1000_write_phy_reg(hw, 0x0000,
7170 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007171 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007172 return ret_val;
7173
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007174 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007175
7176 /* Now enable the transmitter */
7177 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7178
Auke Kok8fc897b2006-08-28 14:56:16 -07007179 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007180 return ret_val;
7181
7182 hw->ffe_config_state = e1000_ffe_config_enabled;
7183 }
7184 }
7185 return E1000_SUCCESS;
7186}
7187
7188/*****************************************************************************
7189 * Set PHY to class A mode
7190 * Assumes the following operations will follow to enable the new class mode.
7191 * 1. Do a PHY soft reset
7192 * 2. Restart auto-negotiation or force link.
7193 *
7194 * hw - Struct containing variables accessed by shared code
7195 ****************************************************************************/
7196static int32_t
7197e1000_set_phy_mode(struct e1000_hw *hw)
7198{
7199 int32_t ret_val;
7200 uint16_t eeprom_data;
7201
7202 DEBUGFUNC("e1000_set_phy_mode");
7203
Auke Kok8fc897b2006-08-28 14:56:16 -07007204 if ((hw->mac_type == e1000_82545_rev_3) &&
7205 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007206 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007207 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007208 return ret_val;
7209 }
7210
Auke Kok8fc897b2006-08-28 14:56:16 -07007211 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7212 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007213 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007214 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215 return ret_val;
7216 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007217 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218 return ret_val;
7219
7220 hw->phy_reset_disable = FALSE;
7221 }
7222 }
7223
7224 return E1000_SUCCESS;
7225}
7226
7227/*****************************************************************************
7228 *
7229 * This function sets the lplu state according to the active flag. When
7230 * activating lplu this function also disables smart speed and vise versa.
7231 * lplu will not be activated unless the device autonegotiation advertisment
7232 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7233 * hw: Struct containing variables accessed by shared code
7234 * active - true to enable lplu false to disable lplu.
7235 *
7236 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7237 * E1000_SUCCESS at any other case.
7238 *
7239 ****************************************************************************/
7240
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007241static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007242e1000_set_d3_lplu_state(struct e1000_hw *hw,
7243 boolean_t active)
7244{
Auke Kokcd94dd02006-06-27 09:08:22 -07007245 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007246 int32_t ret_val;
7247 uint16_t phy_data;
7248 DEBUGFUNC("e1000_set_d3_lplu_state");
7249
Auke Kokcd94dd02006-06-27 09:08:22 -07007250 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7251 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007252 return E1000_SUCCESS;
7253
7254 /* During driver activity LPLU should not be used or it will attain link
7255 * from the lowest speeds starting from 10Mbps. The capability is used for
7256 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007257 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007258 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007259 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007260 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007261 } else if (hw->mac_type == e1000_ich8lan) {
7262 /* MAC writes into PHY register based on the state transition
7263 * and start auto-negotiation. SW driver can overwrite the settings
7264 * in CSR PHY power control E1000_PHY_CTRL register. */
7265 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007266 } else {
7267 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007268 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007269 return ret_val;
7270 }
7271
Auke Kok8fc897b2006-08-28 14:56:16 -07007272 if (!active) {
7273 if (hw->mac_type == e1000_82541_rev_2 ||
7274 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007275 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7276 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007277 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007278 return ret_val;
7279 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007280 if (hw->mac_type == e1000_ich8lan) {
7281 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7282 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7283 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007284 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7285 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7286 phy_data);
7287 if (ret_val)
7288 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007289 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291
7292 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7293 * Dx states where the power conservation is most important. During
7294 * driver activity we should enable SmartSpeed, so performance is
7295 * maintained. */
7296 if (hw->smart_speed == e1000_smart_speed_on) {
7297 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7298 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007299 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007300 return ret_val;
7301
7302 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7303 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7304 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007305 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007306 return ret_val;
7307 } else if (hw->smart_speed == e1000_smart_speed_off) {
7308 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7309 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007310 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007311 return ret_val;
7312
7313 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7314 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7315 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007316 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007317 return ret_val;
7318 }
7319
Auke Kok8fc897b2006-08-28 14:56:16 -07007320 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7321 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7322 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007323
Auke Kok8fc897b2006-08-28 14:56:16 -07007324 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007325 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007326 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7327 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007328 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007329 return ret_val;
7330 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007331 if (hw->mac_type == e1000_ich8lan) {
7332 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7333 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7334 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007335 phy_data |= IGP02E1000_PM_D3_LPLU;
7336 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7337 phy_data);
7338 if (ret_val)
7339 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007340 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007341 }
7342
7343 /* When LPLU is enabled we should disable SmartSpeed */
7344 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007345 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007346 return ret_val;
7347
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007348 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7349 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007350 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007351 return ret_val;
7352
7353 }
7354 return E1000_SUCCESS;
7355}
7356
7357/*****************************************************************************
7358 *
7359 * This function sets the lplu d0 state according to the active flag. When
7360 * activating lplu this function also disables smart speed and vise versa.
7361 * lplu will not be activated unless the device autonegotiation advertisment
7362 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7363 * hw: Struct containing variables accessed by shared code
7364 * active - true to enable lplu false to disable lplu.
7365 *
7366 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7367 * E1000_SUCCESS at any other case.
7368 *
7369 ****************************************************************************/
7370
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007371static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007372e1000_set_d0_lplu_state(struct e1000_hw *hw,
7373 boolean_t active)
7374{
Auke Kokcd94dd02006-06-27 09:08:22 -07007375 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007376 int32_t ret_val;
7377 uint16_t phy_data;
7378 DEBUGFUNC("e1000_set_d0_lplu_state");
7379
Auke Kok8fc897b2006-08-28 14:56:16 -07007380 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007381 return E1000_SUCCESS;
7382
Auke Kokcd94dd02006-06-27 09:08:22 -07007383 if (hw->mac_type == e1000_ich8lan) {
7384 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7385 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007386 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007387 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007388 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007389 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007390
7391 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007392 if (hw->mac_type == e1000_ich8lan) {
7393 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7394 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7395 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007396 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7397 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7398 if (ret_val)
7399 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007400 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007401
7402 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7403 * Dx states where the power conservation is most important. During
7404 * driver activity we should enable SmartSpeed, so performance is
7405 * maintained. */
7406 if (hw->smart_speed == e1000_smart_speed_on) {
7407 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7408 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007409 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007410 return ret_val;
7411
7412 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7413 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7414 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007415 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007416 return ret_val;
7417 } else if (hw->smart_speed == e1000_smart_speed_off) {
7418 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7419 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007420 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007421 return ret_val;
7422
7423 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7424 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7425 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007426 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007427 return ret_val;
7428 }
7429
7430
7431 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007432
Auke Kokcd94dd02006-06-27 09:08:22 -07007433 if (hw->mac_type == e1000_ich8lan) {
7434 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7435 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7436 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007437 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007438 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7439 if (ret_val)
7440 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007441 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007442
Linus Torvalds1da177e2005-04-16 15:20:36 -07007443 /* When LPLU is enabled we should disable SmartSpeed */
7444 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007445 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007446 return ret_val;
7447
7448 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7449 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007450 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007451 return ret_val;
7452
7453 }
7454 return E1000_SUCCESS;
7455}
7456
7457/******************************************************************************
7458 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7459 *
7460 * hw - Struct containing variables accessed by shared code
7461 *****************************************************************************/
7462static int32_t
7463e1000_set_vco_speed(struct e1000_hw *hw)
7464{
7465 int32_t ret_val;
7466 uint16_t default_page = 0;
7467 uint16_t phy_data;
7468
7469 DEBUGFUNC("e1000_set_vco_speed");
7470
Auke Kok8fc897b2006-08-28 14:56:16 -07007471 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007472 case e1000_82545_rev_3:
7473 case e1000_82546_rev_3:
7474 break;
7475 default:
7476 return E1000_SUCCESS;
7477 }
7478
7479 /* Set PHY register 30, page 5, bit 8 to 0 */
7480
7481 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007482 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007483 return ret_val;
7484
7485 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007486 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007487 return ret_val;
7488
7489 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007490 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007491 return ret_val;
7492
7493 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7494 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007495 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007496 return ret_val;
7497
7498 /* Set PHY register 30, page 4, bit 11 to 1 */
7499
7500 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007501 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007502 return ret_val;
7503
7504 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007505 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007506 return ret_val;
7507
7508 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7509 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007510 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007511 return ret_val;
7512
7513 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007514 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007515 return ret_val;
7516
7517 return E1000_SUCCESS;
7518}
7519
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007520
7521/*****************************************************************************
7522 * This function reads the cookie from ARC ram.
7523 *
7524 * returns: - E1000_SUCCESS .
7525 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007526static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007527e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7528{
7529 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007530 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007531 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7532
7533 length = (length >> 2);
7534 offset = (offset >> 2);
7535
7536 for (i = 0; i < length; i++) {
7537 *((uint32_t *) buffer + i) =
7538 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7539 }
7540 return E1000_SUCCESS;
7541}
7542
7543
7544/*****************************************************************************
7545 * This function checks whether the HOST IF is enabled for command operaton
7546 * and also checks whether the previous command is completed.
7547 * It busy waits in case of previous command is not completed.
7548 *
Auke Kok76c224b2006-05-23 13:36:06 -07007549 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007550 * timeout
7551 * - E1000_SUCCESS for success.
7552 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007553static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007554e1000_mng_enable_host_if(struct e1000_hw * hw)
7555{
7556 uint32_t hicr;
7557 uint8_t i;
7558
7559 /* Check that the host interface is enabled. */
7560 hicr = E1000_READ_REG(hw, HICR);
7561 if ((hicr & E1000_HICR_EN) == 0) {
7562 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7563 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7564 }
7565 /* check the previous command is completed */
7566 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7567 hicr = E1000_READ_REG(hw, HICR);
7568 if (!(hicr & E1000_HICR_C))
7569 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007570 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007571 }
7572
Auke Kok76c224b2006-05-23 13:36:06 -07007573 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007574 DEBUGOUT("Previous command timeout failed .\n");
7575 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7576 }
7577 return E1000_SUCCESS;
7578}
7579
7580/*****************************************************************************
7581 * This function writes the buffer content at the offset given on the host if.
7582 * It also does alignment considerations to do the writes in most efficient way.
7583 * Also fills up the sum of the buffer in *buffer parameter.
7584 *
7585 * returns - E1000_SUCCESS for success.
7586 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007587static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007588e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7589 uint16_t length, uint16_t offset, uint8_t *sum)
7590{
7591 uint8_t *tmp;
7592 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007593 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007594 uint16_t remaining, i, j, prev_bytes;
7595
7596 /* sum = only sum of the data and it is not checksum */
7597
7598 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7599 return -E1000_ERR_PARAM;
7600 }
7601
7602 tmp = (uint8_t *)&data;
7603 prev_bytes = offset & 0x3;
7604 offset &= 0xFFFC;
7605 offset >>= 2;
7606
7607 if (prev_bytes) {
7608 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7609 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7610 *(tmp + j) = *bufptr++;
7611 *sum += *(tmp + j);
7612 }
7613 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7614 length -= j - prev_bytes;
7615 offset++;
7616 }
7617
7618 remaining = length & 0x3;
7619 length -= remaining;
7620
7621 /* Calculate length in DWORDs */
7622 length >>= 2;
7623
7624 /* The device driver writes the relevant command block into the
7625 * ram area. */
7626 for (i = 0; i < length; i++) {
7627 for (j = 0; j < sizeof(uint32_t); j++) {
7628 *(tmp + j) = *bufptr++;
7629 *sum += *(tmp + j);
7630 }
7631
7632 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7633 }
7634 if (remaining) {
7635 for (j = 0; j < sizeof(uint32_t); j++) {
7636 if (j < remaining)
7637 *(tmp + j) = *bufptr++;
7638 else
7639 *(tmp + j) = 0;
7640
7641 *sum += *(tmp + j);
7642 }
7643 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7644 }
7645
7646 return E1000_SUCCESS;
7647}
7648
7649
7650/*****************************************************************************
7651 * This function writes the command header after does the checksum calculation.
7652 *
7653 * returns - E1000_SUCCESS for success.
7654 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007655static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007656e1000_mng_write_cmd_header(struct e1000_hw * hw,
7657 struct e1000_host_mng_command_header * hdr)
7658{
7659 uint16_t i;
7660 uint8_t sum;
7661 uint8_t *buffer;
7662
7663 /* Write the whole command header structure which includes sum of
7664 * the buffer */
7665
7666 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7667
7668 sum = hdr->checksum;
7669 hdr->checksum = 0;
7670
7671 buffer = (uint8_t *) hdr;
7672 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007673 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007674 sum += buffer[i];
7675
7676 hdr->checksum = 0 - sum;
7677
7678 length >>= 2;
7679 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007680 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007681 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007682 E1000_WRITE_FLUSH(hw);
7683 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007684
7685 return E1000_SUCCESS;
7686}
7687
7688
7689/*****************************************************************************
7690 * This function indicates to ARC that a new command is pending which completes
7691 * one write operation by the driver.
7692 *
7693 * returns - E1000_SUCCESS for success.
7694 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007695static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007696e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007697{
7698 uint32_t hicr;
7699
7700 hicr = E1000_READ_REG(hw, HICR);
7701 /* Setting this bit tells the ARC that a new command is pending. */
7702 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7703
7704 return E1000_SUCCESS;
7705}
7706
7707
7708/*****************************************************************************
7709 * This function checks the mode of the firmware.
7710 *
7711 * returns - TRUE when the mode is IAMT or FALSE.
7712 ****************************************************************************/
7713boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007714e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007715{
7716 uint32_t fwsm;
7717
7718 fwsm = E1000_READ_REG(hw, FWSM);
7719
Auke Kokcd94dd02006-06-27 09:08:22 -07007720 if (hw->mac_type == e1000_ich8lan) {
7721 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7722 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7723 return TRUE;
7724 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7725 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007726 return TRUE;
7727
7728 return FALSE;
7729}
7730
7731
7732/*****************************************************************************
7733 * This function writes the dhcp info .
7734 ****************************************************************************/
7735int32_t
7736e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007737 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007738{
7739 int32_t ret_val;
7740 struct e1000_host_mng_command_header hdr;
7741
7742 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7743 hdr.command_length = length;
7744 hdr.reserved1 = 0;
7745 hdr.reserved2 = 0;
7746 hdr.checksum = 0;
7747
7748 ret_val = e1000_mng_enable_host_if(hw);
7749 if (ret_val == E1000_SUCCESS) {
7750 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7751 &(hdr.checksum));
7752 if (ret_val == E1000_SUCCESS) {
7753 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7754 if (ret_val == E1000_SUCCESS)
7755 ret_val = e1000_mng_write_commit(hw);
7756 }
7757 }
7758 return ret_val;
7759}
7760
7761
7762/*****************************************************************************
7763 * This function calculates the checksum.
7764 *
7765 * returns - checksum of buffer contents.
7766 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007767static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007768e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7769{
7770 uint8_t sum = 0;
7771 uint32_t i;
7772
7773 if (!buffer)
7774 return 0;
7775
7776 for (i=0; i < length; i++)
7777 sum += buffer[i];
7778
7779 return (uint8_t) (0 - sum);
7780}
7781
7782/*****************************************************************************
7783 * This function checks whether tx pkt filtering needs to be enabled or not.
7784 *
7785 * returns - TRUE for packet filtering or FALSE.
7786 ****************************************************************************/
7787boolean_t
7788e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7789{
7790 /* called in init as well as watchdog timer functions */
7791
7792 int32_t ret_val, checksum;
7793 boolean_t tx_filter = FALSE;
7794 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7795 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7796
7797 if (e1000_check_mng_mode(hw)) {
7798 ret_val = e1000_mng_enable_host_if(hw);
7799 if (ret_val == E1000_SUCCESS) {
7800 ret_val = e1000_host_if_read_cookie(hw, buffer);
7801 if (ret_val == E1000_SUCCESS) {
7802 checksum = hdr->checksum;
7803 hdr->checksum = 0;
7804 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7805 checksum == e1000_calculate_mng_checksum((char *)buffer,
7806 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7807 if (hdr->status &
7808 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7809 tx_filter = TRUE;
7810 } else
7811 tx_filter = TRUE;
7812 } else
7813 tx_filter = TRUE;
7814 }
7815 }
7816
7817 hw->tx_pkt_filtering = tx_filter;
7818 return tx_filter;
7819}
7820
7821/******************************************************************************
7822 * Verifies the hardware needs to allow ARPs to be processed by the host
7823 *
7824 * hw - Struct containing variables accessed by shared code
7825 *
7826 * returns: - TRUE/FALSE
7827 *
7828 *****************************************************************************/
7829uint32_t
7830e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7831{
7832 uint32_t manc;
7833 uint32_t fwsm, factps;
7834
7835 if (hw->asf_firmware_present) {
7836 manc = E1000_READ_REG(hw, MANC);
7837
7838 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7839 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7840 return FALSE;
7841 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7842 fwsm = E1000_READ_REG(hw, FWSM);
7843 factps = E1000_READ_REG(hw, FACTPS);
7844
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05007845 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7846 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007847 return TRUE;
7848 } else
7849 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7850 return TRUE;
7851 }
7852 return FALSE;
7853}
7854
Linus Torvalds1da177e2005-04-16 15:20:36 -07007855static int32_t
7856e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7857{
7858 int32_t ret_val;
7859 uint16_t mii_status_reg;
7860 uint16_t i;
7861
7862 /* Polarity reversal workaround for forced 10F/10H links. */
7863
7864 /* Disable the transmitter on the PHY */
7865
7866 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007867 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007868 return ret_val;
7869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007870 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007871 return ret_val;
7872
7873 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007874 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007875 return ret_val;
7876
7877 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007878 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007879 /* Read the MII Status Register and wait for Link Status bit
7880 * to be clear.
7881 */
7882
7883 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
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_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007888 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007889 return ret_val;
7890
Auke Kok8fc897b2006-08-28 14:56:16 -07007891 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007892 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007893 }
7894
7895 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007896 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007897
7898 /* Now we will re-enable th transmitter on the PHY */
7899
7900 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007901 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007902 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007903 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007904 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007905 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007906 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007907 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007908 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007909 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007910 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007911 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007912 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007913 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007914 return ret_val;
7915
7916 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007917 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007918 return ret_val;
7919
7920 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007921 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007922 /* Read the MII Status Register and wait for Link Status bit
7923 * to be set.
7924 */
7925
7926 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007927 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007928 return ret_val;
7929
7930 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007931 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007932 return ret_val;
7933
Auke Kok8fc897b2006-08-28 14:56:16 -07007934 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007935 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007936 }
7937 return E1000_SUCCESS;
7938}
7939
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007940/***************************************************************************
7941 *
7942 * Disables PCI-Express master access.
7943 *
7944 * hw: Struct containing variables accessed by shared code
7945 *
7946 * returns: - none.
7947 *
7948 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007949static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007950e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7951{
7952 uint32_t ctrl;
7953
7954 DEBUGFUNC("e1000_set_pci_express_master_disable");
7955
7956 if (hw->bus_type != e1000_bus_type_pci_express)
7957 return;
7958
7959 ctrl = E1000_READ_REG(hw, CTRL);
7960 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7961 E1000_WRITE_REG(hw, CTRL, ctrl);
7962}
7963
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007964/*******************************************************************************
7965 *
7966 * Disables PCI-Express master access and verifies there are no pending requests
7967 *
7968 * hw: Struct containing variables accessed by shared code
7969 *
7970 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7971 * caused the master requests to be disabled.
7972 * E1000_SUCCESS master requests disabled.
7973 *
7974 ******************************************************************************/
7975int32_t
7976e1000_disable_pciex_master(struct e1000_hw *hw)
7977{
7978 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7979
7980 DEBUGFUNC("e1000_disable_pciex_master");
7981
7982 if (hw->bus_type != e1000_bus_type_pci_express)
7983 return E1000_SUCCESS;
7984
7985 e1000_set_pci_express_master_disable(hw);
7986
Auke Kok8fc897b2006-08-28 14:56:16 -07007987 while (timeout) {
7988 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007989 break;
7990 else
7991 udelay(100);
7992 timeout--;
7993 }
7994
Auke Kok8fc897b2006-08-28 14:56:16 -07007995 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007996 DEBUGOUT("Master requests are pending.\n");
7997 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7998 }
7999
8000 return E1000_SUCCESS;
8001}
8002
8003/*******************************************************************************
8004 *
8005 * Check for EEPROM Auto Read bit done.
8006 *
8007 * hw: Struct containing variables accessed by shared code
8008 *
8009 * returns: - E1000_ERR_RESET if fail to reset MAC
8010 * E1000_SUCCESS at any other case.
8011 *
8012 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008013static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008014e1000_get_auto_rd_done(struct e1000_hw *hw)
8015{
8016 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8017
8018 DEBUGFUNC("e1000_get_auto_rd_done");
8019
8020 switch (hw->mac_type) {
8021 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008022 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008023 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008024 case e1000_82571:
8025 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008026 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008027 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008028 case e1000_ich8lan:
8029 while (timeout) {
8030 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8031 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008032 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008033 timeout--;
8034 }
8035
Auke Kok8fc897b2006-08-28 14:56:16 -07008036 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008037 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8038 return -E1000_ERR_RESET;
8039 }
8040 break;
8041 }
8042
Jeff Kirsherfd803242005-12-13 00:06:22 -05008043 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8044 * Need to wait for PHY configuration completion before accessing NVM
8045 * and PHY. */
8046 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008047 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008048
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008049 return E1000_SUCCESS;
8050}
8051
8052/***************************************************************************
8053 * Checks if the PHY configuration is done
8054 *
8055 * hw: Struct containing variables accessed by shared code
8056 *
8057 * returns: - E1000_ERR_RESET if fail to reset MAC
8058 * E1000_SUCCESS at any other case.
8059 *
8060 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008061static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008062e1000_get_phy_cfg_done(struct e1000_hw *hw)
8063{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008064 int32_t timeout = PHY_CFG_TIMEOUT;
8065 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8066
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008067 DEBUGFUNC("e1000_get_phy_cfg_done");
8068
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008069 switch (hw->mac_type) {
8070 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008071 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008072 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008073 case e1000_80003es2lan:
8074 /* Separate *_CFG_DONE_* bit for each port */
8075 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8076 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8077 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008078 case e1000_82571:
8079 case e1000_82572:
8080 while (timeout) {
8081 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8082 break;
8083 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008084 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008085 timeout--;
8086 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008087 if (!timeout) {
8088 DEBUGOUT("MNG configuration cycle has not completed.\n");
8089 return -E1000_ERR_RESET;
8090 }
8091 break;
8092 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008093
8094 return E1000_SUCCESS;
8095}
8096
8097/***************************************************************************
8098 *
8099 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8100 * adapter or Eeprom access.
8101 *
8102 * hw: Struct containing variables accessed by shared code
8103 *
8104 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8105 * E1000_SUCCESS at any other case.
8106 *
8107 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008108static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008109e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8110{
8111 int32_t timeout;
8112 uint32_t swsm;
8113
8114 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8115
Auke Kok8fc897b2006-08-28 14:56:16 -07008116 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008117 return E1000_SUCCESS;
8118
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008119 if (hw->mac_type == e1000_80003es2lan) {
8120 /* Get the SW semaphore. */
8121 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8122 return -E1000_ERR_EEPROM;
8123 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008124
8125 /* Get the FW semaphore. */
8126 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008127 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008128 swsm = E1000_READ_REG(hw, SWSM);
8129 swsm |= E1000_SWSM_SWESMBI;
8130 E1000_WRITE_REG(hw, SWSM, swsm);
8131 /* if we managed to set the bit we got the semaphore. */
8132 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008133 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008134 break;
8135
8136 udelay(50);
8137 timeout--;
8138 }
8139
Auke Kok8fc897b2006-08-28 14:56:16 -07008140 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008141 /* Release semaphores */
8142 e1000_put_hw_eeprom_semaphore(hw);
8143 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8144 return -E1000_ERR_EEPROM;
8145 }
8146
8147 return E1000_SUCCESS;
8148}
8149
8150/***************************************************************************
8151 * This function clears HW semaphore bits.
8152 *
8153 * hw: Struct containing variables accessed by shared code
8154 *
8155 * returns: - None.
8156 *
8157 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008158static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008159e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8160{
8161 uint32_t swsm;
8162
8163 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8164
Auke Kok8fc897b2006-08-28 14:56:16 -07008165 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008166 return;
8167
8168 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008169 if (hw->mac_type == e1000_80003es2lan) {
8170 /* Release both semaphores. */
8171 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8172 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008173 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008174 E1000_WRITE_REG(hw, SWSM, swsm);
8175}
8176
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008177/***************************************************************************
8178 *
8179 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8180 *
8181 * hw: Struct containing variables accessed by shared code
8182 *
8183 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8184 * E1000_SUCCESS at any other case.
8185 *
8186 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008187static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008188e1000_get_software_semaphore(struct e1000_hw *hw)
8189{
8190 int32_t timeout = hw->eeprom.word_size + 1;
8191 uint32_t swsm;
8192
8193 DEBUGFUNC("e1000_get_software_semaphore");
8194
Nicholas Nunley35574762006-09-27 12:53:34 -07008195 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008196 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008197 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008198
Auke Kok8fc897b2006-08-28 14:56:16 -07008199 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008200 swsm = E1000_READ_REG(hw, SWSM);
8201 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008202 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008203 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008204 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008205 timeout--;
8206 }
8207
Auke Kok8fc897b2006-08-28 14:56:16 -07008208 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008209 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8210 return -E1000_ERR_RESET;
8211 }
8212
8213 return E1000_SUCCESS;
8214}
8215
8216/***************************************************************************
8217 *
8218 * Release semaphore bit (SMBI).
8219 *
8220 * hw: Struct containing variables accessed by shared code
8221 *
8222 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008223static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008224e1000_release_software_semaphore(struct e1000_hw *hw)
8225{
8226 uint32_t swsm;
8227
8228 DEBUGFUNC("e1000_release_software_semaphore");
8229
Nicholas Nunley35574762006-09-27 12:53:34 -07008230 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008231 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008232 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008233
8234 swsm = E1000_READ_REG(hw, SWSM);
8235 /* Release the SW semaphores.*/
8236 swsm &= ~E1000_SWSM_SMBI;
8237 E1000_WRITE_REG(hw, SWSM, swsm);
8238}
8239
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008240/******************************************************************************
8241 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8242 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8243 * the caller to figure out how to deal with it.
8244 *
8245 * hw - Struct containing variables accessed by shared code
8246 *
8247 * returns: - E1000_BLK_PHY_RESET
8248 * E1000_SUCCESS
8249 *
8250 *****************************************************************************/
8251int32_t
8252e1000_check_phy_reset_block(struct e1000_hw *hw)
8253{
8254 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008255 uint32_t fwsm = 0;
8256
8257 if (hw->mac_type == e1000_ich8lan) {
8258 fwsm = E1000_READ_REG(hw, FWSM);
8259 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8260 : E1000_BLK_PHY_RESET;
8261 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008262
8263 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008264 manc = E1000_READ_REG(hw, MANC);
8265 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008266 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008267}
8268
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008269static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008270e1000_arc_subsystem_valid(struct e1000_hw *hw)
8271{
8272 uint32_t fwsm;
8273
8274 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8275 * may not be provided a DMA clock when no manageability features are
8276 * enabled. We do not want to perform any reads/writes to these registers
8277 * if this is the case. We read FWSM to determine the manageability mode.
8278 */
8279 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008280 case e1000_82571:
8281 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008282 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008283 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008284 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008285 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008286 return TRUE;
8287 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008288 case e1000_ich8lan:
8289 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008290 default:
8291 break;
8292 }
8293 return FALSE;
8294}
8295
8296
Auke Kokd37ea5d2006-06-27 09:08:17 -07008297/******************************************************************************
8298 * Configure PCI-Ex no-snoop
8299 *
8300 * hw - Struct containing variables accessed by shared code.
8301 * no_snoop - Bitmap of no-snoop events.
8302 *
8303 * returns: E1000_SUCCESS
8304 *
8305 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008306static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008307e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8308{
8309 uint32_t gcr_reg = 0;
8310
8311 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8312
8313 if (hw->bus_type == e1000_bus_type_unknown)
8314 e1000_get_bus_info(hw);
8315
8316 if (hw->bus_type != e1000_bus_type_pci_express)
8317 return E1000_SUCCESS;
8318
8319 if (no_snoop) {
8320 gcr_reg = E1000_READ_REG(hw, GCR);
8321 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8322 gcr_reg |= no_snoop;
8323 E1000_WRITE_REG(hw, GCR, gcr_reg);
8324 }
8325 if (hw->mac_type == e1000_ich8lan) {
8326 uint32_t ctrl_ext;
8327
8328 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8329
8330 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8331 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8332 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8333 }
8334
8335 return E1000_SUCCESS;
8336}
8337
8338/***************************************************************************
8339 *
8340 * Get software semaphore FLAG bit (SWFLAG).
8341 * SWFLAG is used to synchronize the access to all shared resource between
8342 * SW, FW and HW.
8343 *
8344 * hw: Struct containing variables accessed by shared code
8345 *
8346 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008347static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008348e1000_get_software_flag(struct e1000_hw *hw)
8349{
8350 int32_t timeout = PHY_CFG_TIMEOUT;
8351 uint32_t extcnf_ctrl;
8352
8353 DEBUGFUNC("e1000_get_software_flag");
8354
8355 if (hw->mac_type == e1000_ich8lan) {
8356 while (timeout) {
8357 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8358 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8359 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8360
8361 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8362 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8363 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008364 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008365 timeout--;
8366 }
8367
8368 if (!timeout) {
8369 DEBUGOUT("FW or HW locks the resource too long.\n");
8370 return -E1000_ERR_CONFIG;
8371 }
8372 }
8373
8374 return E1000_SUCCESS;
8375}
8376
8377/***************************************************************************
8378 *
8379 * Release software semaphore FLAG bit (SWFLAG).
8380 * SWFLAG is used to synchronize the access to all shared resource between
8381 * SW, FW and HW.
8382 *
8383 * hw: Struct containing variables accessed by shared code
8384 *
8385 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008386static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008387e1000_release_software_flag(struct e1000_hw *hw)
8388{
8389 uint32_t extcnf_ctrl;
8390
8391 DEBUGFUNC("e1000_release_software_flag");
8392
8393 if (hw->mac_type == e1000_ich8lan) {
8394 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8395 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8396 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8397 }
8398
8399 return;
8400}
8401
Auke Kokd37ea5d2006-06-27 09:08:17 -07008402/******************************************************************************
8403 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8404 * register.
8405 *
8406 * hw - Struct containing variables accessed by shared code
8407 * offset - offset of word in the EEPROM to read
8408 * data - word read from the EEPROM
8409 * words - number of words to read
8410 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008411static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008412e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8413 uint16_t *data)
8414{
8415 int32_t error = E1000_SUCCESS;
8416 uint32_t flash_bank = 0;
8417 uint32_t act_offset = 0;
8418 uint32_t bank_offset = 0;
8419 uint16_t word = 0;
8420 uint16_t i = 0;
8421
8422 /* We need to know which is the valid flash bank. In the event
8423 * that we didn't allocate eeprom_shadow_ram, we may not be
8424 * managing flash_bank. So it cannot be trusted and needs
8425 * to be updated with each read.
8426 */
8427 /* Value of bit 22 corresponds to the flash bank we're on. */
8428 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8429
8430 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8431 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8432
8433 error = e1000_get_software_flag(hw);
8434 if (error != E1000_SUCCESS)
8435 return error;
8436
8437 for (i = 0; i < words; i++) {
8438 if (hw->eeprom_shadow_ram != NULL &&
8439 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8440 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8441 } else {
8442 /* The NVM part needs a byte offset, hence * 2 */
8443 act_offset = bank_offset + ((offset + i) * 2);
8444 error = e1000_read_ich8_word(hw, act_offset, &word);
8445 if (error != E1000_SUCCESS)
8446 break;
8447 data[i] = word;
8448 }
8449 }
8450
8451 e1000_release_software_flag(hw);
8452
8453 return error;
8454}
8455
8456/******************************************************************************
8457 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8458 * register. Actually, writes are written to the shadow ram cache in the hw
8459 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8460 * the NVM, which occurs when the NVM checksum is updated.
8461 *
8462 * hw - Struct containing variables accessed by shared code
8463 * offset - offset of word in the EEPROM to write
8464 * words - number of words to write
8465 * data - words to write to the EEPROM
8466 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008467static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008468e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8469 uint16_t *data)
8470{
8471 uint32_t i = 0;
8472 int32_t error = E1000_SUCCESS;
8473
8474 error = e1000_get_software_flag(hw);
8475 if (error != E1000_SUCCESS)
8476 return error;
8477
8478 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8479 * allocated. Subsequent reads to the modified words are read from
8480 * this cached structure as well. Writes will only go into this
8481 * cached structure unless it's followed by a call to
8482 * e1000_update_eeprom_checksum() where it will commit the changes
8483 * and clear the "modified" field.
8484 */
8485 if (hw->eeprom_shadow_ram != NULL) {
8486 for (i = 0; i < words; i++) {
8487 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8488 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8489 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8490 } else {
8491 error = -E1000_ERR_EEPROM;
8492 break;
8493 }
8494 }
8495 } else {
8496 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8497 * as they don't perform any NVM writes. An attempt in doing so
8498 * will result in this error.
8499 */
8500 error = -E1000_ERR_EEPROM;
8501 }
8502
8503 e1000_release_software_flag(hw);
8504
8505 return error;
8506}
8507
8508/******************************************************************************
8509 * This function does initial flash setup so that a new read/write/erase cycle
8510 * can be started.
8511 *
8512 * hw - The pointer to the hw structure
8513 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008514static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008515e1000_ich8_cycle_init(struct e1000_hw *hw)
8516{
8517 union ich8_hws_flash_status hsfsts;
8518 int32_t error = E1000_ERR_EEPROM;
8519 int32_t i = 0;
8520
8521 DEBUGFUNC("e1000_ich8_cycle_init");
8522
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008523 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008524
8525 /* May be check the Flash Des Valid bit in Hw status */
8526 if (hsfsts.hsf_status.fldesvalid == 0) {
8527 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8528 return error;
8529 }
8530
8531 /* Clear FCERR in Hw status by writing 1 */
8532 /* Clear DAEL in Hw status by writing a 1 */
8533 hsfsts.hsf_status.flcerr = 1;
8534 hsfsts.hsf_status.dael = 1;
8535
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008536 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008537
8538 /* Either we should have a hardware SPI cycle in progress bit to check
8539 * against, in order to start a new cycle or FDONE bit should be changed
8540 * in the hardware so that it is 1 after harware reset, which can then be
8541 * used as an indication whether a cycle is in progress or has been
8542 * completed .. we should also have some software semaphore mechanism to
8543 * guard FDONE or the cycle in progress bit so that two threads access to
8544 * those bits can be sequentiallized or a way so that 2 threads dont
8545 * start the cycle at the same time */
8546
8547 if (hsfsts.hsf_status.flcinprog == 0) {
8548 /* There is no cycle running at present, so we can start a cycle */
8549 /* Begin by setting Flash Cycle Done. */
8550 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008551 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008552 error = E1000_SUCCESS;
8553 } else {
8554 /* otherwise poll for sometime so the current cycle has a chance
8555 * to end before giving up. */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008556 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8557 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008558 if (hsfsts.hsf_status.flcinprog == 0) {
8559 error = E1000_SUCCESS;
8560 break;
8561 }
8562 udelay(1);
8563 }
8564 if (error == E1000_SUCCESS) {
8565 /* Successful in waiting for previous cycle to timeout,
8566 * now set the Flash Cycle Done. */
8567 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008568 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008569 } else {
8570 DEBUGOUT("Flash controller busy, cannot get access");
8571 }
8572 }
8573 return error;
8574}
8575
8576/******************************************************************************
8577 * This function starts a flash cycle and waits for its completion
8578 *
8579 * hw - The pointer to the hw structure
8580 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008581static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008582e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8583{
8584 union ich8_hws_flash_ctrl hsflctl;
8585 union ich8_hws_flash_status hsfsts;
8586 int32_t error = E1000_ERR_EEPROM;
8587 uint32_t i = 0;
8588
8589 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008590 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008591 hsflctl.hsf_ctrl.flcgo = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008592 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008593
8594 /* wait till FDONE bit is set to 1 */
8595 do {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008596 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008597 if (hsfsts.hsf_status.flcdone == 1)
8598 break;
8599 udelay(1);
8600 i++;
8601 } while (i < timeout);
8602 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8603 error = E1000_SUCCESS;
8604 }
8605 return error;
8606}
8607
8608/******************************************************************************
8609 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8610 *
8611 * hw - The pointer to the hw structure
8612 * index - The index of the byte or word to read.
8613 * size - Size of data to read, 1=byte 2=word
8614 * data - Pointer to the word to store the value read.
8615 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008616static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008617e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8618 uint32_t size, uint16_t* data)
8619{
8620 union ich8_hws_flash_status hsfsts;
8621 union ich8_hws_flash_ctrl hsflctl;
8622 uint32_t flash_linear_address;
8623 uint32_t flash_data = 0;
8624 int32_t error = -E1000_ERR_EEPROM;
8625 int32_t count = 0;
8626
8627 DEBUGFUNC("e1000_read_ich8_data");
8628
8629 if (size < 1 || size > 2 || data == 0x0 ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008630 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008631 return error;
8632
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008633 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008634 hw->flash_base_addr;
8635
8636 do {
8637 udelay(1);
8638 /* Steps */
8639 error = e1000_ich8_cycle_init(hw);
8640 if (error != E1000_SUCCESS)
8641 break;
8642
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008643 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008644 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8645 hsflctl.hsf_ctrl.fldbcount = size - 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008646 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8647 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008648
8649 /* Write the last 24 bits of index into Flash Linear address field in
8650 * Flash Address */
8651 /* TODO: TBD maybe check the index against the size of flash */
8652
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008653 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008654
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008655 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008656
8657 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8658 * sequence a few more times, else read in (shift in) the Flash Data0,
8659 * the order is least significant byte first msb to lsb */
8660 if (error == E1000_SUCCESS) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008661 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008662 if (size == 1) {
8663 *data = (uint8_t)(flash_data & 0x000000FF);
8664 } else if (size == 2) {
8665 *data = (uint16_t)(flash_data & 0x0000FFFF);
8666 }
8667 break;
8668 } else {
8669 /* If we've gotten here, then things are probably completely hosed,
8670 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008671 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008672 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008673 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008674 if (hsfsts.hsf_status.flcerr == 1) {
8675 /* Repeat for some time before giving up. */
8676 continue;
8677 } else if (hsfsts.hsf_status.flcdone == 0) {
8678 DEBUGOUT("Timeout error - flash cycle did not complete.");
8679 break;
8680 }
8681 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008682 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008683
8684 return error;
8685}
8686
8687/******************************************************************************
8688 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8689 *
8690 * hw - The pointer to the hw structure
8691 * index - The index of the byte/word to read.
8692 * size - Size of data to read, 1=byte 2=word
8693 * data - The byte(s) to write to the NVM.
8694 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008695static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008696e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8697 uint16_t data)
8698{
8699 union ich8_hws_flash_status hsfsts;
8700 union ich8_hws_flash_ctrl hsflctl;
8701 uint32_t flash_linear_address;
8702 uint32_t flash_data = 0;
8703 int32_t error = -E1000_ERR_EEPROM;
8704 int32_t count = 0;
8705
8706 DEBUGFUNC("e1000_write_ich8_data");
8707
8708 if (size < 1 || size > 2 || data > size * 0xff ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008709 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008710 return error;
8711
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008712 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008713 hw->flash_base_addr;
8714
8715 do {
8716 udelay(1);
8717 /* Steps */
8718 error = e1000_ich8_cycle_init(hw);
8719 if (error != E1000_SUCCESS)
8720 break;
8721
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008722 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008723 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8724 hsflctl.hsf_ctrl.fldbcount = size -1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008725 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8726 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008727
8728 /* Write the last 24 bits of index into Flash Linear address field in
8729 * Flash Address */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008730 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008731
8732 if (size == 1)
8733 flash_data = (uint32_t)data & 0x00FF;
8734 else
8735 flash_data = (uint32_t)data;
8736
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008737 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008738
8739 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8740 * sequence a few more times else done */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008741 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008742 if (error == E1000_SUCCESS) {
8743 break;
8744 } else {
8745 /* If we're here, then things are most likely completely hosed,
8746 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008747 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008748 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008749 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008750 if (hsfsts.hsf_status.flcerr == 1) {
8751 /* Repeat for some time before giving up. */
8752 continue;
8753 } else if (hsfsts.hsf_status.flcdone == 0) {
8754 DEBUGOUT("Timeout error - flash cycle did not complete.");
8755 break;
8756 }
8757 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008758 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008759
8760 return error;
8761}
8762
8763/******************************************************************************
8764 * Reads a single byte from the NVM using the ICH8 flash access registers.
8765 *
8766 * hw - pointer to e1000_hw structure
8767 * index - The index of the byte to read.
8768 * data - Pointer to a byte to store the value read.
8769 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008770static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008771e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8772{
8773 int32_t status = E1000_SUCCESS;
8774 uint16_t word = 0;
8775
8776 status = e1000_read_ich8_data(hw, index, 1, &word);
8777 if (status == E1000_SUCCESS) {
8778 *data = (uint8_t)word;
8779 }
8780
8781 return status;
8782}
8783
8784/******************************************************************************
8785 * Writes a single byte to the NVM using the ICH8 flash access registers.
8786 * Performs verification by reading back the value and then going through
8787 * a retry algorithm before giving up.
8788 *
8789 * hw - pointer to e1000_hw structure
8790 * index - The index of the byte to write.
8791 * byte - The byte to write to the NVM.
8792 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008793static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008794e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8795{
8796 int32_t error = E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008797 int32_t program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008798
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008799 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008800
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008801 error = e1000_write_ich8_byte(hw, index, byte);
8802
8803 if (error != E1000_SUCCESS) {
8804 for (program_retries = 0; program_retries < 100; program_retries++) {
8805 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8806 error = e1000_write_ich8_byte(hw, index, byte);
8807 udelay(100);
8808 if (error == E1000_SUCCESS)
8809 break;
8810 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008811 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008812
Auke Kokd37ea5d2006-06-27 09:08:17 -07008813 if (program_retries == 100)
8814 error = E1000_ERR_EEPROM;
8815
8816 return error;
8817}
8818
8819/******************************************************************************
8820 * Writes a single byte to the NVM using the ICH8 flash access registers.
8821 *
8822 * hw - pointer to e1000_hw structure
8823 * index - The index of the byte to read.
8824 * data - The byte to write to the NVM.
8825 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008826static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008827e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8828{
8829 int32_t status = E1000_SUCCESS;
8830 uint16_t word = (uint16_t)data;
8831
8832 status = e1000_write_ich8_data(hw, index, 1, word);
8833
8834 return status;
8835}
8836
8837/******************************************************************************
8838 * Reads a word from the NVM using the ICH8 flash access registers.
8839 *
8840 * hw - pointer to e1000_hw structure
8841 * index - The starting byte index of the word to read.
8842 * data - Pointer to a word to store the value read.
8843 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008844static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008845e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8846{
8847 int32_t status = E1000_SUCCESS;
8848 status = e1000_read_ich8_data(hw, index, 2, data);
8849 return status;
8850}
8851
8852/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008853 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8854 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008855 *
8856 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008857 * bank - 0 for first bank, 1 for second bank
8858 *
8859 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8860 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8861 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008862 *****************************************************************************/
8863int32_t
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008864e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008865{
8866 union ich8_hws_flash_status hsfsts;
8867 union ich8_hws_flash_ctrl hsflctl;
8868 uint32_t flash_linear_address;
8869 int32_t count = 0;
8870 int32_t error = E1000_ERR_EEPROM;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008871 int32_t iteration;
8872 int32_t sub_sector_size = 0;
8873 int32_t bank_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008874 int32_t j = 0;
8875 int32_t error_flag = 0;
8876
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008877 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008878
8879 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8880 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8881 * consecutive sectors. The start index for the nth Hw sector can be
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008882 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008883 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8884 * The start index for the nth Hw sector can be calculated
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008885 * as bank * 4096
8886 * 10: The HW sector is 8K bytes
8887 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008888 if (hsfsts.hsf_status.berasesz == 0x0) {
8889 /* Hw sector size 256 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008890 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8891 bank_size = ICH_FLASH_SECTOR_SIZE;
8892 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008893 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008894 bank_size = ICH_FLASH_SEG_SIZE_4K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008895 iteration = 1;
8896 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008897 bank_size = ICH_FLASH_SEG_SIZE_64K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008898 iteration = 1;
8899 } else {
8900 return error;
8901 }
8902
8903 for (j = 0; j < iteration ; j++) {
8904 do {
8905 count++;
8906 /* Steps */
8907 error = e1000_ich8_cycle_init(hw);
8908 if (error != E1000_SUCCESS) {
8909 error_flag = 1;
8910 break;
8911 }
8912
8913 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8914 * Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008915 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8916 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8917 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008918
8919 /* Write the last 24 bits of an index within the block into Flash
8920 * Linear address field in Flash Address. This probably needs to
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008921 * be calculated here based off the on-chip erase sector size and
8922 * the software bank size (4, 8 or 64 KBytes) */
8923 flash_linear_address = bank * bank_size + j * sub_sector_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008924 flash_linear_address += hw->flash_base_addr;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008925 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008926
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008927 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008928
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008929 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008930 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8931 * sequence a few more times else Done */
8932 if (error == E1000_SUCCESS) {
8933 break;
8934 } else {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008935 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008936 if (hsfsts.hsf_status.flcerr == 1) {
8937 /* repeat for some time before giving up */
8938 continue;
8939 } else if (hsfsts.hsf_status.flcdone == 0) {
8940 error_flag = 1;
8941 break;
8942 }
8943 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008944 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008945 if (error_flag == 1)
8946 break;
8947 }
8948 if (error_flag != 1)
8949 error = E1000_SUCCESS;
8950 return error;
8951}
8952
Adrian Bunke4c780b2006-08-14 23:00:10 -07008953static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008954e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8955 uint32_t cnf_base_addr, uint32_t cnf_size)
8956{
8957 uint32_t ret_val = E1000_SUCCESS;
8958 uint16_t word_addr, reg_data, reg_addr;
8959 uint16_t i;
8960
8961 /* cnf_base_addr is in DWORD */
8962 word_addr = (uint16_t)(cnf_base_addr << 1);
8963
8964 /* cnf_size is returned in size of dwords */
8965 for (i = 0; i < cnf_size; i++) {
8966 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8967 if (ret_val)
8968 return ret_val;
8969
8970 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8971 if (ret_val)
8972 return ret_val;
8973
8974 ret_val = e1000_get_software_flag(hw);
8975 if (ret_val != E1000_SUCCESS)
8976 return ret_val;
8977
8978 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8979
8980 e1000_release_software_flag(hw);
8981 }
8982
8983 return ret_val;
8984}
8985
8986
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008987/******************************************************************************
8988 * This function initializes the PHY from the NVM on ICH8 platforms. This
8989 * is needed due to an issue where the NVM configuration is not properly
8990 * autoloaded after power transitions. Therefore, after each PHY reset, we
8991 * will load the configuration data out of the NVM manually.
8992 *
8993 * hw: Struct containing variables accessed by shared code
8994 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008995static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008996e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8997{
8998 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8999
9000 if (hw->phy_type != e1000_phy_igp_3)
9001 return E1000_SUCCESS;
9002
9003 /* Check if SW needs configure the PHY */
9004 reg_data = E1000_READ_REG(hw, FEXTNVM);
9005 if (!(reg_data & FEXTNVM_SW_CONFIG))
9006 return E1000_SUCCESS;
9007
9008 /* Wait for basic configuration completes before proceeding*/
9009 loop = 0;
9010 do {
9011 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9012 udelay(100);
9013 loop++;
9014 } while ((!reg_data) && (loop < 50));
9015
9016 /* Clear the Init Done bit for the next init event */
9017 reg_data = E1000_READ_REG(hw, STATUS);
9018 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9019 E1000_WRITE_REG(hw, STATUS, reg_data);
9020
9021 /* Make sure HW does not configure LCD from PHY extended configuration
9022 before SW configuration */
9023 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9024 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9025 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9026 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9027 cnf_size >>= 16;
9028 if (cnf_size) {
9029 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9030 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9031 /* cnf_base_addr is in DWORD */
9032 cnf_base_addr >>= 16;
9033
9034 /* Configure LCD from extended configuration region. */
9035 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9036 cnf_size);
9037 if (ret_val)
9038 return ret_val;
9039 }
9040 }
9041
9042 return E1000_SUCCESS;
9043}
9044