blob: 48aff8d054f96c6520594ba7fc1a73ccc2e63b67 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Nicholas Nunley35574762006-09-27 12:53:34 -070036static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
43static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static int32_t e1000_check_downshift(struct e1000_hw *hw);
45static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47static void e1000_clear_vfta(struct e1000_hw *hw);
48static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60static int32_t e1000_id_led_init(struct e1000_hw *hw);
61static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63static void e1000_init_rx_addrs(struct e1000_hw *hw);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -070064static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070065static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86static void e1000_release_software_flag(struct e1000_hw *hw);
87static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94static void e1000_phy_init_script(struct e1000_hw *hw);
95static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
103 uint16_t count);
104static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
110 uint16_t *data);
111static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
115 uint16_t count);
116static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
117 uint16_t phy_data);
118static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
119 uint16_t *phy_data);
120static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122static void e1000_release_eeprom(struct e1000_hw *hw);
123static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700127static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Auke Kokcd94dd02006-06-27 09:08:22 -0700129static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
130 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800131static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* IGP cable length table */
134static const
135uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
144
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700145static const
146uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/******************************************************************************
157 * Set the phy type member in the hw struct.
158 *
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -0700161static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162e1000_set_phy_type(struct e1000_hw *hw)
163{
164 DEBUGFUNC("e1000_set_phy_type");
165
Auke Kok8fc897b2006-08-28 14:56:16 -0700166 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700167 return -E1000_ERR_PHY_TYPE;
168
Auke Kok8fc897b2006-08-28 14:56:16 -0700169 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700173 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 hw->phy_type = e1000_phy_m88;
175 break;
176 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 hw->phy_type = e1000_phy_igp;
182 break;
183 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
186 break;
187 case IFE_E_PHY_ID:
188 case IFE_PLUS_E_PHY_ID:
189 case IFE_C_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
191 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* Fall Through */
198 default:
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
202 }
203
204 return E1000_SUCCESS;
205}
206
207/******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
209 *
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
212static void
213e1000_phy_init_script(struct e1000_hw *hw)
214{
215 uint32_t ret_val;
216 uint16_t phy_saved_data;
217
218 DEBUGFUNC("e1000_phy_init_script");
219
Auke Kok8fc897b2006-08-28 14:56:16 -0700220 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400221 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
226
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
229
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400230 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 e1000_write_phy_reg(hw,0x0000,0x0140);
233
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400234 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Auke Kok8fc897b2006-08-28 14:56:16 -0700236 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 case e1000_82541:
238 case e1000_82547:
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
240
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
242
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
244
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
246
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
248
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
250
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
252
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
254
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
256 break;
257
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
261 break;
262 default:
263 break;
264 }
265
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
267
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400268 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
272
Auke Kok8fc897b2006-08-28 14:56:16 -0700273 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 uint16_t fused, fine, coarse;
275
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
278
Auke Kok8fc897b2006-08-28 14:56:16 -0700279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
281
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
284
Auke Kok8fc897b2006-08-28 14:56:16 -0700285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
290
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
294
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
298 }
299 }
300 }
301}
302
303/******************************************************************************
304 * Set the mac type member in the hw struct.
305 *
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
308int32_t
309e1000_set_mac_type(struct e1000_hw *hw)
310{
311 DEBUGFUNC("e1000_set_mac_type");
312
313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
318 break;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
321 break;
322 default:
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
325 }
326 break;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
330 break;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
336 break;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
343 break;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
347 break;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
352 break;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
357 break;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 hw->mac_type = e1000_82546_rev_3;
365 break;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
Auke Kokcd94dd02006-06-27 09:08:22 -0700368 case E1000_DEV_ID_82541ER_LOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 hw->mac_type = e1000_82541;
370 break;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
376 break;
377 case E1000_DEV_ID_82547EI:
Auke Kokcd94dd02006-06-27 09:08:22 -0700378 case E1000_DEV_ID_82547EI_MOBILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 hw->mac_type = e1000_82547;
380 break;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
383 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400388 hw->mac_type = e1000_82571;
389 break;
390 case E1000_DEV_ID_82572EI_COPPER:
391 case E1000_DEV_ID_82572EI_FIBER:
392 case E1000_DEV_ID_82572EI_SERDES:
Auke Kokcd94dd02006-06-27 09:08:22 -0700393 case E1000_DEV_ID_82572EI:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400394 hw->mac_type = e1000_82572;
395 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700396 case E1000_DEV_ID_82573E:
397 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400398 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700399 hw->mac_type = e1000_82573;
400 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700401 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
402 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800403 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
404 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
405 hw->mac_type = e1000_80003es2lan;
406 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700407 case E1000_DEV_ID_ICH8_IGP_M_AMT:
408 case E1000_DEV_ID_ICH8_IGP_AMT:
409 case E1000_DEV_ID_ICH8_IGP_C:
410 case E1000_DEV_ID_ICH8_IFE:
411 case E1000_DEV_ID_ICH8_IGP_M:
412 hw->mac_type = e1000_ich8lan;
413 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 default:
415 /* Should never have loaded on this device */
416 return -E1000_ERR_MAC_TYPE;
417 }
418
Auke Kok8fc897b2006-08-28 14:56:16 -0700419 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700420 case e1000_ich8lan:
421 hw->swfwhw_semaphore_present = TRUE;
422 hw->asf_firmware_present = TRUE;
423 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800424 case e1000_80003es2lan:
425 hw->swfw_sync_present = TRUE;
426 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400427 case e1000_82571:
428 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700429 case e1000_82573:
430 hw->eeprom_semaphore_present = TRUE;
431 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 case e1000_82541:
433 case e1000_82547:
434 case e1000_82541_rev_2:
435 case e1000_82547_rev_2:
436 hw->asf_firmware_present = TRUE;
437 break;
438 default:
439 break;
440 }
441
442 return E1000_SUCCESS;
443}
444
445/*****************************************************************************
446 * Set media type and TBI compatibility.
447 *
448 * hw - Struct containing variables accessed by shared code
449 * **************************************************************************/
450void
451e1000_set_media_type(struct e1000_hw *hw)
452{
453 uint32_t status;
454
455 DEBUGFUNC("e1000_set_media_type");
456
Auke Kok8fc897b2006-08-28 14:56:16 -0700457 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /* tbi_compatibility is only valid on 82543 */
459 hw->tbi_compatibility_en = FALSE;
460 }
461
462 switch (hw->device_id) {
463 case E1000_DEV_ID_82545GM_SERDES:
464 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400465 case E1000_DEV_ID_82571EB_SERDES:
466 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800467 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 hw->media_type = e1000_media_type_internal_serdes;
469 break;
470 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700471 switch (hw->mac_type) {
472 case e1000_82542_rev2_0:
473 case e1000_82542_rev2_1:
474 hw->media_type = e1000_media_type_fiber;
475 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700476 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700477 case e1000_82573:
478 /* The STATUS_TBIMODE bit is reserved or reused for the this
479 * device.
480 */
481 hw->media_type = e1000_media_type_copper;
482 break;
483 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700485 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 hw->media_type = e1000_media_type_fiber;
487 /* tbi_compatibility not valid on fiber */
488 hw->tbi_compatibility_en = FALSE;
489 } else {
490 hw->media_type = e1000_media_type_copper;
491 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700492 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494 }
495}
496
497/******************************************************************************
498 * Reset the transmit and receive units; mask and clear all interrupts.
499 *
500 * hw - Struct containing variables accessed by shared code
501 *****************************************************************************/
502int32_t
503e1000_reset_hw(struct e1000_hw *hw)
504{
505 uint32_t ctrl;
506 uint32_t ctrl_ext;
507 uint32_t icr;
508 uint32_t manc;
509 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700510 uint32_t timeout;
511 uint32_t extcnf_ctrl;
512 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 DEBUGFUNC("e1000_reset_hw");
515
516 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700517 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
519 e1000_pci_clear_mwi(hw);
520 }
521
Auke Kok8fc897b2006-08-28 14:56:16 -0700522 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700523 /* Prevent the PCI-E bus from sticking if there is no TLP connection
524 * on the last TLP read/write transaction when MAC is reset.
525 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700526 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700527 DEBUGOUT("PCI-E Master disable polling has failed.\n");
528 }
529 }
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* Clear interrupt mask to stop board from generating interrupts */
532 DEBUGOUT("Masking off all interrupts\n");
533 E1000_WRITE_REG(hw, IMC, 0xffffffff);
534
535 /* Disable the Transmit and Receive units. Then delay to allow
536 * any pending transactions to complete before we hit the MAC with
537 * the global reset.
538 */
539 E1000_WRITE_REG(hw, RCTL, 0);
540 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
541 E1000_WRITE_FLUSH(hw);
542
543 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
544 hw->tbi_compatibility_on = FALSE;
545
546 /* Delay to allow any outstanding PCI transactions to complete before
547 * resetting the device
548 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400549 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 ctrl = E1000_READ_REG(hw, CTRL);
552
553 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700554 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700555 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400556 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700559 /* Must acquire the MDIO ownership before MAC reset.
560 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700561 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700562 timeout = 10;
563
564 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
565 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
566
567 do {
568 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
569 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
570
Auke Kok8fc897b2006-08-28 14:56:16 -0700571 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700572 break;
573 else
574 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
575
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400576 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700577 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700578 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700579 }
580
Auke Kokcd94dd02006-06-27 09:08:22 -0700581 /* Workaround for ICH8 bit corruption issue in FIFO memory */
582 if (hw->mac_type == e1000_ich8lan) {
583 /* Set Tx and Rx buffer allocation to 8k apiece. */
584 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
585 /* Set Packet Buffer Size to 16k. */
586 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
587 }
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 /* Issue a global reset to the MAC. This will reset the chip's
590 * transmit, receive, DMA, and link units. It will not effect
591 * the current PCI configuration. The global reset bit is self-
592 * clearing, and should clear within a microsecond.
593 */
594 DEBUGOUT("Issuing a global reset to MAC\n");
595
Auke Kok8fc897b2006-08-28 14:56:16 -0700596 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 case e1000_82544:
598 case e1000_82540:
599 case e1000_82545:
600 case e1000_82546:
601 case e1000_82541:
602 case e1000_82541_rev_2:
603 /* These controllers can't ack the 64-bit write when issuing the
604 * reset, so use IO-mapping as a workaround to issue the reset */
605 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
606 break;
607 case e1000_82545_rev_3:
608 case e1000_82546_rev_3:
609 /* Reset is performed on a shadow of the control register */
610 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
611 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700612 case e1000_ich8lan:
613 if (!hw->phy_reset_disable &&
614 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
615 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
616 * at the same time to make sure the interface between
617 * MAC and the external PHY is reset.
618 */
619 ctrl |= E1000_CTRL_PHY_RST;
620 }
621
622 e1000_get_software_flag(hw);
623 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400624 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700625 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 default:
627 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
628 break;
629 }
630
631 /* After MAC reset, force reload of EEPROM to restore power-on settings to
632 * device. Later controllers reload the EEPROM automatically, so just wait
633 * for reload to complete.
634 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700635 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 case e1000_82542_rev2_0:
637 case e1000_82542_rev2_1:
638 case e1000_82543:
639 case e1000_82544:
640 /* Wait for reset to complete */
641 udelay(10);
642 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
643 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
644 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
645 E1000_WRITE_FLUSH(hw);
646 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400647 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
649 case e1000_82541:
650 case e1000_82541_rev_2:
651 case e1000_82547:
652 case e1000_82547_rev_2:
653 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400654 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700656 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500657 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
658 udelay(10);
659 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
660 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
661 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
662 E1000_WRITE_FLUSH(hw);
663 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700664 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400665 case e1000_82571:
666 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -0700667 case e1000_ich8lan:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800668 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700669 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700670 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700671 /* We don't want to continue accessing MAC registers. */
672 return ret_val;
673 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 default:
675 /* Wait for EEPROM reload (it happens automatically) */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400676 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 break;
678 }
679
680 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700681 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 manc = E1000_READ_REG(hw, MANC);
683 manc &= ~(E1000_MANC_ARP_EN);
684 E1000_WRITE_REG(hw, MANC, manc);
685 }
686
Auke Kok8fc897b2006-08-28 14:56:16 -0700687 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 e1000_phy_init_script(hw);
689
690 /* Configure activity LED after PHY reset */
691 led_ctrl = E1000_READ_REG(hw, LEDCTL);
692 led_ctrl &= IGP_ACTIVITY_LED_MASK;
693 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
694 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
695 }
696
697 /* Clear interrupt mask to stop board from generating interrupts */
698 DEBUGOUT("Masking off all interrupts\n");
699 E1000_WRITE_REG(hw, IMC, 0xffffffff);
700
701 /* Clear any pending interrupt events. */
702 icr = E1000_READ_REG(hw, ICR);
703
704 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700705 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400706 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 e1000_pci_set_mwi(hw);
708 }
709
Auke Kokcd94dd02006-06-27 09:08:22 -0700710 if (hw->mac_type == e1000_ich8lan) {
711 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
712 kab |= E1000_KABGTXD_BGSQLBIAS;
713 E1000_WRITE_REG(hw, KABGTXD, kab);
714 }
715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 return E1000_SUCCESS;
717}
718
719/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700720 *
721 * Initialize a number of hardware-dependent bits
722 *
723 * hw: Struct containing variables accessed by shared code
724 *
725 * This function contains hardware limitation workarounds for PCI-E adapters
726 *
727 *****************************************************************************/
728static void
729e1000_initialize_hardware_bits(struct e1000_hw *hw)
730{
731 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
732 /* Settings common to all PCI-express silicon */
733 uint32_t reg_ctrl, reg_ctrl_ext;
734 uint32_t reg_tarc0, reg_tarc1;
735 uint32_t reg_tctl;
736 uint32_t reg_txdctl, reg_txdctl1;
737
738 /* link autonegotiation/sync workarounds */
739 reg_tarc0 = E1000_READ_REG(hw, TARC0);
740 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
741
742 /* Enable not-done TX descriptor counting */
743 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
744 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
745 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
746 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
747 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
748 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
749
750 switch (hw->mac_type) {
751 case e1000_82571:
752 case e1000_82572:
753 /* Clear PHY TX compatible mode bits */
754 reg_tarc1 = E1000_READ_REG(hw, TARC1);
755 reg_tarc1 &= ~((1 << 30)|(1 << 29));
756
757 /* link autonegotiation/sync workarounds */
758 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
759
760 /* TX ring control fixes */
761 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
762
763 /* Multiple read bit is reversed polarity */
764 reg_tctl = E1000_READ_REG(hw, TCTL);
765 if (reg_tctl & E1000_TCTL_MULR)
766 reg_tarc1 &= ~(1 << 28);
767 else
768 reg_tarc1 |= (1 << 28);
769
770 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
771 break;
772 case e1000_82573:
773 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
774 reg_ctrl_ext &= ~(1 << 23);
775 reg_ctrl_ext |= (1 << 22);
776
777 /* TX byte count fix */
778 reg_ctrl = E1000_READ_REG(hw, CTRL);
779 reg_ctrl &= ~(1 << 29);
780
781 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
782 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
783 break;
784 case e1000_80003es2lan:
785 /* improve small packet performace for fiber/serdes */
786 if ((hw->media_type == e1000_media_type_fiber) ||
787 (hw->media_type == e1000_media_type_internal_serdes)) {
788 reg_tarc0 &= ~(1 << 20);
789 }
790
791 /* Multiple read bit is reversed polarity */
792 reg_tctl = E1000_READ_REG(hw, TCTL);
793 reg_tarc1 = E1000_READ_REG(hw, TARC1);
794 if (reg_tctl & E1000_TCTL_MULR)
795 reg_tarc1 &= ~(1 << 28);
796 else
797 reg_tarc1 |= (1 << 28);
798
799 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
800 break;
801 case e1000_ich8lan:
802 /* Reduce concurrent DMA requests to 3 from 4 */
803 if ((hw->revision_id < 3) ||
804 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
805 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
806 reg_tarc0 |= ((1 << 29)|(1 << 28));
807
808 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
809 reg_ctrl_ext |= (1 << 22);
810 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
811
812 /* workaround TX hang with TSO=on */
813 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
814
815 /* Multiple read bit is reversed polarity */
816 reg_tctl = E1000_READ_REG(hw, TCTL);
817 reg_tarc1 = E1000_READ_REG(hw, TARC1);
818 if (reg_tctl & E1000_TCTL_MULR)
819 reg_tarc1 &= ~(1 << 28);
820 else
821 reg_tarc1 |= (1 << 28);
822
823 /* workaround TX hang with TSO=on */
824 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
825
826 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
827 break;
828 default:
829 break;
830 }
831
832 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
833 }
834}
835
836/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 * Performs basic configuration of the adapter.
838 *
839 * hw - Struct containing variables accessed by shared code
840 *
841 * Assumes that the controller has previously been reset and is in a
842 * post-reset uninitialized state. Initializes the receive address registers,
843 * multicast table, and VLAN filter table. Calls routines to setup link
844 * configuration and flow control settings. Clears all on-chip counters. Leaves
845 * the transmit and receive units disabled and uninitialized.
846 *****************************************************************************/
847int32_t
848e1000_init_hw(struct e1000_hw *hw)
849{
850 uint32_t ctrl;
851 uint32_t i;
852 int32_t ret_val;
853 uint16_t pcix_cmd_word;
854 uint16_t pcix_stat_hi_word;
855 uint16_t cmd_mmrbc;
856 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700857 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800858 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800859 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 DEBUGFUNC("e1000_init_hw");
862
Jeff Kirsher7820d422006-08-16 13:39:00 -0700863 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700864 if ((hw->mac_type == e1000_ich8lan) &&
865 ((hw->revision_id < 3) ||
866 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
867 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
868 reg_data = E1000_READ_REG(hw, STATUS);
869 reg_data &= ~0x80000000;
870 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700871 }
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /* Initialize Identification LED */
874 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700875 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 DEBUGOUT("Error Initializing Identification LED\n");
877 return ret_val;
878 }
879
880 /* Set the media type and TBI compatibility */
881 e1000_set_media_type(hw);
882
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700883 /* Must be called after e1000_set_media_type because media_type is used */
884 e1000_initialize_hardware_bits(hw);
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 /* Disabling VLAN filtering. */
887 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700888 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
889 if (hw->mac_type != e1000_ich8lan) {
890 if (hw->mac_type < e1000_82545_rev_3)
891 E1000_WRITE_REG(hw, VET, 0);
892 e1000_clear_vfta(hw);
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700896 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
898 e1000_pci_clear_mwi(hw);
899 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
900 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400901 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903
904 /* Setup the receive address. This involves initializing all of the Receive
905 * Address Registers (RARs 0 - 15).
906 */
907 e1000_init_rx_addrs(hw);
908
909 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700910 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 E1000_WRITE_REG(hw, RCTL, 0);
912 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400913 msleep(1);
914 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 e1000_pci_set_mwi(hw);
916 }
917
918 /* Zero out the Multicast HASH table */
919 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700920 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700921 if (hw->mac_type == e1000_ich8lan)
922 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700923 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700925 /* use write flush to prevent Memory Write Block (MWB) from
926 * occuring when accessing our register space */
927 E1000_WRITE_FLUSH(hw);
928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 /* Set the PCI priority bit correctly in the CTRL register. This
931 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700932 * gives equal priority to transmits and receives. Valid only on
933 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700935 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 ctrl = E1000_READ_REG(hw, CTRL);
937 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
938 }
939
Auke Kok8fc897b2006-08-28 14:56:16 -0700940 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 case e1000_82545_rev_3:
942 case e1000_82546_rev_3:
943 break;
944 default:
945 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700946 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
948 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
949 &pcix_stat_hi_word);
950 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
951 PCIX_COMMAND_MMRBC_SHIFT;
952 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
953 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700954 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700956 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
958 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
959 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
960 &pcix_cmd_word);
961 }
962 }
963 break;
964 }
965
Auke Kokcd94dd02006-06-27 09:08:22 -0700966 /* More time needed for PHY to initialize */
967 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400968 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 /* Call a subroutine to configure the link and setup flow control. */
971 ret_val = e1000_setup_link(hw);
972
973 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700974 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 ctrl = E1000_READ_REG(hw, TXDCTL);
976 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
977 E1000_WRITE_REG(hw, TXDCTL, ctrl);
978 }
979
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700980 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700981 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700982 }
983
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400984 switch (hw->mac_type) {
985 default:
986 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800987 case e1000_80003es2lan:
988 /* Enable retransmit on late collisions */
989 reg_data = E1000_READ_REG(hw, TCTL);
990 reg_data |= E1000_TCTL_RTLC;
991 E1000_WRITE_REG(hw, TCTL, reg_data);
992
993 /* Configure Gigabit Carry Extend Padding */
994 reg_data = E1000_READ_REG(hw, TCTL_EXT);
995 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
996 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
997 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
998
999 /* Configure Transmit Inter-Packet Gap */
1000 reg_data = E1000_READ_REG(hw, TIPG);
1001 reg_data &= ~E1000_TIPG_IPGT_MASK;
1002 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1003 E1000_WRITE_REG(hw, TIPG, reg_data);
1004
1005 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1006 reg_data &= ~0x00100000;
1007 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1008 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001009 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001010 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001011 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001012 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001013 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001014 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1015 break;
1016 }
1017
1018
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001019 if (hw->mac_type == e1000_82573) {
1020 uint32_t gcr = E1000_READ_REG(hw, GCR);
1021 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1022 E1000_WRITE_REG(hw, GCR, gcr);
1023 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 /* Clear all of the statistics registers (clear on read). It is
1026 * important that we do this after we have tried to establish link
1027 * because the symbol error count will increment wildly if there
1028 * is no link.
1029 */
1030 e1000_clear_hw_cntrs(hw);
1031
Auke Kokcd94dd02006-06-27 09:08:22 -07001032 /* ICH8 No-snoop bits are opposite polarity.
1033 * Set to snoop by default after reset. */
1034 if (hw->mac_type == e1000_ich8lan)
1035 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1036
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001037 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1038 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1039 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1040 /* Relaxed ordering must be disabled to avoid a parity
1041 * error crash in a PCI slot. */
1042 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1043 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1044 }
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 return ret_val;
1047}
1048
1049/******************************************************************************
1050 * Adjust SERDES output amplitude based on EEPROM setting.
1051 *
1052 * hw - Struct containing variables accessed by shared code.
1053 *****************************************************************************/
1054static int32_t
1055e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1056{
1057 uint16_t eeprom_data;
1058 int32_t ret_val;
1059
1060 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1061
Auke Kok8fc897b2006-08-28 14:56:16 -07001062 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return E1000_SUCCESS;
1064
Auke Kok8fc897b2006-08-28 14:56:16 -07001065 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 case e1000_82545_rev_3:
1067 case e1000_82546_rev_3:
1068 break;
1069 default:
1070 return E1000_SUCCESS;
1071 }
1072
1073 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1074 if (ret_val) {
1075 return ret_val;
1076 }
1077
Auke Kok8fc897b2006-08-28 14:56:16 -07001078 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001080 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001082 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return ret_val;
1084 }
1085
1086 return E1000_SUCCESS;
1087}
1088
1089/******************************************************************************
1090 * Configures flow control and link settings.
1091 *
1092 * hw - Struct containing variables accessed by shared code
1093 *
1094 * Determines which flow control settings to use. Calls the apropriate media-
1095 * specific link configuration function. Configures the flow control settings.
1096 * Assuming the adapter has a valid link partner, a valid link should be
1097 * established. Assumes the hardware has previously been reset and the
1098 * transmitter and receiver are not enabled.
1099 *****************************************************************************/
1100int32_t
1101e1000_setup_link(struct e1000_hw *hw)
1102{
1103 uint32_t ctrl_ext;
1104 int32_t ret_val;
1105 uint16_t eeprom_data;
1106
1107 DEBUGFUNC("e1000_setup_link");
1108
Jeff Kirsher526f9952006-01-12 16:50:46 -08001109 /* In the case of the phy reset being blocked, we already have a link.
1110 * We do not have to set it up again. */
1111 if (e1000_check_phy_reset_block(hw))
1112 return E1000_SUCCESS;
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 /* Read and store word 0x0F of the EEPROM. This word contains bits
1115 * that determine the hardware's default PAUSE (flow control) mode,
1116 * a bit that determines whether the HW defaults to enabling or
1117 * disabling auto-negotiation, and the direction of the
1118 * SW defined pins. If there is no SW over-ride of the flow
1119 * control setting, then the variable hw->fc will
1120 * be initialized based on a value in the EEPROM.
1121 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001122 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001123 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001124 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001125 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001126 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001127 break;
1128 default:
1129 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1130 1, &eeprom_data);
1131 if (ret_val) {
1132 DEBUGOUT("EEPROM Read Error\n");
1133 return -E1000_ERR_EEPROM;
1134 }
1135 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001136 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001137 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1138 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001139 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001140 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001141 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001142 break;
1143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 }
1145
1146 /* We want to save off the original Flow Control configuration just
1147 * in case we get disconnected and then reconnected into a different
1148 * hub or switch with different Flow Control capabilities.
1149 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001150 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001151 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Auke Kok8fc897b2006-08-28 14:56:16 -07001153 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001154 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156 hw->original_fc = hw->fc;
1157
1158 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1159
1160 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1161 * polarity value for the SW controlled pins, and setup the
1162 * Extended Device Control reg with that info.
1163 * This is needed because one of the SW controlled pins is used for
1164 * signal detection. So this should be done before e1000_setup_pcs_link()
1165 * or e1000_phy_setup() is called.
1166 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001167 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001168 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1169 1, &eeprom_data);
1170 if (ret_val) {
1171 DEBUGOUT("EEPROM Read Error\n");
1172 return -E1000_ERR_EEPROM;
1173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1175 SWDPIO__EXT_SHIFT);
1176 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1177 }
1178
1179 /* Call the necessary subroutine to configure the link. */
1180 ret_val = (hw->media_type == e1000_media_type_copper) ?
1181 e1000_setup_copper_link(hw) :
1182 e1000_setup_fiber_serdes_link(hw);
1183
1184 /* Initialize the flow control address, type, and PAUSE timer
1185 * registers to their default values. This is done even if flow
1186 * control is disabled, because it does not hurt anything to
1187 * initialize these registers.
1188 */
1189 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1190
Auke Kokcd94dd02006-06-27 09:08:22 -07001191 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1192 if (hw->mac_type != e1000_ich8lan) {
1193 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1194 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1195 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1196 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1199
1200 /* Set the flow control receive threshold registers. Normally,
1201 * these registers will be set to a default threshold that may be
1202 * adjusted later by the driver's runtime code. However, if the
1203 * ability to transmit pause frames in not enabled, then these
1204 * registers will be set to 0.
1205 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001206 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 E1000_WRITE_REG(hw, FCRTL, 0);
1208 E1000_WRITE_REG(hw, FCRTH, 0);
1209 } else {
1210 /* We need to set up the Receive Threshold high and low water marks
1211 * as well as (optionally) enabling the transmission of XON frames.
1212 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001213 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1215 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1216 } else {
1217 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1218 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1219 }
1220 }
1221 return ret_val;
1222}
1223
1224/******************************************************************************
1225 * Sets up link for a fiber based or serdes based adapter
1226 *
1227 * hw - Struct containing variables accessed by shared code
1228 *
1229 * Manipulates Physical Coding Sublayer functions in order to configure
1230 * link. Assumes the hardware has been previously reset and the transmitter
1231 * and receiver are not enabled.
1232 *****************************************************************************/
1233static int32_t
1234e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1235{
1236 uint32_t ctrl;
1237 uint32_t status;
1238 uint32_t txcw = 0;
1239 uint32_t i;
1240 uint32_t signal = 0;
1241 int32_t ret_val;
1242
1243 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1244
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001245 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1246 * until explicitly turned off or a power cycle is performed. A read to
1247 * the register does not indicate its status. Therefore, we ensure
1248 * loopback mode is disabled during initialization.
1249 */
1250 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1251 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1252
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001253 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 * set when the optics detect a signal. On older adapters, it will be
1255 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001256 * If we're on serdes media, adjust the output amplitude to value
1257 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 */
1259 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001260 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1262
1263 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001264 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 return ret_val;
1266
1267 /* Take the link out of reset */
1268 ctrl &= ~(E1000_CTRL_LRST);
1269
1270 /* Adjust VCO speed to improve BER performance */
1271 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001272 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 return ret_val;
1274
1275 e1000_config_collision_dist(hw);
1276
1277 /* Check for a software override of the flow control settings, and setup
1278 * the device accordingly. If auto-negotiation is enabled, then software
1279 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1280 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1281 * auto-negotiation is disabled, then software will have to manually
1282 * configure the two flow control enable bits in the CTRL register.
1283 *
1284 * The possible values of the "fc" parameter are:
1285 * 0: Flow control is completely disabled
1286 * 1: Rx flow control is enabled (we can receive pause frames, but
1287 * not send pause frames).
1288 * 2: Tx flow control is enabled (we can send pause frames but we do
1289 * not support receiving pause frames).
1290 * 3: Both Rx and TX flow control (symmetric) are enabled.
1291 */
1292 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001293 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 /* Flow control is completely disabled by a software over-ride. */
1295 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1296 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001297 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 /* RX Flow control is enabled and TX Flow control is disabled by a
1299 * software over-ride. Since there really isn't a way to advertise
1300 * that we are capable of RX Pause ONLY, we will advertise that we
1301 * support both symmetric and asymmetric RX PAUSE. Later, we will
1302 * disable the adapter's ability to send PAUSE frames.
1303 */
1304 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1305 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001306 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1308 * software over-ride.
1309 */
1310 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1311 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001312 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1314 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1315 break;
1316 default:
1317 DEBUGOUT("Flow control param set incorrectly\n");
1318 return -E1000_ERR_CONFIG;
1319 break;
1320 }
1321
1322 /* Since auto-negotiation is enabled, take the link out of reset (the link
1323 * will be in reset, because we previously reset the chip). This will
1324 * restart auto-negotiation. If auto-neogtiation is successful then the
1325 * link-up status bit will be set and the flow control enable bits (RFCE
1326 * and TFCE) will be set according to their negotiated value.
1327 */
1328 DEBUGOUT("Auto-negotiation enabled\n");
1329
1330 E1000_WRITE_REG(hw, TXCW, txcw);
1331 E1000_WRITE_REG(hw, CTRL, ctrl);
1332 E1000_WRITE_FLUSH(hw);
1333
1334 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001335 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1338 * indication in the Device Status Register. Time-out if a link isn't
1339 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1340 * less than 500 milliseconds even if the other end is doing it in SW).
1341 * For internal serdes, we just assume a signal is present, then poll.
1342 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001343 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1345 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001346 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001347 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001349 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001351 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1353 hw->autoneg_failed = 1;
1354 /* AutoNeg failed to achieve a link, so we'll call
1355 * e1000_check_for_link. This routine will force the link up if
1356 * we detect a signal. This will allow us to communicate with
1357 * non-autonegotiating link partners.
1358 */
1359 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001360 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 DEBUGOUT("Error while checking for link\n");
1362 return ret_val;
1363 }
1364 hw->autoneg_failed = 0;
1365 } else {
1366 hw->autoneg_failed = 0;
1367 DEBUGOUT("Valid Link Found\n");
1368 }
1369 } else {
1370 DEBUGOUT("No Signal Detected\n");
1371 }
1372 return E1000_SUCCESS;
1373}
1374
1375/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001376* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377*
1378* hw - Struct containing variables accessed by shared code
1379******************************************************************************/
1380static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001381e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
1383 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 uint16_t phy_data;
1386
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001387 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 ctrl = E1000_READ_REG(hw, CTRL);
1390 /* With 82543, we need to force speed and duplex on the MAC equal to what
1391 * the PHY speed and duplex configuration is. In addition, we need to
1392 * perform a hardware reset on the PHY to take it out of reset.
1393 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001394 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 ctrl |= E1000_CTRL_SLU;
1396 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1397 E1000_WRITE_REG(hw, CTRL, ctrl);
1398 } else {
1399 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1400 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001401 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001402 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001403 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405
1406 /* Make sure we have a valid PHY */
1407 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001408 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 DEBUGOUT("Error, did not detect valid phy.\n");
1410 return ret_val;
1411 }
1412 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1413
1414 /* Set PHY to class A mode (if necessary) */
1415 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001416 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 return ret_val;
1418
Auke Kok8fc897b2006-08-28 14:56:16 -07001419 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 (hw->mac_type == e1000_82546_rev_3)) {
1421 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1422 phy_data |= 0x00000008;
1423 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1424 }
1425
Auke Kok8fc897b2006-08-28 14:56:16 -07001426 if (hw->mac_type <= e1000_82543 ||
1427 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1428 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 hw->phy_reset_disable = FALSE;
1430
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001431 return E1000_SUCCESS;
1432}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001435/********************************************************************
1436* Copper link setup for e1000_phy_igp series.
1437*
1438* hw - Struct containing variables accessed by shared code
1439*********************************************************************/
1440static int32_t
1441e1000_copper_link_igp_setup(struct e1000_hw *hw)
1442{
1443 uint32_t led_ctrl;
1444 int32_t ret_val;
1445 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001447 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001449 if (hw->phy_reset_disable)
1450 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001451
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001452 ret_val = e1000_phy_reset(hw);
1453 if (ret_val) {
1454 DEBUGOUT("Error Resetting the PHY\n");
1455 return ret_val;
1456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Auke Kok8fc897b2006-08-28 14:56:16 -07001458 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001459 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001460 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001461 /* Configure activity LED after PHY reset */
1462 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1463 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1464 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1465 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001466 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001467
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001468 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1469 if (hw->phy_type == e1000_phy_igp) {
1470 /* disable lplu d3 during driver init */
1471 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1472 if (ret_val) {
1473 DEBUGOUT("Error Disabling LPLU D3\n");
1474 return ret_val;
1475 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001476 }
1477
1478 /* disable lplu d0 during driver init */
1479 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1480 if (ret_val) {
1481 DEBUGOUT("Error Disabling LPLU D0\n");
1482 return ret_val;
1483 }
1484 /* Configure mdi-mdix settings */
1485 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1486 if (ret_val)
1487 return ret_val;
1488
1489 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1490 hw->dsp_config_state = e1000_dsp_config_disabled;
1491 /* Force MDI for earlier revs of the IGP PHY */
1492 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1493 hw->mdix = 1;
1494
1495 } else {
1496 hw->dsp_config_state = e1000_dsp_config_enabled;
1497 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1498
1499 switch (hw->mdix) {
1500 case 1:
1501 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1502 break;
1503 case 2:
1504 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1505 break;
1506 case 0:
1507 default:
1508 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1509 break;
1510 }
1511 }
1512 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001513 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001514 return ret_val;
1515
1516 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001517 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001518 e1000_ms_type phy_ms_setting = hw->master_slave;
1519
Auke Kok8fc897b2006-08-28 14:56:16 -07001520 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001521 hw->ffe_config_state = e1000_ffe_config_enabled;
1522
Auke Kok8fc897b2006-08-28 14:56:16 -07001523 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001524 hw->dsp_config_state = e1000_dsp_config_enabled;
1525
1526 /* when autonegotiation advertisment is only 1000Mbps then we
1527 * should disable SmartSpeed and enable Auto MasterSlave
1528 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001529 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001530 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001531 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1532 &phy_data);
1533 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001535 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001536 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1537 phy_data);
1538 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001540 /* Set auto Master/Slave resolution process */
1541 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001542 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001543 return ret_val;
1544 phy_data &= ~CR_1000T_MS_ENABLE;
1545 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001546 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001547 return ret_val;
1548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001550 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001551 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001552 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001554 /* load defaults for future use */
1555 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1556 ((phy_data & CR_1000T_MS_VALUE) ?
1557 e1000_ms_force_master :
1558 e1000_ms_force_slave) :
1559 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001561 switch (phy_ms_setting) {
1562 case e1000_ms_force_master:
1563 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1564 break;
1565 case e1000_ms_force_slave:
1566 phy_data |= CR_1000T_MS_ENABLE;
1567 phy_data &= ~(CR_1000T_MS_VALUE);
1568 break;
1569 case e1000_ms_auto:
1570 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001572 break;
1573 }
1574 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001575 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001576 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Malli Chilakala2b028932005-06-17 17:46:06 -07001579 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001580}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001582/********************************************************************
1583* Copper link setup for e1000_phy_gg82563 series.
1584*
1585* hw - Struct containing variables accessed by shared code
1586*********************************************************************/
1587static int32_t
1588e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1589{
1590 int32_t ret_val;
1591 uint16_t phy_data;
1592 uint32_t reg_data;
1593
1594 DEBUGFUNC("e1000_copper_link_ggp_setup");
1595
Auke Kok8fc897b2006-08-28 14:56:16 -07001596 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001597
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001598 /* Enable CRS on TX for half-duplex operation. */
1599 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1600 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001601 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001602 return ret_val;
1603
1604 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1605 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1606 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1607
1608 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1609 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001610 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001611 return ret_val;
1612
1613 /* Options:
1614 * MDI/MDI-X = 0 (default)
1615 * 0 - Auto for all speeds
1616 * 1 - MDI mode
1617 * 2 - MDI-X mode
1618 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1619 */
1620 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001621 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001622 return ret_val;
1623
1624 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1625
1626 switch (hw->mdix) {
1627 case 1:
1628 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1629 break;
1630 case 2:
1631 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1632 break;
1633 case 0:
1634 default:
1635 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1636 break;
1637 }
1638
1639 /* Options:
1640 * disable_polarity_correction = 0 (default)
1641 * Automatic Correction for Reversed Cable Polarity
1642 * 0 - Disabled
1643 * 1 - Enabled
1644 */
1645 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001646 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001647 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1648 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1649
Auke Kok8fc897b2006-08-28 14:56:16 -07001650 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001651 return ret_val;
1652
1653 /* SW Reset the PHY so all changes take effect */
1654 ret_val = e1000_phy_reset(hw);
1655 if (ret_val) {
1656 DEBUGOUT("Error Resetting the PHY\n");
1657 return ret_val;
1658 }
1659 } /* phy_reset_disable */
1660
1661 if (hw->mac_type == e1000_80003es2lan) {
1662 /* Bypass RX and TX FIFO's */
1663 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1664 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1665 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1666 if (ret_val)
1667 return ret_val;
1668
1669 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1670 if (ret_val)
1671 return ret_val;
1672
1673 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1674 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1675
1676 if (ret_val)
1677 return ret_val;
1678
1679 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1680 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1681 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1682
1683 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1684 &phy_data);
1685 if (ret_val)
1686 return ret_val;
1687
1688 /* Do not init these registers when the HW is in IAMT mode, since the
1689 * firmware will have already initialized them. We only initialize
1690 * them if the HW is not in IAMT mode.
1691 */
1692 if (e1000_check_mng_mode(hw) == FALSE) {
1693 /* Enable Electrical Idle on the PHY */
1694 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1695 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1696 phy_data);
1697 if (ret_val)
1698 return ret_val;
1699
1700 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1701 &phy_data);
1702 if (ret_val)
1703 return ret_val;
1704
Auke Kokcd94dd02006-06-27 09:08:22 -07001705 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001706 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1707 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001708
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001709 if (ret_val)
1710 return ret_val;
1711 }
1712
1713 /* Workaround: Disable padding in Kumeran interface in the MAC
1714 * and in the PHY to avoid CRC errors.
1715 */
1716 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1717 &phy_data);
1718 if (ret_val)
1719 return ret_val;
1720 phy_data |= GG82563_ICR_DIS_PADDING;
1721 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1722 phy_data);
1723 if (ret_val)
1724 return ret_val;
1725 }
1726
1727 return E1000_SUCCESS;
1728}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001730/********************************************************************
1731* Copper link setup for e1000_phy_m88 series.
1732*
1733* hw - Struct containing variables accessed by shared code
1734*********************************************************************/
1735static int32_t
1736e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1737{
1738 int32_t ret_val;
1739 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001741 DEBUGFUNC("e1000_copper_link_mgp_setup");
1742
Auke Kok8fc897b2006-08-28 14:56:16 -07001743 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001744 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001745
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001746 /* Enable CRS on TX. This must be set for half-duplex operation. */
1747 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001748 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001749 return ret_val;
1750
1751 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1752
1753 /* Options:
1754 * MDI/MDI-X = 0 (default)
1755 * 0 - Auto for all speeds
1756 * 1 - MDI mode
1757 * 2 - MDI-X mode
1758 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1759 */
1760 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1761
1762 switch (hw->mdix) {
1763 case 1:
1764 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1765 break;
1766 case 2:
1767 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1768 break;
1769 case 3:
1770 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1771 break;
1772 case 0:
1773 default:
1774 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1775 break;
1776 }
1777
1778 /* Options:
1779 * disable_polarity_correction = 0 (default)
1780 * Automatic Correction for Reversed Cable Polarity
1781 * 0 - Disabled
1782 * 1 - Enabled
1783 */
1784 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001785 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001786 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001787 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1788 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001789 return ret_val;
1790
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001791 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001792 /* Force TX_CLK in the Extended PHY Specific Control Register
1793 * to 25MHz clock.
1794 */
1795 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1796 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001797 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001798
1799 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1800
1801 if ((hw->phy_revision == E1000_REVISION_2) &&
1802 (hw->phy_id == M88E1111_I_PHY_ID)) {
1803 /* Vidalia Phy, set the downshift counter to 5x */
1804 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1805 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1806 ret_val = e1000_write_phy_reg(hw,
1807 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1808 if (ret_val)
1809 return ret_val;
1810 } else {
1811 /* Configure Master and Slave downshift values */
1812 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1813 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1814 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1815 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1816 ret_val = e1000_write_phy_reg(hw,
1817 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1818 if (ret_val)
1819 return ret_val;
1820 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001823 /* SW Reset the PHY so all changes take effect */
1824 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001825 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826 DEBUGOUT("Error Resetting the PHY\n");
1827 return ret_val;
1828 }
1829
1830 return E1000_SUCCESS;
1831}
1832
1833/********************************************************************
1834* Setup auto-negotiation and flow control advertisements,
1835* and then perform auto-negotiation.
1836*
1837* hw - Struct containing variables accessed by shared code
1838*********************************************************************/
1839static int32_t
1840e1000_copper_link_autoneg(struct e1000_hw *hw)
1841{
1842 int32_t ret_val;
1843 uint16_t phy_data;
1844
1845 DEBUGFUNC("e1000_copper_link_autoneg");
1846
1847 /* Perform some bounds checking on the hw->autoneg_advertised
1848 * parameter. If this variable is zero, then set it to the default.
1849 */
1850 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1851
1852 /* If autoneg_advertised is zero, we assume it was not defaulted
1853 * by the calling code so we set to advertise full capability.
1854 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001855 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001856 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1857
Auke Kokcd94dd02006-06-27 09:08:22 -07001858 /* IFE phy only supports 10/100 */
1859 if (hw->phy_type == e1000_phy_ife)
1860 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1861
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001862 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1863 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001864 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001865 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1866 return ret_val;
1867 }
1868 DEBUGOUT("Restarting Auto-Neg\n");
1869
1870 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1871 * the Auto Neg Restart bit in the PHY control register.
1872 */
1873 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001874 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001875 return ret_val;
1876
1877 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1878 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001879 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001880 return ret_val;
1881
1882 /* Does the user want to wait for Auto-Neg to complete here, or
1883 * check at a later time (for example, callback routine).
1884 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001885 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001886 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001887 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001888 DEBUGOUT("Error while waiting for autoneg to complete\n");
1889 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001893 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001895 return E1000_SUCCESS;
1896}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001898/******************************************************************************
1899* Config the MAC and the PHY after link is up.
1900* 1) Set up the MAC to the current PHY speed/duplex
1901* if we are on 82543. If we
1902* are on newer silicon, we only need to configure
1903* collision distance in the Transmit Control Register.
1904* 2) Set up flow control on the MAC to that established with
1905* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001906* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001907*
1908* hw - Struct containing variables accessed by shared code
1909******************************************************************************/
1910static int32_t
1911e1000_copper_link_postconfig(struct e1000_hw *hw)
1912{
1913 int32_t ret_val;
1914 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001915
Auke Kok8fc897b2006-08-28 14:56:16 -07001916 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001917 e1000_config_collision_dist(hw);
1918 } else {
1919 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001920 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001921 DEBUGOUT("Error configuring MAC to PHY settings\n");
1922 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001924 }
1925 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001926 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001927 DEBUGOUT("Error Configuring Flow Control\n");
1928 return ret_val;
1929 }
1930
1931 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001932 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001933 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001934 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001935 DEBUGOUT("Error Configuring DSP after link up\n");
1936 return ret_val;
1937 }
1938 }
Auke Kok76c224b2006-05-23 13:36:06 -07001939
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001940 return E1000_SUCCESS;
1941}
1942
1943/******************************************************************************
1944* Detects which PHY is present and setup the speed and duplex
1945*
1946* hw - Struct containing variables accessed by shared code
1947******************************************************************************/
1948static int32_t
1949e1000_setup_copper_link(struct e1000_hw *hw)
1950{
1951 int32_t ret_val;
1952 uint16_t i;
1953 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001954 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001955
1956 DEBUGFUNC("e1000_setup_copper_link");
1957
Auke Kokcd94dd02006-06-27 09:08:22 -07001958 switch (hw->mac_type) {
1959 case e1000_80003es2lan:
1960 case e1000_ich8lan:
1961 /* Set the mac to wait the maximum time between each
1962 * iteration and increase the max iterations when
1963 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1964 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1965 if (ret_val)
1966 return ret_val;
1967 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1968 if (ret_val)
1969 return ret_val;
1970 reg_data |= 0x3F;
1971 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1972 if (ret_val)
1973 return ret_val;
1974 default:
1975 break;
1976 }
1977
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001978 /* Check if it is a valid PHY and set PHY mode if necessary. */
1979 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001980 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001981 return ret_val;
1982
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001983 switch (hw->mac_type) {
1984 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001985 /* Kumeran registers are written-only */
1986 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001987 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1988 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1989 reg_data);
1990 if (ret_val)
1991 return ret_val;
1992 break;
1993 default:
1994 break;
1995 }
1996
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001997 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07001998 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001999 hw->phy_type == e1000_phy_igp_2) {
2000 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002001 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002002 return ret_val;
2003 } else if (hw->phy_type == e1000_phy_m88) {
2004 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002005 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002006 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002007 } else if (hw->phy_type == e1000_phy_gg82563) {
2008 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002009 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002010 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002011 }
2012
Auke Kok8fc897b2006-08-28 14:56:16 -07002013 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002014 /* Setup autoneg and flow control advertisement
2015 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002016 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002017 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002018 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002019 } else {
2020 /* PHY will be set to 10H, 10F, 100H,or 100F
2021 * depending on value from forced_speed_duplex. */
2022 DEBUGOUT("Forcing speed and duplex\n");
2023 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002024 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002025 DEBUGOUT("Error Forcing Speed and Duplex\n");
2026 return ret_val;
2027 }
2028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 /* Check link status. Wait up to 100 microseconds for link to become
2031 * valid.
2032 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002033 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002035 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 return ret_val;
2037 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002038 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 return ret_val;
2040
Auke Kok8fc897b2006-08-28 14:56:16 -07002041 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002042 /* Config the MAC and PHY after link is up */
2043 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002044 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 DEBUGOUT("Valid link established!!!\n");
2048 return E1000_SUCCESS;
2049 }
2050 udelay(10);
2051 }
2052
2053 DEBUGOUT("Unable to establish link!!!\n");
2054 return E1000_SUCCESS;
2055}
2056
2057/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002058* Configure the MAC-to-PHY interface for 10/100Mbps
2059*
2060* hw - Struct containing variables accessed by shared code
2061******************************************************************************/
2062static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002063e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002064{
2065 int32_t ret_val = E1000_SUCCESS;
2066 uint32_t tipg;
2067 uint16_t reg_data;
2068
2069 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2070
2071 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2072 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2073 reg_data);
2074 if (ret_val)
2075 return ret_val;
2076
2077 /* Configure Transmit Inter-Packet Gap */
2078 tipg = E1000_READ_REG(hw, TIPG);
2079 tipg &= ~E1000_TIPG_IPGT_MASK;
2080 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2081 E1000_WRITE_REG(hw, TIPG, tipg);
2082
Auke Kokcd94dd02006-06-27 09:08:22 -07002083 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2084
2085 if (ret_val)
2086 return ret_val;
2087
2088 if (duplex == HALF_DUPLEX)
2089 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2090 else
2091 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2092
2093 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2094
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002095 return ret_val;
2096}
2097
2098static int32_t
2099e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2100{
2101 int32_t ret_val = E1000_SUCCESS;
2102 uint16_t reg_data;
2103 uint32_t tipg;
2104
2105 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2106
2107 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2108 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2109 reg_data);
2110 if (ret_val)
2111 return ret_val;
2112
2113 /* Configure Transmit Inter-Packet Gap */
2114 tipg = E1000_READ_REG(hw, TIPG);
2115 tipg &= ~E1000_TIPG_IPGT_MASK;
2116 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2117 E1000_WRITE_REG(hw, TIPG, tipg);
2118
Auke Kokcd94dd02006-06-27 09:08:22 -07002119 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2120
2121 if (ret_val)
2122 return ret_val;
2123
2124 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2125 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2126
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002127 return ret_val;
2128}
2129
2130/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131* Configures PHY autoneg and flow control advertisement settings
2132*
2133* hw - Struct containing variables accessed by shared code
2134******************************************************************************/
2135int32_t
2136e1000_phy_setup_autoneg(struct e1000_hw *hw)
2137{
2138 int32_t ret_val;
2139 uint16_t mii_autoneg_adv_reg;
2140 uint16_t mii_1000t_ctrl_reg;
2141
2142 DEBUGFUNC("e1000_phy_setup_autoneg");
2143
2144 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2145 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002146 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 return ret_val;
2148
Auke Kokcd94dd02006-06-27 09:08:22 -07002149 if (hw->phy_type != e1000_phy_ife) {
2150 /* Read the MII 1000Base-T Control Register (Address 9). */
2151 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2152 if (ret_val)
2153 return ret_val;
2154 } else
2155 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157 /* Need to parse both autoneg_advertised and fc and set up
2158 * the appropriate PHY registers. First we will parse for
2159 * autoneg_advertised software override. Since we can advertise
2160 * a plethora of combinations, we need to check each bit
2161 * individually.
2162 */
2163
2164 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2165 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2166 * the 1000Base-T Control Register (Address 9).
2167 */
2168 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2169 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2170
2171 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2172
2173 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002174 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 DEBUGOUT("Advertise 10mb Half duplex\n");
2176 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2177 }
2178
2179 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002180 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 DEBUGOUT("Advertise 10mb Full duplex\n");
2182 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2183 }
2184
2185 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002186 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 DEBUGOUT("Advertise 100mb Half duplex\n");
2188 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2189 }
2190
2191 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002192 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 DEBUGOUT("Advertise 100mb Full duplex\n");
2194 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2195 }
2196
2197 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002198 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2200 }
2201
2202 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002203 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 DEBUGOUT("Advertise 1000mb Full duplex\n");
2205 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002206 if (hw->phy_type == e1000_phy_ife) {
2207 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 }
2210
2211 /* Check for a software override of the flow control settings, and
2212 * setup the PHY advertisement registers accordingly. If
2213 * auto-negotiation is enabled, then software will have to set the
2214 * "PAUSE" bits to the correct value in the Auto-Negotiation
2215 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2216 *
2217 * The possible values of the "fc" parameter are:
2218 * 0: Flow control is completely disabled
2219 * 1: Rx flow control is enabled (we can receive pause frames
2220 * but not send pause frames).
2221 * 2: Tx flow control is enabled (we can send pause frames
2222 * but we do not support receiving pause frames).
2223 * 3: Both Rx and TX flow control (symmetric) are enabled.
2224 * other: No software override. The flow control configuration
2225 * in the EEPROM is used.
2226 */
2227 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002228 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 /* Flow control (RX & TX) is completely disabled by a
2230 * software over-ride.
2231 */
2232 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2233 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002234 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 /* RX Flow control is enabled, and TX Flow control is
2236 * disabled, by a software over-ride.
2237 */
2238 /* Since there really isn't a way to advertise that we are
2239 * capable of RX Pause ONLY, we will advertise that we
2240 * support both symmetric and asymmetric RX PAUSE. Later
2241 * (in e1000_config_fc_after_link_up) we will disable the
2242 *hw's ability to send PAUSE frames.
2243 */
2244 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2245 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002246 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 /* TX Flow control is enabled, and RX Flow control is
2248 * disabled, by a software over-ride.
2249 */
2250 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2251 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2252 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002253 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 /* Flow control (both RX and TX) is enabled by a software
2255 * over-ride.
2256 */
2257 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2258 break;
2259 default:
2260 DEBUGOUT("Flow control param set incorrectly\n");
2261 return -E1000_ERR_CONFIG;
2262 }
2263
2264 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002265 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 return ret_val;
2267
2268 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2269
Auke Kokcd94dd02006-06-27 09:08:22 -07002270 if (hw->phy_type != e1000_phy_ife) {
2271 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2272 if (ret_val)
2273 return ret_val;
2274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 return E1000_SUCCESS;
2277}
2278
2279/******************************************************************************
2280* Force PHY speed and duplex settings to hw->forced_speed_duplex
2281*
2282* hw - Struct containing variables accessed by shared code
2283******************************************************************************/
2284static int32_t
2285e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2286{
2287 uint32_t ctrl;
2288 int32_t ret_val;
2289 uint16_t mii_ctrl_reg;
2290 uint16_t mii_status_reg;
2291 uint16_t phy_data;
2292 uint16_t i;
2293
2294 DEBUGFUNC("e1000_phy_force_speed_duplex");
2295
2296 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002297 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
2299 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2300
2301 /* Read the Device Control Register. */
2302 ctrl = E1000_READ_REG(hw, CTRL);
2303
2304 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2305 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2306 ctrl &= ~(DEVICE_SPEED_MASK);
2307
2308 /* Clear the Auto Speed Detect Enable bit. */
2309 ctrl &= ~E1000_CTRL_ASDE;
2310
2311 /* Read the MII Control Register. */
2312 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002313 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 return ret_val;
2315
2316 /* We need to disable autoneg in order to force link and duplex. */
2317
2318 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2319
2320 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002321 if (hw->forced_speed_duplex == e1000_100_full ||
2322 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 /* We want to force full duplex so we SET the full duplex bits in the
2324 * Device and MII Control Registers.
2325 */
2326 ctrl |= E1000_CTRL_FD;
2327 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2328 DEBUGOUT("Full Duplex\n");
2329 } else {
2330 /* We want to force half duplex so we CLEAR the full duplex bits in
2331 * the Device and MII Control Registers.
2332 */
2333 ctrl &= ~E1000_CTRL_FD;
2334 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2335 DEBUGOUT("Half Duplex\n");
2336 }
2337
2338 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002339 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 hw->forced_speed_duplex == e1000_100_half) {
2341 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2342 ctrl |= E1000_CTRL_SPD_100;
2343 mii_ctrl_reg |= MII_CR_SPEED_100;
2344 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2345 DEBUGOUT("Forcing 100mb ");
2346 } else {
2347 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2348 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2349 mii_ctrl_reg |= MII_CR_SPEED_10;
2350 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2351 DEBUGOUT("Forcing 10mb ");
2352 }
2353
2354 e1000_config_collision_dist(hw);
2355
2356 /* Write the configured values back to the Device Control Reg. */
2357 E1000_WRITE_REG(hw, CTRL, ctrl);
2358
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002359 if ((hw->phy_type == e1000_phy_m88) ||
2360 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002362 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 return ret_val;
2364
2365 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2366 * forced whenever speed are duplex are forced.
2367 */
2368 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2369 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002370 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 return ret_val;
2372
2373 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2374
2375 /* Need to reset the PHY or these changes will be ignored */
2376 mii_ctrl_reg |= MII_CR_RESET;
Auke Kokcd94dd02006-06-27 09:08:22 -07002377 /* Disable MDI-X support for 10/100 */
2378 } else if (hw->phy_type == e1000_phy_ife) {
2379 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2380 if (ret_val)
2381 return ret_val;
2382
2383 phy_data &= ~IFE_PMC_AUTO_MDIX;
2384 phy_data &= ~IFE_PMC_FORCE_MDIX;
2385
2386 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2387 if (ret_val)
2388 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 } else {
2390 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2391 * forced whenever speed or duplex are forced.
2392 */
2393 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002394 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 return ret_val;
2396
2397 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2398 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2399
2400 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002401 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 return ret_val;
2403 }
2404
2405 /* Write back the modified PHY MII control register. */
2406 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002407 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return ret_val;
2409
2410 udelay(1);
2411
2412 /* The wait_autoneg_complete flag may be a little misleading here.
2413 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2414 * But we do want to delay for a period while forcing only so we
2415 * don't generate false No Link messages. So we will wait here
2416 * only if the user has set wait_autoneg_complete to 1, which is
2417 * the default.
2418 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002419 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 /* We will wait for autoneg to complete. */
2421 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2422 mii_status_reg = 0;
2423
2424 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002425 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2427 * to be set.
2428 */
2429 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_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 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002434 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 return ret_val;
2436
Auke Kok8fc897b2006-08-28 14:56:16 -07002437 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002438 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002440 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002441 ((hw->phy_type == e1000_phy_m88) ||
2442 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 /* We didn't get link. Reset the DSP and wait again for link. */
2444 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002445 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 DEBUGOUT("Error Resetting PHY DSP\n");
2447 return ret_val;
2448 }
2449 }
2450 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002451 for (i = PHY_FORCE_TIME; i > 0; i--) {
2452 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002453 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2455 * to be set.
2456 */
2457 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002458 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 return ret_val;
2460
2461 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002462 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 return ret_val;
2464 }
2465 }
2466
2467 if (hw->phy_type == e1000_phy_m88) {
2468 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2469 * Extended PHY Specific Control Register to 25MHz clock. This value
2470 * defaults back to a 2.5MHz clock when the PHY is reset.
2471 */
2472 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002473 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 return ret_val;
2475
2476 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2477 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002478 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 return ret_val;
2480
2481 /* In addition, because of the s/w reset above, we need to enable CRS on
2482 * TX. This must be set for both full and half duplex operation.
2483 */
2484 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002485 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 return ret_val;
2487
2488 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2489 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002490 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 return ret_val;
2492
Auke Kok8fc897b2006-08-28 14:56:16 -07002493 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2494 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2495 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002497 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 return ret_val;
2499 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002500 } else if (hw->phy_type == e1000_phy_gg82563) {
2501 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2502 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2503 * we're not in a forced 10/duplex configuration. */
2504 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2505 if (ret_val)
2506 return ret_val;
2507
2508 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2509 if ((hw->forced_speed_duplex == e1000_10_full) ||
2510 (hw->forced_speed_duplex == e1000_10_half))
2511 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2512 else
2513 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2514
2515 /* Also due to the reset, we need to enable CRS on Tx. */
2516 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2517
2518 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2519 if (ret_val)
2520 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 }
2522 return E1000_SUCCESS;
2523}
2524
2525/******************************************************************************
2526* Sets the collision distance in the Transmit Control register
2527*
2528* hw - Struct containing variables accessed by shared code
2529*
2530* Link should have been established previously. Reads the speed and duplex
2531* information from the Device Status register.
2532******************************************************************************/
2533void
2534e1000_config_collision_dist(struct e1000_hw *hw)
2535{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002536 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
2538 DEBUGFUNC("e1000_config_collision_dist");
2539
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002540 if (hw->mac_type < e1000_82543)
2541 coll_dist = E1000_COLLISION_DISTANCE_82542;
2542 else
2543 coll_dist = E1000_COLLISION_DISTANCE;
2544
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 tctl = E1000_READ_REG(hw, TCTL);
2546
2547 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002548 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
2550 E1000_WRITE_REG(hw, TCTL, tctl);
2551 E1000_WRITE_FLUSH(hw);
2552}
2553
2554/******************************************************************************
2555* Sets MAC speed and duplex settings to reflect the those in the PHY
2556*
2557* hw - Struct containing variables accessed by shared code
2558* mii_reg - data to write to the MII control register
2559*
2560* The contents of the PHY register containing the needed information need to
2561* be passed in.
2562******************************************************************************/
2563static int32_t
2564e1000_config_mac_to_phy(struct e1000_hw *hw)
2565{
2566 uint32_t ctrl;
2567 int32_t ret_val;
2568 uint16_t phy_data;
2569
2570 DEBUGFUNC("e1000_config_mac_to_phy");
2571
Auke Kok76c224b2006-05-23 13:36:06 -07002572 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002573 * MAC speed/duplex configuration.*/
2574 if (hw->mac_type >= e1000_82544)
2575 return E1000_SUCCESS;
2576
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 /* Read the Device Control Register and set the bits to Force Speed
2578 * and Duplex.
2579 */
2580 ctrl = E1000_READ_REG(hw, CTRL);
2581 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2582 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2583
2584 /* Set up duplex in the Device Control and Transmit Control
2585 * registers depending on negotiated values.
2586 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002587 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002588 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002589 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Auke Kok8fc897b2006-08-28 14:56:16 -07002591 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002592 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002593 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002594 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002596 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002598 /* Set up speed in the Device Control register depending on
2599 * negotiated values.
2600 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002601 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002602 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002603 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002604 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /* Write the configured values back to the Device Control Reg. */
2607 E1000_WRITE_REG(hw, CTRL, ctrl);
2608 return E1000_SUCCESS;
2609}
2610
2611/******************************************************************************
2612 * Forces the MAC's flow control settings.
2613 *
2614 * hw - Struct containing variables accessed by shared code
2615 *
2616 * Sets the TFCE and RFCE bits in the device control register to reflect
2617 * the adapter settings. TFCE and RFCE need to be explicitly set by
2618 * software when a Copper PHY is used because autonegotiation is managed
2619 * by the PHY rather than the MAC. Software must also configure these
2620 * bits when link is forced on a fiber connection.
2621 *****************************************************************************/
2622int32_t
2623e1000_force_mac_fc(struct e1000_hw *hw)
2624{
2625 uint32_t ctrl;
2626
2627 DEBUGFUNC("e1000_force_mac_fc");
2628
2629 /* Get the current configuration of the Device Control Register */
2630 ctrl = E1000_READ_REG(hw, CTRL);
2631
2632 /* Because we didn't get link via the internal auto-negotiation
2633 * mechanism (we either forced link or we got link via PHY
2634 * auto-neg), we have to manually enable/disable transmit an
2635 * receive flow control.
2636 *
2637 * The "Case" statement below enables/disable flow control
2638 * according to the "hw->fc" parameter.
2639 *
2640 * The possible values of the "fc" parameter are:
2641 * 0: Flow control is completely disabled
2642 * 1: Rx flow control is enabled (we can receive pause
2643 * frames but not send pause frames).
2644 * 2: Tx flow control is enabled (we can send pause frames
2645 * frames but we do not receive pause frames).
2646 * 3: Both Rx and TX flow control (symmetric) is enabled.
2647 * other: No other values should be possible at this point.
2648 */
2649
2650 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002651 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2653 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002654 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 ctrl &= (~E1000_CTRL_TFCE);
2656 ctrl |= E1000_CTRL_RFCE;
2657 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002658 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 ctrl &= (~E1000_CTRL_RFCE);
2660 ctrl |= E1000_CTRL_TFCE;
2661 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002662 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2664 break;
2665 default:
2666 DEBUGOUT("Flow control param set incorrectly\n");
2667 return -E1000_ERR_CONFIG;
2668 }
2669
2670 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002671 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 ctrl &= (~E1000_CTRL_TFCE);
2673
2674 E1000_WRITE_REG(hw, CTRL, ctrl);
2675 return E1000_SUCCESS;
2676}
2677
2678/******************************************************************************
2679 * Configures flow control settings after link is established
2680 *
2681 * hw - Struct containing variables accessed by shared code
2682 *
2683 * Should be called immediately after a valid link has been established.
2684 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2685 * and autonegotiation is enabled, the MAC flow control settings will be set
2686 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2687 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2688 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002689static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690e1000_config_fc_after_link_up(struct e1000_hw *hw)
2691{
2692 int32_t ret_val;
2693 uint16_t mii_status_reg;
2694 uint16_t mii_nway_adv_reg;
2695 uint16_t mii_nway_lp_ability_reg;
2696 uint16_t speed;
2697 uint16_t duplex;
2698
2699 DEBUGFUNC("e1000_config_fc_after_link_up");
2700
2701 /* Check for the case where we have fiber media and auto-neg failed
2702 * so we had to force link. In this case, we need to force the
2703 * configuration of the MAC to match the "fc" parameter.
2704 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002705 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2706 ((hw->media_type == e1000_media_type_internal_serdes) &&
2707 (hw->autoneg_failed)) ||
2708 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002710 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 DEBUGOUT("Error forcing flow control settings\n");
2712 return ret_val;
2713 }
2714 }
2715
2716 /* Check for the case where we have copper media and auto-neg is
2717 * enabled. In this case, we need to check and see if Auto-Neg
2718 * has completed, and if so, how the PHY and link partner has
2719 * flow control configured.
2720 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002721 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 /* Read the MII Status Register and check to see if AutoNeg
2723 * has completed. We read this twice because this reg has
2724 * some "sticky" (latched) bits.
2725 */
2726 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002727 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 return ret_val;
2729 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002730 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 return ret_val;
2732
Auke Kok8fc897b2006-08-28 14:56:16 -07002733 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 /* The AutoNeg process has completed, so we now need to
2735 * read both the Auto Negotiation Advertisement Register
2736 * (Address 4) and the Auto_Negotiation Base Page Ability
2737 * Register (Address 5) to determine how flow control was
2738 * negotiated.
2739 */
2740 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2741 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002742 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 return ret_val;
2744 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2745 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002746 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 return ret_val;
2748
2749 /* Two bits in the Auto Negotiation Advertisement Register
2750 * (Address 4) and two bits in the Auto Negotiation Base
2751 * Page Ability Register (Address 5) determine flow control
2752 * for both the PHY and the link partner. The following
2753 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2754 * 1999, describes these PAUSE resolution bits and how flow
2755 * control is determined based upon these settings.
2756 * NOTE: DC = Don't Care
2757 *
2758 * LOCAL DEVICE | LINK PARTNER
2759 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2760 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002761 * 0 | 0 | DC | DC | E1000_FC_NONE
2762 * 0 | 1 | 0 | DC | E1000_FC_NONE
2763 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2764 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2765 * 1 | 0 | 0 | DC | E1000_FC_NONE
2766 * 1 | DC | 1 | DC | E1000_FC_FULL
2767 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2768 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 *
2770 */
2771 /* Are both PAUSE bits set to 1? If so, this implies
2772 * Symmetric Flow Control is enabled at both ends. The
2773 * ASM_DIR bits are irrelevant per the spec.
2774 *
2775 * For Symmetric Flow Control:
2776 *
2777 * LOCAL DEVICE | LINK PARTNER
2778 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2779 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002780 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 *
2782 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002783 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2784 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 /* Now we need to check if the user selected RX ONLY
2786 * of pause frames. In this case, we had to advertise
2787 * FULL flow control because we could not advertise RX
2788 * ONLY. Hence, we must now check to see if we need to
2789 * turn OFF the TRANSMISSION of PAUSE frames.
2790 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002791 if (hw->original_fc == E1000_FC_FULL) {
2792 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002793 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002795 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002796 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 }
2798 }
2799 /* For receiving PAUSE frames ONLY.
2800 *
2801 * LOCAL DEVICE | LINK PARTNER
2802 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2803 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002804 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 *
2806 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002807 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2808 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2809 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2810 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002811 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002812 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 }
2814 /* For transmitting PAUSE frames ONLY.
2815 *
2816 * LOCAL DEVICE | LINK PARTNER
2817 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2818 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002819 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 *
2821 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002822 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2823 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2824 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2825 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002826 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002827 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 }
2829 /* Per the IEEE spec, at this point flow control should be
2830 * disabled. However, we want to consider that we could
2831 * be connected to a legacy switch that doesn't advertise
2832 * desired flow control, but can be forced on the link
2833 * partner. So if we advertised no flow control, that is
2834 * what we will resolve to. If we advertised some kind of
2835 * receive capability (Rx Pause Only or Full Flow Control)
2836 * and the link partner advertised none, we will configure
2837 * ourselves to enable Rx Flow Control only. We can do
2838 * this safely for two reasons: If the link partner really
2839 * didn't want flow control enabled, and we enable Rx, no
2840 * harm done since we won't be receiving any PAUSE frames
2841 * anyway. If the intent on the link partner was to have
2842 * flow control enabled, then by us enabling RX only, we
2843 * can at least receive pause frames and process them.
2844 * This is a good idea because in most cases, since we are
2845 * predominantly a server NIC, more times than not we will
2846 * be asked to delay transmission of packets than asking
2847 * our link partner to pause transmission of frames.
2848 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002849 else if ((hw->original_fc == E1000_FC_NONE ||
2850 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002851 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002852 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002853 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002855 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002856 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 }
2858
2859 /* Now we need to do one last check... If we auto-
2860 * negotiated to HALF DUPLEX, flow control should not be
2861 * enabled per IEEE 802.3 spec.
2862 */
2863 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002864 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 DEBUGOUT("Error getting link speed and duplex\n");
2866 return ret_val;
2867 }
2868
Auke Kok8fc897b2006-08-28 14:56:16 -07002869 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002870 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872 /* Now we call a subroutine to actually force the MAC
2873 * controller to use the correct flow control settings.
2874 */
2875 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002876 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 DEBUGOUT("Error forcing flow control settings\n");
2878 return ret_val;
2879 }
2880 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002881 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 }
2883 }
2884 return E1000_SUCCESS;
2885}
2886
2887/******************************************************************************
2888 * Checks to see if the link status of the hardware has changed.
2889 *
2890 * hw - Struct containing variables accessed by shared code
2891 *
2892 * Called by any function that needs to check the link status of the adapter.
2893 *****************************************************************************/
2894int32_t
2895e1000_check_for_link(struct e1000_hw *hw)
2896{
2897 uint32_t rxcw = 0;
2898 uint32_t ctrl;
2899 uint32_t status;
2900 uint32_t rctl;
2901 uint32_t icr;
2902 uint32_t signal = 0;
2903 int32_t ret_val;
2904 uint16_t phy_data;
2905
2906 DEBUGFUNC("e1000_check_for_link");
2907
2908 ctrl = E1000_READ_REG(hw, CTRL);
2909 status = E1000_READ_REG(hw, STATUS);
2910
2911 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2912 * set when the optics detect a signal. On older adapters, it will be
2913 * cleared when there is a signal. This applies to fiber media only.
2914 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002915 if ((hw->media_type == e1000_media_type_fiber) ||
2916 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 rxcw = E1000_READ_REG(hw, RXCW);
2918
Auke Kok8fc897b2006-08-28 14:56:16 -07002919 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002921 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 hw->get_link_status = FALSE;
2923 }
2924 }
2925
2926 /* If we have a copper PHY then we only want to go out to the PHY
2927 * registers to see if Auto-Neg has completed and/or if our link
2928 * status has changed. The get_link_status flag will be set if we
2929 * receive a Link Status Change interrupt or we have Rx Sequence
2930 * Errors.
2931 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002932 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 /* First we want to see if the MII Status Register reports
2934 * link. If so, then we want to get the current speed/duplex
2935 * of the PHY.
2936 * Read the register twice since the link bit is sticky.
2937 */
2938 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002939 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return ret_val;
2941 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002942 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 return ret_val;
2944
Auke Kok8fc897b2006-08-28 14:56:16 -07002945 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 hw->get_link_status = FALSE;
2947 /* Check if there was DownShift, must be checked immediately after
2948 * link-up */
2949 e1000_check_downshift(hw);
2950
2951 /* If we are on 82544 or 82543 silicon and speed/duplex
2952 * are forced to 10H or 10F, then we will implement the polarity
2953 * reversal workaround. We disable interrupts first, and upon
2954 * returning, place the devices interrupt state to its previous
2955 * value except for the link status change interrupt which will
2956 * happen due to the execution of this workaround.
2957 */
2958
Auke Kok8fc897b2006-08-28 14:56:16 -07002959 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2960 (!hw->autoneg) &&
2961 (hw->forced_speed_duplex == e1000_10_full ||
2962 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2964 ret_val = e1000_polarity_reversal_workaround(hw);
2965 icr = E1000_READ_REG(hw, ICR);
2966 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2967 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2968 }
2969
2970 } else {
2971 /* No link detected */
2972 e1000_config_dsp_after_link_change(hw, FALSE);
2973 return 0;
2974 }
2975
2976 /* If we are forcing speed/duplex, then we simply return since
2977 * we have already determined whether we have link or not.
2978 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002979 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
2981 /* optimize the dsp settings for the igp phy */
2982 e1000_config_dsp_after_link_change(hw, TRUE);
2983
2984 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2985 * have Si on board that is 82544 or newer, Auto
2986 * Speed Detection takes care of MAC speed/duplex
2987 * configuration. So we only need to configure Collision
2988 * Distance in the MAC. Otherwise, we need to force
2989 * speed/duplex on the MAC to the current PHY speed/duplex
2990 * settings.
2991 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002992 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 e1000_config_collision_dist(hw);
2994 else {
2995 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002996 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 DEBUGOUT("Error configuring MAC to PHY settings\n");
2998 return ret_val;
2999 }
3000 }
3001
3002 /* Configure Flow Control now that Auto-Neg has completed. First, we
3003 * need to restore the desired flow control settings because we may
3004 * have had to re-autoneg with a different link partner.
3005 */
3006 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003007 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 DEBUGOUT("Error configuring flow control\n");
3009 return ret_val;
3010 }
3011
3012 /* At this point we know that we are on copper and we have
3013 * auto-negotiated link. These are conditions for checking the link
3014 * partner capability register. We use the link speed to determine if
3015 * TBI compatibility needs to be turned on or off. If the link is not
3016 * at gigabit speed, then TBI compatibility is not needed. If we are
3017 * at gigabit speed, we turn on TBI compatibility.
3018 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003019 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003021 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3022 if (ret_val) {
3023 DEBUGOUT("Error getting link speed and duplex\n");
3024 return ret_val;
3025 }
3026 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 /* If link speed is not set to gigabit speed, we do not need
3028 * to enable TBI compatibility.
3029 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003030 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 /* If we previously were in the mode, turn it off. */
3032 rctl = E1000_READ_REG(hw, RCTL);
3033 rctl &= ~E1000_RCTL_SBP;
3034 E1000_WRITE_REG(hw, RCTL, rctl);
3035 hw->tbi_compatibility_on = FALSE;
3036 }
3037 } else {
3038 /* If TBI compatibility is was previously off, turn it on. For
3039 * compatibility with a TBI link partner, we will store bad
3040 * packets. Some frames have an additional byte on the end and
3041 * will look like CRC errors to to the hardware.
3042 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003043 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 hw->tbi_compatibility_on = TRUE;
3045 rctl = E1000_READ_REG(hw, RCTL);
3046 rctl |= E1000_RCTL_SBP;
3047 E1000_WRITE_REG(hw, RCTL, rctl);
3048 }
3049 }
3050 }
3051 }
3052 /* If we don't have link (auto-negotiation failed or link partner cannot
3053 * auto-negotiate), the cable is plugged in (we have signal), and our
3054 * link partner is not trying to auto-negotiate with us (we are receiving
3055 * idles or data), we need to force link up. We also need to give
3056 * auto-negotiation time to complete, in case the cable was just plugged
3057 * in. The autoneg_failed flag does this.
3058 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003059 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003061 (hw->media_type == e1000_media_type_internal_serdes)) &&
3062 (!(status & E1000_STATUS_LU)) &&
3063 (!(rxcw & E1000_RXCW_C))) {
3064 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 hw->autoneg_failed = 1;
3066 return 0;
3067 }
Auke Koka42a5072006-05-23 13:36:01 -07003068 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069
3070 /* Disable auto-negotiation in the TXCW register */
3071 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3072
3073 /* Force link-up and also force full-duplex. */
3074 ctrl = E1000_READ_REG(hw, CTRL);
3075 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3076 E1000_WRITE_REG(hw, CTRL, ctrl);
3077
3078 /* Configure Flow Control after forcing link up. */
3079 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003080 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 DEBUGOUT("Error configuring flow control\n");
3082 return ret_val;
3083 }
3084 }
3085 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3086 * auto-negotiation in the TXCW register and disable forced link in the
3087 * Device Control register in an attempt to auto-negotiate with our link
3088 * partner.
3089 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003090 else if (((hw->media_type == e1000_media_type_fiber) ||
3091 (hw->media_type == e1000_media_type_internal_serdes)) &&
3092 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003093 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3095 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3096
3097 hw->serdes_link_down = FALSE;
3098 }
3099 /* If we force link for non-auto-negotiation switch, check link status
3100 * based on MAC synchronization for internal serdes media type.
3101 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003102 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3103 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 /* SYNCH bit and IV bit are sticky. */
3105 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003106 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3107 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 hw->serdes_link_down = FALSE;
3109 DEBUGOUT("SERDES: Link is up.\n");
3110 }
3111 } else {
3112 hw->serdes_link_down = TRUE;
3113 DEBUGOUT("SERDES: Link is down.\n");
3114 }
3115 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003116 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3117 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3119 }
3120 return E1000_SUCCESS;
3121}
3122
3123/******************************************************************************
3124 * Detects the current speed and duplex settings of the hardware.
3125 *
3126 * hw - Struct containing variables accessed by shared code
3127 * speed - Speed of the connection
3128 * duplex - Duplex setting of the connection
3129 *****************************************************************************/
3130int32_t
3131e1000_get_speed_and_duplex(struct e1000_hw *hw,
3132 uint16_t *speed,
3133 uint16_t *duplex)
3134{
3135 uint32_t status;
3136 int32_t ret_val;
3137 uint16_t phy_data;
3138
3139 DEBUGFUNC("e1000_get_speed_and_duplex");
3140
Auke Kok8fc897b2006-08-28 14:56:16 -07003141 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003143 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 *speed = SPEED_1000;
3145 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003146 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 *speed = SPEED_100;
3148 DEBUGOUT("100 Mbs, ");
3149 } else {
3150 *speed = SPEED_10;
3151 DEBUGOUT("10 Mbs, ");
3152 }
3153
Auke Kok8fc897b2006-08-28 14:56:16 -07003154 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003156 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 } else {
3158 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003159 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003162 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 *speed = SPEED_1000;
3164 *duplex = FULL_DUPLEX;
3165 }
3166
3167 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3168 * if it is operating at half duplex. Here we set the duplex settings to
3169 * match the duplex in the link partner's capabilities.
3170 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003171 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003173 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 return ret_val;
3175
Auke Kok8fc897b2006-08-28 14:56:16 -07003176 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 *duplex = HALF_DUPLEX;
3178 else {
3179 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003180 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003182 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3184 *duplex = HALF_DUPLEX;
3185 }
3186 }
3187
Auke Kok76c224b2006-05-23 13:36:06 -07003188 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003189 (hw->media_type == e1000_media_type_copper)) {
3190 if (*speed == SPEED_1000)
3191 ret_val = e1000_configure_kmrn_for_1000(hw);
3192 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003193 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3194 if (ret_val)
3195 return ret_val;
3196 }
3197
3198 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3199 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003200 if (ret_val)
3201 return ret_val;
3202 }
3203
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return E1000_SUCCESS;
3205}
3206
3207/******************************************************************************
3208* Blocks until autoneg completes or times out (~4.5 seconds)
3209*
3210* hw - Struct containing variables accessed by shared code
3211******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003212static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213e1000_wait_autoneg(struct e1000_hw *hw)
3214{
3215 int32_t ret_val;
3216 uint16_t i;
3217 uint16_t phy_data;
3218
3219 DEBUGFUNC("e1000_wait_autoneg");
3220 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3221
3222 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003223 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 /* Read the MII Status Register and wait for Auto-Neg
3225 * Complete bit to be set.
3226 */
3227 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003228 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 return ret_val;
3230 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003231 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003233 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 return E1000_SUCCESS;
3235 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003236 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 }
3238 return E1000_SUCCESS;
3239}
3240
3241/******************************************************************************
3242* Raises the Management Data Clock
3243*
3244* hw - Struct containing variables accessed by shared code
3245* ctrl - Device control register's current value
3246******************************************************************************/
3247static void
3248e1000_raise_mdi_clk(struct e1000_hw *hw,
3249 uint32_t *ctrl)
3250{
3251 /* Raise the clock input to the Management Data Clock (by setting the MDC
3252 * bit), and then delay 10 microseconds.
3253 */
3254 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3255 E1000_WRITE_FLUSH(hw);
3256 udelay(10);
3257}
3258
3259/******************************************************************************
3260* Lowers the Management Data Clock
3261*
3262* hw - Struct containing variables accessed by shared code
3263* ctrl - Device control register's current value
3264******************************************************************************/
3265static void
3266e1000_lower_mdi_clk(struct e1000_hw *hw,
3267 uint32_t *ctrl)
3268{
3269 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3270 * bit), and then delay 10 microseconds.
3271 */
3272 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3273 E1000_WRITE_FLUSH(hw);
3274 udelay(10);
3275}
3276
3277/******************************************************************************
3278* Shifts data bits out to the PHY
3279*
3280* hw - Struct containing variables accessed by shared code
3281* data - Data to send out to the PHY
3282* count - Number of bits to shift out
3283*
3284* Bits are shifted out in MSB to LSB order.
3285******************************************************************************/
3286static void
3287e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3288 uint32_t data,
3289 uint16_t count)
3290{
3291 uint32_t ctrl;
3292 uint32_t mask;
3293
3294 /* We need to shift "count" number of bits out to the PHY. So, the value
3295 * in the "data" parameter will be shifted out to the PHY one bit at a
3296 * time. In order to do this, "data" must be broken down into bits.
3297 */
3298 mask = 0x01;
3299 mask <<= (count - 1);
3300
3301 ctrl = E1000_READ_REG(hw, CTRL);
3302
3303 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3304 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3305
Auke Kok8fc897b2006-08-28 14:56:16 -07003306 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3308 * then raising and lowering the Management Data Clock. A "0" is
3309 * shifted out to the PHY by setting the MDIO bit to "0" and then
3310 * raising and lowering the clock.
3311 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003312 if (data & mask)
3313 ctrl |= E1000_CTRL_MDIO;
3314 else
3315 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
3317 E1000_WRITE_REG(hw, CTRL, ctrl);
3318 E1000_WRITE_FLUSH(hw);
3319
3320 udelay(10);
3321
3322 e1000_raise_mdi_clk(hw, &ctrl);
3323 e1000_lower_mdi_clk(hw, &ctrl);
3324
3325 mask = mask >> 1;
3326 }
3327}
3328
3329/******************************************************************************
3330* Shifts data bits in from the PHY
3331*
3332* hw - Struct containing variables accessed by shared code
3333*
3334* Bits are shifted in in MSB to LSB order.
3335******************************************************************************/
3336static uint16_t
3337e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3338{
3339 uint32_t ctrl;
3340 uint16_t data = 0;
3341 uint8_t i;
3342
3343 /* In order to read a register from the PHY, we need to shift in a total
3344 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3345 * to avoid contention on the MDIO pin when a read operation is performed.
3346 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3347 * by raising the input to the Management Data Clock (setting the MDC bit),
3348 * and then reading the value of the MDIO bit.
3349 */
3350 ctrl = E1000_READ_REG(hw, CTRL);
3351
3352 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3353 ctrl &= ~E1000_CTRL_MDIO_DIR;
3354 ctrl &= ~E1000_CTRL_MDIO;
3355
3356 E1000_WRITE_REG(hw, CTRL, ctrl);
3357 E1000_WRITE_FLUSH(hw);
3358
3359 /* Raise and Lower the clock before reading in the data. This accounts for
3360 * the turnaround bits. The first clock occurred when we clocked out the
3361 * last bit of the Register Address.
3362 */
3363 e1000_raise_mdi_clk(hw, &ctrl);
3364 e1000_lower_mdi_clk(hw, &ctrl);
3365
Auke Kok8fc897b2006-08-28 14:56:16 -07003366 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 data = data << 1;
3368 e1000_raise_mdi_clk(hw, &ctrl);
3369 ctrl = E1000_READ_REG(hw, CTRL);
3370 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003371 if (ctrl & E1000_CTRL_MDIO)
3372 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 e1000_lower_mdi_clk(hw, &ctrl);
3374 }
3375
3376 e1000_raise_mdi_clk(hw, &ctrl);
3377 e1000_lower_mdi_clk(hw, &ctrl);
3378
3379 return data;
3380}
3381
Adrian Bunke4c780b2006-08-14 23:00:10 -07003382static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003383e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3384{
3385 uint32_t swfw_sync = 0;
3386 uint32_t swmask = mask;
3387 uint32_t fwmask = mask << 16;
3388 int32_t timeout = 200;
3389
3390 DEBUGFUNC("e1000_swfw_sync_acquire");
3391
Auke Kokcd94dd02006-06-27 09:08:22 -07003392 if (hw->swfwhw_semaphore_present)
3393 return e1000_get_software_flag(hw);
3394
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003395 if (!hw->swfw_sync_present)
3396 return e1000_get_hw_eeprom_semaphore(hw);
3397
Auke Kok8fc897b2006-08-28 14:56:16 -07003398 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003399 if (e1000_get_hw_eeprom_semaphore(hw))
3400 return -E1000_ERR_SWFW_SYNC;
3401
3402 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3403 if (!(swfw_sync & (fwmask | swmask))) {
3404 break;
3405 }
3406
3407 /* firmware currently using resource (fwmask) */
3408 /* or other software thread currently using resource (swmask) */
3409 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003410 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003411 timeout--;
3412 }
3413
3414 if (!timeout) {
3415 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3416 return -E1000_ERR_SWFW_SYNC;
3417 }
3418
3419 swfw_sync |= swmask;
3420 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3421
3422 e1000_put_hw_eeprom_semaphore(hw);
3423 return E1000_SUCCESS;
3424}
3425
Adrian Bunke4c780b2006-08-14 23:00:10 -07003426static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003427e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3428{
3429 uint32_t swfw_sync;
3430 uint32_t swmask = mask;
3431
3432 DEBUGFUNC("e1000_swfw_sync_release");
3433
Auke Kokcd94dd02006-06-27 09:08:22 -07003434 if (hw->swfwhw_semaphore_present) {
3435 e1000_release_software_flag(hw);
3436 return;
3437 }
3438
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003439 if (!hw->swfw_sync_present) {
3440 e1000_put_hw_eeprom_semaphore(hw);
3441 return;
3442 }
3443
3444 /* if (e1000_get_hw_eeprom_semaphore(hw))
3445 * return -E1000_ERR_SWFW_SYNC; */
3446 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3447 /* empty */
3448
3449 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3450 swfw_sync &= ~swmask;
3451 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3452
3453 e1000_put_hw_eeprom_semaphore(hw);
3454}
3455
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456/*****************************************************************************
3457* Reads the value from a PHY register, if the value is on a specific non zero
3458* page, sets the page first.
3459* hw - Struct containing variables accessed by shared code
3460* reg_addr - address of the PHY register to read
3461******************************************************************************/
3462int32_t
3463e1000_read_phy_reg(struct e1000_hw *hw,
3464 uint32_t reg_addr,
3465 uint16_t *phy_data)
3466{
3467 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003468 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
3470 DEBUGFUNC("e1000_read_phy_reg");
3471
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003472 if ((hw->mac_type == e1000_80003es2lan) &&
3473 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3474 swfw = E1000_SWFW_PHY1_SM;
3475 } else {
3476 swfw = E1000_SWFW_PHY0_SM;
3477 }
3478 if (e1000_swfw_sync_acquire(hw, swfw))
3479 return -E1000_ERR_SWFW_SYNC;
3480
Auke Kokcd94dd02006-06-27 09:08:22 -07003481 if ((hw->phy_type == e1000_phy_igp ||
3482 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003483 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3485 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3486 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003487 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003488 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 return ret_val;
3490 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003491 } else if (hw->phy_type == e1000_phy_gg82563) {
3492 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3493 (hw->mac_type == e1000_80003es2lan)) {
3494 /* Select Configuration Page */
3495 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3496 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3497 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3498 } else {
3499 /* Use Alternative Page Select register to access
3500 * registers 30 and 31
3501 */
3502 ret_val = e1000_write_phy_reg_ex(hw,
3503 GG82563_PHY_PAGE_SELECT_ALT,
3504 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3505 }
3506
3507 if (ret_val) {
3508 e1000_swfw_sync_release(hw, swfw);
3509 return ret_val;
3510 }
3511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 }
3513
3514 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3515 phy_data);
3516
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003517 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 return ret_val;
3519}
3520
Nicholas Nunley35574762006-09-27 12:53:34 -07003521static int32_t
3522e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 uint16_t *phy_data)
3524{
3525 uint32_t i;
3526 uint32_t mdic = 0;
3527 const uint32_t phy_addr = 1;
3528
3529 DEBUGFUNC("e1000_read_phy_reg_ex");
3530
Auke Kok8fc897b2006-08-28 14:56:16 -07003531 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3533 return -E1000_ERR_PARAM;
3534 }
3535
Auke Kok8fc897b2006-08-28 14:56:16 -07003536 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 /* Set up Op-code, Phy Address, and register address in the MDI
3538 * Control register. The MAC will take care of interfacing with the
3539 * PHY to retrieve the desired data.
3540 */
3541 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3542 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3543 (E1000_MDIC_OP_READ));
3544
3545 E1000_WRITE_REG(hw, MDIC, mdic);
3546
3547 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003548 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 udelay(50);
3550 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003551 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003553 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 DEBUGOUT("MDI Read did not complete\n");
3555 return -E1000_ERR_PHY;
3556 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003557 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 DEBUGOUT("MDI Error\n");
3559 return -E1000_ERR_PHY;
3560 }
3561 *phy_data = (uint16_t) mdic;
3562 } else {
3563 /* We must first send a preamble through the MDIO pin to signal the
3564 * beginning of an MII instruction. This is done by sending 32
3565 * consecutive "1" bits.
3566 */
3567 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3568
3569 /* Now combine the next few fields that are required for a read
3570 * operation. We use this method instead of calling the
3571 * e1000_shift_out_mdi_bits routine five different times. The format of
3572 * a MII read instruction consists of a shift out of 14 bits and is
3573 * defined as follows:
3574 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3575 * followed by a shift in of 18 bits. This first two bits shifted in
3576 * are TurnAround bits used to avoid contention on the MDIO pin when a
3577 * READ operation is performed. These two bits are thrown away
3578 * followed by a shift in of 16 bits which contains the desired data.
3579 */
3580 mdic = ((reg_addr) | (phy_addr << 5) |
3581 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3582
3583 e1000_shift_out_mdi_bits(hw, mdic, 14);
3584
3585 /* Now that we've shifted out the read command to the MII, we need to
3586 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3587 * register address.
3588 */
3589 *phy_data = e1000_shift_in_mdi_bits(hw);
3590 }
3591 return E1000_SUCCESS;
3592}
3593
3594/******************************************************************************
3595* Writes a value to a PHY register
3596*
3597* hw - Struct containing variables accessed by shared code
3598* reg_addr - address of the PHY register to write
3599* data - data to write to the PHY
3600******************************************************************************/
3601int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003602e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 uint16_t phy_data)
3604{
3605 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003606 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607
3608 DEBUGFUNC("e1000_write_phy_reg");
3609
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003610 if ((hw->mac_type == e1000_80003es2lan) &&
3611 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3612 swfw = E1000_SWFW_PHY1_SM;
3613 } else {
3614 swfw = E1000_SWFW_PHY0_SM;
3615 }
3616 if (e1000_swfw_sync_acquire(hw, swfw))
3617 return -E1000_ERR_SWFW_SYNC;
3618
Auke Kokcd94dd02006-06-27 09:08:22 -07003619 if ((hw->phy_type == e1000_phy_igp ||
3620 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003621 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3623 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3624 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003625 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003626 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 return ret_val;
3628 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003629 } else if (hw->phy_type == e1000_phy_gg82563) {
3630 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3631 (hw->mac_type == e1000_80003es2lan)) {
3632 /* Select Configuration Page */
3633 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3634 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3635 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3636 } else {
3637 /* Use Alternative Page Select register to access
3638 * registers 30 and 31
3639 */
3640 ret_val = e1000_write_phy_reg_ex(hw,
3641 GG82563_PHY_PAGE_SELECT_ALT,
3642 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3643 }
3644
3645 if (ret_val) {
3646 e1000_swfw_sync_release(hw, swfw);
3647 return ret_val;
3648 }
3649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 }
3651
3652 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3653 phy_data);
3654
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003655 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 return ret_val;
3657}
3658
Nicholas Nunley35574762006-09-27 12:53:34 -07003659static int32_t
3660e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3661 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662{
3663 uint32_t i;
3664 uint32_t mdic = 0;
3665 const uint32_t phy_addr = 1;
3666
3667 DEBUGFUNC("e1000_write_phy_reg_ex");
3668
Auke Kok8fc897b2006-08-28 14:56:16 -07003669 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3671 return -E1000_ERR_PARAM;
3672 }
3673
Auke Kok8fc897b2006-08-28 14:56:16 -07003674 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 /* Set up Op-code, Phy Address, register address, and data intended
3676 * for the PHY register in the MDI Control register. The MAC will take
3677 * care of interfacing with the PHY to send the desired data.
3678 */
3679 mdic = (((uint32_t) phy_data) |
3680 (reg_addr << E1000_MDIC_REG_SHIFT) |
3681 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3682 (E1000_MDIC_OP_WRITE));
3683
3684 E1000_WRITE_REG(hw, MDIC, mdic);
3685
3686 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003687 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 udelay(5);
3689 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003690 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003692 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 DEBUGOUT("MDI Write did not complete\n");
3694 return -E1000_ERR_PHY;
3695 }
3696 } else {
3697 /* We'll need to use the SW defined pins to shift the write command
3698 * out to the PHY. We first send a preamble to the PHY to signal the
3699 * beginning of the MII instruction. This is done by sending 32
3700 * consecutive "1" bits.
3701 */
3702 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3703
3704 /* Now combine the remaining required fields that will indicate a
3705 * write operation. We use this method instead of calling the
3706 * e1000_shift_out_mdi_bits routine for each field in the command. The
3707 * format of a MII write instruction is as follows:
3708 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3709 */
3710 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3711 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3712 mdic <<= 16;
3713 mdic |= (uint32_t) phy_data;
3714
3715 e1000_shift_out_mdi_bits(hw, mdic, 32);
3716 }
3717
3718 return E1000_SUCCESS;
3719}
3720
Adrian Bunke4c780b2006-08-14 23:00:10 -07003721static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003722e1000_read_kmrn_reg(struct e1000_hw *hw,
3723 uint32_t reg_addr,
3724 uint16_t *data)
3725{
3726 uint32_t reg_val;
3727 uint16_t swfw;
3728 DEBUGFUNC("e1000_read_kmrn_reg");
3729
3730 if ((hw->mac_type == e1000_80003es2lan) &&
3731 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3732 swfw = E1000_SWFW_PHY1_SM;
3733 } else {
3734 swfw = E1000_SWFW_PHY0_SM;
3735 }
3736 if (e1000_swfw_sync_acquire(hw, swfw))
3737 return -E1000_ERR_SWFW_SYNC;
3738
3739 /* Write register address */
3740 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3741 E1000_KUMCTRLSTA_OFFSET) |
3742 E1000_KUMCTRLSTA_REN;
3743 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3744 udelay(2);
3745
3746 /* Read the data returned */
3747 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3748 *data = (uint16_t)reg_val;
3749
3750 e1000_swfw_sync_release(hw, swfw);
3751 return E1000_SUCCESS;
3752}
3753
Adrian Bunke4c780b2006-08-14 23:00:10 -07003754static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003755e1000_write_kmrn_reg(struct e1000_hw *hw,
3756 uint32_t reg_addr,
3757 uint16_t data)
3758{
3759 uint32_t reg_val;
3760 uint16_t swfw;
3761 DEBUGFUNC("e1000_write_kmrn_reg");
3762
3763 if ((hw->mac_type == e1000_80003es2lan) &&
3764 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3765 swfw = E1000_SWFW_PHY1_SM;
3766 } else {
3767 swfw = E1000_SWFW_PHY0_SM;
3768 }
3769 if (e1000_swfw_sync_acquire(hw, swfw))
3770 return -E1000_ERR_SWFW_SYNC;
3771
3772 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3773 E1000_KUMCTRLSTA_OFFSET) | data;
3774 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3775 udelay(2);
3776
3777 e1000_swfw_sync_release(hw, swfw);
3778 return E1000_SUCCESS;
3779}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003780
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781/******************************************************************************
3782* Returns the PHY to the power-on reset state
3783*
3784* hw - Struct containing variables accessed by shared code
3785******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003786int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787e1000_phy_hw_reset(struct e1000_hw *hw)
3788{
3789 uint32_t ctrl, ctrl_ext;
3790 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003791 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003792 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
3794 DEBUGFUNC("e1000_phy_hw_reset");
3795
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003796 /* In the case of the phy reset being blocked, it's not an error, we
3797 * simply return success without performing the reset. */
3798 ret_val = e1000_check_phy_reset_block(hw);
3799 if (ret_val)
3800 return E1000_SUCCESS;
3801
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 DEBUGOUT("Resetting Phy...\n");
3803
Auke Kok8fc897b2006-08-28 14:56:16 -07003804 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003805 if ((hw->mac_type == e1000_80003es2lan) &&
3806 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3807 swfw = E1000_SWFW_PHY1_SM;
3808 } else {
3809 swfw = E1000_SWFW_PHY0_SM;
3810 }
3811 if (e1000_swfw_sync_acquire(hw, swfw)) {
3812 e1000_release_software_semaphore(hw);
3813 return -E1000_ERR_SWFW_SYNC;
3814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3816 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003817 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003818 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003819 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 */
3821 ctrl = E1000_READ_REG(hw, CTRL);
3822 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3823 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003824
3825 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003826 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003827 else
3828 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003829
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 E1000_WRITE_REG(hw, CTRL, ctrl);
3831 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003832
Jeff Kirsherfd803242005-12-13 00:06:22 -05003833 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003834 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003835
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003836 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 } else {
3838 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3839 * bit to put the PHY into reset. Then, take it out of reset.
3840 */
3841 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3842 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3843 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3844 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3845 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003846 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3848 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3849 E1000_WRITE_FLUSH(hw);
3850 }
3851 udelay(150);
3852
Auke Kok8fc897b2006-08-28 14:56:16 -07003853 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 /* Configure activity LED after PHY reset */
3855 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3856 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3857 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3858 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3859 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003860
3861 /* Wait for FW to finish PHY configuration. */
3862 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003863 if (ret_val != E1000_SUCCESS)
3864 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003865 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003866
Auke Kok8fc897b2006-08-28 14:56:16 -07003867 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3868 ret_val = e1000_init_lcd_from_nvm(hw);
3869
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003870 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871}
3872
3873/******************************************************************************
3874* Resets the PHY
3875*
3876* hw - Struct containing variables accessed by shared code
3877*
3878* Sets bit 15 of the MII Control regiser
3879******************************************************************************/
3880int32_t
3881e1000_phy_reset(struct e1000_hw *hw)
3882{
3883 int32_t ret_val;
3884 uint16_t phy_data;
3885
3886 DEBUGFUNC("e1000_phy_reset");
3887
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003888 /* In the case of the phy reset being blocked, it's not an error, we
3889 * simply return success without performing the reset. */
3890 ret_val = e1000_check_phy_reset_block(hw);
3891 if (ret_val)
3892 return E1000_SUCCESS;
3893
3894 switch (hw->mac_type) {
3895 case e1000_82541_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003896 case e1000_82571:
3897 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07003898 case e1000_ich8lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003899 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003900 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003901 return ret_val;
3902 break;
3903 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003905 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 return ret_val;
3907
3908 phy_data |= MII_CR_RESET;
3909 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003910 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 return ret_val;
3912
3913 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003914 break;
3915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
Auke Kok8fc897b2006-08-28 14:56:16 -07003917 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 e1000_phy_init_script(hw);
3919
3920 return E1000_SUCCESS;
3921}
3922
3923/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003924* Work-around for 82566 power-down: on D3 entry-
3925* 1) disable gigabit link
3926* 2) write VR power-down enable
3927* 3) read it back
3928* if successful continue, else issue LCD reset and repeat
3929*
3930* hw - struct containing variables accessed by shared code
3931******************************************************************************/
3932void
3933e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3934{
3935 int32_t reg;
3936 uint16_t phy_data;
3937 int32_t retry = 0;
3938
3939 DEBUGFUNC("e1000_phy_powerdown_workaround");
3940
3941 if (hw->phy_type != e1000_phy_igp_3)
3942 return;
3943
3944 do {
3945 /* Disable link */
3946 reg = E1000_READ_REG(hw, PHY_CTRL);
3947 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3948 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3949
3950 /* Write VR power-down enable */
3951 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3952 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data |
3953 IGP3_VR_CTRL_MODE_SHUT);
3954
3955 /* Read it back and test */
3956 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3957 if ((phy_data & IGP3_VR_CTRL_MODE_SHUT) || retry)
3958 break;
3959
3960 /* Issue PHY reset and repeat at most one more time */
3961 reg = E1000_READ_REG(hw, CTRL);
3962 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3963 retry++;
3964 } while (retry);
3965
3966 return;
3967
3968}
3969
3970/******************************************************************************
3971* Work-around for 82566 Kumeran PCS lock loss:
3972* On link status change (i.e. PCI reset, speed change) and link is up and
3973* speed is gigabit-
3974* 0) if workaround is optionally disabled do nothing
3975* 1) wait 1ms for Kumeran link to come up
3976* 2) check Kumeran Diagnostic register PCS lock loss bit
3977* 3) if not set the link is locked (all is good), otherwise...
3978* 4) reset the PHY
3979* 5) repeat up to 10 times
3980* Note: this is only called for IGP3 copper when speed is 1gb.
3981*
3982* hw - struct containing variables accessed by shared code
3983******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003984static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003985e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3986{
3987 int32_t ret_val;
3988 int32_t reg;
3989 int32_t cnt;
3990 uint16_t phy_data;
3991
3992 if (hw->kmrn_lock_loss_workaround_disabled)
3993 return E1000_SUCCESS;
3994
Auke Kok8fc897b2006-08-28 14:56:16 -07003995 /* Make sure link is up before proceeding. If not just return.
3996 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003997 * stability */
3998 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3999 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4000
4001 if (phy_data & MII_SR_LINK_STATUS) {
4002 for (cnt = 0; cnt < 10; cnt++) {
4003 /* read once to clear */
4004 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4005 if (ret_val)
4006 return ret_val;
4007 /* and again to get new status */
4008 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4009 if (ret_val)
4010 return ret_val;
4011
4012 /* check for PCS lock */
4013 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4014 return E1000_SUCCESS;
4015
4016 /* Issue PHY reset */
4017 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004018 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004019 }
4020 /* Disable GigE link negotiation */
4021 reg = E1000_READ_REG(hw, PHY_CTRL);
4022 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4023 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4024
4025 /* unable to acquire PCS lock */
4026 return E1000_ERR_PHY;
4027 }
4028
4029 return E1000_SUCCESS;
4030}
4031
4032/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033* Probes the expected PHY address for known PHY IDs
4034*
4035* hw - Struct containing variables accessed by shared code
4036******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004037static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038e1000_detect_gig_phy(struct e1000_hw *hw)
4039{
4040 int32_t phy_init_status, ret_val;
4041 uint16_t phy_id_high, phy_id_low;
4042 boolean_t match = FALSE;
4043
4044 DEBUGFUNC("e1000_detect_gig_phy");
4045
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004046 /* The 82571 firmware may still be configuring the PHY. In this
4047 * case, we cannot access the PHY until the configuration is done. So
4048 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004049 if (hw->mac_type == e1000_82571 ||
4050 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004051 hw->phy_id = IGP01E1000_I_PHY_ID;
4052 hw->phy_type = e1000_phy_igp_2;
4053 return E1000_SUCCESS;
4054 }
4055
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004056 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4057 * around that forces PHY page 0 to be set or the reads fail. The rest of
4058 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4059 * So for ESB-2 we need to have this set so our reads won't fail. If the
4060 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4061 * this out as well. */
4062 if (hw->mac_type == e1000_80003es2lan)
4063 hw->phy_type = e1000_phy_gg82563;
4064
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 /* Read the PHY ID Registers to identify which PHY is onboard. */
4066 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004067 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 return ret_val;
4069
4070 hw->phy_id = (uint32_t) (phy_id_high << 16);
4071 udelay(20);
4072 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004073 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 return ret_val;
4075
4076 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4077 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4078
Auke Kok8fc897b2006-08-28 14:56:16 -07004079 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004081 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 break;
4083 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004084 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 break;
4086 case e1000_82540:
4087 case e1000_82545:
4088 case e1000_82545_rev_3:
4089 case e1000_82546:
4090 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004091 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 break;
4093 case e1000_82541:
4094 case e1000_82541_rev_2:
4095 case e1000_82547:
4096 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004097 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004099 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004100 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004101 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004102 case e1000_80003es2lan:
4103 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4104 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004105 case e1000_ich8lan:
4106 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4107 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4108 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4109 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4110 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 default:
4112 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4113 return -E1000_ERR_CONFIG;
4114 }
4115 phy_init_status = e1000_set_phy_type(hw);
4116
4117 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4118 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4119 return E1000_SUCCESS;
4120 }
4121 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4122 return -E1000_ERR_PHY;
4123}
4124
4125/******************************************************************************
4126* Resets the PHY's DSP
4127*
4128* hw - Struct containing variables accessed by shared code
4129******************************************************************************/
4130static int32_t
4131e1000_phy_reset_dsp(struct e1000_hw *hw)
4132{
4133 int32_t ret_val;
4134 DEBUGFUNC("e1000_phy_reset_dsp");
4135
4136 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004137 if (hw->phy_type != e1000_phy_gg82563) {
4138 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004139 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004142 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004144 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004146 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147
4148 return ret_val;
4149}
4150
4151/******************************************************************************
4152* Get PHY information from various PHY registers for igp PHY only.
4153*
4154* hw - Struct containing variables accessed by shared code
4155* phy_info - PHY information structure
4156******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004157static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158e1000_phy_igp_get_info(struct e1000_hw *hw,
4159 struct e1000_phy_info *phy_info)
4160{
4161 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004162 uint16_t phy_data, min_length, max_length, average;
4163 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164
4165 DEBUGFUNC("e1000_phy_igp_get_info");
4166
4167 /* The downshift status is checked only once, after link is established,
4168 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004169 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170
4171 /* IGP01E1000 does not need to support it. */
4172 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4173
4174 /* IGP01E1000 always correct polarity reversal */
4175 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4176
4177 /* Check polarity status */
4178 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004179 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 return ret_val;
4181
4182 phy_info->cable_polarity = polarity;
4183
4184 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004185 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 return ret_val;
4187
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004188 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4189 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190
Auke Kok8fc897b2006-08-28 14:56:16 -07004191 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 IGP01E1000_PSSR_SPEED_1000MBPS) {
4193 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4194 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004195 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 return ret_val;
4197
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004198 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4199 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4200 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4201 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4202 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4203 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204
4205 /* Get cable length */
4206 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004207 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 return ret_val;
4209
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004210 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 average = (max_length + min_length) / 2;
4212
Auke Kok8fc897b2006-08-28 14:56:16 -07004213 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004215 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004217 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004219 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 phy_info->cable_length = e1000_cable_length_110_140;
4221 else
4222 phy_info->cable_length = e1000_cable_length_140;
4223 }
4224
4225 return E1000_SUCCESS;
4226}
4227
4228/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004229* Get PHY information from various PHY registers for ife PHY only.
4230*
4231* hw - Struct containing variables accessed by shared code
4232* phy_info - PHY information structure
4233******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004234static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004235e1000_phy_ife_get_info(struct e1000_hw *hw,
4236 struct e1000_phy_info *phy_info)
4237{
4238 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004239 uint16_t phy_data;
4240 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004241
4242 DEBUGFUNC("e1000_phy_ife_get_info");
4243
4244 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4245 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4246
4247 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4248 if (ret_val)
4249 return ret_val;
4250 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004251 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4252 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4253 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004254
4255 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4256 ret_val = e1000_check_polarity(hw, &polarity);
4257 if (ret_val)
4258 return ret_val;
4259 } else {
4260 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004261 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4262 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4263 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004264 }
4265 phy_info->cable_polarity = polarity;
4266
4267 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4268 if (ret_val)
4269 return ret_val;
4270
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004271 phy_info->mdix_mode = (e1000_auto_x_mode)
4272 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4273 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004274
4275 return E1000_SUCCESS;
4276}
4277
4278/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279* Get PHY information from various PHY registers fot m88 PHY only.
4280*
4281* hw - Struct containing variables accessed by shared code
4282* phy_info - PHY information structure
4283******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004284static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285e1000_phy_m88_get_info(struct e1000_hw *hw,
4286 struct e1000_phy_info *phy_info)
4287{
4288 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004289 uint16_t phy_data;
4290 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291
4292 DEBUGFUNC("e1000_phy_m88_get_info");
4293
4294 /* The downshift status is checked only once, after link is established,
4295 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004296 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297
4298 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004299 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 return ret_val;
4301
4302 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004303 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4304 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4305 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4306
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004308 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4309 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4310 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311
4312 /* Check polarity status */
4313 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004314 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004315 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 phy_info->cable_polarity = polarity;
4317
4318 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004319 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 return ret_val;
4321
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004322 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4323 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
4325 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4326 /* Cable Length Estimation and Local/Remote Receiver Information
4327 * are only valid at 1000 Mbps.
4328 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004329 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004330 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004331 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4332 } else {
4333 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4334 &phy_data);
4335 if (ret_val)
4336 return ret_val;
4337
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004338 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340
4341 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004342 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 return ret_val;
4344
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004345 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4346 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4347 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4348 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4349 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4350 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 }
4353
4354 return E1000_SUCCESS;
4355}
4356
4357/******************************************************************************
4358* Get PHY information from various PHY registers
4359*
4360* hw - Struct containing variables accessed by shared code
4361* phy_info - PHY information structure
4362******************************************************************************/
4363int32_t
4364e1000_phy_get_info(struct e1000_hw *hw,
4365 struct e1000_phy_info *phy_info)
4366{
4367 int32_t ret_val;
4368 uint16_t phy_data;
4369
4370 DEBUGFUNC("e1000_phy_get_info");
4371
4372 phy_info->cable_length = e1000_cable_length_undefined;
4373 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4374 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4375 phy_info->downshift = e1000_downshift_undefined;
4376 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4377 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4378 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4379 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4380
Auke Kok8fc897b2006-08-28 14:56:16 -07004381 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 DEBUGOUT("PHY info is only valid for copper media\n");
4383 return -E1000_ERR_CONFIG;
4384 }
4385
4386 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004387 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 return ret_val;
4389
4390 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004391 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 return ret_val;
4393
Auke Kok8fc897b2006-08-28 14:56:16 -07004394 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 DEBUGOUT("PHY info is only valid if link is up\n");
4396 return -E1000_ERR_CONFIG;
4397 }
4398
Auke Kokcd94dd02006-06-27 09:08:22 -07004399 if (hw->phy_type == e1000_phy_igp ||
4400 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004401 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004403 else if (hw->phy_type == e1000_phy_ife)
4404 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 else
4406 return e1000_phy_m88_get_info(hw, phy_info);
4407}
4408
4409int32_t
4410e1000_validate_mdi_setting(struct e1000_hw *hw)
4411{
4412 DEBUGFUNC("e1000_validate_mdi_settings");
4413
Auke Kok8fc897b2006-08-28 14:56:16 -07004414 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 DEBUGOUT("Invalid MDI setting detected\n");
4416 hw->mdix = 1;
4417 return -E1000_ERR_CONFIG;
4418 }
4419 return E1000_SUCCESS;
4420}
4421
4422
4423/******************************************************************************
4424 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004425 * is configured. Additionally, if this is ICH8, the flash controller GbE
4426 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 *
4428 * hw - Struct containing variables accessed by shared code
4429 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004430int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431e1000_init_eeprom_params(struct e1000_hw *hw)
4432{
4433 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4434 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004435 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 uint16_t eeprom_size;
4437
4438 DEBUGFUNC("e1000_init_eeprom_params");
4439
4440 switch (hw->mac_type) {
4441 case e1000_82542_rev2_0:
4442 case e1000_82542_rev2_1:
4443 case e1000_82543:
4444 case e1000_82544:
4445 eeprom->type = e1000_eeprom_microwire;
4446 eeprom->word_size = 64;
4447 eeprom->opcode_bits = 3;
4448 eeprom->address_bits = 6;
4449 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004450 eeprom->use_eerd = FALSE;
4451 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452 break;
4453 case e1000_82540:
4454 case e1000_82545:
4455 case e1000_82545_rev_3:
4456 case e1000_82546:
4457 case e1000_82546_rev_3:
4458 eeprom->type = e1000_eeprom_microwire;
4459 eeprom->opcode_bits = 3;
4460 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004461 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 eeprom->word_size = 256;
4463 eeprom->address_bits = 8;
4464 } else {
4465 eeprom->word_size = 64;
4466 eeprom->address_bits = 6;
4467 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004468 eeprom->use_eerd = FALSE;
4469 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 break;
4471 case e1000_82541:
4472 case e1000_82541_rev_2:
4473 case e1000_82547:
4474 case e1000_82547_rev_2:
4475 if (eecd & E1000_EECD_TYPE) {
4476 eeprom->type = e1000_eeprom_spi;
4477 eeprom->opcode_bits = 8;
4478 eeprom->delay_usec = 1;
4479 if (eecd & E1000_EECD_ADDR_BITS) {
4480 eeprom->page_size = 32;
4481 eeprom->address_bits = 16;
4482 } else {
4483 eeprom->page_size = 8;
4484 eeprom->address_bits = 8;
4485 }
4486 } else {
4487 eeprom->type = e1000_eeprom_microwire;
4488 eeprom->opcode_bits = 3;
4489 eeprom->delay_usec = 50;
4490 if (eecd & E1000_EECD_ADDR_BITS) {
4491 eeprom->word_size = 256;
4492 eeprom->address_bits = 8;
4493 } else {
4494 eeprom->word_size = 64;
4495 eeprom->address_bits = 6;
4496 }
4497 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004498 eeprom->use_eerd = FALSE;
4499 eeprom->use_eewr = FALSE;
4500 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004501 case e1000_82571:
4502 case e1000_82572:
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 eeprom->use_eerd = FALSE;
4514 eeprom->use_eewr = FALSE;
4515 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004516 case e1000_82573:
4517 eeprom->type = e1000_eeprom_spi;
4518 eeprom->opcode_bits = 8;
4519 eeprom->delay_usec = 1;
4520 if (eecd & E1000_EECD_ADDR_BITS) {
4521 eeprom->page_size = 32;
4522 eeprom->address_bits = 16;
4523 } else {
4524 eeprom->page_size = 8;
4525 eeprom->address_bits = 8;
4526 }
4527 eeprom->use_eerd = TRUE;
4528 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004529 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004530 eeprom->type = e1000_eeprom_flash;
4531 eeprom->word_size = 2048;
4532
4533 /* Ensure that the Autonomous FLASH update bit is cleared due to
4534 * Flash update issue on parts which use a FLASH for NVM. */
4535 eecd &= ~E1000_EECD_AUPDEN;
4536 E1000_WRITE_REG(hw, EECD, eecd);
4537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004539 case e1000_80003es2lan:
4540 eeprom->type = e1000_eeprom_spi;
4541 eeprom->opcode_bits = 8;
4542 eeprom->delay_usec = 1;
4543 if (eecd & E1000_EECD_ADDR_BITS) {
4544 eeprom->page_size = 32;
4545 eeprom->address_bits = 16;
4546 } else {
4547 eeprom->page_size = 8;
4548 eeprom->address_bits = 8;
4549 }
4550 eeprom->use_eerd = TRUE;
4551 eeprom->use_eewr = FALSE;
4552 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004553 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004554 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004555 int32_t i = 0;
4556 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4557
4558 eeprom->type = e1000_eeprom_ich8;
4559 eeprom->use_eerd = FALSE;
4560 eeprom->use_eewr = FALSE;
4561 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4562
4563 /* Zero the shadow RAM structure. But don't load it from NVM
4564 * so as to save time for driver init */
4565 if (hw->eeprom_shadow_ram != NULL) {
4566 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4567 hw->eeprom_shadow_ram[i].modified = FALSE;
4568 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4569 }
4570 }
4571
4572 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4573 ICH8_FLASH_SECTOR_SIZE;
4574
4575 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4576 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4577 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4578 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4579
4580 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 default:
4583 break;
4584 }
4585
4586 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004587 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4588 * 32KB (incremented by powers of 2).
4589 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004590 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004591 /* Set to default value for initial eeprom read. */
4592 eeprom->word_size = 64;
4593 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004594 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004595 return ret_val;
4596 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4597 /* 256B eeprom size was not supported in earlier hardware, so we
4598 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4599 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004600 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004601 eeprom_size++;
4602 } else {
4603 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4604 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004606
4607 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004609 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610}
4611
4612/******************************************************************************
4613 * Raises the EEPROM's clock input.
4614 *
4615 * hw - Struct containing variables accessed by shared code
4616 * eecd - EECD's current value
4617 *****************************************************************************/
4618static void
4619e1000_raise_ee_clk(struct e1000_hw *hw,
4620 uint32_t *eecd)
4621{
4622 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4623 * wait <delay> microseconds.
4624 */
4625 *eecd = *eecd | E1000_EECD_SK;
4626 E1000_WRITE_REG(hw, EECD, *eecd);
4627 E1000_WRITE_FLUSH(hw);
4628 udelay(hw->eeprom.delay_usec);
4629}
4630
4631/******************************************************************************
4632 * Lowers the EEPROM's clock input.
4633 *
4634 * hw - Struct containing variables accessed by shared code
4635 * eecd - EECD's current value
4636 *****************************************************************************/
4637static void
4638e1000_lower_ee_clk(struct e1000_hw *hw,
4639 uint32_t *eecd)
4640{
4641 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4642 * wait 50 microseconds.
4643 */
4644 *eecd = *eecd & ~E1000_EECD_SK;
4645 E1000_WRITE_REG(hw, EECD, *eecd);
4646 E1000_WRITE_FLUSH(hw);
4647 udelay(hw->eeprom.delay_usec);
4648}
4649
4650/******************************************************************************
4651 * Shift data bits out to the EEPROM.
4652 *
4653 * hw - Struct containing variables accessed by shared code
4654 * data - data to send to the EEPROM
4655 * count - number of bits to shift out
4656 *****************************************************************************/
4657static void
4658e1000_shift_out_ee_bits(struct e1000_hw *hw,
4659 uint16_t data,
4660 uint16_t count)
4661{
4662 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4663 uint32_t eecd;
4664 uint32_t mask;
4665
4666 /* We need to shift "count" bits out to the EEPROM. So, value in the
4667 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4668 * In order to do this, "data" must be broken down into bits.
4669 */
4670 mask = 0x01 << (count - 1);
4671 eecd = E1000_READ_REG(hw, EECD);
4672 if (eeprom->type == e1000_eeprom_microwire) {
4673 eecd &= ~E1000_EECD_DO;
4674 } else if (eeprom->type == e1000_eeprom_spi) {
4675 eecd |= E1000_EECD_DO;
4676 }
4677 do {
4678 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4679 * and then raising and then lowering the clock (the SK bit controls
4680 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4681 * by setting "DI" to "0" and then raising and then lowering the clock.
4682 */
4683 eecd &= ~E1000_EECD_DI;
4684
Auke Kok8fc897b2006-08-28 14:56:16 -07004685 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 eecd |= E1000_EECD_DI;
4687
4688 E1000_WRITE_REG(hw, EECD, eecd);
4689 E1000_WRITE_FLUSH(hw);
4690
4691 udelay(eeprom->delay_usec);
4692
4693 e1000_raise_ee_clk(hw, &eecd);
4694 e1000_lower_ee_clk(hw, &eecd);
4695
4696 mask = mask >> 1;
4697
Auke Kok8fc897b2006-08-28 14:56:16 -07004698 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699
4700 /* We leave the "DI" bit set to "0" when we leave this routine. */
4701 eecd &= ~E1000_EECD_DI;
4702 E1000_WRITE_REG(hw, EECD, eecd);
4703}
4704
4705/******************************************************************************
4706 * Shift data bits in from the EEPROM
4707 *
4708 * hw - Struct containing variables accessed by shared code
4709 *****************************************************************************/
4710static uint16_t
4711e1000_shift_in_ee_bits(struct e1000_hw *hw,
4712 uint16_t count)
4713{
4714 uint32_t eecd;
4715 uint32_t i;
4716 uint16_t data;
4717
4718 /* In order to read a register from the EEPROM, we need to shift 'count'
4719 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4720 * input to the EEPROM (setting the SK bit), and then reading the value of
4721 * the "DO" bit. During this "shifting in" process the "DI" bit should
4722 * always be clear.
4723 */
4724
4725 eecd = E1000_READ_REG(hw, EECD);
4726
4727 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4728 data = 0;
4729
Auke Kok8fc897b2006-08-28 14:56:16 -07004730 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 data = data << 1;
4732 e1000_raise_ee_clk(hw, &eecd);
4733
4734 eecd = E1000_READ_REG(hw, EECD);
4735
4736 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004737 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 data |= 1;
4739
4740 e1000_lower_ee_clk(hw, &eecd);
4741 }
4742
4743 return data;
4744}
4745
4746/******************************************************************************
4747 * Prepares EEPROM for access
4748 *
4749 * hw - Struct containing variables accessed by shared code
4750 *
4751 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4752 * function should be called before issuing a command to the EEPROM.
4753 *****************************************************************************/
4754static int32_t
4755e1000_acquire_eeprom(struct e1000_hw *hw)
4756{
4757 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4758 uint32_t eecd, i=0;
4759
4760 DEBUGFUNC("e1000_acquire_eeprom");
4761
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004762 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4763 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 eecd = E1000_READ_REG(hw, EECD);
4765
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004766 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004767 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004768 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004769 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004771 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004772 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004773 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4774 i++;
4775 udelay(5);
4776 eecd = E1000_READ_REG(hw, EECD);
4777 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004778 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004779 eecd &= ~E1000_EECD_REQ;
4780 E1000_WRITE_REG(hw, EECD, eecd);
4781 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004782 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004783 return -E1000_ERR_EEPROM;
4784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 }
4786 }
4787
4788 /* Setup EEPROM for Read/Write */
4789
4790 if (eeprom->type == e1000_eeprom_microwire) {
4791 /* Clear SK and DI */
4792 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4793 E1000_WRITE_REG(hw, EECD, eecd);
4794
4795 /* Set CS */
4796 eecd |= E1000_EECD_CS;
4797 E1000_WRITE_REG(hw, EECD, eecd);
4798 } else if (eeprom->type == e1000_eeprom_spi) {
4799 /* Clear SK and CS */
4800 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4801 E1000_WRITE_REG(hw, EECD, eecd);
4802 udelay(1);
4803 }
4804
4805 return E1000_SUCCESS;
4806}
4807
4808/******************************************************************************
4809 * Returns EEPROM to a "standby" state
4810 *
4811 * hw - Struct containing variables accessed by shared code
4812 *****************************************************************************/
4813static void
4814e1000_standby_eeprom(struct e1000_hw *hw)
4815{
4816 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4817 uint32_t eecd;
4818
4819 eecd = E1000_READ_REG(hw, EECD);
4820
Auke Kok8fc897b2006-08-28 14:56:16 -07004821 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4823 E1000_WRITE_REG(hw, EECD, eecd);
4824 E1000_WRITE_FLUSH(hw);
4825 udelay(eeprom->delay_usec);
4826
4827 /* Clock high */
4828 eecd |= E1000_EECD_SK;
4829 E1000_WRITE_REG(hw, EECD, eecd);
4830 E1000_WRITE_FLUSH(hw);
4831 udelay(eeprom->delay_usec);
4832
4833 /* Select EEPROM */
4834 eecd |= E1000_EECD_CS;
4835 E1000_WRITE_REG(hw, EECD, eecd);
4836 E1000_WRITE_FLUSH(hw);
4837 udelay(eeprom->delay_usec);
4838
4839 /* Clock low */
4840 eecd &= ~E1000_EECD_SK;
4841 E1000_WRITE_REG(hw, EECD, eecd);
4842 E1000_WRITE_FLUSH(hw);
4843 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004844 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 /* Toggle CS to flush commands */
4846 eecd |= E1000_EECD_CS;
4847 E1000_WRITE_REG(hw, EECD, eecd);
4848 E1000_WRITE_FLUSH(hw);
4849 udelay(eeprom->delay_usec);
4850 eecd &= ~E1000_EECD_CS;
4851 E1000_WRITE_REG(hw, EECD, eecd);
4852 E1000_WRITE_FLUSH(hw);
4853 udelay(eeprom->delay_usec);
4854 }
4855}
4856
4857/******************************************************************************
4858 * Terminates a command by inverting the EEPROM's chip select pin
4859 *
4860 * hw - Struct containing variables accessed by shared code
4861 *****************************************************************************/
4862static void
4863e1000_release_eeprom(struct e1000_hw *hw)
4864{
4865 uint32_t eecd;
4866
4867 DEBUGFUNC("e1000_release_eeprom");
4868
4869 eecd = E1000_READ_REG(hw, EECD);
4870
4871 if (hw->eeprom.type == e1000_eeprom_spi) {
4872 eecd |= E1000_EECD_CS; /* Pull CS high */
4873 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4874
4875 E1000_WRITE_REG(hw, EECD, eecd);
4876
4877 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004878 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 /* cleanup eeprom */
4880
4881 /* CS on Microwire is active-high */
4882 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4883
4884 E1000_WRITE_REG(hw, EECD, eecd);
4885
4886 /* Rising edge of clock */
4887 eecd |= E1000_EECD_SK;
4888 E1000_WRITE_REG(hw, EECD, eecd);
4889 E1000_WRITE_FLUSH(hw);
4890 udelay(hw->eeprom.delay_usec);
4891
4892 /* Falling edge of clock */
4893 eecd &= ~E1000_EECD_SK;
4894 E1000_WRITE_REG(hw, EECD, eecd);
4895 E1000_WRITE_FLUSH(hw);
4896 udelay(hw->eeprom.delay_usec);
4897 }
4898
4899 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004900 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 eecd &= ~E1000_EECD_REQ;
4902 E1000_WRITE_REG(hw, EECD, eecd);
4903 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004904
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004905 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906}
4907
4908/******************************************************************************
4909 * Reads a 16 bit word from the EEPROM.
4910 *
4911 * hw - Struct containing variables accessed by shared code
4912 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004913static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914e1000_spi_eeprom_ready(struct e1000_hw *hw)
4915{
4916 uint16_t retry_count = 0;
4917 uint8_t spi_stat_reg;
4918
4919 DEBUGFUNC("e1000_spi_eeprom_ready");
4920
4921 /* Read "Status Register" repeatedly until the LSB is cleared. The
4922 * EEPROM will signal that the command has been completed by clearing
4923 * bit 0 of the internal status register. If it's not cleared within
4924 * 5 milliseconds, then error out.
4925 */
4926 retry_count = 0;
4927 do {
4928 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4929 hw->eeprom.opcode_bits);
4930 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4931 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4932 break;
4933
4934 udelay(5);
4935 retry_count += 5;
4936
4937 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004938 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939
4940 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4941 * only 0-5mSec on 5V devices)
4942 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004943 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944 DEBUGOUT("SPI EEPROM Status error\n");
4945 return -E1000_ERR_EEPROM;
4946 }
4947
4948 return E1000_SUCCESS;
4949}
4950
4951/******************************************************************************
4952 * Reads a 16 bit word from the EEPROM.
4953 *
4954 * hw - Struct containing variables accessed by shared code
4955 * offset - offset of word in the EEPROM to read
4956 * data - word read from the EEPROM
4957 * words - number of words to read
4958 *****************************************************************************/
4959int32_t
4960e1000_read_eeprom(struct e1000_hw *hw,
4961 uint16_t offset,
4962 uint16_t words,
4963 uint16_t *data)
4964{
4965 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4966 uint32_t i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004967 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968
4969 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004970
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 /* A check for invalid values: offset too large, too many words, and not
4972 * enough words.
4973 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004974 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 (words == 0)) {
4976 DEBUGOUT("\"words\" parameter out of bounds\n");
4977 return -E1000_ERR_EEPROM;
4978 }
4979
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004980 /* FLASH reads without acquiring the semaphore are safe */
4981 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004982 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004983 switch (hw->mac_type) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004984 case e1000_80003es2lan:
4985 break;
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004986 default:
4987 /* Prepare the EEPROM for reading */
4988 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4989 return -E1000_ERR_EEPROM;
4990 break;
4991 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004992 }
4993
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004994 if (eeprom->use_eerd == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004995 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4996 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4997 (hw->mac_type != e1000_82573))
4998 e1000_release_eeprom(hw);
4999 return ret_val;
5000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
Auke Kokcd94dd02006-06-27 09:08:22 -07005002 if (eeprom->type == e1000_eeprom_ich8)
5003 return e1000_read_eeprom_ich8(hw, offset, words, data);
5004
5005 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 uint16_t word_in;
5007 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5008
Auke Kok8fc897b2006-08-28 14:56:16 -07005009 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 e1000_release_eeprom(hw);
5011 return -E1000_ERR_EEPROM;
5012 }
5013
5014 e1000_standby_eeprom(hw);
5015
5016 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005017 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 read_opcode |= EEPROM_A8_OPCODE_SPI;
5019
5020 /* Send the READ command (opcode + addr) */
5021 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5022 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5023
5024 /* Read the data. The address of the eeprom internally increments with
5025 * each byte (spi) being read, saving on the overhead of eeprom setup
5026 * and tear-down. The address counter will roll over if reading beyond
5027 * the size of the eeprom, thus allowing the entire memory to be read
5028 * starting from any offset. */
5029 for (i = 0; i < words; i++) {
5030 word_in = e1000_shift_in_ee_bits(hw, 16);
5031 data[i] = (word_in >> 8) | (word_in << 8);
5032 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005033 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 for (i = 0; i < words; i++) {
5035 /* Send the READ command (opcode + addr) */
5036 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5037 eeprom->opcode_bits);
5038 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5039 eeprom->address_bits);
5040
5041 /* Read the data. For microwire, each word requires the overhead
5042 * of eeprom setup and tear-down. */
5043 data[i] = e1000_shift_in_ee_bits(hw, 16);
5044 e1000_standby_eeprom(hw);
5045 }
5046 }
5047
5048 /* End this read operation */
5049 e1000_release_eeprom(hw);
5050
5051 return E1000_SUCCESS;
5052}
5053
5054/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005055 * Reads a 16 bit word from the EEPROM using the EERD register.
5056 *
5057 * hw - Struct containing variables accessed by shared code
5058 * offset - offset of word in the EEPROM to read
5059 * data - word read from the EEPROM
5060 * words - number of words to read
5061 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005062static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005063e1000_read_eeprom_eerd(struct e1000_hw *hw,
5064 uint16_t offset,
5065 uint16_t words,
5066 uint16_t *data)
5067{
5068 uint32_t i, eerd = 0;
5069 int32_t error = 0;
5070
5071 for (i = 0; i < words; i++) {
5072 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5073 E1000_EEPROM_RW_REG_START;
5074
5075 E1000_WRITE_REG(hw, EERD, eerd);
5076 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005077
Auke Kok8fc897b2006-08-28 14:56:16 -07005078 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005079 break;
5080 }
5081 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005082
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005083 }
Auke Kok76c224b2006-05-23 13:36:06 -07005084
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005085 return error;
5086}
5087
5088/******************************************************************************
5089 * Writes a 16 bit word from the EEPROM using the EEWR register.
5090 *
5091 * hw - Struct containing variables accessed by shared code
5092 * offset - offset of word in the EEPROM to read
5093 * data - word read from the EEPROM
5094 * words - number of words to read
5095 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005096static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005097e1000_write_eeprom_eewr(struct e1000_hw *hw,
5098 uint16_t offset,
5099 uint16_t words,
5100 uint16_t *data)
5101{
5102 uint32_t register_value = 0;
5103 uint32_t i = 0;
5104 int32_t error = 0;
5105
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005106 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5107 return -E1000_ERR_SWFW_SYNC;
5108
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005109 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005110 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5111 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005112 E1000_EEPROM_RW_REG_START;
5113
5114 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005115 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005116 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005117 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005118
5119 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005120
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005121 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005122
Auke Kok8fc897b2006-08-28 14:56:16 -07005123 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005124 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005125 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005126 }
Auke Kok76c224b2006-05-23 13:36:06 -07005127
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005128 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005129 return error;
5130}
5131
5132/******************************************************************************
5133 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5134 *
5135 * hw - Struct containing variables accessed by shared code
5136 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005137static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005138e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5139{
5140 uint32_t attempts = 100000;
5141 uint32_t i, reg = 0;
5142 int32_t done = E1000_ERR_EEPROM;
5143
Auke Kok8fc897b2006-08-28 14:56:16 -07005144 for (i = 0; i < attempts; i++) {
5145 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005146 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005147 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005148 reg = E1000_READ_REG(hw, EEWR);
5149
Auke Kok8fc897b2006-08-28 14:56:16 -07005150 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005151 done = E1000_SUCCESS;
5152 break;
5153 }
5154 udelay(5);
5155 }
5156
5157 return done;
5158}
5159
5160/***************************************************************************
5161* Description: Determines if the onboard NVM is FLASH or EEPROM.
5162*
5163* hw - Struct containing variables accessed by shared code
5164****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005165static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005166e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5167{
5168 uint32_t eecd = 0;
5169
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005170 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5171
Auke Kokcd94dd02006-06-27 09:08:22 -07005172 if (hw->mac_type == e1000_ich8lan)
5173 return FALSE;
5174
5175 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005176 eecd = E1000_READ_REG(hw, EECD);
5177
5178 /* Isolate bits 15 & 16 */
5179 eecd = ((eecd >> 15) & 0x03);
5180
5181 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005182 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005183 return FALSE;
5184 }
5185 }
5186 return TRUE;
5187}
5188
5189/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 * Verifies that the EEPROM has a valid checksum
5191 *
5192 * hw - Struct containing variables accessed by shared code
5193 *
5194 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5195 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5196 * valid.
5197 *****************************************************************************/
5198int32_t
5199e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5200{
5201 uint16_t checksum = 0;
5202 uint16_t i, eeprom_data;
5203
5204 DEBUGFUNC("e1000_validate_eeprom_checksum");
5205
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005206 if ((hw->mac_type == e1000_82573) &&
5207 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5208 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5209 * 10h-12h. Checksum may need to be fixed. */
5210 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5211 if ((eeprom_data & 0x10) == 0) {
5212 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5213 * has already been fixed. If the checksum is still wrong and this
5214 * bit is a 1, we need to return bad checksum. Otherwise, we need
5215 * to set this bit to a 1 and update the checksum. */
5216 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5217 if ((eeprom_data & 0x8000) == 0) {
5218 eeprom_data |= 0x8000;
5219 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5220 e1000_update_eeprom_checksum(hw);
5221 }
5222 }
5223 }
5224
Auke Kokcd94dd02006-06-27 09:08:22 -07005225 if (hw->mac_type == e1000_ich8lan) {
5226 /* Drivers must allocate the shadow ram structure for the
5227 * EEPROM checksum to be updated. Otherwise, this bit as well
5228 * as the checksum must both be set correctly for this
5229 * validation to pass.
5230 */
5231 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5232 if ((eeprom_data & 0x40) == 0) {
5233 eeprom_data |= 0x40;
5234 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5235 e1000_update_eeprom_checksum(hw);
5236 }
5237 }
5238
5239 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5240 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 DEBUGOUT("EEPROM Read Error\n");
5242 return -E1000_ERR_EEPROM;
5243 }
5244 checksum += eeprom_data;
5245 }
5246
Auke Kok8fc897b2006-08-28 14:56:16 -07005247 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 return E1000_SUCCESS;
5249 else {
5250 DEBUGOUT("EEPROM Checksum Invalid\n");
5251 return -E1000_ERR_EEPROM;
5252 }
5253}
5254
5255/******************************************************************************
5256 * Calculates the EEPROM checksum and writes it to the EEPROM
5257 *
5258 * hw - Struct containing variables accessed by shared code
5259 *
5260 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5261 * Writes the difference to word offset 63 of the EEPROM.
5262 *****************************************************************************/
5263int32_t
5264e1000_update_eeprom_checksum(struct e1000_hw *hw)
5265{
Auke Kokcd94dd02006-06-27 09:08:22 -07005266 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267 uint16_t checksum = 0;
5268 uint16_t i, eeprom_data;
5269
5270 DEBUGFUNC("e1000_update_eeprom_checksum");
5271
Auke Kok8fc897b2006-08-28 14:56:16 -07005272 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5273 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 DEBUGOUT("EEPROM Read Error\n");
5275 return -E1000_ERR_EEPROM;
5276 }
5277 checksum += eeprom_data;
5278 }
5279 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005280 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281 DEBUGOUT("EEPROM Write Error\n");
5282 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005283 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5284 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005285 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5286 e1000_commit_shadow_ram(hw);
5287 /* Reload the EEPROM, or else modifications will not appear
5288 * until after next adapter reset. */
5289 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5290 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5291 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005292 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 }
5294 return E1000_SUCCESS;
5295}
5296
5297/******************************************************************************
5298 * Parent function for writing words to the different EEPROM types.
5299 *
5300 * hw - Struct containing variables accessed by shared code
5301 * offset - offset within the EEPROM to be written to
5302 * words - number of words to write
5303 * data - 16 bit word to be written to the EEPROM
5304 *
5305 * If e1000_update_eeprom_checksum is not called after this function, the
5306 * EEPROM will most likely contain an invalid checksum.
5307 *****************************************************************************/
5308int32_t
5309e1000_write_eeprom(struct e1000_hw *hw,
5310 uint16_t offset,
5311 uint16_t words,
5312 uint16_t *data)
5313{
5314 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5315 int32_t status = 0;
5316
5317 DEBUGFUNC("e1000_write_eeprom");
5318
5319 /* A check for invalid values: offset too large, too many words, and not
5320 * enough words.
5321 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005322 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323 (words == 0)) {
5324 DEBUGOUT("\"words\" parameter out of bounds\n");
5325 return -E1000_ERR_EEPROM;
5326 }
5327
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005328 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005329 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005330 return e1000_write_eeprom_eewr(hw, offset, words, data);
5331
Auke Kokcd94dd02006-06-27 09:08:22 -07005332 if (eeprom->type == e1000_eeprom_ich8)
5333 return e1000_write_eeprom_ich8(hw, offset, words, data);
5334
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335 /* Prepare the EEPROM for writing */
5336 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5337 return -E1000_ERR_EEPROM;
5338
Auke Kok8fc897b2006-08-28 14:56:16 -07005339 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5341 } else {
5342 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005343 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 }
5345
5346 /* Done with writing */
5347 e1000_release_eeprom(hw);
5348
5349 return status;
5350}
5351
5352/******************************************************************************
5353 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5354 *
5355 * hw - Struct containing variables accessed by shared code
5356 * offset - offset within the EEPROM to be written to
5357 * words - number of words to write
5358 * data - pointer to array of 8 bit words to be written to the EEPROM
5359 *
5360 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005361static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362e1000_write_eeprom_spi(struct e1000_hw *hw,
5363 uint16_t offset,
5364 uint16_t words,
5365 uint16_t *data)
5366{
5367 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5368 uint16_t widx = 0;
5369
5370 DEBUGFUNC("e1000_write_eeprom_spi");
5371
5372 while (widx < words) {
5373 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5374
Auke Kok8fc897b2006-08-28 14:56:16 -07005375 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376
5377 e1000_standby_eeprom(hw);
5378
5379 /* Send the WRITE ENABLE command (8 bit opcode ) */
5380 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5381 eeprom->opcode_bits);
5382
5383 e1000_standby_eeprom(hw);
5384
5385 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005386 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387 write_opcode |= EEPROM_A8_OPCODE_SPI;
5388
5389 /* Send the Write command (8-bit opcode + addr) */
5390 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5391
5392 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5393 eeprom->address_bits);
5394
5395 /* Send the data */
5396
5397 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5398 while (widx < words) {
5399 uint16_t word_out = data[widx];
5400 word_out = (word_out >> 8) | (word_out << 8);
5401 e1000_shift_out_ee_bits(hw, word_out, 16);
5402 widx++;
5403
5404 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5405 * operation, while the smaller eeproms are capable of an 8-byte
5406 * PAGE WRITE operation. Break the inner loop to pass new address
5407 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005408 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 e1000_standby_eeprom(hw);
5410 break;
5411 }
5412 }
5413 }
5414
5415 return E1000_SUCCESS;
5416}
5417
5418/******************************************************************************
5419 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5420 *
5421 * hw - Struct containing variables accessed by shared code
5422 * offset - offset within the EEPROM to be written to
5423 * words - number of words to write
5424 * data - pointer to array of 16 bit words to be written to the EEPROM
5425 *
5426 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005427static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428e1000_write_eeprom_microwire(struct e1000_hw *hw,
5429 uint16_t offset,
5430 uint16_t words,
5431 uint16_t *data)
5432{
5433 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5434 uint32_t eecd;
5435 uint16_t words_written = 0;
5436 uint16_t i = 0;
5437
5438 DEBUGFUNC("e1000_write_eeprom_microwire");
5439
5440 /* Send the write enable command to the EEPROM (3-bit opcode plus
5441 * 6/8-bit dummy address beginning with 11). It's less work to include
5442 * the 11 of the dummy address as part of the opcode than it is to shift
5443 * it over the correct number of bits for the address. This puts the
5444 * EEPROM into write/erase mode.
5445 */
5446 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5447 (uint16_t)(eeprom->opcode_bits + 2));
5448
5449 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5450
5451 /* Prepare the EEPROM */
5452 e1000_standby_eeprom(hw);
5453
5454 while (words_written < words) {
5455 /* Send the Write command (3-bit opcode + addr) */
5456 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5457 eeprom->opcode_bits);
5458
5459 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5460 eeprom->address_bits);
5461
5462 /* Send the data */
5463 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5464
5465 /* Toggle the CS line. This in effect tells the EEPROM to execute
5466 * the previous command.
5467 */
5468 e1000_standby_eeprom(hw);
5469
5470 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5471 * signal that the command has been completed by raising the DO signal.
5472 * If DO does not go high in 10 milliseconds, then error out.
5473 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005474 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005476 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477 udelay(50);
5478 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005479 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 DEBUGOUT("EEPROM Write did not complete\n");
5481 return -E1000_ERR_EEPROM;
5482 }
5483
5484 /* Recover from write */
5485 e1000_standby_eeprom(hw);
5486
5487 words_written++;
5488 }
5489
5490 /* Send the write disable command to the EEPROM (3-bit opcode plus
5491 * 6/8-bit dummy address beginning with 10). It's less work to include
5492 * the 10 of the dummy address as part of the opcode than it is to shift
5493 * it over the correct number of bits for the address. This takes the
5494 * EEPROM out of write/erase mode.
5495 */
5496 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5497 (uint16_t)(eeprom->opcode_bits + 2));
5498
5499 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5500
5501 return E1000_SUCCESS;
5502}
5503
5504/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005505 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5506 * in the eeprom cache and the non modified values in the currently active bank
5507 * to the new bank.
5508 *
5509 * hw - Struct containing variables accessed by shared code
5510 * offset - offset of word in the EEPROM to read
5511 * data - word read from the EEPROM
5512 * words - number of words to read
5513 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005514static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005515e1000_commit_shadow_ram(struct e1000_hw *hw)
5516{
5517 uint32_t attempts = 100000;
5518 uint32_t eecd = 0;
5519 uint32_t flop = 0;
5520 uint32_t i = 0;
5521 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005522 uint32_t old_bank_offset = 0;
5523 uint32_t new_bank_offset = 0;
5524 uint32_t sector_retries = 0;
5525 uint8_t low_byte = 0;
5526 uint8_t high_byte = 0;
5527 uint8_t temp_byte = 0;
5528 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005529
5530 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005531 /* The flop register will be used to determine if flash type is STM */
5532 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005533 for (i=0; i < attempts; i++) {
5534 eecd = E1000_READ_REG(hw, EECD);
5535 if ((eecd & E1000_EECD_FLUPD) == 0) {
5536 break;
5537 }
5538 udelay(5);
5539 }
5540
5541 if (i == attempts) {
5542 return -E1000_ERR_EEPROM;
5543 }
5544
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005545 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005546 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5547 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5548 }
5549
5550 /* Perform the flash update */
5551 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5552
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005553 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005554 eecd = E1000_READ_REG(hw, EECD);
5555 if ((eecd & E1000_EECD_FLUPD) == 0) {
5556 break;
5557 }
5558 udelay(5);
5559 }
5560
5561 if (i == attempts) {
5562 return -E1000_ERR_EEPROM;
5563 }
5564 }
5565
Auke Kokcd94dd02006-06-27 09:08:22 -07005566 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5567 /* We're writing to the opposite bank so if we're on bank 1,
5568 * write to bank 0 etc. We also need to erase the segment that
5569 * is going to be written */
5570 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5571 new_bank_offset = hw->flash_bank_size * 2;
5572 old_bank_offset = 0;
5573 e1000_erase_ich8_4k_segment(hw, 1);
5574 } else {
5575 old_bank_offset = hw->flash_bank_size * 2;
5576 new_bank_offset = 0;
5577 e1000_erase_ich8_4k_segment(hw, 0);
5578 }
5579
5580 do {
5581 sector_write_failed = FALSE;
5582 /* Loop for every byte in the shadow RAM,
5583 * which is in units of words. */
5584 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5585 /* Determine whether to write the value stored
5586 * in the other NVM bank or a modified value stored
5587 * in the shadow RAM */
5588 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5589 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5590 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5591 &temp_byte);
5592 udelay(100);
5593 error = e1000_verify_write_ich8_byte(hw,
5594 (i << 1) + new_bank_offset,
5595 low_byte);
5596 if (error != E1000_SUCCESS)
5597 sector_write_failed = TRUE;
5598 high_byte =
5599 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5600 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5601 &temp_byte);
5602 udelay(100);
5603 } else {
5604 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5605 &low_byte);
5606 udelay(100);
5607 error = e1000_verify_write_ich8_byte(hw,
5608 (i << 1) + new_bank_offset, low_byte);
5609 if (error != E1000_SUCCESS)
5610 sector_write_failed = TRUE;
5611 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5612 &high_byte);
5613 }
5614
5615 /* If the word is 0x13, then make sure the signature bits
5616 * (15:14) are 11b until the commit has completed.
5617 * This will allow us to write 10b which indicates the
5618 * signature is valid. We want to do this after the write
5619 * has completed so that we don't mark the segment valid
5620 * while the write is still in progress */
5621 if (i == E1000_ICH8_NVM_SIG_WORD)
5622 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5623
5624 error = e1000_verify_write_ich8_byte(hw,
5625 (i << 1) + new_bank_offset + 1, high_byte);
5626 if (error != E1000_SUCCESS)
5627 sector_write_failed = TRUE;
5628
5629 if (sector_write_failed == FALSE) {
5630 /* Clear the now not used entry in the cache */
5631 hw->eeprom_shadow_ram[i].modified = FALSE;
5632 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5633 }
5634 }
5635
5636 /* Don't bother writing the segment valid bits if sector
5637 * programming failed. */
5638 if (sector_write_failed == FALSE) {
5639 /* Finally validate the new segment by setting bit 15:14
5640 * to 10b in word 0x13 , this can be done without an
5641 * erase as well since these bits are 11 to start with
5642 * and we need to change bit 14 to 0b */
5643 e1000_read_ich8_byte(hw,
5644 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5645 &high_byte);
5646 high_byte &= 0xBF;
5647 error = e1000_verify_write_ich8_byte(hw,
5648 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5649 high_byte);
5650 if (error != E1000_SUCCESS)
5651 sector_write_failed = TRUE;
5652
5653 /* And invalidate the previously valid segment by setting
5654 * its signature word (0x13) high_byte to 0b. This can be
5655 * done without an erase because flash erase sets all bits
5656 * to 1's. We can write 1's to 0's without an erase */
5657 error = e1000_verify_write_ich8_byte(hw,
5658 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5659 0);
5660 if (error != E1000_SUCCESS)
5661 sector_write_failed = TRUE;
5662 }
5663 } while (++sector_retries < 10 && sector_write_failed == TRUE);
5664 }
5665
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005666 return error;
5667}
5668
5669/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5671 * second function of dual function devices
5672 *
5673 * hw - Struct containing variables accessed by shared code
5674 *****************************************************************************/
5675int32_t
5676e1000_read_mac_addr(struct e1000_hw * hw)
5677{
5678 uint16_t offset;
5679 uint16_t eeprom_data, i;
5680
5681 DEBUGFUNC("e1000_read_mac_addr");
5682
Auke Kok8fc897b2006-08-28 14:56:16 -07005683 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005685 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 DEBUGOUT("EEPROM Read Error\n");
5687 return -E1000_ERR_EEPROM;
5688 }
5689 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5690 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5691 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005692
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005693 switch (hw->mac_type) {
5694 default:
5695 break;
5696 case e1000_82546:
5697 case e1000_82546_rev_3:
5698 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005699 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005700 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005702 break;
5703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704
Auke Kok8fc897b2006-08-28 14:56:16 -07005705 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 hw->mac_addr[i] = hw->perm_mac_addr[i];
5707 return E1000_SUCCESS;
5708}
5709
5710/******************************************************************************
5711 * Initializes receive address filters.
5712 *
5713 * hw - Struct containing variables accessed by shared code
5714 *
5715 * Places the MAC address in receive address register 0 and clears the rest
5716 * of the receive addresss registers. Clears the multicast table. Assumes
5717 * the receiver is in reset when the routine is called.
5718 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005719static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720e1000_init_rx_addrs(struct e1000_hw *hw)
5721{
5722 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005723 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724
5725 DEBUGFUNC("e1000_init_rx_addrs");
5726
5727 /* Setup the receive address. */
5728 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5729
5730 e1000_rar_set(hw, hw->mac_addr, 0);
5731
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005732 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005733
5734 /* Reserve a spot for the Locally Administered Address to work around
5735 * an 82571 issue in which a reset on one port will reload the MAC on
5736 * the other port. */
5737 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5738 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005739 if (hw->mac_type == e1000_ich8lan)
5740 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5741
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 /* Zero out the other 15 receive addresses. */
5743 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005744 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005746 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005748 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749 }
5750}
5751
5752/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 * Hashes an address to determine its location in the multicast table
5754 *
5755 * hw - Struct containing variables accessed by shared code
5756 * mc_addr - the multicast address to hash
5757 *****************************************************************************/
5758uint32_t
5759e1000_hash_mc_addr(struct e1000_hw *hw,
5760 uint8_t *mc_addr)
5761{
5762 uint32_t hash_value = 0;
5763
5764 /* The portion of the address that is used for the hash table is
5765 * determined by the mc_filter_type setting.
5766 */
5767 switch (hw->mc_filter_type) {
5768 /* [0] [1] [2] [3] [4] [5]
5769 * 01 AA 00 12 34 56
5770 * LSB MSB
5771 */
5772 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005773 if (hw->mac_type == e1000_ich8lan) {
5774 /* [47:38] i.e. 0x158 for above example address */
5775 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5776 } else {
5777 /* [47:36] i.e. 0x563 for above example address */
5778 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 break;
5781 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005782 if (hw->mac_type == e1000_ich8lan) {
5783 /* [46:37] i.e. 0x2B1 for above example address */
5784 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5785 } else {
5786 /* [46:35] i.e. 0xAC6 for above example address */
5787 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789 break;
5790 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005791 if (hw->mac_type == e1000_ich8lan) {
5792 /*[45:36] i.e. 0x163 for above example address */
5793 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5794 } else {
5795 /* [45:34] i.e. 0x5D8 for above example address */
5796 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798 break;
5799 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005800 if (hw->mac_type == e1000_ich8lan) {
5801 /* [43:34] i.e. 0x18D for above example address */
5802 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5803 } else {
5804 /* [43:32] i.e. 0x634 for above example address */
5805 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 break;
5808 }
5809
5810 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005811 if (hw->mac_type == e1000_ich8lan)
5812 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005813
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814 return hash_value;
5815}
5816
5817/******************************************************************************
5818 * Sets the bit in the multicast table corresponding to the hash value.
5819 *
5820 * hw - Struct containing variables accessed by shared code
5821 * hash_value - Multicast address hash value
5822 *****************************************************************************/
5823void
5824e1000_mta_set(struct e1000_hw *hw,
5825 uint32_t hash_value)
5826{
5827 uint32_t hash_bit, hash_reg;
5828 uint32_t mta;
5829 uint32_t temp;
5830
5831 /* The MTA is a register array of 128 32-bit registers.
5832 * It is treated like an array of 4096 bits. We want to set
5833 * bit BitArray[hash_value]. So we figure out what register
5834 * the bit is in, read it, OR in the new bit, then write
5835 * back the new value. The register is determined by the
5836 * upper 7 bits of the hash value and the bit within that
5837 * register are determined by the lower 5 bits of the value.
5838 */
5839 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005840 if (hw->mac_type == e1000_ich8lan)
5841 hash_reg &= 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 hash_bit = hash_value & 0x1F;
5843
5844 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5845
5846 mta |= (1 << hash_bit);
5847
5848 /* If we are on an 82544 and we are trying to write an odd offset
5849 * in the MTA, save off the previous entry before writing and
5850 * restore the old value after writing.
5851 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005852 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5854 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005855 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005857 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858 } else {
5859 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005860 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861 }
5862}
5863
5864/******************************************************************************
5865 * Puts an ethernet address into a receive address register.
5866 *
5867 * hw - Struct containing variables accessed by shared code
5868 * addr - Address to put into receive address register
5869 * index - Receive address register to write
5870 *****************************************************************************/
5871void
5872e1000_rar_set(struct e1000_hw *hw,
5873 uint8_t *addr,
5874 uint32_t index)
5875{
5876 uint32_t rar_low, rar_high;
5877
5878 /* HW expects these in little endian so we reverse the byte order
5879 * from network order (big endian) to little endian
5880 */
5881 rar_low = ((uint32_t) addr[0] |
5882 ((uint32_t) addr[1] << 8) |
5883 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005884 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005886 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5887 * unit hang.
5888 *
5889 * Description:
5890 * If there are any Rx frames queued up or otherwise present in the HW
5891 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5892 * hang. To work around this issue, we have to disable receives and
5893 * flush out all Rx frames before we enable RSS. To do so, we modify we
5894 * redirect all Rx traffic to manageability and then reset the HW.
5895 * This flushes away Rx frames, and (since the redirections to
5896 * manageability persists across resets) keeps new ones from coming in
5897 * while we work. Then, we clear the Address Valid AV bit for all MAC
5898 * addresses and undo the re-direction to manageability.
5899 * Now, frames are coming in again, but the MAC won't accept them, so
5900 * far so good. We now proceed to initialize RSS (if necessary) and
5901 * configure the Rx unit. Last, we re-enable the AV bits and continue
5902 * on our merry way.
5903 */
5904 switch (hw->mac_type) {
5905 case e1000_82571:
5906 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005907 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005908 if (hw->leave_av_bit_off == TRUE)
5909 break;
5910 default:
5911 /* Indicate to hardware the Address is Valid. */
5912 rar_high |= E1000_RAH_AV;
5913 break;
5914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915
5916 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005917 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005919 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920}
5921
5922/******************************************************************************
5923 * Writes a value to the specified offset in the VLAN filter table.
5924 *
5925 * hw - Struct containing variables accessed by shared code
5926 * offset - Offset in VLAN filer table to write
5927 * value - Value to write into VLAN filter table
5928 *****************************************************************************/
5929void
5930e1000_write_vfta(struct e1000_hw *hw,
5931 uint32_t offset,
5932 uint32_t value)
5933{
5934 uint32_t temp;
5935
Auke Kokcd94dd02006-06-27 09:08:22 -07005936 if (hw->mac_type == e1000_ich8lan)
5937 return;
5938
5939 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5941 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005942 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005944 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945 } else {
5946 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005947 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 }
5949}
5950
5951/******************************************************************************
5952 * Clears the VLAN filer table
5953 *
5954 * hw - Struct containing variables accessed by shared code
5955 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005956static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957e1000_clear_vfta(struct e1000_hw *hw)
5958{
5959 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005960 uint32_t vfta_value = 0;
5961 uint32_t vfta_offset = 0;
5962 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963
Auke Kokcd94dd02006-06-27 09:08:22 -07005964 if (hw->mac_type == e1000_ich8lan)
5965 return;
5966
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005967 if (hw->mac_type == e1000_82573) {
5968 if (hw->mng_cookie.vlan_id != 0) {
5969 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5970 * ID. The following operations determine which 32b entry
5971 * (i.e. offset) into the array we want to set the VLAN ID
5972 * (i.e. bit) of the manageability unit. */
5973 vfta_offset = (hw->mng_cookie.vlan_id >>
5974 E1000_VFTA_ENTRY_SHIFT) &
5975 E1000_VFTA_ENTRY_MASK;
5976 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5977 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5978 }
5979 }
5980 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5981 /* If the offset we want to clear is the same offset of the
5982 * manageability VLAN ID, then clear all bits except that of the
5983 * manageability unit */
5984 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5985 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005986 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988}
5989
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005990static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991e1000_id_led_init(struct e1000_hw * hw)
5992{
5993 uint32_t ledctl;
5994 const uint32_t ledctl_mask = 0x000000FF;
5995 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5996 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5997 uint16_t eeprom_data, i, temp;
5998 const uint16_t led_mask = 0x0F;
5999
6000 DEBUGFUNC("e1000_id_led_init");
6001
Auke Kok8fc897b2006-08-28 14:56:16 -07006002 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 /* Nothing to do */
6004 return E1000_SUCCESS;
6005 }
6006
6007 ledctl = E1000_READ_REG(hw, LEDCTL);
6008 hw->ledctl_default = ledctl;
6009 hw->ledctl_mode1 = hw->ledctl_default;
6010 hw->ledctl_mode2 = hw->ledctl_default;
6011
Auke Kok8fc897b2006-08-28 14:56:16 -07006012 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 DEBUGOUT("EEPROM Read Error\n");
6014 return -E1000_ERR_EEPROM;
6015 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006016
6017 if ((hw->mac_type == e1000_82573) &&
6018 (eeprom_data == ID_LED_RESERVED_82573))
6019 eeprom_data = ID_LED_DEFAULT_82573;
6020 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6021 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6022 if (hw->mac_type == e1000_ich8lan)
6023 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6024 else
6025 eeprom_data = ID_LED_DEFAULT;
6026 }
6027 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006029 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 case ID_LED_ON1_DEF2:
6031 case ID_LED_ON1_ON2:
6032 case ID_LED_ON1_OFF2:
6033 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6034 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6035 break;
6036 case ID_LED_OFF1_DEF2:
6037 case ID_LED_OFF1_ON2:
6038 case ID_LED_OFF1_OFF2:
6039 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6040 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6041 break;
6042 default:
6043 /* Do nothing */
6044 break;
6045 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006046 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047 case ID_LED_DEF1_ON2:
6048 case ID_LED_ON1_ON2:
6049 case ID_LED_OFF1_ON2:
6050 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6051 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6052 break;
6053 case ID_LED_DEF1_OFF2:
6054 case ID_LED_ON1_OFF2:
6055 case ID_LED_OFF1_OFF2:
6056 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6057 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6058 break;
6059 default:
6060 /* Do nothing */
6061 break;
6062 }
6063 }
6064 return E1000_SUCCESS;
6065}
6066
6067/******************************************************************************
6068 * Prepares SW controlable LED for use and saves the current state of the LED.
6069 *
6070 * hw - Struct containing variables accessed by shared code
6071 *****************************************************************************/
6072int32_t
6073e1000_setup_led(struct e1000_hw *hw)
6074{
6075 uint32_t ledctl;
6076 int32_t ret_val = E1000_SUCCESS;
6077
6078 DEBUGFUNC("e1000_setup_led");
6079
Auke Kok8fc897b2006-08-28 14:56:16 -07006080 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 case e1000_82542_rev2_0:
6082 case e1000_82542_rev2_1:
6083 case e1000_82543:
6084 case e1000_82544:
6085 /* No setup necessary */
6086 break;
6087 case e1000_82541:
6088 case e1000_82547:
6089 case e1000_82541_rev_2:
6090 case e1000_82547_rev_2:
6091 /* Turn off PHY Smart Power Down (if enabled) */
6092 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6093 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006094 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 return ret_val;
6096 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6097 (uint16_t)(hw->phy_spd_default &
6098 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006099 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 return ret_val;
6101 /* Fall Through */
6102 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006103 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 ledctl = E1000_READ_REG(hw, LEDCTL);
6105 /* Save current LEDCTL settings */
6106 hw->ledctl_default = ledctl;
6107 /* Turn off LED0 */
6108 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6109 E1000_LEDCTL_LED0_BLINK |
6110 E1000_LEDCTL_LED0_MODE_MASK);
6111 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6112 E1000_LEDCTL_LED0_MODE_SHIFT);
6113 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006114 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6116 break;
6117 }
6118
6119 return E1000_SUCCESS;
6120}
6121
Auke Kok8fc897b2006-08-28 14:56:16 -07006122
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006124 * Used on 82571 and later Si that has LED blink bits.
6125 * Callers must use their own timer and should have already called
6126 * e1000_id_led_init()
6127 * Call e1000_cleanup led() to stop blinking
6128 *
6129 * hw - Struct containing variables accessed by shared code
6130 *****************************************************************************/
6131int32_t
6132e1000_blink_led_start(struct e1000_hw *hw)
6133{
6134 int16_t i;
6135 uint32_t ledctl_blink = 0;
6136
6137 DEBUGFUNC("e1000_id_led_blink_on");
6138
6139 if (hw->mac_type < e1000_82571) {
6140 /* Nothing to do */
6141 return E1000_SUCCESS;
6142 }
6143 if (hw->media_type == e1000_media_type_fiber) {
6144 /* always blink LED0 for PCI-E fiber */
6145 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6146 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6147 } else {
6148 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6149 ledctl_blink = hw->ledctl_mode2;
6150 for (i=0; i < 4; i++)
6151 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6152 E1000_LEDCTL_MODE_LED_ON)
6153 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6154 }
6155
6156 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6157
6158 return E1000_SUCCESS;
6159}
6160
6161/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 * Restores the saved state of the SW controlable LED.
6163 *
6164 * hw - Struct containing variables accessed by shared code
6165 *****************************************************************************/
6166int32_t
6167e1000_cleanup_led(struct e1000_hw *hw)
6168{
6169 int32_t ret_val = E1000_SUCCESS;
6170
6171 DEBUGFUNC("e1000_cleanup_led");
6172
Auke Kok8fc897b2006-08-28 14:56:16 -07006173 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 case e1000_82542_rev2_0:
6175 case e1000_82542_rev2_1:
6176 case e1000_82543:
6177 case e1000_82544:
6178 /* No cleanup necessary */
6179 break;
6180 case e1000_82541:
6181 case e1000_82547:
6182 case e1000_82541_rev_2:
6183 case e1000_82547_rev_2:
6184 /* Turn on PHY Smart Power Down (if previously enabled) */
6185 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6186 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006187 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 return ret_val;
6189 /* Fall Through */
6190 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006191 if (hw->phy_type == e1000_phy_ife) {
6192 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6193 break;
6194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 /* Restore LEDCTL settings */
6196 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6197 break;
6198 }
6199
6200 return E1000_SUCCESS;
6201}
6202
6203/******************************************************************************
6204 * Turns on the software controllable LED
6205 *
6206 * hw - Struct containing variables accessed by shared code
6207 *****************************************************************************/
6208int32_t
6209e1000_led_on(struct e1000_hw *hw)
6210{
6211 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6212
6213 DEBUGFUNC("e1000_led_on");
6214
Auke Kok8fc897b2006-08-28 14:56:16 -07006215 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216 case e1000_82542_rev2_0:
6217 case e1000_82542_rev2_1:
6218 case e1000_82543:
6219 /* Set SW Defineable Pin 0 to turn on the LED */
6220 ctrl |= E1000_CTRL_SWDPIN0;
6221 ctrl |= E1000_CTRL_SWDPIO0;
6222 break;
6223 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006224 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 /* Set SW Defineable Pin 0 to turn on the LED */
6226 ctrl |= E1000_CTRL_SWDPIN0;
6227 ctrl |= E1000_CTRL_SWDPIO0;
6228 } else {
6229 /* Clear SW Defineable Pin 0 to turn on the LED */
6230 ctrl &= ~E1000_CTRL_SWDPIN0;
6231 ctrl |= E1000_CTRL_SWDPIO0;
6232 }
6233 break;
6234 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006235 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 /* Clear SW Defineable Pin 0 to turn on the LED */
6237 ctrl &= ~E1000_CTRL_SWDPIN0;
6238 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006239 } else if (hw->phy_type == e1000_phy_ife) {
6240 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6241 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6242 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6244 return E1000_SUCCESS;
6245 }
6246 break;
6247 }
6248
6249 E1000_WRITE_REG(hw, CTRL, ctrl);
6250
6251 return E1000_SUCCESS;
6252}
6253
6254/******************************************************************************
6255 * Turns off the software controllable LED
6256 *
6257 * hw - Struct containing variables accessed by shared code
6258 *****************************************************************************/
6259int32_t
6260e1000_led_off(struct e1000_hw *hw)
6261{
6262 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6263
6264 DEBUGFUNC("e1000_led_off");
6265
Auke Kok8fc897b2006-08-28 14:56:16 -07006266 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 case e1000_82542_rev2_0:
6268 case e1000_82542_rev2_1:
6269 case e1000_82543:
6270 /* Clear SW Defineable Pin 0 to turn off the LED */
6271 ctrl &= ~E1000_CTRL_SWDPIN0;
6272 ctrl |= E1000_CTRL_SWDPIO0;
6273 break;
6274 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006275 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 /* Clear SW Defineable Pin 0 to turn off the LED */
6277 ctrl &= ~E1000_CTRL_SWDPIN0;
6278 ctrl |= E1000_CTRL_SWDPIO0;
6279 } else {
6280 /* Set SW Defineable Pin 0 to turn off the LED */
6281 ctrl |= E1000_CTRL_SWDPIN0;
6282 ctrl |= E1000_CTRL_SWDPIO0;
6283 }
6284 break;
6285 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006286 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 /* Set SW Defineable Pin 0 to turn off the LED */
6288 ctrl |= E1000_CTRL_SWDPIN0;
6289 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006290 } else if (hw->phy_type == e1000_phy_ife) {
6291 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6292 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6293 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6295 return E1000_SUCCESS;
6296 }
6297 break;
6298 }
6299
6300 E1000_WRITE_REG(hw, CTRL, ctrl);
6301
6302 return E1000_SUCCESS;
6303}
6304
6305/******************************************************************************
6306 * Clears all hardware statistics counters.
6307 *
6308 * hw - Struct containing variables accessed by shared code
6309 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006310static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311e1000_clear_hw_cntrs(struct e1000_hw *hw)
6312{
6313 volatile uint32_t temp;
6314
6315 temp = E1000_READ_REG(hw, CRCERRS);
6316 temp = E1000_READ_REG(hw, SYMERRS);
6317 temp = E1000_READ_REG(hw, MPC);
6318 temp = E1000_READ_REG(hw, SCC);
6319 temp = E1000_READ_REG(hw, ECOL);
6320 temp = E1000_READ_REG(hw, MCC);
6321 temp = E1000_READ_REG(hw, LATECOL);
6322 temp = E1000_READ_REG(hw, COLC);
6323 temp = E1000_READ_REG(hw, DC);
6324 temp = E1000_READ_REG(hw, SEC);
6325 temp = E1000_READ_REG(hw, RLEC);
6326 temp = E1000_READ_REG(hw, XONRXC);
6327 temp = E1000_READ_REG(hw, XONTXC);
6328 temp = E1000_READ_REG(hw, XOFFRXC);
6329 temp = E1000_READ_REG(hw, XOFFTXC);
6330 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006331
6332 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333 temp = E1000_READ_REG(hw, PRC64);
6334 temp = E1000_READ_REG(hw, PRC127);
6335 temp = E1000_READ_REG(hw, PRC255);
6336 temp = E1000_READ_REG(hw, PRC511);
6337 temp = E1000_READ_REG(hw, PRC1023);
6338 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006339 }
6340
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341 temp = E1000_READ_REG(hw, GPRC);
6342 temp = E1000_READ_REG(hw, BPRC);
6343 temp = E1000_READ_REG(hw, MPRC);
6344 temp = E1000_READ_REG(hw, GPTC);
6345 temp = E1000_READ_REG(hw, GORCL);
6346 temp = E1000_READ_REG(hw, GORCH);
6347 temp = E1000_READ_REG(hw, GOTCL);
6348 temp = E1000_READ_REG(hw, GOTCH);
6349 temp = E1000_READ_REG(hw, RNBC);
6350 temp = E1000_READ_REG(hw, RUC);
6351 temp = E1000_READ_REG(hw, RFC);
6352 temp = E1000_READ_REG(hw, ROC);
6353 temp = E1000_READ_REG(hw, RJC);
6354 temp = E1000_READ_REG(hw, TORL);
6355 temp = E1000_READ_REG(hw, TORH);
6356 temp = E1000_READ_REG(hw, TOTL);
6357 temp = E1000_READ_REG(hw, TOTH);
6358 temp = E1000_READ_REG(hw, TPR);
6359 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006360
6361 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 temp = E1000_READ_REG(hw, PTC64);
6363 temp = E1000_READ_REG(hw, PTC127);
6364 temp = E1000_READ_REG(hw, PTC255);
6365 temp = E1000_READ_REG(hw, PTC511);
6366 temp = E1000_READ_REG(hw, PTC1023);
6367 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006368 }
6369
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370 temp = E1000_READ_REG(hw, MPTC);
6371 temp = E1000_READ_REG(hw, BPTC);
6372
Auke Kok8fc897b2006-08-28 14:56:16 -07006373 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374
6375 temp = E1000_READ_REG(hw, ALGNERRC);
6376 temp = E1000_READ_REG(hw, RXERRC);
6377 temp = E1000_READ_REG(hw, TNCRS);
6378 temp = E1000_READ_REG(hw, CEXTERR);
6379 temp = E1000_READ_REG(hw, TSCTC);
6380 temp = E1000_READ_REG(hw, TSCTFC);
6381
Auke Kok8fc897b2006-08-28 14:56:16 -07006382 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383
6384 temp = E1000_READ_REG(hw, MGTPRC);
6385 temp = E1000_READ_REG(hw, MGTPDC);
6386 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006387
Auke Kok8fc897b2006-08-28 14:56:16 -07006388 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006389
6390 temp = E1000_READ_REG(hw, IAC);
6391 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006392
6393 if (hw->mac_type == e1000_ich8lan) return;
6394
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006395 temp = E1000_READ_REG(hw, ICRXPTC);
6396 temp = E1000_READ_REG(hw, ICRXATC);
6397 temp = E1000_READ_REG(hw, ICTXPTC);
6398 temp = E1000_READ_REG(hw, ICTXATC);
6399 temp = E1000_READ_REG(hw, ICTXQEC);
6400 temp = E1000_READ_REG(hw, ICTXQMTC);
6401 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402}
6403
6404/******************************************************************************
6405 * Resets Adaptive IFS to its default state.
6406 *
6407 * hw - Struct containing variables accessed by shared code
6408 *
6409 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6410 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6411 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6412 * before calling this function.
6413 *****************************************************************************/
6414void
6415e1000_reset_adaptive(struct e1000_hw *hw)
6416{
6417 DEBUGFUNC("e1000_reset_adaptive");
6418
Auke Kok8fc897b2006-08-28 14:56:16 -07006419 if (hw->adaptive_ifs) {
6420 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 hw->current_ifs_val = 0;
6422 hw->ifs_min_val = IFS_MIN;
6423 hw->ifs_max_val = IFS_MAX;
6424 hw->ifs_step_size = IFS_STEP;
6425 hw->ifs_ratio = IFS_RATIO;
6426 }
6427 hw->in_ifs_mode = FALSE;
6428 E1000_WRITE_REG(hw, AIT, 0);
6429 } else {
6430 DEBUGOUT("Not in Adaptive IFS mode!\n");
6431 }
6432}
6433
6434/******************************************************************************
6435 * Called during the callback/watchdog routine to update IFS value based on
6436 * the ratio of transmits to collisions.
6437 *
6438 * hw - Struct containing variables accessed by shared code
6439 * tx_packets - Number of transmits since last callback
6440 * total_collisions - Number of collisions since last callback
6441 *****************************************************************************/
6442void
6443e1000_update_adaptive(struct e1000_hw *hw)
6444{
6445 DEBUGFUNC("e1000_update_adaptive");
6446
Auke Kok8fc897b2006-08-28 14:56:16 -07006447 if (hw->adaptive_ifs) {
6448 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6449 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006451 if (hw->current_ifs_val < hw->ifs_max_val) {
6452 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 hw->current_ifs_val = hw->ifs_min_val;
6454 else
6455 hw->current_ifs_val += hw->ifs_step_size;
6456 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6457 }
6458 }
6459 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006460 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 hw->current_ifs_val = 0;
6462 hw->in_ifs_mode = FALSE;
6463 E1000_WRITE_REG(hw, AIT, 0);
6464 }
6465 }
6466 } else {
6467 DEBUGOUT("Not in Adaptive IFS mode!\n");
6468 }
6469}
6470
6471/******************************************************************************
6472 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6473 *
6474 * hw - Struct containing variables accessed by shared code
6475 * frame_len - The length of the frame in question
6476 * mac_addr - The Ethernet destination address of the frame in question
6477 *****************************************************************************/
6478void
6479e1000_tbi_adjust_stats(struct e1000_hw *hw,
6480 struct e1000_hw_stats *stats,
6481 uint32_t frame_len,
6482 uint8_t *mac_addr)
6483{
6484 uint64_t carry_bit;
6485
6486 /* First adjust the frame length. */
6487 frame_len--;
6488 /* We need to adjust the statistics counters, since the hardware
6489 * counters overcount this packet as a CRC error and undercount
6490 * the packet as a good packet
6491 */
6492 /* This packet should not be counted as a CRC error. */
6493 stats->crcerrs--;
6494 /* This packet does count as a Good Packet Received. */
6495 stats->gprc++;
6496
6497 /* Adjust the Good Octets received counters */
6498 carry_bit = 0x80000000 & stats->gorcl;
6499 stats->gorcl += frame_len;
6500 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6501 * Received Count) was one before the addition,
6502 * AND it is zero after, then we lost the carry out,
6503 * need to add one to Gorch (Good Octets Received Count High).
6504 * This could be simplified if all environments supported
6505 * 64-bit integers.
6506 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006507 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 stats->gorch++;
6509 /* Is this a broadcast or multicast? Check broadcast first,
6510 * since the test for a multicast frame will test positive on
6511 * a broadcast frame.
6512 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006513 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 /* Broadcast packet */
6515 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006516 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 /* Multicast packet */
6518 stats->mprc++;
6519
Auke Kok8fc897b2006-08-28 14:56:16 -07006520 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 /* In this case, the hardware has overcounted the number of
6522 * oversize frames.
6523 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006524 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 stats->roc--;
6526 }
6527
6528 /* Adjust the bin counters when the extra byte put the frame in the
6529 * wrong bin. Remember that the frame_len was adjusted above.
6530 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006531 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 stats->prc64++;
6533 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006534 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 stats->prc127++;
6536 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006537 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538 stats->prc255++;
6539 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006540 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 stats->prc511++;
6542 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006543 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 stats->prc1023++;
6545 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006546 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 stats->prc1522++;
6548 }
6549}
6550
6551/******************************************************************************
6552 * Gets the current PCI bus type, speed, and width of the hardware
6553 *
6554 * hw - Struct containing variables accessed by shared code
6555 *****************************************************************************/
6556void
6557e1000_get_bus_info(struct e1000_hw *hw)
6558{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006559 int32_t ret_val;
6560 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561 uint32_t status;
6562
6563 switch (hw->mac_type) {
6564 case e1000_82542_rev2_0:
6565 case e1000_82542_rev2_1:
6566 hw->bus_type = e1000_bus_type_unknown;
6567 hw->bus_speed = e1000_bus_speed_unknown;
6568 hw->bus_width = e1000_bus_width_unknown;
6569 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006570 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006571 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006572 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006573 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006574 hw->bus_type = e1000_bus_type_pci_express;
6575 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006576 ret_val = e1000_read_pcie_cap_reg(hw,
6577 PCI_EX_LINK_STATUS,
6578 &pci_ex_link_status);
6579 if (ret_val)
6580 hw->bus_width = e1000_bus_width_unknown;
6581 else
6582 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6583 PCI_EX_LINK_WIDTH_SHIFT;
6584 break;
6585 case e1000_ich8lan:
6586 hw->bus_type = e1000_bus_type_pci_express;
6587 hw->bus_speed = e1000_bus_speed_2500;
6588 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006589 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 default:
6591 status = E1000_READ_REG(hw, STATUS);
6592 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6593 e1000_bus_type_pcix : e1000_bus_type_pci;
6594
Auke Kok8fc897b2006-08-28 14:56:16 -07006595 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6597 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006598 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6600 e1000_bus_speed_66 : e1000_bus_speed_33;
6601 } else {
6602 switch (status & E1000_STATUS_PCIX_SPEED) {
6603 case E1000_STATUS_PCIX_SPEED_66:
6604 hw->bus_speed = e1000_bus_speed_66;
6605 break;
6606 case E1000_STATUS_PCIX_SPEED_100:
6607 hw->bus_speed = e1000_bus_speed_100;
6608 break;
6609 case E1000_STATUS_PCIX_SPEED_133:
6610 hw->bus_speed = e1000_bus_speed_133;
6611 break;
6612 default:
6613 hw->bus_speed = e1000_bus_speed_reserved;
6614 break;
6615 }
6616 }
6617 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6618 e1000_bus_width_64 : e1000_bus_width_32;
6619 break;
6620 }
6621}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622
6623/******************************************************************************
6624 * Writes a value to one of the devices registers using port I/O (as opposed to
6625 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6626 *
6627 * hw - Struct containing variables accessed by shared code
6628 * offset - offset to write to
6629 * value - value to write
6630 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006631static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632e1000_write_reg_io(struct e1000_hw *hw,
6633 uint32_t offset,
6634 uint32_t value)
6635{
6636 unsigned long io_addr = hw->io_base;
6637 unsigned long io_data = hw->io_base + 4;
6638
6639 e1000_io_write(hw, io_addr, offset);
6640 e1000_io_write(hw, io_data, value);
6641}
6642
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643/******************************************************************************
6644 * Estimates the cable length.
6645 *
6646 * hw - Struct containing variables accessed by shared code
6647 * min_length - The estimated minimum length
6648 * max_length - The estimated maximum length
6649 *
6650 * returns: - E1000_ERR_XXX
6651 * E1000_SUCCESS
6652 *
6653 * This function always returns a ranged length (minimum & maximum).
6654 * So for M88 phy's, this function interprets the one value returned from the
6655 * register to the minimum and maximum range.
6656 * For IGP phy's, the function calculates the range by the AGC registers.
6657 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006658static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659e1000_get_cable_length(struct e1000_hw *hw,
6660 uint16_t *min_length,
6661 uint16_t *max_length)
6662{
6663 int32_t ret_val;
6664 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 uint16_t i, phy_data;
6666 uint16_t cable_length;
6667
6668 DEBUGFUNC("e1000_get_cable_length");
6669
6670 *min_length = *max_length = 0;
6671
6672 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006673 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006674
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6676 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006677 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678 return ret_val;
6679 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6680 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6681
6682 /* Convert the enum value to ranged values */
6683 switch (cable_length) {
6684 case e1000_cable_length_50:
6685 *min_length = 0;
6686 *max_length = e1000_igp_cable_length_50;
6687 break;
6688 case e1000_cable_length_50_80:
6689 *min_length = e1000_igp_cable_length_50;
6690 *max_length = e1000_igp_cable_length_80;
6691 break;
6692 case e1000_cable_length_80_110:
6693 *min_length = e1000_igp_cable_length_80;
6694 *max_length = e1000_igp_cable_length_110;
6695 break;
6696 case e1000_cable_length_110_140:
6697 *min_length = e1000_igp_cable_length_110;
6698 *max_length = e1000_igp_cable_length_140;
6699 break;
6700 case e1000_cable_length_140:
6701 *min_length = e1000_igp_cable_length_140;
6702 *max_length = e1000_igp_cable_length_170;
6703 break;
6704 default:
6705 return -E1000_ERR_PHY;
6706 break;
6707 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006708 } else if (hw->phy_type == e1000_phy_gg82563) {
6709 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6710 &phy_data);
6711 if (ret_val)
6712 return ret_val;
6713 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6714
6715 switch (cable_length) {
6716 case e1000_gg_cable_length_60:
6717 *min_length = 0;
6718 *max_length = e1000_igp_cable_length_60;
6719 break;
6720 case e1000_gg_cable_length_60_115:
6721 *min_length = e1000_igp_cable_length_60;
6722 *max_length = e1000_igp_cable_length_115;
6723 break;
6724 case e1000_gg_cable_length_115_150:
6725 *min_length = e1000_igp_cable_length_115;
6726 *max_length = e1000_igp_cable_length_150;
6727 break;
6728 case e1000_gg_cable_length_150:
6729 *min_length = e1000_igp_cable_length_150;
6730 *max_length = e1000_igp_cable_length_180;
6731 break;
6732 default:
6733 return -E1000_ERR_PHY;
6734 break;
6735 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006736 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006737 uint16_t cur_agc_value;
6738 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6740 {IGP01E1000_PHY_AGC_A,
6741 IGP01E1000_PHY_AGC_B,
6742 IGP01E1000_PHY_AGC_C,
6743 IGP01E1000_PHY_AGC_D};
6744 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006745 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746
6747 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006748 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 return ret_val;
6750
Auke Kokcd94dd02006-06-27 09:08:22 -07006751 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752
Auke Kokcd94dd02006-06-27 09:08:22 -07006753 /* Value bound check. */
6754 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6755 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756 return -E1000_ERR_PHY;
6757
Auke Kokcd94dd02006-06-27 09:08:22 -07006758 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759
6760 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006761 if (min_agc_value > cur_agc_value)
6762 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 }
6764
6765 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006766 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6767 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768
6769 /* Get the average length of the remaining 3 channels */
6770 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6771 } else {
6772 /* Get the average length of all the 4 channels. */
6773 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6774 }
6775
6776 /* Set the range of the calculated length. */
6777 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6778 IGP01E1000_AGC_RANGE) > 0) ?
6779 (e1000_igp_cable_length_table[agc_value] -
6780 IGP01E1000_AGC_RANGE) : 0;
6781 *max_length = e1000_igp_cable_length_table[agc_value] +
6782 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006783 } else if (hw->phy_type == e1000_phy_igp_2 ||
6784 hw->phy_type == e1000_phy_igp_3) {
6785 uint16_t cur_agc_index, max_agc_index = 0;
6786 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006787 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6788 {IGP02E1000_PHY_AGC_A,
6789 IGP02E1000_PHY_AGC_B,
6790 IGP02E1000_PHY_AGC_C,
6791 IGP02E1000_PHY_AGC_D};
6792 /* Read the AGC registers for all channels */
6793 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6794 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6795 if (ret_val)
6796 return ret_val;
6797
Auke Kok8fc897b2006-08-28 14:56:16 -07006798 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006799 * fine gain values. The result is a number that can be put into
6800 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006801 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6802 IGP02E1000_AGC_LENGTH_MASK;
6803
6804 /* Array index bound check. */
6805 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6806 (cur_agc_index == 0))
6807 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006808
6809 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006810 if (e1000_igp_2_cable_length_table[min_agc_index] >
6811 e1000_igp_2_cable_length_table[cur_agc_index])
6812 min_agc_index = cur_agc_index;
6813 if (e1000_igp_2_cable_length_table[max_agc_index] <
6814 e1000_igp_2_cable_length_table[cur_agc_index])
6815 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006816
Auke Kokcd94dd02006-06-27 09:08:22 -07006817 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006818 }
6819
Auke Kokcd94dd02006-06-27 09:08:22 -07006820 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6821 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006822 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6823
6824 /* Calculate cable length with the error range of +/- 10 meters. */
6825 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6826 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6827 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006828 }
6829
6830 return E1000_SUCCESS;
6831}
6832
6833/******************************************************************************
6834 * Check the cable polarity
6835 *
6836 * hw - Struct containing variables accessed by shared code
6837 * polarity - output parameter : 0 - Polarity is not reversed
6838 * 1 - Polarity is reversed.
6839 *
6840 * returns: - E1000_ERR_XXX
6841 * E1000_SUCCESS
6842 *
6843 * For phy's older then IGP, this function simply reads the polarity bit in the
6844 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6845 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6846 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6847 * IGP01E1000_PHY_PCS_INIT_REG.
6848 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006849static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006851 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006852{
6853 int32_t ret_val;
6854 uint16_t phy_data;
6855
6856 DEBUGFUNC("e1000_check_polarity");
6857
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006858 if ((hw->phy_type == e1000_phy_m88) ||
6859 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860 /* return the Polarity bit in the Status register. */
6861 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6862 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006863 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006865 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6866 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6867 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6868
Auke Kokcd94dd02006-06-27 09:08:22 -07006869 } else if (hw->phy_type == e1000_phy_igp ||
6870 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006871 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872 /* Read the Status register to check the speed */
6873 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6874 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006875 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006876 return ret_val;
6877
6878 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6879 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006880 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881 IGP01E1000_PSSR_SPEED_1000MBPS) {
6882
6883 /* Read the GIG initialization PCS register (0x00B4) */
6884 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6885 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006886 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006887 return ret_val;
6888
6889 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006890 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6891 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 } else {
6893 /* For 10 Mbps, read the polarity bit in the status register. (for
6894 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006895 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6896 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006898 } else if (hw->phy_type == e1000_phy_ife) {
6899 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6900 &phy_data);
6901 if (ret_val)
6902 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006903 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6904 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6905 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906 }
6907 return E1000_SUCCESS;
6908}
6909
6910/******************************************************************************
6911 * Check if Downshift occured
6912 *
6913 * hw - Struct containing variables accessed by shared code
6914 * downshift - output parameter : 0 - No Downshift ocured.
6915 * 1 - Downshift ocured.
6916 *
6917 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006918 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919 *
6920 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6921 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6922 * Link Health register. In IGP this bit is latched high, so the driver must
6923 * read it immediately after link is established.
6924 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006925static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006926e1000_check_downshift(struct e1000_hw *hw)
6927{
6928 int32_t ret_val;
6929 uint16_t phy_data;
6930
6931 DEBUGFUNC("e1000_check_downshift");
6932
Auke Kokcd94dd02006-06-27 09:08:22 -07006933 if (hw->phy_type == e1000_phy_igp ||
6934 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006935 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006936 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6937 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006938 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006939 return ret_val;
6940
6941 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006942 } else if ((hw->phy_type == e1000_phy_m88) ||
6943 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006944 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6945 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006946 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 return ret_val;
6948
6949 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6950 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006951 } else if (hw->phy_type == e1000_phy_ife) {
6952 /* e1000_phy_ife supports 10/100 speed only */
6953 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006955
Linus Torvalds1da177e2005-04-16 15:20:36 -07006956 return E1000_SUCCESS;
6957}
6958
6959/*****************************************************************************
6960 *
6961 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6962 * gigabit link is achieved to improve link quality.
6963 *
6964 * hw: Struct containing variables accessed by shared code
6965 *
6966 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6967 * E1000_SUCCESS at any other case.
6968 *
6969 ****************************************************************************/
6970
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006971static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006972e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6973 boolean_t link_up)
6974{
6975 int32_t ret_val;
6976 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6977 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6978 {IGP01E1000_PHY_AGC_PARAM_A,
6979 IGP01E1000_PHY_AGC_PARAM_B,
6980 IGP01E1000_PHY_AGC_PARAM_C,
6981 IGP01E1000_PHY_AGC_PARAM_D};
6982 uint16_t min_length, max_length;
6983
6984 DEBUGFUNC("e1000_config_dsp_after_link_change");
6985
Auke Kok8fc897b2006-08-28 14:56:16 -07006986 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006987 return E1000_SUCCESS;
6988
Auke Kok8fc897b2006-08-28 14:56:16 -07006989 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07006991 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992 DEBUGOUT("Error getting link speed and duplex\n");
6993 return ret_val;
6994 }
6995
Auke Kok8fc897b2006-08-28 14:56:16 -07006996 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997
Auke Kokcd94dd02006-06-27 09:08:22 -07006998 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
6999 if (ret_val)
7000 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007001
Auke Kok8fc897b2006-08-28 14:56:16 -07007002 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007003 min_length >= e1000_igp_cable_length_50) {
7004
Auke Kok8fc897b2006-08-28 14:56:16 -07007005 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007006 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7007 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007008 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007009 return ret_val;
7010
7011 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7012
7013 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7014 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007015 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016 return ret_val;
7017 }
7018 hw->dsp_config_state = e1000_dsp_config_activated;
7019 }
7020
Auke Kok8fc897b2006-08-28 14:56:16 -07007021 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 (min_length < e1000_igp_cable_length_50)) {
7023
7024 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7025 uint32_t idle_errs = 0;
7026
7027 /* clear previous idle error counts */
7028 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7029 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007030 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031 return ret_val;
7032
Auke Kok8fc897b2006-08-28 14:56:16 -07007033 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034 udelay(1000);
7035 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7036 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007037 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038 return ret_val;
7039
7040 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007041 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 hw->ffe_config_state = e1000_ffe_config_active;
7043
7044 ret_val = e1000_write_phy_reg(hw,
7045 IGP01E1000_PHY_DSP_FFE,
7046 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007047 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 return ret_val;
7049 break;
7050 }
7051
Auke Kok8fc897b2006-08-28 14:56:16 -07007052 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7054 }
7055 }
7056 }
7057 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007058 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 /* Save off the current value of register 0x2F5B to be restored at
7060 * the end of the routines. */
7061 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7062
Auke Kok8fc897b2006-08-28 14:56:16 -07007063 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 return ret_val;
7065
7066 /* Disable the PHY transmitter */
7067 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7068
Auke Kok8fc897b2006-08-28 14:56:16 -07007069 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007070 return ret_val;
7071
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007072 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007073
7074 ret_val = e1000_write_phy_reg(hw, 0x0000,
7075 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007076 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007078 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007079 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007080 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007081 return ret_val;
7082
7083 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7084 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7085
7086 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007087 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007088 return ret_val;
7089 }
7090
7091 ret_val = e1000_write_phy_reg(hw, 0x0000,
7092 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007093 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007094 return ret_val;
7095
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007096 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007097
7098 /* Now enable the transmitter */
7099 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7100
Auke Kok8fc897b2006-08-28 14:56:16 -07007101 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007102 return ret_val;
7103
7104 hw->dsp_config_state = e1000_dsp_config_enabled;
7105 }
7106
Auke Kok8fc897b2006-08-28 14:56:16 -07007107 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007108 /* Save off the current value of register 0x2F5B to be restored at
7109 * the end of the routines. */
7110 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7111
Auke Kok8fc897b2006-08-28 14:56:16 -07007112 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007113 return ret_val;
7114
7115 /* Disable the PHY transmitter */
7116 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7117
Auke Kok8fc897b2006-08-28 14:56:16 -07007118 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007119 return ret_val;
7120
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007121 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007122
7123 ret_val = e1000_write_phy_reg(hw, 0x0000,
7124 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007125 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007126 return ret_val;
7127 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7128 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007129 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007130 return ret_val;
7131
7132 ret_val = e1000_write_phy_reg(hw, 0x0000,
7133 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007134 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007135 return ret_val;
7136
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007137 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007138
7139 /* Now enable the transmitter */
7140 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7141
Auke Kok8fc897b2006-08-28 14:56:16 -07007142 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007143 return ret_val;
7144
7145 hw->ffe_config_state = e1000_ffe_config_enabled;
7146 }
7147 }
7148 return E1000_SUCCESS;
7149}
7150
7151/*****************************************************************************
7152 * Set PHY to class A mode
7153 * Assumes the following operations will follow to enable the new class mode.
7154 * 1. Do a PHY soft reset
7155 * 2. Restart auto-negotiation or force link.
7156 *
7157 * hw - Struct containing variables accessed by shared code
7158 ****************************************************************************/
7159static int32_t
7160e1000_set_phy_mode(struct e1000_hw *hw)
7161{
7162 int32_t ret_val;
7163 uint16_t eeprom_data;
7164
7165 DEBUGFUNC("e1000_set_phy_mode");
7166
Auke Kok8fc897b2006-08-28 14:56:16 -07007167 if ((hw->mac_type == e1000_82545_rev_3) &&
7168 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007169 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007170 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007171 return ret_val;
7172 }
7173
Auke Kok8fc897b2006-08-28 14:56:16 -07007174 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7175 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007176 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007177 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007178 return ret_val;
7179 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007180 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 return ret_val;
7182
7183 hw->phy_reset_disable = FALSE;
7184 }
7185 }
7186
7187 return E1000_SUCCESS;
7188}
7189
7190/*****************************************************************************
7191 *
7192 * This function sets the lplu state according to the active flag. When
7193 * activating lplu this function also disables smart speed and vise versa.
7194 * lplu will not be activated unless the device autonegotiation advertisment
7195 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7196 * hw: Struct containing variables accessed by shared code
7197 * active - true to enable lplu false to disable lplu.
7198 *
7199 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7200 * E1000_SUCCESS at any other case.
7201 *
7202 ****************************************************************************/
7203
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007204static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007205e1000_set_d3_lplu_state(struct e1000_hw *hw,
7206 boolean_t active)
7207{
Auke Kokcd94dd02006-06-27 09:08:22 -07007208 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007209 int32_t ret_val;
7210 uint16_t phy_data;
7211 DEBUGFUNC("e1000_set_d3_lplu_state");
7212
Auke Kokcd94dd02006-06-27 09:08:22 -07007213 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7214 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215 return E1000_SUCCESS;
7216
7217 /* During driver activity LPLU should not be used or it will attain link
7218 * from the lowest speeds starting from 10Mbps. The capability is used for
7219 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007220 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007221 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007222 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007223 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007224 } else if (hw->mac_type == e1000_ich8lan) {
7225 /* MAC writes into PHY register based on the state transition
7226 * and start auto-negotiation. SW driver can overwrite the settings
7227 * in CSR PHY power control E1000_PHY_CTRL register. */
7228 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007229 } else {
7230 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007231 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007232 return ret_val;
7233 }
7234
Auke Kok8fc897b2006-08-28 14:56:16 -07007235 if (!active) {
7236 if (hw->mac_type == e1000_82541_rev_2 ||
7237 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007238 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7239 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007240 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007241 return ret_val;
7242 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007243 if (hw->mac_type == e1000_ich8lan) {
7244 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7245 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7246 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007247 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7248 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7249 phy_data);
7250 if (ret_val)
7251 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007252 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007254
7255 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7256 * Dx states where the power conservation is most important. During
7257 * driver activity we should enable SmartSpeed, so performance is
7258 * maintained. */
7259 if (hw->smart_speed == e1000_smart_speed_on) {
7260 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7261 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007262 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007263 return ret_val;
7264
7265 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7266 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7267 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007269 return ret_val;
7270 } else if (hw->smart_speed == e1000_smart_speed_off) {
7271 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7272 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007273 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007274 return ret_val;
7275
7276 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7277 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7278 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007279 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280 return ret_val;
7281 }
7282
Auke Kok8fc897b2006-08-28 14:56:16 -07007283 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7284 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7285 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007286
Auke Kok8fc897b2006-08-28 14:56:16 -07007287 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007288 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007289 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7290 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007291 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007292 return ret_val;
7293 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007294 if (hw->mac_type == e1000_ich8lan) {
7295 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7296 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7297 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007298 phy_data |= IGP02E1000_PM_D3_LPLU;
7299 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7300 phy_data);
7301 if (ret_val)
7302 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007303 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007304 }
7305
7306 /* When LPLU is enabled we should disable SmartSpeed */
7307 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007308 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007309 return ret_val;
7310
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007311 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7312 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007313 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007314 return ret_val;
7315
7316 }
7317 return E1000_SUCCESS;
7318}
7319
7320/*****************************************************************************
7321 *
7322 * This function sets the lplu d0 state according to the active flag. When
7323 * activating lplu this function also disables smart speed and vise versa.
7324 * lplu will not be activated unless the device autonegotiation advertisment
7325 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7326 * hw: Struct containing variables accessed by shared code
7327 * active - true to enable lplu false to disable lplu.
7328 *
7329 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7330 * E1000_SUCCESS at any other case.
7331 *
7332 ****************************************************************************/
7333
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007334static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007335e1000_set_d0_lplu_state(struct e1000_hw *hw,
7336 boolean_t active)
7337{
Auke Kokcd94dd02006-06-27 09:08:22 -07007338 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007339 int32_t ret_val;
7340 uint16_t phy_data;
7341 DEBUGFUNC("e1000_set_d0_lplu_state");
7342
Auke Kok8fc897b2006-08-28 14:56:16 -07007343 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007344 return E1000_SUCCESS;
7345
Auke Kokcd94dd02006-06-27 09:08:22 -07007346 if (hw->mac_type == e1000_ich8lan) {
7347 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7348 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007349 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007350 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007351 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007352 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007353
7354 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007355 if (hw->mac_type == e1000_ich8lan) {
7356 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7357 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7358 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007359 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7360 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7361 if (ret_val)
7362 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007363 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007364
7365 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7366 * Dx states where the power conservation is most important. During
7367 * driver activity we should enable SmartSpeed, so performance is
7368 * maintained. */
7369 if (hw->smart_speed == e1000_smart_speed_on) {
7370 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7371 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007372 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007373 return ret_val;
7374
7375 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7376 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7377 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007378 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007379 return ret_val;
7380 } else if (hw->smart_speed == e1000_smart_speed_off) {
7381 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7382 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007383 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007384 return ret_val;
7385
7386 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7387 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7388 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007389 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007390 return ret_val;
7391 }
7392
7393
7394 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007395
Auke Kokcd94dd02006-06-27 09:08:22 -07007396 if (hw->mac_type == e1000_ich8lan) {
7397 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7398 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7399 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007400 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007401 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7402 if (ret_val)
7403 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007404 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007405
Linus Torvalds1da177e2005-04-16 15:20:36 -07007406 /* When LPLU is enabled we should disable SmartSpeed */
7407 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007408 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007409 return ret_val;
7410
7411 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7412 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007413 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007414 return ret_val;
7415
7416 }
7417 return E1000_SUCCESS;
7418}
7419
7420/******************************************************************************
7421 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7422 *
7423 * hw - Struct containing variables accessed by shared code
7424 *****************************************************************************/
7425static int32_t
7426e1000_set_vco_speed(struct e1000_hw *hw)
7427{
7428 int32_t ret_val;
7429 uint16_t default_page = 0;
7430 uint16_t phy_data;
7431
7432 DEBUGFUNC("e1000_set_vco_speed");
7433
Auke Kok8fc897b2006-08-28 14:56:16 -07007434 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007435 case e1000_82545_rev_3:
7436 case e1000_82546_rev_3:
7437 break;
7438 default:
7439 return E1000_SUCCESS;
7440 }
7441
7442 /* Set PHY register 30, page 5, bit 8 to 0 */
7443
7444 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007445 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007446 return ret_val;
7447
7448 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007449 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007450 return ret_val;
7451
7452 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007453 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007454 return ret_val;
7455
7456 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7457 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007458 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007459 return ret_val;
7460
7461 /* Set PHY register 30, page 4, bit 11 to 1 */
7462
7463 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007464 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007465 return ret_val;
7466
7467 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007468 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007469 return ret_val;
7470
7471 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7472 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007473 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474 return ret_val;
7475
7476 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007477 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007478 return ret_val;
7479
7480 return E1000_SUCCESS;
7481}
7482
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007483
7484/*****************************************************************************
7485 * This function reads the cookie from ARC ram.
7486 *
7487 * returns: - E1000_SUCCESS .
7488 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007489static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007490e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7491{
7492 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007493 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007494 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7495
7496 length = (length >> 2);
7497 offset = (offset >> 2);
7498
7499 for (i = 0; i < length; i++) {
7500 *((uint32_t *) buffer + i) =
7501 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7502 }
7503 return E1000_SUCCESS;
7504}
7505
7506
7507/*****************************************************************************
7508 * This function checks whether the HOST IF is enabled for command operaton
7509 * and also checks whether the previous command is completed.
7510 * It busy waits in case of previous command is not completed.
7511 *
Auke Kok76c224b2006-05-23 13:36:06 -07007512 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007513 * timeout
7514 * - E1000_SUCCESS for success.
7515 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007516static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007517e1000_mng_enable_host_if(struct e1000_hw * hw)
7518{
7519 uint32_t hicr;
7520 uint8_t i;
7521
7522 /* Check that the host interface is enabled. */
7523 hicr = E1000_READ_REG(hw, HICR);
7524 if ((hicr & E1000_HICR_EN) == 0) {
7525 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7526 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7527 }
7528 /* check the previous command is completed */
7529 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7530 hicr = E1000_READ_REG(hw, HICR);
7531 if (!(hicr & E1000_HICR_C))
7532 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007533 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007534 }
7535
Auke Kok76c224b2006-05-23 13:36:06 -07007536 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007537 DEBUGOUT("Previous command timeout failed .\n");
7538 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7539 }
7540 return E1000_SUCCESS;
7541}
7542
7543/*****************************************************************************
7544 * This function writes the buffer content at the offset given on the host if.
7545 * It also does alignment considerations to do the writes in most efficient way.
7546 * Also fills up the sum of the buffer in *buffer parameter.
7547 *
7548 * returns - E1000_SUCCESS for success.
7549 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007550static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007551e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7552 uint16_t length, uint16_t offset, uint8_t *sum)
7553{
7554 uint8_t *tmp;
7555 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007556 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007557 uint16_t remaining, i, j, prev_bytes;
7558
7559 /* sum = only sum of the data and it is not checksum */
7560
7561 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7562 return -E1000_ERR_PARAM;
7563 }
7564
7565 tmp = (uint8_t *)&data;
7566 prev_bytes = offset & 0x3;
7567 offset &= 0xFFFC;
7568 offset >>= 2;
7569
7570 if (prev_bytes) {
7571 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7572 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7573 *(tmp + j) = *bufptr++;
7574 *sum += *(tmp + j);
7575 }
7576 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7577 length -= j - prev_bytes;
7578 offset++;
7579 }
7580
7581 remaining = length & 0x3;
7582 length -= remaining;
7583
7584 /* Calculate length in DWORDs */
7585 length >>= 2;
7586
7587 /* The device driver writes the relevant command block into the
7588 * ram area. */
7589 for (i = 0; i < length; i++) {
7590 for (j = 0; j < sizeof(uint32_t); j++) {
7591 *(tmp + j) = *bufptr++;
7592 *sum += *(tmp + j);
7593 }
7594
7595 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7596 }
7597 if (remaining) {
7598 for (j = 0; j < sizeof(uint32_t); j++) {
7599 if (j < remaining)
7600 *(tmp + j) = *bufptr++;
7601 else
7602 *(tmp + j) = 0;
7603
7604 *sum += *(tmp + j);
7605 }
7606 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7607 }
7608
7609 return E1000_SUCCESS;
7610}
7611
7612
7613/*****************************************************************************
7614 * This function writes the command header after does the checksum calculation.
7615 *
7616 * returns - E1000_SUCCESS for success.
7617 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007618static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007619e1000_mng_write_cmd_header(struct e1000_hw * hw,
7620 struct e1000_host_mng_command_header * hdr)
7621{
7622 uint16_t i;
7623 uint8_t sum;
7624 uint8_t *buffer;
7625
7626 /* Write the whole command header structure which includes sum of
7627 * the buffer */
7628
7629 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7630
7631 sum = hdr->checksum;
7632 hdr->checksum = 0;
7633
7634 buffer = (uint8_t *) hdr;
7635 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007636 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007637 sum += buffer[i];
7638
7639 hdr->checksum = 0 - sum;
7640
7641 length >>= 2;
7642 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007643 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007644 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007645 E1000_WRITE_FLUSH(hw);
7646 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007647
7648 return E1000_SUCCESS;
7649}
7650
7651
7652/*****************************************************************************
7653 * This function indicates to ARC that a new command is pending which completes
7654 * one write operation by the driver.
7655 *
7656 * returns - E1000_SUCCESS for success.
7657 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007658static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007659e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007660{
7661 uint32_t hicr;
7662
7663 hicr = E1000_READ_REG(hw, HICR);
7664 /* Setting this bit tells the ARC that a new command is pending. */
7665 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7666
7667 return E1000_SUCCESS;
7668}
7669
7670
7671/*****************************************************************************
7672 * This function checks the mode of the firmware.
7673 *
7674 * returns - TRUE when the mode is IAMT or FALSE.
7675 ****************************************************************************/
7676boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007677e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007678{
7679 uint32_t fwsm;
7680
7681 fwsm = E1000_READ_REG(hw, FWSM);
7682
Auke Kokcd94dd02006-06-27 09:08:22 -07007683 if (hw->mac_type == e1000_ich8lan) {
7684 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7685 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7686 return TRUE;
7687 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7688 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007689 return TRUE;
7690
7691 return FALSE;
7692}
7693
7694
7695/*****************************************************************************
7696 * This function writes the dhcp info .
7697 ****************************************************************************/
7698int32_t
7699e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007700 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007701{
7702 int32_t ret_val;
7703 struct e1000_host_mng_command_header hdr;
7704
7705 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7706 hdr.command_length = length;
7707 hdr.reserved1 = 0;
7708 hdr.reserved2 = 0;
7709 hdr.checksum = 0;
7710
7711 ret_val = e1000_mng_enable_host_if(hw);
7712 if (ret_val == E1000_SUCCESS) {
7713 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7714 &(hdr.checksum));
7715 if (ret_val == E1000_SUCCESS) {
7716 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7717 if (ret_val == E1000_SUCCESS)
7718 ret_val = e1000_mng_write_commit(hw);
7719 }
7720 }
7721 return ret_val;
7722}
7723
7724
7725/*****************************************************************************
7726 * This function calculates the checksum.
7727 *
7728 * returns - checksum of buffer contents.
7729 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007730static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007731e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7732{
7733 uint8_t sum = 0;
7734 uint32_t i;
7735
7736 if (!buffer)
7737 return 0;
7738
7739 for (i=0; i < length; i++)
7740 sum += buffer[i];
7741
7742 return (uint8_t) (0 - sum);
7743}
7744
7745/*****************************************************************************
7746 * This function checks whether tx pkt filtering needs to be enabled or not.
7747 *
7748 * returns - TRUE for packet filtering or FALSE.
7749 ****************************************************************************/
7750boolean_t
7751e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7752{
7753 /* called in init as well as watchdog timer functions */
7754
7755 int32_t ret_val, checksum;
7756 boolean_t tx_filter = FALSE;
7757 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7758 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7759
7760 if (e1000_check_mng_mode(hw)) {
7761 ret_val = e1000_mng_enable_host_if(hw);
7762 if (ret_val == E1000_SUCCESS) {
7763 ret_val = e1000_host_if_read_cookie(hw, buffer);
7764 if (ret_val == E1000_SUCCESS) {
7765 checksum = hdr->checksum;
7766 hdr->checksum = 0;
7767 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7768 checksum == e1000_calculate_mng_checksum((char *)buffer,
7769 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7770 if (hdr->status &
7771 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7772 tx_filter = TRUE;
7773 } else
7774 tx_filter = TRUE;
7775 } else
7776 tx_filter = TRUE;
7777 }
7778 }
7779
7780 hw->tx_pkt_filtering = tx_filter;
7781 return tx_filter;
7782}
7783
7784/******************************************************************************
7785 * Verifies the hardware needs to allow ARPs to be processed by the host
7786 *
7787 * hw - Struct containing variables accessed by shared code
7788 *
7789 * returns: - TRUE/FALSE
7790 *
7791 *****************************************************************************/
7792uint32_t
7793e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7794{
7795 uint32_t manc;
7796 uint32_t fwsm, factps;
7797
7798 if (hw->asf_firmware_present) {
7799 manc = E1000_READ_REG(hw, MANC);
7800
7801 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7802 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7803 return FALSE;
7804 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7805 fwsm = E1000_READ_REG(hw, FWSM);
7806 factps = E1000_READ_REG(hw, FACTPS);
7807
7808 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7809 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7810 (factps & E1000_FACTPS_MNGCG))
7811 return TRUE;
7812 } else
7813 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7814 return TRUE;
7815 }
7816 return FALSE;
7817}
7818
Linus Torvalds1da177e2005-04-16 15:20:36 -07007819static int32_t
7820e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7821{
7822 int32_t ret_val;
7823 uint16_t mii_status_reg;
7824 uint16_t i;
7825
7826 /* Polarity reversal workaround for forced 10F/10H links. */
7827
7828 /* Disable the transmitter on the PHY */
7829
7830 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007831 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007832 return ret_val;
7833 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007834 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007835 return ret_val;
7836
7837 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007838 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007839 return ret_val;
7840
7841 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007842 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007843 /* Read the MII Status Register and wait for Link Status bit
7844 * to be clear.
7845 */
7846
7847 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007848 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007849 return ret_val;
7850
7851 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007852 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007853 return ret_val;
7854
Auke Kok8fc897b2006-08-28 14:56:16 -07007855 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007856 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007857 }
7858
7859 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007860 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007861
7862 /* Now we will re-enable th transmitter on the PHY */
7863
7864 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007865 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007866 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007867 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007868 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007869 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007870 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007871 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007872 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007873 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007874 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007875 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007876 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007877 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007878 return ret_val;
7879
7880 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007881 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007882 return ret_val;
7883
7884 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007885 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007886 /* Read the MII Status Register and wait for Link Status bit
7887 * to be set.
7888 */
7889
7890 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007891 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007892 return ret_val;
7893
7894 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007895 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007896 return ret_val;
7897
Auke Kok8fc897b2006-08-28 14:56:16 -07007898 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007899 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007900 }
7901 return E1000_SUCCESS;
7902}
7903
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007904/***************************************************************************
7905 *
7906 * Disables PCI-Express master access.
7907 *
7908 * hw: Struct containing variables accessed by shared code
7909 *
7910 * returns: - none.
7911 *
7912 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007913static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007914e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7915{
7916 uint32_t ctrl;
7917
7918 DEBUGFUNC("e1000_set_pci_express_master_disable");
7919
7920 if (hw->bus_type != e1000_bus_type_pci_express)
7921 return;
7922
7923 ctrl = E1000_READ_REG(hw, CTRL);
7924 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7925 E1000_WRITE_REG(hw, CTRL, ctrl);
7926}
7927
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007928/*******************************************************************************
7929 *
7930 * Disables PCI-Express master access and verifies there are no pending requests
7931 *
7932 * hw: Struct containing variables accessed by shared code
7933 *
7934 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7935 * caused the master requests to be disabled.
7936 * E1000_SUCCESS master requests disabled.
7937 *
7938 ******************************************************************************/
7939int32_t
7940e1000_disable_pciex_master(struct e1000_hw *hw)
7941{
7942 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7943
7944 DEBUGFUNC("e1000_disable_pciex_master");
7945
7946 if (hw->bus_type != e1000_bus_type_pci_express)
7947 return E1000_SUCCESS;
7948
7949 e1000_set_pci_express_master_disable(hw);
7950
Auke Kok8fc897b2006-08-28 14:56:16 -07007951 while (timeout) {
7952 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007953 break;
7954 else
7955 udelay(100);
7956 timeout--;
7957 }
7958
Auke Kok8fc897b2006-08-28 14:56:16 -07007959 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007960 DEBUGOUT("Master requests are pending.\n");
7961 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7962 }
7963
7964 return E1000_SUCCESS;
7965}
7966
7967/*******************************************************************************
7968 *
7969 * Check for EEPROM Auto Read bit done.
7970 *
7971 * hw: Struct containing variables accessed by shared code
7972 *
7973 * returns: - E1000_ERR_RESET if fail to reset MAC
7974 * E1000_SUCCESS at any other case.
7975 *
7976 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007977static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007978e1000_get_auto_rd_done(struct e1000_hw *hw)
7979{
7980 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7981
7982 DEBUGFUNC("e1000_get_auto_rd_done");
7983
7984 switch (hw->mac_type) {
7985 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007986 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007987 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007988 case e1000_82571:
7989 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007990 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007991 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07007992 case e1000_ich8lan:
7993 while (timeout) {
7994 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
7995 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007996 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007997 timeout--;
7998 }
7999
Auke Kok8fc897b2006-08-28 14:56:16 -07008000 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008001 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8002 return -E1000_ERR_RESET;
8003 }
8004 break;
8005 }
8006
Jeff Kirsherfd803242005-12-13 00:06:22 -05008007 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8008 * Need to wait for PHY configuration completion before accessing NVM
8009 * and PHY. */
8010 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008011 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008012
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008013 return E1000_SUCCESS;
8014}
8015
8016/***************************************************************************
8017 * Checks if the PHY configuration is done
8018 *
8019 * hw: Struct containing variables accessed by shared code
8020 *
8021 * returns: - E1000_ERR_RESET if fail to reset MAC
8022 * E1000_SUCCESS at any other case.
8023 *
8024 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008025static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008026e1000_get_phy_cfg_done(struct e1000_hw *hw)
8027{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008028 int32_t timeout = PHY_CFG_TIMEOUT;
8029 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8030
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008031 DEBUGFUNC("e1000_get_phy_cfg_done");
8032
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008033 switch (hw->mac_type) {
8034 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008035 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008036 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008037 case e1000_80003es2lan:
8038 /* Separate *_CFG_DONE_* bit for each port */
8039 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8040 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8041 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008042 case e1000_82571:
8043 case e1000_82572:
8044 while (timeout) {
8045 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8046 break;
8047 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008048 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008049 timeout--;
8050 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008051 if (!timeout) {
8052 DEBUGOUT("MNG configuration cycle has not completed.\n");
8053 return -E1000_ERR_RESET;
8054 }
8055 break;
8056 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008057
8058 return E1000_SUCCESS;
8059}
8060
8061/***************************************************************************
8062 *
8063 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8064 * adapter or Eeprom access.
8065 *
8066 * hw: Struct containing variables accessed by shared code
8067 *
8068 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8069 * E1000_SUCCESS at any other case.
8070 *
8071 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008072static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008073e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8074{
8075 int32_t timeout;
8076 uint32_t swsm;
8077
8078 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8079
Auke Kok8fc897b2006-08-28 14:56:16 -07008080 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008081 return E1000_SUCCESS;
8082
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008083 if (hw->mac_type == e1000_80003es2lan) {
8084 /* Get the SW semaphore. */
8085 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8086 return -E1000_ERR_EEPROM;
8087 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008088
8089 /* Get the FW semaphore. */
8090 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008091 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008092 swsm = E1000_READ_REG(hw, SWSM);
8093 swsm |= E1000_SWSM_SWESMBI;
8094 E1000_WRITE_REG(hw, SWSM, swsm);
8095 /* if we managed to set the bit we got the semaphore. */
8096 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008097 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008098 break;
8099
8100 udelay(50);
8101 timeout--;
8102 }
8103
Auke Kok8fc897b2006-08-28 14:56:16 -07008104 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008105 /* Release semaphores */
8106 e1000_put_hw_eeprom_semaphore(hw);
8107 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8108 return -E1000_ERR_EEPROM;
8109 }
8110
8111 return E1000_SUCCESS;
8112}
8113
8114/***************************************************************************
8115 * This function clears HW semaphore bits.
8116 *
8117 * hw: Struct containing variables accessed by shared code
8118 *
8119 * returns: - None.
8120 *
8121 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008122static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008123e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8124{
8125 uint32_t swsm;
8126
8127 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8128
Auke Kok8fc897b2006-08-28 14:56:16 -07008129 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008130 return;
8131
8132 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008133 if (hw->mac_type == e1000_80003es2lan) {
8134 /* Release both semaphores. */
8135 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8136 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008137 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008138 E1000_WRITE_REG(hw, SWSM, swsm);
8139}
8140
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008141/***************************************************************************
8142 *
8143 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8144 *
8145 * hw: Struct containing variables accessed by shared code
8146 *
8147 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8148 * E1000_SUCCESS at any other case.
8149 *
8150 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008151static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008152e1000_get_software_semaphore(struct e1000_hw *hw)
8153{
8154 int32_t timeout = hw->eeprom.word_size + 1;
8155 uint32_t swsm;
8156
8157 DEBUGFUNC("e1000_get_software_semaphore");
8158
Nicholas Nunley35574762006-09-27 12:53:34 -07008159 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008160 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008161 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008162
Auke Kok8fc897b2006-08-28 14:56:16 -07008163 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008164 swsm = E1000_READ_REG(hw, SWSM);
8165 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008166 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008167 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008168 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008169 timeout--;
8170 }
8171
Auke Kok8fc897b2006-08-28 14:56:16 -07008172 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008173 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8174 return -E1000_ERR_RESET;
8175 }
8176
8177 return E1000_SUCCESS;
8178}
8179
8180/***************************************************************************
8181 *
8182 * Release semaphore bit (SMBI).
8183 *
8184 * hw: Struct containing variables accessed by shared code
8185 *
8186 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008187static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008188e1000_release_software_semaphore(struct e1000_hw *hw)
8189{
8190 uint32_t swsm;
8191
8192 DEBUGFUNC("e1000_release_software_semaphore");
8193
Nicholas Nunley35574762006-09-27 12:53:34 -07008194 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008195 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008196 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008197
8198 swsm = E1000_READ_REG(hw, SWSM);
8199 /* Release the SW semaphores.*/
8200 swsm &= ~E1000_SWSM_SMBI;
8201 E1000_WRITE_REG(hw, SWSM, swsm);
8202}
8203
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008204/******************************************************************************
8205 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8206 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8207 * the caller to figure out how to deal with it.
8208 *
8209 * hw - Struct containing variables accessed by shared code
8210 *
8211 * returns: - E1000_BLK_PHY_RESET
8212 * E1000_SUCCESS
8213 *
8214 *****************************************************************************/
8215int32_t
8216e1000_check_phy_reset_block(struct e1000_hw *hw)
8217{
8218 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008219 uint32_t fwsm = 0;
8220
8221 if (hw->mac_type == e1000_ich8lan) {
8222 fwsm = E1000_READ_REG(hw, FWSM);
8223 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8224 : E1000_BLK_PHY_RESET;
8225 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008226
8227 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008228 manc = E1000_READ_REG(hw, MANC);
8229 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008230 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008231}
8232
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008233static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008234e1000_arc_subsystem_valid(struct e1000_hw *hw)
8235{
8236 uint32_t fwsm;
8237
8238 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8239 * may not be provided a DMA clock when no manageability features are
8240 * enabled. We do not want to perform any reads/writes to these registers
8241 * if this is the case. We read FWSM to determine the manageability mode.
8242 */
8243 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008244 case e1000_82571:
8245 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008246 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008247 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008248 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008249 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008250 return TRUE;
8251 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008252 case e1000_ich8lan:
8253 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008254 default:
8255 break;
8256 }
8257 return FALSE;
8258}
8259
8260
Auke Kokd37ea5d2006-06-27 09:08:17 -07008261/******************************************************************************
8262 * Configure PCI-Ex no-snoop
8263 *
8264 * hw - Struct containing variables accessed by shared code.
8265 * no_snoop - Bitmap of no-snoop events.
8266 *
8267 * returns: E1000_SUCCESS
8268 *
8269 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008270static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008271e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8272{
8273 uint32_t gcr_reg = 0;
8274
8275 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8276
8277 if (hw->bus_type == e1000_bus_type_unknown)
8278 e1000_get_bus_info(hw);
8279
8280 if (hw->bus_type != e1000_bus_type_pci_express)
8281 return E1000_SUCCESS;
8282
8283 if (no_snoop) {
8284 gcr_reg = E1000_READ_REG(hw, GCR);
8285 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8286 gcr_reg |= no_snoop;
8287 E1000_WRITE_REG(hw, GCR, gcr_reg);
8288 }
8289 if (hw->mac_type == e1000_ich8lan) {
8290 uint32_t ctrl_ext;
8291
8292 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8293
8294 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8295 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8296 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8297 }
8298
8299 return E1000_SUCCESS;
8300}
8301
8302/***************************************************************************
8303 *
8304 * Get software semaphore FLAG bit (SWFLAG).
8305 * SWFLAG is used to synchronize the access to all shared resource between
8306 * SW, FW and HW.
8307 *
8308 * hw: Struct containing variables accessed by shared code
8309 *
8310 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008311static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008312e1000_get_software_flag(struct e1000_hw *hw)
8313{
8314 int32_t timeout = PHY_CFG_TIMEOUT;
8315 uint32_t extcnf_ctrl;
8316
8317 DEBUGFUNC("e1000_get_software_flag");
8318
8319 if (hw->mac_type == e1000_ich8lan) {
8320 while (timeout) {
8321 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8322 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8323 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8324
8325 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8326 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8327 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008328 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008329 timeout--;
8330 }
8331
8332 if (!timeout) {
8333 DEBUGOUT("FW or HW locks the resource too long.\n");
8334 return -E1000_ERR_CONFIG;
8335 }
8336 }
8337
8338 return E1000_SUCCESS;
8339}
8340
8341/***************************************************************************
8342 *
8343 * Release software semaphore FLAG bit (SWFLAG).
8344 * SWFLAG is used to synchronize the access to all shared resource between
8345 * SW, FW and HW.
8346 *
8347 * hw: Struct containing variables accessed by shared code
8348 *
8349 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008350static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008351e1000_release_software_flag(struct e1000_hw *hw)
8352{
8353 uint32_t extcnf_ctrl;
8354
8355 DEBUGFUNC("e1000_release_software_flag");
8356
8357 if (hw->mac_type == e1000_ich8lan) {
8358 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8359 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8360 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8361 }
8362
8363 return;
8364}
8365
Auke Kokd37ea5d2006-06-27 09:08:17 -07008366/******************************************************************************
8367 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8368 * register.
8369 *
8370 * hw - Struct containing variables accessed by shared code
8371 * offset - offset of word in the EEPROM to read
8372 * data - word read from the EEPROM
8373 * words - number of words to read
8374 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008375static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008376e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8377 uint16_t *data)
8378{
8379 int32_t error = E1000_SUCCESS;
8380 uint32_t flash_bank = 0;
8381 uint32_t act_offset = 0;
8382 uint32_t bank_offset = 0;
8383 uint16_t word = 0;
8384 uint16_t i = 0;
8385
8386 /* We need to know which is the valid flash bank. In the event
8387 * that we didn't allocate eeprom_shadow_ram, we may not be
8388 * managing flash_bank. So it cannot be trusted and needs
8389 * to be updated with each read.
8390 */
8391 /* Value of bit 22 corresponds to the flash bank we're on. */
8392 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8393
8394 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8395 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8396
8397 error = e1000_get_software_flag(hw);
8398 if (error != E1000_SUCCESS)
8399 return error;
8400
8401 for (i = 0; i < words; i++) {
8402 if (hw->eeprom_shadow_ram != NULL &&
8403 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8404 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8405 } else {
8406 /* The NVM part needs a byte offset, hence * 2 */
8407 act_offset = bank_offset + ((offset + i) * 2);
8408 error = e1000_read_ich8_word(hw, act_offset, &word);
8409 if (error != E1000_SUCCESS)
8410 break;
8411 data[i] = word;
8412 }
8413 }
8414
8415 e1000_release_software_flag(hw);
8416
8417 return error;
8418}
8419
8420/******************************************************************************
8421 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8422 * register. Actually, writes are written to the shadow ram cache in the hw
8423 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8424 * the NVM, which occurs when the NVM checksum is updated.
8425 *
8426 * hw - Struct containing variables accessed by shared code
8427 * offset - offset of word in the EEPROM to write
8428 * words - number of words to write
8429 * data - words to write to the EEPROM
8430 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008431static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008432e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8433 uint16_t *data)
8434{
8435 uint32_t i = 0;
8436 int32_t error = E1000_SUCCESS;
8437
8438 error = e1000_get_software_flag(hw);
8439 if (error != E1000_SUCCESS)
8440 return error;
8441
8442 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8443 * allocated. Subsequent reads to the modified words are read from
8444 * this cached structure as well. Writes will only go into this
8445 * cached structure unless it's followed by a call to
8446 * e1000_update_eeprom_checksum() where it will commit the changes
8447 * and clear the "modified" field.
8448 */
8449 if (hw->eeprom_shadow_ram != NULL) {
8450 for (i = 0; i < words; i++) {
8451 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8452 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8453 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8454 } else {
8455 error = -E1000_ERR_EEPROM;
8456 break;
8457 }
8458 }
8459 } else {
8460 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8461 * as they don't perform any NVM writes. An attempt in doing so
8462 * will result in this error.
8463 */
8464 error = -E1000_ERR_EEPROM;
8465 }
8466
8467 e1000_release_software_flag(hw);
8468
8469 return error;
8470}
8471
8472/******************************************************************************
8473 * This function does initial flash setup so that a new read/write/erase cycle
8474 * can be started.
8475 *
8476 * hw - The pointer to the hw structure
8477 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008478static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008479e1000_ich8_cycle_init(struct e1000_hw *hw)
8480{
8481 union ich8_hws_flash_status hsfsts;
8482 int32_t error = E1000_ERR_EEPROM;
8483 int32_t i = 0;
8484
8485 DEBUGFUNC("e1000_ich8_cycle_init");
8486
8487 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8488
8489 /* May be check the Flash Des Valid bit in Hw status */
8490 if (hsfsts.hsf_status.fldesvalid == 0) {
8491 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8492 return error;
8493 }
8494
8495 /* Clear FCERR in Hw status by writing 1 */
8496 /* Clear DAEL in Hw status by writing a 1 */
8497 hsfsts.hsf_status.flcerr = 1;
8498 hsfsts.hsf_status.dael = 1;
8499
8500 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8501
8502 /* Either we should have a hardware SPI cycle in progress bit to check
8503 * against, in order to start a new cycle or FDONE bit should be changed
8504 * in the hardware so that it is 1 after harware reset, which can then be
8505 * used as an indication whether a cycle is in progress or has been
8506 * completed .. we should also have some software semaphore mechanism to
8507 * guard FDONE or the cycle in progress bit so that two threads access to
8508 * those bits can be sequentiallized or a way so that 2 threads dont
8509 * start the cycle at the same time */
8510
8511 if (hsfsts.hsf_status.flcinprog == 0) {
8512 /* There is no cycle running at present, so we can start a cycle */
8513 /* Begin by setting Flash Cycle Done. */
8514 hsfsts.hsf_status.flcdone = 1;
8515 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8516 error = E1000_SUCCESS;
8517 } else {
8518 /* otherwise poll for sometime so the current cycle has a chance
8519 * to end before giving up. */
8520 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8521 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8522 if (hsfsts.hsf_status.flcinprog == 0) {
8523 error = E1000_SUCCESS;
8524 break;
8525 }
8526 udelay(1);
8527 }
8528 if (error == E1000_SUCCESS) {
8529 /* Successful in waiting for previous cycle to timeout,
8530 * now set the Flash Cycle Done. */
8531 hsfsts.hsf_status.flcdone = 1;
8532 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8533 } else {
8534 DEBUGOUT("Flash controller busy, cannot get access");
8535 }
8536 }
8537 return error;
8538}
8539
8540/******************************************************************************
8541 * This function starts a flash cycle and waits for its completion
8542 *
8543 * hw - The pointer to the hw structure
8544 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008545static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008546e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8547{
8548 union ich8_hws_flash_ctrl hsflctl;
8549 union ich8_hws_flash_status hsfsts;
8550 int32_t error = E1000_ERR_EEPROM;
8551 uint32_t i = 0;
8552
8553 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8554 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8555 hsflctl.hsf_ctrl.flcgo = 1;
8556 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8557
8558 /* wait till FDONE bit is set to 1 */
8559 do {
8560 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8561 if (hsfsts.hsf_status.flcdone == 1)
8562 break;
8563 udelay(1);
8564 i++;
8565 } while (i < timeout);
8566 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8567 error = E1000_SUCCESS;
8568 }
8569 return error;
8570}
8571
8572/******************************************************************************
8573 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8574 *
8575 * hw - The pointer to the hw structure
8576 * index - The index of the byte or word to read.
8577 * size - Size of data to read, 1=byte 2=word
8578 * data - Pointer to the word to store the value read.
8579 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008580static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008581e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8582 uint32_t size, uint16_t* data)
8583{
8584 union ich8_hws_flash_status hsfsts;
8585 union ich8_hws_flash_ctrl hsflctl;
8586 uint32_t flash_linear_address;
8587 uint32_t flash_data = 0;
8588 int32_t error = -E1000_ERR_EEPROM;
8589 int32_t count = 0;
8590
8591 DEBUGFUNC("e1000_read_ich8_data");
8592
8593 if (size < 1 || size > 2 || data == 0x0 ||
8594 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8595 return error;
8596
8597 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8598 hw->flash_base_addr;
8599
8600 do {
8601 udelay(1);
8602 /* Steps */
8603 error = e1000_ich8_cycle_init(hw);
8604 if (error != E1000_SUCCESS)
8605 break;
8606
8607 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8608 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8609 hsflctl.hsf_ctrl.fldbcount = size - 1;
8610 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8611 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8612
8613 /* Write the last 24 bits of index into Flash Linear address field in
8614 * Flash Address */
8615 /* TODO: TBD maybe check the index against the size of flash */
8616
8617 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8618
8619 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8620
8621 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8622 * sequence a few more times, else read in (shift in) the Flash Data0,
8623 * the order is least significant byte first msb to lsb */
8624 if (error == E1000_SUCCESS) {
8625 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8626 if (size == 1) {
8627 *data = (uint8_t)(flash_data & 0x000000FF);
8628 } else if (size == 2) {
8629 *data = (uint16_t)(flash_data & 0x0000FFFF);
8630 }
8631 break;
8632 } else {
8633 /* If we've gotten here, then things are probably completely hosed,
8634 * but if the error condition is detected, it won't hurt to give
8635 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8636 */
8637 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8638 if (hsfsts.hsf_status.flcerr == 1) {
8639 /* Repeat for some time before giving up. */
8640 continue;
8641 } else if (hsfsts.hsf_status.flcdone == 0) {
8642 DEBUGOUT("Timeout error - flash cycle did not complete.");
8643 break;
8644 }
8645 }
8646 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8647
8648 return error;
8649}
8650
8651/******************************************************************************
8652 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8653 *
8654 * hw - The pointer to the hw structure
8655 * index - The index of the byte/word to read.
8656 * size - Size of data to read, 1=byte 2=word
8657 * data - The byte(s) to write to the NVM.
8658 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008659static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008660e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8661 uint16_t data)
8662{
8663 union ich8_hws_flash_status hsfsts;
8664 union ich8_hws_flash_ctrl hsflctl;
8665 uint32_t flash_linear_address;
8666 uint32_t flash_data = 0;
8667 int32_t error = -E1000_ERR_EEPROM;
8668 int32_t count = 0;
8669
8670 DEBUGFUNC("e1000_write_ich8_data");
8671
8672 if (size < 1 || size > 2 || data > size * 0xff ||
8673 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8674 return error;
8675
8676 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8677 hw->flash_base_addr;
8678
8679 do {
8680 udelay(1);
8681 /* Steps */
8682 error = e1000_ich8_cycle_init(hw);
8683 if (error != E1000_SUCCESS)
8684 break;
8685
8686 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8687 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8688 hsflctl.hsf_ctrl.fldbcount = size -1;
8689 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8690 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8691
8692 /* Write the last 24 bits of index into Flash Linear address field in
8693 * Flash Address */
8694 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8695
8696 if (size == 1)
8697 flash_data = (uint32_t)data & 0x00FF;
8698 else
8699 flash_data = (uint32_t)data;
8700
8701 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8702
8703 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8704 * sequence a few more times else done */
8705 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8706 if (error == E1000_SUCCESS) {
8707 break;
8708 } else {
8709 /* If we're here, then things are most likely completely hosed,
8710 * but if the error condition is detected, it won't hurt to give
8711 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8712 */
8713 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8714 if (hsfsts.hsf_status.flcerr == 1) {
8715 /* Repeat for some time before giving up. */
8716 continue;
8717 } else if (hsfsts.hsf_status.flcdone == 0) {
8718 DEBUGOUT("Timeout error - flash cycle did not complete.");
8719 break;
8720 }
8721 }
8722 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8723
8724 return error;
8725}
8726
8727/******************************************************************************
8728 * Reads a single byte from the NVM using the ICH8 flash access registers.
8729 *
8730 * hw - pointer to e1000_hw structure
8731 * index - The index of the byte to read.
8732 * data - Pointer to a byte to store the value read.
8733 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008734static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008735e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8736{
8737 int32_t status = E1000_SUCCESS;
8738 uint16_t word = 0;
8739
8740 status = e1000_read_ich8_data(hw, index, 1, &word);
8741 if (status == E1000_SUCCESS) {
8742 *data = (uint8_t)word;
8743 }
8744
8745 return status;
8746}
8747
8748/******************************************************************************
8749 * Writes a single byte to the NVM using the ICH8 flash access registers.
8750 * Performs verification by reading back the value and then going through
8751 * a retry algorithm before giving up.
8752 *
8753 * hw - pointer to e1000_hw structure
8754 * index - The index of the byte to write.
8755 * byte - The byte to write to the NVM.
8756 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008757static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008758e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8759{
8760 int32_t error = E1000_SUCCESS;
8761 int32_t program_retries;
8762 uint8_t temp_byte;
8763
8764 e1000_write_ich8_byte(hw, index, byte);
8765 udelay(100);
8766
8767 for (program_retries = 0; program_retries < 100; program_retries++) {
8768 e1000_read_ich8_byte(hw, index, &temp_byte);
8769 if (temp_byte == byte)
8770 break;
8771 udelay(10);
8772 e1000_write_ich8_byte(hw, index, byte);
8773 udelay(100);
8774 }
8775 if (program_retries == 100)
8776 error = E1000_ERR_EEPROM;
8777
8778 return error;
8779}
8780
8781/******************************************************************************
8782 * Writes a single byte to the NVM using the ICH8 flash access registers.
8783 *
8784 * hw - pointer to e1000_hw structure
8785 * index - The index of the byte to read.
8786 * data - The byte to write to the NVM.
8787 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008788static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008789e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8790{
8791 int32_t status = E1000_SUCCESS;
8792 uint16_t word = (uint16_t)data;
8793
8794 status = e1000_write_ich8_data(hw, index, 1, word);
8795
8796 return status;
8797}
8798
8799/******************************************************************************
8800 * Reads a word from the NVM using the ICH8 flash access registers.
8801 *
8802 * hw - pointer to e1000_hw structure
8803 * index - The starting byte index of the word to read.
8804 * data - Pointer to a word to store the value read.
8805 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008806static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008807e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8808{
8809 int32_t status = E1000_SUCCESS;
8810 status = e1000_read_ich8_data(hw, index, 2, data);
8811 return status;
8812}
8813
8814/******************************************************************************
8815 * Writes a word to the NVM using the ICH8 flash access registers.
8816 *
8817 * hw - pointer to e1000_hw structure
8818 * index - The starting byte index of the word to read.
8819 * data - The word to write to the NVM.
8820 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008821#if 0
Auke Kokd37ea5d2006-06-27 09:08:17 -07008822int32_t
8823e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8824{
8825 int32_t status = E1000_SUCCESS;
8826 status = e1000_write_ich8_data(hw, index, 2, data);
8827 return status;
8828}
Adrian Bunke4c780b2006-08-14 23:00:10 -07008829#endif /* 0 */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008830
8831/******************************************************************************
8832 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8833 * segment N is 4096 * N + flash_reg_addr.
8834 *
8835 * hw - pointer to e1000_hw structure
8836 * segment - 0 for first segment, 1 for second segment, etc.
8837 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008838static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008839e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8840{
8841 union ich8_hws_flash_status hsfsts;
8842 union ich8_hws_flash_ctrl hsflctl;
8843 uint32_t flash_linear_address;
8844 int32_t count = 0;
8845 int32_t error = E1000_ERR_EEPROM;
8846 int32_t iteration, seg_size;
8847 int32_t sector_size;
8848 int32_t j = 0;
8849 int32_t error_flag = 0;
8850
8851 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8852
8853 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8854 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8855 * consecutive sectors. The start index for the nth Hw sector can be
8856 * calculated as = segment * 4096 + n * 256
8857 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8858 * The start index for the nth Hw sector can be calculated
8859 * as = segment * 4096
8860 * 10: Error condition
8861 * 11: The Hw sector size is much bigger than the size asked to
8862 * erase...error condition */
8863 if (hsfsts.hsf_status.berasesz == 0x0) {
8864 /* Hw sector size 256 */
8865 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256;
8866 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8867 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8868 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K;
8869 iteration = 1;
8870 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8871 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K;
8872 iteration = 1;
8873 } else {
8874 return error;
8875 }
8876
8877 for (j = 0; j < iteration ; j++) {
8878 do {
8879 count++;
8880 /* Steps */
8881 error = e1000_ich8_cycle_init(hw);
8882 if (error != E1000_SUCCESS) {
8883 error_flag = 1;
8884 break;
8885 }
8886
8887 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8888 * Control */
8889 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8890 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8891 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8892
8893 /* Write the last 24 bits of an index within the block into Flash
8894 * Linear address field in Flash Address. This probably needs to
8895 * be calculated here based off the on-chip segment size and the
8896 * software segment size assumed (4K) */
8897 /* TBD */
8898 flash_linear_address = segment * sector_size + j * seg_size;
8899 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8900 flash_linear_address += hw->flash_base_addr;
8901
8902 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8903
8904 error = e1000_ich8_flash_cycle(hw, 1000000);
8905 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8906 * sequence a few more times else Done */
8907 if (error == E1000_SUCCESS) {
8908 break;
8909 } else {
8910 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8911 if (hsfsts.hsf_status.flcerr == 1) {
8912 /* repeat for some time before giving up */
8913 continue;
8914 } else if (hsfsts.hsf_status.flcdone == 0) {
8915 error_flag = 1;
8916 break;
8917 }
8918 }
8919 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8920 if (error_flag == 1)
8921 break;
8922 }
8923 if (error_flag != 1)
8924 error = E1000_SUCCESS;
8925 return error;
8926}
8927
Adrian Bunke4c780b2006-08-14 23:00:10 -07008928static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008929e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8930 uint32_t cnf_base_addr, uint32_t cnf_size)
8931{
8932 uint32_t ret_val = E1000_SUCCESS;
8933 uint16_t word_addr, reg_data, reg_addr;
8934 uint16_t i;
8935
8936 /* cnf_base_addr is in DWORD */
8937 word_addr = (uint16_t)(cnf_base_addr << 1);
8938
8939 /* cnf_size is returned in size of dwords */
8940 for (i = 0; i < cnf_size; i++) {
8941 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8942 if (ret_val)
8943 return ret_val;
8944
8945 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8946 if (ret_val)
8947 return ret_val;
8948
8949 ret_val = e1000_get_software_flag(hw);
8950 if (ret_val != E1000_SUCCESS)
8951 return ret_val;
8952
8953 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8954
8955 e1000_release_software_flag(hw);
8956 }
8957
8958 return ret_val;
8959}
8960
8961
Adrian Bunke4c780b2006-08-14 23:00:10 -07008962static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008963e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8964{
8965 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8966
8967 if (hw->phy_type != e1000_phy_igp_3)
8968 return E1000_SUCCESS;
8969
8970 /* Check if SW needs configure the PHY */
8971 reg_data = E1000_READ_REG(hw, FEXTNVM);
8972 if (!(reg_data & FEXTNVM_SW_CONFIG))
8973 return E1000_SUCCESS;
8974
8975 /* Wait for basic configuration completes before proceeding*/
8976 loop = 0;
8977 do {
8978 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8979 udelay(100);
8980 loop++;
8981 } while ((!reg_data) && (loop < 50));
8982
8983 /* Clear the Init Done bit for the next init event */
8984 reg_data = E1000_READ_REG(hw, STATUS);
8985 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
8986 E1000_WRITE_REG(hw, STATUS, reg_data);
8987
8988 /* Make sure HW does not configure LCD from PHY extended configuration
8989 before SW configuration */
8990 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
8991 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
8992 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
8993 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
8994 cnf_size >>= 16;
8995 if (cnf_size) {
8996 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
8997 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
8998 /* cnf_base_addr is in DWORD */
8999 cnf_base_addr >>= 16;
9000
9001 /* Configure LCD from extended configuration region. */
9002 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9003 cnf_size);
9004 if (ret_val)
9005 return ret_val;
9006 }
9007 }
9008
9009 return E1000_SUCCESS;
9010}
9011
9012
Malli Chilakala2d7edb92005-04-28 19:43:52 -07009013