blob: 0bb9dd82d633ad8e21131916ab8caaee281f6d8b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Nicholas Nunley35574762006-09-27 12:53:34 -070036static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
43static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static int32_t e1000_check_downshift(struct e1000_hw *hw);
45static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47static void e1000_clear_vfta(struct e1000_hw *hw);
48static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60static int32_t e1000_id_led_init(struct e1000_hw *hw);
61static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63static void e1000_init_rx_addrs(struct e1000_hw *hw);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -070064static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070065static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86static void e1000_release_software_flag(struct e1000_hw *hw);
87static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94static void e1000_phy_init_script(struct e1000_hw *hw);
95static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
103 uint16_t count);
104static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
110 uint16_t *data);
111static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
115 uint16_t count);
116static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
117 uint16_t phy_data);
118static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
119 uint16_t *phy_data);
120static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122static void e1000_release_eeprom(struct e1000_hw *hw);
123static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700127static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Auke Kokcd94dd02006-06-27 09:08:22 -0700129static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
130 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800131static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* IGP cable length table */
134static const
135uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
144
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700145static const
146uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/******************************************************************************
157 * Set the phy type member in the hw struct.
158 *
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -0700161static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162e1000_set_phy_type(struct e1000_hw *hw)
163{
164 DEBUGFUNC("e1000_set_phy_type");
165
Auke Kok8fc897b2006-08-28 14:56:16 -0700166 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700167 return -E1000_ERR_PHY_TYPE;
168
Auke Kok8fc897b2006-08-28 14:56:16 -0700169 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700173 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 hw->phy_type = e1000_phy_m88;
175 break;
176 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 hw->phy_type = e1000_phy_igp;
182 break;
183 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
186 break;
187 case IFE_E_PHY_ID:
188 case IFE_PLUS_E_PHY_ID:
189 case IFE_C_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
191 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* Fall Through */
198 default:
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
202 }
203
204 return E1000_SUCCESS;
205}
206
207/******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
209 *
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
212static void
213e1000_phy_init_script(struct e1000_hw *hw)
214{
215 uint32_t ret_val;
216 uint16_t phy_saved_data;
217
218 DEBUGFUNC("e1000_phy_init_script");
219
Auke Kok8fc897b2006-08-28 14:56:16 -0700220 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400221 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
226
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
229
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400230 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 e1000_write_phy_reg(hw,0x0000,0x0140);
233
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400234 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Auke Kok8fc897b2006-08-28 14:56:16 -0700236 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 case e1000_82541:
238 case e1000_82547:
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
240
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
242
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
244
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
246
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
248
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
250
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
252
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
254
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
256 break;
257
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
261 break;
262 default:
263 break;
264 }
265
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
267
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400268 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
272
Auke Kok8fc897b2006-08-28 14:56:16 -0700273 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 uint16_t fused, fine, coarse;
275
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
278
Auke Kok8fc897b2006-08-28 14:56:16 -0700279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
281
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
284
Auke Kok8fc897b2006-08-28 14:56:16 -0700285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
290
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
294
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
298 }
299 }
300 }
301}
302
303/******************************************************************************
304 * Set the mac type member in the hw struct.
305 *
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
308int32_t
309e1000_set_mac_type(struct e1000_hw *hw)
310{
311 DEBUGFUNC("e1000_set_mac_type");
312
313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
318 break;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
321 break;
322 default:
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
325 }
326 break;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
330 break;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
336 break;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
343 break;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
347 break;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
352 break;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
357 break;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 hw->mac_type = e1000_82546_rev_3;
365 break;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
Auke Kokcd94dd02006-06-27 09:08:22 -0700368 case E1000_DEV_ID_82541ER_LOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 hw->mac_type = e1000_82541;
370 break;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
376 break;
377 case E1000_DEV_ID_82547EI:
Auke Kokcd94dd02006-06-27 09:08:22 -0700378 case E1000_DEV_ID_82547EI_MOBILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 hw->mac_type = e1000_82547;
380 break;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
383 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokfc2307d2006-11-01 08:47:56 -0800388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400389 hw->mac_type = e1000_82571;
390 break;
391 case E1000_DEV_ID_82572EI_COPPER:
392 case E1000_DEV_ID_82572EI_FIBER:
393 case E1000_DEV_ID_82572EI_SERDES:
Auke Kokcd94dd02006-06-27 09:08:22 -0700394 case E1000_DEV_ID_82572EI:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400395 hw->mac_type = e1000_82572;
396 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700397 case E1000_DEV_ID_82573E:
398 case E1000_DEV_ID_82573E_IAMT:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400399 case E1000_DEV_ID_82573L:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700400 hw->mac_type = e1000_82573;
401 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
406 hw->mac_type = e1000_80003es2lan;
407 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700408 case E1000_DEV_ID_ICH8_IGP_M_AMT:
409 case E1000_DEV_ID_ICH8_IGP_AMT:
410 case E1000_DEV_ID_ICH8_IGP_C:
411 case E1000_DEV_ID_ICH8_IFE:
Auke Kokfc2307d2006-11-01 08:47:56 -0800412 case E1000_DEV_ID_ICH8_IFE_GT:
413 case E1000_DEV_ID_ICH8_IFE_G:
Auke Kokcd94dd02006-06-27 09:08:22 -0700414 case E1000_DEV_ID_ICH8_IGP_M:
415 hw->mac_type = e1000_ich8lan;
416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 default:
418 /* Should never have loaded on this device */
419 return -E1000_ERR_MAC_TYPE;
420 }
421
Auke Kok8fc897b2006-08-28 14:56:16 -0700422 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700423 case e1000_ich8lan:
424 hw->swfwhw_semaphore_present = TRUE;
425 hw->asf_firmware_present = TRUE;
426 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800427 case e1000_80003es2lan:
428 hw->swfw_sync_present = TRUE;
429 /* fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400430 case e1000_82571:
431 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700432 case e1000_82573:
433 hw->eeprom_semaphore_present = TRUE;
434 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 case e1000_82541:
436 case e1000_82547:
437 case e1000_82541_rev_2:
438 case e1000_82547_rev_2:
439 hw->asf_firmware_present = TRUE;
440 break;
441 default:
442 break;
443 }
444
445 return E1000_SUCCESS;
446}
447
448/*****************************************************************************
449 * Set media type and TBI compatibility.
450 *
451 * hw - Struct containing variables accessed by shared code
452 * **************************************************************************/
453void
454e1000_set_media_type(struct e1000_hw *hw)
455{
456 uint32_t status;
457
458 DEBUGFUNC("e1000_set_media_type");
459
Auke Kok8fc897b2006-08-28 14:56:16 -0700460 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 /* tbi_compatibility is only valid on 82543 */
462 hw->tbi_compatibility_en = FALSE;
463 }
464
465 switch (hw->device_id) {
466 case E1000_DEV_ID_82545GM_SERDES:
467 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400468 case E1000_DEV_ID_82571EB_SERDES:
469 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800470 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 hw->media_type = e1000_media_type_internal_serdes;
472 break;
473 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700474 switch (hw->mac_type) {
475 case e1000_82542_rev2_0:
476 case e1000_82542_rev2_1:
477 hw->media_type = e1000_media_type_fiber;
478 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700479 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700480 case e1000_82573:
481 /* The STATUS_TBIMODE bit is reserved or reused for the this
482 * device.
483 */
484 hw->media_type = e1000_media_type_copper;
485 break;
486 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700488 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 hw->media_type = e1000_media_type_fiber;
490 /* tbi_compatibility not valid on fiber */
491 hw->tbi_compatibility_en = FALSE;
492 } else {
493 hw->media_type = e1000_media_type_copper;
494 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700495 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497 }
498}
499
500/******************************************************************************
501 * Reset the transmit and receive units; mask and clear all interrupts.
502 *
503 * hw - Struct containing variables accessed by shared code
504 *****************************************************************************/
505int32_t
506e1000_reset_hw(struct e1000_hw *hw)
507{
508 uint32_t ctrl;
509 uint32_t ctrl_ext;
510 uint32_t icr;
511 uint32_t manc;
512 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700513 uint32_t timeout;
514 uint32_t extcnf_ctrl;
515 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 DEBUGFUNC("e1000_reset_hw");
518
519 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700520 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
522 e1000_pci_clear_mwi(hw);
523 }
524
Auke Kok8fc897b2006-08-28 14:56:16 -0700525 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700526 /* Prevent the PCI-E bus from sticking if there is no TLP connection
527 * on the last TLP read/write transaction when MAC is reset.
528 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700529 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700530 DEBUGOUT("PCI-E Master disable polling has failed.\n");
531 }
532 }
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /* Clear interrupt mask to stop board from generating interrupts */
535 DEBUGOUT("Masking off all interrupts\n");
536 E1000_WRITE_REG(hw, IMC, 0xffffffff);
537
538 /* Disable the Transmit and Receive units. Then delay to allow
539 * any pending transactions to complete before we hit the MAC with
540 * the global reset.
541 */
542 E1000_WRITE_REG(hw, RCTL, 0);
543 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
544 E1000_WRITE_FLUSH(hw);
545
546 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
547 hw->tbi_compatibility_on = FALSE;
548
549 /* Delay to allow any outstanding PCI transactions to complete before
550 * resetting the device
551 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400552 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 ctrl = E1000_READ_REG(hw, CTRL);
555
556 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700557 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700558 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400559 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700562 /* Must acquire the MDIO ownership before MAC reset.
563 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700564 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700565 timeout = 10;
566
567 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
568 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
569
570 do {
571 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
572 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
573
Auke Kok8fc897b2006-08-28 14:56:16 -0700574 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700575 break;
576 else
577 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
578
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400579 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700580 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700581 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700582 }
583
Auke Kokcd94dd02006-06-27 09:08:22 -0700584 /* Workaround for ICH8 bit corruption issue in FIFO memory */
585 if (hw->mac_type == e1000_ich8lan) {
586 /* Set Tx and Rx buffer allocation to 8k apiece. */
587 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
588 /* Set Packet Buffer Size to 16k. */
589 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
590 }
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 /* Issue a global reset to the MAC. This will reset the chip's
593 * transmit, receive, DMA, and link units. It will not effect
594 * the current PCI configuration. The global reset bit is self-
595 * clearing, and should clear within a microsecond.
596 */
597 DEBUGOUT("Issuing a global reset to MAC\n");
598
Auke Kok8fc897b2006-08-28 14:56:16 -0700599 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 case e1000_82544:
601 case e1000_82540:
602 case e1000_82545:
603 case e1000_82546:
604 case e1000_82541:
605 case e1000_82541_rev_2:
606 /* These controllers can't ack the 64-bit write when issuing the
607 * reset, so use IO-mapping as a workaround to issue the reset */
608 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
609 break;
610 case e1000_82545_rev_3:
611 case e1000_82546_rev_3:
612 /* Reset is performed on a shadow of the control register */
613 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
614 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700615 case e1000_ich8lan:
616 if (!hw->phy_reset_disable &&
617 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
618 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
619 * at the same time to make sure the interface between
620 * MAC and the external PHY is reset.
621 */
622 ctrl |= E1000_CTRL_PHY_RST;
623 }
624
625 e1000_get_software_flag(hw);
626 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400627 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700628 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 default:
630 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
631 break;
632 }
633
634 /* After MAC reset, force reload of EEPROM to restore power-on settings to
635 * device. Later controllers reload the EEPROM automatically, so just wait
636 * for reload to complete.
637 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700638 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 case e1000_82542_rev2_0:
640 case e1000_82542_rev2_1:
641 case e1000_82543:
642 case e1000_82544:
643 /* Wait for reset to complete */
644 udelay(10);
645 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
646 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
647 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
648 E1000_WRITE_FLUSH(hw);
649 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400650 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
652 case e1000_82541:
653 case e1000_82541_rev_2:
654 case e1000_82547:
655 case e1000_82547_rev_2:
656 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400657 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700659 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500660 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
661 udelay(10);
662 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
663 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
664 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
665 E1000_WRITE_FLUSH(hw);
666 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700667 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700668 default:
669 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700670 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700671 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700672 return ret_val;
673 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
675
676 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700677 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 manc = E1000_READ_REG(hw, MANC);
679 manc &= ~(E1000_MANC_ARP_EN);
680 E1000_WRITE_REG(hw, MANC, manc);
681 }
682
Auke Kok8fc897b2006-08-28 14:56:16 -0700683 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 e1000_phy_init_script(hw);
685
686 /* Configure activity LED after PHY reset */
687 led_ctrl = E1000_READ_REG(hw, LEDCTL);
688 led_ctrl &= IGP_ACTIVITY_LED_MASK;
689 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
690 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
691 }
692
693 /* Clear interrupt mask to stop board from generating interrupts */
694 DEBUGOUT("Masking off all interrupts\n");
695 E1000_WRITE_REG(hw, IMC, 0xffffffff);
696
697 /* Clear any pending interrupt events. */
698 icr = E1000_READ_REG(hw, ICR);
699
700 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700701 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400702 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 e1000_pci_set_mwi(hw);
704 }
705
Auke Kokcd94dd02006-06-27 09:08:22 -0700706 if (hw->mac_type == e1000_ich8lan) {
707 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
708 kab |= E1000_KABGTXD_BGSQLBIAS;
709 E1000_WRITE_REG(hw, KABGTXD, kab);
710 }
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 return E1000_SUCCESS;
713}
714
715/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700716 *
717 * Initialize a number of hardware-dependent bits
718 *
719 * hw: Struct containing variables accessed by shared code
720 *
721 * This function contains hardware limitation workarounds for PCI-E adapters
722 *
723 *****************************************************************************/
724static void
725e1000_initialize_hardware_bits(struct e1000_hw *hw)
726{
727 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
728 /* Settings common to all PCI-express silicon */
729 uint32_t reg_ctrl, reg_ctrl_ext;
730 uint32_t reg_tarc0, reg_tarc1;
731 uint32_t reg_tctl;
732 uint32_t reg_txdctl, reg_txdctl1;
733
734 /* link autonegotiation/sync workarounds */
735 reg_tarc0 = E1000_READ_REG(hw, TARC0);
736 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
737
738 /* Enable not-done TX descriptor counting */
739 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
740 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
741 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
742 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
743 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
744 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
745
746 switch (hw->mac_type) {
747 case e1000_82571:
748 case e1000_82572:
749 /* Clear PHY TX compatible mode bits */
750 reg_tarc1 = E1000_READ_REG(hw, TARC1);
751 reg_tarc1 &= ~((1 << 30)|(1 << 29));
752
753 /* link autonegotiation/sync workarounds */
754 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
755
756 /* TX ring control fixes */
757 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
758
759 /* Multiple read bit is reversed polarity */
760 reg_tctl = E1000_READ_REG(hw, TCTL);
761 if (reg_tctl & E1000_TCTL_MULR)
762 reg_tarc1 &= ~(1 << 28);
763 else
764 reg_tarc1 |= (1 << 28);
765
766 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
767 break;
768 case e1000_82573:
769 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
770 reg_ctrl_ext &= ~(1 << 23);
771 reg_ctrl_ext |= (1 << 22);
772
773 /* TX byte count fix */
774 reg_ctrl = E1000_READ_REG(hw, CTRL);
775 reg_ctrl &= ~(1 << 29);
776
777 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
778 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
779 break;
780 case e1000_80003es2lan:
781 /* improve small packet performace for fiber/serdes */
782 if ((hw->media_type == e1000_media_type_fiber) ||
783 (hw->media_type == e1000_media_type_internal_serdes)) {
784 reg_tarc0 &= ~(1 << 20);
785 }
786
787 /* Multiple read bit is reversed polarity */
788 reg_tctl = E1000_READ_REG(hw, TCTL);
789 reg_tarc1 = E1000_READ_REG(hw, TARC1);
790 if (reg_tctl & E1000_TCTL_MULR)
791 reg_tarc1 &= ~(1 << 28);
792 else
793 reg_tarc1 |= (1 << 28);
794
795 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
796 break;
797 case e1000_ich8lan:
798 /* Reduce concurrent DMA requests to 3 from 4 */
799 if ((hw->revision_id < 3) ||
800 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
801 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
802 reg_tarc0 |= ((1 << 29)|(1 << 28));
803
804 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
805 reg_ctrl_ext |= (1 << 22);
806 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
807
808 /* workaround TX hang with TSO=on */
809 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
810
811 /* Multiple read bit is reversed polarity */
812 reg_tctl = E1000_READ_REG(hw, TCTL);
813 reg_tarc1 = E1000_READ_REG(hw, TARC1);
814 if (reg_tctl & E1000_TCTL_MULR)
815 reg_tarc1 &= ~(1 << 28);
816 else
817 reg_tarc1 |= (1 << 28);
818
819 /* workaround TX hang with TSO=on */
820 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
821
822 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
823 break;
824 default:
825 break;
826 }
827
828 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
829 }
830}
831
832/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 * Performs basic configuration of the adapter.
834 *
835 * hw - Struct containing variables accessed by shared code
836 *
837 * Assumes that the controller has previously been reset and is in a
838 * post-reset uninitialized state. Initializes the receive address registers,
839 * multicast table, and VLAN filter table. Calls routines to setup link
840 * configuration and flow control settings. Clears all on-chip counters. Leaves
841 * the transmit and receive units disabled and uninitialized.
842 *****************************************************************************/
843int32_t
844e1000_init_hw(struct e1000_hw *hw)
845{
846 uint32_t ctrl;
847 uint32_t i;
848 int32_t ret_val;
849 uint16_t pcix_cmd_word;
850 uint16_t pcix_stat_hi_word;
851 uint16_t cmd_mmrbc;
852 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700853 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800854 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800855 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 DEBUGFUNC("e1000_init_hw");
858
Jeff Kirsher7820d422006-08-16 13:39:00 -0700859 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700860 if ((hw->mac_type == e1000_ich8lan) &&
861 ((hw->revision_id < 3) ||
862 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
863 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
864 reg_data = E1000_READ_REG(hw, STATUS);
865 reg_data &= ~0x80000000;
866 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700867 }
868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 /* Initialize Identification LED */
870 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700871 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 DEBUGOUT("Error Initializing Identification LED\n");
873 return ret_val;
874 }
875
876 /* Set the media type and TBI compatibility */
877 e1000_set_media_type(hw);
878
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700879 /* Must be called after e1000_set_media_type because media_type is used */
880 e1000_initialize_hardware_bits(hw);
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /* Disabling VLAN filtering. */
883 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700884 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
885 if (hw->mac_type != e1000_ich8lan) {
886 if (hw->mac_type < e1000_82545_rev_3)
887 E1000_WRITE_REG(hw, VET, 0);
888 e1000_clear_vfta(hw);
889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700892 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
894 e1000_pci_clear_mwi(hw);
895 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
896 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400897 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
900 /* Setup the receive address. This involves initializing all of the Receive
901 * Address Registers (RARs 0 - 15).
902 */
903 e1000_init_rx_addrs(hw);
904
905 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700906 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 E1000_WRITE_REG(hw, RCTL, 0);
908 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400909 msleep(1);
910 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 e1000_pci_set_mwi(hw);
912 }
913
914 /* Zero out the Multicast HASH table */
915 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700916 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700917 if (hw->mac_type == e1000_ich8lan)
918 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700919 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700921 /* use write flush to prevent Memory Write Block (MWB) from
922 * occuring when accessing our register space */
923 E1000_WRITE_FLUSH(hw);
924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /* Set the PCI priority bit correctly in the CTRL register. This
927 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700928 * gives equal priority to transmits and receives. Valid only on
929 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700931 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 ctrl = E1000_READ_REG(hw, CTRL);
933 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
934 }
935
Auke Kok8fc897b2006-08-28 14:56:16 -0700936 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 case e1000_82545_rev_3:
938 case e1000_82546_rev_3:
939 break;
940 default:
941 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700942 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
944 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
945 &pcix_stat_hi_word);
946 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
947 PCIX_COMMAND_MMRBC_SHIFT;
948 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
949 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700950 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700952 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
954 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
955 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
956 &pcix_cmd_word);
957 }
958 }
959 break;
960 }
961
Auke Kokcd94dd02006-06-27 09:08:22 -0700962 /* More time needed for PHY to initialize */
963 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400964 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 /* Call a subroutine to configure the link and setup flow control. */
967 ret_val = e1000_setup_link(hw);
968
969 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700970 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 ctrl = E1000_READ_REG(hw, TXDCTL);
972 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
973 E1000_WRITE_REG(hw, TXDCTL, ctrl);
974 }
975
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700976 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700977 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700978 }
979
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400980 switch (hw->mac_type) {
981 default:
982 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800983 case e1000_80003es2lan:
984 /* Enable retransmit on late collisions */
985 reg_data = E1000_READ_REG(hw, TCTL);
986 reg_data |= E1000_TCTL_RTLC;
987 E1000_WRITE_REG(hw, TCTL, reg_data);
988
989 /* Configure Gigabit Carry Extend Padding */
990 reg_data = E1000_READ_REG(hw, TCTL_EXT);
991 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
992 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
993 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
994
995 /* Configure Transmit Inter-Packet Gap */
996 reg_data = E1000_READ_REG(hw, TIPG);
997 reg_data &= ~E1000_TIPG_IPGT_MASK;
998 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
999 E1000_WRITE_REG(hw, TIPG, reg_data);
1000
1001 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1002 reg_data &= ~0x00100000;
1003 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1004 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001005 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001006 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001007 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001008 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001009 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001010 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1011 break;
1012 }
1013
1014
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001015 if (hw->mac_type == e1000_82573) {
1016 uint32_t gcr = E1000_READ_REG(hw, GCR);
1017 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1018 E1000_WRITE_REG(hw, GCR, gcr);
1019 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 /* Clear all of the statistics registers (clear on read). It is
1022 * important that we do this after we have tried to establish link
1023 * because the symbol error count will increment wildly if there
1024 * is no link.
1025 */
1026 e1000_clear_hw_cntrs(hw);
1027
Auke Kokcd94dd02006-06-27 09:08:22 -07001028 /* ICH8 No-snoop bits are opposite polarity.
1029 * Set to snoop by default after reset. */
1030 if (hw->mac_type == e1000_ich8lan)
1031 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1032
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001033 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1034 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1035 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1036 /* Relaxed ordering must be disabled to avoid a parity
1037 * error crash in a PCI slot. */
1038 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1039 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1040 }
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return ret_val;
1043}
1044
1045/******************************************************************************
1046 * Adjust SERDES output amplitude based on EEPROM setting.
1047 *
1048 * hw - Struct containing variables accessed by shared code.
1049 *****************************************************************************/
1050static int32_t
1051e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1052{
1053 uint16_t eeprom_data;
1054 int32_t ret_val;
1055
1056 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1057
Auke Kok8fc897b2006-08-28 14:56:16 -07001058 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 return E1000_SUCCESS;
1060
Auke Kok8fc897b2006-08-28 14:56:16 -07001061 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 case e1000_82545_rev_3:
1063 case e1000_82546_rev_3:
1064 break;
1065 default:
1066 return E1000_SUCCESS;
1067 }
1068
1069 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1070 if (ret_val) {
1071 return ret_val;
1072 }
1073
Auke Kok8fc897b2006-08-28 14:56:16 -07001074 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001076 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001078 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 return ret_val;
1080 }
1081
1082 return E1000_SUCCESS;
1083}
1084
1085/******************************************************************************
1086 * Configures flow control and link settings.
1087 *
1088 * hw - Struct containing variables accessed by shared code
1089 *
1090 * Determines which flow control settings to use. Calls the apropriate media-
1091 * specific link configuration function. Configures the flow control settings.
1092 * Assuming the adapter has a valid link partner, a valid link should be
1093 * established. Assumes the hardware has previously been reset and the
1094 * transmitter and receiver are not enabled.
1095 *****************************************************************************/
1096int32_t
1097e1000_setup_link(struct e1000_hw *hw)
1098{
1099 uint32_t ctrl_ext;
1100 int32_t ret_val;
1101 uint16_t eeprom_data;
1102
1103 DEBUGFUNC("e1000_setup_link");
1104
Jeff Kirsher526f9952006-01-12 16:50:46 -08001105 /* In the case of the phy reset being blocked, we already have a link.
1106 * We do not have to set it up again. */
1107 if (e1000_check_phy_reset_block(hw))
1108 return E1000_SUCCESS;
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /* Read and store word 0x0F of the EEPROM. This word contains bits
1111 * that determine the hardware's default PAUSE (flow control) mode,
1112 * a bit that determines whether the HW defaults to enabling or
1113 * disabling auto-negotiation, and the direction of the
1114 * SW defined pins. If there is no SW over-ride of the flow
1115 * control setting, then the variable hw->fc will
1116 * be initialized based on a value in the EEPROM.
1117 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001118 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001119 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001120 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001121 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001122 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001123 break;
1124 default:
1125 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1126 1, &eeprom_data);
1127 if (ret_val) {
1128 DEBUGOUT("EEPROM Read Error\n");
1129 return -E1000_ERR_EEPROM;
1130 }
1131 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001132 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001133 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1134 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001135 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001136 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001137 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001138 break;
1139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141
1142 /* We want to save off the original Flow Control configuration just
1143 * in case we get disconnected and then reconnected into a different
1144 * hub or switch with different Flow Control capabilities.
1145 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001146 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001147 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Auke Kok8fc897b2006-08-28 14:56:16 -07001149 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001150 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 hw->original_fc = hw->fc;
1153
1154 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1155
1156 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1157 * polarity value for the SW controlled pins, and setup the
1158 * Extended Device Control reg with that info.
1159 * This is needed because one of the SW controlled pins is used for
1160 * signal detection. So this should be done before e1000_setup_pcs_link()
1161 * or e1000_phy_setup() is called.
1162 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001163 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001164 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1165 1, &eeprom_data);
1166 if (ret_val) {
1167 DEBUGOUT("EEPROM Read Error\n");
1168 return -E1000_ERR_EEPROM;
1169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1171 SWDPIO__EXT_SHIFT);
1172 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1173 }
1174
1175 /* Call the necessary subroutine to configure the link. */
1176 ret_val = (hw->media_type == e1000_media_type_copper) ?
1177 e1000_setup_copper_link(hw) :
1178 e1000_setup_fiber_serdes_link(hw);
1179
1180 /* Initialize the flow control address, type, and PAUSE timer
1181 * registers to their default values. This is done even if flow
1182 * control is disabled, because it does not hurt anything to
1183 * initialize these registers.
1184 */
1185 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1186
Auke Kokcd94dd02006-06-27 09:08:22 -07001187 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1188 if (hw->mac_type != e1000_ich8lan) {
1189 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1190 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1191 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1192 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1195
1196 /* Set the flow control receive threshold registers. Normally,
1197 * these registers will be set to a default threshold that may be
1198 * adjusted later by the driver's runtime code. However, if the
1199 * ability to transmit pause frames in not enabled, then these
1200 * registers will be set to 0.
1201 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001202 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 E1000_WRITE_REG(hw, FCRTL, 0);
1204 E1000_WRITE_REG(hw, FCRTH, 0);
1205 } else {
1206 /* We need to set up the Receive Threshold high and low water marks
1207 * as well as (optionally) enabling the transmission of XON frames.
1208 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001209 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1211 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1212 } else {
1213 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1214 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1215 }
1216 }
1217 return ret_val;
1218}
1219
1220/******************************************************************************
1221 * Sets up link for a fiber based or serdes based adapter
1222 *
1223 * hw - Struct containing variables accessed by shared code
1224 *
1225 * Manipulates Physical Coding Sublayer functions in order to configure
1226 * link. Assumes the hardware has been previously reset and the transmitter
1227 * and receiver are not enabled.
1228 *****************************************************************************/
1229static int32_t
1230e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1231{
1232 uint32_t ctrl;
1233 uint32_t status;
1234 uint32_t txcw = 0;
1235 uint32_t i;
1236 uint32_t signal = 0;
1237 int32_t ret_val;
1238
1239 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1240
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001241 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1242 * until explicitly turned off or a power cycle is performed. A read to
1243 * the register does not indicate its status. Therefore, we ensure
1244 * loopback mode is disabled during initialization.
1245 */
1246 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1247 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1248
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001249 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 * set when the optics detect a signal. On older adapters, it will be
1251 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001252 * If we're on serdes media, adjust the output amplitude to value
1253 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 */
1255 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001256 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1258
1259 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001260 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 return ret_val;
1262
1263 /* Take the link out of reset */
1264 ctrl &= ~(E1000_CTRL_LRST);
1265
1266 /* Adjust VCO speed to improve BER performance */
1267 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return ret_val;
1270
1271 e1000_config_collision_dist(hw);
1272
1273 /* Check for a software override of the flow control settings, and setup
1274 * the device accordingly. If auto-negotiation is enabled, then software
1275 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1276 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1277 * auto-negotiation is disabled, then software will have to manually
1278 * configure the two flow control enable bits in the CTRL register.
1279 *
1280 * The possible values of the "fc" parameter are:
1281 * 0: Flow control is completely disabled
1282 * 1: Rx flow control is enabled (we can receive pause frames, but
1283 * not send pause frames).
1284 * 2: Tx flow control is enabled (we can send pause frames but we do
1285 * not support receiving pause frames).
1286 * 3: Both Rx and TX flow control (symmetric) are enabled.
1287 */
1288 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001289 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 /* Flow control is completely disabled by a software over-ride. */
1291 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1292 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001293 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 /* RX Flow control is enabled and TX Flow control is disabled by a
1295 * software over-ride. Since there really isn't a way to advertise
1296 * that we are capable of RX Pause ONLY, we will advertise that we
1297 * support both symmetric and asymmetric RX PAUSE. Later, we will
1298 * disable the adapter's ability to send PAUSE frames.
1299 */
1300 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1301 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001302 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1304 * software over-ride.
1305 */
1306 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1307 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001308 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1310 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1311 break;
1312 default:
1313 DEBUGOUT("Flow control param set incorrectly\n");
1314 return -E1000_ERR_CONFIG;
1315 break;
1316 }
1317
1318 /* Since auto-negotiation is enabled, take the link out of reset (the link
1319 * will be in reset, because we previously reset the chip). This will
1320 * restart auto-negotiation. If auto-neogtiation is successful then the
1321 * link-up status bit will be set and the flow control enable bits (RFCE
1322 * and TFCE) will be set according to their negotiated value.
1323 */
1324 DEBUGOUT("Auto-negotiation enabled\n");
1325
1326 E1000_WRITE_REG(hw, TXCW, txcw);
1327 E1000_WRITE_REG(hw, CTRL, ctrl);
1328 E1000_WRITE_FLUSH(hw);
1329
1330 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001331 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1334 * indication in the Device Status Register. Time-out if a link isn't
1335 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1336 * less than 500 milliseconds even if the other end is doing it in SW).
1337 * For internal serdes, we just assume a signal is present, then poll.
1338 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001339 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1341 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001342 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001343 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001345 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001347 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1349 hw->autoneg_failed = 1;
1350 /* AutoNeg failed to achieve a link, so we'll call
1351 * e1000_check_for_link. This routine will force the link up if
1352 * we detect a signal. This will allow us to communicate with
1353 * non-autonegotiating link partners.
1354 */
1355 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001356 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 DEBUGOUT("Error while checking for link\n");
1358 return ret_val;
1359 }
1360 hw->autoneg_failed = 0;
1361 } else {
1362 hw->autoneg_failed = 0;
1363 DEBUGOUT("Valid Link Found\n");
1364 }
1365 } else {
1366 DEBUGOUT("No Signal Detected\n");
1367 }
1368 return E1000_SUCCESS;
1369}
1370
1371/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001372* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373*
1374* hw - Struct containing variables accessed by shared code
1375******************************************************************************/
1376static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001377e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 uint16_t phy_data;
1382
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001383 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 ctrl = E1000_READ_REG(hw, CTRL);
1386 /* With 82543, we need to force speed and duplex on the MAC equal to what
1387 * the PHY speed and duplex configuration is. In addition, we need to
1388 * perform a hardware reset on the PHY to take it out of reset.
1389 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001390 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 ctrl |= E1000_CTRL_SLU;
1392 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1393 E1000_WRITE_REG(hw, CTRL, ctrl);
1394 } else {
1395 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1396 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001397 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001398 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001399 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 }
1401
1402 /* Make sure we have a valid PHY */
1403 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001404 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 DEBUGOUT("Error, did not detect valid phy.\n");
1406 return ret_val;
1407 }
1408 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1409
1410 /* Set PHY to class A mode (if necessary) */
1411 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001412 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 return ret_val;
1414
Auke Kok8fc897b2006-08-28 14:56:16 -07001415 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 (hw->mac_type == e1000_82546_rev_3)) {
1417 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1418 phy_data |= 0x00000008;
1419 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1420 }
1421
Auke Kok8fc897b2006-08-28 14:56:16 -07001422 if (hw->mac_type <= e1000_82543 ||
1423 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1424 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 hw->phy_reset_disable = FALSE;
1426
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001427 return E1000_SUCCESS;
1428}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001431/********************************************************************
1432* Copper link setup for e1000_phy_igp series.
1433*
1434* hw - Struct containing variables accessed by shared code
1435*********************************************************************/
1436static int32_t
1437e1000_copper_link_igp_setup(struct e1000_hw *hw)
1438{
1439 uint32_t led_ctrl;
1440 int32_t ret_val;
1441 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001443 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001445 if (hw->phy_reset_disable)
1446 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001447
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001448 ret_val = e1000_phy_reset(hw);
1449 if (ret_val) {
1450 DEBUGOUT("Error Resetting the PHY\n");
1451 return ret_val;
1452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Auke Kok8fc897b2006-08-28 14:56:16 -07001454 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001455 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001456 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001457 /* Configure activity LED after PHY reset */
1458 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1459 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1460 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1461 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001462 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001463
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001464 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1465 if (hw->phy_type == e1000_phy_igp) {
1466 /* disable lplu d3 during driver init */
1467 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1468 if (ret_val) {
1469 DEBUGOUT("Error Disabling LPLU D3\n");
1470 return ret_val;
1471 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001472 }
1473
1474 /* disable lplu d0 during driver init */
1475 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1476 if (ret_val) {
1477 DEBUGOUT("Error Disabling LPLU D0\n");
1478 return ret_val;
1479 }
1480 /* Configure mdi-mdix settings */
1481 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1482 if (ret_val)
1483 return ret_val;
1484
1485 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1486 hw->dsp_config_state = e1000_dsp_config_disabled;
1487 /* Force MDI for earlier revs of the IGP PHY */
1488 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1489 hw->mdix = 1;
1490
1491 } else {
1492 hw->dsp_config_state = e1000_dsp_config_enabled;
1493 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1494
1495 switch (hw->mdix) {
1496 case 1:
1497 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1498 break;
1499 case 2:
1500 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1501 break;
1502 case 0:
1503 default:
1504 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1505 break;
1506 }
1507 }
1508 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001509 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001510 return ret_val;
1511
1512 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001513 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001514 e1000_ms_type phy_ms_setting = hw->master_slave;
1515
Auke Kok8fc897b2006-08-28 14:56:16 -07001516 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001517 hw->ffe_config_state = e1000_ffe_config_enabled;
1518
Auke Kok8fc897b2006-08-28 14:56:16 -07001519 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001520 hw->dsp_config_state = e1000_dsp_config_enabled;
1521
1522 /* when autonegotiation advertisment is only 1000Mbps then we
1523 * should disable SmartSpeed and enable Auto MasterSlave
1524 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001525 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001526 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001527 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1528 &phy_data);
1529 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001531 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001532 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1533 phy_data);
1534 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001536 /* Set auto Master/Slave resolution process */
1537 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001538 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001539 return ret_val;
1540 phy_data &= ~CR_1000T_MS_ENABLE;
1541 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001542 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001543 return ret_val;
1544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001546 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001547 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001548 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001550 /* load defaults for future use */
1551 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1552 ((phy_data & CR_1000T_MS_VALUE) ?
1553 e1000_ms_force_master :
1554 e1000_ms_force_slave) :
1555 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001557 switch (phy_ms_setting) {
1558 case e1000_ms_force_master:
1559 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1560 break;
1561 case e1000_ms_force_slave:
1562 phy_data |= CR_1000T_MS_ENABLE;
1563 phy_data &= ~(CR_1000T_MS_VALUE);
1564 break;
1565 case e1000_ms_auto:
1566 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001568 break;
1569 }
1570 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001571 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001572 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Malli Chilakala2b028932005-06-17 17:46:06 -07001575 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001576}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001578/********************************************************************
1579* Copper link setup for e1000_phy_gg82563 series.
1580*
1581* hw - Struct containing variables accessed by shared code
1582*********************************************************************/
1583static int32_t
1584e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1585{
1586 int32_t ret_val;
1587 uint16_t phy_data;
1588 uint32_t reg_data;
1589
1590 DEBUGFUNC("e1000_copper_link_ggp_setup");
1591
Auke Kok8fc897b2006-08-28 14:56:16 -07001592 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001593
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001594 /* Enable CRS on TX for half-duplex operation. */
1595 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1596 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001597 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001598 return ret_val;
1599
1600 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1601 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1602 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1603
1604 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1605 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001606 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001607 return ret_val;
1608
1609 /* Options:
1610 * MDI/MDI-X = 0 (default)
1611 * 0 - Auto for all speeds
1612 * 1 - MDI mode
1613 * 2 - MDI-X mode
1614 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1615 */
1616 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001617 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001618 return ret_val;
1619
1620 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1621
1622 switch (hw->mdix) {
1623 case 1:
1624 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1625 break;
1626 case 2:
1627 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1628 break;
1629 case 0:
1630 default:
1631 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1632 break;
1633 }
1634
1635 /* Options:
1636 * disable_polarity_correction = 0 (default)
1637 * Automatic Correction for Reversed Cable Polarity
1638 * 0 - Disabled
1639 * 1 - Enabled
1640 */
1641 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001642 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001643 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1644 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1645
Auke Kok8fc897b2006-08-28 14:56:16 -07001646 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001647 return ret_val;
1648
1649 /* SW Reset the PHY so all changes take effect */
1650 ret_val = e1000_phy_reset(hw);
1651 if (ret_val) {
1652 DEBUGOUT("Error Resetting the PHY\n");
1653 return ret_val;
1654 }
1655 } /* phy_reset_disable */
1656
1657 if (hw->mac_type == e1000_80003es2lan) {
1658 /* Bypass RX and TX FIFO's */
1659 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1660 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1661 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1662 if (ret_val)
1663 return ret_val;
1664
1665 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1666 if (ret_val)
1667 return ret_val;
1668
1669 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1670 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1671
1672 if (ret_val)
1673 return ret_val;
1674
1675 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1676 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1677 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1678
1679 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1680 &phy_data);
1681 if (ret_val)
1682 return ret_val;
1683
1684 /* Do not init these registers when the HW is in IAMT mode, since the
1685 * firmware will have already initialized them. We only initialize
1686 * them if the HW is not in IAMT mode.
1687 */
1688 if (e1000_check_mng_mode(hw) == FALSE) {
1689 /* Enable Electrical Idle on the PHY */
1690 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1691 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1692 phy_data);
1693 if (ret_val)
1694 return ret_val;
1695
1696 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1697 &phy_data);
1698 if (ret_val)
1699 return ret_val;
1700
Auke Kokcd94dd02006-06-27 09:08:22 -07001701 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001702 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1703 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001704
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001705 if (ret_val)
1706 return ret_val;
1707 }
1708
1709 /* Workaround: Disable padding in Kumeran interface in the MAC
1710 * and in the PHY to avoid CRC errors.
1711 */
1712 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1713 &phy_data);
1714 if (ret_val)
1715 return ret_val;
1716 phy_data |= GG82563_ICR_DIS_PADDING;
1717 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1718 phy_data);
1719 if (ret_val)
1720 return ret_val;
1721 }
1722
1723 return E1000_SUCCESS;
1724}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001726/********************************************************************
1727* Copper link setup for e1000_phy_m88 series.
1728*
1729* hw - Struct containing variables accessed by shared code
1730*********************************************************************/
1731static int32_t
1732e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1733{
1734 int32_t ret_val;
1735 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001737 DEBUGFUNC("e1000_copper_link_mgp_setup");
1738
Auke Kok8fc897b2006-08-28 14:56:16 -07001739 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001740 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001741
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001742 /* Enable CRS on TX. This must be set for half-duplex operation. */
1743 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001744 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001745 return ret_val;
1746
1747 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1748
1749 /* Options:
1750 * MDI/MDI-X = 0 (default)
1751 * 0 - Auto for all speeds
1752 * 1 - MDI mode
1753 * 2 - MDI-X mode
1754 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1755 */
1756 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1757
1758 switch (hw->mdix) {
1759 case 1:
1760 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1761 break;
1762 case 2:
1763 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1764 break;
1765 case 3:
1766 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1767 break;
1768 case 0:
1769 default:
1770 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1771 break;
1772 }
1773
1774 /* Options:
1775 * disable_polarity_correction = 0 (default)
1776 * Automatic Correction for Reversed Cable Polarity
1777 * 0 - Disabled
1778 * 1 - Enabled
1779 */
1780 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001781 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001782 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001783 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1784 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001785 return ret_val;
1786
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001787 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001788 /* Force TX_CLK in the Extended PHY Specific Control Register
1789 * to 25MHz clock.
1790 */
1791 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1792 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001793 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001794
1795 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1796
1797 if ((hw->phy_revision == E1000_REVISION_2) &&
1798 (hw->phy_id == M88E1111_I_PHY_ID)) {
1799 /* Vidalia Phy, set the downshift counter to 5x */
1800 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1801 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1802 ret_val = e1000_write_phy_reg(hw,
1803 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1804 if (ret_val)
1805 return ret_val;
1806 } else {
1807 /* Configure Master and Slave downshift values */
1808 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1809 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1810 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1811 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1812 ret_val = e1000_write_phy_reg(hw,
1813 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1814 if (ret_val)
1815 return ret_val;
1816 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001819 /* SW Reset the PHY so all changes take effect */
1820 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001821 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001822 DEBUGOUT("Error Resetting the PHY\n");
1823 return ret_val;
1824 }
1825
1826 return E1000_SUCCESS;
1827}
1828
1829/********************************************************************
1830* Setup auto-negotiation and flow control advertisements,
1831* and then perform auto-negotiation.
1832*
1833* hw - Struct containing variables accessed by shared code
1834*********************************************************************/
1835static int32_t
1836e1000_copper_link_autoneg(struct e1000_hw *hw)
1837{
1838 int32_t ret_val;
1839 uint16_t phy_data;
1840
1841 DEBUGFUNC("e1000_copper_link_autoneg");
1842
1843 /* Perform some bounds checking on the hw->autoneg_advertised
1844 * parameter. If this variable is zero, then set it to the default.
1845 */
1846 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1847
1848 /* If autoneg_advertised is zero, we assume it was not defaulted
1849 * by the calling code so we set to advertise full capability.
1850 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001851 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001852 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1853
Auke Kokcd94dd02006-06-27 09:08:22 -07001854 /* IFE phy only supports 10/100 */
1855 if (hw->phy_type == e1000_phy_ife)
1856 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1857
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001858 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1859 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001860 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001861 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1862 return ret_val;
1863 }
1864 DEBUGOUT("Restarting Auto-Neg\n");
1865
1866 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1867 * the Auto Neg Restart bit in the PHY control register.
1868 */
1869 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001870 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001871 return ret_val;
1872
1873 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1874 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001875 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001876 return ret_val;
1877
1878 /* Does the user want to wait for Auto-Neg to complete here, or
1879 * check at a later time (for example, callback routine).
1880 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001881 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001882 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001883 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001884 DEBUGOUT("Error while waiting for autoneg to complete\n");
1885 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001889 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001891 return E1000_SUCCESS;
1892}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001894/******************************************************************************
1895* Config the MAC and the PHY after link is up.
1896* 1) Set up the MAC to the current PHY speed/duplex
1897* if we are on 82543. If we
1898* are on newer silicon, we only need to configure
1899* collision distance in the Transmit Control Register.
1900* 2) Set up flow control on the MAC to that established with
1901* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001902* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001903*
1904* hw - Struct containing variables accessed by shared code
1905******************************************************************************/
1906static int32_t
1907e1000_copper_link_postconfig(struct e1000_hw *hw)
1908{
1909 int32_t ret_val;
1910 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001911
Auke Kok8fc897b2006-08-28 14:56:16 -07001912 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001913 e1000_config_collision_dist(hw);
1914 } else {
1915 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001916 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001917 DEBUGOUT("Error configuring MAC to PHY settings\n");
1918 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001920 }
1921 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001922 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001923 DEBUGOUT("Error Configuring Flow Control\n");
1924 return ret_val;
1925 }
1926
1927 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001928 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001929 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001930 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001931 DEBUGOUT("Error Configuring DSP after link up\n");
1932 return ret_val;
1933 }
1934 }
Auke Kok76c224b2006-05-23 13:36:06 -07001935
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001936 return E1000_SUCCESS;
1937}
1938
1939/******************************************************************************
1940* Detects which PHY is present and setup the speed and duplex
1941*
1942* hw - Struct containing variables accessed by shared code
1943******************************************************************************/
1944static int32_t
1945e1000_setup_copper_link(struct e1000_hw *hw)
1946{
1947 int32_t ret_val;
1948 uint16_t i;
1949 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001950 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001951
1952 DEBUGFUNC("e1000_setup_copper_link");
1953
Auke Kokcd94dd02006-06-27 09:08:22 -07001954 switch (hw->mac_type) {
1955 case e1000_80003es2lan:
1956 case e1000_ich8lan:
1957 /* Set the mac to wait the maximum time between each
1958 * iteration and increase the max iterations when
1959 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1960 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1961 if (ret_val)
1962 return ret_val;
1963 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1964 if (ret_val)
1965 return ret_val;
1966 reg_data |= 0x3F;
1967 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1968 if (ret_val)
1969 return ret_val;
1970 default:
1971 break;
1972 }
1973
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001974 /* Check if it is a valid PHY and set PHY mode if necessary. */
1975 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001976 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001977 return ret_val;
1978
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001979 switch (hw->mac_type) {
1980 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001981 /* Kumeran registers are written-only */
1982 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001983 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1984 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1985 reg_data);
1986 if (ret_val)
1987 return ret_val;
1988 break;
1989 default:
1990 break;
1991 }
1992
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001993 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07001994 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001995 hw->phy_type == e1000_phy_igp_2) {
1996 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001997 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001998 return ret_val;
1999 } else if (hw->phy_type == e1000_phy_m88) {
2000 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002001 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002002 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002003 } else if (hw->phy_type == e1000_phy_gg82563) {
2004 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002005 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002006 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002007 }
2008
Auke Kok8fc897b2006-08-28 14:56:16 -07002009 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002010 /* Setup autoneg and flow control advertisement
2011 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002012 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002013 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002014 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002015 } else {
2016 /* PHY will be set to 10H, 10F, 100H,or 100F
2017 * depending on value from forced_speed_duplex. */
2018 DEBUGOUT("Forcing speed and duplex\n");
2019 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002020 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002021 DEBUGOUT("Error Forcing Speed and Duplex\n");
2022 return ret_val;
2023 }
2024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
2026 /* Check link status. Wait up to 100 microseconds for link to become
2027 * valid.
2028 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002029 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002031 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 return ret_val;
2033 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002034 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 return ret_val;
2036
Auke Kok8fc897b2006-08-28 14:56:16 -07002037 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002038 /* Config the MAC and PHY after link is up */
2039 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002040 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 DEBUGOUT("Valid link established!!!\n");
2044 return E1000_SUCCESS;
2045 }
2046 udelay(10);
2047 }
2048
2049 DEBUGOUT("Unable to establish link!!!\n");
2050 return E1000_SUCCESS;
2051}
2052
2053/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002054* Configure the MAC-to-PHY interface for 10/100Mbps
2055*
2056* hw - Struct containing variables accessed by shared code
2057******************************************************************************/
2058static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002059e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002060{
2061 int32_t ret_val = E1000_SUCCESS;
2062 uint32_t tipg;
2063 uint16_t reg_data;
2064
2065 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2066
2067 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2068 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2069 reg_data);
2070 if (ret_val)
2071 return ret_val;
2072
2073 /* Configure Transmit Inter-Packet Gap */
2074 tipg = E1000_READ_REG(hw, TIPG);
2075 tipg &= ~E1000_TIPG_IPGT_MASK;
2076 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2077 E1000_WRITE_REG(hw, TIPG, tipg);
2078
Auke Kokcd94dd02006-06-27 09:08:22 -07002079 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2080
2081 if (ret_val)
2082 return ret_val;
2083
2084 if (duplex == HALF_DUPLEX)
2085 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2086 else
2087 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2088
2089 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2090
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002091 return ret_val;
2092}
2093
2094static int32_t
2095e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2096{
2097 int32_t ret_val = E1000_SUCCESS;
2098 uint16_t reg_data;
2099 uint32_t tipg;
2100
2101 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2102
2103 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2104 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2105 reg_data);
2106 if (ret_val)
2107 return ret_val;
2108
2109 /* Configure Transmit Inter-Packet Gap */
2110 tipg = E1000_READ_REG(hw, TIPG);
2111 tipg &= ~E1000_TIPG_IPGT_MASK;
2112 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2113 E1000_WRITE_REG(hw, TIPG, tipg);
2114
Auke Kokcd94dd02006-06-27 09:08:22 -07002115 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2116
2117 if (ret_val)
2118 return ret_val;
2119
2120 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2121 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2122
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002123 return ret_val;
2124}
2125
2126/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127* Configures PHY autoneg and flow control advertisement settings
2128*
2129* hw - Struct containing variables accessed by shared code
2130******************************************************************************/
2131int32_t
2132e1000_phy_setup_autoneg(struct e1000_hw *hw)
2133{
2134 int32_t ret_val;
2135 uint16_t mii_autoneg_adv_reg;
2136 uint16_t mii_1000t_ctrl_reg;
2137
2138 DEBUGFUNC("e1000_phy_setup_autoneg");
2139
2140 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2141 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002142 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 return ret_val;
2144
Auke Kokcd94dd02006-06-27 09:08:22 -07002145 if (hw->phy_type != e1000_phy_ife) {
2146 /* Read the MII 1000Base-T Control Register (Address 9). */
2147 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2148 if (ret_val)
2149 return ret_val;
2150 } else
2151 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 /* Need to parse both autoneg_advertised and fc and set up
2154 * the appropriate PHY registers. First we will parse for
2155 * autoneg_advertised software override. Since we can advertise
2156 * a plethora of combinations, we need to check each bit
2157 * individually.
2158 */
2159
2160 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2161 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2162 * the 1000Base-T Control Register (Address 9).
2163 */
2164 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2165 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2166
2167 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2168
2169 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002170 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 DEBUGOUT("Advertise 10mb Half duplex\n");
2172 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2173 }
2174
2175 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002176 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 DEBUGOUT("Advertise 10mb Full duplex\n");
2178 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2179 }
2180
2181 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002182 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 DEBUGOUT("Advertise 100mb Half duplex\n");
2184 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2185 }
2186
2187 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002188 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 DEBUGOUT("Advertise 100mb Full duplex\n");
2190 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2191 }
2192
2193 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002194 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2196 }
2197
2198 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002199 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 DEBUGOUT("Advertise 1000mb Full duplex\n");
2201 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002202 if (hw->phy_type == e1000_phy_ife) {
2203 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 }
2206
2207 /* Check for a software override of the flow control settings, and
2208 * setup the PHY advertisement registers accordingly. If
2209 * auto-negotiation is enabled, then software will have to set the
2210 * "PAUSE" bits to the correct value in the Auto-Negotiation
2211 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2212 *
2213 * The possible values of the "fc" parameter are:
2214 * 0: Flow control is completely disabled
2215 * 1: Rx flow control is enabled (we can receive pause frames
2216 * but not send pause frames).
2217 * 2: Tx flow control is enabled (we can send pause frames
2218 * but we do not support receiving pause frames).
2219 * 3: Both Rx and TX flow control (symmetric) are enabled.
2220 * other: No software override. The flow control configuration
2221 * in the EEPROM is used.
2222 */
2223 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002224 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 /* Flow control (RX & TX) is completely disabled by a
2226 * software over-ride.
2227 */
2228 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2229 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002230 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 /* RX Flow control is enabled, and TX Flow control is
2232 * disabled, by a software over-ride.
2233 */
2234 /* Since there really isn't a way to advertise that we are
2235 * capable of RX Pause ONLY, we will advertise that we
2236 * support both symmetric and asymmetric RX PAUSE. Later
2237 * (in e1000_config_fc_after_link_up) we will disable the
2238 *hw's ability to send PAUSE frames.
2239 */
2240 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2241 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002242 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 /* TX Flow control is enabled, and RX Flow control is
2244 * disabled, by a software over-ride.
2245 */
2246 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2247 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2248 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002249 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 /* Flow control (both RX and TX) is enabled by a software
2251 * over-ride.
2252 */
2253 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2254 break;
2255 default:
2256 DEBUGOUT("Flow control param set incorrectly\n");
2257 return -E1000_ERR_CONFIG;
2258 }
2259
2260 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002261 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return ret_val;
2263
2264 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2265
Auke Kokcd94dd02006-06-27 09:08:22 -07002266 if (hw->phy_type != e1000_phy_ife) {
2267 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2268 if (ret_val)
2269 return ret_val;
2270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
2272 return E1000_SUCCESS;
2273}
2274
2275/******************************************************************************
2276* Force PHY speed and duplex settings to hw->forced_speed_duplex
2277*
2278* hw - Struct containing variables accessed by shared code
2279******************************************************************************/
2280static int32_t
2281e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2282{
2283 uint32_t ctrl;
2284 int32_t ret_val;
2285 uint16_t mii_ctrl_reg;
2286 uint16_t mii_status_reg;
2287 uint16_t phy_data;
2288 uint16_t i;
2289
2290 DEBUGFUNC("e1000_phy_force_speed_duplex");
2291
2292 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002293 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2296
2297 /* Read the Device Control Register. */
2298 ctrl = E1000_READ_REG(hw, CTRL);
2299
2300 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2301 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2302 ctrl &= ~(DEVICE_SPEED_MASK);
2303
2304 /* Clear the Auto Speed Detect Enable bit. */
2305 ctrl &= ~E1000_CTRL_ASDE;
2306
2307 /* Read the MII Control Register. */
2308 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002309 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 return ret_val;
2311
2312 /* We need to disable autoneg in order to force link and duplex. */
2313
2314 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2315
2316 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002317 if (hw->forced_speed_duplex == e1000_100_full ||
2318 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 /* We want to force full duplex so we SET the full duplex bits in the
2320 * Device and MII Control Registers.
2321 */
2322 ctrl |= E1000_CTRL_FD;
2323 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2324 DEBUGOUT("Full Duplex\n");
2325 } else {
2326 /* We want to force half duplex so we CLEAR the full duplex bits in
2327 * the Device and MII Control Registers.
2328 */
2329 ctrl &= ~E1000_CTRL_FD;
2330 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2331 DEBUGOUT("Half Duplex\n");
2332 }
2333
2334 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002335 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 hw->forced_speed_duplex == e1000_100_half) {
2337 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2338 ctrl |= E1000_CTRL_SPD_100;
2339 mii_ctrl_reg |= MII_CR_SPEED_100;
2340 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2341 DEBUGOUT("Forcing 100mb ");
2342 } else {
2343 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2344 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2345 mii_ctrl_reg |= MII_CR_SPEED_10;
2346 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2347 DEBUGOUT("Forcing 10mb ");
2348 }
2349
2350 e1000_config_collision_dist(hw);
2351
2352 /* Write the configured values back to the Device Control Reg. */
2353 E1000_WRITE_REG(hw, CTRL, ctrl);
2354
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002355 if ((hw->phy_type == e1000_phy_m88) ||
2356 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002358 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 return ret_val;
2360
2361 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2362 * forced whenever speed are duplex are forced.
2363 */
2364 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2365 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002366 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 return ret_val;
2368
2369 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2370
2371 /* Need to reset the PHY or these changes will be ignored */
2372 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002373
Auke Kokcd94dd02006-06-27 09:08:22 -07002374 /* Disable MDI-X support for 10/100 */
2375 } else if (hw->phy_type == e1000_phy_ife) {
2376 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2377 if (ret_val)
2378 return ret_val;
2379
2380 phy_data &= ~IFE_PMC_AUTO_MDIX;
2381 phy_data &= ~IFE_PMC_FORCE_MDIX;
2382
2383 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2384 if (ret_val)
2385 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 } else {
2388 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2389 * forced whenever speed or duplex are forced.
2390 */
2391 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002392 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 return ret_val;
2394
2395 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2396 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2397
2398 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002399 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 return ret_val;
2401 }
2402
2403 /* Write back the modified PHY MII control register. */
2404 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002405 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 return ret_val;
2407
2408 udelay(1);
2409
2410 /* The wait_autoneg_complete flag may be a little misleading here.
2411 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2412 * But we do want to delay for a period while forcing only so we
2413 * don't generate false No Link messages. So we will wait here
2414 * only if the user has set wait_autoneg_complete to 1, which is
2415 * the default.
2416 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002417 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 /* We will wait for autoneg to complete. */
2419 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2420 mii_status_reg = 0;
2421
2422 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002423 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2425 * to be set.
2426 */
2427 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002428 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 return ret_val;
2430
2431 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002432 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 return ret_val;
2434
Auke Kok8fc897b2006-08-28 14:56:16 -07002435 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002436 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002438 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002439 ((hw->phy_type == e1000_phy_m88) ||
2440 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 /* We didn't get link. Reset the DSP and wait again for link. */
2442 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002443 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 DEBUGOUT("Error Resetting PHY DSP\n");
2445 return ret_val;
2446 }
2447 }
2448 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002449 for (i = PHY_FORCE_TIME; i > 0; i--) {
2450 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002451 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2453 * to be set.
2454 */
2455 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002456 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 return ret_val;
2458
2459 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002460 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 return ret_val;
2462 }
2463 }
2464
2465 if (hw->phy_type == e1000_phy_m88) {
2466 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2467 * Extended PHY Specific Control Register to 25MHz clock. This value
2468 * defaults back to a 2.5MHz clock when the PHY is reset.
2469 */
2470 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002471 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 return ret_val;
2473
2474 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2475 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002476 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 return ret_val;
2478
2479 /* In addition, because of the s/w reset above, we need to enable CRS on
2480 * TX. This must be set for both full and half duplex operation.
2481 */
2482 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002483 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return ret_val;
2485
2486 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2487 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002488 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 return ret_val;
2490
Auke Kok8fc897b2006-08-28 14:56:16 -07002491 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2492 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2493 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002495 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return ret_val;
2497 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002498 } else if (hw->phy_type == e1000_phy_gg82563) {
2499 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2500 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2501 * we're not in a forced 10/duplex configuration. */
2502 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2503 if (ret_val)
2504 return ret_val;
2505
2506 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2507 if ((hw->forced_speed_duplex == e1000_10_full) ||
2508 (hw->forced_speed_duplex == e1000_10_half))
2509 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2510 else
2511 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2512
2513 /* Also due to the reset, we need to enable CRS on Tx. */
2514 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2515
2516 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2517 if (ret_val)
2518 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 }
2520 return E1000_SUCCESS;
2521}
2522
2523/******************************************************************************
2524* Sets the collision distance in the Transmit Control register
2525*
2526* hw - Struct containing variables accessed by shared code
2527*
2528* Link should have been established previously. Reads the speed and duplex
2529* information from the Device Status register.
2530******************************************************************************/
2531void
2532e1000_config_collision_dist(struct e1000_hw *hw)
2533{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002534 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
2536 DEBUGFUNC("e1000_config_collision_dist");
2537
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002538 if (hw->mac_type < e1000_82543)
2539 coll_dist = E1000_COLLISION_DISTANCE_82542;
2540 else
2541 coll_dist = E1000_COLLISION_DISTANCE;
2542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 tctl = E1000_READ_REG(hw, TCTL);
2544
2545 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002546 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 E1000_WRITE_REG(hw, TCTL, tctl);
2549 E1000_WRITE_FLUSH(hw);
2550}
2551
2552/******************************************************************************
2553* Sets MAC speed and duplex settings to reflect the those in the PHY
2554*
2555* hw - Struct containing variables accessed by shared code
2556* mii_reg - data to write to the MII control register
2557*
2558* The contents of the PHY register containing the needed information need to
2559* be passed in.
2560******************************************************************************/
2561static int32_t
2562e1000_config_mac_to_phy(struct e1000_hw *hw)
2563{
2564 uint32_t ctrl;
2565 int32_t ret_val;
2566 uint16_t phy_data;
2567
2568 DEBUGFUNC("e1000_config_mac_to_phy");
2569
Auke Kok76c224b2006-05-23 13:36:06 -07002570 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002571 * MAC speed/duplex configuration.*/
2572 if (hw->mac_type >= e1000_82544)
2573 return E1000_SUCCESS;
2574
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 /* Read the Device Control Register and set the bits to Force Speed
2576 * and Duplex.
2577 */
2578 ctrl = E1000_READ_REG(hw, CTRL);
2579 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2580 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2581
2582 /* Set up duplex in the Device Control and Transmit Control
2583 * registers depending on negotiated values.
2584 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002585 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002586 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002587 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Auke Kok8fc897b2006-08-28 14:56:16 -07002589 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002590 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002591 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002592 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002594 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002596 /* Set up speed in the Device Control register depending on
2597 * negotiated values.
2598 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002599 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002600 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002601 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002602 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 /* Write the configured values back to the Device Control Reg. */
2605 E1000_WRITE_REG(hw, CTRL, ctrl);
2606 return E1000_SUCCESS;
2607}
2608
2609/******************************************************************************
2610 * Forces the MAC's flow control settings.
2611 *
2612 * hw - Struct containing variables accessed by shared code
2613 *
2614 * Sets the TFCE and RFCE bits in the device control register to reflect
2615 * the adapter settings. TFCE and RFCE need to be explicitly set by
2616 * software when a Copper PHY is used because autonegotiation is managed
2617 * by the PHY rather than the MAC. Software must also configure these
2618 * bits when link is forced on a fiber connection.
2619 *****************************************************************************/
2620int32_t
2621e1000_force_mac_fc(struct e1000_hw *hw)
2622{
2623 uint32_t ctrl;
2624
2625 DEBUGFUNC("e1000_force_mac_fc");
2626
2627 /* Get the current configuration of the Device Control Register */
2628 ctrl = E1000_READ_REG(hw, CTRL);
2629
2630 /* Because we didn't get link via the internal auto-negotiation
2631 * mechanism (we either forced link or we got link via PHY
2632 * auto-neg), we have to manually enable/disable transmit an
2633 * receive flow control.
2634 *
2635 * The "Case" statement below enables/disable flow control
2636 * according to the "hw->fc" parameter.
2637 *
2638 * The possible values of the "fc" parameter are:
2639 * 0: Flow control is completely disabled
2640 * 1: Rx flow control is enabled (we can receive pause
2641 * frames but not send pause frames).
2642 * 2: Tx flow control is enabled (we can send pause frames
2643 * frames but we do not receive pause frames).
2644 * 3: Both Rx and TX flow control (symmetric) is enabled.
2645 * other: No other values should be possible at this point.
2646 */
2647
2648 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002649 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2651 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002652 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 ctrl &= (~E1000_CTRL_TFCE);
2654 ctrl |= E1000_CTRL_RFCE;
2655 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002656 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 ctrl &= (~E1000_CTRL_RFCE);
2658 ctrl |= E1000_CTRL_TFCE;
2659 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002660 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2662 break;
2663 default:
2664 DEBUGOUT("Flow control param set incorrectly\n");
2665 return -E1000_ERR_CONFIG;
2666 }
2667
2668 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002669 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 ctrl &= (~E1000_CTRL_TFCE);
2671
2672 E1000_WRITE_REG(hw, CTRL, ctrl);
2673 return E1000_SUCCESS;
2674}
2675
2676/******************************************************************************
2677 * Configures flow control settings after link is established
2678 *
2679 * hw - Struct containing variables accessed by shared code
2680 *
2681 * Should be called immediately after a valid link has been established.
2682 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2683 * and autonegotiation is enabled, the MAC flow control settings will be set
2684 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2685 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2686 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002687static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688e1000_config_fc_after_link_up(struct e1000_hw *hw)
2689{
2690 int32_t ret_val;
2691 uint16_t mii_status_reg;
2692 uint16_t mii_nway_adv_reg;
2693 uint16_t mii_nway_lp_ability_reg;
2694 uint16_t speed;
2695 uint16_t duplex;
2696
2697 DEBUGFUNC("e1000_config_fc_after_link_up");
2698
2699 /* Check for the case where we have fiber media and auto-neg failed
2700 * so we had to force link. In this case, we need to force the
2701 * configuration of the MAC to match the "fc" parameter.
2702 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002703 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2704 ((hw->media_type == e1000_media_type_internal_serdes) &&
2705 (hw->autoneg_failed)) ||
2706 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002708 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 DEBUGOUT("Error forcing flow control settings\n");
2710 return ret_val;
2711 }
2712 }
2713
2714 /* Check for the case where we have copper media and auto-neg is
2715 * enabled. In this case, we need to check and see if Auto-Neg
2716 * has completed, and if so, how the PHY and link partner has
2717 * flow control configured.
2718 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002719 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 /* Read the MII Status Register and check to see if AutoNeg
2721 * has completed. We read this twice because this reg has
2722 * some "sticky" (latched) bits.
2723 */
2724 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002725 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 return ret_val;
2727 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002728 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 return ret_val;
2730
Auke Kok8fc897b2006-08-28 14:56:16 -07002731 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 /* The AutoNeg process has completed, so we now need to
2733 * read both the Auto Negotiation Advertisement Register
2734 * (Address 4) and the Auto_Negotiation Base Page Ability
2735 * Register (Address 5) to determine how flow control was
2736 * negotiated.
2737 */
2738 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2739 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002740 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 return ret_val;
2742 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2743 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002744 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return ret_val;
2746
2747 /* Two bits in the Auto Negotiation Advertisement Register
2748 * (Address 4) and two bits in the Auto Negotiation Base
2749 * Page Ability Register (Address 5) determine flow control
2750 * for both the PHY and the link partner. The following
2751 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2752 * 1999, describes these PAUSE resolution bits and how flow
2753 * control is determined based upon these settings.
2754 * NOTE: DC = Don't Care
2755 *
2756 * LOCAL DEVICE | LINK PARTNER
2757 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2758 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002759 * 0 | 0 | DC | DC | E1000_FC_NONE
2760 * 0 | 1 | 0 | DC | E1000_FC_NONE
2761 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2762 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2763 * 1 | 0 | 0 | DC | E1000_FC_NONE
2764 * 1 | DC | 1 | DC | E1000_FC_FULL
2765 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2766 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 *
2768 */
2769 /* Are both PAUSE bits set to 1? If so, this implies
2770 * Symmetric Flow Control is enabled at both ends. The
2771 * ASM_DIR bits are irrelevant per the spec.
2772 *
2773 * For Symmetric Flow Control:
2774 *
2775 * LOCAL DEVICE | LINK PARTNER
2776 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2777 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002778 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 *
2780 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002781 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2782 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 /* Now we need to check if the user selected RX ONLY
2784 * of pause frames. In this case, we had to advertise
2785 * FULL flow control because we could not advertise RX
2786 * ONLY. Hence, we must now check to see if we need to
2787 * turn OFF the TRANSMISSION of PAUSE frames.
2788 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002789 if (hw->original_fc == E1000_FC_FULL) {
2790 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002791 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002793 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002794 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
2796 }
2797 /* For receiving PAUSE frames ONLY.
2798 *
2799 * LOCAL DEVICE | LINK PARTNER
2800 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2801 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002802 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 *
2804 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002805 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2806 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2807 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2808 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002809 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002810 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 }
2812 /* For transmitting PAUSE frames ONLY.
2813 *
2814 * LOCAL DEVICE | LINK PARTNER
2815 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2816 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002817 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 *
2819 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002820 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2821 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2822 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2823 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002824 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002825 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
2827 /* Per the IEEE spec, at this point flow control should be
2828 * disabled. However, we want to consider that we could
2829 * be connected to a legacy switch that doesn't advertise
2830 * desired flow control, but can be forced on the link
2831 * partner. So if we advertised no flow control, that is
2832 * what we will resolve to. If we advertised some kind of
2833 * receive capability (Rx Pause Only or Full Flow Control)
2834 * and the link partner advertised none, we will configure
2835 * ourselves to enable Rx Flow Control only. We can do
2836 * this safely for two reasons: If the link partner really
2837 * didn't want flow control enabled, and we enable Rx, no
2838 * harm done since we won't be receiving any PAUSE frames
2839 * anyway. If the intent on the link partner was to have
2840 * flow control enabled, then by us enabling RX only, we
2841 * can at least receive pause frames and process them.
2842 * This is a good idea because in most cases, since we are
2843 * predominantly a server NIC, more times than not we will
2844 * be asked to delay transmission of packets than asking
2845 * our link partner to pause transmission of frames.
2846 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002847 else if ((hw->original_fc == E1000_FC_NONE ||
2848 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002849 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002850 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002851 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002853 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002854 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 }
2856
2857 /* Now we need to do one last check... If we auto-
2858 * negotiated to HALF DUPLEX, flow control should not be
2859 * enabled per IEEE 802.3 spec.
2860 */
2861 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002862 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 DEBUGOUT("Error getting link speed and duplex\n");
2864 return ret_val;
2865 }
2866
Auke Kok8fc897b2006-08-28 14:56:16 -07002867 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002868 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
2870 /* Now we call a subroutine to actually force the MAC
2871 * controller to use the correct flow control settings.
2872 */
2873 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002874 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 DEBUGOUT("Error forcing flow control settings\n");
2876 return ret_val;
2877 }
2878 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002879 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 }
2881 }
2882 return E1000_SUCCESS;
2883}
2884
2885/******************************************************************************
2886 * Checks to see if the link status of the hardware has changed.
2887 *
2888 * hw - Struct containing variables accessed by shared code
2889 *
2890 * Called by any function that needs to check the link status of the adapter.
2891 *****************************************************************************/
2892int32_t
2893e1000_check_for_link(struct e1000_hw *hw)
2894{
2895 uint32_t rxcw = 0;
2896 uint32_t ctrl;
2897 uint32_t status;
2898 uint32_t rctl;
2899 uint32_t icr;
2900 uint32_t signal = 0;
2901 int32_t ret_val;
2902 uint16_t phy_data;
2903
2904 DEBUGFUNC("e1000_check_for_link");
2905
2906 ctrl = E1000_READ_REG(hw, CTRL);
2907 status = E1000_READ_REG(hw, STATUS);
2908
2909 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2910 * set when the optics detect a signal. On older adapters, it will be
2911 * cleared when there is a signal. This applies to fiber media only.
2912 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002913 if ((hw->media_type == e1000_media_type_fiber) ||
2914 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 rxcw = E1000_READ_REG(hw, RXCW);
2916
Auke Kok8fc897b2006-08-28 14:56:16 -07002917 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002919 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 hw->get_link_status = FALSE;
2921 }
2922 }
2923
2924 /* If we have a copper PHY then we only want to go out to the PHY
2925 * registers to see if Auto-Neg has completed and/or if our link
2926 * status has changed. The get_link_status flag will be set if we
2927 * receive a Link Status Change interrupt or we have Rx Sequence
2928 * Errors.
2929 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002930 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 /* First we want to see if the MII Status Register reports
2932 * link. If so, then we want to get the current speed/duplex
2933 * of the PHY.
2934 * Read the register twice since the link bit is sticky.
2935 */
2936 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002937 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 return ret_val;
2939 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002940 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 return ret_val;
2942
Auke Kok8fc897b2006-08-28 14:56:16 -07002943 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 hw->get_link_status = FALSE;
2945 /* Check if there was DownShift, must be checked immediately after
2946 * link-up */
2947 e1000_check_downshift(hw);
2948
2949 /* If we are on 82544 or 82543 silicon and speed/duplex
2950 * are forced to 10H or 10F, then we will implement the polarity
2951 * reversal workaround. We disable interrupts first, and upon
2952 * returning, place the devices interrupt state to its previous
2953 * value except for the link status change interrupt which will
2954 * happen due to the execution of this workaround.
2955 */
2956
Auke Kok8fc897b2006-08-28 14:56:16 -07002957 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2958 (!hw->autoneg) &&
2959 (hw->forced_speed_duplex == e1000_10_full ||
2960 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2962 ret_val = e1000_polarity_reversal_workaround(hw);
2963 icr = E1000_READ_REG(hw, ICR);
2964 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2965 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2966 }
2967
2968 } else {
2969 /* No link detected */
2970 e1000_config_dsp_after_link_change(hw, FALSE);
2971 return 0;
2972 }
2973
2974 /* If we are forcing speed/duplex, then we simply return since
2975 * we have already determined whether we have link or not.
2976 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002977 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
2979 /* optimize the dsp settings for the igp phy */
2980 e1000_config_dsp_after_link_change(hw, TRUE);
2981
2982 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2983 * have Si on board that is 82544 or newer, Auto
2984 * Speed Detection takes care of MAC speed/duplex
2985 * configuration. So we only need to configure Collision
2986 * Distance in the MAC. Otherwise, we need to force
2987 * speed/duplex on the MAC to the current PHY speed/duplex
2988 * settings.
2989 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002990 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 e1000_config_collision_dist(hw);
2992 else {
2993 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002994 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 DEBUGOUT("Error configuring MAC to PHY settings\n");
2996 return ret_val;
2997 }
2998 }
2999
3000 /* Configure Flow Control now that Auto-Neg has completed. First, we
3001 * need to restore the desired flow control settings because we may
3002 * have had to re-autoneg with a different link partner.
3003 */
3004 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003005 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 DEBUGOUT("Error configuring flow control\n");
3007 return ret_val;
3008 }
3009
3010 /* At this point we know that we are on copper and we have
3011 * auto-negotiated link. These are conditions for checking the link
3012 * partner capability register. We use the link speed to determine if
3013 * TBI compatibility needs to be turned on or off. If the link is not
3014 * at gigabit speed, then TBI compatibility is not needed. If we are
3015 * at gigabit speed, we turn on TBI compatibility.
3016 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003017 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003019 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3020 if (ret_val) {
3021 DEBUGOUT("Error getting link speed and duplex\n");
3022 return ret_val;
3023 }
3024 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 /* If link speed is not set to gigabit speed, we do not need
3026 * to enable TBI compatibility.
3027 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003028 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 /* If we previously were in the mode, turn it off. */
3030 rctl = E1000_READ_REG(hw, RCTL);
3031 rctl &= ~E1000_RCTL_SBP;
3032 E1000_WRITE_REG(hw, RCTL, rctl);
3033 hw->tbi_compatibility_on = FALSE;
3034 }
3035 } else {
3036 /* If TBI compatibility is was previously off, turn it on. For
3037 * compatibility with a TBI link partner, we will store bad
3038 * packets. Some frames have an additional byte on the end and
3039 * will look like CRC errors to to the hardware.
3040 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003041 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 hw->tbi_compatibility_on = TRUE;
3043 rctl = E1000_READ_REG(hw, RCTL);
3044 rctl |= E1000_RCTL_SBP;
3045 E1000_WRITE_REG(hw, RCTL, rctl);
3046 }
3047 }
3048 }
3049 }
3050 /* If we don't have link (auto-negotiation failed or link partner cannot
3051 * auto-negotiate), the cable is plugged in (we have signal), and our
3052 * link partner is not trying to auto-negotiate with us (we are receiving
3053 * idles or data), we need to force link up. We also need to give
3054 * auto-negotiation time to complete, in case the cable was just plugged
3055 * in. The autoneg_failed flag does this.
3056 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003057 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003059 (hw->media_type == e1000_media_type_internal_serdes)) &&
3060 (!(status & E1000_STATUS_LU)) &&
3061 (!(rxcw & E1000_RXCW_C))) {
3062 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 hw->autoneg_failed = 1;
3064 return 0;
3065 }
Auke Koka42a5072006-05-23 13:36:01 -07003066 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068 /* Disable auto-negotiation in the TXCW register */
3069 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3070
3071 /* Force link-up and also force full-duplex. */
3072 ctrl = E1000_READ_REG(hw, CTRL);
3073 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3074 E1000_WRITE_REG(hw, CTRL, ctrl);
3075
3076 /* Configure Flow Control after forcing link up. */
3077 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003078 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 DEBUGOUT("Error configuring flow control\n");
3080 return ret_val;
3081 }
3082 }
3083 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3084 * auto-negotiation in the TXCW register and disable forced link in the
3085 * Device Control register in an attempt to auto-negotiate with our link
3086 * partner.
3087 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003088 else if (((hw->media_type == e1000_media_type_fiber) ||
3089 (hw->media_type == e1000_media_type_internal_serdes)) &&
3090 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003091 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3093 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3094
3095 hw->serdes_link_down = FALSE;
3096 }
3097 /* If we force link for non-auto-negotiation switch, check link status
3098 * based on MAC synchronization for internal serdes media type.
3099 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003100 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3101 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 /* SYNCH bit and IV bit are sticky. */
3103 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003104 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3105 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 hw->serdes_link_down = FALSE;
3107 DEBUGOUT("SERDES: Link is up.\n");
3108 }
3109 } else {
3110 hw->serdes_link_down = TRUE;
3111 DEBUGOUT("SERDES: Link is down.\n");
3112 }
3113 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003114 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3115 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3117 }
3118 return E1000_SUCCESS;
3119}
3120
3121/******************************************************************************
3122 * Detects the current speed and duplex settings of the hardware.
3123 *
3124 * hw - Struct containing variables accessed by shared code
3125 * speed - Speed of the connection
3126 * duplex - Duplex setting of the connection
3127 *****************************************************************************/
3128int32_t
3129e1000_get_speed_and_duplex(struct e1000_hw *hw,
3130 uint16_t *speed,
3131 uint16_t *duplex)
3132{
3133 uint32_t status;
3134 int32_t ret_val;
3135 uint16_t phy_data;
3136
3137 DEBUGFUNC("e1000_get_speed_and_duplex");
3138
Auke Kok8fc897b2006-08-28 14:56:16 -07003139 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003141 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 *speed = SPEED_1000;
3143 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003144 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 *speed = SPEED_100;
3146 DEBUGOUT("100 Mbs, ");
3147 } else {
3148 *speed = SPEED_10;
3149 DEBUGOUT("10 Mbs, ");
3150 }
3151
Auke Kok8fc897b2006-08-28 14:56:16 -07003152 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003154 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 } else {
3156 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003157 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 }
3159 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003160 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 *speed = SPEED_1000;
3162 *duplex = FULL_DUPLEX;
3163 }
3164
3165 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3166 * if it is operating at half duplex. Here we set the duplex settings to
3167 * match the duplex in the link partner's capabilities.
3168 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003169 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003171 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return ret_val;
3173
Auke Kok8fc897b2006-08-28 14:56:16 -07003174 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 *duplex = HALF_DUPLEX;
3176 else {
3177 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003178 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003180 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3182 *duplex = HALF_DUPLEX;
3183 }
3184 }
3185
Auke Kok76c224b2006-05-23 13:36:06 -07003186 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003187 (hw->media_type == e1000_media_type_copper)) {
3188 if (*speed == SPEED_1000)
3189 ret_val = e1000_configure_kmrn_for_1000(hw);
3190 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003191 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3192 if (ret_val)
3193 return ret_val;
3194 }
3195
3196 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3197 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003198 if (ret_val)
3199 return ret_val;
3200 }
3201
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 return E1000_SUCCESS;
3203}
3204
3205/******************************************************************************
3206* Blocks until autoneg completes or times out (~4.5 seconds)
3207*
3208* hw - Struct containing variables accessed by shared code
3209******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003210static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211e1000_wait_autoneg(struct e1000_hw *hw)
3212{
3213 int32_t ret_val;
3214 uint16_t i;
3215 uint16_t phy_data;
3216
3217 DEBUGFUNC("e1000_wait_autoneg");
3218 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3219
3220 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003221 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 /* Read the MII Status Register and wait for Auto-Neg
3223 * Complete bit to be set.
3224 */
3225 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003226 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return ret_val;
3228 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003229 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003231 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 return E1000_SUCCESS;
3233 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003234 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 }
3236 return E1000_SUCCESS;
3237}
3238
3239/******************************************************************************
3240* Raises the Management Data Clock
3241*
3242* hw - Struct containing variables accessed by shared code
3243* ctrl - Device control register's current value
3244******************************************************************************/
3245static void
3246e1000_raise_mdi_clk(struct e1000_hw *hw,
3247 uint32_t *ctrl)
3248{
3249 /* Raise the clock input to the Management Data Clock (by setting the MDC
3250 * bit), and then delay 10 microseconds.
3251 */
3252 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3253 E1000_WRITE_FLUSH(hw);
3254 udelay(10);
3255}
3256
3257/******************************************************************************
3258* Lowers the Management Data Clock
3259*
3260* hw - Struct containing variables accessed by shared code
3261* ctrl - Device control register's current value
3262******************************************************************************/
3263static void
3264e1000_lower_mdi_clk(struct e1000_hw *hw,
3265 uint32_t *ctrl)
3266{
3267 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3268 * bit), and then delay 10 microseconds.
3269 */
3270 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3271 E1000_WRITE_FLUSH(hw);
3272 udelay(10);
3273}
3274
3275/******************************************************************************
3276* Shifts data bits out to the PHY
3277*
3278* hw - Struct containing variables accessed by shared code
3279* data - Data to send out to the PHY
3280* count - Number of bits to shift out
3281*
3282* Bits are shifted out in MSB to LSB order.
3283******************************************************************************/
3284static void
3285e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3286 uint32_t data,
3287 uint16_t count)
3288{
3289 uint32_t ctrl;
3290 uint32_t mask;
3291
3292 /* We need to shift "count" number of bits out to the PHY. So, the value
3293 * in the "data" parameter will be shifted out to the PHY one bit at a
3294 * time. In order to do this, "data" must be broken down into bits.
3295 */
3296 mask = 0x01;
3297 mask <<= (count - 1);
3298
3299 ctrl = E1000_READ_REG(hw, CTRL);
3300
3301 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3302 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3303
Auke Kok8fc897b2006-08-28 14:56:16 -07003304 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3306 * then raising and lowering the Management Data Clock. A "0" is
3307 * shifted out to the PHY by setting the MDIO bit to "0" and then
3308 * raising and lowering the clock.
3309 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003310 if (data & mask)
3311 ctrl |= E1000_CTRL_MDIO;
3312 else
3313 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
3315 E1000_WRITE_REG(hw, CTRL, ctrl);
3316 E1000_WRITE_FLUSH(hw);
3317
3318 udelay(10);
3319
3320 e1000_raise_mdi_clk(hw, &ctrl);
3321 e1000_lower_mdi_clk(hw, &ctrl);
3322
3323 mask = mask >> 1;
3324 }
3325}
3326
3327/******************************************************************************
3328* Shifts data bits in from the PHY
3329*
3330* hw - Struct containing variables accessed by shared code
3331*
3332* Bits are shifted in in MSB to LSB order.
3333******************************************************************************/
3334static uint16_t
3335e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3336{
3337 uint32_t ctrl;
3338 uint16_t data = 0;
3339 uint8_t i;
3340
3341 /* In order to read a register from the PHY, we need to shift in a total
3342 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3343 * to avoid contention on the MDIO pin when a read operation is performed.
3344 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3345 * by raising the input to the Management Data Clock (setting the MDC bit),
3346 * and then reading the value of the MDIO bit.
3347 */
3348 ctrl = E1000_READ_REG(hw, CTRL);
3349
3350 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3351 ctrl &= ~E1000_CTRL_MDIO_DIR;
3352 ctrl &= ~E1000_CTRL_MDIO;
3353
3354 E1000_WRITE_REG(hw, CTRL, ctrl);
3355 E1000_WRITE_FLUSH(hw);
3356
3357 /* Raise and Lower the clock before reading in the data. This accounts for
3358 * the turnaround bits. The first clock occurred when we clocked out the
3359 * last bit of the Register Address.
3360 */
3361 e1000_raise_mdi_clk(hw, &ctrl);
3362 e1000_lower_mdi_clk(hw, &ctrl);
3363
Auke Kok8fc897b2006-08-28 14:56:16 -07003364 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 data = data << 1;
3366 e1000_raise_mdi_clk(hw, &ctrl);
3367 ctrl = E1000_READ_REG(hw, CTRL);
3368 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003369 if (ctrl & E1000_CTRL_MDIO)
3370 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 e1000_lower_mdi_clk(hw, &ctrl);
3372 }
3373
3374 e1000_raise_mdi_clk(hw, &ctrl);
3375 e1000_lower_mdi_clk(hw, &ctrl);
3376
3377 return data;
3378}
3379
Adrian Bunke4c780b2006-08-14 23:00:10 -07003380static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003381e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3382{
3383 uint32_t swfw_sync = 0;
3384 uint32_t swmask = mask;
3385 uint32_t fwmask = mask << 16;
3386 int32_t timeout = 200;
3387
3388 DEBUGFUNC("e1000_swfw_sync_acquire");
3389
Auke Kokcd94dd02006-06-27 09:08:22 -07003390 if (hw->swfwhw_semaphore_present)
3391 return e1000_get_software_flag(hw);
3392
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003393 if (!hw->swfw_sync_present)
3394 return e1000_get_hw_eeprom_semaphore(hw);
3395
Auke Kok8fc897b2006-08-28 14:56:16 -07003396 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003397 if (e1000_get_hw_eeprom_semaphore(hw))
3398 return -E1000_ERR_SWFW_SYNC;
3399
3400 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3401 if (!(swfw_sync & (fwmask | swmask))) {
3402 break;
3403 }
3404
3405 /* firmware currently using resource (fwmask) */
3406 /* or other software thread currently using resource (swmask) */
3407 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003408 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003409 timeout--;
3410 }
3411
3412 if (!timeout) {
3413 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3414 return -E1000_ERR_SWFW_SYNC;
3415 }
3416
3417 swfw_sync |= swmask;
3418 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3419
3420 e1000_put_hw_eeprom_semaphore(hw);
3421 return E1000_SUCCESS;
3422}
3423
Adrian Bunke4c780b2006-08-14 23:00:10 -07003424static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003425e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3426{
3427 uint32_t swfw_sync;
3428 uint32_t swmask = mask;
3429
3430 DEBUGFUNC("e1000_swfw_sync_release");
3431
Auke Kokcd94dd02006-06-27 09:08:22 -07003432 if (hw->swfwhw_semaphore_present) {
3433 e1000_release_software_flag(hw);
3434 return;
3435 }
3436
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003437 if (!hw->swfw_sync_present) {
3438 e1000_put_hw_eeprom_semaphore(hw);
3439 return;
3440 }
3441
3442 /* if (e1000_get_hw_eeprom_semaphore(hw))
3443 * return -E1000_ERR_SWFW_SYNC; */
3444 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3445 /* empty */
3446
3447 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3448 swfw_sync &= ~swmask;
3449 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3450
3451 e1000_put_hw_eeprom_semaphore(hw);
3452}
3453
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454/*****************************************************************************
3455* Reads the value from a PHY register, if the value is on a specific non zero
3456* page, sets the page first.
3457* hw - Struct containing variables accessed by shared code
3458* reg_addr - address of the PHY register to read
3459******************************************************************************/
3460int32_t
3461e1000_read_phy_reg(struct e1000_hw *hw,
3462 uint32_t reg_addr,
3463 uint16_t *phy_data)
3464{
3465 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003466 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467
3468 DEBUGFUNC("e1000_read_phy_reg");
3469
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003470 if ((hw->mac_type == e1000_80003es2lan) &&
3471 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3472 swfw = E1000_SWFW_PHY1_SM;
3473 } else {
3474 swfw = E1000_SWFW_PHY0_SM;
3475 }
3476 if (e1000_swfw_sync_acquire(hw, swfw))
3477 return -E1000_ERR_SWFW_SYNC;
3478
Auke Kokcd94dd02006-06-27 09:08:22 -07003479 if ((hw->phy_type == e1000_phy_igp ||
3480 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003481 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3483 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3484 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003485 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003486 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 return ret_val;
3488 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003489 } else if (hw->phy_type == e1000_phy_gg82563) {
3490 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3491 (hw->mac_type == e1000_80003es2lan)) {
3492 /* Select Configuration Page */
3493 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3494 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3495 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3496 } else {
3497 /* Use Alternative Page Select register to access
3498 * registers 30 and 31
3499 */
3500 ret_val = e1000_write_phy_reg_ex(hw,
3501 GG82563_PHY_PAGE_SELECT_ALT,
3502 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3503 }
3504
3505 if (ret_val) {
3506 e1000_swfw_sync_release(hw, swfw);
3507 return ret_val;
3508 }
3509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 }
3511
3512 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3513 phy_data);
3514
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003515 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 return ret_val;
3517}
3518
Nicholas Nunley35574762006-09-27 12:53:34 -07003519static int32_t
3520e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 uint16_t *phy_data)
3522{
3523 uint32_t i;
3524 uint32_t mdic = 0;
3525 const uint32_t phy_addr = 1;
3526
3527 DEBUGFUNC("e1000_read_phy_reg_ex");
3528
Auke Kok8fc897b2006-08-28 14:56:16 -07003529 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3531 return -E1000_ERR_PARAM;
3532 }
3533
Auke Kok8fc897b2006-08-28 14:56:16 -07003534 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 /* Set up Op-code, Phy Address, and register address in the MDI
3536 * Control register. The MAC will take care of interfacing with the
3537 * PHY to retrieve the desired data.
3538 */
3539 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3540 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3541 (E1000_MDIC_OP_READ));
3542
3543 E1000_WRITE_REG(hw, MDIC, mdic);
3544
3545 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003546 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 udelay(50);
3548 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003549 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003551 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 DEBUGOUT("MDI Read did not complete\n");
3553 return -E1000_ERR_PHY;
3554 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003555 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 DEBUGOUT("MDI Error\n");
3557 return -E1000_ERR_PHY;
3558 }
3559 *phy_data = (uint16_t) mdic;
3560 } else {
3561 /* We must first send a preamble through the MDIO pin to signal the
3562 * beginning of an MII instruction. This is done by sending 32
3563 * consecutive "1" bits.
3564 */
3565 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3566
3567 /* Now combine the next few fields that are required for a read
3568 * operation. We use this method instead of calling the
3569 * e1000_shift_out_mdi_bits routine five different times. The format of
3570 * a MII read instruction consists of a shift out of 14 bits and is
3571 * defined as follows:
3572 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3573 * followed by a shift in of 18 bits. This first two bits shifted in
3574 * are TurnAround bits used to avoid contention on the MDIO pin when a
3575 * READ operation is performed. These two bits are thrown away
3576 * followed by a shift in of 16 bits which contains the desired data.
3577 */
3578 mdic = ((reg_addr) | (phy_addr << 5) |
3579 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3580
3581 e1000_shift_out_mdi_bits(hw, mdic, 14);
3582
3583 /* Now that we've shifted out the read command to the MII, we need to
3584 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3585 * register address.
3586 */
3587 *phy_data = e1000_shift_in_mdi_bits(hw);
3588 }
3589 return E1000_SUCCESS;
3590}
3591
3592/******************************************************************************
3593* Writes a value to a PHY register
3594*
3595* hw - Struct containing variables accessed by shared code
3596* reg_addr - address of the PHY register to write
3597* data - data to write to the PHY
3598******************************************************************************/
3599int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003600e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 uint16_t phy_data)
3602{
3603 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003604 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
3606 DEBUGFUNC("e1000_write_phy_reg");
3607
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003608 if ((hw->mac_type == e1000_80003es2lan) &&
3609 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3610 swfw = E1000_SWFW_PHY1_SM;
3611 } else {
3612 swfw = E1000_SWFW_PHY0_SM;
3613 }
3614 if (e1000_swfw_sync_acquire(hw, swfw))
3615 return -E1000_ERR_SWFW_SYNC;
3616
Auke Kokcd94dd02006-06-27 09:08:22 -07003617 if ((hw->phy_type == e1000_phy_igp ||
3618 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003619 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3621 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3622 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003623 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003624 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 return ret_val;
3626 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003627 } else if (hw->phy_type == e1000_phy_gg82563) {
3628 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3629 (hw->mac_type == e1000_80003es2lan)) {
3630 /* Select Configuration Page */
3631 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3632 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3633 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3634 } else {
3635 /* Use Alternative Page Select register to access
3636 * registers 30 and 31
3637 */
3638 ret_val = e1000_write_phy_reg_ex(hw,
3639 GG82563_PHY_PAGE_SELECT_ALT,
3640 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3641 }
3642
3643 if (ret_val) {
3644 e1000_swfw_sync_release(hw, swfw);
3645 return ret_val;
3646 }
3647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 }
3649
3650 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3651 phy_data);
3652
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003653 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 return ret_val;
3655}
3656
Nicholas Nunley35574762006-09-27 12:53:34 -07003657static int32_t
3658e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3659 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660{
3661 uint32_t i;
3662 uint32_t mdic = 0;
3663 const uint32_t phy_addr = 1;
3664
3665 DEBUGFUNC("e1000_write_phy_reg_ex");
3666
Auke Kok8fc897b2006-08-28 14:56:16 -07003667 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3669 return -E1000_ERR_PARAM;
3670 }
3671
Auke Kok8fc897b2006-08-28 14:56:16 -07003672 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 /* Set up Op-code, Phy Address, register address, and data intended
3674 * for the PHY register in the MDI Control register. The MAC will take
3675 * care of interfacing with the PHY to send the desired data.
3676 */
3677 mdic = (((uint32_t) phy_data) |
3678 (reg_addr << E1000_MDIC_REG_SHIFT) |
3679 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3680 (E1000_MDIC_OP_WRITE));
3681
3682 E1000_WRITE_REG(hw, MDIC, mdic);
3683
3684 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003685 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 udelay(5);
3687 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003688 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003690 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 DEBUGOUT("MDI Write did not complete\n");
3692 return -E1000_ERR_PHY;
3693 }
3694 } else {
3695 /* We'll need to use the SW defined pins to shift the write command
3696 * out to the PHY. We first send a preamble to the PHY to signal the
3697 * beginning of the MII instruction. This is done by sending 32
3698 * consecutive "1" bits.
3699 */
3700 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3701
3702 /* Now combine the remaining required fields that will indicate a
3703 * write operation. We use this method instead of calling the
3704 * e1000_shift_out_mdi_bits routine for each field in the command. The
3705 * format of a MII write instruction is as follows:
3706 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3707 */
3708 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3709 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3710 mdic <<= 16;
3711 mdic |= (uint32_t) phy_data;
3712
3713 e1000_shift_out_mdi_bits(hw, mdic, 32);
3714 }
3715
3716 return E1000_SUCCESS;
3717}
3718
Adrian Bunke4c780b2006-08-14 23:00:10 -07003719static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003720e1000_read_kmrn_reg(struct e1000_hw *hw,
3721 uint32_t reg_addr,
3722 uint16_t *data)
3723{
3724 uint32_t reg_val;
3725 uint16_t swfw;
3726 DEBUGFUNC("e1000_read_kmrn_reg");
3727
3728 if ((hw->mac_type == e1000_80003es2lan) &&
3729 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3730 swfw = E1000_SWFW_PHY1_SM;
3731 } else {
3732 swfw = E1000_SWFW_PHY0_SM;
3733 }
3734 if (e1000_swfw_sync_acquire(hw, swfw))
3735 return -E1000_ERR_SWFW_SYNC;
3736
3737 /* Write register address */
3738 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3739 E1000_KUMCTRLSTA_OFFSET) |
3740 E1000_KUMCTRLSTA_REN;
3741 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3742 udelay(2);
3743
3744 /* Read the data returned */
3745 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3746 *data = (uint16_t)reg_val;
3747
3748 e1000_swfw_sync_release(hw, swfw);
3749 return E1000_SUCCESS;
3750}
3751
Adrian Bunke4c780b2006-08-14 23:00:10 -07003752static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003753e1000_write_kmrn_reg(struct e1000_hw *hw,
3754 uint32_t reg_addr,
3755 uint16_t data)
3756{
3757 uint32_t reg_val;
3758 uint16_t swfw;
3759 DEBUGFUNC("e1000_write_kmrn_reg");
3760
3761 if ((hw->mac_type == e1000_80003es2lan) &&
3762 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3763 swfw = E1000_SWFW_PHY1_SM;
3764 } else {
3765 swfw = E1000_SWFW_PHY0_SM;
3766 }
3767 if (e1000_swfw_sync_acquire(hw, swfw))
3768 return -E1000_ERR_SWFW_SYNC;
3769
3770 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3771 E1000_KUMCTRLSTA_OFFSET) | data;
3772 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3773 udelay(2);
3774
3775 e1000_swfw_sync_release(hw, swfw);
3776 return E1000_SUCCESS;
3777}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003778
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779/******************************************************************************
3780* Returns the PHY to the power-on reset state
3781*
3782* hw - Struct containing variables accessed by shared code
3783******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003784int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785e1000_phy_hw_reset(struct e1000_hw *hw)
3786{
3787 uint32_t ctrl, ctrl_ext;
3788 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003789 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003790 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
3792 DEBUGFUNC("e1000_phy_hw_reset");
3793
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003794 /* In the case of the phy reset being blocked, it's not an error, we
3795 * simply return success without performing the reset. */
3796 ret_val = e1000_check_phy_reset_block(hw);
3797 if (ret_val)
3798 return E1000_SUCCESS;
3799
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 DEBUGOUT("Resetting Phy...\n");
3801
Auke Kok8fc897b2006-08-28 14:56:16 -07003802 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003803 if ((hw->mac_type == e1000_80003es2lan) &&
3804 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3805 swfw = E1000_SWFW_PHY1_SM;
3806 } else {
3807 swfw = E1000_SWFW_PHY0_SM;
3808 }
3809 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003810 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003811 return -E1000_ERR_SWFW_SYNC;
3812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3814 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003815 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003816 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003817 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 */
3819 ctrl = E1000_READ_REG(hw, CTRL);
3820 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3821 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003822
3823 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003824 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003825 else
3826 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003827
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 E1000_WRITE_REG(hw, CTRL, ctrl);
3829 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003830
Jeff Kirsherfd803242005-12-13 00:06:22 -05003831 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003832 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003833
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003834 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 } else {
3836 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3837 * bit to put the PHY into reset. Then, take it out of reset.
3838 */
3839 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3840 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3841 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3842 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3843 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003844 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3846 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3847 E1000_WRITE_FLUSH(hw);
3848 }
3849 udelay(150);
3850
Auke Kok8fc897b2006-08-28 14:56:16 -07003851 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 /* Configure activity LED after PHY reset */
3853 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3854 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3855 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3856 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3857 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003858
3859 /* Wait for FW to finish PHY configuration. */
3860 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003861 if (ret_val != E1000_SUCCESS)
3862 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003863 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003864
Auke Kok8fc897b2006-08-28 14:56:16 -07003865 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3866 ret_val = e1000_init_lcd_from_nvm(hw);
3867
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003868 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869}
3870
3871/******************************************************************************
3872* Resets the PHY
3873*
3874* hw - Struct containing variables accessed by shared code
3875*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003876* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877******************************************************************************/
3878int32_t
3879e1000_phy_reset(struct e1000_hw *hw)
3880{
3881 int32_t ret_val;
3882 uint16_t phy_data;
3883
3884 DEBUGFUNC("e1000_phy_reset");
3885
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003886 /* In the case of the phy reset being blocked, it's not an error, we
3887 * simply return success without performing the reset. */
3888 ret_val = e1000_check_phy_reset_block(hw);
3889 if (ret_val)
3890 return E1000_SUCCESS;
3891
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003892 switch (hw->phy_type) {
3893 case e1000_phy_igp:
3894 case e1000_phy_igp_2:
3895 case e1000_phy_igp_3:
3896 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003897 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003898 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003899 return ret_val;
3900 break;
3901 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003903 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 return ret_val;
3905
3906 phy_data |= MII_CR_RESET;
3907 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003908 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 return ret_val;
3910
3911 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003912 break;
3913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914
Auke Kok8fc897b2006-08-28 14:56:16 -07003915 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 e1000_phy_init_script(hw);
3917
3918 return E1000_SUCCESS;
3919}
3920
3921/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003922* Work-around for 82566 power-down: on D3 entry-
3923* 1) disable gigabit link
3924* 2) write VR power-down enable
3925* 3) read it back
3926* if successful continue, else issue LCD reset and repeat
3927*
3928* hw - struct containing variables accessed by shared code
3929******************************************************************************/
3930void
3931e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3932{
3933 int32_t reg;
3934 uint16_t phy_data;
3935 int32_t retry = 0;
3936
3937 DEBUGFUNC("e1000_phy_powerdown_workaround");
3938
3939 if (hw->phy_type != e1000_phy_igp_3)
3940 return;
3941
3942 do {
3943 /* Disable link */
3944 reg = E1000_READ_REG(hw, PHY_CTRL);
3945 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3946 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3947
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003948 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003949 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003950 phy_data |= (1 << 9);
3951 phy_data &= ~(1 << 8);
3952 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003953
3954 /* Read it back and test */
3955 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003956 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003957 break;
3958
3959 /* Issue PHY reset and repeat at most one more time */
3960 reg = E1000_READ_REG(hw, CTRL);
3961 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3962 retry++;
3963 } while (retry);
3964
3965 return;
3966
3967}
3968
3969/******************************************************************************
3970* Work-around for 82566 Kumeran PCS lock loss:
3971* On link status change (i.e. PCI reset, speed change) and link is up and
3972* speed is gigabit-
3973* 0) if workaround is optionally disabled do nothing
3974* 1) wait 1ms for Kumeran link to come up
3975* 2) check Kumeran Diagnostic register PCS lock loss bit
3976* 3) if not set the link is locked (all is good), otherwise...
3977* 4) reset the PHY
3978* 5) repeat up to 10 times
3979* Note: this is only called for IGP3 copper when speed is 1gb.
3980*
3981* hw - struct containing variables accessed by shared code
3982******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003983static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003984e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3985{
3986 int32_t ret_val;
3987 int32_t reg;
3988 int32_t cnt;
3989 uint16_t phy_data;
3990
3991 if (hw->kmrn_lock_loss_workaround_disabled)
3992 return E1000_SUCCESS;
3993
Auke Kok8fc897b2006-08-28 14:56:16 -07003994 /* Make sure link is up before proceeding. If not just return.
3995 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003996 * stability */
3997 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3998 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3999
4000 if (phy_data & MII_SR_LINK_STATUS) {
4001 for (cnt = 0; cnt < 10; cnt++) {
4002 /* read once to clear */
4003 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4004 if (ret_val)
4005 return ret_val;
4006 /* and again to get new status */
4007 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4008 if (ret_val)
4009 return ret_val;
4010
4011 /* check for PCS lock */
4012 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4013 return E1000_SUCCESS;
4014
4015 /* Issue PHY reset */
4016 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004017 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004018 }
4019 /* Disable GigE link negotiation */
4020 reg = E1000_READ_REG(hw, PHY_CTRL);
4021 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4022 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4023
4024 /* unable to acquire PCS lock */
4025 return E1000_ERR_PHY;
4026 }
4027
4028 return E1000_SUCCESS;
4029}
4030
4031/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032* Probes the expected PHY address for known PHY IDs
4033*
4034* hw - Struct containing variables accessed by shared code
4035******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004036static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037e1000_detect_gig_phy(struct e1000_hw *hw)
4038{
4039 int32_t phy_init_status, ret_val;
4040 uint16_t phy_id_high, phy_id_low;
4041 boolean_t match = FALSE;
4042
4043 DEBUGFUNC("e1000_detect_gig_phy");
4044
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004045 if (hw->phy_id != 0)
4046 return E1000_SUCCESS;
4047
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004048 /* The 82571 firmware may still be configuring the PHY. In this
4049 * case, we cannot access the PHY until the configuration is done. So
4050 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004051 if (hw->mac_type == e1000_82571 ||
4052 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004053 hw->phy_id = IGP01E1000_I_PHY_ID;
4054 hw->phy_type = e1000_phy_igp_2;
4055 return E1000_SUCCESS;
4056 }
4057
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004058 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4059 * around that forces PHY page 0 to be set or the reads fail. The rest of
4060 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4061 * So for ESB-2 we need to have this set so our reads won't fail. If the
4062 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4063 * this out as well. */
4064 if (hw->mac_type == e1000_80003es2lan)
4065 hw->phy_type = e1000_phy_gg82563;
4066
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 /* Read the PHY ID Registers to identify which PHY is onboard. */
4068 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004069 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 return ret_val;
4071
4072 hw->phy_id = (uint32_t) (phy_id_high << 16);
4073 udelay(20);
4074 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004075 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 return ret_val;
4077
4078 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4079 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4080
Auke Kok8fc897b2006-08-28 14:56:16 -07004081 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004083 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 break;
4085 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004086 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 break;
4088 case e1000_82540:
4089 case e1000_82545:
4090 case e1000_82545_rev_3:
4091 case e1000_82546:
4092 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004093 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 break;
4095 case e1000_82541:
4096 case e1000_82541_rev_2:
4097 case e1000_82547:
4098 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004099 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004101 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004102 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004103 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004104 case e1000_80003es2lan:
4105 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4106 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004107 case e1000_ich8lan:
4108 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4109 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4110 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4111 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4112 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 default:
4114 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4115 return -E1000_ERR_CONFIG;
4116 }
4117 phy_init_status = e1000_set_phy_type(hw);
4118
4119 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4120 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4121 return E1000_SUCCESS;
4122 }
4123 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4124 return -E1000_ERR_PHY;
4125}
4126
4127/******************************************************************************
4128* Resets the PHY's DSP
4129*
4130* hw - Struct containing variables accessed by shared code
4131******************************************************************************/
4132static int32_t
4133e1000_phy_reset_dsp(struct e1000_hw *hw)
4134{
4135 int32_t ret_val;
4136 DEBUGFUNC("e1000_phy_reset_dsp");
4137
4138 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004139 if (hw->phy_type != e1000_phy_gg82563) {
4140 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004141 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004144 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004146 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004148 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149
4150 return ret_val;
4151}
4152
4153/******************************************************************************
4154* Get PHY information from various PHY registers for igp PHY only.
4155*
4156* hw - Struct containing variables accessed by shared code
4157* phy_info - PHY information structure
4158******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004159static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160e1000_phy_igp_get_info(struct e1000_hw *hw,
4161 struct e1000_phy_info *phy_info)
4162{
4163 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004164 uint16_t phy_data, min_length, max_length, average;
4165 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
4167 DEBUGFUNC("e1000_phy_igp_get_info");
4168
4169 /* The downshift status is checked only once, after link is established,
4170 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004171 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172
4173 /* IGP01E1000 does not need to support it. */
4174 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4175
4176 /* IGP01E1000 always correct polarity reversal */
4177 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4178
4179 /* Check polarity status */
4180 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004181 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 return ret_val;
4183
4184 phy_info->cable_polarity = polarity;
4185
4186 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004187 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 return ret_val;
4189
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004190 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4191 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Auke Kok8fc897b2006-08-28 14:56:16 -07004193 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 IGP01E1000_PSSR_SPEED_1000MBPS) {
4195 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4196 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004197 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 return ret_val;
4199
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004200 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4201 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4202 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4203 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4204 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4205 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206
4207 /* Get cable length */
4208 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004209 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 return ret_val;
4211
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004212 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 average = (max_length + min_length) / 2;
4214
Auke Kok8fc897b2006-08-28 14:56:16 -07004215 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004217 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004219 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004221 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 phy_info->cable_length = e1000_cable_length_110_140;
4223 else
4224 phy_info->cable_length = e1000_cable_length_140;
4225 }
4226
4227 return E1000_SUCCESS;
4228}
4229
4230/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004231* Get PHY information from various PHY registers for ife PHY only.
4232*
4233* hw - Struct containing variables accessed by shared code
4234* phy_info - PHY information structure
4235******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004236static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004237e1000_phy_ife_get_info(struct e1000_hw *hw,
4238 struct e1000_phy_info *phy_info)
4239{
4240 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004241 uint16_t phy_data;
4242 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004243
4244 DEBUGFUNC("e1000_phy_ife_get_info");
4245
4246 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4247 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4248
4249 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4250 if (ret_val)
4251 return ret_val;
4252 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004253 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4254 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4255 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004256
4257 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4258 ret_val = e1000_check_polarity(hw, &polarity);
4259 if (ret_val)
4260 return ret_val;
4261 } else {
4262 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004263 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4264 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4265 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004266 }
4267 phy_info->cable_polarity = polarity;
4268
4269 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4270 if (ret_val)
4271 return ret_val;
4272
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004273 phy_info->mdix_mode = (e1000_auto_x_mode)
4274 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4275 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004276
4277 return E1000_SUCCESS;
4278}
4279
4280/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281* Get PHY information from various PHY registers fot m88 PHY only.
4282*
4283* hw - Struct containing variables accessed by shared code
4284* phy_info - PHY information structure
4285******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004286static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287e1000_phy_m88_get_info(struct e1000_hw *hw,
4288 struct e1000_phy_info *phy_info)
4289{
4290 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004291 uint16_t phy_data;
4292 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293
4294 DEBUGFUNC("e1000_phy_m88_get_info");
4295
4296 /* The downshift status is checked only once, after link is established,
4297 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004298 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299
4300 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004301 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 return ret_val;
4303
4304 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004305 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4306 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4307 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4308
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004310 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4311 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4312 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313
4314 /* Check polarity status */
4315 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004316 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004317 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 phy_info->cable_polarity = polarity;
4319
4320 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004321 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 return ret_val;
4323
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004324 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4325 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326
4327 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4328 /* Cable Length Estimation and Local/Remote Receiver Information
4329 * are only valid at 1000 Mbps.
4330 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004331 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004332 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004333 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4334 } else {
4335 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4336 &phy_data);
4337 if (ret_val)
4338 return ret_val;
4339
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004340 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342
4343 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004344 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 return ret_val;
4346
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004347 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4348 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4349 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4350 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4351 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4352 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 }
4355
4356 return E1000_SUCCESS;
4357}
4358
4359/******************************************************************************
4360* Get PHY information from various PHY registers
4361*
4362* hw - Struct containing variables accessed by shared code
4363* phy_info - PHY information structure
4364******************************************************************************/
4365int32_t
4366e1000_phy_get_info(struct e1000_hw *hw,
4367 struct e1000_phy_info *phy_info)
4368{
4369 int32_t ret_val;
4370 uint16_t phy_data;
4371
4372 DEBUGFUNC("e1000_phy_get_info");
4373
4374 phy_info->cable_length = e1000_cable_length_undefined;
4375 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4376 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4377 phy_info->downshift = e1000_downshift_undefined;
4378 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4379 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4380 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4381 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4382
Auke Kok8fc897b2006-08-28 14:56:16 -07004383 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 DEBUGOUT("PHY info is only valid for copper media\n");
4385 return -E1000_ERR_CONFIG;
4386 }
4387
4388 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004389 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 return ret_val;
4391
4392 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004393 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 return ret_val;
4395
Auke Kok8fc897b2006-08-28 14:56:16 -07004396 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 DEBUGOUT("PHY info is only valid if link is up\n");
4398 return -E1000_ERR_CONFIG;
4399 }
4400
Auke Kokcd94dd02006-06-27 09:08:22 -07004401 if (hw->phy_type == e1000_phy_igp ||
4402 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004403 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004405 else if (hw->phy_type == e1000_phy_ife)
4406 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 else
4408 return e1000_phy_m88_get_info(hw, phy_info);
4409}
4410
4411int32_t
4412e1000_validate_mdi_setting(struct e1000_hw *hw)
4413{
4414 DEBUGFUNC("e1000_validate_mdi_settings");
4415
Auke Kok8fc897b2006-08-28 14:56:16 -07004416 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 DEBUGOUT("Invalid MDI setting detected\n");
4418 hw->mdix = 1;
4419 return -E1000_ERR_CONFIG;
4420 }
4421 return E1000_SUCCESS;
4422}
4423
4424
4425/******************************************************************************
4426 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004427 * is configured. Additionally, if this is ICH8, the flash controller GbE
4428 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 *
4430 * hw - Struct containing variables accessed by shared code
4431 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004432int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433e1000_init_eeprom_params(struct e1000_hw *hw)
4434{
4435 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4436 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004437 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 uint16_t eeprom_size;
4439
4440 DEBUGFUNC("e1000_init_eeprom_params");
4441
4442 switch (hw->mac_type) {
4443 case e1000_82542_rev2_0:
4444 case e1000_82542_rev2_1:
4445 case e1000_82543:
4446 case e1000_82544:
4447 eeprom->type = e1000_eeprom_microwire;
4448 eeprom->word_size = 64;
4449 eeprom->opcode_bits = 3;
4450 eeprom->address_bits = 6;
4451 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004452 eeprom->use_eerd = FALSE;
4453 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 break;
4455 case e1000_82540:
4456 case e1000_82545:
4457 case e1000_82545_rev_3:
4458 case e1000_82546:
4459 case e1000_82546_rev_3:
4460 eeprom->type = e1000_eeprom_microwire;
4461 eeprom->opcode_bits = 3;
4462 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004463 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 eeprom->word_size = 256;
4465 eeprom->address_bits = 8;
4466 } else {
4467 eeprom->word_size = 64;
4468 eeprom->address_bits = 6;
4469 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004470 eeprom->use_eerd = FALSE;
4471 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 break;
4473 case e1000_82541:
4474 case e1000_82541_rev_2:
4475 case e1000_82547:
4476 case e1000_82547_rev_2:
4477 if (eecd & E1000_EECD_TYPE) {
4478 eeprom->type = e1000_eeprom_spi;
4479 eeprom->opcode_bits = 8;
4480 eeprom->delay_usec = 1;
4481 if (eecd & E1000_EECD_ADDR_BITS) {
4482 eeprom->page_size = 32;
4483 eeprom->address_bits = 16;
4484 } else {
4485 eeprom->page_size = 8;
4486 eeprom->address_bits = 8;
4487 }
4488 } else {
4489 eeprom->type = e1000_eeprom_microwire;
4490 eeprom->opcode_bits = 3;
4491 eeprom->delay_usec = 50;
4492 if (eecd & E1000_EECD_ADDR_BITS) {
4493 eeprom->word_size = 256;
4494 eeprom->address_bits = 8;
4495 } else {
4496 eeprom->word_size = 64;
4497 eeprom->address_bits = 6;
4498 }
4499 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004500 eeprom->use_eerd = FALSE;
4501 eeprom->use_eewr = FALSE;
4502 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004503 case e1000_82571:
4504 case e1000_82572:
4505 eeprom->type = e1000_eeprom_spi;
4506 eeprom->opcode_bits = 8;
4507 eeprom->delay_usec = 1;
4508 if (eecd & E1000_EECD_ADDR_BITS) {
4509 eeprom->page_size = 32;
4510 eeprom->address_bits = 16;
4511 } else {
4512 eeprom->page_size = 8;
4513 eeprom->address_bits = 8;
4514 }
4515 eeprom->use_eerd = FALSE;
4516 eeprom->use_eewr = FALSE;
4517 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004518 case e1000_82573:
4519 eeprom->type = e1000_eeprom_spi;
4520 eeprom->opcode_bits = 8;
4521 eeprom->delay_usec = 1;
4522 if (eecd & E1000_EECD_ADDR_BITS) {
4523 eeprom->page_size = 32;
4524 eeprom->address_bits = 16;
4525 } else {
4526 eeprom->page_size = 8;
4527 eeprom->address_bits = 8;
4528 }
4529 eeprom->use_eerd = TRUE;
4530 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004531 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004532 eeprom->type = e1000_eeprom_flash;
4533 eeprom->word_size = 2048;
4534
4535 /* Ensure that the Autonomous FLASH update bit is cleared due to
4536 * Flash update issue on parts which use a FLASH for NVM. */
4537 eecd &= ~E1000_EECD_AUPDEN;
4538 E1000_WRITE_REG(hw, EECD, eecd);
4539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004541 case e1000_80003es2lan:
4542 eeprom->type = e1000_eeprom_spi;
4543 eeprom->opcode_bits = 8;
4544 eeprom->delay_usec = 1;
4545 if (eecd & E1000_EECD_ADDR_BITS) {
4546 eeprom->page_size = 32;
4547 eeprom->address_bits = 16;
4548 } else {
4549 eeprom->page_size = 8;
4550 eeprom->address_bits = 8;
4551 }
4552 eeprom->use_eerd = TRUE;
4553 eeprom->use_eewr = FALSE;
4554 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004555 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004556 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004557 int32_t i = 0;
4558 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4559
4560 eeprom->type = e1000_eeprom_ich8;
4561 eeprom->use_eerd = FALSE;
4562 eeprom->use_eewr = FALSE;
4563 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4564
4565 /* Zero the shadow RAM structure. But don't load it from NVM
4566 * so as to save time for driver init */
4567 if (hw->eeprom_shadow_ram != NULL) {
4568 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4569 hw->eeprom_shadow_ram[i].modified = FALSE;
4570 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4571 }
4572 }
4573
4574 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4575 ICH8_FLASH_SECTOR_SIZE;
4576
4577 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4578 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4579 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4580 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4581
4582 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 default:
4585 break;
4586 }
4587
4588 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004589 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4590 * 32KB (incremented by powers of 2).
4591 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004592 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004593 /* Set to default value for initial eeprom read. */
4594 eeprom->word_size = 64;
4595 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004596 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004597 return ret_val;
4598 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4599 /* 256B eeprom size was not supported in earlier hardware, so we
4600 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4601 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004602 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004603 eeprom_size++;
4604 } else {
4605 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4606 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004608
4609 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004611 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612}
4613
4614/******************************************************************************
4615 * Raises the EEPROM's clock input.
4616 *
4617 * hw - Struct containing variables accessed by shared code
4618 * eecd - EECD's current value
4619 *****************************************************************************/
4620static void
4621e1000_raise_ee_clk(struct e1000_hw *hw,
4622 uint32_t *eecd)
4623{
4624 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4625 * wait <delay> microseconds.
4626 */
4627 *eecd = *eecd | E1000_EECD_SK;
4628 E1000_WRITE_REG(hw, EECD, *eecd);
4629 E1000_WRITE_FLUSH(hw);
4630 udelay(hw->eeprom.delay_usec);
4631}
4632
4633/******************************************************************************
4634 * Lowers the EEPROM's clock input.
4635 *
4636 * hw - Struct containing variables accessed by shared code
4637 * eecd - EECD's current value
4638 *****************************************************************************/
4639static void
4640e1000_lower_ee_clk(struct e1000_hw *hw,
4641 uint32_t *eecd)
4642{
4643 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4644 * wait 50 microseconds.
4645 */
4646 *eecd = *eecd & ~E1000_EECD_SK;
4647 E1000_WRITE_REG(hw, EECD, *eecd);
4648 E1000_WRITE_FLUSH(hw);
4649 udelay(hw->eeprom.delay_usec);
4650}
4651
4652/******************************************************************************
4653 * Shift data bits out to the EEPROM.
4654 *
4655 * hw - Struct containing variables accessed by shared code
4656 * data - data to send to the EEPROM
4657 * count - number of bits to shift out
4658 *****************************************************************************/
4659static void
4660e1000_shift_out_ee_bits(struct e1000_hw *hw,
4661 uint16_t data,
4662 uint16_t count)
4663{
4664 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4665 uint32_t eecd;
4666 uint32_t mask;
4667
4668 /* We need to shift "count" bits out to the EEPROM. So, value in the
4669 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4670 * In order to do this, "data" must be broken down into bits.
4671 */
4672 mask = 0x01 << (count - 1);
4673 eecd = E1000_READ_REG(hw, EECD);
4674 if (eeprom->type == e1000_eeprom_microwire) {
4675 eecd &= ~E1000_EECD_DO;
4676 } else if (eeprom->type == e1000_eeprom_spi) {
4677 eecd |= E1000_EECD_DO;
4678 }
4679 do {
4680 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4681 * and then raising and then lowering the clock (the SK bit controls
4682 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4683 * by setting "DI" to "0" and then raising and then lowering the clock.
4684 */
4685 eecd &= ~E1000_EECD_DI;
4686
Auke Kok8fc897b2006-08-28 14:56:16 -07004687 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688 eecd |= E1000_EECD_DI;
4689
4690 E1000_WRITE_REG(hw, EECD, eecd);
4691 E1000_WRITE_FLUSH(hw);
4692
4693 udelay(eeprom->delay_usec);
4694
4695 e1000_raise_ee_clk(hw, &eecd);
4696 e1000_lower_ee_clk(hw, &eecd);
4697
4698 mask = mask >> 1;
4699
Auke Kok8fc897b2006-08-28 14:56:16 -07004700 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701
4702 /* We leave the "DI" bit set to "0" when we leave this routine. */
4703 eecd &= ~E1000_EECD_DI;
4704 E1000_WRITE_REG(hw, EECD, eecd);
4705}
4706
4707/******************************************************************************
4708 * Shift data bits in from the EEPROM
4709 *
4710 * hw - Struct containing variables accessed by shared code
4711 *****************************************************************************/
4712static uint16_t
4713e1000_shift_in_ee_bits(struct e1000_hw *hw,
4714 uint16_t count)
4715{
4716 uint32_t eecd;
4717 uint32_t i;
4718 uint16_t data;
4719
4720 /* In order to read a register from the EEPROM, we need to shift 'count'
4721 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4722 * input to the EEPROM (setting the SK bit), and then reading the value of
4723 * the "DO" bit. During this "shifting in" process the "DI" bit should
4724 * always be clear.
4725 */
4726
4727 eecd = E1000_READ_REG(hw, EECD);
4728
4729 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4730 data = 0;
4731
Auke Kok8fc897b2006-08-28 14:56:16 -07004732 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 data = data << 1;
4734 e1000_raise_ee_clk(hw, &eecd);
4735
4736 eecd = E1000_READ_REG(hw, EECD);
4737
4738 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004739 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 data |= 1;
4741
4742 e1000_lower_ee_clk(hw, &eecd);
4743 }
4744
4745 return data;
4746}
4747
4748/******************************************************************************
4749 * Prepares EEPROM for access
4750 *
4751 * hw - Struct containing variables accessed by shared code
4752 *
4753 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4754 * function should be called before issuing a command to the EEPROM.
4755 *****************************************************************************/
4756static int32_t
4757e1000_acquire_eeprom(struct e1000_hw *hw)
4758{
4759 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4760 uint32_t eecd, i=0;
4761
4762 DEBUGFUNC("e1000_acquire_eeprom");
4763
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004764 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4765 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 eecd = E1000_READ_REG(hw, EECD);
4767
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004768 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004769 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004770 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004771 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004773 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004774 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004775 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4776 i++;
4777 udelay(5);
4778 eecd = E1000_READ_REG(hw, EECD);
4779 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004780 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004781 eecd &= ~E1000_EECD_REQ;
4782 E1000_WRITE_REG(hw, EECD, eecd);
4783 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004784 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004785 return -E1000_ERR_EEPROM;
4786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 }
4788 }
4789
4790 /* Setup EEPROM for Read/Write */
4791
4792 if (eeprom->type == e1000_eeprom_microwire) {
4793 /* Clear SK and DI */
4794 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4795 E1000_WRITE_REG(hw, EECD, eecd);
4796
4797 /* Set CS */
4798 eecd |= E1000_EECD_CS;
4799 E1000_WRITE_REG(hw, EECD, eecd);
4800 } else if (eeprom->type == e1000_eeprom_spi) {
4801 /* Clear SK and CS */
4802 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4803 E1000_WRITE_REG(hw, EECD, eecd);
4804 udelay(1);
4805 }
4806
4807 return E1000_SUCCESS;
4808}
4809
4810/******************************************************************************
4811 * Returns EEPROM to a "standby" state
4812 *
4813 * hw - Struct containing variables accessed by shared code
4814 *****************************************************************************/
4815static void
4816e1000_standby_eeprom(struct e1000_hw *hw)
4817{
4818 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4819 uint32_t eecd;
4820
4821 eecd = E1000_READ_REG(hw, EECD);
4822
Auke Kok8fc897b2006-08-28 14:56:16 -07004823 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4825 E1000_WRITE_REG(hw, EECD, eecd);
4826 E1000_WRITE_FLUSH(hw);
4827 udelay(eeprom->delay_usec);
4828
4829 /* Clock high */
4830 eecd |= E1000_EECD_SK;
4831 E1000_WRITE_REG(hw, EECD, eecd);
4832 E1000_WRITE_FLUSH(hw);
4833 udelay(eeprom->delay_usec);
4834
4835 /* Select EEPROM */
4836 eecd |= E1000_EECD_CS;
4837 E1000_WRITE_REG(hw, EECD, eecd);
4838 E1000_WRITE_FLUSH(hw);
4839 udelay(eeprom->delay_usec);
4840
4841 /* Clock low */
4842 eecd &= ~E1000_EECD_SK;
4843 E1000_WRITE_REG(hw, EECD, eecd);
4844 E1000_WRITE_FLUSH(hw);
4845 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004846 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 /* Toggle CS to flush commands */
4848 eecd |= E1000_EECD_CS;
4849 E1000_WRITE_REG(hw, EECD, eecd);
4850 E1000_WRITE_FLUSH(hw);
4851 udelay(eeprom->delay_usec);
4852 eecd &= ~E1000_EECD_CS;
4853 E1000_WRITE_REG(hw, EECD, eecd);
4854 E1000_WRITE_FLUSH(hw);
4855 udelay(eeprom->delay_usec);
4856 }
4857}
4858
4859/******************************************************************************
4860 * Terminates a command by inverting the EEPROM's chip select pin
4861 *
4862 * hw - Struct containing variables accessed by shared code
4863 *****************************************************************************/
4864static void
4865e1000_release_eeprom(struct e1000_hw *hw)
4866{
4867 uint32_t eecd;
4868
4869 DEBUGFUNC("e1000_release_eeprom");
4870
4871 eecd = E1000_READ_REG(hw, EECD);
4872
4873 if (hw->eeprom.type == e1000_eeprom_spi) {
4874 eecd |= E1000_EECD_CS; /* Pull CS high */
4875 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4876
4877 E1000_WRITE_REG(hw, EECD, eecd);
4878
4879 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004880 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 /* cleanup eeprom */
4882
4883 /* CS on Microwire is active-high */
4884 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4885
4886 E1000_WRITE_REG(hw, EECD, eecd);
4887
4888 /* Rising edge of clock */
4889 eecd |= E1000_EECD_SK;
4890 E1000_WRITE_REG(hw, EECD, eecd);
4891 E1000_WRITE_FLUSH(hw);
4892 udelay(hw->eeprom.delay_usec);
4893
4894 /* Falling edge of clock */
4895 eecd &= ~E1000_EECD_SK;
4896 E1000_WRITE_REG(hw, EECD, eecd);
4897 E1000_WRITE_FLUSH(hw);
4898 udelay(hw->eeprom.delay_usec);
4899 }
4900
4901 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004902 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 eecd &= ~E1000_EECD_REQ;
4904 E1000_WRITE_REG(hw, EECD, eecd);
4905 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004906
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004907 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908}
4909
4910/******************************************************************************
4911 * Reads a 16 bit word from the EEPROM.
4912 *
4913 * hw - Struct containing variables accessed by shared code
4914 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004915static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916e1000_spi_eeprom_ready(struct e1000_hw *hw)
4917{
4918 uint16_t retry_count = 0;
4919 uint8_t spi_stat_reg;
4920
4921 DEBUGFUNC("e1000_spi_eeprom_ready");
4922
4923 /* Read "Status Register" repeatedly until the LSB is cleared. The
4924 * EEPROM will signal that the command has been completed by clearing
4925 * bit 0 of the internal status register. If it's not cleared within
4926 * 5 milliseconds, then error out.
4927 */
4928 retry_count = 0;
4929 do {
4930 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4931 hw->eeprom.opcode_bits);
4932 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4933 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4934 break;
4935
4936 udelay(5);
4937 retry_count += 5;
4938
4939 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004940 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941
4942 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4943 * only 0-5mSec on 5V devices)
4944 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004945 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946 DEBUGOUT("SPI EEPROM Status error\n");
4947 return -E1000_ERR_EEPROM;
4948 }
4949
4950 return E1000_SUCCESS;
4951}
4952
4953/******************************************************************************
4954 * Reads a 16 bit word from the EEPROM.
4955 *
4956 * hw - Struct containing variables accessed by shared code
4957 * offset - offset of word in the EEPROM to read
4958 * data - word read from the EEPROM
4959 * words - number of words to read
4960 *****************************************************************************/
4961int32_t
4962e1000_read_eeprom(struct e1000_hw *hw,
4963 uint16_t offset,
4964 uint16_t words,
4965 uint16_t *data)
4966{
4967 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4968 uint32_t i = 0;
4969
4970 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004971
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004972 /* If eeprom is not yet detected, do so now */
4973 if (eeprom->word_size == 0)
4974 e1000_init_eeprom_params(hw);
4975
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 /* A check for invalid values: offset too large, too many words, and not
4977 * enough words.
4978 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004979 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004981 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 return -E1000_ERR_EEPROM;
4983 }
4984
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004985 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4986 * directly. In this case, we need to acquire the EEPROM so that
4987 * FW or other port software does not interrupt.
4988 */
Jeff Kirsher4d3518582006-01-12 16:50:48 -08004989 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004990 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004991 /* Prepare the EEPROM for bit-bang reading */
4992 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4993 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004994 }
4995
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004996 /* Eerd register EEPROM access requires no eeprom aquire/release */
4997 if (eeprom->use_eerd == TRUE)
4998 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005000 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07005001 if (eeprom->type == e1000_eeprom_ich8)
5002 return e1000_read_eeprom_ich8(hw, offset, words, data);
5003
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005004 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5005 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07005006 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 uint16_t word_in;
5008 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5009
Auke Kok8fc897b2006-08-28 14:56:16 -07005010 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 e1000_release_eeprom(hw);
5012 return -E1000_ERR_EEPROM;
5013 }
5014
5015 e1000_standby_eeprom(hw);
5016
5017 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005018 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 read_opcode |= EEPROM_A8_OPCODE_SPI;
5020
5021 /* Send the READ command (opcode + addr) */
5022 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5023 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5024
5025 /* Read the data. The address of the eeprom internally increments with
5026 * each byte (spi) being read, saving on the overhead of eeprom setup
5027 * and tear-down. The address counter will roll over if reading beyond
5028 * the size of the eeprom, thus allowing the entire memory to be read
5029 * starting from any offset. */
5030 for (i = 0; i < words; i++) {
5031 word_in = e1000_shift_in_ee_bits(hw, 16);
5032 data[i] = (word_in >> 8) | (word_in << 8);
5033 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005034 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 for (i = 0; i < words; i++) {
5036 /* Send the READ command (opcode + addr) */
5037 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5038 eeprom->opcode_bits);
5039 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5040 eeprom->address_bits);
5041
5042 /* Read the data. For microwire, each word requires the overhead
5043 * of eeprom setup and tear-down. */
5044 data[i] = e1000_shift_in_ee_bits(hw, 16);
5045 e1000_standby_eeprom(hw);
5046 }
5047 }
5048
5049 /* End this read operation */
5050 e1000_release_eeprom(hw);
5051
5052 return E1000_SUCCESS;
5053}
5054
5055/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005056 * Reads a 16 bit word from the EEPROM using the EERD register.
5057 *
5058 * hw - Struct containing variables accessed by shared code
5059 * offset - offset of word in the EEPROM to read
5060 * data - word read from the EEPROM
5061 * words - number of words to read
5062 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005063static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005064e1000_read_eeprom_eerd(struct e1000_hw *hw,
5065 uint16_t offset,
5066 uint16_t words,
5067 uint16_t *data)
5068{
5069 uint32_t i, eerd = 0;
5070 int32_t error = 0;
5071
5072 for (i = 0; i < words; i++) {
5073 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5074 E1000_EEPROM_RW_REG_START;
5075
5076 E1000_WRITE_REG(hw, EERD, eerd);
5077 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005078
Auke Kok8fc897b2006-08-28 14:56:16 -07005079 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005080 break;
5081 }
5082 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005083
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005084 }
Auke Kok76c224b2006-05-23 13:36:06 -07005085
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005086 return error;
5087}
5088
5089/******************************************************************************
5090 * Writes a 16 bit word from the EEPROM using the EEWR register.
5091 *
5092 * hw - Struct containing variables accessed by shared code
5093 * offset - offset of word in the EEPROM to read
5094 * data - word read from the EEPROM
5095 * words - number of words to read
5096 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005097static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005098e1000_write_eeprom_eewr(struct e1000_hw *hw,
5099 uint16_t offset,
5100 uint16_t words,
5101 uint16_t *data)
5102{
5103 uint32_t register_value = 0;
5104 uint32_t i = 0;
5105 int32_t error = 0;
5106
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005107 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5108 return -E1000_ERR_SWFW_SYNC;
5109
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005110 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005111 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5112 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005113 E1000_EEPROM_RW_REG_START;
5114
5115 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005116 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005117 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005118 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005119
5120 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005121
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005122 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005123
Auke Kok8fc897b2006-08-28 14:56:16 -07005124 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005125 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005126 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005127 }
Auke Kok76c224b2006-05-23 13:36:06 -07005128
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005129 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005130 return error;
5131}
5132
5133/******************************************************************************
5134 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5135 *
5136 * hw - Struct containing variables accessed by shared code
5137 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005138static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005139e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5140{
5141 uint32_t attempts = 100000;
5142 uint32_t i, reg = 0;
5143 int32_t done = E1000_ERR_EEPROM;
5144
Auke Kok8fc897b2006-08-28 14:56:16 -07005145 for (i = 0; i < attempts; i++) {
5146 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005147 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005148 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005149 reg = E1000_READ_REG(hw, EEWR);
5150
Auke Kok8fc897b2006-08-28 14:56:16 -07005151 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005152 done = E1000_SUCCESS;
5153 break;
5154 }
5155 udelay(5);
5156 }
5157
5158 return done;
5159}
5160
5161/***************************************************************************
5162* Description: Determines if the onboard NVM is FLASH or EEPROM.
5163*
5164* hw - Struct containing variables accessed by shared code
5165****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005166static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005167e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5168{
5169 uint32_t eecd = 0;
5170
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005171 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5172
Auke Kokcd94dd02006-06-27 09:08:22 -07005173 if (hw->mac_type == e1000_ich8lan)
5174 return FALSE;
5175
5176 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005177 eecd = E1000_READ_REG(hw, EECD);
5178
5179 /* Isolate bits 15 & 16 */
5180 eecd = ((eecd >> 15) & 0x03);
5181
5182 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005183 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005184 return FALSE;
5185 }
5186 }
5187 return TRUE;
5188}
5189
5190/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 * Verifies that the EEPROM has a valid checksum
5192 *
5193 * hw - Struct containing variables accessed by shared code
5194 *
5195 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5196 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5197 * valid.
5198 *****************************************************************************/
5199int32_t
5200e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5201{
5202 uint16_t checksum = 0;
5203 uint16_t i, eeprom_data;
5204
5205 DEBUGFUNC("e1000_validate_eeprom_checksum");
5206
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005207 if ((hw->mac_type == e1000_82573) &&
5208 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5209 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5210 * 10h-12h. Checksum may need to be fixed. */
5211 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5212 if ((eeprom_data & 0x10) == 0) {
5213 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5214 * has already been fixed. If the checksum is still wrong and this
5215 * bit is a 1, we need to return bad checksum. Otherwise, we need
5216 * to set this bit to a 1 and update the checksum. */
5217 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5218 if ((eeprom_data & 0x8000) == 0) {
5219 eeprom_data |= 0x8000;
5220 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5221 e1000_update_eeprom_checksum(hw);
5222 }
5223 }
5224 }
5225
Auke Kokcd94dd02006-06-27 09:08:22 -07005226 if (hw->mac_type == e1000_ich8lan) {
5227 /* Drivers must allocate the shadow ram structure for the
5228 * EEPROM checksum to be updated. Otherwise, this bit as well
5229 * as the checksum must both be set correctly for this
5230 * validation to pass.
5231 */
5232 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5233 if ((eeprom_data & 0x40) == 0) {
5234 eeprom_data |= 0x40;
5235 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5236 e1000_update_eeprom_checksum(hw);
5237 }
5238 }
5239
5240 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5241 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242 DEBUGOUT("EEPROM Read Error\n");
5243 return -E1000_ERR_EEPROM;
5244 }
5245 checksum += eeprom_data;
5246 }
5247
Auke Kok8fc897b2006-08-28 14:56:16 -07005248 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 return E1000_SUCCESS;
5250 else {
5251 DEBUGOUT("EEPROM Checksum Invalid\n");
5252 return -E1000_ERR_EEPROM;
5253 }
5254}
5255
5256/******************************************************************************
5257 * Calculates the EEPROM checksum and writes it to the EEPROM
5258 *
5259 * hw - Struct containing variables accessed by shared code
5260 *
5261 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5262 * Writes the difference to word offset 63 of the EEPROM.
5263 *****************************************************************************/
5264int32_t
5265e1000_update_eeprom_checksum(struct e1000_hw *hw)
5266{
Auke Kokcd94dd02006-06-27 09:08:22 -07005267 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 uint16_t checksum = 0;
5269 uint16_t i, eeprom_data;
5270
5271 DEBUGFUNC("e1000_update_eeprom_checksum");
5272
Auke Kok8fc897b2006-08-28 14:56:16 -07005273 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5274 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 DEBUGOUT("EEPROM Read Error\n");
5276 return -E1000_ERR_EEPROM;
5277 }
5278 checksum += eeprom_data;
5279 }
5280 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005281 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 DEBUGOUT("EEPROM Write Error\n");
5283 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005284 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5285 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005286 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5287 e1000_commit_shadow_ram(hw);
5288 /* Reload the EEPROM, or else modifications will not appear
5289 * until after next adapter reset. */
5290 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5291 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5292 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005293 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 }
5295 return E1000_SUCCESS;
5296}
5297
5298/******************************************************************************
5299 * Parent function for writing words to the different EEPROM types.
5300 *
5301 * hw - Struct containing variables accessed by shared code
5302 * offset - offset within the EEPROM to be written to
5303 * words - number of words to write
5304 * data - 16 bit word to be written to the EEPROM
5305 *
5306 * If e1000_update_eeprom_checksum is not called after this function, the
5307 * EEPROM will most likely contain an invalid checksum.
5308 *****************************************************************************/
5309int32_t
5310e1000_write_eeprom(struct e1000_hw *hw,
5311 uint16_t offset,
5312 uint16_t words,
5313 uint16_t *data)
5314{
5315 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5316 int32_t status = 0;
5317
5318 DEBUGFUNC("e1000_write_eeprom");
5319
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005320 /* If eeprom is not yet detected, do so now */
5321 if (eeprom->word_size == 0)
5322 e1000_init_eeprom_params(hw);
5323
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324 /* A check for invalid values: offset too large, too many words, and not
5325 * enough words.
5326 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005327 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328 (words == 0)) {
5329 DEBUGOUT("\"words\" parameter out of bounds\n");
5330 return -E1000_ERR_EEPROM;
5331 }
5332
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005333 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005334 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005335 return e1000_write_eeprom_eewr(hw, offset, words, data);
5336
Auke Kokcd94dd02006-06-27 09:08:22 -07005337 if (eeprom->type == e1000_eeprom_ich8)
5338 return e1000_write_eeprom_ich8(hw, offset, words, data);
5339
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 /* Prepare the EEPROM for writing */
5341 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5342 return -E1000_ERR_EEPROM;
5343
Auke Kok8fc897b2006-08-28 14:56:16 -07005344 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5346 } else {
5347 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005348 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349 }
5350
5351 /* Done with writing */
5352 e1000_release_eeprom(hw);
5353
5354 return status;
5355}
5356
5357/******************************************************************************
5358 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5359 *
5360 * hw - Struct containing variables accessed by shared code
5361 * offset - offset within the EEPROM to be written to
5362 * words - number of words to write
5363 * data - pointer to array of 8 bit words to be written to the EEPROM
5364 *
5365 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005366static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367e1000_write_eeprom_spi(struct e1000_hw *hw,
5368 uint16_t offset,
5369 uint16_t words,
5370 uint16_t *data)
5371{
5372 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5373 uint16_t widx = 0;
5374
5375 DEBUGFUNC("e1000_write_eeprom_spi");
5376
5377 while (widx < words) {
5378 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5379
Auke Kok8fc897b2006-08-28 14:56:16 -07005380 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381
5382 e1000_standby_eeprom(hw);
5383
5384 /* Send the WRITE ENABLE command (8 bit opcode ) */
5385 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5386 eeprom->opcode_bits);
5387
5388 e1000_standby_eeprom(hw);
5389
5390 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005391 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392 write_opcode |= EEPROM_A8_OPCODE_SPI;
5393
5394 /* Send the Write command (8-bit opcode + addr) */
5395 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5396
5397 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5398 eeprom->address_bits);
5399
5400 /* Send the data */
5401
5402 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5403 while (widx < words) {
5404 uint16_t word_out = data[widx];
5405 word_out = (word_out >> 8) | (word_out << 8);
5406 e1000_shift_out_ee_bits(hw, word_out, 16);
5407 widx++;
5408
5409 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5410 * operation, while the smaller eeproms are capable of an 8-byte
5411 * PAGE WRITE operation. Break the inner loop to pass new address
5412 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005413 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 e1000_standby_eeprom(hw);
5415 break;
5416 }
5417 }
5418 }
5419
5420 return E1000_SUCCESS;
5421}
5422
5423/******************************************************************************
5424 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5425 *
5426 * hw - Struct containing variables accessed by shared code
5427 * offset - offset within the EEPROM to be written to
5428 * words - number of words to write
5429 * data - pointer to array of 16 bit words to be written to the EEPROM
5430 *
5431 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005432static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433e1000_write_eeprom_microwire(struct e1000_hw *hw,
5434 uint16_t offset,
5435 uint16_t words,
5436 uint16_t *data)
5437{
5438 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5439 uint32_t eecd;
5440 uint16_t words_written = 0;
5441 uint16_t i = 0;
5442
5443 DEBUGFUNC("e1000_write_eeprom_microwire");
5444
5445 /* Send the write enable command to the EEPROM (3-bit opcode plus
5446 * 6/8-bit dummy address beginning with 11). It's less work to include
5447 * the 11 of the dummy address as part of the opcode than it is to shift
5448 * it over the correct number of bits for the address. This puts the
5449 * EEPROM into write/erase mode.
5450 */
5451 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5452 (uint16_t)(eeprom->opcode_bits + 2));
5453
5454 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5455
5456 /* Prepare the EEPROM */
5457 e1000_standby_eeprom(hw);
5458
5459 while (words_written < words) {
5460 /* Send the Write command (3-bit opcode + addr) */
5461 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5462 eeprom->opcode_bits);
5463
5464 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5465 eeprom->address_bits);
5466
5467 /* Send the data */
5468 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5469
5470 /* Toggle the CS line. This in effect tells the EEPROM to execute
5471 * the previous command.
5472 */
5473 e1000_standby_eeprom(hw);
5474
5475 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5476 * signal that the command has been completed by raising the DO signal.
5477 * If DO does not go high in 10 milliseconds, then error out.
5478 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005479 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005481 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482 udelay(50);
5483 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005484 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485 DEBUGOUT("EEPROM Write did not complete\n");
5486 return -E1000_ERR_EEPROM;
5487 }
5488
5489 /* Recover from write */
5490 e1000_standby_eeprom(hw);
5491
5492 words_written++;
5493 }
5494
5495 /* Send the write disable command to the EEPROM (3-bit opcode plus
5496 * 6/8-bit dummy address beginning with 10). It's less work to include
5497 * the 10 of the dummy address as part of the opcode than it is to shift
5498 * it over the correct number of bits for the address. This takes the
5499 * EEPROM out of write/erase mode.
5500 */
5501 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5502 (uint16_t)(eeprom->opcode_bits + 2));
5503
5504 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5505
5506 return E1000_SUCCESS;
5507}
5508
5509/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005510 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5511 * in the eeprom cache and the non modified values in the currently active bank
5512 * to the new bank.
5513 *
5514 * hw - Struct containing variables accessed by shared code
5515 * offset - offset of word in the EEPROM to read
5516 * data - word read from the EEPROM
5517 * words - number of words to read
5518 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005519static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005520e1000_commit_shadow_ram(struct e1000_hw *hw)
5521{
5522 uint32_t attempts = 100000;
5523 uint32_t eecd = 0;
5524 uint32_t flop = 0;
5525 uint32_t i = 0;
5526 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005527 uint32_t old_bank_offset = 0;
5528 uint32_t new_bank_offset = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005529 uint8_t low_byte = 0;
5530 uint8_t high_byte = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005531 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005532
5533 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005534 /* The flop register will be used to determine if flash type is STM */
5535 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005536 for (i=0; i < attempts; i++) {
5537 eecd = E1000_READ_REG(hw, EECD);
5538 if ((eecd & E1000_EECD_FLUPD) == 0) {
5539 break;
5540 }
5541 udelay(5);
5542 }
5543
5544 if (i == attempts) {
5545 return -E1000_ERR_EEPROM;
5546 }
5547
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005548 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005549 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5550 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5551 }
5552
5553 /* Perform the flash update */
5554 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5555
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005556 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005557 eecd = E1000_READ_REG(hw, EECD);
5558 if ((eecd & E1000_EECD_FLUPD) == 0) {
5559 break;
5560 }
5561 udelay(5);
5562 }
5563
5564 if (i == attempts) {
5565 return -E1000_ERR_EEPROM;
5566 }
5567 }
5568
Auke Kokcd94dd02006-06-27 09:08:22 -07005569 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5570 /* We're writing to the opposite bank so if we're on bank 1,
5571 * write to bank 0 etc. We also need to erase the segment that
5572 * is going to be written */
5573 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5574 new_bank_offset = hw->flash_bank_size * 2;
5575 old_bank_offset = 0;
5576 e1000_erase_ich8_4k_segment(hw, 1);
5577 } else {
5578 old_bank_offset = hw->flash_bank_size * 2;
5579 new_bank_offset = 0;
5580 e1000_erase_ich8_4k_segment(hw, 0);
5581 }
5582
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005583 sector_write_failed = FALSE;
5584 /* Loop for every byte in the shadow RAM,
5585 * which is in units of words. */
5586 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5587 /* Determine whether to write the value stored
5588 * in the other NVM bank or a modified value stored
5589 * in the shadow RAM */
5590 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5591 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5592 udelay(100);
5593 error = e1000_verify_write_ich8_byte(hw,
5594 (i << 1) + new_bank_offset, low_byte);
5595
5596 if (error != E1000_SUCCESS)
5597 sector_write_failed = TRUE;
5598 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005599 high_byte =
5600 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005601 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005602 }
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
5610 if (error != E1000_SUCCESS)
5611 sector_write_failed = TRUE;
5612 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005613 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5614 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005615 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005616 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005617 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005618
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005619 /* If the write of the low byte was successful, go ahread and
5620 * write the high byte while checking to make sure that if it
5621 * is the signature byte, then it is handled properly */
5622 if (sector_write_failed == FALSE) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005623 /* If the word is 0x13, then make sure the signature bits
5624 * (15:14) are 11b until the commit has completed.
5625 * This will allow us to write 10b which indicates the
5626 * signature is valid. We want to do this after the write
5627 * has completed so that we don't mark the segment valid
5628 * while the write is still in progress */
5629 if (i == E1000_ICH8_NVM_SIG_WORD)
5630 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5631
5632 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005633 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005634 if (error != E1000_SUCCESS)
5635 sector_write_failed = TRUE;
5636
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005637 } else {
5638 /* If the write failed then break from the loop and
5639 * return an error */
5640 break;
5641 }
5642 }
5643
5644 /* Don't bother writing the segment valid bits if sector
5645 * programming failed. */
5646 if (sector_write_failed == FALSE) {
5647 /* Finally validate the new segment by setting bit 15:14
5648 * to 10b in word 0x13 , this can be done without an
5649 * erase as well since these bits are 11 to start with
5650 * and we need to change bit 14 to 0b */
5651 e1000_read_ich8_byte(hw,
5652 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5653 &high_byte);
5654 high_byte &= 0xBF;
5655 error = e1000_verify_write_ich8_byte(hw,
5656 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5657 /* And invalidate the previously valid segment by setting
5658 * its signature word (0x13) high_byte to 0b. This can be
5659 * done without an erase because flash erase sets all bits
5660 * to 1's. We can write 1's to 0's without an erase */
5661 if (error == E1000_SUCCESS) {
5662 error = e1000_verify_write_ich8_byte(hw,
5663 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005664 }
5665
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005666 /* Clear the now not used entry in the cache */
5667 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5668 hw->eeprom_shadow_ram[i].modified = FALSE;
5669 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005670 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005671 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005672 }
5673
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005674 return error;
5675}
5676
5677/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5679 * second function of dual function devices
5680 *
5681 * hw - Struct containing variables accessed by shared code
5682 *****************************************************************************/
5683int32_t
5684e1000_read_mac_addr(struct e1000_hw * hw)
5685{
5686 uint16_t offset;
5687 uint16_t eeprom_data, i;
5688
5689 DEBUGFUNC("e1000_read_mac_addr");
5690
Auke Kok8fc897b2006-08-28 14:56:16 -07005691 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005693 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694 DEBUGOUT("EEPROM Read Error\n");
5695 return -E1000_ERR_EEPROM;
5696 }
5697 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5698 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5699 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005700
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005701 switch (hw->mac_type) {
5702 default:
5703 break;
5704 case e1000_82546:
5705 case e1000_82546_rev_3:
5706 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005707 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005708 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005710 break;
5711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712
Auke Kok8fc897b2006-08-28 14:56:16 -07005713 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714 hw->mac_addr[i] = hw->perm_mac_addr[i];
5715 return E1000_SUCCESS;
5716}
5717
5718/******************************************************************************
5719 * Initializes receive address filters.
5720 *
5721 * hw - Struct containing variables accessed by shared code
5722 *
5723 * Places the MAC address in receive address register 0 and clears the rest
5724 * of the receive addresss registers. Clears the multicast table. Assumes
5725 * the receiver is in reset when the routine is called.
5726 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005727static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728e1000_init_rx_addrs(struct e1000_hw *hw)
5729{
5730 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005731 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732
5733 DEBUGFUNC("e1000_init_rx_addrs");
5734
5735 /* Setup the receive address. */
5736 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5737
5738 e1000_rar_set(hw, hw->mac_addr, 0);
5739
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005740 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005741
5742 /* Reserve a spot for the Locally Administered Address to work around
5743 * an 82571 issue in which a reset on one port will reload the MAC on
5744 * the other port. */
5745 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5746 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005747 if (hw->mac_type == e1000_ich8lan)
5748 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5749
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 /* Zero out the other 15 receive addresses. */
5751 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005752 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005754 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005756 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757 }
5758}
5759
5760/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 * Hashes an address to determine its location in the multicast table
5762 *
5763 * hw - Struct containing variables accessed by shared code
5764 * mc_addr - the multicast address to hash
5765 *****************************************************************************/
5766uint32_t
5767e1000_hash_mc_addr(struct e1000_hw *hw,
5768 uint8_t *mc_addr)
5769{
5770 uint32_t hash_value = 0;
5771
5772 /* The portion of the address that is used for the hash table is
5773 * determined by the mc_filter_type setting.
5774 */
5775 switch (hw->mc_filter_type) {
5776 /* [0] [1] [2] [3] [4] [5]
5777 * 01 AA 00 12 34 56
5778 * LSB MSB
5779 */
5780 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005781 if (hw->mac_type == e1000_ich8lan) {
5782 /* [47:38] i.e. 0x158 for above example address */
5783 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5784 } else {
5785 /* [47:36] i.e. 0x563 for above example address */
5786 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 break;
5789 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005790 if (hw->mac_type == e1000_ich8lan) {
5791 /* [46:37] i.e. 0x2B1 for above example address */
5792 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5793 } else {
5794 /* [46:35] i.e. 0xAC6 for above example address */
5795 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797 break;
5798 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005799 if (hw->mac_type == e1000_ich8lan) {
5800 /*[45:36] i.e. 0x163 for above example address */
5801 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5802 } else {
5803 /* [45:34] i.e. 0x5D8 for above example address */
5804 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806 break;
5807 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005808 if (hw->mac_type == e1000_ich8lan) {
5809 /* [43:34] i.e. 0x18D for above example address */
5810 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5811 } else {
5812 /* [43:32] i.e. 0x634 for above example address */
5813 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815 break;
5816 }
5817
5818 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005819 if (hw->mac_type == e1000_ich8lan)
5820 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005821
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 return hash_value;
5823}
5824
5825/******************************************************************************
5826 * Sets the bit in the multicast table corresponding to the hash value.
5827 *
5828 * hw - Struct containing variables accessed by shared code
5829 * hash_value - Multicast address hash value
5830 *****************************************************************************/
5831void
5832e1000_mta_set(struct e1000_hw *hw,
5833 uint32_t hash_value)
5834{
5835 uint32_t hash_bit, hash_reg;
5836 uint32_t mta;
5837 uint32_t temp;
5838
5839 /* The MTA is a register array of 128 32-bit registers.
5840 * It is treated like an array of 4096 bits. We want to set
5841 * bit BitArray[hash_value]. So we figure out what register
5842 * the bit is in, read it, OR in the new bit, then write
5843 * back the new value. The register is determined by the
5844 * upper 7 bits of the hash value and the bit within that
5845 * register are determined by the lower 5 bits of the value.
5846 */
5847 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005848 if (hw->mac_type == e1000_ich8lan)
5849 hash_reg &= 0x1F;
Auke Kok90fb5132006-11-01 08:47:30 -08005850
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851 hash_bit = hash_value & 0x1F;
5852
5853 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5854
5855 mta |= (1 << hash_bit);
5856
5857 /* If we are on an 82544 and we are trying to write an odd offset
5858 * in the MTA, save off the previous entry before writing and
5859 * restore the old value after writing.
5860 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005861 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5863 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005864 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005866 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 } else {
5868 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005869 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 }
5871}
5872
5873/******************************************************************************
5874 * Puts an ethernet address into a receive address register.
5875 *
5876 * hw - Struct containing variables accessed by shared code
5877 * addr - Address to put into receive address register
5878 * index - Receive address register to write
5879 *****************************************************************************/
5880void
5881e1000_rar_set(struct e1000_hw *hw,
5882 uint8_t *addr,
5883 uint32_t index)
5884{
5885 uint32_t rar_low, rar_high;
5886
5887 /* HW expects these in little endian so we reverse the byte order
5888 * from network order (big endian) to little endian
5889 */
5890 rar_low = ((uint32_t) addr[0] |
5891 ((uint32_t) addr[1] << 8) |
5892 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005893 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005895 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5896 * unit hang.
5897 *
5898 * Description:
5899 * If there are any Rx frames queued up or otherwise present in the HW
5900 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5901 * hang. To work around this issue, we have to disable receives and
5902 * flush out all Rx frames before we enable RSS. To do so, we modify we
5903 * redirect all Rx traffic to manageability and then reset the HW.
5904 * This flushes away Rx frames, and (since the redirections to
5905 * manageability persists across resets) keeps new ones from coming in
5906 * while we work. Then, we clear the Address Valid AV bit for all MAC
5907 * addresses and undo the re-direction to manageability.
5908 * Now, frames are coming in again, but the MAC won't accept them, so
5909 * far so good. We now proceed to initialize RSS (if necessary) and
5910 * configure the Rx unit. Last, we re-enable the AV bits and continue
5911 * on our merry way.
5912 */
5913 switch (hw->mac_type) {
5914 case e1000_82571:
5915 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005916 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005917 if (hw->leave_av_bit_off == TRUE)
5918 break;
5919 default:
5920 /* Indicate to hardware the Address is Valid. */
5921 rar_high |= E1000_RAH_AV;
5922 break;
5923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924
5925 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005926 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005928 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929}
5930
5931/******************************************************************************
5932 * Writes a value to the specified offset in the VLAN filter table.
5933 *
5934 * hw - Struct containing variables accessed by shared code
5935 * offset - Offset in VLAN filer table to write
5936 * value - Value to write into VLAN filter table
5937 *****************************************************************************/
5938void
5939e1000_write_vfta(struct e1000_hw *hw,
5940 uint32_t offset,
5941 uint32_t value)
5942{
5943 uint32_t temp;
5944
Auke Kokcd94dd02006-06-27 09:08:22 -07005945 if (hw->mac_type == e1000_ich8lan)
5946 return;
5947
5948 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5950 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005951 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005953 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 } else {
5955 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005956 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957 }
5958}
5959
5960/******************************************************************************
5961 * Clears the VLAN filer table
5962 *
5963 * hw - Struct containing variables accessed by shared code
5964 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005965static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966e1000_clear_vfta(struct e1000_hw *hw)
5967{
5968 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005969 uint32_t vfta_value = 0;
5970 uint32_t vfta_offset = 0;
5971 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972
Auke Kokcd94dd02006-06-27 09:08:22 -07005973 if (hw->mac_type == e1000_ich8lan)
5974 return;
5975
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005976 if (hw->mac_type == e1000_82573) {
5977 if (hw->mng_cookie.vlan_id != 0) {
5978 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5979 * ID. The following operations determine which 32b entry
5980 * (i.e. offset) into the array we want to set the VLAN ID
5981 * (i.e. bit) of the manageability unit. */
5982 vfta_offset = (hw->mng_cookie.vlan_id >>
5983 E1000_VFTA_ENTRY_SHIFT) &
5984 E1000_VFTA_ENTRY_MASK;
5985 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5986 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5987 }
5988 }
5989 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5990 /* If the offset we want to clear is the same offset of the
5991 * manageability VLAN ID, then clear all bits except that of the
5992 * manageability unit */
5993 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5994 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005995 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997}
5998
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005999static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000e1000_id_led_init(struct e1000_hw * hw)
6001{
6002 uint32_t ledctl;
6003 const uint32_t ledctl_mask = 0x000000FF;
6004 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6005 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6006 uint16_t eeprom_data, i, temp;
6007 const uint16_t led_mask = 0x0F;
6008
6009 DEBUGFUNC("e1000_id_led_init");
6010
Auke Kok8fc897b2006-08-28 14:56:16 -07006011 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 /* Nothing to do */
6013 return E1000_SUCCESS;
6014 }
6015
6016 ledctl = E1000_READ_REG(hw, LEDCTL);
6017 hw->ledctl_default = ledctl;
6018 hw->ledctl_mode1 = hw->ledctl_default;
6019 hw->ledctl_mode2 = hw->ledctl_default;
6020
Auke Kok8fc897b2006-08-28 14:56:16 -07006021 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 DEBUGOUT("EEPROM Read Error\n");
6023 return -E1000_ERR_EEPROM;
6024 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006025
6026 if ((hw->mac_type == e1000_82573) &&
6027 (eeprom_data == ID_LED_RESERVED_82573))
6028 eeprom_data = ID_LED_DEFAULT_82573;
6029 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6030 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6031 if (hw->mac_type == e1000_ich8lan)
6032 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6033 else
6034 eeprom_data = ID_LED_DEFAULT;
6035 }
Auke Kok90fb5132006-11-01 08:47:30 -08006036
Auke Kokcd94dd02006-06-27 09:08:22 -07006037 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006039 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040 case ID_LED_ON1_DEF2:
6041 case ID_LED_ON1_ON2:
6042 case ID_LED_ON1_OFF2:
6043 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6044 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6045 break;
6046 case ID_LED_OFF1_DEF2:
6047 case ID_LED_OFF1_ON2:
6048 case ID_LED_OFF1_OFF2:
6049 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6050 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6051 break;
6052 default:
6053 /* Do nothing */
6054 break;
6055 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006056 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057 case ID_LED_DEF1_ON2:
6058 case ID_LED_ON1_ON2:
6059 case ID_LED_OFF1_ON2:
6060 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6061 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6062 break;
6063 case ID_LED_DEF1_OFF2:
6064 case ID_LED_ON1_OFF2:
6065 case ID_LED_OFF1_OFF2:
6066 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6067 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6068 break;
6069 default:
6070 /* Do nothing */
6071 break;
6072 }
6073 }
6074 return E1000_SUCCESS;
6075}
6076
6077/******************************************************************************
6078 * Prepares SW controlable LED for use and saves the current state of the LED.
6079 *
6080 * hw - Struct containing variables accessed by shared code
6081 *****************************************************************************/
6082int32_t
6083e1000_setup_led(struct e1000_hw *hw)
6084{
6085 uint32_t ledctl;
6086 int32_t ret_val = E1000_SUCCESS;
6087
6088 DEBUGFUNC("e1000_setup_led");
6089
Auke Kok8fc897b2006-08-28 14:56:16 -07006090 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 case e1000_82542_rev2_0:
6092 case e1000_82542_rev2_1:
6093 case e1000_82543:
6094 case e1000_82544:
6095 /* No setup necessary */
6096 break;
6097 case e1000_82541:
6098 case e1000_82547:
6099 case e1000_82541_rev_2:
6100 case e1000_82547_rev_2:
6101 /* Turn off PHY Smart Power Down (if enabled) */
6102 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6103 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006104 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 return ret_val;
6106 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6107 (uint16_t)(hw->phy_spd_default &
6108 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006109 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 return ret_val;
6111 /* Fall Through */
6112 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006113 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 ledctl = E1000_READ_REG(hw, LEDCTL);
6115 /* Save current LEDCTL settings */
6116 hw->ledctl_default = ledctl;
6117 /* Turn off LED0 */
6118 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6119 E1000_LEDCTL_LED0_BLINK |
6120 E1000_LEDCTL_LED0_MODE_MASK);
6121 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6122 E1000_LEDCTL_LED0_MODE_SHIFT);
6123 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006124 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6126 break;
6127 }
6128
6129 return E1000_SUCCESS;
6130}
6131
Auke Kok8fc897b2006-08-28 14:56:16 -07006132
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006134 * Used on 82571 and later Si that has LED blink bits.
6135 * Callers must use their own timer and should have already called
6136 * e1000_id_led_init()
6137 * Call e1000_cleanup led() to stop blinking
6138 *
6139 * hw - Struct containing variables accessed by shared code
6140 *****************************************************************************/
6141int32_t
6142e1000_blink_led_start(struct e1000_hw *hw)
6143{
6144 int16_t i;
6145 uint32_t ledctl_blink = 0;
6146
6147 DEBUGFUNC("e1000_id_led_blink_on");
6148
6149 if (hw->mac_type < e1000_82571) {
6150 /* Nothing to do */
6151 return E1000_SUCCESS;
6152 }
6153 if (hw->media_type == e1000_media_type_fiber) {
6154 /* always blink LED0 for PCI-E fiber */
6155 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6156 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6157 } else {
6158 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6159 ledctl_blink = hw->ledctl_mode2;
6160 for (i=0; i < 4; i++)
6161 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6162 E1000_LEDCTL_MODE_LED_ON)
6163 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6164 }
6165
6166 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6167
6168 return E1000_SUCCESS;
6169}
6170
6171/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172 * Restores the saved state of the SW controlable LED.
6173 *
6174 * hw - Struct containing variables accessed by shared code
6175 *****************************************************************************/
6176int32_t
6177e1000_cleanup_led(struct e1000_hw *hw)
6178{
6179 int32_t ret_val = E1000_SUCCESS;
6180
6181 DEBUGFUNC("e1000_cleanup_led");
6182
Auke Kok8fc897b2006-08-28 14:56:16 -07006183 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 case e1000_82542_rev2_0:
6185 case e1000_82542_rev2_1:
6186 case e1000_82543:
6187 case e1000_82544:
6188 /* No cleanup necessary */
6189 break;
6190 case e1000_82541:
6191 case e1000_82547:
6192 case e1000_82541_rev_2:
6193 case e1000_82547_rev_2:
6194 /* Turn on PHY Smart Power Down (if previously enabled) */
6195 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6196 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006197 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 return ret_val;
6199 /* Fall Through */
6200 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006201 if (hw->phy_type == e1000_phy_ife) {
6202 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6203 break;
6204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 /* Restore LEDCTL settings */
6206 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6207 break;
6208 }
6209
6210 return E1000_SUCCESS;
6211}
6212
6213/******************************************************************************
6214 * Turns on the software controllable LED
6215 *
6216 * hw - Struct containing variables accessed by shared code
6217 *****************************************************************************/
6218int32_t
6219e1000_led_on(struct e1000_hw *hw)
6220{
6221 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6222
6223 DEBUGFUNC("e1000_led_on");
6224
Auke Kok8fc897b2006-08-28 14:56:16 -07006225 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 case e1000_82542_rev2_0:
6227 case e1000_82542_rev2_1:
6228 case e1000_82543:
6229 /* Set SW Defineable Pin 0 to turn on the LED */
6230 ctrl |= E1000_CTRL_SWDPIN0;
6231 ctrl |= E1000_CTRL_SWDPIO0;
6232 break;
6233 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006234 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 /* Set SW Defineable Pin 0 to turn on the LED */
6236 ctrl |= E1000_CTRL_SWDPIN0;
6237 ctrl |= E1000_CTRL_SWDPIO0;
6238 } else {
6239 /* Clear SW Defineable Pin 0 to turn on the LED */
6240 ctrl &= ~E1000_CTRL_SWDPIN0;
6241 ctrl |= E1000_CTRL_SWDPIO0;
6242 }
6243 break;
6244 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006245 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 /* Clear SW Defineable Pin 0 to turn on the LED */
6247 ctrl &= ~E1000_CTRL_SWDPIN0;
6248 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006249 } else if (hw->phy_type == e1000_phy_ife) {
6250 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6251 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6252 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6254 return E1000_SUCCESS;
6255 }
6256 break;
6257 }
6258
6259 E1000_WRITE_REG(hw, CTRL, ctrl);
6260
6261 return E1000_SUCCESS;
6262}
6263
6264/******************************************************************************
6265 * Turns off the software controllable LED
6266 *
6267 * hw - Struct containing variables accessed by shared code
6268 *****************************************************************************/
6269int32_t
6270e1000_led_off(struct e1000_hw *hw)
6271{
6272 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6273
6274 DEBUGFUNC("e1000_led_off");
6275
Auke Kok8fc897b2006-08-28 14:56:16 -07006276 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 case e1000_82542_rev2_0:
6278 case e1000_82542_rev2_1:
6279 case e1000_82543:
6280 /* Clear SW Defineable Pin 0 to turn off the LED */
6281 ctrl &= ~E1000_CTRL_SWDPIN0;
6282 ctrl |= E1000_CTRL_SWDPIO0;
6283 break;
6284 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006285 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 /* Clear SW Defineable Pin 0 to turn off the LED */
6287 ctrl &= ~E1000_CTRL_SWDPIN0;
6288 ctrl |= E1000_CTRL_SWDPIO0;
6289 } else {
6290 /* Set SW Defineable Pin 0 to turn off the LED */
6291 ctrl |= E1000_CTRL_SWDPIN0;
6292 ctrl |= E1000_CTRL_SWDPIO0;
6293 }
6294 break;
6295 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006296 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 /* Set SW Defineable Pin 0 to turn off the LED */
6298 ctrl |= E1000_CTRL_SWDPIN0;
6299 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006300 } else if (hw->phy_type == e1000_phy_ife) {
6301 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6302 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6303 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6305 return E1000_SUCCESS;
6306 }
6307 break;
6308 }
6309
6310 E1000_WRITE_REG(hw, CTRL, ctrl);
6311
6312 return E1000_SUCCESS;
6313}
6314
6315/******************************************************************************
6316 * Clears all hardware statistics counters.
6317 *
6318 * hw - Struct containing variables accessed by shared code
6319 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006320static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321e1000_clear_hw_cntrs(struct e1000_hw *hw)
6322{
6323 volatile uint32_t temp;
6324
6325 temp = E1000_READ_REG(hw, CRCERRS);
6326 temp = E1000_READ_REG(hw, SYMERRS);
6327 temp = E1000_READ_REG(hw, MPC);
6328 temp = E1000_READ_REG(hw, SCC);
6329 temp = E1000_READ_REG(hw, ECOL);
6330 temp = E1000_READ_REG(hw, MCC);
6331 temp = E1000_READ_REG(hw, LATECOL);
6332 temp = E1000_READ_REG(hw, COLC);
6333 temp = E1000_READ_REG(hw, DC);
6334 temp = E1000_READ_REG(hw, SEC);
6335 temp = E1000_READ_REG(hw, RLEC);
6336 temp = E1000_READ_REG(hw, XONRXC);
6337 temp = E1000_READ_REG(hw, XONTXC);
6338 temp = E1000_READ_REG(hw, XOFFRXC);
6339 temp = E1000_READ_REG(hw, XOFFTXC);
6340 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006341
6342 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 temp = E1000_READ_REG(hw, PRC64);
6344 temp = E1000_READ_REG(hw, PRC127);
6345 temp = E1000_READ_REG(hw, PRC255);
6346 temp = E1000_READ_REG(hw, PRC511);
6347 temp = E1000_READ_REG(hw, PRC1023);
6348 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006349 }
6350
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 temp = E1000_READ_REG(hw, GPRC);
6352 temp = E1000_READ_REG(hw, BPRC);
6353 temp = E1000_READ_REG(hw, MPRC);
6354 temp = E1000_READ_REG(hw, GPTC);
6355 temp = E1000_READ_REG(hw, GORCL);
6356 temp = E1000_READ_REG(hw, GORCH);
6357 temp = E1000_READ_REG(hw, GOTCL);
6358 temp = E1000_READ_REG(hw, GOTCH);
6359 temp = E1000_READ_REG(hw, RNBC);
6360 temp = E1000_READ_REG(hw, RUC);
6361 temp = E1000_READ_REG(hw, RFC);
6362 temp = E1000_READ_REG(hw, ROC);
6363 temp = E1000_READ_REG(hw, RJC);
6364 temp = E1000_READ_REG(hw, TORL);
6365 temp = E1000_READ_REG(hw, TORH);
6366 temp = E1000_READ_REG(hw, TOTL);
6367 temp = E1000_READ_REG(hw, TOTH);
6368 temp = E1000_READ_REG(hw, TPR);
6369 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006370
6371 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 temp = E1000_READ_REG(hw, PTC64);
6373 temp = E1000_READ_REG(hw, PTC127);
6374 temp = E1000_READ_REG(hw, PTC255);
6375 temp = E1000_READ_REG(hw, PTC511);
6376 temp = E1000_READ_REG(hw, PTC1023);
6377 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006378 }
6379
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380 temp = E1000_READ_REG(hw, MPTC);
6381 temp = E1000_READ_REG(hw, BPTC);
6382
Auke Kok8fc897b2006-08-28 14:56:16 -07006383 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384
6385 temp = E1000_READ_REG(hw, ALGNERRC);
6386 temp = E1000_READ_REG(hw, RXERRC);
6387 temp = E1000_READ_REG(hw, TNCRS);
6388 temp = E1000_READ_REG(hw, CEXTERR);
6389 temp = E1000_READ_REG(hw, TSCTC);
6390 temp = E1000_READ_REG(hw, TSCTFC);
6391
Auke Kok8fc897b2006-08-28 14:56:16 -07006392 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393
6394 temp = E1000_READ_REG(hw, MGTPRC);
6395 temp = E1000_READ_REG(hw, MGTPDC);
6396 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006397
Auke Kok8fc897b2006-08-28 14:56:16 -07006398 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006399
6400 temp = E1000_READ_REG(hw, IAC);
6401 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006402
6403 if (hw->mac_type == e1000_ich8lan) return;
6404
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006405 temp = E1000_READ_REG(hw, ICRXPTC);
6406 temp = E1000_READ_REG(hw, ICRXATC);
6407 temp = E1000_READ_REG(hw, ICTXPTC);
6408 temp = E1000_READ_REG(hw, ICTXATC);
6409 temp = E1000_READ_REG(hw, ICTXQEC);
6410 temp = E1000_READ_REG(hw, ICTXQMTC);
6411 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412}
6413
6414/******************************************************************************
6415 * Resets Adaptive IFS to its default state.
6416 *
6417 * hw - Struct containing variables accessed by shared code
6418 *
6419 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6420 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6421 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6422 * before calling this function.
6423 *****************************************************************************/
6424void
6425e1000_reset_adaptive(struct e1000_hw *hw)
6426{
6427 DEBUGFUNC("e1000_reset_adaptive");
6428
Auke Kok8fc897b2006-08-28 14:56:16 -07006429 if (hw->adaptive_ifs) {
6430 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 hw->current_ifs_val = 0;
6432 hw->ifs_min_val = IFS_MIN;
6433 hw->ifs_max_val = IFS_MAX;
6434 hw->ifs_step_size = IFS_STEP;
6435 hw->ifs_ratio = IFS_RATIO;
6436 }
6437 hw->in_ifs_mode = FALSE;
6438 E1000_WRITE_REG(hw, AIT, 0);
6439 } else {
6440 DEBUGOUT("Not in Adaptive IFS mode!\n");
6441 }
6442}
6443
6444/******************************************************************************
6445 * Called during the callback/watchdog routine to update IFS value based on
6446 * the ratio of transmits to collisions.
6447 *
6448 * hw - Struct containing variables accessed by shared code
6449 * tx_packets - Number of transmits since last callback
6450 * total_collisions - Number of collisions since last callback
6451 *****************************************************************************/
6452void
6453e1000_update_adaptive(struct e1000_hw *hw)
6454{
6455 DEBUGFUNC("e1000_update_adaptive");
6456
Auke Kok8fc897b2006-08-28 14:56:16 -07006457 if (hw->adaptive_ifs) {
6458 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6459 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006461 if (hw->current_ifs_val < hw->ifs_max_val) {
6462 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 hw->current_ifs_val = hw->ifs_min_val;
6464 else
6465 hw->current_ifs_val += hw->ifs_step_size;
6466 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6467 }
6468 }
6469 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006470 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 hw->current_ifs_val = 0;
6472 hw->in_ifs_mode = FALSE;
6473 E1000_WRITE_REG(hw, AIT, 0);
6474 }
6475 }
6476 } else {
6477 DEBUGOUT("Not in Adaptive IFS mode!\n");
6478 }
6479}
6480
6481/******************************************************************************
6482 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6483 *
6484 * hw - Struct containing variables accessed by shared code
6485 * frame_len - The length of the frame in question
6486 * mac_addr - The Ethernet destination address of the frame in question
6487 *****************************************************************************/
6488void
6489e1000_tbi_adjust_stats(struct e1000_hw *hw,
6490 struct e1000_hw_stats *stats,
6491 uint32_t frame_len,
6492 uint8_t *mac_addr)
6493{
6494 uint64_t carry_bit;
6495
6496 /* First adjust the frame length. */
6497 frame_len--;
6498 /* We need to adjust the statistics counters, since the hardware
6499 * counters overcount this packet as a CRC error and undercount
6500 * the packet as a good packet
6501 */
6502 /* This packet should not be counted as a CRC error. */
6503 stats->crcerrs--;
6504 /* This packet does count as a Good Packet Received. */
6505 stats->gprc++;
6506
6507 /* Adjust the Good Octets received counters */
6508 carry_bit = 0x80000000 & stats->gorcl;
6509 stats->gorcl += frame_len;
6510 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6511 * Received Count) was one before the addition,
6512 * AND it is zero after, then we lost the carry out,
6513 * need to add one to Gorch (Good Octets Received Count High).
6514 * This could be simplified if all environments supported
6515 * 64-bit integers.
6516 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006517 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 stats->gorch++;
6519 /* Is this a broadcast or multicast? Check broadcast first,
6520 * since the test for a multicast frame will test positive on
6521 * a broadcast frame.
6522 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006523 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 /* Broadcast packet */
6525 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006526 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 /* Multicast packet */
6528 stats->mprc++;
6529
Auke Kok8fc897b2006-08-28 14:56:16 -07006530 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531 /* In this case, the hardware has overcounted the number of
6532 * oversize frames.
6533 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006534 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 stats->roc--;
6536 }
6537
6538 /* Adjust the bin counters when the extra byte put the frame in the
6539 * wrong bin. Remember that the frame_len was adjusted above.
6540 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006541 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 stats->prc64++;
6543 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006544 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 stats->prc127++;
6546 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006547 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 stats->prc255++;
6549 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006550 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 stats->prc511++;
6552 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006553 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 stats->prc1023++;
6555 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006556 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557 stats->prc1522++;
6558 }
6559}
6560
6561/******************************************************************************
6562 * Gets the current PCI bus type, speed, and width of the hardware
6563 *
6564 * hw - Struct containing variables accessed by shared code
6565 *****************************************************************************/
6566void
6567e1000_get_bus_info(struct e1000_hw *hw)
6568{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006569 int32_t ret_val;
6570 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571 uint32_t status;
6572
6573 switch (hw->mac_type) {
6574 case e1000_82542_rev2_0:
6575 case e1000_82542_rev2_1:
6576 hw->bus_type = e1000_bus_type_unknown;
6577 hw->bus_speed = e1000_bus_speed_unknown;
6578 hw->bus_width = e1000_bus_width_unknown;
6579 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006580 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006581 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006582 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006583 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006584 hw->bus_type = e1000_bus_type_pci_express;
6585 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006586 ret_val = e1000_read_pcie_cap_reg(hw,
6587 PCI_EX_LINK_STATUS,
6588 &pci_ex_link_status);
6589 if (ret_val)
6590 hw->bus_width = e1000_bus_width_unknown;
6591 else
6592 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6593 PCI_EX_LINK_WIDTH_SHIFT;
6594 break;
6595 case e1000_ich8lan:
6596 hw->bus_type = e1000_bus_type_pci_express;
6597 hw->bus_speed = e1000_bus_speed_2500;
6598 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006599 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 default:
6601 status = E1000_READ_REG(hw, STATUS);
6602 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6603 e1000_bus_type_pcix : e1000_bus_type_pci;
6604
Auke Kok8fc897b2006-08-28 14:56:16 -07006605 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6607 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006608 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6610 e1000_bus_speed_66 : e1000_bus_speed_33;
6611 } else {
6612 switch (status & E1000_STATUS_PCIX_SPEED) {
6613 case E1000_STATUS_PCIX_SPEED_66:
6614 hw->bus_speed = e1000_bus_speed_66;
6615 break;
6616 case E1000_STATUS_PCIX_SPEED_100:
6617 hw->bus_speed = e1000_bus_speed_100;
6618 break;
6619 case E1000_STATUS_PCIX_SPEED_133:
6620 hw->bus_speed = e1000_bus_speed_133;
6621 break;
6622 default:
6623 hw->bus_speed = e1000_bus_speed_reserved;
6624 break;
6625 }
6626 }
6627 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6628 e1000_bus_width_64 : e1000_bus_width_32;
6629 break;
6630 }
6631}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632
6633/******************************************************************************
6634 * Writes a value to one of the devices registers using port I/O (as opposed to
6635 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6636 *
6637 * hw - Struct containing variables accessed by shared code
6638 * offset - offset to write to
6639 * value - value to write
6640 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006641static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642e1000_write_reg_io(struct e1000_hw *hw,
6643 uint32_t offset,
6644 uint32_t value)
6645{
6646 unsigned long io_addr = hw->io_base;
6647 unsigned long io_data = hw->io_base + 4;
6648
6649 e1000_io_write(hw, io_addr, offset);
6650 e1000_io_write(hw, io_data, value);
6651}
6652
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653/******************************************************************************
6654 * Estimates the cable length.
6655 *
6656 * hw - Struct containing variables accessed by shared code
6657 * min_length - The estimated minimum length
6658 * max_length - The estimated maximum length
6659 *
6660 * returns: - E1000_ERR_XXX
6661 * E1000_SUCCESS
6662 *
6663 * This function always returns a ranged length (minimum & maximum).
6664 * So for M88 phy's, this function interprets the one value returned from the
6665 * register to the minimum and maximum range.
6666 * For IGP phy's, the function calculates the range by the AGC registers.
6667 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006668static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669e1000_get_cable_length(struct e1000_hw *hw,
6670 uint16_t *min_length,
6671 uint16_t *max_length)
6672{
6673 int32_t ret_val;
6674 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 uint16_t i, phy_data;
6676 uint16_t cable_length;
6677
6678 DEBUGFUNC("e1000_get_cable_length");
6679
6680 *min_length = *max_length = 0;
6681
6682 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006683 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006684
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6686 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006687 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688 return ret_val;
6689 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6690 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6691
6692 /* Convert the enum value to ranged values */
6693 switch (cable_length) {
6694 case e1000_cable_length_50:
6695 *min_length = 0;
6696 *max_length = e1000_igp_cable_length_50;
6697 break;
6698 case e1000_cable_length_50_80:
6699 *min_length = e1000_igp_cable_length_50;
6700 *max_length = e1000_igp_cable_length_80;
6701 break;
6702 case e1000_cable_length_80_110:
6703 *min_length = e1000_igp_cable_length_80;
6704 *max_length = e1000_igp_cable_length_110;
6705 break;
6706 case e1000_cable_length_110_140:
6707 *min_length = e1000_igp_cable_length_110;
6708 *max_length = e1000_igp_cable_length_140;
6709 break;
6710 case e1000_cable_length_140:
6711 *min_length = e1000_igp_cable_length_140;
6712 *max_length = e1000_igp_cable_length_170;
6713 break;
6714 default:
6715 return -E1000_ERR_PHY;
6716 break;
6717 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006718 } else if (hw->phy_type == e1000_phy_gg82563) {
6719 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6720 &phy_data);
6721 if (ret_val)
6722 return ret_val;
6723 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6724
6725 switch (cable_length) {
6726 case e1000_gg_cable_length_60:
6727 *min_length = 0;
6728 *max_length = e1000_igp_cable_length_60;
6729 break;
6730 case e1000_gg_cable_length_60_115:
6731 *min_length = e1000_igp_cable_length_60;
6732 *max_length = e1000_igp_cable_length_115;
6733 break;
6734 case e1000_gg_cable_length_115_150:
6735 *min_length = e1000_igp_cable_length_115;
6736 *max_length = e1000_igp_cable_length_150;
6737 break;
6738 case e1000_gg_cable_length_150:
6739 *min_length = e1000_igp_cable_length_150;
6740 *max_length = e1000_igp_cable_length_180;
6741 break;
6742 default:
6743 return -E1000_ERR_PHY;
6744 break;
6745 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006746 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006747 uint16_t cur_agc_value;
6748 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6750 {IGP01E1000_PHY_AGC_A,
6751 IGP01E1000_PHY_AGC_B,
6752 IGP01E1000_PHY_AGC_C,
6753 IGP01E1000_PHY_AGC_D};
6754 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006755 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756
6757 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006758 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 return ret_val;
6760
Auke Kokcd94dd02006-06-27 09:08:22 -07006761 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762
Auke Kokcd94dd02006-06-27 09:08:22 -07006763 /* Value bound check. */
6764 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6765 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 return -E1000_ERR_PHY;
6767
Auke Kokcd94dd02006-06-27 09:08:22 -07006768 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769
6770 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006771 if (min_agc_value > cur_agc_value)
6772 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773 }
6774
6775 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006776 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6777 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778
6779 /* Get the average length of the remaining 3 channels */
6780 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6781 } else {
6782 /* Get the average length of all the 4 channels. */
6783 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6784 }
6785
6786 /* Set the range of the calculated length. */
6787 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6788 IGP01E1000_AGC_RANGE) > 0) ?
6789 (e1000_igp_cable_length_table[agc_value] -
6790 IGP01E1000_AGC_RANGE) : 0;
6791 *max_length = e1000_igp_cable_length_table[agc_value] +
6792 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006793 } else if (hw->phy_type == e1000_phy_igp_2 ||
6794 hw->phy_type == e1000_phy_igp_3) {
6795 uint16_t cur_agc_index, max_agc_index = 0;
6796 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006797 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6798 {IGP02E1000_PHY_AGC_A,
6799 IGP02E1000_PHY_AGC_B,
6800 IGP02E1000_PHY_AGC_C,
6801 IGP02E1000_PHY_AGC_D};
6802 /* Read the AGC registers for all channels */
6803 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6804 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6805 if (ret_val)
6806 return ret_val;
6807
Auke Kok8fc897b2006-08-28 14:56:16 -07006808 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006809 * fine gain values. The result is a number that can be put into
6810 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006811 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6812 IGP02E1000_AGC_LENGTH_MASK;
6813
6814 /* Array index bound check. */
6815 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6816 (cur_agc_index == 0))
6817 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006818
6819 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006820 if (e1000_igp_2_cable_length_table[min_agc_index] >
6821 e1000_igp_2_cable_length_table[cur_agc_index])
6822 min_agc_index = cur_agc_index;
6823 if (e1000_igp_2_cable_length_table[max_agc_index] <
6824 e1000_igp_2_cable_length_table[cur_agc_index])
6825 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006826
Auke Kokcd94dd02006-06-27 09:08:22 -07006827 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006828 }
6829
Auke Kokcd94dd02006-06-27 09:08:22 -07006830 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6831 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006832 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6833
6834 /* Calculate cable length with the error range of +/- 10 meters. */
6835 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6836 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6837 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 }
6839
6840 return E1000_SUCCESS;
6841}
6842
6843/******************************************************************************
6844 * Check the cable polarity
6845 *
6846 * hw - Struct containing variables accessed by shared code
6847 * polarity - output parameter : 0 - Polarity is not reversed
6848 * 1 - Polarity is reversed.
6849 *
6850 * returns: - E1000_ERR_XXX
6851 * E1000_SUCCESS
6852 *
6853 * For phy's older then IGP, this function simply reads the polarity bit in the
6854 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6855 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6856 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6857 * IGP01E1000_PHY_PCS_INIT_REG.
6858 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006859static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006861 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862{
6863 int32_t ret_val;
6864 uint16_t phy_data;
6865
6866 DEBUGFUNC("e1000_check_polarity");
6867
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006868 if ((hw->phy_type == e1000_phy_m88) ||
6869 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006870 /* return the Polarity bit in the Status register. */
6871 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6872 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006873 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006875 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6876 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6877 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6878
Auke Kokcd94dd02006-06-27 09:08:22 -07006879 } else if (hw->phy_type == e1000_phy_igp ||
6880 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006881 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882 /* Read the Status register to check the speed */
6883 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6884 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006885 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 return ret_val;
6887
6888 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6889 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006890 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 IGP01E1000_PSSR_SPEED_1000MBPS) {
6892
6893 /* Read the GIG initialization PCS register (0x00B4) */
6894 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6895 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006896 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 return ret_val;
6898
6899 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006900 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6901 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 } else {
6903 /* For 10 Mbps, read the polarity bit in the status register. (for
6904 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006905 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6906 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006907 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006908 } else if (hw->phy_type == e1000_phy_ife) {
6909 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6910 &phy_data);
6911 if (ret_val)
6912 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006913 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6914 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6915 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916 }
6917 return E1000_SUCCESS;
6918}
6919
6920/******************************************************************************
6921 * Check if Downshift occured
6922 *
6923 * hw - Struct containing variables accessed by shared code
6924 * downshift - output parameter : 0 - No Downshift ocured.
6925 * 1 - Downshift ocured.
6926 *
6927 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006928 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929 *
6930 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6931 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6932 * Link Health register. In IGP this bit is latched high, so the driver must
6933 * read it immediately after link is established.
6934 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006935static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006936e1000_check_downshift(struct e1000_hw *hw)
6937{
6938 int32_t ret_val;
6939 uint16_t phy_data;
6940
6941 DEBUGFUNC("e1000_check_downshift");
6942
Auke Kokcd94dd02006-06-27 09:08:22 -07006943 if (hw->phy_type == e1000_phy_igp ||
6944 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006945 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006946 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6947 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006948 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006949 return ret_val;
6950
6951 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006952 } else if ((hw->phy_type == e1000_phy_m88) ||
6953 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6955 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006956 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006957 return ret_val;
6958
6959 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6960 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006961 } else if (hw->phy_type == e1000_phy_ife) {
6962 /* e1000_phy_ife supports 10/100 speed only */
6963 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006965
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 return E1000_SUCCESS;
6967}
6968
6969/*****************************************************************************
6970 *
6971 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6972 * gigabit link is achieved to improve link quality.
6973 *
6974 * hw: Struct containing variables accessed by shared code
6975 *
6976 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6977 * E1000_SUCCESS at any other case.
6978 *
6979 ****************************************************************************/
6980
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006981static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006982e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6983 boolean_t link_up)
6984{
6985 int32_t ret_val;
6986 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6987 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6988 {IGP01E1000_PHY_AGC_PARAM_A,
6989 IGP01E1000_PHY_AGC_PARAM_B,
6990 IGP01E1000_PHY_AGC_PARAM_C,
6991 IGP01E1000_PHY_AGC_PARAM_D};
6992 uint16_t min_length, max_length;
6993
6994 DEBUGFUNC("e1000_config_dsp_after_link_change");
6995
Auke Kok8fc897b2006-08-28 14:56:16 -07006996 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 return E1000_SUCCESS;
6998
Auke Kok8fc897b2006-08-28 14:56:16 -07006999 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07007001 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002 DEBUGOUT("Error getting link speed and duplex\n");
7003 return ret_val;
7004 }
7005
Auke Kok8fc897b2006-08-28 14:56:16 -07007006 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007
Auke Kokcd94dd02006-06-27 09:08:22 -07007008 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7009 if (ret_val)
7010 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011
Auke Kok8fc897b2006-08-28 14:56:16 -07007012 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013 min_length >= e1000_igp_cable_length_50) {
7014
Auke Kok8fc897b2006-08-28 14:56:16 -07007015 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7017 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007018 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007019 return ret_val;
7020
7021 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7022
7023 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7024 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007025 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026 return ret_val;
7027 }
7028 hw->dsp_config_state = e1000_dsp_config_activated;
7029 }
7030
Auke Kok8fc897b2006-08-28 14:56:16 -07007031 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007032 (min_length < e1000_igp_cable_length_50)) {
7033
7034 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7035 uint32_t idle_errs = 0;
7036
7037 /* clear previous idle error counts */
7038 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7039 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007040 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041 return ret_val;
7042
Auke Kok8fc897b2006-08-28 14:56:16 -07007043 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007044 udelay(1000);
7045 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7046 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007047 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 return ret_val;
7049
7050 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007051 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 hw->ffe_config_state = e1000_ffe_config_active;
7053
7054 ret_val = e1000_write_phy_reg(hw,
7055 IGP01E1000_PHY_DSP_FFE,
7056 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007057 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058 return ret_val;
7059 break;
7060 }
7061
Auke Kok8fc897b2006-08-28 14:56:16 -07007062 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007063 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7064 }
7065 }
7066 }
7067 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007068 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007069 /* Save off the current value of register 0x2F5B to be restored at
7070 * the end of the routines. */
7071 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7072
Auke Kok8fc897b2006-08-28 14:56:16 -07007073 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007074 return ret_val;
7075
7076 /* Disable the PHY transmitter */
7077 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7078
Auke Kok8fc897b2006-08-28 14:56:16 -07007079 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080 return ret_val;
7081
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007082 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007083
7084 ret_val = e1000_write_phy_reg(hw, 0x0000,
7085 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007086 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007088 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007089 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007090 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007091 return ret_val;
7092
7093 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7094 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7095
7096 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007097 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007098 return ret_val;
7099 }
7100
7101 ret_val = e1000_write_phy_reg(hw, 0x0000,
7102 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007103 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007104 return ret_val;
7105
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007106 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007107
7108 /* Now enable the transmitter */
7109 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7110
Auke Kok8fc897b2006-08-28 14:56:16 -07007111 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007112 return ret_val;
7113
7114 hw->dsp_config_state = e1000_dsp_config_enabled;
7115 }
7116
Auke Kok8fc897b2006-08-28 14:56:16 -07007117 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007118 /* Save off the current value of register 0x2F5B to be restored at
7119 * the end of the routines. */
7120 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7121
Auke Kok8fc897b2006-08-28 14:56:16 -07007122 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007123 return ret_val;
7124
7125 /* Disable the PHY transmitter */
7126 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7127
Auke Kok8fc897b2006-08-28 14:56:16 -07007128 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007129 return ret_val;
7130
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007131 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007132
7133 ret_val = e1000_write_phy_reg(hw, 0x0000,
7134 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007135 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007136 return ret_val;
7137 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7138 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007139 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007140 return ret_val;
7141
7142 ret_val = e1000_write_phy_reg(hw, 0x0000,
7143 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007144 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007145 return ret_val;
7146
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007147 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007148
7149 /* Now enable the transmitter */
7150 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7151
Auke Kok8fc897b2006-08-28 14:56:16 -07007152 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007153 return ret_val;
7154
7155 hw->ffe_config_state = e1000_ffe_config_enabled;
7156 }
7157 }
7158 return E1000_SUCCESS;
7159}
7160
7161/*****************************************************************************
7162 * Set PHY to class A mode
7163 * Assumes the following operations will follow to enable the new class mode.
7164 * 1. Do a PHY soft reset
7165 * 2. Restart auto-negotiation or force link.
7166 *
7167 * hw - Struct containing variables accessed by shared code
7168 ****************************************************************************/
7169static int32_t
7170e1000_set_phy_mode(struct e1000_hw *hw)
7171{
7172 int32_t ret_val;
7173 uint16_t eeprom_data;
7174
7175 DEBUGFUNC("e1000_set_phy_mode");
7176
Auke Kok8fc897b2006-08-28 14:56:16 -07007177 if ((hw->mac_type == e1000_82545_rev_3) &&
7178 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007179 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007180 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 return ret_val;
7182 }
7183
Auke Kok8fc897b2006-08-28 14:56:16 -07007184 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7185 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007186 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007187 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 return ret_val;
7189 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007190 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 return ret_val;
7192
7193 hw->phy_reset_disable = FALSE;
7194 }
7195 }
7196
7197 return E1000_SUCCESS;
7198}
7199
7200/*****************************************************************************
7201 *
7202 * This function sets the lplu state according to the active flag. When
7203 * activating lplu this function also disables smart speed and vise versa.
7204 * lplu will not be activated unless the device autonegotiation advertisment
7205 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7206 * hw: Struct containing variables accessed by shared code
7207 * active - true to enable lplu false to disable lplu.
7208 *
7209 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7210 * E1000_SUCCESS at any other case.
7211 *
7212 ****************************************************************************/
7213
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007214static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215e1000_set_d3_lplu_state(struct e1000_hw *hw,
7216 boolean_t active)
7217{
Auke Kokcd94dd02006-06-27 09:08:22 -07007218 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007219 int32_t ret_val;
7220 uint16_t phy_data;
7221 DEBUGFUNC("e1000_set_d3_lplu_state");
7222
Auke Kokcd94dd02006-06-27 09:08:22 -07007223 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7224 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007225 return E1000_SUCCESS;
7226
7227 /* During driver activity LPLU should not be used or it will attain link
7228 * from the lowest speeds starting from 10Mbps. The capability is used for
7229 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007230 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007231 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007232 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007233 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007234 } else if (hw->mac_type == e1000_ich8lan) {
7235 /* MAC writes into PHY register based on the state transition
7236 * and start auto-negotiation. SW driver can overwrite the settings
7237 * in CSR PHY power control E1000_PHY_CTRL register. */
7238 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007239 } else {
7240 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007241 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007242 return ret_val;
7243 }
7244
Auke Kok8fc897b2006-08-28 14:56:16 -07007245 if (!active) {
7246 if (hw->mac_type == e1000_82541_rev_2 ||
7247 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007248 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7249 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007250 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007251 return ret_val;
7252 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007253 if (hw->mac_type == e1000_ich8lan) {
7254 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7255 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7256 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007257 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7258 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7259 phy_data);
7260 if (ret_val)
7261 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007262 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007264
7265 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7266 * Dx states where the power conservation is most important. During
7267 * driver activity we should enable SmartSpeed, so performance is
7268 * maintained. */
7269 if (hw->smart_speed == e1000_smart_speed_on) {
7270 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7271 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007272 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007273 return ret_val;
7274
7275 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7276 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7277 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007278 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007279 return ret_val;
7280 } else if (hw->smart_speed == e1000_smart_speed_off) {
7281 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7282 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007283 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007284 return ret_val;
7285
7286 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7287 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7288 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007289 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007290 return ret_val;
7291 }
7292
Auke Kok8fc897b2006-08-28 14:56:16 -07007293 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7294 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7295 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007296
Auke Kok8fc897b2006-08-28 14:56:16 -07007297 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007298 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007299 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7300 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007301 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007302 return ret_val;
7303 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007304 if (hw->mac_type == e1000_ich8lan) {
7305 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7306 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7307 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007308 phy_data |= IGP02E1000_PM_D3_LPLU;
7309 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7310 phy_data);
7311 if (ret_val)
7312 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007313 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007314 }
7315
7316 /* When LPLU is enabled we should disable SmartSpeed */
7317 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007318 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007319 return ret_val;
7320
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007321 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7322 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007323 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007324 return ret_val;
7325
7326 }
7327 return E1000_SUCCESS;
7328}
7329
7330/*****************************************************************************
7331 *
7332 * This function sets the lplu d0 state according to the active flag. When
7333 * activating lplu this function also disables smart speed and vise versa.
7334 * lplu will not be activated unless the device autonegotiation advertisment
7335 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7336 * hw: Struct containing variables accessed by shared code
7337 * active - true to enable lplu false to disable lplu.
7338 *
7339 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7340 * E1000_SUCCESS at any other case.
7341 *
7342 ****************************************************************************/
7343
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007344static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007345e1000_set_d0_lplu_state(struct e1000_hw *hw,
7346 boolean_t active)
7347{
Auke Kokcd94dd02006-06-27 09:08:22 -07007348 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007349 int32_t ret_val;
7350 uint16_t phy_data;
7351 DEBUGFUNC("e1000_set_d0_lplu_state");
7352
Auke Kok8fc897b2006-08-28 14:56:16 -07007353 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007354 return E1000_SUCCESS;
7355
Auke Kokcd94dd02006-06-27 09:08:22 -07007356 if (hw->mac_type == e1000_ich8lan) {
7357 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7358 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007359 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007360 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007361 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007362 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007363
7364 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007365 if (hw->mac_type == e1000_ich8lan) {
7366 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7367 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7368 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007369 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7370 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7371 if (ret_val)
7372 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007373 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007374
7375 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7376 * Dx states where the power conservation is most important. During
7377 * driver activity we should enable SmartSpeed, so performance is
7378 * maintained. */
7379 if (hw->smart_speed == e1000_smart_speed_on) {
7380 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7381 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007382 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007383 return ret_val;
7384
7385 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7386 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7387 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007388 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007389 return ret_val;
7390 } else if (hw->smart_speed == e1000_smart_speed_off) {
7391 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7392 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007393 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007394 return ret_val;
7395
7396 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7397 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7398 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007399 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007400 return ret_val;
7401 }
7402
7403
7404 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007405
Auke Kokcd94dd02006-06-27 09:08:22 -07007406 if (hw->mac_type == e1000_ich8lan) {
7407 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7408 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7409 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007410 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007411 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7412 if (ret_val)
7413 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007414 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007415
Linus Torvalds1da177e2005-04-16 15:20:36 -07007416 /* When LPLU is enabled we should disable SmartSpeed */
7417 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007418 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007419 return ret_val;
7420
7421 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7422 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007423 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424 return ret_val;
7425
7426 }
7427 return E1000_SUCCESS;
7428}
7429
7430/******************************************************************************
7431 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7432 *
7433 * hw - Struct containing variables accessed by shared code
7434 *****************************************************************************/
7435static int32_t
7436e1000_set_vco_speed(struct e1000_hw *hw)
7437{
7438 int32_t ret_val;
7439 uint16_t default_page = 0;
7440 uint16_t phy_data;
7441
7442 DEBUGFUNC("e1000_set_vco_speed");
7443
Auke Kok8fc897b2006-08-28 14:56:16 -07007444 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007445 case e1000_82545_rev_3:
7446 case e1000_82546_rev_3:
7447 break;
7448 default:
7449 return E1000_SUCCESS;
7450 }
7451
7452 /* Set PHY register 30, page 5, bit 8 to 0 */
7453
7454 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007455 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007456 return ret_val;
7457
7458 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007459 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007460 return ret_val;
7461
7462 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007463 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007464 return ret_val;
7465
7466 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7467 ret_val = e1000_write_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 /* Set PHY register 30, page 4, bit 11 to 1 */
7472
7473 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007474 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007475 return ret_val;
7476
7477 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007478 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007479 return ret_val;
7480
7481 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7482 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007483 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007484 return ret_val;
7485
7486 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007487 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007488 return ret_val;
7489
7490 return E1000_SUCCESS;
7491}
7492
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007493
7494/*****************************************************************************
7495 * This function reads the cookie from ARC ram.
7496 *
7497 * returns: - E1000_SUCCESS .
7498 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007499static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007500e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7501{
7502 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007503 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007504 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7505
7506 length = (length >> 2);
7507 offset = (offset >> 2);
7508
7509 for (i = 0; i < length; i++) {
7510 *((uint32_t *) buffer + i) =
7511 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7512 }
7513 return E1000_SUCCESS;
7514}
7515
7516
7517/*****************************************************************************
7518 * This function checks whether the HOST IF is enabled for command operaton
7519 * and also checks whether the previous command is completed.
7520 * It busy waits in case of previous command is not completed.
7521 *
Auke Kok76c224b2006-05-23 13:36:06 -07007522 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007523 * timeout
7524 * - E1000_SUCCESS for success.
7525 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007526static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007527e1000_mng_enable_host_if(struct e1000_hw * hw)
7528{
7529 uint32_t hicr;
7530 uint8_t i;
7531
7532 /* Check that the host interface is enabled. */
7533 hicr = E1000_READ_REG(hw, HICR);
7534 if ((hicr & E1000_HICR_EN) == 0) {
7535 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7536 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7537 }
7538 /* check the previous command is completed */
7539 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7540 hicr = E1000_READ_REG(hw, HICR);
7541 if (!(hicr & E1000_HICR_C))
7542 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007543 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007544 }
7545
Auke Kok76c224b2006-05-23 13:36:06 -07007546 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007547 DEBUGOUT("Previous command timeout failed .\n");
7548 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7549 }
7550 return E1000_SUCCESS;
7551}
7552
7553/*****************************************************************************
7554 * This function writes the buffer content at the offset given on the host if.
7555 * It also does alignment considerations to do the writes in most efficient way.
7556 * Also fills up the sum of the buffer in *buffer parameter.
7557 *
7558 * returns - E1000_SUCCESS for success.
7559 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007560static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007561e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7562 uint16_t length, uint16_t offset, uint8_t *sum)
7563{
7564 uint8_t *tmp;
7565 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007566 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007567 uint16_t remaining, i, j, prev_bytes;
7568
7569 /* sum = only sum of the data and it is not checksum */
7570
7571 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7572 return -E1000_ERR_PARAM;
7573 }
7574
7575 tmp = (uint8_t *)&data;
7576 prev_bytes = offset & 0x3;
7577 offset &= 0xFFFC;
7578 offset >>= 2;
7579
7580 if (prev_bytes) {
7581 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7582 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7583 *(tmp + j) = *bufptr++;
7584 *sum += *(tmp + j);
7585 }
7586 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7587 length -= j - prev_bytes;
7588 offset++;
7589 }
7590
7591 remaining = length & 0x3;
7592 length -= remaining;
7593
7594 /* Calculate length in DWORDs */
7595 length >>= 2;
7596
7597 /* The device driver writes the relevant command block into the
7598 * ram area. */
7599 for (i = 0; i < length; i++) {
7600 for (j = 0; j < sizeof(uint32_t); j++) {
7601 *(tmp + j) = *bufptr++;
7602 *sum += *(tmp + j);
7603 }
7604
7605 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7606 }
7607 if (remaining) {
7608 for (j = 0; j < sizeof(uint32_t); j++) {
7609 if (j < remaining)
7610 *(tmp + j) = *bufptr++;
7611 else
7612 *(tmp + j) = 0;
7613
7614 *sum += *(tmp + j);
7615 }
7616 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7617 }
7618
7619 return E1000_SUCCESS;
7620}
7621
7622
7623/*****************************************************************************
7624 * This function writes the command header after does the checksum calculation.
7625 *
7626 * returns - E1000_SUCCESS for success.
7627 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007628static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007629e1000_mng_write_cmd_header(struct e1000_hw * hw,
7630 struct e1000_host_mng_command_header * hdr)
7631{
7632 uint16_t i;
7633 uint8_t sum;
7634 uint8_t *buffer;
7635
7636 /* Write the whole command header structure which includes sum of
7637 * the buffer */
7638
7639 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7640
7641 sum = hdr->checksum;
7642 hdr->checksum = 0;
7643
7644 buffer = (uint8_t *) hdr;
7645 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007646 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007647 sum += buffer[i];
7648
7649 hdr->checksum = 0 - sum;
7650
7651 length >>= 2;
7652 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007653 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007654 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007655 E1000_WRITE_FLUSH(hw);
7656 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007657
7658 return E1000_SUCCESS;
7659}
7660
7661
7662/*****************************************************************************
7663 * This function indicates to ARC that a new command is pending which completes
7664 * one write operation by the driver.
7665 *
7666 * returns - E1000_SUCCESS for success.
7667 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007668static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007669e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007670{
7671 uint32_t hicr;
7672
7673 hicr = E1000_READ_REG(hw, HICR);
7674 /* Setting this bit tells the ARC that a new command is pending. */
7675 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7676
7677 return E1000_SUCCESS;
7678}
7679
7680
7681/*****************************************************************************
7682 * This function checks the mode of the firmware.
7683 *
7684 * returns - TRUE when the mode is IAMT or FALSE.
7685 ****************************************************************************/
7686boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007687e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007688{
7689 uint32_t fwsm;
7690
7691 fwsm = E1000_READ_REG(hw, FWSM);
7692
Auke Kokcd94dd02006-06-27 09:08:22 -07007693 if (hw->mac_type == e1000_ich8lan) {
7694 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7695 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7696 return TRUE;
7697 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7698 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007699 return TRUE;
7700
7701 return FALSE;
7702}
7703
7704
7705/*****************************************************************************
7706 * This function writes the dhcp info .
7707 ****************************************************************************/
7708int32_t
7709e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007710 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007711{
7712 int32_t ret_val;
7713 struct e1000_host_mng_command_header hdr;
7714
7715 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7716 hdr.command_length = length;
7717 hdr.reserved1 = 0;
7718 hdr.reserved2 = 0;
7719 hdr.checksum = 0;
7720
7721 ret_val = e1000_mng_enable_host_if(hw);
7722 if (ret_val == E1000_SUCCESS) {
7723 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7724 &(hdr.checksum));
7725 if (ret_val == E1000_SUCCESS) {
7726 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7727 if (ret_val == E1000_SUCCESS)
7728 ret_val = e1000_mng_write_commit(hw);
7729 }
7730 }
7731 return ret_val;
7732}
7733
7734
7735/*****************************************************************************
7736 * This function calculates the checksum.
7737 *
7738 * returns - checksum of buffer contents.
7739 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007740static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007741e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7742{
7743 uint8_t sum = 0;
7744 uint32_t i;
7745
7746 if (!buffer)
7747 return 0;
7748
7749 for (i=0; i < length; i++)
7750 sum += buffer[i];
7751
7752 return (uint8_t) (0 - sum);
7753}
7754
7755/*****************************************************************************
7756 * This function checks whether tx pkt filtering needs to be enabled or not.
7757 *
7758 * returns - TRUE for packet filtering or FALSE.
7759 ****************************************************************************/
7760boolean_t
7761e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7762{
7763 /* called in init as well as watchdog timer functions */
7764
7765 int32_t ret_val, checksum;
7766 boolean_t tx_filter = FALSE;
7767 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7768 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7769
7770 if (e1000_check_mng_mode(hw)) {
7771 ret_val = e1000_mng_enable_host_if(hw);
7772 if (ret_val == E1000_SUCCESS) {
7773 ret_val = e1000_host_if_read_cookie(hw, buffer);
7774 if (ret_val == E1000_SUCCESS) {
7775 checksum = hdr->checksum;
7776 hdr->checksum = 0;
7777 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7778 checksum == e1000_calculate_mng_checksum((char *)buffer,
7779 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7780 if (hdr->status &
7781 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7782 tx_filter = TRUE;
7783 } else
7784 tx_filter = TRUE;
7785 } else
7786 tx_filter = TRUE;
7787 }
7788 }
7789
7790 hw->tx_pkt_filtering = tx_filter;
7791 return tx_filter;
7792}
7793
7794/******************************************************************************
7795 * Verifies the hardware needs to allow ARPs to be processed by the host
7796 *
7797 * hw - Struct containing variables accessed by shared code
7798 *
7799 * returns: - TRUE/FALSE
7800 *
7801 *****************************************************************************/
7802uint32_t
7803e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7804{
7805 uint32_t manc;
7806 uint32_t fwsm, factps;
7807
7808 if (hw->asf_firmware_present) {
7809 manc = E1000_READ_REG(hw, MANC);
7810
7811 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7812 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7813 return FALSE;
7814 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7815 fwsm = E1000_READ_REG(hw, FWSM);
7816 factps = E1000_READ_REG(hw, FACTPS);
7817
7818 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7819 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7820 (factps & E1000_FACTPS_MNGCG))
7821 return TRUE;
7822 } else
7823 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7824 return TRUE;
7825 }
7826 return FALSE;
7827}
7828
Linus Torvalds1da177e2005-04-16 15:20:36 -07007829static int32_t
7830e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7831{
7832 int32_t ret_val;
7833 uint16_t mii_status_reg;
7834 uint16_t i;
7835
7836 /* Polarity reversal workaround for forced 10F/10H links. */
7837
7838 /* Disable the transmitter on the PHY */
7839
7840 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007841 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007842 return ret_val;
7843 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007844 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007845 return ret_val;
7846
7847 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007848 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007849 return ret_val;
7850
7851 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007852 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007853 /* Read the MII Status Register and wait for Link Status bit
7854 * to be clear.
7855 */
7856
7857 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007858 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007859 return ret_val;
7860
7861 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007862 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007863 return ret_val;
7864
Auke Kok8fc897b2006-08-28 14:56:16 -07007865 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007866 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007867 }
7868
7869 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007870 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007871
7872 /* Now we will re-enable th transmitter on the PHY */
7873
7874 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007875 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007876 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007877 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007878 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007879 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007880 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007881 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007882 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007883 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007884 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007885 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007886 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007887 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007888 return ret_val;
7889
7890 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007891 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007892 return ret_val;
7893
7894 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007895 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007896 /* Read the MII Status Register and wait for Link Status bit
7897 * to be set.
7898 */
7899
7900 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007901 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007902 return ret_val;
7903
7904 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007905 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007906 return ret_val;
7907
Auke Kok8fc897b2006-08-28 14:56:16 -07007908 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007909 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007910 }
7911 return E1000_SUCCESS;
7912}
7913
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007914/***************************************************************************
7915 *
7916 * Disables PCI-Express master access.
7917 *
7918 * hw: Struct containing variables accessed by shared code
7919 *
7920 * returns: - none.
7921 *
7922 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007923static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007924e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7925{
7926 uint32_t ctrl;
7927
7928 DEBUGFUNC("e1000_set_pci_express_master_disable");
7929
7930 if (hw->bus_type != e1000_bus_type_pci_express)
7931 return;
7932
7933 ctrl = E1000_READ_REG(hw, CTRL);
7934 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7935 E1000_WRITE_REG(hw, CTRL, ctrl);
7936}
7937
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007938/*******************************************************************************
7939 *
7940 * Disables PCI-Express master access and verifies there are no pending requests
7941 *
7942 * hw: Struct containing variables accessed by shared code
7943 *
7944 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7945 * caused the master requests to be disabled.
7946 * E1000_SUCCESS master requests disabled.
7947 *
7948 ******************************************************************************/
7949int32_t
7950e1000_disable_pciex_master(struct e1000_hw *hw)
7951{
7952 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7953
7954 DEBUGFUNC("e1000_disable_pciex_master");
7955
7956 if (hw->bus_type != e1000_bus_type_pci_express)
7957 return E1000_SUCCESS;
7958
7959 e1000_set_pci_express_master_disable(hw);
7960
Auke Kok8fc897b2006-08-28 14:56:16 -07007961 while (timeout) {
7962 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007963 break;
7964 else
7965 udelay(100);
7966 timeout--;
7967 }
7968
Auke Kok8fc897b2006-08-28 14:56:16 -07007969 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007970 DEBUGOUT("Master requests are pending.\n");
7971 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7972 }
7973
7974 return E1000_SUCCESS;
7975}
7976
7977/*******************************************************************************
7978 *
7979 * Check for EEPROM Auto Read bit done.
7980 *
7981 * hw: Struct containing variables accessed by shared code
7982 *
7983 * returns: - E1000_ERR_RESET if fail to reset MAC
7984 * E1000_SUCCESS at any other case.
7985 *
7986 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007987static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007988e1000_get_auto_rd_done(struct e1000_hw *hw)
7989{
7990 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7991
7992 DEBUGFUNC("e1000_get_auto_rd_done");
7993
7994 switch (hw->mac_type) {
7995 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007996 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007997 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007998 case e1000_82571:
7999 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008000 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008001 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008002 case e1000_ich8lan:
8003 while (timeout) {
8004 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8005 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008006 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008007 timeout--;
8008 }
8009
Auke Kok8fc897b2006-08-28 14:56:16 -07008010 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008011 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8012 return -E1000_ERR_RESET;
8013 }
8014 break;
8015 }
8016
Jeff Kirsherfd803242005-12-13 00:06:22 -05008017 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8018 * Need to wait for PHY configuration completion before accessing NVM
8019 * and PHY. */
8020 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008021 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008022
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008023 return E1000_SUCCESS;
8024}
8025
8026/***************************************************************************
8027 * Checks if the PHY configuration is done
8028 *
8029 * hw: Struct containing variables accessed by shared code
8030 *
8031 * returns: - E1000_ERR_RESET if fail to reset MAC
8032 * E1000_SUCCESS at any other case.
8033 *
8034 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008035static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008036e1000_get_phy_cfg_done(struct e1000_hw *hw)
8037{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008038 int32_t timeout = PHY_CFG_TIMEOUT;
8039 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8040
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008041 DEBUGFUNC("e1000_get_phy_cfg_done");
8042
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008043 switch (hw->mac_type) {
8044 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008045 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008046 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008047 case e1000_80003es2lan:
8048 /* Separate *_CFG_DONE_* bit for each port */
8049 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8050 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8051 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008052 case e1000_82571:
8053 case e1000_82572:
8054 while (timeout) {
8055 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8056 break;
8057 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008058 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008059 timeout--;
8060 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008061 if (!timeout) {
8062 DEBUGOUT("MNG configuration cycle has not completed.\n");
8063 return -E1000_ERR_RESET;
8064 }
8065 break;
8066 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008067
8068 return E1000_SUCCESS;
8069}
8070
8071/***************************************************************************
8072 *
8073 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8074 * adapter or Eeprom access.
8075 *
8076 * hw: Struct containing variables accessed by shared code
8077 *
8078 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8079 * E1000_SUCCESS at any other case.
8080 *
8081 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008082static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008083e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8084{
8085 int32_t timeout;
8086 uint32_t swsm;
8087
8088 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8089
Auke Kok8fc897b2006-08-28 14:56:16 -07008090 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008091 return E1000_SUCCESS;
8092
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008093 if (hw->mac_type == e1000_80003es2lan) {
8094 /* Get the SW semaphore. */
8095 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8096 return -E1000_ERR_EEPROM;
8097 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008098
8099 /* Get the FW semaphore. */
8100 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008101 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008102 swsm = E1000_READ_REG(hw, SWSM);
8103 swsm |= E1000_SWSM_SWESMBI;
8104 E1000_WRITE_REG(hw, SWSM, swsm);
8105 /* if we managed to set the bit we got the semaphore. */
8106 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008107 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008108 break;
8109
8110 udelay(50);
8111 timeout--;
8112 }
8113
Auke Kok8fc897b2006-08-28 14:56:16 -07008114 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008115 /* Release semaphores */
8116 e1000_put_hw_eeprom_semaphore(hw);
8117 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8118 return -E1000_ERR_EEPROM;
8119 }
8120
8121 return E1000_SUCCESS;
8122}
8123
8124/***************************************************************************
8125 * This function clears HW semaphore bits.
8126 *
8127 * hw: Struct containing variables accessed by shared code
8128 *
8129 * returns: - None.
8130 *
8131 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008132static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008133e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8134{
8135 uint32_t swsm;
8136
8137 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8138
Auke Kok8fc897b2006-08-28 14:56:16 -07008139 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008140 return;
8141
8142 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008143 if (hw->mac_type == e1000_80003es2lan) {
8144 /* Release both semaphores. */
8145 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8146 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008147 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008148 E1000_WRITE_REG(hw, SWSM, swsm);
8149}
8150
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008151/***************************************************************************
8152 *
8153 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8154 *
8155 * hw: Struct containing variables accessed by shared code
8156 *
8157 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8158 * E1000_SUCCESS at any other case.
8159 *
8160 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008161static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008162e1000_get_software_semaphore(struct e1000_hw *hw)
8163{
8164 int32_t timeout = hw->eeprom.word_size + 1;
8165 uint32_t swsm;
8166
8167 DEBUGFUNC("e1000_get_software_semaphore");
8168
Nicholas Nunley35574762006-09-27 12:53:34 -07008169 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008170 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008171 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008172
Auke Kok8fc897b2006-08-28 14:56:16 -07008173 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008174 swsm = E1000_READ_REG(hw, SWSM);
8175 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008176 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008177 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008178 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008179 timeout--;
8180 }
8181
Auke Kok8fc897b2006-08-28 14:56:16 -07008182 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008183 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8184 return -E1000_ERR_RESET;
8185 }
8186
8187 return E1000_SUCCESS;
8188}
8189
8190/***************************************************************************
8191 *
8192 * Release semaphore bit (SMBI).
8193 *
8194 * hw: Struct containing variables accessed by shared code
8195 *
8196 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008197static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008198e1000_release_software_semaphore(struct e1000_hw *hw)
8199{
8200 uint32_t swsm;
8201
8202 DEBUGFUNC("e1000_release_software_semaphore");
8203
Nicholas Nunley35574762006-09-27 12:53:34 -07008204 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008205 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008206 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008207
8208 swsm = E1000_READ_REG(hw, SWSM);
8209 /* Release the SW semaphores.*/
8210 swsm &= ~E1000_SWSM_SMBI;
8211 E1000_WRITE_REG(hw, SWSM, swsm);
8212}
8213
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008214/******************************************************************************
8215 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8216 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8217 * the caller to figure out how to deal with it.
8218 *
8219 * hw - Struct containing variables accessed by shared code
8220 *
8221 * returns: - E1000_BLK_PHY_RESET
8222 * E1000_SUCCESS
8223 *
8224 *****************************************************************************/
8225int32_t
8226e1000_check_phy_reset_block(struct e1000_hw *hw)
8227{
8228 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008229 uint32_t fwsm = 0;
8230
8231 if (hw->mac_type == e1000_ich8lan) {
8232 fwsm = E1000_READ_REG(hw, FWSM);
8233 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8234 : E1000_BLK_PHY_RESET;
8235 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008236
8237 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008238 manc = E1000_READ_REG(hw, MANC);
8239 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008240 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008241}
8242
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008243static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008244e1000_arc_subsystem_valid(struct e1000_hw *hw)
8245{
8246 uint32_t fwsm;
8247
8248 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8249 * may not be provided a DMA clock when no manageability features are
8250 * enabled. We do not want to perform any reads/writes to these registers
8251 * if this is the case. We read FWSM to determine the manageability mode.
8252 */
8253 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008254 case e1000_82571:
8255 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008256 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008257 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008258 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008259 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008260 return TRUE;
8261 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008262 case e1000_ich8lan:
8263 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008264 default:
8265 break;
8266 }
8267 return FALSE;
8268}
8269
8270
Auke Kokd37ea5d2006-06-27 09:08:17 -07008271/******************************************************************************
8272 * Configure PCI-Ex no-snoop
8273 *
8274 * hw - Struct containing variables accessed by shared code.
8275 * no_snoop - Bitmap of no-snoop events.
8276 *
8277 * returns: E1000_SUCCESS
8278 *
8279 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008280static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008281e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8282{
8283 uint32_t gcr_reg = 0;
8284
8285 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8286
8287 if (hw->bus_type == e1000_bus_type_unknown)
8288 e1000_get_bus_info(hw);
8289
8290 if (hw->bus_type != e1000_bus_type_pci_express)
8291 return E1000_SUCCESS;
8292
8293 if (no_snoop) {
8294 gcr_reg = E1000_READ_REG(hw, GCR);
8295 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8296 gcr_reg |= no_snoop;
8297 E1000_WRITE_REG(hw, GCR, gcr_reg);
8298 }
8299 if (hw->mac_type == e1000_ich8lan) {
8300 uint32_t ctrl_ext;
8301
8302 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8303
8304 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8305 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8306 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8307 }
8308
8309 return E1000_SUCCESS;
8310}
8311
8312/***************************************************************************
8313 *
8314 * Get software semaphore FLAG bit (SWFLAG).
8315 * SWFLAG is used to synchronize the access to all shared resource between
8316 * SW, FW and HW.
8317 *
8318 * hw: Struct containing variables accessed by shared code
8319 *
8320 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008321static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008322e1000_get_software_flag(struct e1000_hw *hw)
8323{
8324 int32_t timeout = PHY_CFG_TIMEOUT;
8325 uint32_t extcnf_ctrl;
8326
8327 DEBUGFUNC("e1000_get_software_flag");
8328
8329 if (hw->mac_type == e1000_ich8lan) {
8330 while (timeout) {
8331 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8332 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8333 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8334
8335 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8336 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8337 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008338 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008339 timeout--;
8340 }
8341
8342 if (!timeout) {
8343 DEBUGOUT("FW or HW locks the resource too long.\n");
8344 return -E1000_ERR_CONFIG;
8345 }
8346 }
8347
8348 return E1000_SUCCESS;
8349}
8350
8351/***************************************************************************
8352 *
8353 * Release software semaphore FLAG bit (SWFLAG).
8354 * SWFLAG is used to synchronize the access to all shared resource between
8355 * SW, FW and HW.
8356 *
8357 * hw: Struct containing variables accessed by shared code
8358 *
8359 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008360static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008361e1000_release_software_flag(struct e1000_hw *hw)
8362{
8363 uint32_t extcnf_ctrl;
8364
8365 DEBUGFUNC("e1000_release_software_flag");
8366
8367 if (hw->mac_type == e1000_ich8lan) {
8368 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8369 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8370 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8371 }
8372
8373 return;
8374}
8375
Auke Kokd37ea5d2006-06-27 09:08:17 -07008376/******************************************************************************
8377 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8378 * register.
8379 *
8380 * hw - Struct containing variables accessed by shared code
8381 * offset - offset of word in the EEPROM to read
8382 * data - word read from the EEPROM
8383 * words - number of words to read
8384 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008385static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008386e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8387 uint16_t *data)
8388{
8389 int32_t error = E1000_SUCCESS;
8390 uint32_t flash_bank = 0;
8391 uint32_t act_offset = 0;
8392 uint32_t bank_offset = 0;
8393 uint16_t word = 0;
8394 uint16_t i = 0;
8395
8396 /* We need to know which is the valid flash bank. In the event
8397 * that we didn't allocate eeprom_shadow_ram, we may not be
8398 * managing flash_bank. So it cannot be trusted and needs
8399 * to be updated with each read.
8400 */
8401 /* Value of bit 22 corresponds to the flash bank we're on. */
8402 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8403
8404 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8405 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8406
8407 error = e1000_get_software_flag(hw);
8408 if (error != E1000_SUCCESS)
8409 return error;
8410
8411 for (i = 0; i < words; i++) {
8412 if (hw->eeprom_shadow_ram != NULL &&
8413 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8414 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8415 } else {
8416 /* The NVM part needs a byte offset, hence * 2 */
8417 act_offset = bank_offset + ((offset + i) * 2);
8418 error = e1000_read_ich8_word(hw, act_offset, &word);
8419 if (error != E1000_SUCCESS)
8420 break;
8421 data[i] = word;
8422 }
8423 }
8424
8425 e1000_release_software_flag(hw);
8426
8427 return error;
8428}
8429
8430/******************************************************************************
8431 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8432 * register. Actually, writes are written to the shadow ram cache in the hw
8433 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8434 * the NVM, which occurs when the NVM checksum is updated.
8435 *
8436 * hw - Struct containing variables accessed by shared code
8437 * offset - offset of word in the EEPROM to write
8438 * words - number of words to write
8439 * data - words to write to the EEPROM
8440 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008441static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008442e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8443 uint16_t *data)
8444{
8445 uint32_t i = 0;
8446 int32_t error = E1000_SUCCESS;
8447
8448 error = e1000_get_software_flag(hw);
8449 if (error != E1000_SUCCESS)
8450 return error;
8451
8452 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8453 * allocated. Subsequent reads to the modified words are read from
8454 * this cached structure as well. Writes will only go into this
8455 * cached structure unless it's followed by a call to
8456 * e1000_update_eeprom_checksum() where it will commit the changes
8457 * and clear the "modified" field.
8458 */
8459 if (hw->eeprom_shadow_ram != NULL) {
8460 for (i = 0; i < words; i++) {
8461 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8462 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8463 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8464 } else {
8465 error = -E1000_ERR_EEPROM;
8466 break;
8467 }
8468 }
8469 } else {
8470 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8471 * as they don't perform any NVM writes. An attempt in doing so
8472 * will result in this error.
8473 */
8474 error = -E1000_ERR_EEPROM;
8475 }
8476
8477 e1000_release_software_flag(hw);
8478
8479 return error;
8480}
8481
8482/******************************************************************************
8483 * This function does initial flash setup so that a new read/write/erase cycle
8484 * can be started.
8485 *
8486 * hw - The pointer to the hw structure
8487 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008488static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008489e1000_ich8_cycle_init(struct e1000_hw *hw)
8490{
8491 union ich8_hws_flash_status hsfsts;
8492 int32_t error = E1000_ERR_EEPROM;
8493 int32_t i = 0;
8494
8495 DEBUGFUNC("e1000_ich8_cycle_init");
8496
8497 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8498
8499 /* May be check the Flash Des Valid bit in Hw status */
8500 if (hsfsts.hsf_status.fldesvalid == 0) {
8501 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8502 return error;
8503 }
8504
8505 /* Clear FCERR in Hw status by writing 1 */
8506 /* Clear DAEL in Hw status by writing a 1 */
8507 hsfsts.hsf_status.flcerr = 1;
8508 hsfsts.hsf_status.dael = 1;
8509
8510 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8511
8512 /* Either we should have a hardware SPI cycle in progress bit to check
8513 * against, in order to start a new cycle or FDONE bit should be changed
8514 * in the hardware so that it is 1 after harware reset, which can then be
8515 * used as an indication whether a cycle is in progress or has been
8516 * completed .. we should also have some software semaphore mechanism to
8517 * guard FDONE or the cycle in progress bit so that two threads access to
8518 * those bits can be sequentiallized or a way so that 2 threads dont
8519 * start the cycle at the same time */
8520
8521 if (hsfsts.hsf_status.flcinprog == 0) {
8522 /* There is no cycle running at present, so we can start a cycle */
8523 /* Begin by setting Flash Cycle Done. */
8524 hsfsts.hsf_status.flcdone = 1;
8525 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8526 error = E1000_SUCCESS;
8527 } else {
8528 /* otherwise poll for sometime so the current cycle has a chance
8529 * to end before giving up. */
8530 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8531 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8532 if (hsfsts.hsf_status.flcinprog == 0) {
8533 error = E1000_SUCCESS;
8534 break;
8535 }
8536 udelay(1);
8537 }
8538 if (error == E1000_SUCCESS) {
8539 /* Successful in waiting for previous cycle to timeout,
8540 * now set the Flash Cycle Done. */
8541 hsfsts.hsf_status.flcdone = 1;
8542 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8543 } else {
8544 DEBUGOUT("Flash controller busy, cannot get access");
8545 }
8546 }
8547 return error;
8548}
8549
8550/******************************************************************************
8551 * This function starts a flash cycle and waits for its completion
8552 *
8553 * hw - The pointer to the hw structure
8554 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008555static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008556e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8557{
8558 union ich8_hws_flash_ctrl hsflctl;
8559 union ich8_hws_flash_status hsfsts;
8560 int32_t error = E1000_ERR_EEPROM;
8561 uint32_t i = 0;
8562
8563 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8564 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8565 hsflctl.hsf_ctrl.flcgo = 1;
8566 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8567
8568 /* wait till FDONE bit is set to 1 */
8569 do {
8570 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8571 if (hsfsts.hsf_status.flcdone == 1)
8572 break;
8573 udelay(1);
8574 i++;
8575 } while (i < timeout);
8576 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8577 error = E1000_SUCCESS;
8578 }
8579 return error;
8580}
8581
8582/******************************************************************************
8583 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8584 *
8585 * hw - The pointer to the hw structure
8586 * index - The index of the byte or word to read.
8587 * size - Size of data to read, 1=byte 2=word
8588 * data - Pointer to the word to store the value read.
8589 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008590static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008591e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8592 uint32_t size, uint16_t* data)
8593{
8594 union ich8_hws_flash_status hsfsts;
8595 union ich8_hws_flash_ctrl hsflctl;
8596 uint32_t flash_linear_address;
8597 uint32_t flash_data = 0;
8598 int32_t error = -E1000_ERR_EEPROM;
8599 int32_t count = 0;
8600
8601 DEBUGFUNC("e1000_read_ich8_data");
8602
8603 if (size < 1 || size > 2 || data == 0x0 ||
8604 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8605 return error;
8606
8607 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8608 hw->flash_base_addr;
8609
8610 do {
8611 udelay(1);
8612 /* Steps */
8613 error = e1000_ich8_cycle_init(hw);
8614 if (error != E1000_SUCCESS)
8615 break;
8616
8617 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8618 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8619 hsflctl.hsf_ctrl.fldbcount = size - 1;
8620 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8621 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8622
8623 /* Write the last 24 bits of index into Flash Linear address field in
8624 * Flash Address */
8625 /* TODO: TBD maybe check the index against the size of flash */
8626
8627 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8628
8629 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8630
8631 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8632 * sequence a few more times, else read in (shift in) the Flash Data0,
8633 * the order is least significant byte first msb to lsb */
8634 if (error == E1000_SUCCESS) {
8635 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8636 if (size == 1) {
8637 *data = (uint8_t)(flash_data & 0x000000FF);
8638 } else if (size == 2) {
8639 *data = (uint16_t)(flash_data & 0x0000FFFF);
8640 }
8641 break;
8642 } else {
8643 /* If we've gotten here, then things are probably completely hosed,
8644 * but if the error condition is detected, it won't hurt to give
8645 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8646 */
8647 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8648 if (hsfsts.hsf_status.flcerr == 1) {
8649 /* Repeat for some time before giving up. */
8650 continue;
8651 } else if (hsfsts.hsf_status.flcdone == 0) {
8652 DEBUGOUT("Timeout error - flash cycle did not complete.");
8653 break;
8654 }
8655 }
8656 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8657
8658 return error;
8659}
8660
8661/******************************************************************************
8662 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8663 *
8664 * hw - The pointer to the hw structure
8665 * index - The index of the byte/word to read.
8666 * size - Size of data to read, 1=byte 2=word
8667 * data - The byte(s) to write to the NVM.
8668 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008669static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008670e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8671 uint16_t data)
8672{
8673 union ich8_hws_flash_status hsfsts;
8674 union ich8_hws_flash_ctrl hsflctl;
8675 uint32_t flash_linear_address;
8676 uint32_t flash_data = 0;
8677 int32_t error = -E1000_ERR_EEPROM;
8678 int32_t count = 0;
8679
8680 DEBUGFUNC("e1000_write_ich8_data");
8681
8682 if (size < 1 || size > 2 || data > size * 0xff ||
8683 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8684 return error;
8685
8686 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8687 hw->flash_base_addr;
8688
8689 do {
8690 udelay(1);
8691 /* Steps */
8692 error = e1000_ich8_cycle_init(hw);
8693 if (error != E1000_SUCCESS)
8694 break;
8695
8696 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8697 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8698 hsflctl.hsf_ctrl.fldbcount = size -1;
8699 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8700 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8701
8702 /* Write the last 24 bits of index into Flash Linear address field in
8703 * Flash Address */
8704 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8705
8706 if (size == 1)
8707 flash_data = (uint32_t)data & 0x00FF;
8708 else
8709 flash_data = (uint32_t)data;
8710
8711 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8712
8713 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8714 * sequence a few more times else done */
8715 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8716 if (error == E1000_SUCCESS) {
8717 break;
8718 } else {
8719 /* If we're here, then things are most likely completely hosed,
8720 * but if the error condition is detected, it won't hurt to give
8721 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8722 */
8723 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8724 if (hsfsts.hsf_status.flcerr == 1) {
8725 /* Repeat for some time before giving up. */
8726 continue;
8727 } else if (hsfsts.hsf_status.flcdone == 0) {
8728 DEBUGOUT("Timeout error - flash cycle did not complete.");
8729 break;
8730 }
8731 }
8732 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8733
8734 return error;
8735}
8736
8737/******************************************************************************
8738 * Reads a single byte from the NVM using the ICH8 flash access registers.
8739 *
8740 * hw - pointer to e1000_hw structure
8741 * index - The index of the byte to read.
8742 * data - Pointer to a byte to store the value read.
8743 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008744static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008745e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8746{
8747 int32_t status = E1000_SUCCESS;
8748 uint16_t word = 0;
8749
8750 status = e1000_read_ich8_data(hw, index, 1, &word);
8751 if (status == E1000_SUCCESS) {
8752 *data = (uint8_t)word;
8753 }
8754
8755 return status;
8756}
8757
8758/******************************************************************************
8759 * Writes a single byte to the NVM using the ICH8 flash access registers.
8760 * Performs verification by reading back the value and then going through
8761 * a retry algorithm before giving up.
8762 *
8763 * hw - pointer to e1000_hw structure
8764 * index - The index of the byte to write.
8765 * byte - The byte to write to the NVM.
8766 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008767static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008768e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8769{
8770 int32_t error = E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008771 int32_t program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008772
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008773 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008774
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008775 error = e1000_write_ich8_byte(hw, index, byte);
8776
8777 if (error != E1000_SUCCESS) {
8778 for (program_retries = 0; program_retries < 100; program_retries++) {
8779 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8780 error = e1000_write_ich8_byte(hw, index, byte);
8781 udelay(100);
8782 if (error == E1000_SUCCESS)
8783 break;
8784 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008785 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008786
Auke Kokd37ea5d2006-06-27 09:08:17 -07008787 if (program_retries == 100)
8788 error = E1000_ERR_EEPROM;
8789
8790 return error;
8791}
8792
8793/******************************************************************************
8794 * Writes a single byte to the NVM using the ICH8 flash access registers.
8795 *
8796 * hw - pointer to e1000_hw structure
8797 * index - The index of the byte to read.
8798 * data - The byte to write to the NVM.
8799 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008800static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008801e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8802{
8803 int32_t status = E1000_SUCCESS;
8804 uint16_t word = (uint16_t)data;
8805
8806 status = e1000_write_ich8_data(hw, index, 1, word);
8807
8808 return status;
8809}
8810
8811/******************************************************************************
8812 * Reads a word from the NVM using the ICH8 flash access registers.
8813 *
8814 * hw - pointer to e1000_hw structure
8815 * index - The starting byte index of the word to read.
8816 * data - Pointer to a word to store the value read.
8817 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008818static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008819e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8820{
8821 int32_t status = E1000_SUCCESS;
8822 status = e1000_read_ich8_data(hw, index, 2, data);
8823 return status;
8824}
8825
8826/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008827 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8828 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008829 *
8830 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008831 * bank - 0 for first bank, 1 for second bank
8832 *
8833 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8834 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8835 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008836 *****************************************************************************/
8837int32_t
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008838e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008839{
8840 union ich8_hws_flash_status hsfsts;
8841 union ich8_hws_flash_ctrl hsflctl;
8842 uint32_t flash_linear_address;
8843 int32_t count = 0;
8844 int32_t error = E1000_ERR_EEPROM;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008845 int32_t iteration;
8846 int32_t sub_sector_size = 0;
8847 int32_t bank_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008848 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
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008856 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008857 * 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
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008859 * as bank * 4096
8860 * 10: The HW sector is 8K bytes
8861 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008862 if (hsfsts.hsf_status.berasesz == 0x0) {
8863 /* Hw sector size 256 */
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008864 sub_sector_size = ICH8_FLASH_SEG_SIZE_256;
8865 bank_size = ICH8_FLASH_SECTOR_SIZE;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008866 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8867 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008868 bank_size = ICH8_FLASH_SEG_SIZE_4K;
8869 iteration = 1;
8870 } else if (hw->mac_type != e1000_ich8lan &&
8871 hsfsts.hsf_status.berasesz == 0x2) {
8872 /* 8K erase size invalid for ICH8 - added in for ICH9 */
8873 bank_size = ICH9_FLASH_SEG_SIZE_8K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008874 iteration = 1;
8875 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008876 bank_size = ICH8_FLASH_SEG_SIZE_64K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008877 iteration = 1;
8878 } else {
8879 return error;
8880 }
8881
8882 for (j = 0; j < iteration ; j++) {
8883 do {
8884 count++;
8885 /* Steps */
8886 error = e1000_ich8_cycle_init(hw);
8887 if (error != E1000_SUCCESS) {
8888 error_flag = 1;
8889 break;
8890 }
8891
8892 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8893 * Control */
8894 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8895 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8896 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8897
8898 /* Write the last 24 bits of an index within the block into Flash
8899 * Linear address field in Flash Address. This probably needs to
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008900 * be calculated here based off the on-chip erase sector size and
8901 * the software bank size (4, 8 or 64 KBytes) */
8902 flash_linear_address = bank * bank_size + j * sub_sector_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008903 flash_linear_address += hw->flash_base_addr;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008904 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008905
8906 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8907
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008908 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_ERASE_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008909 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8910 * sequence a few more times else Done */
8911 if (error == E1000_SUCCESS) {
8912 break;
8913 } else {
8914 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8915 if (hsfsts.hsf_status.flcerr == 1) {
8916 /* repeat for some time before giving up */
8917 continue;
8918 } else if (hsfsts.hsf_status.flcdone == 0) {
8919 error_flag = 1;
8920 break;
8921 }
8922 }
8923 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8924 if (error_flag == 1)
8925 break;
8926 }
8927 if (error_flag != 1)
8928 error = E1000_SUCCESS;
8929 return error;
8930}
8931
Adrian Bunke4c780b2006-08-14 23:00:10 -07008932static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008933e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8934 uint32_t cnf_base_addr, uint32_t cnf_size)
8935{
8936 uint32_t ret_val = E1000_SUCCESS;
8937 uint16_t word_addr, reg_data, reg_addr;
8938 uint16_t i;
8939
8940 /* cnf_base_addr is in DWORD */
8941 word_addr = (uint16_t)(cnf_base_addr << 1);
8942
8943 /* cnf_size is returned in size of dwords */
8944 for (i = 0; i < cnf_size; i++) {
8945 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8946 if (ret_val)
8947 return ret_val;
8948
8949 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8950 if (ret_val)
8951 return ret_val;
8952
8953 ret_val = e1000_get_software_flag(hw);
8954 if (ret_val != E1000_SUCCESS)
8955 return ret_val;
8956
8957 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8958
8959 e1000_release_software_flag(hw);
8960 }
8961
8962 return ret_val;
8963}
8964
8965
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008966/******************************************************************************
8967 * This function initializes the PHY from the NVM on ICH8 platforms. This
8968 * is needed due to an issue where the NVM configuration is not properly
8969 * autoloaded after power transitions. Therefore, after each PHY reset, we
8970 * will load the configuration data out of the NVM manually.
8971 *
8972 * hw: Struct containing variables accessed by shared code
8973 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008974static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008975e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8976{
8977 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8978
8979 if (hw->phy_type != e1000_phy_igp_3)
8980 return E1000_SUCCESS;
8981
8982 /* Check if SW needs configure the PHY */
8983 reg_data = E1000_READ_REG(hw, FEXTNVM);
8984 if (!(reg_data & FEXTNVM_SW_CONFIG))
8985 return E1000_SUCCESS;
8986
8987 /* Wait for basic configuration completes before proceeding*/
8988 loop = 0;
8989 do {
8990 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8991 udelay(100);
8992 loop++;
8993 } while ((!reg_data) && (loop < 50));
8994
8995 /* Clear the Init Done bit for the next init event */
8996 reg_data = E1000_READ_REG(hw, STATUS);
8997 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
8998 E1000_WRITE_REG(hw, STATUS, reg_data);
8999
9000 /* Make sure HW does not configure LCD from PHY extended configuration
9001 before SW configuration */
9002 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9003 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9004 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9005 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9006 cnf_size >>= 16;
9007 if (cnf_size) {
9008 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9009 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9010 /* cnf_base_addr is in DWORD */
9011 cnf_base_addr >>= 16;
9012
9013 /* Configure LCD from extended configuration region. */
9014 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9015 cnf_size);
9016 if (ret_val)
9017 return ret_val;
9018 }
9019 }
9020
9021 return E1000_SUCCESS;
9022}
9023