blob: 1ea556ef093bd3275ee13737dda7e3568d1bf716 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Nicholas Nunley35574762006-09-27 12:53:34 -070036static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
43static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static int32_t e1000_check_downshift(struct e1000_hw *hw);
45static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47static void e1000_clear_vfta(struct e1000_hw *hw);
48static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60static int32_t e1000_id_led_init(struct e1000_hw *hw);
61static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63static void e1000_init_rx_addrs(struct e1000_hw *hw);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -070064static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070065static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86static void e1000_release_software_flag(struct e1000_hw *hw);
87static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94static void e1000_phy_init_script(struct e1000_hw *hw);
95static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
103 uint16_t count);
104static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
110 uint16_t *data);
111static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
115 uint16_t count);
116static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
117 uint16_t phy_data);
118static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
119 uint16_t *phy_data);
120static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122static void e1000_release_eeprom(struct e1000_hw *hw);
123static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700127static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Auke Kokcd94dd02006-06-27 09:08:22 -0700129static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
130 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800131static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* IGP cable length table */
134static const
135uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
144
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700145static const
146uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/******************************************************************************
157 * Set the phy type member in the hw struct.
158 *
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -0700161static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162e1000_set_phy_type(struct e1000_hw *hw)
163{
164 DEBUGFUNC("e1000_set_phy_type");
165
Auke Kok8fc897b2006-08-28 14:56:16 -0700166 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700167 return -E1000_ERR_PHY_TYPE;
168
Auke Kok8fc897b2006-08-28 14:56:16 -0700169 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700173 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 hw->phy_type = e1000_phy_m88;
175 break;
176 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 hw->phy_type = e1000_phy_igp;
182 break;
183 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
186 break;
187 case IFE_E_PHY_ID:
188 case IFE_PLUS_E_PHY_ID:
189 case IFE_C_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
191 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* Fall Through */
198 default:
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
202 }
203
204 return E1000_SUCCESS;
205}
206
207/******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
209 *
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
212static void
213e1000_phy_init_script(struct e1000_hw *hw)
214{
215 uint32_t ret_val;
216 uint16_t phy_saved_data;
217
218 DEBUGFUNC("e1000_phy_init_script");
219
Auke Kok8fc897b2006-08-28 14:56:16 -0700220 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400221 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
226
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
229
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400230 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 e1000_write_phy_reg(hw,0x0000,0x0140);
233
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400234 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Auke Kok8fc897b2006-08-28 14:56:16 -0700236 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 case e1000_82541:
238 case e1000_82547:
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
240
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
242
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
244
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
246
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
248
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
250
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
252
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
254
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
256 break;
257
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
261 break;
262 default:
263 break;
264 }
265
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
267
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400268 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
272
Auke Kok8fc897b2006-08-28 14:56:16 -0700273 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 uint16_t fused, fine, coarse;
275
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
278
Auke Kok8fc897b2006-08-28 14:56:16 -0700279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
281
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
284
Auke Kok8fc897b2006-08-28 14:56:16 -0700285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
290
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
294
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
298 }
299 }
300 }
301}
302
303/******************************************************************************
304 * Set the mac type member in the hw struct.
305 *
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
308int32_t
309e1000_set_mac_type(struct e1000_hw *hw)
310{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500311 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
318 break;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
321 break;
322 default:
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
325 }
326 break;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
330 break;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
336 break;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
343 break;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
347 break;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
352 break;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
357 break;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3;
365 break;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541;
370 break;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
376 break;
377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547;
380 break;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
383 break;
384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
389 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:
394 case E1000_DEV_ID_82572EI:
395 hw->mac_type = e1000_82572;
396 break;
397 case E1000_DEV_ID_82573E:
398 case E1000_DEV_ID_82573E_IAMT:
399 case E1000_DEV_ID_82573L:
400 hw->mac_type = e1000_82573;
401 break;
402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
406 hw->mac_type = e1000_80003es2lan;
407 break;
408 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:
412 case E1000_DEV_ID_ICH8_IFE_GT:
413 case E1000_DEV_ID_ICH8_IFE_G:
414 case E1000_DEV_ID_ICH8_IGP_M:
415 hw->mac_type = e1000_ich8lan;
416 break;
417 default:
418 /* Should never have loaded on this device */
419 return -E1000_ERR_MAC_TYPE;
420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500422 switch (hw->mac_type) {
423 case e1000_ich8lan:
424 hw->swfwhw_semaphore_present = TRUE;
425 hw->asf_firmware_present = TRUE;
426 break;
427 case e1000_80003es2lan:
428 hw->swfw_sync_present = TRUE;
429 /* fall through */
430 case e1000_82571:
431 case e1000_82572:
432 case e1000_82573:
433 hw->eeprom_semaphore_present = TRUE;
434 /* fall through */
435 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Jeff Garzik167fb282006-12-15 10:41:15 -0500445 /* The 82543 chip does not count tx_carrier_errors properly in
446 * FD mode
447 */
448 if (hw->mac_type == e1000_82543)
449 hw->bad_tx_carr_stats_fd = TRUE;
450
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500451 /* capable of receiving management packets to the host */
452 if (hw->mac_type >= e1000_82571)
453 hw->has_manc2h = TRUE;
454
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500455 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
458/*****************************************************************************
459 * Set media type and TBI compatibility.
460 *
461 * hw - Struct containing variables accessed by shared code
462 * **************************************************************************/
463void
464e1000_set_media_type(struct e1000_hw *hw)
465{
466 uint32_t status;
467
468 DEBUGFUNC("e1000_set_media_type");
469
Auke Kok8fc897b2006-08-28 14:56:16 -0700470 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 /* tbi_compatibility is only valid on 82543 */
472 hw->tbi_compatibility_en = FALSE;
473 }
474
475 switch (hw->device_id) {
476 case E1000_DEV_ID_82545GM_SERDES:
477 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400478 case E1000_DEV_ID_82571EB_SERDES:
479 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800480 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 hw->media_type = e1000_media_type_internal_serdes;
482 break;
483 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700484 switch (hw->mac_type) {
485 case e1000_82542_rev2_0:
486 case e1000_82542_rev2_1:
487 hw->media_type = e1000_media_type_fiber;
488 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700489 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700490 case e1000_82573:
491 /* The STATUS_TBIMODE bit is reserved or reused for the this
492 * device.
493 */
494 hw->media_type = e1000_media_type_copper;
495 break;
496 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700498 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 hw->media_type = e1000_media_type_fiber;
500 /* tbi_compatibility not valid on fiber */
501 hw->tbi_compatibility_en = FALSE;
502 } else {
503 hw->media_type = e1000_media_type_copper;
504 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700505 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507 }
508}
509
510/******************************************************************************
511 * Reset the transmit and receive units; mask and clear all interrupts.
512 *
513 * hw - Struct containing variables accessed by shared code
514 *****************************************************************************/
515int32_t
516e1000_reset_hw(struct e1000_hw *hw)
517{
518 uint32_t ctrl;
519 uint32_t ctrl_ext;
520 uint32_t icr;
521 uint32_t manc;
522 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700523 uint32_t timeout;
524 uint32_t extcnf_ctrl;
525 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 DEBUGFUNC("e1000_reset_hw");
528
529 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700530 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
532 e1000_pci_clear_mwi(hw);
533 }
534
Auke Kok8fc897b2006-08-28 14:56:16 -0700535 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700536 /* Prevent the PCI-E bus from sticking if there is no TLP connection
537 * on the last TLP read/write transaction when MAC is reset.
538 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700539 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700540 DEBUGOUT("PCI-E Master disable polling has failed.\n");
541 }
542 }
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 /* Clear interrupt mask to stop board from generating interrupts */
545 DEBUGOUT("Masking off all interrupts\n");
546 E1000_WRITE_REG(hw, IMC, 0xffffffff);
547
548 /* Disable the Transmit and Receive units. Then delay to allow
549 * any pending transactions to complete before we hit the MAC with
550 * the global reset.
551 */
552 E1000_WRITE_REG(hw, RCTL, 0);
553 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
554 E1000_WRITE_FLUSH(hw);
555
556 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
557 hw->tbi_compatibility_on = FALSE;
558
559 /* Delay to allow any outstanding PCI transactions to complete before
560 * resetting the device
561 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400562 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 ctrl = E1000_READ_REG(hw, CTRL);
565
566 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700567 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700568 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400569 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
571
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700572 /* Must acquire the MDIO ownership before MAC reset.
573 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700574 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700575 timeout = 10;
576
577 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
578 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
579
580 do {
581 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
582 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
583
Auke Kok8fc897b2006-08-28 14:56:16 -0700584 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700585 break;
586 else
587 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
588
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400589 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700590 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700591 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700592 }
593
Auke Kokcd94dd02006-06-27 09:08:22 -0700594 /* Workaround for ICH8 bit corruption issue in FIFO memory */
595 if (hw->mac_type == e1000_ich8lan) {
596 /* Set Tx and Rx buffer allocation to 8k apiece. */
597 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
598 /* Set Packet Buffer Size to 16k. */
599 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
600 }
601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /* Issue a global reset to the MAC. This will reset the chip's
603 * transmit, receive, DMA, and link units. It will not effect
604 * the current PCI configuration. The global reset bit is self-
605 * clearing, and should clear within a microsecond.
606 */
607 DEBUGOUT("Issuing a global reset to MAC\n");
608
Auke Kok8fc897b2006-08-28 14:56:16 -0700609 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 case e1000_82544:
611 case e1000_82540:
612 case e1000_82545:
613 case e1000_82546:
614 case e1000_82541:
615 case e1000_82541_rev_2:
616 /* These controllers can't ack the 64-bit write when issuing the
617 * reset, so use IO-mapping as a workaround to issue the reset */
618 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
619 break;
620 case e1000_82545_rev_3:
621 case e1000_82546_rev_3:
622 /* Reset is performed on a shadow of the control register */
623 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
624 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700625 case e1000_ich8lan:
626 if (!hw->phy_reset_disable &&
627 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
628 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
629 * at the same time to make sure the interface between
630 * MAC and the external PHY is reset.
631 */
632 ctrl |= E1000_CTRL_PHY_RST;
633 }
634
635 e1000_get_software_flag(hw);
636 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400637 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700638 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 default:
640 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
641 break;
642 }
643
644 /* After MAC reset, force reload of EEPROM to restore power-on settings to
645 * device. Later controllers reload the EEPROM automatically, so just wait
646 * for reload to complete.
647 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700648 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 case e1000_82542_rev2_0:
650 case e1000_82542_rev2_1:
651 case e1000_82543:
652 case e1000_82544:
653 /* Wait for reset to complete */
654 udelay(10);
655 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
656 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
657 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
658 E1000_WRITE_FLUSH(hw);
659 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400660 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 break;
662 case e1000_82541:
663 case e1000_82541_rev_2:
664 case e1000_82547:
665 case e1000_82547_rev_2:
666 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400667 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700669 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500670 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
671 udelay(10);
672 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
673 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
674 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
675 E1000_WRITE_FLUSH(hw);
676 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700677 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700678 default:
679 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700680 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700681 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700682 return ret_val;
683 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
686 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700687 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 manc = E1000_READ_REG(hw, MANC);
689 manc &= ~(E1000_MANC_ARP_EN);
690 E1000_WRITE_REG(hw, MANC, manc);
691 }
692
Auke Kok8fc897b2006-08-28 14:56:16 -0700693 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 e1000_phy_init_script(hw);
695
696 /* Configure activity LED after PHY reset */
697 led_ctrl = E1000_READ_REG(hw, LEDCTL);
698 led_ctrl &= IGP_ACTIVITY_LED_MASK;
699 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
700 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
701 }
702
703 /* Clear interrupt mask to stop board from generating interrupts */
704 DEBUGOUT("Masking off all interrupts\n");
705 E1000_WRITE_REG(hw, IMC, 0xffffffff);
706
707 /* Clear any pending interrupt events. */
708 icr = E1000_READ_REG(hw, ICR);
709
710 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700711 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400712 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 e1000_pci_set_mwi(hw);
714 }
715
Auke Kokcd94dd02006-06-27 09:08:22 -0700716 if (hw->mac_type == e1000_ich8lan) {
717 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
718 kab |= E1000_KABGTXD_BGSQLBIAS;
719 E1000_WRITE_REG(hw, KABGTXD, kab);
720 }
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 return E1000_SUCCESS;
723}
724
725/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700726 *
727 * Initialize a number of hardware-dependent bits
728 *
729 * hw: Struct containing variables accessed by shared code
730 *
731 * This function contains hardware limitation workarounds for PCI-E adapters
732 *
733 *****************************************************************************/
734static void
735e1000_initialize_hardware_bits(struct e1000_hw *hw)
736{
737 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
738 /* Settings common to all PCI-express silicon */
739 uint32_t reg_ctrl, reg_ctrl_ext;
740 uint32_t reg_tarc0, reg_tarc1;
741 uint32_t reg_tctl;
742 uint32_t reg_txdctl, reg_txdctl1;
743
744 /* link autonegotiation/sync workarounds */
745 reg_tarc0 = E1000_READ_REG(hw, TARC0);
746 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
747
748 /* Enable not-done TX descriptor counting */
749 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
750 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
751 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
752 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
753 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
754 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
755
756 switch (hw->mac_type) {
757 case e1000_82571:
758 case e1000_82572:
759 /* Clear PHY TX compatible mode bits */
760 reg_tarc1 = E1000_READ_REG(hw, TARC1);
761 reg_tarc1 &= ~((1 << 30)|(1 << 29));
762
763 /* link autonegotiation/sync workarounds */
764 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
765
766 /* TX ring control fixes */
767 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
768
769 /* Multiple read bit is reversed polarity */
770 reg_tctl = E1000_READ_REG(hw, TCTL);
771 if (reg_tctl & E1000_TCTL_MULR)
772 reg_tarc1 &= ~(1 << 28);
773 else
774 reg_tarc1 |= (1 << 28);
775
776 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
777 break;
778 case e1000_82573:
779 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
780 reg_ctrl_ext &= ~(1 << 23);
781 reg_ctrl_ext |= (1 << 22);
782
783 /* TX byte count fix */
784 reg_ctrl = E1000_READ_REG(hw, CTRL);
785 reg_ctrl &= ~(1 << 29);
786
787 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
788 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
789 break;
790 case e1000_80003es2lan:
791 /* improve small packet performace for fiber/serdes */
792 if ((hw->media_type == e1000_media_type_fiber) ||
793 (hw->media_type == e1000_media_type_internal_serdes)) {
794 reg_tarc0 &= ~(1 << 20);
795 }
796
797 /* Multiple read bit is reversed polarity */
798 reg_tctl = E1000_READ_REG(hw, TCTL);
799 reg_tarc1 = E1000_READ_REG(hw, TARC1);
800 if (reg_tctl & E1000_TCTL_MULR)
801 reg_tarc1 &= ~(1 << 28);
802 else
803 reg_tarc1 |= (1 << 28);
804
805 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
806 break;
807 case e1000_ich8lan:
808 /* Reduce concurrent DMA requests to 3 from 4 */
809 if ((hw->revision_id < 3) ||
810 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
811 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
812 reg_tarc0 |= ((1 << 29)|(1 << 28));
813
814 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
815 reg_ctrl_ext |= (1 << 22);
816 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
817
818 /* workaround TX hang with TSO=on */
819 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
820
821 /* Multiple read bit is reversed polarity */
822 reg_tctl = E1000_READ_REG(hw, TCTL);
823 reg_tarc1 = E1000_READ_REG(hw, TARC1);
824 if (reg_tctl & E1000_TCTL_MULR)
825 reg_tarc1 &= ~(1 << 28);
826 else
827 reg_tarc1 |= (1 << 28);
828
829 /* workaround TX hang with TSO=on */
830 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
831
832 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
833 break;
834 default:
835 break;
836 }
837
838 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
839 }
840}
841
842/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 * Performs basic configuration of the adapter.
844 *
845 * hw - Struct containing variables accessed by shared code
846 *
847 * Assumes that the controller has previously been reset and is in a
848 * post-reset uninitialized state. Initializes the receive address registers,
849 * multicast table, and VLAN filter table. Calls routines to setup link
850 * configuration and flow control settings. Clears all on-chip counters. Leaves
851 * the transmit and receive units disabled and uninitialized.
852 *****************************************************************************/
853int32_t
854e1000_init_hw(struct e1000_hw *hw)
855{
856 uint32_t ctrl;
857 uint32_t i;
858 int32_t ret_val;
859 uint16_t pcix_cmd_word;
860 uint16_t pcix_stat_hi_word;
861 uint16_t cmd_mmrbc;
862 uint16_t stat_mmrbc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700863 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800864 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800865 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 DEBUGFUNC("e1000_init_hw");
868
Jeff Kirsher7820d422006-08-16 13:39:00 -0700869 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700870 if ((hw->mac_type == e1000_ich8lan) &&
871 ((hw->revision_id < 3) ||
872 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
873 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
874 reg_data = E1000_READ_REG(hw, STATUS);
875 reg_data &= ~0x80000000;
876 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700877 }
878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 /* Initialize Identification LED */
880 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700881 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 DEBUGOUT("Error Initializing Identification LED\n");
883 return ret_val;
884 }
885
886 /* Set the media type and TBI compatibility */
887 e1000_set_media_type(hw);
888
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700889 /* Must be called after e1000_set_media_type because media_type is used */
890 e1000_initialize_hardware_bits(hw);
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 /* Disabling VLAN filtering. */
893 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700894 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
895 if (hw->mac_type != e1000_ich8lan) {
896 if (hw->mac_type < e1000_82545_rev_3)
897 E1000_WRITE_REG(hw, VET, 0);
898 e1000_clear_vfta(hw);
899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700902 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
904 e1000_pci_clear_mwi(hw);
905 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
906 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400907 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 }
909
910 /* Setup the receive address. This involves initializing all of the Receive
911 * Address Registers (RARs 0 - 15).
912 */
913 e1000_init_rx_addrs(hw);
914
915 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700916 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 E1000_WRITE_REG(hw, RCTL, 0);
918 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400919 msleep(1);
920 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 e1000_pci_set_mwi(hw);
922 }
923
924 /* Zero out the Multicast HASH table */
925 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700926 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700927 if (hw->mac_type == e1000_ich8lan)
928 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700929 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700931 /* use write flush to prevent Memory Write Block (MWB) from
932 * occuring when accessing our register space */
933 E1000_WRITE_FLUSH(hw);
934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 /* Set the PCI priority bit correctly in the CTRL register. This
937 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700938 * gives equal priority to transmits and receives. Valid only on
939 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700941 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 ctrl = E1000_READ_REG(hw, CTRL);
943 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
944 }
945
Auke Kok8fc897b2006-08-28 14:56:16 -0700946 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 case e1000_82545_rev_3:
948 case e1000_82546_rev_3:
949 break;
950 default:
951 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700952 if (hw->bus_type == e1000_bus_type_pcix) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
954 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
955 &pcix_stat_hi_word);
956 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
957 PCIX_COMMAND_MMRBC_SHIFT;
958 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
959 PCIX_STATUS_HI_MMRBC_SHIFT;
Auke Kok8fc897b2006-08-28 14:56:16 -0700960 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
Auke Kok8fc897b2006-08-28 14:56:16 -0700962 if (cmd_mmrbc > stat_mmrbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
964 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
965 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
966 &pcix_cmd_word);
967 }
968 }
969 break;
970 }
971
Auke Kokcd94dd02006-06-27 09:08:22 -0700972 /* More time needed for PHY to initialize */
973 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400974 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 /* Call a subroutine to configure the link and setup flow control. */
977 ret_val = e1000_setup_link(hw);
978
979 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700980 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 ctrl = E1000_READ_REG(hw, TXDCTL);
982 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
983 E1000_WRITE_REG(hw, TXDCTL, ctrl);
984 }
985
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700986 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700987 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700988 }
989
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400990 switch (hw->mac_type) {
991 default:
992 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800993 case e1000_80003es2lan:
994 /* Enable retransmit on late collisions */
995 reg_data = E1000_READ_REG(hw, TCTL);
996 reg_data |= E1000_TCTL_RTLC;
997 E1000_WRITE_REG(hw, TCTL, reg_data);
998
999 /* Configure Gigabit Carry Extend Padding */
1000 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1001 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1002 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1003 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1004
1005 /* Configure Transmit Inter-Packet Gap */
1006 reg_data = E1000_READ_REG(hw, TIPG);
1007 reg_data &= ~E1000_TIPG_IPGT_MASK;
1008 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1009 E1000_WRITE_REG(hw, TIPG, reg_data);
1010
1011 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1012 reg_data &= ~0x00100000;
1013 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1014 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001015 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001016 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001017 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001018 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001019 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001020 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1021 break;
1022 }
1023
1024
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001025 if (hw->mac_type == e1000_82573) {
1026 uint32_t gcr = E1000_READ_REG(hw, GCR);
1027 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1028 E1000_WRITE_REG(hw, GCR, gcr);
1029 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* Clear all of the statistics registers (clear on read). It is
1032 * important that we do this after we have tried to establish link
1033 * because the symbol error count will increment wildly if there
1034 * is no link.
1035 */
1036 e1000_clear_hw_cntrs(hw);
1037
Auke Kokcd94dd02006-06-27 09:08:22 -07001038 /* ICH8 No-snoop bits are opposite polarity.
1039 * Set to snoop by default after reset. */
1040 if (hw->mac_type == e1000_ich8lan)
1041 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1042
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001043 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1044 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1045 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1046 /* Relaxed ordering must be disabled to avoid a parity
1047 * error crash in a PCI slot. */
1048 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1049 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1050 }
1051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 return ret_val;
1053}
1054
1055/******************************************************************************
1056 * Adjust SERDES output amplitude based on EEPROM setting.
1057 *
1058 * hw - Struct containing variables accessed by shared code.
1059 *****************************************************************************/
1060static int32_t
1061e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1062{
1063 uint16_t eeprom_data;
1064 int32_t ret_val;
1065
1066 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1067
Auke Kok8fc897b2006-08-28 14:56:16 -07001068 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return E1000_SUCCESS;
1070
Auke Kok8fc897b2006-08-28 14:56:16 -07001071 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 case e1000_82545_rev_3:
1073 case e1000_82546_rev_3:
1074 break;
1075 default:
1076 return E1000_SUCCESS;
1077 }
1078
1079 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1080 if (ret_val) {
1081 return ret_val;
1082 }
1083
Auke Kok8fc897b2006-08-28 14:56:16 -07001084 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001086 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001088 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 return ret_val;
1090 }
1091
1092 return E1000_SUCCESS;
1093}
1094
1095/******************************************************************************
1096 * Configures flow control and link settings.
1097 *
1098 * hw - Struct containing variables accessed by shared code
1099 *
1100 * Determines which flow control settings to use. Calls the apropriate media-
1101 * specific link configuration function. Configures the flow control settings.
1102 * Assuming the adapter has a valid link partner, a valid link should be
1103 * established. Assumes the hardware has previously been reset and the
1104 * transmitter and receiver are not enabled.
1105 *****************************************************************************/
1106int32_t
1107e1000_setup_link(struct e1000_hw *hw)
1108{
1109 uint32_t ctrl_ext;
1110 int32_t ret_val;
1111 uint16_t eeprom_data;
1112
1113 DEBUGFUNC("e1000_setup_link");
1114
Jeff Kirsher526f9952006-01-12 16:50:46 -08001115 /* In the case of the phy reset being blocked, we already have a link.
1116 * We do not have to set it up again. */
1117 if (e1000_check_phy_reset_block(hw))
1118 return E1000_SUCCESS;
1119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 /* Read and store word 0x0F of the EEPROM. This word contains bits
1121 * that determine the hardware's default PAUSE (flow control) mode,
1122 * a bit that determines whether the HW defaults to enabling or
1123 * disabling auto-negotiation, and the direction of the
1124 * SW defined pins. If there is no SW over-ride of the flow
1125 * control setting, then the variable hw->fc will
1126 * be initialized based on a value in the EEPROM.
1127 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001128 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001129 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001130 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001131 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001132 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001133 break;
1134 default:
1135 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1136 1, &eeprom_data);
1137 if (ret_val) {
1138 DEBUGOUT("EEPROM Read Error\n");
1139 return -E1000_ERR_EEPROM;
1140 }
1141 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001142 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001143 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1144 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001145 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001146 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001147 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001148 break;
1149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 }
1151
1152 /* We want to save off the original Flow Control configuration just
1153 * in case we get disconnected and then reconnected into a different
1154 * hub or switch with different Flow Control capabilities.
1155 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001156 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001157 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Auke Kok8fc897b2006-08-28 14:56:16 -07001159 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001160 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
1162 hw->original_fc = hw->fc;
1163
1164 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1165
1166 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1167 * polarity value for the SW controlled pins, and setup the
1168 * Extended Device Control reg with that info.
1169 * This is needed because one of the SW controlled pins is used for
1170 * signal detection. So this should be done before e1000_setup_pcs_link()
1171 * or e1000_phy_setup() is called.
1172 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001173 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001174 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1175 1, &eeprom_data);
1176 if (ret_val) {
1177 DEBUGOUT("EEPROM Read Error\n");
1178 return -E1000_ERR_EEPROM;
1179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1181 SWDPIO__EXT_SHIFT);
1182 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1183 }
1184
1185 /* Call the necessary subroutine to configure the link. */
1186 ret_val = (hw->media_type == e1000_media_type_copper) ?
1187 e1000_setup_copper_link(hw) :
1188 e1000_setup_fiber_serdes_link(hw);
1189
1190 /* Initialize the flow control address, type, and PAUSE timer
1191 * registers to their default values. This is done even if flow
1192 * control is disabled, because it does not hurt anything to
1193 * initialize these registers.
1194 */
1195 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1196
Auke Kokcd94dd02006-06-27 09:08:22 -07001197 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1198 if (hw->mac_type != e1000_ich8lan) {
1199 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1200 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1201 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1202 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1205
1206 /* Set the flow control receive threshold registers. Normally,
1207 * these registers will be set to a default threshold that may be
1208 * adjusted later by the driver's runtime code. However, if the
1209 * ability to transmit pause frames in not enabled, then these
1210 * registers will be set to 0.
1211 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001212 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 E1000_WRITE_REG(hw, FCRTL, 0);
1214 E1000_WRITE_REG(hw, FCRTH, 0);
1215 } else {
1216 /* We need to set up the Receive Threshold high and low water marks
1217 * as well as (optionally) enabling the transmission of XON frames.
1218 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001219 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1221 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1222 } else {
1223 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1224 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1225 }
1226 }
1227 return ret_val;
1228}
1229
1230/******************************************************************************
1231 * Sets up link for a fiber based or serdes based adapter
1232 *
1233 * hw - Struct containing variables accessed by shared code
1234 *
1235 * Manipulates Physical Coding Sublayer functions in order to configure
1236 * link. Assumes the hardware has been previously reset and the transmitter
1237 * and receiver are not enabled.
1238 *****************************************************************************/
1239static int32_t
1240e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1241{
1242 uint32_t ctrl;
1243 uint32_t status;
1244 uint32_t txcw = 0;
1245 uint32_t i;
1246 uint32_t signal = 0;
1247 int32_t ret_val;
1248
1249 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1250
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001251 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1252 * until explicitly turned off or a power cycle is performed. A read to
1253 * the register does not indicate its status. Therefore, we ensure
1254 * loopback mode is disabled during initialization.
1255 */
1256 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1257 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1258
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001259 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 * set when the optics detect a signal. On older adapters, it will be
1261 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001262 * If we're on serdes media, adjust the output amplitude to value
1263 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 */
1265 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001266 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1268
1269 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001270 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 return ret_val;
1272
1273 /* Take the link out of reset */
1274 ctrl &= ~(E1000_CTRL_LRST);
1275
1276 /* Adjust VCO speed to improve BER performance */
1277 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001278 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 return ret_val;
1280
1281 e1000_config_collision_dist(hw);
1282
1283 /* Check for a software override of the flow control settings, and setup
1284 * the device accordingly. If auto-negotiation is enabled, then software
1285 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1286 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1287 * auto-negotiation is disabled, then software will have to manually
1288 * configure the two flow control enable bits in the CTRL register.
1289 *
1290 * The possible values of the "fc" parameter are:
1291 * 0: Flow control is completely disabled
1292 * 1: Rx flow control is enabled (we can receive pause frames, but
1293 * not send pause frames).
1294 * 2: Tx flow control is enabled (we can send pause frames but we do
1295 * not support receiving pause frames).
1296 * 3: Both Rx and TX flow control (symmetric) are enabled.
1297 */
1298 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001299 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 /* Flow control is completely disabled by a software over-ride. */
1301 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1302 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001303 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 /* RX Flow control is enabled and TX Flow control is disabled by a
1305 * software over-ride. Since there really isn't a way to advertise
1306 * that we are capable of RX Pause ONLY, we will advertise that we
1307 * support both symmetric and asymmetric RX PAUSE. Later, we will
1308 * disable the adapter's ability to send PAUSE frames.
1309 */
1310 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1311 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001312 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1314 * software over-ride.
1315 */
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1317 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001318 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1320 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1321 break;
1322 default:
1323 DEBUGOUT("Flow control param set incorrectly\n");
1324 return -E1000_ERR_CONFIG;
1325 break;
1326 }
1327
1328 /* Since auto-negotiation is enabled, take the link out of reset (the link
1329 * will be in reset, because we previously reset the chip). This will
1330 * restart auto-negotiation. If auto-neogtiation is successful then the
1331 * link-up status bit will be set and the flow control enable bits (RFCE
1332 * and TFCE) will be set according to their negotiated value.
1333 */
1334 DEBUGOUT("Auto-negotiation enabled\n");
1335
1336 E1000_WRITE_REG(hw, TXCW, txcw);
1337 E1000_WRITE_REG(hw, CTRL, ctrl);
1338 E1000_WRITE_FLUSH(hw);
1339
1340 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001341 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1344 * indication in the Device Status Register. Time-out if a link isn't
1345 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1346 * less than 500 milliseconds even if the other end is doing it in SW).
1347 * For internal serdes, we just assume a signal is present, then poll.
1348 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001349 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1351 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001352 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001353 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001355 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001357 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1359 hw->autoneg_failed = 1;
1360 /* AutoNeg failed to achieve a link, so we'll call
1361 * e1000_check_for_link. This routine will force the link up if
1362 * we detect a signal. This will allow us to communicate with
1363 * non-autonegotiating link partners.
1364 */
1365 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001366 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 DEBUGOUT("Error while checking for link\n");
1368 return ret_val;
1369 }
1370 hw->autoneg_failed = 0;
1371 } else {
1372 hw->autoneg_failed = 0;
1373 DEBUGOUT("Valid Link Found\n");
1374 }
1375 } else {
1376 DEBUGOUT("No Signal Detected\n");
1377 }
1378 return E1000_SUCCESS;
1379}
1380
1381/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001382* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383*
1384* hw - Struct containing variables accessed by shared code
1385******************************************************************************/
1386static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001387e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 uint16_t phy_data;
1392
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001393 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
1395 ctrl = E1000_READ_REG(hw, CTRL);
1396 /* With 82543, we need to force speed and duplex on the MAC equal to what
1397 * the PHY speed and duplex configuration is. In addition, we need to
1398 * perform a hardware reset on the PHY to take it out of reset.
1399 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001400 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 ctrl |= E1000_CTRL_SLU;
1402 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1403 E1000_WRITE_REG(hw, CTRL, ctrl);
1404 } else {
1405 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1406 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001407 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001408 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001409 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 }
1411
1412 /* Make sure we have a valid PHY */
1413 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001414 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 DEBUGOUT("Error, did not detect valid phy.\n");
1416 return ret_val;
1417 }
1418 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1419
1420 /* Set PHY to class A mode (if necessary) */
1421 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001422 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 return ret_val;
1424
Auke Kok8fc897b2006-08-28 14:56:16 -07001425 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 (hw->mac_type == e1000_82546_rev_3)) {
1427 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1428 phy_data |= 0x00000008;
1429 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1430 }
1431
Auke Kok8fc897b2006-08-28 14:56:16 -07001432 if (hw->mac_type <= e1000_82543 ||
1433 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1434 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 hw->phy_reset_disable = FALSE;
1436
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001437 return E1000_SUCCESS;
1438}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001441/********************************************************************
1442* Copper link setup for e1000_phy_igp series.
1443*
1444* hw - Struct containing variables accessed by shared code
1445*********************************************************************/
1446static int32_t
1447e1000_copper_link_igp_setup(struct e1000_hw *hw)
1448{
1449 uint32_t led_ctrl;
1450 int32_t ret_val;
1451 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001453 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001455 if (hw->phy_reset_disable)
1456 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001457
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001458 ret_val = e1000_phy_reset(hw);
1459 if (ret_val) {
1460 DEBUGOUT("Error Resetting the PHY\n");
1461 return ret_val;
1462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Auke Kok8fc897b2006-08-28 14:56:16 -07001464 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001465 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001466 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001467 /* Configure activity LED after PHY reset */
1468 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1469 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1470 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1471 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001472 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001473
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001474 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1475 if (hw->phy_type == e1000_phy_igp) {
1476 /* disable lplu d3 during driver init */
1477 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1478 if (ret_val) {
1479 DEBUGOUT("Error Disabling LPLU D3\n");
1480 return ret_val;
1481 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001482 }
1483
1484 /* disable lplu d0 during driver init */
1485 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1486 if (ret_val) {
1487 DEBUGOUT("Error Disabling LPLU D0\n");
1488 return ret_val;
1489 }
1490 /* Configure mdi-mdix settings */
1491 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1492 if (ret_val)
1493 return ret_val;
1494
1495 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1496 hw->dsp_config_state = e1000_dsp_config_disabled;
1497 /* Force MDI for earlier revs of the IGP PHY */
1498 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1499 hw->mdix = 1;
1500
1501 } else {
1502 hw->dsp_config_state = e1000_dsp_config_enabled;
1503 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1504
1505 switch (hw->mdix) {
1506 case 1:
1507 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1508 break;
1509 case 2:
1510 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1511 break;
1512 case 0:
1513 default:
1514 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1515 break;
1516 }
1517 }
1518 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001519 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001520 return ret_val;
1521
1522 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001523 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001524 e1000_ms_type phy_ms_setting = hw->master_slave;
1525
Auke Kok8fc897b2006-08-28 14:56:16 -07001526 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001527 hw->ffe_config_state = e1000_ffe_config_enabled;
1528
Auke Kok8fc897b2006-08-28 14:56:16 -07001529 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001530 hw->dsp_config_state = e1000_dsp_config_enabled;
1531
1532 /* when autonegotiation advertisment is only 1000Mbps then we
1533 * should disable SmartSpeed and enable Auto MasterSlave
1534 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001535 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001536 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001537 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1538 &phy_data);
1539 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001541 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001542 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1543 phy_data);
1544 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001546 /* Set auto Master/Slave resolution process */
1547 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001548 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001549 return ret_val;
1550 phy_data &= ~CR_1000T_MS_ENABLE;
1551 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001552 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001553 return ret_val;
1554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001556 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001557 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001558 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001560 /* load defaults for future use */
1561 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1562 ((phy_data & CR_1000T_MS_VALUE) ?
1563 e1000_ms_force_master :
1564 e1000_ms_force_slave) :
1565 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001567 switch (phy_ms_setting) {
1568 case e1000_ms_force_master:
1569 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1570 break;
1571 case e1000_ms_force_slave:
1572 phy_data |= CR_1000T_MS_ENABLE;
1573 phy_data &= ~(CR_1000T_MS_VALUE);
1574 break;
1575 case e1000_ms_auto:
1576 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001578 break;
1579 }
1580 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001581 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001582 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Malli Chilakala2b028932005-06-17 17:46:06 -07001585 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001586}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001588/********************************************************************
1589* Copper link setup for e1000_phy_gg82563 series.
1590*
1591* hw - Struct containing variables accessed by shared code
1592*********************************************************************/
1593static int32_t
1594e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1595{
1596 int32_t ret_val;
1597 uint16_t phy_data;
1598 uint32_t reg_data;
1599
1600 DEBUGFUNC("e1000_copper_link_ggp_setup");
1601
Auke Kok8fc897b2006-08-28 14:56:16 -07001602 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001603
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001604 /* Enable CRS on TX for half-duplex operation. */
1605 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1606 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001607 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001608 return ret_val;
1609
1610 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1611 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1612 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1613
1614 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1615 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001616 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001617 return ret_val;
1618
1619 /* Options:
1620 * MDI/MDI-X = 0 (default)
1621 * 0 - Auto for all speeds
1622 * 1 - MDI mode
1623 * 2 - MDI-X mode
1624 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1625 */
1626 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001627 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001628 return ret_val;
1629
1630 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1631
1632 switch (hw->mdix) {
1633 case 1:
1634 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1635 break;
1636 case 2:
1637 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1638 break;
1639 case 0:
1640 default:
1641 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1642 break;
1643 }
1644
1645 /* Options:
1646 * disable_polarity_correction = 0 (default)
1647 * Automatic Correction for Reversed Cable Polarity
1648 * 0 - Disabled
1649 * 1 - Enabled
1650 */
1651 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001652 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001653 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1654 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1655
Auke Kok8fc897b2006-08-28 14:56:16 -07001656 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001657 return ret_val;
1658
1659 /* SW Reset the PHY so all changes take effect */
1660 ret_val = e1000_phy_reset(hw);
1661 if (ret_val) {
1662 DEBUGOUT("Error Resetting the PHY\n");
1663 return ret_val;
1664 }
1665 } /* phy_reset_disable */
1666
1667 if (hw->mac_type == e1000_80003es2lan) {
1668 /* Bypass RX and TX FIFO's */
1669 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1670 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1671 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1672 if (ret_val)
1673 return ret_val;
1674
1675 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1676 if (ret_val)
1677 return ret_val;
1678
1679 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1680 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1681
1682 if (ret_val)
1683 return ret_val;
1684
1685 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1686 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1687 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1688
1689 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1690 &phy_data);
1691 if (ret_val)
1692 return ret_val;
1693
1694 /* Do not init these registers when the HW is in IAMT mode, since the
1695 * firmware will have already initialized them. We only initialize
1696 * them if the HW is not in IAMT mode.
1697 */
1698 if (e1000_check_mng_mode(hw) == FALSE) {
1699 /* Enable Electrical Idle on the PHY */
1700 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1701 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1702 phy_data);
1703 if (ret_val)
1704 return ret_val;
1705
1706 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1707 &phy_data);
1708 if (ret_val)
1709 return ret_val;
1710
Auke Kokcd94dd02006-06-27 09:08:22 -07001711 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001712 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1713 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001714
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001715 if (ret_val)
1716 return ret_val;
1717 }
1718
1719 /* Workaround: Disable padding in Kumeran interface in the MAC
1720 * and in the PHY to avoid CRC errors.
1721 */
1722 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1723 &phy_data);
1724 if (ret_val)
1725 return ret_val;
1726 phy_data |= GG82563_ICR_DIS_PADDING;
1727 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1728 phy_data);
1729 if (ret_val)
1730 return ret_val;
1731 }
1732
1733 return E1000_SUCCESS;
1734}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001736/********************************************************************
1737* Copper link setup for e1000_phy_m88 series.
1738*
1739* hw - Struct containing variables accessed by shared code
1740*********************************************************************/
1741static int32_t
1742e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1743{
1744 int32_t ret_val;
1745 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001747 DEBUGFUNC("e1000_copper_link_mgp_setup");
1748
Auke Kok8fc897b2006-08-28 14:56:16 -07001749 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001750 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001751
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001752 /* Enable CRS on TX. This must be set for half-duplex operation. */
1753 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001754 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001755 return ret_val;
1756
1757 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1758
1759 /* Options:
1760 * MDI/MDI-X = 0 (default)
1761 * 0 - Auto for all speeds
1762 * 1 - MDI mode
1763 * 2 - MDI-X mode
1764 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1765 */
1766 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1767
1768 switch (hw->mdix) {
1769 case 1:
1770 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1771 break;
1772 case 2:
1773 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1774 break;
1775 case 3:
1776 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1777 break;
1778 case 0:
1779 default:
1780 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1781 break;
1782 }
1783
1784 /* Options:
1785 * disable_polarity_correction = 0 (default)
1786 * Automatic Correction for Reversed Cable Polarity
1787 * 0 - Disabled
1788 * 1 - Enabled
1789 */
1790 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001791 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001792 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001793 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1794 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001795 return ret_val;
1796
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001797 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001798 /* Force TX_CLK in the Extended PHY Specific Control Register
1799 * to 25MHz clock.
1800 */
1801 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1802 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001803 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001804
1805 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1806
1807 if ((hw->phy_revision == E1000_REVISION_2) &&
1808 (hw->phy_id == M88E1111_I_PHY_ID)) {
1809 /* Vidalia Phy, set the downshift counter to 5x */
1810 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1811 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
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 } else {
1817 /* Configure Master and Slave downshift values */
1818 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1819 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1820 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1821 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1822 ret_val = e1000_write_phy_reg(hw,
1823 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1824 if (ret_val)
1825 return ret_val;
1826 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001829 /* SW Reset the PHY so all changes take effect */
1830 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001831 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001832 DEBUGOUT("Error Resetting the PHY\n");
1833 return ret_val;
1834 }
1835
1836 return E1000_SUCCESS;
1837}
1838
1839/********************************************************************
1840* Setup auto-negotiation and flow control advertisements,
1841* and then perform auto-negotiation.
1842*
1843* hw - Struct containing variables accessed by shared code
1844*********************************************************************/
1845static int32_t
1846e1000_copper_link_autoneg(struct e1000_hw *hw)
1847{
1848 int32_t ret_val;
1849 uint16_t phy_data;
1850
1851 DEBUGFUNC("e1000_copper_link_autoneg");
1852
1853 /* Perform some bounds checking on the hw->autoneg_advertised
1854 * parameter. If this variable is zero, then set it to the default.
1855 */
1856 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1857
1858 /* If autoneg_advertised is zero, we assume it was not defaulted
1859 * by the calling code so we set to advertise full capability.
1860 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001861 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001862 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1863
Auke Kokcd94dd02006-06-27 09:08:22 -07001864 /* IFE phy only supports 10/100 */
1865 if (hw->phy_type == e1000_phy_ife)
1866 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1867
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001868 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1869 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001870 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001871 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1872 return ret_val;
1873 }
1874 DEBUGOUT("Restarting Auto-Neg\n");
1875
1876 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1877 * the Auto Neg Restart bit in the PHY control register.
1878 */
1879 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001880 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001881 return ret_val;
1882
1883 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1884 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001885 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001886 return ret_val;
1887
1888 /* Does the user want to wait for Auto-Neg to complete here, or
1889 * check at a later time (for example, callback routine).
1890 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001891 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001892 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001893 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001894 DEBUGOUT("Error while waiting for autoneg to complete\n");
1895 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001899 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001901 return E1000_SUCCESS;
1902}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001904/******************************************************************************
1905* Config the MAC and the PHY after link is up.
1906* 1) Set up the MAC to the current PHY speed/duplex
1907* if we are on 82543. If we
1908* are on newer silicon, we only need to configure
1909* collision distance in the Transmit Control Register.
1910* 2) Set up flow control on the MAC to that established with
1911* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001912* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001913*
1914* hw - Struct containing variables accessed by shared code
1915******************************************************************************/
1916static int32_t
1917e1000_copper_link_postconfig(struct e1000_hw *hw)
1918{
1919 int32_t ret_val;
1920 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001921
Auke Kok8fc897b2006-08-28 14:56:16 -07001922 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001923 e1000_config_collision_dist(hw);
1924 } else {
1925 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001926 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001927 DEBUGOUT("Error configuring MAC to PHY settings\n");
1928 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001930 }
1931 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001932 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001933 DEBUGOUT("Error Configuring Flow Control\n");
1934 return ret_val;
1935 }
1936
1937 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001938 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001939 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001940 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001941 DEBUGOUT("Error Configuring DSP after link up\n");
1942 return ret_val;
1943 }
1944 }
Auke Kok76c224b2006-05-23 13:36:06 -07001945
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001946 return E1000_SUCCESS;
1947}
1948
1949/******************************************************************************
1950* Detects which PHY is present and setup the speed and duplex
1951*
1952* hw - Struct containing variables accessed by shared code
1953******************************************************************************/
1954static int32_t
1955e1000_setup_copper_link(struct e1000_hw *hw)
1956{
1957 int32_t ret_val;
1958 uint16_t i;
1959 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001960 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001961
1962 DEBUGFUNC("e1000_setup_copper_link");
1963
Auke Kokcd94dd02006-06-27 09:08:22 -07001964 switch (hw->mac_type) {
1965 case e1000_80003es2lan:
1966 case e1000_ich8lan:
1967 /* Set the mac to wait the maximum time between each
1968 * iteration and increase the max iterations when
1969 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1970 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1971 if (ret_val)
1972 return ret_val;
1973 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1974 if (ret_val)
1975 return ret_val;
1976 reg_data |= 0x3F;
1977 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1978 if (ret_val)
1979 return ret_val;
1980 default:
1981 break;
1982 }
1983
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001984 /* Check if it is a valid PHY and set PHY mode if necessary. */
1985 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001986 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001987 return ret_val;
1988
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001989 switch (hw->mac_type) {
1990 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001991 /* Kumeran registers are written-only */
1992 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001993 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1994 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1995 reg_data);
1996 if (ret_val)
1997 return ret_val;
1998 break;
1999 default:
2000 break;
2001 }
2002
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002003 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07002004 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002005 hw->phy_type == e1000_phy_igp_2) {
2006 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002007 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002008 return ret_val;
2009 } else if (hw->phy_type == e1000_phy_m88) {
2010 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002011 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002012 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002013 } else if (hw->phy_type == e1000_phy_gg82563) {
2014 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002015 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002016 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002017 }
2018
Auke Kok8fc897b2006-08-28 14:56:16 -07002019 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002020 /* Setup autoneg and flow control advertisement
2021 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002022 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002023 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002024 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002025 } else {
2026 /* PHY will be set to 10H, 10F, 100H,or 100F
2027 * depending on value from forced_speed_duplex. */
2028 DEBUGOUT("Forcing speed and duplex\n");
2029 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002030 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002031 DEBUGOUT("Error Forcing Speed and Duplex\n");
2032 return ret_val;
2033 }
2034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
2036 /* Check link status. Wait up to 100 microseconds for link to become
2037 * valid.
2038 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002039 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002041 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 return ret_val;
2043 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002044 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 return ret_val;
2046
Auke Kok8fc897b2006-08-28 14:56:16 -07002047 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002048 /* Config the MAC and PHY after link is up */
2049 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002050 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002052
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 DEBUGOUT("Valid link established!!!\n");
2054 return E1000_SUCCESS;
2055 }
2056 udelay(10);
2057 }
2058
2059 DEBUGOUT("Unable to establish link!!!\n");
2060 return E1000_SUCCESS;
2061}
2062
2063/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002064* Configure the MAC-to-PHY interface for 10/100Mbps
2065*
2066* hw - Struct containing variables accessed by shared code
2067******************************************************************************/
2068static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002069e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002070{
2071 int32_t ret_val = E1000_SUCCESS;
2072 uint32_t tipg;
2073 uint16_t reg_data;
2074
2075 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2076
2077 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2078 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2079 reg_data);
2080 if (ret_val)
2081 return ret_val;
2082
2083 /* Configure Transmit Inter-Packet Gap */
2084 tipg = E1000_READ_REG(hw, TIPG);
2085 tipg &= ~E1000_TIPG_IPGT_MASK;
2086 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2087 E1000_WRITE_REG(hw, TIPG, tipg);
2088
Auke Kokcd94dd02006-06-27 09:08:22 -07002089 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2090
2091 if (ret_val)
2092 return ret_val;
2093
2094 if (duplex == HALF_DUPLEX)
2095 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2096 else
2097 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2098
2099 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2100
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002101 return ret_val;
2102}
2103
2104static int32_t
2105e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2106{
2107 int32_t ret_val = E1000_SUCCESS;
2108 uint16_t reg_data;
2109 uint32_t tipg;
2110
2111 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2112
2113 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2114 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2115 reg_data);
2116 if (ret_val)
2117 return ret_val;
2118
2119 /* Configure Transmit Inter-Packet Gap */
2120 tipg = E1000_READ_REG(hw, TIPG);
2121 tipg &= ~E1000_TIPG_IPGT_MASK;
2122 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2123 E1000_WRITE_REG(hw, TIPG, tipg);
2124
Auke Kokcd94dd02006-06-27 09:08:22 -07002125 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2126
2127 if (ret_val)
2128 return ret_val;
2129
2130 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2131 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2132
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002133 return ret_val;
2134}
2135
2136/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137* Configures PHY autoneg and flow control advertisement settings
2138*
2139* hw - Struct containing variables accessed by shared code
2140******************************************************************************/
2141int32_t
2142e1000_phy_setup_autoneg(struct e1000_hw *hw)
2143{
2144 int32_t ret_val;
2145 uint16_t mii_autoneg_adv_reg;
2146 uint16_t mii_1000t_ctrl_reg;
2147
2148 DEBUGFUNC("e1000_phy_setup_autoneg");
2149
2150 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2151 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002152 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 return ret_val;
2154
Auke Kokcd94dd02006-06-27 09:08:22 -07002155 if (hw->phy_type != e1000_phy_ife) {
2156 /* Read the MII 1000Base-T Control Register (Address 9). */
2157 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2158 if (ret_val)
2159 return ret_val;
2160 } else
2161 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
2163 /* Need to parse both autoneg_advertised and fc and set up
2164 * the appropriate PHY registers. First we will parse for
2165 * autoneg_advertised software override. Since we can advertise
2166 * a plethora of combinations, we need to check each bit
2167 * individually.
2168 */
2169
2170 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2171 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2172 * the 1000Base-T Control Register (Address 9).
2173 */
2174 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2175 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2176
2177 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2178
2179 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002180 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 DEBUGOUT("Advertise 10mb Half duplex\n");
2182 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2183 }
2184
2185 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002186 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 DEBUGOUT("Advertise 10mb Full duplex\n");
2188 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2189 }
2190
2191 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002192 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 DEBUGOUT("Advertise 100mb Half duplex\n");
2194 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2195 }
2196
2197 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002198 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 DEBUGOUT("Advertise 100mb Full duplex\n");
2200 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2201 }
2202
2203 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002204 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2206 }
2207
2208 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002209 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 DEBUGOUT("Advertise 1000mb Full duplex\n");
2211 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002212 if (hw->phy_type == e1000_phy_ife) {
2213 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 }
2216
2217 /* Check for a software override of the flow control settings, and
2218 * setup the PHY advertisement registers accordingly. If
2219 * auto-negotiation is enabled, then software will have to set the
2220 * "PAUSE" bits to the correct value in the Auto-Negotiation
2221 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2222 *
2223 * The possible values of the "fc" parameter are:
2224 * 0: Flow control is completely disabled
2225 * 1: Rx flow control is enabled (we can receive pause frames
2226 * but not send pause frames).
2227 * 2: Tx flow control is enabled (we can send pause frames
2228 * but we do not support receiving pause frames).
2229 * 3: Both Rx and TX flow control (symmetric) are enabled.
2230 * other: No software override. The flow control configuration
2231 * in the EEPROM is used.
2232 */
2233 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002234 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 /* Flow control (RX & TX) is completely disabled by a
2236 * software over-ride.
2237 */
2238 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2239 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002240 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 /* RX Flow control is enabled, and TX Flow control is
2242 * disabled, by a software over-ride.
2243 */
2244 /* Since there really isn't a way to advertise that we are
2245 * capable of RX Pause ONLY, we will advertise that we
2246 * support both symmetric and asymmetric RX PAUSE. Later
2247 * (in e1000_config_fc_after_link_up) we will disable the
2248 *hw's ability to send PAUSE frames.
2249 */
2250 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2251 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002252 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 /* TX Flow control is enabled, and RX Flow control is
2254 * disabled, by a software over-ride.
2255 */
2256 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2257 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2258 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002259 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 /* Flow control (both RX and TX) is enabled by a software
2261 * over-ride.
2262 */
2263 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2264 break;
2265 default:
2266 DEBUGOUT("Flow control param set incorrectly\n");
2267 return -E1000_ERR_CONFIG;
2268 }
2269
2270 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002271 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 return ret_val;
2273
2274 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2275
Auke Kokcd94dd02006-06-27 09:08:22 -07002276 if (hw->phy_type != e1000_phy_ife) {
2277 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2278 if (ret_val)
2279 return ret_val;
2280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282 return E1000_SUCCESS;
2283}
2284
2285/******************************************************************************
2286* Force PHY speed and duplex settings to hw->forced_speed_duplex
2287*
2288* hw - Struct containing variables accessed by shared code
2289******************************************************************************/
2290static int32_t
2291e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2292{
2293 uint32_t ctrl;
2294 int32_t ret_val;
2295 uint16_t mii_ctrl_reg;
2296 uint16_t mii_status_reg;
2297 uint16_t phy_data;
2298 uint16_t i;
2299
2300 DEBUGFUNC("e1000_phy_force_speed_duplex");
2301
2302 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002303 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2306
2307 /* Read the Device Control Register. */
2308 ctrl = E1000_READ_REG(hw, CTRL);
2309
2310 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2311 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2312 ctrl &= ~(DEVICE_SPEED_MASK);
2313
2314 /* Clear the Auto Speed Detect Enable bit. */
2315 ctrl &= ~E1000_CTRL_ASDE;
2316
2317 /* Read the MII Control Register. */
2318 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002319 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 return ret_val;
2321
2322 /* We need to disable autoneg in order to force link and duplex. */
2323
2324 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2325
2326 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002327 if (hw->forced_speed_duplex == e1000_100_full ||
2328 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 /* We want to force full duplex so we SET the full duplex bits in the
2330 * Device and MII Control Registers.
2331 */
2332 ctrl |= E1000_CTRL_FD;
2333 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2334 DEBUGOUT("Full Duplex\n");
2335 } else {
2336 /* We want to force half duplex so we CLEAR the full duplex bits in
2337 * the Device and MII Control Registers.
2338 */
2339 ctrl &= ~E1000_CTRL_FD;
2340 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2341 DEBUGOUT("Half Duplex\n");
2342 }
2343
2344 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002345 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 hw->forced_speed_duplex == e1000_100_half) {
2347 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2348 ctrl |= E1000_CTRL_SPD_100;
2349 mii_ctrl_reg |= MII_CR_SPEED_100;
2350 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2351 DEBUGOUT("Forcing 100mb ");
2352 } else {
2353 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2354 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2355 mii_ctrl_reg |= MII_CR_SPEED_10;
2356 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2357 DEBUGOUT("Forcing 10mb ");
2358 }
2359
2360 e1000_config_collision_dist(hw);
2361
2362 /* Write the configured values back to the Device Control Reg. */
2363 E1000_WRITE_REG(hw, CTRL, ctrl);
2364
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002365 if ((hw->phy_type == e1000_phy_m88) ||
2366 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002368 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 return ret_val;
2370
2371 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2372 * forced whenever speed are duplex are forced.
2373 */
2374 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2375 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002376 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 return ret_val;
2378
2379 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2380
2381 /* Need to reset the PHY or these changes will be ignored */
2382 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002383
Auke Kokcd94dd02006-06-27 09:08:22 -07002384 /* Disable MDI-X support for 10/100 */
2385 } else if (hw->phy_type == e1000_phy_ife) {
2386 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2387 if (ret_val)
2388 return ret_val;
2389
2390 phy_data &= ~IFE_PMC_AUTO_MDIX;
2391 phy_data &= ~IFE_PMC_FORCE_MDIX;
2392
2393 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2394 if (ret_val)
2395 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 } else {
2398 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2399 * forced whenever speed or duplex are forced.
2400 */
2401 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002402 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return ret_val;
2404
2405 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2406 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2407
2408 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002409 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 return ret_val;
2411 }
2412
2413 /* Write back the modified PHY MII control register. */
2414 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002415 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 return ret_val;
2417
2418 udelay(1);
2419
2420 /* The wait_autoneg_complete flag may be a little misleading here.
2421 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2422 * But we do want to delay for a period while forcing only so we
2423 * don't generate false No Link messages. So we will wait here
2424 * only if the user has set wait_autoneg_complete to 1, which is
2425 * the default.
2426 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002427 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 /* We will wait for autoneg to complete. */
2429 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2430 mii_status_reg = 0;
2431
2432 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002433 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2435 * to be set.
2436 */
2437 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002438 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 return ret_val;
2440
2441 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002442 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 return ret_val;
2444
Auke Kok8fc897b2006-08-28 14:56:16 -07002445 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002446 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002448 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002449 ((hw->phy_type == e1000_phy_m88) ||
2450 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 /* We didn't get link. Reset the DSP and wait again for link. */
2452 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002453 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 DEBUGOUT("Error Resetting PHY DSP\n");
2455 return ret_val;
2456 }
2457 }
2458 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002459 for (i = PHY_FORCE_TIME; i > 0; i--) {
2460 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002461 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2463 * to be set.
2464 */
2465 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002466 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 return ret_val;
2468
2469 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002470 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return ret_val;
2472 }
2473 }
2474
2475 if (hw->phy_type == e1000_phy_m88) {
2476 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2477 * Extended PHY Specific Control Register to 25MHz clock. This value
2478 * defaults back to a 2.5MHz clock when the PHY is reset.
2479 */
2480 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002481 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 return ret_val;
2483
2484 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2485 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002486 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 return ret_val;
2488
2489 /* In addition, because of the s/w reset above, we need to enable CRS on
2490 * TX. This must be set for both full and half duplex operation.
2491 */
2492 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002493 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 return ret_val;
2495
2496 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2497 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002498 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 return ret_val;
2500
Auke Kok8fc897b2006-08-28 14:56:16 -07002501 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2502 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2503 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002505 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 return ret_val;
2507 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002508 } else if (hw->phy_type == e1000_phy_gg82563) {
2509 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2510 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2511 * we're not in a forced 10/duplex configuration. */
2512 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2513 if (ret_val)
2514 return ret_val;
2515
2516 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2517 if ((hw->forced_speed_duplex == e1000_10_full) ||
2518 (hw->forced_speed_duplex == e1000_10_half))
2519 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2520 else
2521 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2522
2523 /* Also due to the reset, we need to enable CRS on Tx. */
2524 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2525
2526 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2527 if (ret_val)
2528 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 }
2530 return E1000_SUCCESS;
2531}
2532
2533/******************************************************************************
2534* Sets the collision distance in the Transmit Control register
2535*
2536* hw - Struct containing variables accessed by shared code
2537*
2538* Link should have been established previously. Reads the speed and duplex
2539* information from the Device Status register.
2540******************************************************************************/
2541void
2542e1000_config_collision_dist(struct e1000_hw *hw)
2543{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002544 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
2546 DEBUGFUNC("e1000_config_collision_dist");
2547
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002548 if (hw->mac_type < e1000_82543)
2549 coll_dist = E1000_COLLISION_DISTANCE_82542;
2550 else
2551 coll_dist = E1000_COLLISION_DISTANCE;
2552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 tctl = E1000_READ_REG(hw, TCTL);
2554
2555 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002556 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
2558 E1000_WRITE_REG(hw, TCTL, tctl);
2559 E1000_WRITE_FLUSH(hw);
2560}
2561
2562/******************************************************************************
2563* Sets MAC speed and duplex settings to reflect the those in the PHY
2564*
2565* hw - Struct containing variables accessed by shared code
2566* mii_reg - data to write to the MII control register
2567*
2568* The contents of the PHY register containing the needed information need to
2569* be passed in.
2570******************************************************************************/
2571static int32_t
2572e1000_config_mac_to_phy(struct e1000_hw *hw)
2573{
2574 uint32_t ctrl;
2575 int32_t ret_val;
2576 uint16_t phy_data;
2577
2578 DEBUGFUNC("e1000_config_mac_to_phy");
2579
Auke Kok76c224b2006-05-23 13:36:06 -07002580 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002581 * MAC speed/duplex configuration.*/
2582 if (hw->mac_type >= e1000_82544)
2583 return E1000_SUCCESS;
2584
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 /* Read the Device Control Register and set the bits to Force Speed
2586 * and Duplex.
2587 */
2588 ctrl = E1000_READ_REG(hw, CTRL);
2589 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2590 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2591
2592 /* Set up duplex in the Device Control and Transmit Control
2593 * registers depending on negotiated values.
2594 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002595 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002596 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002597 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
Auke Kok8fc897b2006-08-28 14:56:16 -07002599 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002600 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002601 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002602 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002604 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002606 /* Set up speed in the Device Control register depending on
2607 * negotiated values.
2608 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002609 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002610 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002611 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002612 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 /* Write the configured values back to the Device Control Reg. */
2615 E1000_WRITE_REG(hw, CTRL, ctrl);
2616 return E1000_SUCCESS;
2617}
2618
2619/******************************************************************************
2620 * Forces the MAC's flow control settings.
2621 *
2622 * hw - Struct containing variables accessed by shared code
2623 *
2624 * Sets the TFCE and RFCE bits in the device control register to reflect
2625 * the adapter settings. TFCE and RFCE need to be explicitly set by
2626 * software when a Copper PHY is used because autonegotiation is managed
2627 * by the PHY rather than the MAC. Software must also configure these
2628 * bits when link is forced on a fiber connection.
2629 *****************************************************************************/
2630int32_t
2631e1000_force_mac_fc(struct e1000_hw *hw)
2632{
2633 uint32_t ctrl;
2634
2635 DEBUGFUNC("e1000_force_mac_fc");
2636
2637 /* Get the current configuration of the Device Control Register */
2638 ctrl = E1000_READ_REG(hw, CTRL);
2639
2640 /* Because we didn't get link via the internal auto-negotiation
2641 * mechanism (we either forced link or we got link via PHY
2642 * auto-neg), we have to manually enable/disable transmit an
2643 * receive flow control.
2644 *
2645 * The "Case" statement below enables/disable flow control
2646 * according to the "hw->fc" parameter.
2647 *
2648 * The possible values of the "fc" parameter are:
2649 * 0: Flow control is completely disabled
2650 * 1: Rx flow control is enabled (we can receive pause
2651 * frames but not send pause frames).
2652 * 2: Tx flow control is enabled (we can send pause frames
2653 * frames but we do not receive pause frames).
2654 * 3: Both Rx and TX flow control (symmetric) is enabled.
2655 * other: No other values should be possible at this point.
2656 */
2657
2658 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002659 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2661 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002662 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 ctrl &= (~E1000_CTRL_TFCE);
2664 ctrl |= E1000_CTRL_RFCE;
2665 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002666 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 ctrl &= (~E1000_CTRL_RFCE);
2668 ctrl |= E1000_CTRL_TFCE;
2669 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002670 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2672 break;
2673 default:
2674 DEBUGOUT("Flow control param set incorrectly\n");
2675 return -E1000_ERR_CONFIG;
2676 }
2677
2678 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002679 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 ctrl &= (~E1000_CTRL_TFCE);
2681
2682 E1000_WRITE_REG(hw, CTRL, ctrl);
2683 return E1000_SUCCESS;
2684}
2685
2686/******************************************************************************
2687 * Configures flow control settings after link is established
2688 *
2689 * hw - Struct containing variables accessed by shared code
2690 *
2691 * Should be called immediately after a valid link has been established.
2692 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2693 * and autonegotiation is enabled, the MAC flow control settings will be set
2694 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2695 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2696 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002697static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698e1000_config_fc_after_link_up(struct e1000_hw *hw)
2699{
2700 int32_t ret_val;
2701 uint16_t mii_status_reg;
2702 uint16_t mii_nway_adv_reg;
2703 uint16_t mii_nway_lp_ability_reg;
2704 uint16_t speed;
2705 uint16_t duplex;
2706
2707 DEBUGFUNC("e1000_config_fc_after_link_up");
2708
2709 /* Check for the case where we have fiber media and auto-neg failed
2710 * so we had to force link. In this case, we need to force the
2711 * configuration of the MAC to match the "fc" parameter.
2712 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002713 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2714 ((hw->media_type == e1000_media_type_internal_serdes) &&
2715 (hw->autoneg_failed)) ||
2716 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002718 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 DEBUGOUT("Error forcing flow control settings\n");
2720 return ret_val;
2721 }
2722 }
2723
2724 /* Check for the case where we have copper media and auto-neg is
2725 * enabled. In this case, we need to check and see if Auto-Neg
2726 * has completed, and if so, how the PHY and link partner has
2727 * flow control configured.
2728 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002729 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 /* Read the MII Status Register and check to see if AutoNeg
2731 * has completed. We read this twice because this reg has
2732 * some "sticky" (latched) bits.
2733 */
2734 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002735 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 return ret_val;
2737 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002738 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 return ret_val;
2740
Auke Kok8fc897b2006-08-28 14:56:16 -07002741 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 /* The AutoNeg process has completed, so we now need to
2743 * read both the Auto Negotiation Advertisement Register
2744 * (Address 4) and the Auto_Negotiation Base Page Ability
2745 * Register (Address 5) to determine how flow control was
2746 * negotiated.
2747 */
2748 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2749 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002750 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 return ret_val;
2752 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2753 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002754 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 return ret_val;
2756
2757 /* Two bits in the Auto Negotiation Advertisement Register
2758 * (Address 4) and two bits in the Auto Negotiation Base
2759 * Page Ability Register (Address 5) determine flow control
2760 * for both the PHY and the link partner. The following
2761 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2762 * 1999, describes these PAUSE resolution bits and how flow
2763 * control is determined based upon these settings.
2764 * NOTE: DC = Don't Care
2765 *
2766 * LOCAL DEVICE | LINK PARTNER
2767 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2768 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002769 * 0 | 0 | DC | DC | E1000_FC_NONE
2770 * 0 | 1 | 0 | DC | E1000_FC_NONE
2771 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2772 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2773 * 1 | 0 | 0 | DC | E1000_FC_NONE
2774 * 1 | DC | 1 | DC | E1000_FC_FULL
2775 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2776 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 *
2778 */
2779 /* Are both PAUSE bits set to 1? If so, this implies
2780 * Symmetric Flow Control is enabled at both ends. The
2781 * ASM_DIR bits are irrelevant per the spec.
2782 *
2783 * For Symmetric Flow Control:
2784 *
2785 * LOCAL DEVICE | LINK PARTNER
2786 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2787 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002788 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 *
2790 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002791 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2792 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 /* Now we need to check if the user selected RX ONLY
2794 * of pause frames. In this case, we had to advertise
2795 * FULL flow control because we could not advertise RX
2796 * ONLY. Hence, we must now check to see if we need to
2797 * turn OFF the TRANSMISSION of PAUSE frames.
2798 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002799 if (hw->original_fc == E1000_FC_FULL) {
2800 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002801 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002803 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002804 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 }
2806 }
2807 /* For receiving PAUSE frames ONLY.
2808 *
2809 * LOCAL DEVICE | LINK PARTNER
2810 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2811 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002812 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 *
2814 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002815 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2816 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2817 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2818 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002819 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002820 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 }
2822 /* For transmitting PAUSE frames ONLY.
2823 *
2824 * LOCAL DEVICE | LINK PARTNER
2825 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2826 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002827 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 *
2829 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002830 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2831 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2832 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2833 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002834 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002835 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 }
2837 /* Per the IEEE spec, at this point flow control should be
2838 * disabled. However, we want to consider that we could
2839 * be connected to a legacy switch that doesn't advertise
2840 * desired flow control, but can be forced on the link
2841 * partner. So if we advertised no flow control, that is
2842 * what we will resolve to. If we advertised some kind of
2843 * receive capability (Rx Pause Only or Full Flow Control)
2844 * and the link partner advertised none, we will configure
2845 * ourselves to enable Rx Flow Control only. We can do
2846 * this safely for two reasons: If the link partner really
2847 * didn't want flow control enabled, and we enable Rx, no
2848 * harm done since we won't be receiving any PAUSE frames
2849 * anyway. If the intent on the link partner was to have
2850 * flow control enabled, then by us enabling RX only, we
2851 * can at least receive pause frames and process them.
2852 * This is a good idea because in most cases, since we are
2853 * predominantly a server NIC, more times than not we will
2854 * be asked to delay transmission of packets than asking
2855 * our link partner to pause transmission of frames.
2856 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002857 else if ((hw->original_fc == E1000_FC_NONE ||
2858 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002859 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002860 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002861 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002863 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002864 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 }
2866
2867 /* Now we need to do one last check... If we auto-
2868 * negotiated to HALF DUPLEX, flow control should not be
2869 * enabled per IEEE 802.3 spec.
2870 */
2871 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002872 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 DEBUGOUT("Error getting link speed and duplex\n");
2874 return ret_val;
2875 }
2876
Auke Kok8fc897b2006-08-28 14:56:16 -07002877 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002878 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
2880 /* Now we call a subroutine to actually force the MAC
2881 * controller to use the correct flow control settings.
2882 */
2883 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002884 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 DEBUGOUT("Error forcing flow control settings\n");
2886 return ret_val;
2887 }
2888 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002889 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 }
2891 }
2892 return E1000_SUCCESS;
2893}
2894
2895/******************************************************************************
2896 * Checks to see if the link status of the hardware has changed.
2897 *
2898 * hw - Struct containing variables accessed by shared code
2899 *
2900 * Called by any function that needs to check the link status of the adapter.
2901 *****************************************************************************/
2902int32_t
2903e1000_check_for_link(struct e1000_hw *hw)
2904{
2905 uint32_t rxcw = 0;
2906 uint32_t ctrl;
2907 uint32_t status;
2908 uint32_t rctl;
2909 uint32_t icr;
2910 uint32_t signal = 0;
2911 int32_t ret_val;
2912 uint16_t phy_data;
2913
2914 DEBUGFUNC("e1000_check_for_link");
2915
2916 ctrl = E1000_READ_REG(hw, CTRL);
2917 status = E1000_READ_REG(hw, STATUS);
2918
2919 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2920 * set when the optics detect a signal. On older adapters, it will be
2921 * cleared when there is a signal. This applies to fiber media only.
2922 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002923 if ((hw->media_type == e1000_media_type_fiber) ||
2924 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 rxcw = E1000_READ_REG(hw, RXCW);
2926
Auke Kok8fc897b2006-08-28 14:56:16 -07002927 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002929 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 hw->get_link_status = FALSE;
2931 }
2932 }
2933
2934 /* If we have a copper PHY then we only want to go out to the PHY
2935 * registers to see if Auto-Neg has completed and/or if our link
2936 * status has changed. The get_link_status flag will be set if we
2937 * receive a Link Status Change interrupt or we have Rx Sequence
2938 * Errors.
2939 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002940 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 /* First we want to see if the MII Status Register reports
2942 * link. If so, then we want to get the current speed/duplex
2943 * of the PHY.
2944 * Read the register twice since the link bit is sticky.
2945 */
2946 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002947 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 return ret_val;
2949 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002950 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 return ret_val;
2952
Auke Kok8fc897b2006-08-28 14:56:16 -07002953 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 hw->get_link_status = FALSE;
2955 /* Check if there was DownShift, must be checked immediately after
2956 * link-up */
2957 e1000_check_downshift(hw);
2958
2959 /* If we are on 82544 or 82543 silicon and speed/duplex
2960 * are forced to 10H or 10F, then we will implement the polarity
2961 * reversal workaround. We disable interrupts first, and upon
2962 * returning, place the devices interrupt state to its previous
2963 * value except for the link status change interrupt which will
2964 * happen due to the execution of this workaround.
2965 */
2966
Auke Kok8fc897b2006-08-28 14:56:16 -07002967 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2968 (!hw->autoneg) &&
2969 (hw->forced_speed_duplex == e1000_10_full ||
2970 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2972 ret_val = e1000_polarity_reversal_workaround(hw);
2973 icr = E1000_READ_REG(hw, ICR);
2974 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2975 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2976 }
2977
2978 } else {
2979 /* No link detected */
2980 e1000_config_dsp_after_link_change(hw, FALSE);
2981 return 0;
2982 }
2983
2984 /* If we are forcing speed/duplex, then we simply return since
2985 * we have already determined whether we have link or not.
2986 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002987 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
2989 /* optimize the dsp settings for the igp phy */
2990 e1000_config_dsp_after_link_change(hw, TRUE);
2991
2992 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2993 * have Si on board that is 82544 or newer, Auto
2994 * Speed Detection takes care of MAC speed/duplex
2995 * configuration. So we only need to configure Collision
2996 * Distance in the MAC. Otherwise, we need to force
2997 * speed/duplex on the MAC to the current PHY speed/duplex
2998 * settings.
2999 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003000 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 e1000_config_collision_dist(hw);
3002 else {
3003 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003004 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 DEBUGOUT("Error configuring MAC to PHY settings\n");
3006 return ret_val;
3007 }
3008 }
3009
3010 /* Configure Flow Control now that Auto-Neg has completed. First, we
3011 * need to restore the desired flow control settings because we may
3012 * have had to re-autoneg with a different link partner.
3013 */
3014 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003015 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 DEBUGOUT("Error configuring flow control\n");
3017 return ret_val;
3018 }
3019
3020 /* At this point we know that we are on copper and we have
3021 * auto-negotiated link. These are conditions for checking the link
3022 * partner capability register. We use the link speed to determine if
3023 * TBI compatibility needs to be turned on or off. If the link is not
3024 * at gigabit speed, then TBI compatibility is not needed. If we are
3025 * at gigabit speed, we turn on TBI compatibility.
3026 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003027 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003029 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3030 if (ret_val) {
3031 DEBUGOUT("Error getting link speed and duplex\n");
3032 return ret_val;
3033 }
3034 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 /* If link speed is not set to gigabit speed, we do not need
3036 * to enable TBI compatibility.
3037 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003038 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 /* If we previously were in the mode, turn it off. */
3040 rctl = E1000_READ_REG(hw, RCTL);
3041 rctl &= ~E1000_RCTL_SBP;
3042 E1000_WRITE_REG(hw, RCTL, rctl);
3043 hw->tbi_compatibility_on = FALSE;
3044 }
3045 } else {
3046 /* If TBI compatibility is was previously off, turn it on. For
3047 * compatibility with a TBI link partner, we will store bad
3048 * packets. Some frames have an additional byte on the end and
3049 * will look like CRC errors to to the hardware.
3050 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003051 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 hw->tbi_compatibility_on = TRUE;
3053 rctl = E1000_READ_REG(hw, RCTL);
3054 rctl |= E1000_RCTL_SBP;
3055 E1000_WRITE_REG(hw, RCTL, rctl);
3056 }
3057 }
3058 }
3059 }
3060 /* If we don't have link (auto-negotiation failed or link partner cannot
3061 * auto-negotiate), the cable is plugged in (we have signal), and our
3062 * link partner is not trying to auto-negotiate with us (we are receiving
3063 * idles or data), we need to force link up. We also need to give
3064 * auto-negotiation time to complete, in case the cable was just plugged
3065 * in. The autoneg_failed flag does this.
3066 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003067 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003069 (hw->media_type == e1000_media_type_internal_serdes)) &&
3070 (!(status & E1000_STATUS_LU)) &&
3071 (!(rxcw & E1000_RXCW_C))) {
3072 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 hw->autoneg_failed = 1;
3074 return 0;
3075 }
Auke Koka42a5072006-05-23 13:36:01 -07003076 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
3078 /* Disable auto-negotiation in the TXCW register */
3079 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3080
3081 /* Force link-up and also force full-duplex. */
3082 ctrl = E1000_READ_REG(hw, CTRL);
3083 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3084 E1000_WRITE_REG(hw, CTRL, ctrl);
3085
3086 /* Configure Flow Control after forcing link up. */
3087 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003088 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 DEBUGOUT("Error configuring flow control\n");
3090 return ret_val;
3091 }
3092 }
3093 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3094 * auto-negotiation in the TXCW register and disable forced link in the
3095 * Device Control register in an attempt to auto-negotiate with our link
3096 * partner.
3097 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003098 else if (((hw->media_type == e1000_media_type_fiber) ||
3099 (hw->media_type == e1000_media_type_internal_serdes)) &&
3100 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003101 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3103 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3104
3105 hw->serdes_link_down = FALSE;
3106 }
3107 /* If we force link for non-auto-negotiation switch, check link status
3108 * based on MAC synchronization for internal serdes media type.
3109 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003110 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3111 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 /* SYNCH bit and IV bit are sticky. */
3113 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003114 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3115 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 hw->serdes_link_down = FALSE;
3117 DEBUGOUT("SERDES: Link is up.\n");
3118 }
3119 } else {
3120 hw->serdes_link_down = TRUE;
3121 DEBUGOUT("SERDES: Link is down.\n");
3122 }
3123 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003124 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3125 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3127 }
3128 return E1000_SUCCESS;
3129}
3130
3131/******************************************************************************
3132 * Detects the current speed and duplex settings of the hardware.
3133 *
3134 * hw - Struct containing variables accessed by shared code
3135 * speed - Speed of the connection
3136 * duplex - Duplex setting of the connection
3137 *****************************************************************************/
3138int32_t
3139e1000_get_speed_and_duplex(struct e1000_hw *hw,
3140 uint16_t *speed,
3141 uint16_t *duplex)
3142{
3143 uint32_t status;
3144 int32_t ret_val;
3145 uint16_t phy_data;
3146
3147 DEBUGFUNC("e1000_get_speed_and_duplex");
3148
Auke Kok8fc897b2006-08-28 14:56:16 -07003149 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003151 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 *speed = SPEED_1000;
3153 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003154 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 *speed = SPEED_100;
3156 DEBUGOUT("100 Mbs, ");
3157 } else {
3158 *speed = SPEED_10;
3159 DEBUGOUT("10 Mbs, ");
3160 }
3161
Auke Kok8fc897b2006-08-28 14:56:16 -07003162 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003164 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 } else {
3166 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003167 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 }
3169 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003170 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 *speed = SPEED_1000;
3172 *duplex = FULL_DUPLEX;
3173 }
3174
3175 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3176 * if it is operating at half duplex. Here we set the duplex settings to
3177 * match the duplex in the link partner's capabilities.
3178 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003179 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003181 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 return ret_val;
3183
Auke Kok8fc897b2006-08-28 14:56:16 -07003184 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 *duplex = HALF_DUPLEX;
3186 else {
3187 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003188 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003190 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3192 *duplex = HALF_DUPLEX;
3193 }
3194 }
3195
Auke Kok76c224b2006-05-23 13:36:06 -07003196 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003197 (hw->media_type == e1000_media_type_copper)) {
3198 if (*speed == SPEED_1000)
3199 ret_val = e1000_configure_kmrn_for_1000(hw);
3200 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003201 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3202 if (ret_val)
3203 return ret_val;
3204 }
3205
3206 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3207 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003208 if (ret_val)
3209 return ret_val;
3210 }
3211
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 return E1000_SUCCESS;
3213}
3214
3215/******************************************************************************
3216* Blocks until autoneg completes or times out (~4.5 seconds)
3217*
3218* hw - Struct containing variables accessed by shared code
3219******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003220static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221e1000_wait_autoneg(struct e1000_hw *hw)
3222{
3223 int32_t ret_val;
3224 uint16_t i;
3225 uint16_t phy_data;
3226
3227 DEBUGFUNC("e1000_wait_autoneg");
3228 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3229
3230 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003231 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 /* Read the MII Status Register and wait for Auto-Neg
3233 * Complete bit to be set.
3234 */
3235 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003236 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 return ret_val;
3238 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003239 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003241 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 return E1000_SUCCESS;
3243 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003244 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 }
3246 return E1000_SUCCESS;
3247}
3248
3249/******************************************************************************
3250* Raises the Management Data Clock
3251*
3252* hw - Struct containing variables accessed by shared code
3253* ctrl - Device control register's current value
3254******************************************************************************/
3255static void
3256e1000_raise_mdi_clk(struct e1000_hw *hw,
3257 uint32_t *ctrl)
3258{
3259 /* Raise the clock input to the Management Data Clock (by setting the MDC
3260 * bit), and then delay 10 microseconds.
3261 */
3262 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3263 E1000_WRITE_FLUSH(hw);
3264 udelay(10);
3265}
3266
3267/******************************************************************************
3268* Lowers the Management Data Clock
3269*
3270* hw - Struct containing variables accessed by shared code
3271* ctrl - Device control register's current value
3272******************************************************************************/
3273static void
3274e1000_lower_mdi_clk(struct e1000_hw *hw,
3275 uint32_t *ctrl)
3276{
3277 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3278 * bit), and then delay 10 microseconds.
3279 */
3280 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3281 E1000_WRITE_FLUSH(hw);
3282 udelay(10);
3283}
3284
3285/******************************************************************************
3286* Shifts data bits out to the PHY
3287*
3288* hw - Struct containing variables accessed by shared code
3289* data - Data to send out to the PHY
3290* count - Number of bits to shift out
3291*
3292* Bits are shifted out in MSB to LSB order.
3293******************************************************************************/
3294static void
3295e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3296 uint32_t data,
3297 uint16_t count)
3298{
3299 uint32_t ctrl;
3300 uint32_t mask;
3301
3302 /* We need to shift "count" number of bits out to the PHY. So, the value
3303 * in the "data" parameter will be shifted out to the PHY one bit at a
3304 * time. In order to do this, "data" must be broken down into bits.
3305 */
3306 mask = 0x01;
3307 mask <<= (count - 1);
3308
3309 ctrl = E1000_READ_REG(hw, CTRL);
3310
3311 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3312 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3313
Auke Kok8fc897b2006-08-28 14:56:16 -07003314 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3316 * then raising and lowering the Management Data Clock. A "0" is
3317 * shifted out to the PHY by setting the MDIO bit to "0" and then
3318 * raising and lowering the clock.
3319 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003320 if (data & mask)
3321 ctrl |= E1000_CTRL_MDIO;
3322 else
3323 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
3325 E1000_WRITE_REG(hw, CTRL, ctrl);
3326 E1000_WRITE_FLUSH(hw);
3327
3328 udelay(10);
3329
3330 e1000_raise_mdi_clk(hw, &ctrl);
3331 e1000_lower_mdi_clk(hw, &ctrl);
3332
3333 mask = mask >> 1;
3334 }
3335}
3336
3337/******************************************************************************
3338* Shifts data bits in from the PHY
3339*
3340* hw - Struct containing variables accessed by shared code
3341*
3342* Bits are shifted in in MSB to LSB order.
3343******************************************************************************/
3344static uint16_t
3345e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3346{
3347 uint32_t ctrl;
3348 uint16_t data = 0;
3349 uint8_t i;
3350
3351 /* In order to read a register from the PHY, we need to shift in a total
3352 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3353 * to avoid contention on the MDIO pin when a read operation is performed.
3354 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3355 * by raising the input to the Management Data Clock (setting the MDC bit),
3356 * and then reading the value of the MDIO bit.
3357 */
3358 ctrl = E1000_READ_REG(hw, CTRL);
3359
3360 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3361 ctrl &= ~E1000_CTRL_MDIO_DIR;
3362 ctrl &= ~E1000_CTRL_MDIO;
3363
3364 E1000_WRITE_REG(hw, CTRL, ctrl);
3365 E1000_WRITE_FLUSH(hw);
3366
3367 /* Raise and Lower the clock before reading in the data. This accounts for
3368 * the turnaround bits. The first clock occurred when we clocked out the
3369 * last bit of the Register Address.
3370 */
3371 e1000_raise_mdi_clk(hw, &ctrl);
3372 e1000_lower_mdi_clk(hw, &ctrl);
3373
Auke Kok8fc897b2006-08-28 14:56:16 -07003374 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 data = data << 1;
3376 e1000_raise_mdi_clk(hw, &ctrl);
3377 ctrl = E1000_READ_REG(hw, CTRL);
3378 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003379 if (ctrl & E1000_CTRL_MDIO)
3380 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 e1000_lower_mdi_clk(hw, &ctrl);
3382 }
3383
3384 e1000_raise_mdi_clk(hw, &ctrl);
3385 e1000_lower_mdi_clk(hw, &ctrl);
3386
3387 return data;
3388}
3389
Adrian Bunke4c780b2006-08-14 23:00:10 -07003390static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003391e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3392{
3393 uint32_t swfw_sync = 0;
3394 uint32_t swmask = mask;
3395 uint32_t fwmask = mask << 16;
3396 int32_t timeout = 200;
3397
3398 DEBUGFUNC("e1000_swfw_sync_acquire");
3399
Auke Kokcd94dd02006-06-27 09:08:22 -07003400 if (hw->swfwhw_semaphore_present)
3401 return e1000_get_software_flag(hw);
3402
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003403 if (!hw->swfw_sync_present)
3404 return e1000_get_hw_eeprom_semaphore(hw);
3405
Auke Kok8fc897b2006-08-28 14:56:16 -07003406 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003407 if (e1000_get_hw_eeprom_semaphore(hw))
3408 return -E1000_ERR_SWFW_SYNC;
3409
3410 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3411 if (!(swfw_sync & (fwmask | swmask))) {
3412 break;
3413 }
3414
3415 /* firmware currently using resource (fwmask) */
3416 /* or other software thread currently using resource (swmask) */
3417 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003418 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003419 timeout--;
3420 }
3421
3422 if (!timeout) {
3423 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3424 return -E1000_ERR_SWFW_SYNC;
3425 }
3426
3427 swfw_sync |= swmask;
3428 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3429
3430 e1000_put_hw_eeprom_semaphore(hw);
3431 return E1000_SUCCESS;
3432}
3433
Adrian Bunke4c780b2006-08-14 23:00:10 -07003434static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003435e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3436{
3437 uint32_t swfw_sync;
3438 uint32_t swmask = mask;
3439
3440 DEBUGFUNC("e1000_swfw_sync_release");
3441
Auke Kokcd94dd02006-06-27 09:08:22 -07003442 if (hw->swfwhw_semaphore_present) {
3443 e1000_release_software_flag(hw);
3444 return;
3445 }
3446
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003447 if (!hw->swfw_sync_present) {
3448 e1000_put_hw_eeprom_semaphore(hw);
3449 return;
3450 }
3451
3452 /* if (e1000_get_hw_eeprom_semaphore(hw))
3453 * return -E1000_ERR_SWFW_SYNC; */
3454 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3455 /* empty */
3456
3457 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3458 swfw_sync &= ~swmask;
3459 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3460
3461 e1000_put_hw_eeprom_semaphore(hw);
3462}
3463
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464/*****************************************************************************
3465* Reads the value from a PHY register, if the value is on a specific non zero
3466* page, sets the page first.
3467* hw - Struct containing variables accessed by shared code
3468* reg_addr - address of the PHY register to read
3469******************************************************************************/
3470int32_t
3471e1000_read_phy_reg(struct e1000_hw *hw,
3472 uint32_t reg_addr,
3473 uint16_t *phy_data)
3474{
3475 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003476 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
3478 DEBUGFUNC("e1000_read_phy_reg");
3479
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003480 if ((hw->mac_type == e1000_80003es2lan) &&
3481 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3482 swfw = E1000_SWFW_PHY1_SM;
3483 } else {
3484 swfw = E1000_SWFW_PHY0_SM;
3485 }
3486 if (e1000_swfw_sync_acquire(hw, swfw))
3487 return -E1000_ERR_SWFW_SYNC;
3488
Auke Kokcd94dd02006-06-27 09:08:22 -07003489 if ((hw->phy_type == e1000_phy_igp ||
3490 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003491 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3493 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3494 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003495 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003496 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 return ret_val;
3498 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003499 } else if (hw->phy_type == e1000_phy_gg82563) {
3500 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3501 (hw->mac_type == e1000_80003es2lan)) {
3502 /* Select Configuration Page */
3503 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3504 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3505 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3506 } else {
3507 /* Use Alternative Page Select register to access
3508 * registers 30 and 31
3509 */
3510 ret_val = e1000_write_phy_reg_ex(hw,
3511 GG82563_PHY_PAGE_SELECT_ALT,
3512 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3513 }
3514
3515 if (ret_val) {
3516 e1000_swfw_sync_release(hw, swfw);
3517 return ret_val;
3518 }
3519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 }
3521
3522 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3523 phy_data);
3524
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003525 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 return ret_val;
3527}
3528
Nicholas Nunley35574762006-09-27 12:53:34 -07003529static int32_t
3530e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 uint16_t *phy_data)
3532{
3533 uint32_t i;
3534 uint32_t mdic = 0;
3535 const uint32_t phy_addr = 1;
3536
3537 DEBUGFUNC("e1000_read_phy_reg_ex");
3538
Auke Kok8fc897b2006-08-28 14:56:16 -07003539 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3541 return -E1000_ERR_PARAM;
3542 }
3543
Auke Kok8fc897b2006-08-28 14:56:16 -07003544 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 /* Set up Op-code, Phy Address, and register address in the MDI
3546 * Control register. The MAC will take care of interfacing with the
3547 * PHY to retrieve the desired data.
3548 */
3549 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3550 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3551 (E1000_MDIC_OP_READ));
3552
3553 E1000_WRITE_REG(hw, MDIC, mdic);
3554
3555 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003556 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 udelay(50);
3558 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003559 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003561 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 DEBUGOUT("MDI Read did not complete\n");
3563 return -E1000_ERR_PHY;
3564 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003565 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 DEBUGOUT("MDI Error\n");
3567 return -E1000_ERR_PHY;
3568 }
3569 *phy_data = (uint16_t) mdic;
3570 } else {
3571 /* We must first send a preamble through the MDIO pin to signal the
3572 * beginning of an MII instruction. This is done by sending 32
3573 * consecutive "1" bits.
3574 */
3575 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3576
3577 /* Now combine the next few fields that are required for a read
3578 * operation. We use this method instead of calling the
3579 * e1000_shift_out_mdi_bits routine five different times. The format of
3580 * a MII read instruction consists of a shift out of 14 bits and is
3581 * defined as follows:
3582 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3583 * followed by a shift in of 18 bits. This first two bits shifted in
3584 * are TurnAround bits used to avoid contention on the MDIO pin when a
3585 * READ operation is performed. These two bits are thrown away
3586 * followed by a shift in of 16 bits which contains the desired data.
3587 */
3588 mdic = ((reg_addr) | (phy_addr << 5) |
3589 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3590
3591 e1000_shift_out_mdi_bits(hw, mdic, 14);
3592
3593 /* Now that we've shifted out the read command to the MII, we need to
3594 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3595 * register address.
3596 */
3597 *phy_data = e1000_shift_in_mdi_bits(hw);
3598 }
3599 return E1000_SUCCESS;
3600}
3601
3602/******************************************************************************
3603* Writes a value to a PHY register
3604*
3605* hw - Struct containing variables accessed by shared code
3606* reg_addr - address of the PHY register to write
3607* data - data to write to the PHY
3608******************************************************************************/
3609int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003610e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 uint16_t phy_data)
3612{
3613 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003614 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
3616 DEBUGFUNC("e1000_write_phy_reg");
3617
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003618 if ((hw->mac_type == e1000_80003es2lan) &&
3619 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3620 swfw = E1000_SWFW_PHY1_SM;
3621 } else {
3622 swfw = E1000_SWFW_PHY0_SM;
3623 }
3624 if (e1000_swfw_sync_acquire(hw, swfw))
3625 return -E1000_ERR_SWFW_SYNC;
3626
Auke Kokcd94dd02006-06-27 09:08:22 -07003627 if ((hw->phy_type == e1000_phy_igp ||
3628 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003629 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3631 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3632 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003633 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003634 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 return ret_val;
3636 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003637 } else if (hw->phy_type == e1000_phy_gg82563) {
3638 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3639 (hw->mac_type == e1000_80003es2lan)) {
3640 /* Select Configuration Page */
3641 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3642 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3643 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3644 } else {
3645 /* Use Alternative Page Select register to access
3646 * registers 30 and 31
3647 */
3648 ret_val = e1000_write_phy_reg_ex(hw,
3649 GG82563_PHY_PAGE_SELECT_ALT,
3650 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3651 }
3652
3653 if (ret_val) {
3654 e1000_swfw_sync_release(hw, swfw);
3655 return ret_val;
3656 }
3657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 }
3659
3660 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3661 phy_data);
3662
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003663 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 return ret_val;
3665}
3666
Nicholas Nunley35574762006-09-27 12:53:34 -07003667static int32_t
3668e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3669 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670{
3671 uint32_t i;
3672 uint32_t mdic = 0;
3673 const uint32_t phy_addr = 1;
3674
3675 DEBUGFUNC("e1000_write_phy_reg_ex");
3676
Auke Kok8fc897b2006-08-28 14:56:16 -07003677 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3679 return -E1000_ERR_PARAM;
3680 }
3681
Auke Kok8fc897b2006-08-28 14:56:16 -07003682 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 /* Set up Op-code, Phy Address, register address, and data intended
3684 * for the PHY register in the MDI Control register. The MAC will take
3685 * care of interfacing with the PHY to send the desired data.
3686 */
3687 mdic = (((uint32_t) phy_data) |
3688 (reg_addr << E1000_MDIC_REG_SHIFT) |
3689 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3690 (E1000_MDIC_OP_WRITE));
3691
3692 E1000_WRITE_REG(hw, MDIC, mdic);
3693
3694 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003695 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 udelay(5);
3697 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003698 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003700 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 DEBUGOUT("MDI Write did not complete\n");
3702 return -E1000_ERR_PHY;
3703 }
3704 } else {
3705 /* We'll need to use the SW defined pins to shift the write command
3706 * out to the PHY. We first send a preamble to the PHY to signal the
3707 * beginning of the MII instruction. This is done by sending 32
3708 * consecutive "1" bits.
3709 */
3710 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3711
3712 /* Now combine the remaining required fields that will indicate a
3713 * write operation. We use this method instead of calling the
3714 * e1000_shift_out_mdi_bits routine for each field in the command. The
3715 * format of a MII write instruction is as follows:
3716 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3717 */
3718 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3719 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3720 mdic <<= 16;
3721 mdic |= (uint32_t) phy_data;
3722
3723 e1000_shift_out_mdi_bits(hw, mdic, 32);
3724 }
3725
3726 return E1000_SUCCESS;
3727}
3728
Adrian Bunke4c780b2006-08-14 23:00:10 -07003729static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003730e1000_read_kmrn_reg(struct e1000_hw *hw,
3731 uint32_t reg_addr,
3732 uint16_t *data)
3733{
3734 uint32_t reg_val;
3735 uint16_t swfw;
3736 DEBUGFUNC("e1000_read_kmrn_reg");
3737
3738 if ((hw->mac_type == e1000_80003es2lan) &&
3739 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3740 swfw = E1000_SWFW_PHY1_SM;
3741 } else {
3742 swfw = E1000_SWFW_PHY0_SM;
3743 }
3744 if (e1000_swfw_sync_acquire(hw, swfw))
3745 return -E1000_ERR_SWFW_SYNC;
3746
3747 /* Write register address */
3748 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3749 E1000_KUMCTRLSTA_OFFSET) |
3750 E1000_KUMCTRLSTA_REN;
3751 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3752 udelay(2);
3753
3754 /* Read the data returned */
3755 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3756 *data = (uint16_t)reg_val;
3757
3758 e1000_swfw_sync_release(hw, swfw);
3759 return E1000_SUCCESS;
3760}
3761
Adrian Bunke4c780b2006-08-14 23:00:10 -07003762static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003763e1000_write_kmrn_reg(struct e1000_hw *hw,
3764 uint32_t reg_addr,
3765 uint16_t data)
3766{
3767 uint32_t reg_val;
3768 uint16_t swfw;
3769 DEBUGFUNC("e1000_write_kmrn_reg");
3770
3771 if ((hw->mac_type == e1000_80003es2lan) &&
3772 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3773 swfw = E1000_SWFW_PHY1_SM;
3774 } else {
3775 swfw = E1000_SWFW_PHY0_SM;
3776 }
3777 if (e1000_swfw_sync_acquire(hw, swfw))
3778 return -E1000_ERR_SWFW_SYNC;
3779
3780 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3781 E1000_KUMCTRLSTA_OFFSET) | data;
3782 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3783 udelay(2);
3784
3785 e1000_swfw_sync_release(hw, swfw);
3786 return E1000_SUCCESS;
3787}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003788
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789/******************************************************************************
3790* Returns the PHY to the power-on reset state
3791*
3792* hw - Struct containing variables accessed by shared code
3793******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003794int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795e1000_phy_hw_reset(struct e1000_hw *hw)
3796{
3797 uint32_t ctrl, ctrl_ext;
3798 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003799 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003800 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801
3802 DEBUGFUNC("e1000_phy_hw_reset");
3803
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003804 /* In the case of the phy reset being blocked, it's not an error, we
3805 * simply return success without performing the reset. */
3806 ret_val = e1000_check_phy_reset_block(hw);
3807 if (ret_val)
3808 return E1000_SUCCESS;
3809
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 DEBUGOUT("Resetting Phy...\n");
3811
Auke Kok8fc897b2006-08-28 14:56:16 -07003812 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003813 if ((hw->mac_type == e1000_80003es2lan) &&
3814 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3815 swfw = E1000_SWFW_PHY1_SM;
3816 } else {
3817 swfw = E1000_SWFW_PHY0_SM;
3818 }
3819 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003820 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003821 return -E1000_ERR_SWFW_SYNC;
3822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3824 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003825 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003826 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003827 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 */
3829 ctrl = E1000_READ_REG(hw, CTRL);
3830 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3831 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003832
3833 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003834 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003835 else
3836 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003837
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 E1000_WRITE_REG(hw, CTRL, ctrl);
3839 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003840
Jeff Kirsherfd803242005-12-13 00:06:22 -05003841 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003842 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003843
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003844 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 } else {
3846 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3847 * bit to put the PHY into reset. Then, take it out of reset.
3848 */
3849 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3850 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3851 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3852 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3853 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003854 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3856 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3857 E1000_WRITE_FLUSH(hw);
3858 }
3859 udelay(150);
3860
Auke Kok8fc897b2006-08-28 14:56:16 -07003861 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 /* Configure activity LED after PHY reset */
3863 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3864 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3865 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3866 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3867 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003868
3869 /* Wait for FW to finish PHY configuration. */
3870 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003871 if (ret_val != E1000_SUCCESS)
3872 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003873 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003874
Auke Kok8fc897b2006-08-28 14:56:16 -07003875 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3876 ret_val = e1000_init_lcd_from_nvm(hw);
3877
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003878 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879}
3880
3881/******************************************************************************
3882* Resets the PHY
3883*
3884* hw - Struct containing variables accessed by shared code
3885*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003886* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887******************************************************************************/
3888int32_t
3889e1000_phy_reset(struct e1000_hw *hw)
3890{
3891 int32_t ret_val;
3892 uint16_t phy_data;
3893
3894 DEBUGFUNC("e1000_phy_reset");
3895
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003896 /* In the case of the phy reset being blocked, it's not an error, we
3897 * simply return success without performing the reset. */
3898 ret_val = e1000_check_phy_reset_block(hw);
3899 if (ret_val)
3900 return E1000_SUCCESS;
3901
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003902 switch (hw->phy_type) {
3903 case e1000_phy_igp:
3904 case e1000_phy_igp_2:
3905 case e1000_phy_igp_3:
3906 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003907 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003908 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003909 return ret_val;
3910 break;
3911 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003913 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 return ret_val;
3915
3916 phy_data |= MII_CR_RESET;
3917 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003918 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 return ret_val;
3920
3921 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003922 break;
3923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
Auke Kok8fc897b2006-08-28 14:56:16 -07003925 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 e1000_phy_init_script(hw);
3927
3928 return E1000_SUCCESS;
3929}
3930
3931/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003932* Work-around for 82566 power-down: on D3 entry-
3933* 1) disable gigabit link
3934* 2) write VR power-down enable
3935* 3) read it back
3936* if successful continue, else issue LCD reset and repeat
3937*
3938* hw - struct containing variables accessed by shared code
3939******************************************************************************/
3940void
3941e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3942{
3943 int32_t reg;
3944 uint16_t phy_data;
3945 int32_t retry = 0;
3946
3947 DEBUGFUNC("e1000_phy_powerdown_workaround");
3948
3949 if (hw->phy_type != e1000_phy_igp_3)
3950 return;
3951
3952 do {
3953 /* Disable link */
3954 reg = E1000_READ_REG(hw, PHY_CTRL);
3955 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3956 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3957
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003958 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003959 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003960 phy_data |= (1 << 9);
3961 phy_data &= ~(1 << 8);
3962 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003963
3964 /* Read it back and test */
3965 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003966 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003967 break;
3968
3969 /* Issue PHY reset and repeat at most one more time */
3970 reg = E1000_READ_REG(hw, CTRL);
3971 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3972 retry++;
3973 } while (retry);
3974
3975 return;
3976
3977}
3978
3979/******************************************************************************
3980* Work-around for 82566 Kumeran PCS lock loss:
3981* On link status change (i.e. PCI reset, speed change) and link is up and
3982* speed is gigabit-
3983* 0) if workaround is optionally disabled do nothing
3984* 1) wait 1ms for Kumeran link to come up
3985* 2) check Kumeran Diagnostic register PCS lock loss bit
3986* 3) if not set the link is locked (all is good), otherwise...
3987* 4) reset the PHY
3988* 5) repeat up to 10 times
3989* Note: this is only called for IGP3 copper when speed is 1gb.
3990*
3991* hw - struct containing variables accessed by shared code
3992******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003993static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003994e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3995{
3996 int32_t ret_val;
3997 int32_t reg;
3998 int32_t cnt;
3999 uint16_t phy_data;
4000
4001 if (hw->kmrn_lock_loss_workaround_disabled)
4002 return E1000_SUCCESS;
4003
Auke Kok8fc897b2006-08-28 14:56:16 -07004004 /* Make sure link is up before proceeding. If not just return.
4005 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07004006 * stability */
4007 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4008 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4009
4010 if (phy_data & MII_SR_LINK_STATUS) {
4011 for (cnt = 0; cnt < 10; cnt++) {
4012 /* read once to clear */
4013 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4014 if (ret_val)
4015 return ret_val;
4016 /* and again to get new status */
4017 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4018 if (ret_val)
4019 return ret_val;
4020
4021 /* check for PCS lock */
4022 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4023 return E1000_SUCCESS;
4024
4025 /* Issue PHY reset */
4026 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004027 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004028 }
4029 /* Disable GigE link negotiation */
4030 reg = E1000_READ_REG(hw, PHY_CTRL);
4031 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4032 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4033
4034 /* unable to acquire PCS lock */
4035 return E1000_ERR_PHY;
4036 }
4037
4038 return E1000_SUCCESS;
4039}
4040
4041/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042* Probes the expected PHY address for known PHY IDs
4043*
4044* hw - Struct containing variables accessed by shared code
4045******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004046static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047e1000_detect_gig_phy(struct e1000_hw *hw)
4048{
4049 int32_t phy_init_status, ret_val;
4050 uint16_t phy_id_high, phy_id_low;
4051 boolean_t match = FALSE;
4052
4053 DEBUGFUNC("e1000_detect_gig_phy");
4054
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004055 if (hw->phy_id != 0)
4056 return E1000_SUCCESS;
4057
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004058 /* The 82571 firmware may still be configuring the PHY. In this
4059 * case, we cannot access the PHY until the configuration is done. So
4060 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004061 if (hw->mac_type == e1000_82571 ||
4062 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004063 hw->phy_id = IGP01E1000_I_PHY_ID;
4064 hw->phy_type = e1000_phy_igp_2;
4065 return E1000_SUCCESS;
4066 }
4067
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004068 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4069 * around that forces PHY page 0 to be set or the reads fail. The rest of
4070 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4071 * So for ESB-2 we need to have this set so our reads won't fail. If the
4072 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4073 * this out as well. */
4074 if (hw->mac_type == e1000_80003es2lan)
4075 hw->phy_type = e1000_phy_gg82563;
4076
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 /* Read the PHY ID Registers to identify which PHY is onboard. */
4078 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004079 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 return ret_val;
4081
4082 hw->phy_id = (uint32_t) (phy_id_high << 16);
4083 udelay(20);
4084 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004085 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 return ret_val;
4087
4088 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4089 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4090
Auke Kok8fc897b2006-08-28 14:56:16 -07004091 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004093 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 break;
4095 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004096 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 break;
4098 case e1000_82540:
4099 case e1000_82545:
4100 case e1000_82545_rev_3:
4101 case e1000_82546:
4102 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004103 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 break;
4105 case e1000_82541:
4106 case e1000_82541_rev_2:
4107 case e1000_82547:
4108 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004109 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004111 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004112 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004113 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004114 case e1000_80003es2lan:
4115 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4116 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004117 case e1000_ich8lan:
4118 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4119 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4120 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4121 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4122 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 default:
4124 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4125 return -E1000_ERR_CONFIG;
4126 }
4127 phy_init_status = e1000_set_phy_type(hw);
4128
4129 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4130 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4131 return E1000_SUCCESS;
4132 }
4133 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4134 return -E1000_ERR_PHY;
4135}
4136
4137/******************************************************************************
4138* Resets the PHY's DSP
4139*
4140* hw - Struct containing variables accessed by shared code
4141******************************************************************************/
4142static int32_t
4143e1000_phy_reset_dsp(struct e1000_hw *hw)
4144{
4145 int32_t ret_val;
4146 DEBUGFUNC("e1000_phy_reset_dsp");
4147
4148 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004149 if (hw->phy_type != e1000_phy_gg82563) {
4150 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004151 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004154 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004156 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004158 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159
4160 return ret_val;
4161}
4162
4163/******************************************************************************
4164* Get PHY information from various PHY registers for igp PHY only.
4165*
4166* hw - Struct containing variables accessed by shared code
4167* phy_info - PHY information structure
4168******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004169static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170e1000_phy_igp_get_info(struct e1000_hw *hw,
4171 struct e1000_phy_info *phy_info)
4172{
4173 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004174 uint16_t phy_data, min_length, max_length, average;
4175 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176
4177 DEBUGFUNC("e1000_phy_igp_get_info");
4178
4179 /* The downshift status is checked only once, after link is established,
4180 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004181 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182
4183 /* IGP01E1000 does not need to support it. */
4184 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4185
4186 /* IGP01E1000 always correct polarity reversal */
4187 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4188
4189 /* Check polarity status */
4190 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004191 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 return ret_val;
4193
4194 phy_info->cable_polarity = polarity;
4195
4196 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_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->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4201 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
Auke Kok8fc897b2006-08-28 14:56:16 -07004203 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 IGP01E1000_PSSR_SPEED_1000MBPS) {
4205 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4206 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004207 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 return ret_val;
4209
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004210 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4211 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4212 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4213 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4214 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4215 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216
4217 /* Get cable length */
4218 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004219 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 return ret_val;
4221
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004222 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 average = (max_length + min_length) / 2;
4224
Auke Kok8fc897b2006-08-28 14:56:16 -07004225 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004227 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004229 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004231 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 phy_info->cable_length = e1000_cable_length_110_140;
4233 else
4234 phy_info->cable_length = e1000_cable_length_140;
4235 }
4236
4237 return E1000_SUCCESS;
4238}
4239
4240/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004241* Get PHY information from various PHY registers for ife PHY only.
4242*
4243* hw - Struct containing variables accessed by shared code
4244* phy_info - PHY information structure
4245******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004246static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004247e1000_phy_ife_get_info(struct e1000_hw *hw,
4248 struct e1000_phy_info *phy_info)
4249{
4250 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004251 uint16_t phy_data;
4252 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004253
4254 DEBUGFUNC("e1000_phy_ife_get_info");
4255
4256 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4257 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4258
4259 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4260 if (ret_val)
4261 return ret_val;
4262 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004263 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4264 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4265 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004266
4267 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4268 ret_val = e1000_check_polarity(hw, &polarity);
4269 if (ret_val)
4270 return ret_val;
4271 } else {
4272 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004273 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4274 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4275 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004276 }
4277 phy_info->cable_polarity = polarity;
4278
4279 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4280 if (ret_val)
4281 return ret_val;
4282
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004283 phy_info->mdix_mode = (e1000_auto_x_mode)
4284 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4285 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004286
4287 return E1000_SUCCESS;
4288}
4289
4290/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291* Get PHY information from various PHY registers fot m88 PHY only.
4292*
4293* hw - Struct containing variables accessed by shared code
4294* phy_info - PHY information structure
4295******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004296static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297e1000_phy_m88_get_info(struct e1000_hw *hw,
4298 struct e1000_phy_info *phy_info)
4299{
4300 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004301 uint16_t phy_data;
4302 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303
4304 DEBUGFUNC("e1000_phy_m88_get_info");
4305
4306 /* The downshift status is checked only once, after link is established,
4307 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004308 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309
4310 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004311 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 return ret_val;
4313
4314 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004315 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4316 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4317 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4318
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004320 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4321 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4322 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323
4324 /* Check polarity status */
4325 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004326 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004327 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 phy_info->cable_polarity = polarity;
4329
4330 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004331 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 return ret_val;
4333
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004334 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4335 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336
4337 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4338 /* Cable Length Estimation and Local/Remote Receiver Information
4339 * are only valid at 1000 Mbps.
4340 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004341 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004342 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004343 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4344 } else {
4345 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4346 &phy_data);
4347 if (ret_val)
4348 return ret_val;
4349
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004350 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352
4353 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004354 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 return ret_val;
4356
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004357 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4358 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4359 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4360 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4361 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4362 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 }
4365
4366 return E1000_SUCCESS;
4367}
4368
4369/******************************************************************************
4370* Get PHY information from various PHY registers
4371*
4372* hw - Struct containing variables accessed by shared code
4373* phy_info - PHY information structure
4374******************************************************************************/
4375int32_t
4376e1000_phy_get_info(struct e1000_hw *hw,
4377 struct e1000_phy_info *phy_info)
4378{
4379 int32_t ret_val;
4380 uint16_t phy_data;
4381
4382 DEBUGFUNC("e1000_phy_get_info");
4383
4384 phy_info->cable_length = e1000_cable_length_undefined;
4385 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4386 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4387 phy_info->downshift = e1000_downshift_undefined;
4388 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4389 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4390 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4391 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4392
Auke Kok8fc897b2006-08-28 14:56:16 -07004393 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 DEBUGOUT("PHY info is only valid for copper media\n");
4395 return -E1000_ERR_CONFIG;
4396 }
4397
4398 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004399 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 return ret_val;
4401
4402 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004403 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return ret_val;
4405
Auke Kok8fc897b2006-08-28 14:56:16 -07004406 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 DEBUGOUT("PHY info is only valid if link is up\n");
4408 return -E1000_ERR_CONFIG;
4409 }
4410
Auke Kokcd94dd02006-06-27 09:08:22 -07004411 if (hw->phy_type == e1000_phy_igp ||
4412 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004413 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004415 else if (hw->phy_type == e1000_phy_ife)
4416 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 else
4418 return e1000_phy_m88_get_info(hw, phy_info);
4419}
4420
4421int32_t
4422e1000_validate_mdi_setting(struct e1000_hw *hw)
4423{
4424 DEBUGFUNC("e1000_validate_mdi_settings");
4425
Auke Kok8fc897b2006-08-28 14:56:16 -07004426 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 DEBUGOUT("Invalid MDI setting detected\n");
4428 hw->mdix = 1;
4429 return -E1000_ERR_CONFIG;
4430 }
4431 return E1000_SUCCESS;
4432}
4433
4434
4435/******************************************************************************
4436 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004437 * is configured. Additionally, if this is ICH8, the flash controller GbE
4438 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 *
4440 * hw - Struct containing variables accessed by shared code
4441 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004442int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443e1000_init_eeprom_params(struct e1000_hw *hw)
4444{
4445 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4446 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004447 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 uint16_t eeprom_size;
4449
4450 DEBUGFUNC("e1000_init_eeprom_params");
4451
4452 switch (hw->mac_type) {
4453 case e1000_82542_rev2_0:
4454 case e1000_82542_rev2_1:
4455 case e1000_82543:
4456 case e1000_82544:
4457 eeprom->type = e1000_eeprom_microwire;
4458 eeprom->word_size = 64;
4459 eeprom->opcode_bits = 3;
4460 eeprom->address_bits = 6;
4461 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004462 eeprom->use_eerd = FALSE;
4463 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 break;
4465 case e1000_82540:
4466 case e1000_82545:
4467 case e1000_82545_rev_3:
4468 case e1000_82546:
4469 case e1000_82546_rev_3:
4470 eeprom->type = e1000_eeprom_microwire;
4471 eeprom->opcode_bits = 3;
4472 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004473 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 eeprom->word_size = 256;
4475 eeprom->address_bits = 8;
4476 } else {
4477 eeprom->word_size = 64;
4478 eeprom->address_bits = 6;
4479 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004480 eeprom->use_eerd = FALSE;
4481 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 break;
4483 case e1000_82541:
4484 case e1000_82541_rev_2:
4485 case e1000_82547:
4486 case e1000_82547_rev_2:
4487 if (eecd & E1000_EECD_TYPE) {
4488 eeprom->type = e1000_eeprom_spi;
4489 eeprom->opcode_bits = 8;
4490 eeprom->delay_usec = 1;
4491 if (eecd & E1000_EECD_ADDR_BITS) {
4492 eeprom->page_size = 32;
4493 eeprom->address_bits = 16;
4494 } else {
4495 eeprom->page_size = 8;
4496 eeprom->address_bits = 8;
4497 }
4498 } else {
4499 eeprom->type = e1000_eeprom_microwire;
4500 eeprom->opcode_bits = 3;
4501 eeprom->delay_usec = 50;
4502 if (eecd & E1000_EECD_ADDR_BITS) {
4503 eeprom->word_size = 256;
4504 eeprom->address_bits = 8;
4505 } else {
4506 eeprom->word_size = 64;
4507 eeprom->address_bits = 6;
4508 }
4509 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004510 eeprom->use_eerd = FALSE;
4511 eeprom->use_eewr = FALSE;
4512 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004513 case e1000_82571:
4514 case e1000_82572:
4515 eeprom->type = e1000_eeprom_spi;
4516 eeprom->opcode_bits = 8;
4517 eeprom->delay_usec = 1;
4518 if (eecd & E1000_EECD_ADDR_BITS) {
4519 eeprom->page_size = 32;
4520 eeprom->address_bits = 16;
4521 } else {
4522 eeprom->page_size = 8;
4523 eeprom->address_bits = 8;
4524 }
4525 eeprom->use_eerd = FALSE;
4526 eeprom->use_eewr = FALSE;
4527 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004528 case e1000_82573:
4529 eeprom->type = e1000_eeprom_spi;
4530 eeprom->opcode_bits = 8;
4531 eeprom->delay_usec = 1;
4532 if (eecd & E1000_EECD_ADDR_BITS) {
4533 eeprom->page_size = 32;
4534 eeprom->address_bits = 16;
4535 } else {
4536 eeprom->page_size = 8;
4537 eeprom->address_bits = 8;
4538 }
4539 eeprom->use_eerd = TRUE;
4540 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004541 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004542 eeprom->type = e1000_eeprom_flash;
4543 eeprom->word_size = 2048;
4544
4545 /* Ensure that the Autonomous FLASH update bit is cleared due to
4546 * Flash update issue on parts which use a FLASH for NVM. */
4547 eecd &= ~E1000_EECD_AUPDEN;
4548 E1000_WRITE_REG(hw, EECD, eecd);
4549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004551 case e1000_80003es2lan:
4552 eeprom->type = e1000_eeprom_spi;
4553 eeprom->opcode_bits = 8;
4554 eeprom->delay_usec = 1;
4555 if (eecd & E1000_EECD_ADDR_BITS) {
4556 eeprom->page_size = 32;
4557 eeprom->address_bits = 16;
4558 } else {
4559 eeprom->page_size = 8;
4560 eeprom->address_bits = 8;
4561 }
4562 eeprom->use_eerd = TRUE;
4563 eeprom->use_eewr = FALSE;
4564 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004565 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004566 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004567 int32_t i = 0;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004568 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
Auke Kokcd94dd02006-06-27 09:08:22 -07004569
4570 eeprom->type = e1000_eeprom_ich8;
4571 eeprom->use_eerd = FALSE;
4572 eeprom->use_eewr = FALSE;
4573 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4574
4575 /* Zero the shadow RAM structure. But don't load it from NVM
4576 * so as to save time for driver init */
4577 if (hw->eeprom_shadow_ram != NULL) {
4578 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4579 hw->eeprom_shadow_ram[i].modified = FALSE;
4580 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4581 }
4582 }
4583
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004584 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4585 ICH_FLASH_SECTOR_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -07004586
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004587 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4588 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4589
4590 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4591
Auke Kokcd94dd02006-06-27 09:08:22 -07004592 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4593
4594 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 default:
4597 break;
4598 }
4599
4600 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004601 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4602 * 32KB (incremented by powers of 2).
4603 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004604 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004605 /* Set to default value for initial eeprom read. */
4606 eeprom->word_size = 64;
4607 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004608 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004609 return ret_val;
4610 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4611 /* 256B eeprom size was not supported in earlier hardware, so we
4612 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4613 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004614 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004615 eeprom_size++;
4616 } else {
4617 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4618 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004620
4621 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004623 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624}
4625
4626/******************************************************************************
4627 * Raises the EEPROM's clock input.
4628 *
4629 * hw - Struct containing variables accessed by shared code
4630 * eecd - EECD's current value
4631 *****************************************************************************/
4632static void
4633e1000_raise_ee_clk(struct e1000_hw *hw,
4634 uint32_t *eecd)
4635{
4636 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4637 * wait <delay> microseconds.
4638 */
4639 *eecd = *eecd | E1000_EECD_SK;
4640 E1000_WRITE_REG(hw, EECD, *eecd);
4641 E1000_WRITE_FLUSH(hw);
4642 udelay(hw->eeprom.delay_usec);
4643}
4644
4645/******************************************************************************
4646 * Lowers the EEPROM's clock input.
4647 *
4648 * hw - Struct containing variables accessed by shared code
4649 * eecd - EECD's current value
4650 *****************************************************************************/
4651static void
4652e1000_lower_ee_clk(struct e1000_hw *hw,
4653 uint32_t *eecd)
4654{
4655 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4656 * wait 50 microseconds.
4657 */
4658 *eecd = *eecd & ~E1000_EECD_SK;
4659 E1000_WRITE_REG(hw, EECD, *eecd);
4660 E1000_WRITE_FLUSH(hw);
4661 udelay(hw->eeprom.delay_usec);
4662}
4663
4664/******************************************************************************
4665 * Shift data bits out to the EEPROM.
4666 *
4667 * hw - Struct containing variables accessed by shared code
4668 * data - data to send to the EEPROM
4669 * count - number of bits to shift out
4670 *****************************************************************************/
4671static void
4672e1000_shift_out_ee_bits(struct e1000_hw *hw,
4673 uint16_t data,
4674 uint16_t count)
4675{
4676 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4677 uint32_t eecd;
4678 uint32_t mask;
4679
4680 /* We need to shift "count" bits out to the EEPROM. So, value in the
4681 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4682 * In order to do this, "data" must be broken down into bits.
4683 */
4684 mask = 0x01 << (count - 1);
4685 eecd = E1000_READ_REG(hw, EECD);
4686 if (eeprom->type == e1000_eeprom_microwire) {
4687 eecd &= ~E1000_EECD_DO;
4688 } else if (eeprom->type == e1000_eeprom_spi) {
4689 eecd |= E1000_EECD_DO;
4690 }
4691 do {
4692 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4693 * and then raising and then lowering the clock (the SK bit controls
4694 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4695 * by setting "DI" to "0" and then raising and then lowering the clock.
4696 */
4697 eecd &= ~E1000_EECD_DI;
4698
Auke Kok8fc897b2006-08-28 14:56:16 -07004699 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 eecd |= E1000_EECD_DI;
4701
4702 E1000_WRITE_REG(hw, EECD, eecd);
4703 E1000_WRITE_FLUSH(hw);
4704
4705 udelay(eeprom->delay_usec);
4706
4707 e1000_raise_ee_clk(hw, &eecd);
4708 e1000_lower_ee_clk(hw, &eecd);
4709
4710 mask = mask >> 1;
4711
Auke Kok8fc897b2006-08-28 14:56:16 -07004712 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713
4714 /* We leave the "DI" bit set to "0" when we leave this routine. */
4715 eecd &= ~E1000_EECD_DI;
4716 E1000_WRITE_REG(hw, EECD, eecd);
4717}
4718
4719/******************************************************************************
4720 * Shift data bits in from the EEPROM
4721 *
4722 * hw - Struct containing variables accessed by shared code
4723 *****************************************************************************/
4724static uint16_t
4725e1000_shift_in_ee_bits(struct e1000_hw *hw,
4726 uint16_t count)
4727{
4728 uint32_t eecd;
4729 uint32_t i;
4730 uint16_t data;
4731
4732 /* In order to read a register from the EEPROM, we need to shift 'count'
4733 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4734 * input to the EEPROM (setting the SK bit), and then reading the value of
4735 * the "DO" bit. During this "shifting in" process the "DI" bit should
4736 * always be clear.
4737 */
4738
4739 eecd = E1000_READ_REG(hw, EECD);
4740
4741 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4742 data = 0;
4743
Auke Kok8fc897b2006-08-28 14:56:16 -07004744 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 data = data << 1;
4746 e1000_raise_ee_clk(hw, &eecd);
4747
4748 eecd = E1000_READ_REG(hw, EECD);
4749
4750 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004751 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 data |= 1;
4753
4754 e1000_lower_ee_clk(hw, &eecd);
4755 }
4756
4757 return data;
4758}
4759
4760/******************************************************************************
4761 * Prepares EEPROM for access
4762 *
4763 * hw - Struct containing variables accessed by shared code
4764 *
4765 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4766 * function should be called before issuing a command to the EEPROM.
4767 *****************************************************************************/
4768static int32_t
4769e1000_acquire_eeprom(struct e1000_hw *hw)
4770{
4771 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4772 uint32_t eecd, i=0;
4773
4774 DEBUGFUNC("e1000_acquire_eeprom");
4775
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004776 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4777 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 eecd = E1000_READ_REG(hw, EECD);
4779
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004780 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004781 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004782 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004783 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004785 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004786 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004787 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4788 i++;
4789 udelay(5);
4790 eecd = E1000_READ_REG(hw, EECD);
4791 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004792 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004793 eecd &= ~E1000_EECD_REQ;
4794 E1000_WRITE_REG(hw, EECD, eecd);
4795 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004796 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004797 return -E1000_ERR_EEPROM;
4798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 }
4800 }
4801
4802 /* Setup EEPROM for Read/Write */
4803
4804 if (eeprom->type == e1000_eeprom_microwire) {
4805 /* Clear SK and DI */
4806 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4807 E1000_WRITE_REG(hw, EECD, eecd);
4808
4809 /* Set CS */
4810 eecd |= E1000_EECD_CS;
4811 E1000_WRITE_REG(hw, EECD, eecd);
4812 } else if (eeprom->type == e1000_eeprom_spi) {
4813 /* Clear SK and CS */
4814 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4815 E1000_WRITE_REG(hw, EECD, eecd);
4816 udelay(1);
4817 }
4818
4819 return E1000_SUCCESS;
4820}
4821
4822/******************************************************************************
4823 * Returns EEPROM to a "standby" state
4824 *
4825 * hw - Struct containing variables accessed by shared code
4826 *****************************************************************************/
4827static void
4828e1000_standby_eeprom(struct e1000_hw *hw)
4829{
4830 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4831 uint32_t eecd;
4832
4833 eecd = E1000_READ_REG(hw, EECD);
4834
Auke Kok8fc897b2006-08-28 14:56:16 -07004835 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4837 E1000_WRITE_REG(hw, EECD, eecd);
4838 E1000_WRITE_FLUSH(hw);
4839 udelay(eeprom->delay_usec);
4840
4841 /* Clock high */
4842 eecd |= E1000_EECD_SK;
4843 E1000_WRITE_REG(hw, EECD, eecd);
4844 E1000_WRITE_FLUSH(hw);
4845 udelay(eeprom->delay_usec);
4846
4847 /* Select EEPROM */
4848 eecd |= E1000_EECD_CS;
4849 E1000_WRITE_REG(hw, EECD, eecd);
4850 E1000_WRITE_FLUSH(hw);
4851 udelay(eeprom->delay_usec);
4852
4853 /* Clock low */
4854 eecd &= ~E1000_EECD_SK;
4855 E1000_WRITE_REG(hw, EECD, eecd);
4856 E1000_WRITE_FLUSH(hw);
4857 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004858 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 /* Toggle CS to flush commands */
4860 eecd |= E1000_EECD_CS;
4861 E1000_WRITE_REG(hw, EECD, eecd);
4862 E1000_WRITE_FLUSH(hw);
4863 udelay(eeprom->delay_usec);
4864 eecd &= ~E1000_EECD_CS;
4865 E1000_WRITE_REG(hw, EECD, eecd);
4866 E1000_WRITE_FLUSH(hw);
4867 udelay(eeprom->delay_usec);
4868 }
4869}
4870
4871/******************************************************************************
4872 * Terminates a command by inverting the EEPROM's chip select pin
4873 *
4874 * hw - Struct containing variables accessed by shared code
4875 *****************************************************************************/
4876static void
4877e1000_release_eeprom(struct e1000_hw *hw)
4878{
4879 uint32_t eecd;
4880
4881 DEBUGFUNC("e1000_release_eeprom");
4882
4883 eecd = E1000_READ_REG(hw, EECD);
4884
4885 if (hw->eeprom.type == e1000_eeprom_spi) {
4886 eecd |= E1000_EECD_CS; /* Pull CS high */
4887 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4888
4889 E1000_WRITE_REG(hw, EECD, eecd);
4890
4891 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004892 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 /* cleanup eeprom */
4894
4895 /* CS on Microwire is active-high */
4896 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4897
4898 E1000_WRITE_REG(hw, EECD, eecd);
4899
4900 /* Rising edge of clock */
4901 eecd |= E1000_EECD_SK;
4902 E1000_WRITE_REG(hw, EECD, eecd);
4903 E1000_WRITE_FLUSH(hw);
4904 udelay(hw->eeprom.delay_usec);
4905
4906 /* Falling edge of clock */
4907 eecd &= ~E1000_EECD_SK;
4908 E1000_WRITE_REG(hw, EECD, eecd);
4909 E1000_WRITE_FLUSH(hw);
4910 udelay(hw->eeprom.delay_usec);
4911 }
4912
4913 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004914 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 eecd &= ~E1000_EECD_REQ;
4916 E1000_WRITE_REG(hw, EECD, eecd);
4917 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004918
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004919 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920}
4921
4922/******************************************************************************
4923 * Reads a 16 bit word from the EEPROM.
4924 *
4925 * hw - Struct containing variables accessed by shared code
4926 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004927static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928e1000_spi_eeprom_ready(struct e1000_hw *hw)
4929{
4930 uint16_t retry_count = 0;
4931 uint8_t spi_stat_reg;
4932
4933 DEBUGFUNC("e1000_spi_eeprom_ready");
4934
4935 /* Read "Status Register" repeatedly until the LSB is cleared. The
4936 * EEPROM will signal that the command has been completed by clearing
4937 * bit 0 of the internal status register. If it's not cleared within
4938 * 5 milliseconds, then error out.
4939 */
4940 retry_count = 0;
4941 do {
4942 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4943 hw->eeprom.opcode_bits);
4944 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4945 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4946 break;
4947
4948 udelay(5);
4949 retry_count += 5;
4950
4951 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004952 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953
4954 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4955 * only 0-5mSec on 5V devices)
4956 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004957 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 DEBUGOUT("SPI EEPROM Status error\n");
4959 return -E1000_ERR_EEPROM;
4960 }
4961
4962 return E1000_SUCCESS;
4963}
4964
4965/******************************************************************************
4966 * Reads a 16 bit word from the EEPROM.
4967 *
4968 * hw - Struct containing variables accessed by shared code
4969 * offset - offset of word in the EEPROM to read
4970 * data - word read from the EEPROM
4971 * words - number of words to read
4972 *****************************************************************************/
4973int32_t
4974e1000_read_eeprom(struct e1000_hw *hw,
4975 uint16_t offset,
4976 uint16_t words,
4977 uint16_t *data)
4978{
4979 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4980 uint32_t i = 0;
4981
4982 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004983
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004984 /* If eeprom is not yet detected, do so now */
4985 if (eeprom->word_size == 0)
4986 e1000_init_eeprom_params(hw);
4987
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 /* A check for invalid values: offset too large, too many words, and not
4989 * enough words.
4990 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004991 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004993 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 return -E1000_ERR_EEPROM;
4995 }
4996
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004997 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4998 * directly. In this case, we need to acquire the EEPROM so that
4999 * FW or other port software does not interrupt.
5000 */
Jeff Kirsher4d3518582006-01-12 16:50:48 -08005001 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07005002 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005003 /* Prepare the EEPROM for bit-bang reading */
5004 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5005 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005006 }
5007
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005008 /* Eerd register EEPROM access requires no eeprom aquire/release */
5009 if (eeprom->use_eerd == TRUE)
5010 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005012 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07005013 if (eeprom->type == e1000_eeprom_ich8)
5014 return e1000_read_eeprom_ich8(hw, offset, words, data);
5015
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005016 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5017 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07005018 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 uint16_t word_in;
5020 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5021
Auke Kok8fc897b2006-08-28 14:56:16 -07005022 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 e1000_release_eeprom(hw);
5024 return -E1000_ERR_EEPROM;
5025 }
5026
5027 e1000_standby_eeprom(hw);
5028
5029 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005030 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 read_opcode |= EEPROM_A8_OPCODE_SPI;
5032
5033 /* Send the READ command (opcode + addr) */
5034 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5035 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5036
5037 /* Read the data. The address of the eeprom internally increments with
5038 * each byte (spi) being read, saving on the overhead of eeprom setup
5039 * and tear-down. The address counter will roll over if reading beyond
5040 * the size of the eeprom, thus allowing the entire memory to be read
5041 * starting from any offset. */
5042 for (i = 0; i < words; i++) {
5043 word_in = e1000_shift_in_ee_bits(hw, 16);
5044 data[i] = (word_in >> 8) | (word_in << 8);
5045 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005046 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 for (i = 0; i < words; i++) {
5048 /* Send the READ command (opcode + addr) */
5049 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5050 eeprom->opcode_bits);
5051 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5052 eeprom->address_bits);
5053
5054 /* Read the data. For microwire, each word requires the overhead
5055 * of eeprom setup and tear-down. */
5056 data[i] = e1000_shift_in_ee_bits(hw, 16);
5057 e1000_standby_eeprom(hw);
5058 }
5059 }
5060
5061 /* End this read operation */
5062 e1000_release_eeprom(hw);
5063
5064 return E1000_SUCCESS;
5065}
5066
5067/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005068 * Reads a 16 bit word from the EEPROM using the EERD register.
5069 *
5070 * hw - Struct containing variables accessed by shared code
5071 * offset - offset of word in the EEPROM to read
5072 * data - word read from the EEPROM
5073 * words - number of words to read
5074 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005075static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005076e1000_read_eeprom_eerd(struct e1000_hw *hw,
5077 uint16_t offset,
5078 uint16_t words,
5079 uint16_t *data)
5080{
5081 uint32_t i, eerd = 0;
5082 int32_t error = 0;
5083
5084 for (i = 0; i < words; i++) {
5085 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5086 E1000_EEPROM_RW_REG_START;
5087
5088 E1000_WRITE_REG(hw, EERD, eerd);
5089 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005090
Auke Kok8fc897b2006-08-28 14:56:16 -07005091 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005092 break;
5093 }
5094 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005095
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005096 }
Auke Kok76c224b2006-05-23 13:36:06 -07005097
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005098 return error;
5099}
5100
5101/******************************************************************************
5102 * Writes a 16 bit word from the EEPROM using the EEWR register.
5103 *
5104 * hw - Struct containing variables accessed by shared code
5105 * offset - offset of word in the EEPROM to read
5106 * data - word read from the EEPROM
5107 * words - number of words to read
5108 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005109static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005110e1000_write_eeprom_eewr(struct e1000_hw *hw,
5111 uint16_t offset,
5112 uint16_t words,
5113 uint16_t *data)
5114{
5115 uint32_t register_value = 0;
5116 uint32_t i = 0;
5117 int32_t error = 0;
5118
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005119 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5120 return -E1000_ERR_SWFW_SYNC;
5121
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005122 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005123 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5124 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005125 E1000_EEPROM_RW_REG_START;
5126
5127 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005128 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005129 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005130 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005131
5132 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005133
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005134 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005135
Auke Kok8fc897b2006-08-28 14:56:16 -07005136 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005137 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005138 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005139 }
Auke Kok76c224b2006-05-23 13:36:06 -07005140
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005141 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005142 return error;
5143}
5144
5145/******************************************************************************
5146 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5147 *
5148 * hw - Struct containing variables accessed by shared code
5149 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005150static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005151e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5152{
5153 uint32_t attempts = 100000;
5154 uint32_t i, reg = 0;
5155 int32_t done = E1000_ERR_EEPROM;
5156
Auke Kok8fc897b2006-08-28 14:56:16 -07005157 for (i = 0; i < attempts; i++) {
5158 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005159 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005160 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005161 reg = E1000_READ_REG(hw, EEWR);
5162
Auke Kok8fc897b2006-08-28 14:56:16 -07005163 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005164 done = E1000_SUCCESS;
5165 break;
5166 }
5167 udelay(5);
5168 }
5169
5170 return done;
5171}
5172
5173/***************************************************************************
5174* Description: Determines if the onboard NVM is FLASH or EEPROM.
5175*
5176* hw - Struct containing variables accessed by shared code
5177****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005178static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005179e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5180{
5181 uint32_t eecd = 0;
5182
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005183 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5184
Auke Kokcd94dd02006-06-27 09:08:22 -07005185 if (hw->mac_type == e1000_ich8lan)
5186 return FALSE;
5187
5188 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005189 eecd = E1000_READ_REG(hw, EECD);
5190
5191 /* Isolate bits 15 & 16 */
5192 eecd = ((eecd >> 15) & 0x03);
5193
5194 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005195 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005196 return FALSE;
5197 }
5198 }
5199 return TRUE;
5200}
5201
5202/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 * Verifies that the EEPROM has a valid checksum
5204 *
5205 * hw - Struct containing variables accessed by shared code
5206 *
5207 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5208 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5209 * valid.
5210 *****************************************************************************/
5211int32_t
5212e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5213{
5214 uint16_t checksum = 0;
5215 uint16_t i, eeprom_data;
5216
5217 DEBUGFUNC("e1000_validate_eeprom_checksum");
5218
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005219 if ((hw->mac_type == e1000_82573) &&
5220 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5221 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5222 * 10h-12h. Checksum may need to be fixed. */
5223 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5224 if ((eeprom_data & 0x10) == 0) {
5225 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5226 * has already been fixed. If the checksum is still wrong and this
5227 * bit is a 1, we need to return bad checksum. Otherwise, we need
5228 * to set this bit to a 1 and update the checksum. */
5229 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5230 if ((eeprom_data & 0x8000) == 0) {
5231 eeprom_data |= 0x8000;
5232 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5233 e1000_update_eeprom_checksum(hw);
5234 }
5235 }
5236 }
5237
Auke Kokcd94dd02006-06-27 09:08:22 -07005238 if (hw->mac_type == e1000_ich8lan) {
5239 /* Drivers must allocate the shadow ram structure for the
5240 * EEPROM checksum to be updated. Otherwise, this bit as well
5241 * as the checksum must both be set correctly for this
5242 * validation to pass.
5243 */
5244 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5245 if ((eeprom_data & 0x40) == 0) {
5246 eeprom_data |= 0x40;
5247 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5248 e1000_update_eeprom_checksum(hw);
5249 }
5250 }
5251
5252 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5253 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 DEBUGOUT("EEPROM Read Error\n");
5255 return -E1000_ERR_EEPROM;
5256 }
5257 checksum += eeprom_data;
5258 }
5259
Auke Kok8fc897b2006-08-28 14:56:16 -07005260 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 return E1000_SUCCESS;
5262 else {
5263 DEBUGOUT("EEPROM Checksum Invalid\n");
5264 return -E1000_ERR_EEPROM;
5265 }
5266}
5267
5268/******************************************************************************
5269 * Calculates the EEPROM checksum and writes it to the EEPROM
5270 *
5271 * hw - Struct containing variables accessed by shared code
5272 *
5273 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5274 * Writes the difference to word offset 63 of the EEPROM.
5275 *****************************************************************************/
5276int32_t
5277e1000_update_eeprom_checksum(struct e1000_hw *hw)
5278{
Auke Kokcd94dd02006-06-27 09:08:22 -07005279 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280 uint16_t checksum = 0;
5281 uint16_t i, eeprom_data;
5282
5283 DEBUGFUNC("e1000_update_eeprom_checksum");
5284
Auke Kok8fc897b2006-08-28 14:56:16 -07005285 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5286 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287 DEBUGOUT("EEPROM Read Error\n");
5288 return -E1000_ERR_EEPROM;
5289 }
5290 checksum += eeprom_data;
5291 }
5292 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005293 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 DEBUGOUT("EEPROM Write Error\n");
5295 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005296 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5297 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005298 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5299 e1000_commit_shadow_ram(hw);
5300 /* Reload the EEPROM, or else modifications will not appear
5301 * until after next adapter reset. */
5302 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5303 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5304 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005305 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306 }
5307 return E1000_SUCCESS;
5308}
5309
5310/******************************************************************************
5311 * Parent function for writing words to the different EEPROM types.
5312 *
5313 * hw - Struct containing variables accessed by shared code
5314 * offset - offset within the EEPROM to be written to
5315 * words - number of words to write
5316 * data - 16 bit word to be written to the EEPROM
5317 *
5318 * If e1000_update_eeprom_checksum is not called after this function, the
5319 * EEPROM will most likely contain an invalid checksum.
5320 *****************************************************************************/
5321int32_t
5322e1000_write_eeprom(struct e1000_hw *hw,
5323 uint16_t offset,
5324 uint16_t words,
5325 uint16_t *data)
5326{
5327 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5328 int32_t status = 0;
5329
5330 DEBUGFUNC("e1000_write_eeprom");
5331
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005332 /* If eeprom is not yet detected, do so now */
5333 if (eeprom->word_size == 0)
5334 e1000_init_eeprom_params(hw);
5335
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 /* A check for invalid values: offset too large, too many words, and not
5337 * enough words.
5338 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005339 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 (words == 0)) {
5341 DEBUGOUT("\"words\" parameter out of bounds\n");
5342 return -E1000_ERR_EEPROM;
5343 }
5344
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005345 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005346 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005347 return e1000_write_eeprom_eewr(hw, offset, words, data);
5348
Auke Kokcd94dd02006-06-27 09:08:22 -07005349 if (eeprom->type == e1000_eeprom_ich8)
5350 return e1000_write_eeprom_ich8(hw, offset, words, data);
5351
Linus Torvalds1da177e2005-04-16 15:20:36 -07005352 /* Prepare the EEPROM for writing */
5353 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5354 return -E1000_ERR_EEPROM;
5355
Auke Kok8fc897b2006-08-28 14:56:16 -07005356 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5358 } else {
5359 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005360 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 }
5362
5363 /* Done with writing */
5364 e1000_release_eeprom(hw);
5365
5366 return status;
5367}
5368
5369/******************************************************************************
5370 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5371 *
5372 * hw - Struct containing variables accessed by shared code
5373 * offset - offset within the EEPROM to be written to
5374 * words - number of words to write
5375 * data - pointer to array of 8 bit words to be written to the EEPROM
5376 *
5377 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005378static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379e1000_write_eeprom_spi(struct e1000_hw *hw,
5380 uint16_t offset,
5381 uint16_t words,
5382 uint16_t *data)
5383{
5384 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5385 uint16_t widx = 0;
5386
5387 DEBUGFUNC("e1000_write_eeprom_spi");
5388
5389 while (widx < words) {
5390 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5391
Auke Kok8fc897b2006-08-28 14:56:16 -07005392 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393
5394 e1000_standby_eeprom(hw);
5395
5396 /* Send the WRITE ENABLE command (8 bit opcode ) */
5397 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5398 eeprom->opcode_bits);
5399
5400 e1000_standby_eeprom(hw);
5401
5402 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005403 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 write_opcode |= EEPROM_A8_OPCODE_SPI;
5405
5406 /* Send the Write command (8-bit opcode + addr) */
5407 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5408
5409 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5410 eeprom->address_bits);
5411
5412 /* Send the data */
5413
5414 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5415 while (widx < words) {
5416 uint16_t word_out = data[widx];
5417 word_out = (word_out >> 8) | (word_out << 8);
5418 e1000_shift_out_ee_bits(hw, word_out, 16);
5419 widx++;
5420
5421 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5422 * operation, while the smaller eeproms are capable of an 8-byte
5423 * PAGE WRITE operation. Break the inner loop to pass new address
5424 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005425 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426 e1000_standby_eeprom(hw);
5427 break;
5428 }
5429 }
5430 }
5431
5432 return E1000_SUCCESS;
5433}
5434
5435/******************************************************************************
5436 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5437 *
5438 * hw - Struct containing variables accessed by shared code
5439 * offset - offset within the EEPROM to be written to
5440 * words - number of words to write
5441 * data - pointer to array of 16 bit words to be written to the EEPROM
5442 *
5443 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005444static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445e1000_write_eeprom_microwire(struct e1000_hw *hw,
5446 uint16_t offset,
5447 uint16_t words,
5448 uint16_t *data)
5449{
5450 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5451 uint32_t eecd;
5452 uint16_t words_written = 0;
5453 uint16_t i = 0;
5454
5455 DEBUGFUNC("e1000_write_eeprom_microwire");
5456
5457 /* Send the write enable command to the EEPROM (3-bit opcode plus
5458 * 6/8-bit dummy address beginning with 11). It's less work to include
5459 * the 11 of the dummy address as part of the opcode than it is to shift
5460 * it over the correct number of bits for the address. This puts the
5461 * EEPROM into write/erase mode.
5462 */
5463 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5464 (uint16_t)(eeprom->opcode_bits + 2));
5465
5466 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5467
5468 /* Prepare the EEPROM */
5469 e1000_standby_eeprom(hw);
5470
5471 while (words_written < words) {
5472 /* Send the Write command (3-bit opcode + addr) */
5473 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5474 eeprom->opcode_bits);
5475
5476 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5477 eeprom->address_bits);
5478
5479 /* Send the data */
5480 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5481
5482 /* Toggle the CS line. This in effect tells the EEPROM to execute
5483 * the previous command.
5484 */
5485 e1000_standby_eeprom(hw);
5486
5487 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5488 * signal that the command has been completed by raising the DO signal.
5489 * If DO does not go high in 10 milliseconds, then error out.
5490 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005491 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005493 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494 udelay(50);
5495 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005496 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497 DEBUGOUT("EEPROM Write did not complete\n");
5498 return -E1000_ERR_EEPROM;
5499 }
5500
5501 /* Recover from write */
5502 e1000_standby_eeprom(hw);
5503
5504 words_written++;
5505 }
5506
5507 /* Send the write disable command to the EEPROM (3-bit opcode plus
5508 * 6/8-bit dummy address beginning with 10). It's less work to include
5509 * the 10 of the dummy address as part of the opcode than it is to shift
5510 * it over the correct number of bits for the address. This takes the
5511 * EEPROM out of write/erase mode.
5512 */
5513 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5514 (uint16_t)(eeprom->opcode_bits + 2));
5515
5516 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5517
5518 return E1000_SUCCESS;
5519}
5520
5521/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005522 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5523 * in the eeprom cache and the non modified values in the currently active bank
5524 * to the new bank.
5525 *
5526 * hw - Struct containing variables accessed by shared code
5527 * offset - offset of word in the EEPROM to read
5528 * data - word read from the EEPROM
5529 * words - number of words to read
5530 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005531static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005532e1000_commit_shadow_ram(struct e1000_hw *hw)
5533{
5534 uint32_t attempts = 100000;
5535 uint32_t eecd = 0;
5536 uint32_t flop = 0;
5537 uint32_t i = 0;
5538 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005539 uint32_t old_bank_offset = 0;
5540 uint32_t new_bank_offset = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005541 uint8_t low_byte = 0;
5542 uint8_t high_byte = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005543 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005544
5545 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005546 /* The flop register will be used to determine if flash type is STM */
5547 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005548 for (i=0; i < attempts; i++) {
5549 eecd = E1000_READ_REG(hw, EECD);
5550 if ((eecd & E1000_EECD_FLUPD) == 0) {
5551 break;
5552 }
5553 udelay(5);
5554 }
5555
5556 if (i == attempts) {
5557 return -E1000_ERR_EEPROM;
5558 }
5559
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005560 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005561 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5562 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5563 }
5564
5565 /* Perform the flash update */
5566 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5567
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005568 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005569 eecd = E1000_READ_REG(hw, EECD);
5570 if ((eecd & E1000_EECD_FLUPD) == 0) {
5571 break;
5572 }
5573 udelay(5);
5574 }
5575
5576 if (i == attempts) {
5577 return -E1000_ERR_EEPROM;
5578 }
5579 }
5580
Auke Kokcd94dd02006-06-27 09:08:22 -07005581 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5582 /* We're writing to the opposite bank so if we're on bank 1,
5583 * write to bank 0 etc. We also need to erase the segment that
5584 * is going to be written */
5585 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5586 new_bank_offset = hw->flash_bank_size * 2;
5587 old_bank_offset = 0;
5588 e1000_erase_ich8_4k_segment(hw, 1);
5589 } else {
5590 old_bank_offset = hw->flash_bank_size * 2;
5591 new_bank_offset = 0;
5592 e1000_erase_ich8_4k_segment(hw, 0);
5593 }
5594
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005595 sector_write_failed = FALSE;
5596 /* Loop for every byte in the shadow RAM,
5597 * which is in units of words. */
5598 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5599 /* Determine whether to write the value stored
5600 * in the other NVM bank or a modified value stored
5601 * in the shadow RAM */
5602 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5603 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5604 udelay(100);
5605 error = e1000_verify_write_ich8_byte(hw,
5606 (i << 1) + new_bank_offset, low_byte);
5607
5608 if (error != E1000_SUCCESS)
5609 sector_write_failed = TRUE;
5610 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005611 high_byte =
5612 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005613 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005614 }
5615 } else {
5616 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5617 &low_byte);
5618 udelay(100);
5619 error = e1000_verify_write_ich8_byte(hw,
5620 (i << 1) + new_bank_offset, low_byte);
5621
5622 if (error != E1000_SUCCESS)
5623 sector_write_failed = TRUE;
5624 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005625 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5626 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005627 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005628 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005629 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005630
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005631 /* If the write of the low byte was successful, go ahread and
5632 * write the high byte while checking to make sure that if it
5633 * is the signature byte, then it is handled properly */
5634 if (sector_write_failed == FALSE) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005635 /* If the word is 0x13, then make sure the signature bits
5636 * (15:14) are 11b until the commit has completed.
5637 * This will allow us to write 10b which indicates the
5638 * signature is valid. We want to do this after the write
5639 * has completed so that we don't mark the segment valid
5640 * while the write is still in progress */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005641 if (i == E1000_ICH_NVM_SIG_WORD)
5642 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
Auke Kokcd94dd02006-06-27 09:08:22 -07005643
5644 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005645 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005646 if (error != E1000_SUCCESS)
5647 sector_write_failed = TRUE;
5648
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005649 } else {
5650 /* If the write failed then break from the loop and
5651 * return an error */
5652 break;
5653 }
5654 }
5655
5656 /* Don't bother writing the segment valid bits if sector
5657 * programming failed. */
5658 if (sector_write_failed == FALSE) {
5659 /* Finally validate the new segment by setting bit 15:14
5660 * to 10b in word 0x13 , this can be done without an
5661 * erase as well since these bits are 11 to start with
5662 * and we need to change bit 14 to 0b */
5663 e1000_read_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005664 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005665 &high_byte);
5666 high_byte &= 0xBF;
5667 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005668 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005669 /* And invalidate the previously valid segment by setting
5670 * its signature word (0x13) high_byte to 0b. This can be
5671 * done without an erase because flash erase sets all bits
5672 * to 1's. We can write 1's to 0's without an erase */
5673 if (error == E1000_SUCCESS) {
5674 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005675 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005676 }
5677
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005678 /* Clear the now not used entry in the cache */
5679 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5680 hw->eeprom_shadow_ram[i].modified = FALSE;
5681 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005682 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005683 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005684 }
5685
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005686 return error;
5687}
5688
5689/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005690 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5691 * second function of dual function devices
5692 *
5693 * hw - Struct containing variables accessed by shared code
5694 *****************************************************************************/
5695int32_t
5696e1000_read_mac_addr(struct e1000_hw * hw)
5697{
5698 uint16_t offset;
5699 uint16_t eeprom_data, i;
5700
5701 DEBUGFUNC("e1000_read_mac_addr");
5702
Auke Kok8fc897b2006-08-28 14:56:16 -07005703 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005705 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 DEBUGOUT("EEPROM Read Error\n");
5707 return -E1000_ERR_EEPROM;
5708 }
5709 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5710 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5711 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005712
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005713 switch (hw->mac_type) {
5714 default:
5715 break;
5716 case e1000_82546:
5717 case e1000_82546_rev_3:
5718 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005719 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005720 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005722 break;
5723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724
Auke Kok8fc897b2006-08-28 14:56:16 -07005725 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 hw->mac_addr[i] = hw->perm_mac_addr[i];
5727 return E1000_SUCCESS;
5728}
5729
5730/******************************************************************************
5731 * Initializes receive address filters.
5732 *
5733 * hw - Struct containing variables accessed by shared code
5734 *
5735 * Places the MAC address in receive address register 0 and clears the rest
5736 * of the receive addresss registers. Clears the multicast table. Assumes
5737 * the receiver is in reset when the routine is called.
5738 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005739static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740e1000_init_rx_addrs(struct e1000_hw *hw)
5741{
5742 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005743 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005744
5745 DEBUGFUNC("e1000_init_rx_addrs");
5746
5747 /* Setup the receive address. */
5748 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5749
5750 e1000_rar_set(hw, hw->mac_addr, 0);
5751
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005752 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005753
5754 /* Reserve a spot for the Locally Administered Address to work around
5755 * an 82571 issue in which a reset on one port will reload the MAC on
5756 * the other port. */
5757 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5758 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005759 if (hw->mac_type == e1000_ich8lan)
5760 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5761
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762 /* Zero out the other 15 receive addresses. */
5763 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005764 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005766 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005768 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769 }
5770}
5771
5772/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005773 * Hashes an address to determine its location in the multicast table
5774 *
5775 * hw - Struct containing variables accessed by shared code
5776 * mc_addr - the multicast address to hash
5777 *****************************************************************************/
5778uint32_t
5779e1000_hash_mc_addr(struct e1000_hw *hw,
5780 uint8_t *mc_addr)
5781{
5782 uint32_t hash_value = 0;
5783
5784 /* The portion of the address that is used for the hash table is
5785 * determined by the mc_filter_type setting.
5786 */
5787 switch (hw->mc_filter_type) {
5788 /* [0] [1] [2] [3] [4] [5]
5789 * 01 AA 00 12 34 56
5790 * LSB MSB
5791 */
5792 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005793 if (hw->mac_type == e1000_ich8lan) {
5794 /* [47:38] i.e. 0x158 for above example address */
5795 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5796 } else {
5797 /* [47:36] i.e. 0x563 for above example address */
5798 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005800 break;
5801 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005802 if (hw->mac_type == e1000_ich8lan) {
5803 /* [46:37] i.e. 0x2B1 for above example address */
5804 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5805 } else {
5806 /* [46:35] i.e. 0xAC6 for above example address */
5807 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 break;
5810 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005811 if (hw->mac_type == e1000_ich8lan) {
5812 /*[45:36] i.e. 0x163 for above example address */
5813 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5814 } else {
5815 /* [45:34] i.e. 0x5D8 for above example address */
5816 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 break;
5819 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005820 if (hw->mac_type == e1000_ich8lan) {
5821 /* [43:34] i.e. 0x18D for above example address */
5822 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5823 } else {
5824 /* [43:32] i.e. 0x634 for above example address */
5825 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827 break;
5828 }
5829
5830 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005831 if (hw->mac_type == e1000_ich8lan)
5832 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005833
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834 return hash_value;
5835}
5836
5837/******************************************************************************
5838 * Sets the bit in the multicast table corresponding to the hash value.
5839 *
5840 * hw - Struct containing variables accessed by shared code
5841 * hash_value - Multicast address hash value
5842 *****************************************************************************/
5843void
5844e1000_mta_set(struct e1000_hw *hw,
5845 uint32_t hash_value)
5846{
5847 uint32_t hash_bit, hash_reg;
5848 uint32_t mta;
5849 uint32_t temp;
5850
5851 /* The MTA is a register array of 128 32-bit registers.
5852 * It is treated like an array of 4096 bits. We want to set
5853 * bit BitArray[hash_value]. So we figure out what register
5854 * the bit is in, read it, OR in the new bit, then write
5855 * back the new value. The register is determined by the
5856 * upper 7 bits of the hash value and the bit within that
5857 * register are determined by the lower 5 bits of the value.
5858 */
5859 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005860 if (hw->mac_type == e1000_ich8lan)
5861 hash_reg &= 0x1F;
Auke Kok90fb5132006-11-01 08:47:30 -08005862
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863 hash_bit = hash_value & 0x1F;
5864
5865 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5866
5867 mta |= (1 << hash_bit);
5868
5869 /* If we are on an 82544 and we are trying to write an odd offset
5870 * in the MTA, save off the previous entry before writing and
5871 * restore the old value after writing.
5872 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005873 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5875 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005876 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005878 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 } else {
5880 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005881 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882 }
5883}
5884
5885/******************************************************************************
5886 * Puts an ethernet address into a receive address register.
5887 *
5888 * hw - Struct containing variables accessed by shared code
5889 * addr - Address to put into receive address register
5890 * index - Receive address register to write
5891 *****************************************************************************/
5892void
5893e1000_rar_set(struct e1000_hw *hw,
5894 uint8_t *addr,
5895 uint32_t index)
5896{
5897 uint32_t rar_low, rar_high;
5898
5899 /* HW expects these in little endian so we reverse the byte order
5900 * from network order (big endian) to little endian
5901 */
5902 rar_low = ((uint32_t) addr[0] |
5903 ((uint32_t) addr[1] << 8) |
5904 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005905 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005907 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5908 * unit hang.
5909 *
5910 * Description:
5911 * If there are any Rx frames queued up or otherwise present in the HW
5912 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5913 * hang. To work around this issue, we have to disable receives and
5914 * flush out all Rx frames before we enable RSS. To do so, we modify we
5915 * redirect all Rx traffic to manageability and then reset the HW.
5916 * This flushes away Rx frames, and (since the redirections to
5917 * manageability persists across resets) keeps new ones from coming in
5918 * while we work. Then, we clear the Address Valid AV bit for all MAC
5919 * addresses and undo the re-direction to manageability.
5920 * Now, frames are coming in again, but the MAC won't accept them, so
5921 * far so good. We now proceed to initialize RSS (if necessary) and
5922 * configure the Rx unit. Last, we re-enable the AV bits and continue
5923 * on our merry way.
5924 */
5925 switch (hw->mac_type) {
5926 case e1000_82571:
5927 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005928 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005929 if (hw->leave_av_bit_off == TRUE)
5930 break;
5931 default:
5932 /* Indicate to hardware the Address is Valid. */
5933 rar_high |= E1000_RAH_AV;
5934 break;
5935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936
5937 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005938 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005940 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005941}
5942
5943/******************************************************************************
5944 * Writes a value to the specified offset in the VLAN filter table.
5945 *
5946 * hw - Struct containing variables accessed by shared code
5947 * offset - Offset in VLAN filer table to write
5948 * value - Value to write into VLAN filter table
5949 *****************************************************************************/
5950void
5951e1000_write_vfta(struct e1000_hw *hw,
5952 uint32_t offset,
5953 uint32_t value)
5954{
5955 uint32_t temp;
5956
Auke Kokcd94dd02006-06-27 09:08:22 -07005957 if (hw->mac_type == e1000_ich8lan)
5958 return;
5959
5960 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005961 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5962 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005963 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005965 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 } else {
5967 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005968 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 }
5970}
5971
5972/******************************************************************************
5973 * Clears the VLAN filer table
5974 *
5975 * hw - Struct containing variables accessed by shared code
5976 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005977static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978e1000_clear_vfta(struct e1000_hw *hw)
5979{
5980 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005981 uint32_t vfta_value = 0;
5982 uint32_t vfta_offset = 0;
5983 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984
Auke Kokcd94dd02006-06-27 09:08:22 -07005985 if (hw->mac_type == e1000_ich8lan)
5986 return;
5987
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005988 if (hw->mac_type == e1000_82573) {
5989 if (hw->mng_cookie.vlan_id != 0) {
5990 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5991 * ID. The following operations determine which 32b entry
5992 * (i.e. offset) into the array we want to set the VLAN ID
5993 * (i.e. bit) of the manageability unit. */
5994 vfta_offset = (hw->mng_cookie.vlan_id >>
5995 E1000_VFTA_ENTRY_SHIFT) &
5996 E1000_VFTA_ENTRY_MASK;
5997 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5998 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5999 }
6000 }
6001 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
6002 /* If the offset we want to clear is the same offset of the
6003 * manageability VLAN ID, then clear all bits except that of the
6004 * manageability unit */
6005 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6006 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07006007 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009}
6010
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006011static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012e1000_id_led_init(struct e1000_hw * hw)
6013{
6014 uint32_t ledctl;
6015 const uint32_t ledctl_mask = 0x000000FF;
6016 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6017 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6018 uint16_t eeprom_data, i, temp;
6019 const uint16_t led_mask = 0x0F;
6020
6021 DEBUGFUNC("e1000_id_led_init");
6022
Auke Kok8fc897b2006-08-28 14:56:16 -07006023 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 /* Nothing to do */
6025 return E1000_SUCCESS;
6026 }
6027
6028 ledctl = E1000_READ_REG(hw, LEDCTL);
6029 hw->ledctl_default = ledctl;
6030 hw->ledctl_mode1 = hw->ledctl_default;
6031 hw->ledctl_mode2 = hw->ledctl_default;
6032
Auke Kok8fc897b2006-08-28 14:56:16 -07006033 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 DEBUGOUT("EEPROM Read Error\n");
6035 return -E1000_ERR_EEPROM;
6036 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006037
6038 if ((hw->mac_type == e1000_82573) &&
6039 (eeprom_data == ID_LED_RESERVED_82573))
6040 eeprom_data = ID_LED_DEFAULT_82573;
6041 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6042 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6043 if (hw->mac_type == e1000_ich8lan)
6044 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6045 else
6046 eeprom_data = ID_LED_DEFAULT;
6047 }
Auke Kok90fb5132006-11-01 08:47:30 -08006048
Auke Kokcd94dd02006-06-27 09:08:22 -07006049 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006051 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052 case ID_LED_ON1_DEF2:
6053 case ID_LED_ON1_ON2:
6054 case ID_LED_ON1_OFF2:
6055 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6056 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6057 break;
6058 case ID_LED_OFF1_DEF2:
6059 case ID_LED_OFF1_ON2:
6060 case ID_LED_OFF1_OFF2:
6061 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6062 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6063 break;
6064 default:
6065 /* Do nothing */
6066 break;
6067 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006068 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069 case ID_LED_DEF1_ON2:
6070 case ID_LED_ON1_ON2:
6071 case ID_LED_OFF1_ON2:
6072 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6073 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6074 break;
6075 case ID_LED_DEF1_OFF2:
6076 case ID_LED_ON1_OFF2:
6077 case ID_LED_OFF1_OFF2:
6078 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6079 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6080 break;
6081 default:
6082 /* Do nothing */
6083 break;
6084 }
6085 }
6086 return E1000_SUCCESS;
6087}
6088
6089/******************************************************************************
6090 * Prepares SW controlable LED for use and saves the current state of the LED.
6091 *
6092 * hw - Struct containing variables accessed by shared code
6093 *****************************************************************************/
6094int32_t
6095e1000_setup_led(struct e1000_hw *hw)
6096{
6097 uint32_t ledctl;
6098 int32_t ret_val = E1000_SUCCESS;
6099
6100 DEBUGFUNC("e1000_setup_led");
6101
Auke Kok8fc897b2006-08-28 14:56:16 -07006102 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 case e1000_82542_rev2_0:
6104 case e1000_82542_rev2_1:
6105 case e1000_82543:
6106 case e1000_82544:
6107 /* No setup necessary */
6108 break;
6109 case e1000_82541:
6110 case e1000_82547:
6111 case e1000_82541_rev_2:
6112 case e1000_82547_rev_2:
6113 /* Turn off PHY Smart Power Down (if enabled) */
6114 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6115 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006116 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 return ret_val;
6118 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6119 (uint16_t)(hw->phy_spd_default &
6120 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006121 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 return ret_val;
6123 /* Fall Through */
6124 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006125 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 ledctl = E1000_READ_REG(hw, LEDCTL);
6127 /* Save current LEDCTL settings */
6128 hw->ledctl_default = ledctl;
6129 /* Turn off LED0 */
6130 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6131 E1000_LEDCTL_LED0_BLINK |
6132 E1000_LEDCTL_LED0_MODE_MASK);
6133 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6134 E1000_LEDCTL_LED0_MODE_SHIFT);
6135 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006136 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6138 break;
6139 }
6140
6141 return E1000_SUCCESS;
6142}
6143
Auke Kok8fc897b2006-08-28 14:56:16 -07006144
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006146 * Used on 82571 and later Si that has LED blink bits.
6147 * Callers must use their own timer and should have already called
6148 * e1000_id_led_init()
6149 * Call e1000_cleanup led() to stop blinking
6150 *
6151 * hw - Struct containing variables accessed by shared code
6152 *****************************************************************************/
6153int32_t
6154e1000_blink_led_start(struct e1000_hw *hw)
6155{
6156 int16_t i;
6157 uint32_t ledctl_blink = 0;
6158
6159 DEBUGFUNC("e1000_id_led_blink_on");
6160
6161 if (hw->mac_type < e1000_82571) {
6162 /* Nothing to do */
6163 return E1000_SUCCESS;
6164 }
6165 if (hw->media_type == e1000_media_type_fiber) {
6166 /* always blink LED0 for PCI-E fiber */
6167 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6168 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6169 } else {
6170 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6171 ledctl_blink = hw->ledctl_mode2;
6172 for (i=0; i < 4; i++)
6173 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6174 E1000_LEDCTL_MODE_LED_ON)
6175 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6176 }
6177
6178 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6179
6180 return E1000_SUCCESS;
6181}
6182
6183/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 * Restores the saved state of the SW controlable LED.
6185 *
6186 * hw - Struct containing variables accessed by shared code
6187 *****************************************************************************/
6188int32_t
6189e1000_cleanup_led(struct e1000_hw *hw)
6190{
6191 int32_t ret_val = E1000_SUCCESS;
6192
6193 DEBUGFUNC("e1000_cleanup_led");
6194
Auke Kok8fc897b2006-08-28 14:56:16 -07006195 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 case e1000_82542_rev2_0:
6197 case e1000_82542_rev2_1:
6198 case e1000_82543:
6199 case e1000_82544:
6200 /* No cleanup necessary */
6201 break;
6202 case e1000_82541:
6203 case e1000_82547:
6204 case e1000_82541_rev_2:
6205 case e1000_82547_rev_2:
6206 /* Turn on PHY Smart Power Down (if previously enabled) */
6207 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6208 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006209 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 return ret_val;
6211 /* Fall Through */
6212 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006213 if (hw->phy_type == e1000_phy_ife) {
6214 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6215 break;
6216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 /* Restore LEDCTL settings */
6218 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6219 break;
6220 }
6221
6222 return E1000_SUCCESS;
6223}
6224
6225/******************************************************************************
6226 * Turns on the software controllable LED
6227 *
6228 * hw - Struct containing variables accessed by shared code
6229 *****************************************************************************/
6230int32_t
6231e1000_led_on(struct e1000_hw *hw)
6232{
6233 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6234
6235 DEBUGFUNC("e1000_led_on");
6236
Auke Kok8fc897b2006-08-28 14:56:16 -07006237 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 case e1000_82542_rev2_0:
6239 case e1000_82542_rev2_1:
6240 case e1000_82543:
6241 /* Set SW Defineable Pin 0 to turn on the LED */
6242 ctrl |= E1000_CTRL_SWDPIN0;
6243 ctrl |= E1000_CTRL_SWDPIO0;
6244 break;
6245 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006246 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247 /* Set SW Defineable Pin 0 to turn on the LED */
6248 ctrl |= E1000_CTRL_SWDPIN0;
6249 ctrl |= E1000_CTRL_SWDPIO0;
6250 } else {
6251 /* Clear SW Defineable Pin 0 to turn on the LED */
6252 ctrl &= ~E1000_CTRL_SWDPIN0;
6253 ctrl |= E1000_CTRL_SWDPIO0;
6254 }
6255 break;
6256 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006257 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 /* Clear SW Defineable Pin 0 to turn on the LED */
6259 ctrl &= ~E1000_CTRL_SWDPIN0;
6260 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006261 } else if (hw->phy_type == e1000_phy_ife) {
6262 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6263 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6264 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6266 return E1000_SUCCESS;
6267 }
6268 break;
6269 }
6270
6271 E1000_WRITE_REG(hw, CTRL, ctrl);
6272
6273 return E1000_SUCCESS;
6274}
6275
6276/******************************************************************************
6277 * Turns off the software controllable LED
6278 *
6279 * hw - Struct containing variables accessed by shared code
6280 *****************************************************************************/
6281int32_t
6282e1000_led_off(struct e1000_hw *hw)
6283{
6284 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6285
6286 DEBUGFUNC("e1000_led_off");
6287
Auke Kok8fc897b2006-08-28 14:56:16 -07006288 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 case e1000_82542_rev2_0:
6290 case e1000_82542_rev2_1:
6291 case e1000_82543:
6292 /* Clear SW Defineable Pin 0 to turn off the LED */
6293 ctrl &= ~E1000_CTRL_SWDPIN0;
6294 ctrl |= E1000_CTRL_SWDPIO0;
6295 break;
6296 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006297 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 /* Clear SW Defineable Pin 0 to turn off the LED */
6299 ctrl &= ~E1000_CTRL_SWDPIN0;
6300 ctrl |= E1000_CTRL_SWDPIO0;
6301 } else {
6302 /* Set SW Defineable Pin 0 to turn off the LED */
6303 ctrl |= E1000_CTRL_SWDPIN0;
6304 ctrl |= E1000_CTRL_SWDPIO0;
6305 }
6306 break;
6307 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006308 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 /* Set SW Defineable Pin 0 to turn off the LED */
6310 ctrl |= E1000_CTRL_SWDPIN0;
6311 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006312 } else if (hw->phy_type == e1000_phy_ife) {
6313 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6314 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6315 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6317 return E1000_SUCCESS;
6318 }
6319 break;
6320 }
6321
6322 E1000_WRITE_REG(hw, CTRL, ctrl);
6323
6324 return E1000_SUCCESS;
6325}
6326
6327/******************************************************************************
6328 * Clears all hardware statistics counters.
6329 *
6330 * hw - Struct containing variables accessed by shared code
6331 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006332static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333e1000_clear_hw_cntrs(struct e1000_hw *hw)
6334{
6335 volatile uint32_t temp;
6336
6337 temp = E1000_READ_REG(hw, CRCERRS);
6338 temp = E1000_READ_REG(hw, SYMERRS);
6339 temp = E1000_READ_REG(hw, MPC);
6340 temp = E1000_READ_REG(hw, SCC);
6341 temp = E1000_READ_REG(hw, ECOL);
6342 temp = E1000_READ_REG(hw, MCC);
6343 temp = E1000_READ_REG(hw, LATECOL);
6344 temp = E1000_READ_REG(hw, COLC);
6345 temp = E1000_READ_REG(hw, DC);
6346 temp = E1000_READ_REG(hw, SEC);
6347 temp = E1000_READ_REG(hw, RLEC);
6348 temp = E1000_READ_REG(hw, XONRXC);
6349 temp = E1000_READ_REG(hw, XONTXC);
6350 temp = E1000_READ_REG(hw, XOFFRXC);
6351 temp = E1000_READ_REG(hw, XOFFTXC);
6352 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006353
6354 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 temp = E1000_READ_REG(hw, PRC64);
6356 temp = E1000_READ_REG(hw, PRC127);
6357 temp = E1000_READ_REG(hw, PRC255);
6358 temp = E1000_READ_REG(hw, PRC511);
6359 temp = E1000_READ_REG(hw, PRC1023);
6360 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006361 }
6362
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 temp = E1000_READ_REG(hw, GPRC);
6364 temp = E1000_READ_REG(hw, BPRC);
6365 temp = E1000_READ_REG(hw, MPRC);
6366 temp = E1000_READ_REG(hw, GPTC);
6367 temp = E1000_READ_REG(hw, GORCL);
6368 temp = E1000_READ_REG(hw, GORCH);
6369 temp = E1000_READ_REG(hw, GOTCL);
6370 temp = E1000_READ_REG(hw, GOTCH);
6371 temp = E1000_READ_REG(hw, RNBC);
6372 temp = E1000_READ_REG(hw, RUC);
6373 temp = E1000_READ_REG(hw, RFC);
6374 temp = E1000_READ_REG(hw, ROC);
6375 temp = E1000_READ_REG(hw, RJC);
6376 temp = E1000_READ_REG(hw, TORL);
6377 temp = E1000_READ_REG(hw, TORH);
6378 temp = E1000_READ_REG(hw, TOTL);
6379 temp = E1000_READ_REG(hw, TOTH);
6380 temp = E1000_READ_REG(hw, TPR);
6381 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006382
6383 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384 temp = E1000_READ_REG(hw, PTC64);
6385 temp = E1000_READ_REG(hw, PTC127);
6386 temp = E1000_READ_REG(hw, PTC255);
6387 temp = E1000_READ_REG(hw, PTC511);
6388 temp = E1000_READ_REG(hw, PTC1023);
6389 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006390 }
6391
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 temp = E1000_READ_REG(hw, MPTC);
6393 temp = E1000_READ_REG(hw, BPTC);
6394
Auke Kok8fc897b2006-08-28 14:56:16 -07006395 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396
6397 temp = E1000_READ_REG(hw, ALGNERRC);
6398 temp = E1000_READ_REG(hw, RXERRC);
6399 temp = E1000_READ_REG(hw, TNCRS);
6400 temp = E1000_READ_REG(hw, CEXTERR);
6401 temp = E1000_READ_REG(hw, TSCTC);
6402 temp = E1000_READ_REG(hw, TSCTFC);
6403
Auke Kok8fc897b2006-08-28 14:56:16 -07006404 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405
6406 temp = E1000_READ_REG(hw, MGTPRC);
6407 temp = E1000_READ_REG(hw, MGTPDC);
6408 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006409
Auke Kok8fc897b2006-08-28 14:56:16 -07006410 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006411
6412 temp = E1000_READ_REG(hw, IAC);
6413 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006414
6415 if (hw->mac_type == e1000_ich8lan) return;
6416
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006417 temp = E1000_READ_REG(hw, ICRXPTC);
6418 temp = E1000_READ_REG(hw, ICRXATC);
6419 temp = E1000_READ_REG(hw, ICTXPTC);
6420 temp = E1000_READ_REG(hw, ICTXATC);
6421 temp = E1000_READ_REG(hw, ICTXQEC);
6422 temp = E1000_READ_REG(hw, ICTXQMTC);
6423 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424}
6425
6426/******************************************************************************
6427 * Resets Adaptive IFS to its default state.
6428 *
6429 * hw - Struct containing variables accessed by shared code
6430 *
6431 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6432 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6433 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6434 * before calling this function.
6435 *****************************************************************************/
6436void
6437e1000_reset_adaptive(struct e1000_hw *hw)
6438{
6439 DEBUGFUNC("e1000_reset_adaptive");
6440
Auke Kok8fc897b2006-08-28 14:56:16 -07006441 if (hw->adaptive_ifs) {
6442 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 hw->current_ifs_val = 0;
6444 hw->ifs_min_val = IFS_MIN;
6445 hw->ifs_max_val = IFS_MAX;
6446 hw->ifs_step_size = IFS_STEP;
6447 hw->ifs_ratio = IFS_RATIO;
6448 }
6449 hw->in_ifs_mode = FALSE;
6450 E1000_WRITE_REG(hw, AIT, 0);
6451 } else {
6452 DEBUGOUT("Not in Adaptive IFS mode!\n");
6453 }
6454}
6455
6456/******************************************************************************
6457 * Called during the callback/watchdog routine to update IFS value based on
6458 * the ratio of transmits to collisions.
6459 *
6460 * hw - Struct containing variables accessed by shared code
6461 * tx_packets - Number of transmits since last callback
6462 * total_collisions - Number of collisions since last callback
6463 *****************************************************************************/
6464void
6465e1000_update_adaptive(struct e1000_hw *hw)
6466{
6467 DEBUGFUNC("e1000_update_adaptive");
6468
Auke Kok8fc897b2006-08-28 14:56:16 -07006469 if (hw->adaptive_ifs) {
6470 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6471 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006473 if (hw->current_ifs_val < hw->ifs_max_val) {
6474 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 hw->current_ifs_val = hw->ifs_min_val;
6476 else
6477 hw->current_ifs_val += hw->ifs_step_size;
6478 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6479 }
6480 }
6481 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006482 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 hw->current_ifs_val = 0;
6484 hw->in_ifs_mode = FALSE;
6485 E1000_WRITE_REG(hw, AIT, 0);
6486 }
6487 }
6488 } else {
6489 DEBUGOUT("Not in Adaptive IFS mode!\n");
6490 }
6491}
6492
6493/******************************************************************************
6494 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6495 *
6496 * hw - Struct containing variables accessed by shared code
6497 * frame_len - The length of the frame in question
6498 * mac_addr - The Ethernet destination address of the frame in question
6499 *****************************************************************************/
6500void
6501e1000_tbi_adjust_stats(struct e1000_hw *hw,
6502 struct e1000_hw_stats *stats,
6503 uint32_t frame_len,
6504 uint8_t *mac_addr)
6505{
6506 uint64_t carry_bit;
6507
6508 /* First adjust the frame length. */
6509 frame_len--;
6510 /* We need to adjust the statistics counters, since the hardware
6511 * counters overcount this packet as a CRC error and undercount
6512 * the packet as a good packet
6513 */
6514 /* This packet should not be counted as a CRC error. */
6515 stats->crcerrs--;
6516 /* This packet does count as a Good Packet Received. */
6517 stats->gprc++;
6518
6519 /* Adjust the Good Octets received counters */
6520 carry_bit = 0x80000000 & stats->gorcl;
6521 stats->gorcl += frame_len;
6522 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6523 * Received Count) was one before the addition,
6524 * AND it is zero after, then we lost the carry out,
6525 * need to add one to Gorch (Good Octets Received Count High).
6526 * This could be simplified if all environments supported
6527 * 64-bit integers.
6528 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006529 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 stats->gorch++;
6531 /* Is this a broadcast or multicast? Check broadcast first,
6532 * since the test for a multicast frame will test positive on
6533 * a broadcast frame.
6534 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006535 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 /* Broadcast packet */
6537 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006538 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 /* Multicast packet */
6540 stats->mprc++;
6541
Auke Kok8fc897b2006-08-28 14:56:16 -07006542 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 /* In this case, the hardware has overcounted the number of
6544 * oversize frames.
6545 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006546 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 stats->roc--;
6548 }
6549
6550 /* Adjust the bin counters when the extra byte put the frame in the
6551 * wrong bin. Remember that the frame_len was adjusted above.
6552 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006553 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 stats->prc64++;
6555 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006556 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557 stats->prc127++;
6558 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006559 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560 stats->prc255++;
6561 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006562 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 stats->prc511++;
6564 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006565 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 stats->prc1023++;
6567 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006568 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 stats->prc1522++;
6570 }
6571}
6572
6573/******************************************************************************
6574 * Gets the current PCI bus type, speed, and width of the hardware
6575 *
6576 * hw - Struct containing variables accessed by shared code
6577 *****************************************************************************/
6578void
6579e1000_get_bus_info(struct e1000_hw *hw)
6580{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006581 int32_t ret_val;
6582 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 uint32_t status;
6584
6585 switch (hw->mac_type) {
6586 case e1000_82542_rev2_0:
6587 case e1000_82542_rev2_1:
6588 hw->bus_type = e1000_bus_type_unknown;
6589 hw->bus_speed = e1000_bus_speed_unknown;
6590 hw->bus_width = e1000_bus_width_unknown;
6591 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006592 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006593 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006594 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006595 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006596 hw->bus_type = e1000_bus_type_pci_express;
6597 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006598 ret_val = e1000_read_pcie_cap_reg(hw,
6599 PCI_EX_LINK_STATUS,
6600 &pci_ex_link_status);
6601 if (ret_val)
6602 hw->bus_width = e1000_bus_width_unknown;
6603 else
6604 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6605 PCI_EX_LINK_WIDTH_SHIFT;
6606 break;
6607 case e1000_ich8lan:
6608 hw->bus_type = e1000_bus_type_pci_express;
6609 hw->bus_speed = e1000_bus_speed_2500;
6610 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006611 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612 default:
6613 status = E1000_READ_REG(hw, STATUS);
6614 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6615 e1000_bus_type_pcix : e1000_bus_type_pci;
6616
Auke Kok8fc897b2006-08-28 14:56:16 -07006617 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6619 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006620 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6622 e1000_bus_speed_66 : e1000_bus_speed_33;
6623 } else {
6624 switch (status & E1000_STATUS_PCIX_SPEED) {
6625 case E1000_STATUS_PCIX_SPEED_66:
6626 hw->bus_speed = e1000_bus_speed_66;
6627 break;
6628 case E1000_STATUS_PCIX_SPEED_100:
6629 hw->bus_speed = e1000_bus_speed_100;
6630 break;
6631 case E1000_STATUS_PCIX_SPEED_133:
6632 hw->bus_speed = e1000_bus_speed_133;
6633 break;
6634 default:
6635 hw->bus_speed = e1000_bus_speed_reserved;
6636 break;
6637 }
6638 }
6639 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6640 e1000_bus_width_64 : e1000_bus_width_32;
6641 break;
6642 }
6643}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644
6645/******************************************************************************
6646 * Writes a value to one of the devices registers using port I/O (as opposed to
6647 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6648 *
6649 * hw - Struct containing variables accessed by shared code
6650 * offset - offset to write to
6651 * value - value to write
6652 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006653static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654e1000_write_reg_io(struct e1000_hw *hw,
6655 uint32_t offset,
6656 uint32_t value)
6657{
6658 unsigned long io_addr = hw->io_base;
6659 unsigned long io_data = hw->io_base + 4;
6660
6661 e1000_io_write(hw, io_addr, offset);
6662 e1000_io_write(hw, io_data, value);
6663}
6664
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665/******************************************************************************
6666 * Estimates the cable length.
6667 *
6668 * hw - Struct containing variables accessed by shared code
6669 * min_length - The estimated minimum length
6670 * max_length - The estimated maximum length
6671 *
6672 * returns: - E1000_ERR_XXX
6673 * E1000_SUCCESS
6674 *
6675 * This function always returns a ranged length (minimum & maximum).
6676 * So for M88 phy's, this function interprets the one value returned from the
6677 * register to the minimum and maximum range.
6678 * For IGP phy's, the function calculates the range by the AGC registers.
6679 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006680static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681e1000_get_cable_length(struct e1000_hw *hw,
6682 uint16_t *min_length,
6683 uint16_t *max_length)
6684{
6685 int32_t ret_val;
6686 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 uint16_t i, phy_data;
6688 uint16_t cable_length;
6689
6690 DEBUGFUNC("e1000_get_cable_length");
6691
6692 *min_length = *max_length = 0;
6693
6694 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006695 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006696
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6698 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006699 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700 return ret_val;
6701 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6702 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6703
6704 /* Convert the enum value to ranged values */
6705 switch (cable_length) {
6706 case e1000_cable_length_50:
6707 *min_length = 0;
6708 *max_length = e1000_igp_cable_length_50;
6709 break;
6710 case e1000_cable_length_50_80:
6711 *min_length = e1000_igp_cable_length_50;
6712 *max_length = e1000_igp_cable_length_80;
6713 break;
6714 case e1000_cable_length_80_110:
6715 *min_length = e1000_igp_cable_length_80;
6716 *max_length = e1000_igp_cable_length_110;
6717 break;
6718 case e1000_cable_length_110_140:
6719 *min_length = e1000_igp_cable_length_110;
6720 *max_length = e1000_igp_cable_length_140;
6721 break;
6722 case e1000_cable_length_140:
6723 *min_length = e1000_igp_cable_length_140;
6724 *max_length = e1000_igp_cable_length_170;
6725 break;
6726 default:
6727 return -E1000_ERR_PHY;
6728 break;
6729 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006730 } else if (hw->phy_type == e1000_phy_gg82563) {
6731 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6732 &phy_data);
6733 if (ret_val)
6734 return ret_val;
6735 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6736
6737 switch (cable_length) {
6738 case e1000_gg_cable_length_60:
6739 *min_length = 0;
6740 *max_length = e1000_igp_cable_length_60;
6741 break;
6742 case e1000_gg_cable_length_60_115:
6743 *min_length = e1000_igp_cable_length_60;
6744 *max_length = e1000_igp_cable_length_115;
6745 break;
6746 case e1000_gg_cable_length_115_150:
6747 *min_length = e1000_igp_cable_length_115;
6748 *max_length = e1000_igp_cable_length_150;
6749 break;
6750 case e1000_gg_cable_length_150:
6751 *min_length = e1000_igp_cable_length_150;
6752 *max_length = e1000_igp_cable_length_180;
6753 break;
6754 default:
6755 return -E1000_ERR_PHY;
6756 break;
6757 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006758 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006759 uint16_t cur_agc_value;
6760 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6762 {IGP01E1000_PHY_AGC_A,
6763 IGP01E1000_PHY_AGC_B,
6764 IGP01E1000_PHY_AGC_C,
6765 IGP01E1000_PHY_AGC_D};
6766 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006767 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768
6769 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006770 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 return ret_val;
6772
Auke Kokcd94dd02006-06-27 09:08:22 -07006773 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774
Auke Kokcd94dd02006-06-27 09:08:22 -07006775 /* Value bound check. */
6776 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6777 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 return -E1000_ERR_PHY;
6779
Auke Kokcd94dd02006-06-27 09:08:22 -07006780 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781
6782 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006783 if (min_agc_value > cur_agc_value)
6784 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 }
6786
6787 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006788 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6789 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790
6791 /* Get the average length of the remaining 3 channels */
6792 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6793 } else {
6794 /* Get the average length of all the 4 channels. */
6795 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6796 }
6797
6798 /* Set the range of the calculated length. */
6799 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6800 IGP01E1000_AGC_RANGE) > 0) ?
6801 (e1000_igp_cable_length_table[agc_value] -
6802 IGP01E1000_AGC_RANGE) : 0;
6803 *max_length = e1000_igp_cable_length_table[agc_value] +
6804 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006805 } else if (hw->phy_type == e1000_phy_igp_2 ||
6806 hw->phy_type == e1000_phy_igp_3) {
6807 uint16_t cur_agc_index, max_agc_index = 0;
6808 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006809 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6810 {IGP02E1000_PHY_AGC_A,
6811 IGP02E1000_PHY_AGC_B,
6812 IGP02E1000_PHY_AGC_C,
6813 IGP02E1000_PHY_AGC_D};
6814 /* Read the AGC registers for all channels */
6815 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6816 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6817 if (ret_val)
6818 return ret_val;
6819
Auke Kok8fc897b2006-08-28 14:56:16 -07006820 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006821 * fine gain values. The result is a number that can be put into
6822 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006823 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6824 IGP02E1000_AGC_LENGTH_MASK;
6825
6826 /* Array index bound check. */
6827 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6828 (cur_agc_index == 0))
6829 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006830
6831 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006832 if (e1000_igp_2_cable_length_table[min_agc_index] >
6833 e1000_igp_2_cable_length_table[cur_agc_index])
6834 min_agc_index = cur_agc_index;
6835 if (e1000_igp_2_cable_length_table[max_agc_index] <
6836 e1000_igp_2_cable_length_table[cur_agc_index])
6837 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006838
Auke Kokcd94dd02006-06-27 09:08:22 -07006839 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006840 }
6841
Auke Kokcd94dd02006-06-27 09:08:22 -07006842 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6843 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006844 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6845
6846 /* Calculate cable length with the error range of +/- 10 meters. */
6847 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6848 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6849 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850 }
6851
6852 return E1000_SUCCESS;
6853}
6854
6855/******************************************************************************
6856 * Check the cable polarity
6857 *
6858 * hw - Struct containing variables accessed by shared code
6859 * polarity - output parameter : 0 - Polarity is not reversed
6860 * 1 - Polarity is reversed.
6861 *
6862 * returns: - E1000_ERR_XXX
6863 * E1000_SUCCESS
6864 *
6865 * For phy's older then IGP, this function simply reads the polarity bit in the
6866 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6867 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6868 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6869 * IGP01E1000_PHY_PCS_INIT_REG.
6870 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006871static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006873 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874{
6875 int32_t ret_val;
6876 uint16_t phy_data;
6877
6878 DEBUGFUNC("e1000_check_polarity");
6879
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006880 if ((hw->phy_type == e1000_phy_m88) ||
6881 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882 /* return the Polarity bit in the Status register. */
6883 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_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;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006887 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6888 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6889 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6890
Auke Kokcd94dd02006-06-27 09:08:22 -07006891 } else if (hw->phy_type == e1000_phy_igp ||
6892 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006893 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894 /* Read the Status register to check the speed */
6895 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6896 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006897 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898 return ret_val;
6899
6900 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6901 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006902 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903 IGP01E1000_PSSR_SPEED_1000MBPS) {
6904
6905 /* Read the GIG initialization PCS register (0x00B4) */
6906 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6907 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006908 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006909 return ret_val;
6910
6911 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006912 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6913 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006914 } else {
6915 /* For 10 Mbps, read the polarity bit in the status register. (for
6916 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006917 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6918 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006920 } else if (hw->phy_type == e1000_phy_ife) {
6921 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6922 &phy_data);
6923 if (ret_val)
6924 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006925 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6926 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6927 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928 }
6929 return E1000_SUCCESS;
6930}
6931
6932/******************************************************************************
6933 * Check if Downshift occured
6934 *
6935 * hw - Struct containing variables accessed by shared code
6936 * downshift - output parameter : 0 - No Downshift ocured.
6937 * 1 - Downshift ocured.
6938 *
6939 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006940 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941 *
6942 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6943 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6944 * Link Health register. In IGP this bit is latched high, so the driver must
6945 * read it immediately after link is established.
6946 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006947static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006948e1000_check_downshift(struct e1000_hw *hw)
6949{
6950 int32_t ret_val;
6951 uint16_t phy_data;
6952
6953 DEBUGFUNC("e1000_check_downshift");
6954
Auke Kokcd94dd02006-06-27 09:08:22 -07006955 if (hw->phy_type == e1000_phy_igp ||
6956 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006957 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006958 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6959 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006960 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961 return ret_val;
6962
6963 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006964 } else if ((hw->phy_type == e1000_phy_m88) ||
6965 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6967 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006968 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006969 return ret_val;
6970
6971 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6972 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006973 } else if (hw->phy_type == e1000_phy_ife) {
6974 /* e1000_phy_ife supports 10/100 speed only */
6975 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006977
Linus Torvalds1da177e2005-04-16 15:20:36 -07006978 return E1000_SUCCESS;
6979}
6980
6981/*****************************************************************************
6982 *
6983 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6984 * gigabit link is achieved to improve link quality.
6985 *
6986 * hw: Struct containing variables accessed by shared code
6987 *
6988 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6989 * E1000_SUCCESS at any other case.
6990 *
6991 ****************************************************************************/
6992
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006993static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006994e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6995 boolean_t link_up)
6996{
6997 int32_t ret_val;
6998 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6999 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
7000 {IGP01E1000_PHY_AGC_PARAM_A,
7001 IGP01E1000_PHY_AGC_PARAM_B,
7002 IGP01E1000_PHY_AGC_PARAM_C,
7003 IGP01E1000_PHY_AGC_PARAM_D};
7004 uint16_t min_length, max_length;
7005
7006 DEBUGFUNC("e1000_config_dsp_after_link_change");
7007
Auke Kok8fc897b2006-08-28 14:56:16 -07007008 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007009 return E1000_SUCCESS;
7010
Auke Kok8fc897b2006-08-28 14:56:16 -07007011 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007012 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07007013 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007014 DEBUGOUT("Error getting link speed and duplex\n");
7015 return ret_val;
7016 }
7017
Auke Kok8fc897b2006-08-28 14:56:16 -07007018 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007019
Auke Kokcd94dd02006-06-27 09:08:22 -07007020 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7021 if (ret_val)
7022 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023
Auke Kok8fc897b2006-08-28 14:56:16 -07007024 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007025 min_length >= e1000_igp_cable_length_50) {
7026
Auke Kok8fc897b2006-08-28 14:56:16 -07007027 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007028 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7029 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007030 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031 return ret_val;
7032
7033 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7034
7035 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7036 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007037 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038 return ret_val;
7039 }
7040 hw->dsp_config_state = e1000_dsp_config_activated;
7041 }
7042
Auke Kok8fc897b2006-08-28 14:56:16 -07007043 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007044 (min_length < e1000_igp_cable_length_50)) {
7045
7046 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7047 uint32_t idle_errs = 0;
7048
7049 /* clear previous idle error counts */
7050 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7051 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007052 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 return ret_val;
7054
Auke Kok8fc897b2006-08-28 14:56:16 -07007055 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056 udelay(1000);
7057 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7058 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007059 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007060 return ret_val;
7061
7062 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007063 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 hw->ffe_config_state = e1000_ffe_config_active;
7065
7066 ret_val = e1000_write_phy_reg(hw,
7067 IGP01E1000_PHY_DSP_FFE,
7068 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007069 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007070 return ret_val;
7071 break;
7072 }
7073
Auke Kok8fc897b2006-08-28 14:56:16 -07007074 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7076 }
7077 }
7078 }
7079 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007080 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007081 /* Save off the current value of register 0x2F5B to be restored at
7082 * the end of the routines. */
7083 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7084
Auke Kok8fc897b2006-08-28 14:56:16 -07007085 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086 return ret_val;
7087
7088 /* Disable the PHY transmitter */
7089 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7090
Auke Kok8fc897b2006-08-28 14:56:16 -07007091 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092 return ret_val;
7093
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007094 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095
7096 ret_val = e1000_write_phy_reg(hw, 0x0000,
7097 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007098 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007100 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007101 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007102 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007103 return ret_val;
7104
7105 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7106 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7107
7108 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007109 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110 return ret_val;
7111 }
7112
7113 ret_val = e1000_write_phy_reg(hw, 0x0000,
7114 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007115 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007116 return ret_val;
7117
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007118 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007119
7120 /* Now enable the transmitter */
7121 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7122
Auke Kok8fc897b2006-08-28 14:56:16 -07007123 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007124 return ret_val;
7125
7126 hw->dsp_config_state = e1000_dsp_config_enabled;
7127 }
7128
Auke Kok8fc897b2006-08-28 14:56:16 -07007129 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007130 /* Save off the current value of register 0x2F5B to be restored at
7131 * the end of the routines. */
7132 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7133
Auke Kok8fc897b2006-08-28 14:56:16 -07007134 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007135 return ret_val;
7136
7137 /* Disable the PHY transmitter */
7138 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7139
Auke Kok8fc897b2006-08-28 14:56:16 -07007140 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007141 return ret_val;
7142
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007143 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007144
7145 ret_val = e1000_write_phy_reg(hw, 0x0000,
7146 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007147 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007148 return ret_val;
7149 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7150 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007151 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007152 return ret_val;
7153
7154 ret_val = e1000_write_phy_reg(hw, 0x0000,
7155 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007156 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007157 return ret_val;
7158
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007159 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007160
7161 /* Now enable the transmitter */
7162 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7163
Auke Kok8fc897b2006-08-28 14:56:16 -07007164 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007165 return ret_val;
7166
7167 hw->ffe_config_state = e1000_ffe_config_enabled;
7168 }
7169 }
7170 return E1000_SUCCESS;
7171}
7172
7173/*****************************************************************************
7174 * Set PHY to class A mode
7175 * Assumes the following operations will follow to enable the new class mode.
7176 * 1. Do a PHY soft reset
7177 * 2. Restart auto-negotiation or force link.
7178 *
7179 * hw - Struct containing variables accessed by shared code
7180 ****************************************************************************/
7181static int32_t
7182e1000_set_phy_mode(struct e1000_hw *hw)
7183{
7184 int32_t ret_val;
7185 uint16_t eeprom_data;
7186
7187 DEBUGFUNC("e1000_set_phy_mode");
7188
Auke Kok8fc897b2006-08-28 14:56:16 -07007189 if ((hw->mac_type == e1000_82545_rev_3) &&
7190 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007192 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007193 return ret_val;
7194 }
7195
Auke Kok8fc897b2006-08-28 14:56:16 -07007196 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7197 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007199 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007200 return ret_val;
7201 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007202 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007203 return ret_val;
7204
7205 hw->phy_reset_disable = FALSE;
7206 }
7207 }
7208
7209 return E1000_SUCCESS;
7210}
7211
7212/*****************************************************************************
7213 *
7214 * This function sets the lplu state according to the active flag. When
7215 * activating lplu this function also disables smart speed and vise versa.
7216 * lplu will not be activated unless the device autonegotiation advertisment
7217 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7218 * hw: Struct containing variables accessed by shared code
7219 * active - true to enable lplu false to disable lplu.
7220 *
7221 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7222 * E1000_SUCCESS at any other case.
7223 *
7224 ****************************************************************************/
7225
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007226static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007227e1000_set_d3_lplu_state(struct e1000_hw *hw,
7228 boolean_t active)
7229{
Auke Kokcd94dd02006-06-27 09:08:22 -07007230 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007231 int32_t ret_val;
7232 uint16_t phy_data;
7233 DEBUGFUNC("e1000_set_d3_lplu_state");
7234
Auke Kokcd94dd02006-06-27 09:08:22 -07007235 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7236 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007237 return E1000_SUCCESS;
7238
7239 /* During driver activity LPLU should not be used or it will attain link
7240 * from the lowest speeds starting from 10Mbps. The capability is used for
7241 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007242 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007243 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007244 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007245 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007246 } else if (hw->mac_type == e1000_ich8lan) {
7247 /* MAC writes into PHY register based on the state transition
7248 * and start auto-negotiation. SW driver can overwrite the settings
7249 * in CSR PHY power control E1000_PHY_CTRL register. */
7250 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007251 } else {
7252 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007253 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007254 return ret_val;
7255 }
7256
Auke Kok8fc897b2006-08-28 14:56:16 -07007257 if (!active) {
7258 if (hw->mac_type == e1000_82541_rev_2 ||
7259 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007260 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7261 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007262 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007263 return ret_val;
7264 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007265 if (hw->mac_type == e1000_ich8lan) {
7266 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7267 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7268 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007269 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7270 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7271 phy_data);
7272 if (ret_val)
7273 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007274 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007276
7277 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7278 * Dx states where the power conservation is most important. During
7279 * driver activity we should enable SmartSpeed, so performance is
7280 * maintained. */
7281 if (hw->smart_speed == e1000_smart_speed_on) {
7282 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7283 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007284 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007285 return ret_val;
7286
7287 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7288 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7289 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007290 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291 return ret_val;
7292 } else if (hw->smart_speed == e1000_smart_speed_off) {
7293 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7294 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007295 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007296 return ret_val;
7297
7298 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7299 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7300 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007301 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007302 return ret_val;
7303 }
7304
Auke Kok8fc897b2006-08-28 14:56:16 -07007305 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7306 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7307 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007308
Auke Kok8fc897b2006-08-28 14:56:16 -07007309 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007310 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007311 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7312 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007313 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007314 return ret_val;
7315 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007316 if (hw->mac_type == e1000_ich8lan) {
7317 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7318 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7319 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007320 phy_data |= IGP02E1000_PM_D3_LPLU;
7321 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7322 phy_data);
7323 if (ret_val)
7324 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007325 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007326 }
7327
7328 /* When LPLU is enabled we should disable SmartSpeed */
7329 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007330 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007331 return ret_val;
7332
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007333 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7334 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007335 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007336 return ret_val;
7337
7338 }
7339 return E1000_SUCCESS;
7340}
7341
7342/*****************************************************************************
7343 *
7344 * This function sets the lplu d0 state according to the active flag. When
7345 * activating lplu this function also disables smart speed and vise versa.
7346 * lplu will not be activated unless the device autonegotiation advertisment
7347 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7348 * hw: Struct containing variables accessed by shared code
7349 * active - true to enable lplu false to disable lplu.
7350 *
7351 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7352 * E1000_SUCCESS at any other case.
7353 *
7354 ****************************************************************************/
7355
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007356static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007357e1000_set_d0_lplu_state(struct e1000_hw *hw,
7358 boolean_t active)
7359{
Auke Kokcd94dd02006-06-27 09:08:22 -07007360 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007361 int32_t ret_val;
7362 uint16_t phy_data;
7363 DEBUGFUNC("e1000_set_d0_lplu_state");
7364
Auke Kok8fc897b2006-08-28 14:56:16 -07007365 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007366 return E1000_SUCCESS;
7367
Auke Kokcd94dd02006-06-27 09:08:22 -07007368 if (hw->mac_type == e1000_ich8lan) {
7369 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7370 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007371 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007372 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007373 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007374 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007375
7376 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007377 if (hw->mac_type == e1000_ich8lan) {
7378 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7379 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7380 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007381 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7382 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7383 if (ret_val)
7384 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007385 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007386
7387 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7388 * Dx states where the power conservation is most important. During
7389 * driver activity we should enable SmartSpeed, so performance is
7390 * maintained. */
7391 if (hw->smart_speed == e1000_smart_speed_on) {
7392 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7393 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007394 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007395 return ret_val;
7396
7397 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7398 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7399 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007400 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007401 return ret_val;
7402 } else if (hw->smart_speed == e1000_smart_speed_off) {
7403 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7404 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007405 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007406 return ret_val;
7407
7408 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7409 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7410 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007411 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007412 return ret_val;
7413 }
7414
7415
7416 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007417
Auke Kokcd94dd02006-06-27 09:08:22 -07007418 if (hw->mac_type == e1000_ich8lan) {
7419 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7420 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7421 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007422 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007423 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7424 if (ret_val)
7425 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007426 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007427
Linus Torvalds1da177e2005-04-16 15:20:36 -07007428 /* When LPLU is enabled we should disable SmartSpeed */
7429 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007430 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007431 return ret_val;
7432
7433 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7434 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007435 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007436 return ret_val;
7437
7438 }
7439 return E1000_SUCCESS;
7440}
7441
7442/******************************************************************************
7443 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7444 *
7445 * hw - Struct containing variables accessed by shared code
7446 *****************************************************************************/
7447static int32_t
7448e1000_set_vco_speed(struct e1000_hw *hw)
7449{
7450 int32_t ret_val;
7451 uint16_t default_page = 0;
7452 uint16_t phy_data;
7453
7454 DEBUGFUNC("e1000_set_vco_speed");
7455
Auke Kok8fc897b2006-08-28 14:56:16 -07007456 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457 case e1000_82545_rev_3:
7458 case e1000_82546_rev_3:
7459 break;
7460 default:
7461 return E1000_SUCCESS;
7462 }
7463
7464 /* Set PHY register 30, page 5, bit 8 to 0 */
7465
7466 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007467 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007468 return ret_val;
7469
7470 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007471 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007472 return ret_val;
7473
7474 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007475 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007476 return ret_val;
7477
7478 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7479 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007480 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007481 return ret_val;
7482
7483 /* Set PHY register 30, page 4, bit 11 to 1 */
7484
7485 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007486 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007487 return ret_val;
7488
7489 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007490 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007491 return ret_val;
7492
7493 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7494 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007495 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007496 return ret_val;
7497
7498 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007499 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007500 return ret_val;
7501
7502 return E1000_SUCCESS;
7503}
7504
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007505
7506/*****************************************************************************
7507 * This function reads the cookie from ARC ram.
7508 *
7509 * returns: - E1000_SUCCESS .
7510 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007511static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007512e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7513{
7514 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007515 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007516 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7517
7518 length = (length >> 2);
7519 offset = (offset >> 2);
7520
7521 for (i = 0; i < length; i++) {
7522 *((uint32_t *) buffer + i) =
7523 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7524 }
7525 return E1000_SUCCESS;
7526}
7527
7528
7529/*****************************************************************************
7530 * This function checks whether the HOST IF is enabled for command operaton
7531 * and also checks whether the previous command is completed.
7532 * It busy waits in case of previous command is not completed.
7533 *
Auke Kok76c224b2006-05-23 13:36:06 -07007534 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007535 * timeout
7536 * - E1000_SUCCESS for success.
7537 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007538static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007539e1000_mng_enable_host_if(struct e1000_hw * hw)
7540{
7541 uint32_t hicr;
7542 uint8_t i;
7543
7544 /* Check that the host interface is enabled. */
7545 hicr = E1000_READ_REG(hw, HICR);
7546 if ((hicr & E1000_HICR_EN) == 0) {
7547 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7548 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7549 }
7550 /* check the previous command is completed */
7551 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7552 hicr = E1000_READ_REG(hw, HICR);
7553 if (!(hicr & E1000_HICR_C))
7554 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007555 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007556 }
7557
Auke Kok76c224b2006-05-23 13:36:06 -07007558 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007559 DEBUGOUT("Previous command timeout failed .\n");
7560 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7561 }
7562 return E1000_SUCCESS;
7563}
7564
7565/*****************************************************************************
7566 * This function writes the buffer content at the offset given on the host if.
7567 * It also does alignment considerations to do the writes in most efficient way.
7568 * Also fills up the sum of the buffer in *buffer parameter.
7569 *
7570 * returns - E1000_SUCCESS for success.
7571 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007572static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007573e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7574 uint16_t length, uint16_t offset, uint8_t *sum)
7575{
7576 uint8_t *tmp;
7577 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007578 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007579 uint16_t remaining, i, j, prev_bytes;
7580
7581 /* sum = only sum of the data and it is not checksum */
7582
7583 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7584 return -E1000_ERR_PARAM;
7585 }
7586
7587 tmp = (uint8_t *)&data;
7588 prev_bytes = offset & 0x3;
7589 offset &= 0xFFFC;
7590 offset >>= 2;
7591
7592 if (prev_bytes) {
7593 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7594 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7595 *(tmp + j) = *bufptr++;
7596 *sum += *(tmp + j);
7597 }
7598 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7599 length -= j - prev_bytes;
7600 offset++;
7601 }
7602
7603 remaining = length & 0x3;
7604 length -= remaining;
7605
7606 /* Calculate length in DWORDs */
7607 length >>= 2;
7608
7609 /* The device driver writes the relevant command block into the
7610 * ram area. */
7611 for (i = 0; i < length; i++) {
7612 for (j = 0; j < sizeof(uint32_t); j++) {
7613 *(tmp + j) = *bufptr++;
7614 *sum += *(tmp + j);
7615 }
7616
7617 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7618 }
7619 if (remaining) {
7620 for (j = 0; j < sizeof(uint32_t); j++) {
7621 if (j < remaining)
7622 *(tmp + j) = *bufptr++;
7623 else
7624 *(tmp + j) = 0;
7625
7626 *sum += *(tmp + j);
7627 }
7628 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7629 }
7630
7631 return E1000_SUCCESS;
7632}
7633
7634
7635/*****************************************************************************
7636 * This function writes the command header after does the checksum calculation.
7637 *
7638 * returns - E1000_SUCCESS for success.
7639 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007640static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007641e1000_mng_write_cmd_header(struct e1000_hw * hw,
7642 struct e1000_host_mng_command_header * hdr)
7643{
7644 uint16_t i;
7645 uint8_t sum;
7646 uint8_t *buffer;
7647
7648 /* Write the whole command header structure which includes sum of
7649 * the buffer */
7650
7651 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7652
7653 sum = hdr->checksum;
7654 hdr->checksum = 0;
7655
7656 buffer = (uint8_t *) hdr;
7657 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007658 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007659 sum += buffer[i];
7660
7661 hdr->checksum = 0 - sum;
7662
7663 length >>= 2;
7664 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007665 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007666 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007667 E1000_WRITE_FLUSH(hw);
7668 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007669
7670 return E1000_SUCCESS;
7671}
7672
7673
7674/*****************************************************************************
7675 * This function indicates to ARC that a new command is pending which completes
7676 * one write operation by the driver.
7677 *
7678 * returns - E1000_SUCCESS for success.
7679 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007680static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007681e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007682{
7683 uint32_t hicr;
7684
7685 hicr = E1000_READ_REG(hw, HICR);
7686 /* Setting this bit tells the ARC that a new command is pending. */
7687 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7688
7689 return E1000_SUCCESS;
7690}
7691
7692
7693/*****************************************************************************
7694 * This function checks the mode of the firmware.
7695 *
7696 * returns - TRUE when the mode is IAMT or FALSE.
7697 ****************************************************************************/
7698boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007699e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007700{
7701 uint32_t fwsm;
7702
7703 fwsm = E1000_READ_REG(hw, FWSM);
7704
Auke Kokcd94dd02006-06-27 09:08:22 -07007705 if (hw->mac_type == e1000_ich8lan) {
7706 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7707 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7708 return TRUE;
7709 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7710 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007711 return TRUE;
7712
7713 return FALSE;
7714}
7715
7716
7717/*****************************************************************************
7718 * This function writes the dhcp info .
7719 ****************************************************************************/
7720int32_t
7721e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007722 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007723{
7724 int32_t ret_val;
7725 struct e1000_host_mng_command_header hdr;
7726
7727 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7728 hdr.command_length = length;
7729 hdr.reserved1 = 0;
7730 hdr.reserved2 = 0;
7731 hdr.checksum = 0;
7732
7733 ret_val = e1000_mng_enable_host_if(hw);
7734 if (ret_val == E1000_SUCCESS) {
7735 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7736 &(hdr.checksum));
7737 if (ret_val == E1000_SUCCESS) {
7738 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7739 if (ret_val == E1000_SUCCESS)
7740 ret_val = e1000_mng_write_commit(hw);
7741 }
7742 }
7743 return ret_val;
7744}
7745
7746
7747/*****************************************************************************
7748 * This function calculates the checksum.
7749 *
7750 * returns - checksum of buffer contents.
7751 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007752static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007753e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7754{
7755 uint8_t sum = 0;
7756 uint32_t i;
7757
7758 if (!buffer)
7759 return 0;
7760
7761 for (i=0; i < length; i++)
7762 sum += buffer[i];
7763
7764 return (uint8_t) (0 - sum);
7765}
7766
7767/*****************************************************************************
7768 * This function checks whether tx pkt filtering needs to be enabled or not.
7769 *
7770 * returns - TRUE for packet filtering or FALSE.
7771 ****************************************************************************/
7772boolean_t
7773e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7774{
7775 /* called in init as well as watchdog timer functions */
7776
7777 int32_t ret_val, checksum;
7778 boolean_t tx_filter = FALSE;
7779 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7780 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7781
7782 if (e1000_check_mng_mode(hw)) {
7783 ret_val = e1000_mng_enable_host_if(hw);
7784 if (ret_val == E1000_SUCCESS) {
7785 ret_val = e1000_host_if_read_cookie(hw, buffer);
7786 if (ret_val == E1000_SUCCESS) {
7787 checksum = hdr->checksum;
7788 hdr->checksum = 0;
7789 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7790 checksum == e1000_calculate_mng_checksum((char *)buffer,
7791 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7792 if (hdr->status &
7793 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7794 tx_filter = TRUE;
7795 } else
7796 tx_filter = TRUE;
7797 } else
7798 tx_filter = TRUE;
7799 }
7800 }
7801
7802 hw->tx_pkt_filtering = tx_filter;
7803 return tx_filter;
7804}
7805
7806/******************************************************************************
7807 * Verifies the hardware needs to allow ARPs to be processed by the host
7808 *
7809 * hw - Struct containing variables accessed by shared code
7810 *
7811 * returns: - TRUE/FALSE
7812 *
7813 *****************************************************************************/
7814uint32_t
7815e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7816{
7817 uint32_t manc;
7818 uint32_t fwsm, factps;
7819
7820 if (hw->asf_firmware_present) {
7821 manc = E1000_READ_REG(hw, MANC);
7822
7823 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7824 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7825 return FALSE;
7826 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7827 fwsm = E1000_READ_REG(hw, FWSM);
7828 factps = E1000_READ_REG(hw, FACTPS);
7829
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05007830 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7831 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007832 return TRUE;
7833 } else
7834 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7835 return TRUE;
7836 }
7837 return FALSE;
7838}
7839
Linus Torvalds1da177e2005-04-16 15:20:36 -07007840static int32_t
7841e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7842{
7843 int32_t ret_val;
7844 uint16_t mii_status_reg;
7845 uint16_t i;
7846
7847 /* Polarity reversal workaround for forced 10F/10H links. */
7848
7849 /* Disable the transmitter on the PHY */
7850
7851 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007852 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007853 return ret_val;
7854 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007855 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007856 return ret_val;
7857
7858 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007859 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007860 return ret_val;
7861
7862 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007863 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007864 /* Read the MII Status Register and wait for Link Status bit
7865 * to be clear.
7866 */
7867
7868 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007869 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007870 return ret_val;
7871
7872 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007873 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007874 return ret_val;
7875
Auke Kok8fc897b2006-08-28 14:56:16 -07007876 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007877 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007878 }
7879
7880 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007881 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007882
7883 /* Now we will re-enable th transmitter on the PHY */
7884
7885 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007886 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007887 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007888 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007889 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007890 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007891 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007892 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007893 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007894 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007895 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007896 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007897 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007898 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007899 return ret_val;
7900
7901 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007902 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007903 return ret_val;
7904
7905 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007906 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007907 /* Read the MII Status Register and wait for Link Status bit
7908 * to be set.
7909 */
7910
7911 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007912 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007913 return ret_val;
7914
7915 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007916 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007917 return ret_val;
7918
Auke Kok8fc897b2006-08-28 14:56:16 -07007919 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007920 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007921 }
7922 return E1000_SUCCESS;
7923}
7924
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007925/***************************************************************************
7926 *
7927 * Disables PCI-Express master access.
7928 *
7929 * hw: Struct containing variables accessed by shared code
7930 *
7931 * returns: - none.
7932 *
7933 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007934static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007935e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7936{
7937 uint32_t ctrl;
7938
7939 DEBUGFUNC("e1000_set_pci_express_master_disable");
7940
7941 if (hw->bus_type != e1000_bus_type_pci_express)
7942 return;
7943
7944 ctrl = E1000_READ_REG(hw, CTRL);
7945 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7946 E1000_WRITE_REG(hw, CTRL, ctrl);
7947}
7948
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007949/*******************************************************************************
7950 *
7951 * Disables PCI-Express master access and verifies there are no pending requests
7952 *
7953 * hw: Struct containing variables accessed by shared code
7954 *
7955 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7956 * caused the master requests to be disabled.
7957 * E1000_SUCCESS master requests disabled.
7958 *
7959 ******************************************************************************/
7960int32_t
7961e1000_disable_pciex_master(struct e1000_hw *hw)
7962{
7963 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7964
7965 DEBUGFUNC("e1000_disable_pciex_master");
7966
7967 if (hw->bus_type != e1000_bus_type_pci_express)
7968 return E1000_SUCCESS;
7969
7970 e1000_set_pci_express_master_disable(hw);
7971
Auke Kok8fc897b2006-08-28 14:56:16 -07007972 while (timeout) {
7973 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007974 break;
7975 else
7976 udelay(100);
7977 timeout--;
7978 }
7979
Auke Kok8fc897b2006-08-28 14:56:16 -07007980 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007981 DEBUGOUT("Master requests are pending.\n");
7982 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7983 }
7984
7985 return E1000_SUCCESS;
7986}
7987
7988/*******************************************************************************
7989 *
7990 * Check for EEPROM Auto Read bit done.
7991 *
7992 * hw: Struct containing variables accessed by shared code
7993 *
7994 * returns: - E1000_ERR_RESET if fail to reset MAC
7995 * E1000_SUCCESS at any other case.
7996 *
7997 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007998static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007999e1000_get_auto_rd_done(struct e1000_hw *hw)
8000{
8001 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8002
8003 DEBUGFUNC("e1000_get_auto_rd_done");
8004
8005 switch (hw->mac_type) {
8006 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008007 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008008 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008009 case e1000_82571:
8010 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008011 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008012 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008013 case e1000_ich8lan:
8014 while (timeout) {
8015 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8016 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008017 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008018 timeout--;
8019 }
8020
Auke Kok8fc897b2006-08-28 14:56:16 -07008021 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008022 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8023 return -E1000_ERR_RESET;
8024 }
8025 break;
8026 }
8027
Jeff Kirsherfd803242005-12-13 00:06:22 -05008028 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8029 * Need to wait for PHY configuration completion before accessing NVM
8030 * and PHY. */
8031 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008032 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008033
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008034 return E1000_SUCCESS;
8035}
8036
8037/***************************************************************************
8038 * Checks if the PHY configuration is done
8039 *
8040 * hw: Struct containing variables accessed by shared code
8041 *
8042 * returns: - E1000_ERR_RESET if fail to reset MAC
8043 * E1000_SUCCESS at any other case.
8044 *
8045 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008046static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008047e1000_get_phy_cfg_done(struct e1000_hw *hw)
8048{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008049 int32_t timeout = PHY_CFG_TIMEOUT;
8050 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8051
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008052 DEBUGFUNC("e1000_get_phy_cfg_done");
8053
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008054 switch (hw->mac_type) {
8055 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008056 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008057 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008058 case e1000_80003es2lan:
8059 /* Separate *_CFG_DONE_* bit for each port */
8060 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8061 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8062 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008063 case e1000_82571:
8064 case e1000_82572:
8065 while (timeout) {
8066 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8067 break;
8068 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008069 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008070 timeout--;
8071 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008072 if (!timeout) {
8073 DEBUGOUT("MNG configuration cycle has not completed.\n");
8074 return -E1000_ERR_RESET;
8075 }
8076 break;
8077 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008078
8079 return E1000_SUCCESS;
8080}
8081
8082/***************************************************************************
8083 *
8084 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8085 * adapter or Eeprom access.
8086 *
8087 * hw: Struct containing variables accessed by shared code
8088 *
8089 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8090 * E1000_SUCCESS at any other case.
8091 *
8092 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008093static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008094e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8095{
8096 int32_t timeout;
8097 uint32_t swsm;
8098
8099 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8100
Auke Kok8fc897b2006-08-28 14:56:16 -07008101 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008102 return E1000_SUCCESS;
8103
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008104 if (hw->mac_type == e1000_80003es2lan) {
8105 /* Get the SW semaphore. */
8106 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8107 return -E1000_ERR_EEPROM;
8108 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008109
8110 /* Get the FW semaphore. */
8111 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008112 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008113 swsm = E1000_READ_REG(hw, SWSM);
8114 swsm |= E1000_SWSM_SWESMBI;
8115 E1000_WRITE_REG(hw, SWSM, swsm);
8116 /* if we managed to set the bit we got the semaphore. */
8117 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008118 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008119 break;
8120
8121 udelay(50);
8122 timeout--;
8123 }
8124
Auke Kok8fc897b2006-08-28 14:56:16 -07008125 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008126 /* Release semaphores */
8127 e1000_put_hw_eeprom_semaphore(hw);
8128 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8129 return -E1000_ERR_EEPROM;
8130 }
8131
8132 return E1000_SUCCESS;
8133}
8134
8135/***************************************************************************
8136 * This function clears HW semaphore bits.
8137 *
8138 * hw: Struct containing variables accessed by shared code
8139 *
8140 * returns: - None.
8141 *
8142 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008143static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008144e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8145{
8146 uint32_t swsm;
8147
8148 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8149
Auke Kok8fc897b2006-08-28 14:56:16 -07008150 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008151 return;
8152
8153 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008154 if (hw->mac_type == e1000_80003es2lan) {
8155 /* Release both semaphores. */
8156 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8157 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008158 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008159 E1000_WRITE_REG(hw, SWSM, swsm);
8160}
8161
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008162/***************************************************************************
8163 *
8164 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8165 *
8166 * hw: Struct containing variables accessed by shared code
8167 *
8168 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8169 * E1000_SUCCESS at any other case.
8170 *
8171 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008172static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008173e1000_get_software_semaphore(struct e1000_hw *hw)
8174{
8175 int32_t timeout = hw->eeprom.word_size + 1;
8176 uint32_t swsm;
8177
8178 DEBUGFUNC("e1000_get_software_semaphore");
8179
Nicholas Nunley35574762006-09-27 12:53:34 -07008180 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008181 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008182 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008183
Auke Kok8fc897b2006-08-28 14:56:16 -07008184 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008185 swsm = E1000_READ_REG(hw, SWSM);
8186 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008187 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008188 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008189 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008190 timeout--;
8191 }
8192
Auke Kok8fc897b2006-08-28 14:56:16 -07008193 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008194 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8195 return -E1000_ERR_RESET;
8196 }
8197
8198 return E1000_SUCCESS;
8199}
8200
8201/***************************************************************************
8202 *
8203 * Release semaphore bit (SMBI).
8204 *
8205 * hw: Struct containing variables accessed by shared code
8206 *
8207 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008208static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008209e1000_release_software_semaphore(struct e1000_hw *hw)
8210{
8211 uint32_t swsm;
8212
8213 DEBUGFUNC("e1000_release_software_semaphore");
8214
Nicholas Nunley35574762006-09-27 12:53:34 -07008215 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008216 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008217 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008218
8219 swsm = E1000_READ_REG(hw, SWSM);
8220 /* Release the SW semaphores.*/
8221 swsm &= ~E1000_SWSM_SMBI;
8222 E1000_WRITE_REG(hw, SWSM, swsm);
8223}
8224
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008225/******************************************************************************
8226 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8227 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8228 * the caller to figure out how to deal with it.
8229 *
8230 * hw - Struct containing variables accessed by shared code
8231 *
8232 * returns: - E1000_BLK_PHY_RESET
8233 * E1000_SUCCESS
8234 *
8235 *****************************************************************************/
8236int32_t
8237e1000_check_phy_reset_block(struct e1000_hw *hw)
8238{
8239 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008240 uint32_t fwsm = 0;
8241
8242 if (hw->mac_type == e1000_ich8lan) {
8243 fwsm = E1000_READ_REG(hw, FWSM);
8244 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8245 : E1000_BLK_PHY_RESET;
8246 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008247
8248 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008249 manc = E1000_READ_REG(hw, MANC);
8250 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008251 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008252}
8253
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008254static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008255e1000_arc_subsystem_valid(struct e1000_hw *hw)
8256{
8257 uint32_t fwsm;
8258
8259 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8260 * may not be provided a DMA clock when no manageability features are
8261 * enabled. We do not want to perform any reads/writes to these registers
8262 * if this is the case. We read FWSM to determine the manageability mode.
8263 */
8264 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008265 case e1000_82571:
8266 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008267 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008268 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008269 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008270 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008271 return TRUE;
8272 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008273 case e1000_ich8lan:
8274 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008275 default:
8276 break;
8277 }
8278 return FALSE;
8279}
8280
8281
Auke Kokd37ea5d2006-06-27 09:08:17 -07008282/******************************************************************************
8283 * Configure PCI-Ex no-snoop
8284 *
8285 * hw - Struct containing variables accessed by shared code.
8286 * no_snoop - Bitmap of no-snoop events.
8287 *
8288 * returns: E1000_SUCCESS
8289 *
8290 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008291static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008292e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8293{
8294 uint32_t gcr_reg = 0;
8295
8296 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8297
8298 if (hw->bus_type == e1000_bus_type_unknown)
8299 e1000_get_bus_info(hw);
8300
8301 if (hw->bus_type != e1000_bus_type_pci_express)
8302 return E1000_SUCCESS;
8303
8304 if (no_snoop) {
8305 gcr_reg = E1000_READ_REG(hw, GCR);
8306 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8307 gcr_reg |= no_snoop;
8308 E1000_WRITE_REG(hw, GCR, gcr_reg);
8309 }
8310 if (hw->mac_type == e1000_ich8lan) {
8311 uint32_t ctrl_ext;
8312
8313 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8314
8315 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8316 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8317 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8318 }
8319
8320 return E1000_SUCCESS;
8321}
8322
8323/***************************************************************************
8324 *
8325 * Get software semaphore FLAG bit (SWFLAG).
8326 * SWFLAG is used to synchronize the access to all shared resource between
8327 * SW, FW and HW.
8328 *
8329 * hw: Struct containing variables accessed by shared code
8330 *
8331 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008332static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008333e1000_get_software_flag(struct e1000_hw *hw)
8334{
8335 int32_t timeout = PHY_CFG_TIMEOUT;
8336 uint32_t extcnf_ctrl;
8337
8338 DEBUGFUNC("e1000_get_software_flag");
8339
8340 if (hw->mac_type == e1000_ich8lan) {
8341 while (timeout) {
8342 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8343 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8344 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8345
8346 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8347 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8348 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008349 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008350 timeout--;
8351 }
8352
8353 if (!timeout) {
8354 DEBUGOUT("FW or HW locks the resource too long.\n");
8355 return -E1000_ERR_CONFIG;
8356 }
8357 }
8358
8359 return E1000_SUCCESS;
8360}
8361
8362/***************************************************************************
8363 *
8364 * Release software semaphore FLAG bit (SWFLAG).
8365 * SWFLAG is used to synchronize the access to all shared resource between
8366 * SW, FW and HW.
8367 *
8368 * hw: Struct containing variables accessed by shared code
8369 *
8370 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008371static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008372e1000_release_software_flag(struct e1000_hw *hw)
8373{
8374 uint32_t extcnf_ctrl;
8375
8376 DEBUGFUNC("e1000_release_software_flag");
8377
8378 if (hw->mac_type == e1000_ich8lan) {
8379 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8380 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8381 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8382 }
8383
8384 return;
8385}
8386
Auke Kokd37ea5d2006-06-27 09:08:17 -07008387/******************************************************************************
8388 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8389 * register.
8390 *
8391 * hw - Struct containing variables accessed by shared code
8392 * offset - offset of word in the EEPROM to read
8393 * data - word read from the EEPROM
8394 * words - number of words to read
8395 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008396static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008397e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8398 uint16_t *data)
8399{
8400 int32_t error = E1000_SUCCESS;
8401 uint32_t flash_bank = 0;
8402 uint32_t act_offset = 0;
8403 uint32_t bank_offset = 0;
8404 uint16_t word = 0;
8405 uint16_t i = 0;
8406
8407 /* We need to know which is the valid flash bank. In the event
8408 * that we didn't allocate eeprom_shadow_ram, we may not be
8409 * managing flash_bank. So it cannot be trusted and needs
8410 * to be updated with each read.
8411 */
8412 /* Value of bit 22 corresponds to the flash bank we're on. */
8413 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8414
8415 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8416 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8417
8418 error = e1000_get_software_flag(hw);
8419 if (error != E1000_SUCCESS)
8420 return error;
8421
8422 for (i = 0; i < words; i++) {
8423 if (hw->eeprom_shadow_ram != NULL &&
8424 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8425 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8426 } else {
8427 /* The NVM part needs a byte offset, hence * 2 */
8428 act_offset = bank_offset + ((offset + i) * 2);
8429 error = e1000_read_ich8_word(hw, act_offset, &word);
8430 if (error != E1000_SUCCESS)
8431 break;
8432 data[i] = word;
8433 }
8434 }
8435
8436 e1000_release_software_flag(hw);
8437
8438 return error;
8439}
8440
8441/******************************************************************************
8442 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8443 * register. Actually, writes are written to the shadow ram cache in the hw
8444 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8445 * the NVM, which occurs when the NVM checksum is updated.
8446 *
8447 * hw - Struct containing variables accessed by shared code
8448 * offset - offset of word in the EEPROM to write
8449 * words - number of words to write
8450 * data - words to write to the EEPROM
8451 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008452static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008453e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8454 uint16_t *data)
8455{
8456 uint32_t i = 0;
8457 int32_t error = E1000_SUCCESS;
8458
8459 error = e1000_get_software_flag(hw);
8460 if (error != E1000_SUCCESS)
8461 return error;
8462
8463 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8464 * allocated. Subsequent reads to the modified words are read from
8465 * this cached structure as well. Writes will only go into this
8466 * cached structure unless it's followed by a call to
8467 * e1000_update_eeprom_checksum() where it will commit the changes
8468 * and clear the "modified" field.
8469 */
8470 if (hw->eeprom_shadow_ram != NULL) {
8471 for (i = 0; i < words; i++) {
8472 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8473 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8474 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8475 } else {
8476 error = -E1000_ERR_EEPROM;
8477 break;
8478 }
8479 }
8480 } else {
8481 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8482 * as they don't perform any NVM writes. An attempt in doing so
8483 * will result in this error.
8484 */
8485 error = -E1000_ERR_EEPROM;
8486 }
8487
8488 e1000_release_software_flag(hw);
8489
8490 return error;
8491}
8492
8493/******************************************************************************
8494 * This function does initial flash setup so that a new read/write/erase cycle
8495 * can be started.
8496 *
8497 * hw - The pointer to the hw structure
8498 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008499static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008500e1000_ich8_cycle_init(struct e1000_hw *hw)
8501{
8502 union ich8_hws_flash_status hsfsts;
8503 int32_t error = E1000_ERR_EEPROM;
8504 int32_t i = 0;
8505
8506 DEBUGFUNC("e1000_ich8_cycle_init");
8507
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008508 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008509
8510 /* May be check the Flash Des Valid bit in Hw status */
8511 if (hsfsts.hsf_status.fldesvalid == 0) {
8512 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8513 return error;
8514 }
8515
8516 /* Clear FCERR in Hw status by writing 1 */
8517 /* Clear DAEL in Hw status by writing a 1 */
8518 hsfsts.hsf_status.flcerr = 1;
8519 hsfsts.hsf_status.dael = 1;
8520
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008521 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008522
8523 /* Either we should have a hardware SPI cycle in progress bit to check
8524 * against, in order to start a new cycle or FDONE bit should be changed
8525 * in the hardware so that it is 1 after harware reset, which can then be
8526 * used as an indication whether a cycle is in progress or has been
8527 * completed .. we should also have some software semaphore mechanism to
8528 * guard FDONE or the cycle in progress bit so that two threads access to
8529 * those bits can be sequentiallized or a way so that 2 threads dont
8530 * start the cycle at the same time */
8531
8532 if (hsfsts.hsf_status.flcinprog == 0) {
8533 /* There is no cycle running at present, so we can start a cycle */
8534 /* Begin by setting Flash Cycle Done. */
8535 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008536 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008537 error = E1000_SUCCESS;
8538 } else {
8539 /* otherwise poll for sometime so the current cycle has a chance
8540 * to end before giving up. */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008541 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8542 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008543 if (hsfsts.hsf_status.flcinprog == 0) {
8544 error = E1000_SUCCESS;
8545 break;
8546 }
8547 udelay(1);
8548 }
8549 if (error == E1000_SUCCESS) {
8550 /* Successful in waiting for previous cycle to timeout,
8551 * now set the Flash Cycle Done. */
8552 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008553 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008554 } else {
8555 DEBUGOUT("Flash controller busy, cannot get access");
8556 }
8557 }
8558 return error;
8559}
8560
8561/******************************************************************************
8562 * This function starts a flash cycle and waits for its completion
8563 *
8564 * hw - The pointer to the hw structure
8565 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008566static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008567e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8568{
8569 union ich8_hws_flash_ctrl hsflctl;
8570 union ich8_hws_flash_status hsfsts;
8571 int32_t error = E1000_ERR_EEPROM;
8572 uint32_t i = 0;
8573
8574 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008575 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008576 hsflctl.hsf_ctrl.flcgo = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008577 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008578
8579 /* wait till FDONE bit is set to 1 */
8580 do {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008581 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008582 if (hsfsts.hsf_status.flcdone == 1)
8583 break;
8584 udelay(1);
8585 i++;
8586 } while (i < timeout);
8587 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8588 error = E1000_SUCCESS;
8589 }
8590 return error;
8591}
8592
8593/******************************************************************************
8594 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8595 *
8596 * hw - The pointer to the hw structure
8597 * index - The index of the byte or word to read.
8598 * size - Size of data to read, 1=byte 2=word
8599 * data - Pointer to the word to store the value read.
8600 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008601static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008602e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8603 uint32_t size, uint16_t* data)
8604{
8605 union ich8_hws_flash_status hsfsts;
8606 union ich8_hws_flash_ctrl hsflctl;
8607 uint32_t flash_linear_address;
8608 uint32_t flash_data = 0;
8609 int32_t error = -E1000_ERR_EEPROM;
8610 int32_t count = 0;
8611
8612 DEBUGFUNC("e1000_read_ich8_data");
8613
8614 if (size < 1 || size > 2 || data == 0x0 ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008615 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008616 return error;
8617
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008618 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008619 hw->flash_base_addr;
8620
8621 do {
8622 udelay(1);
8623 /* Steps */
8624 error = e1000_ich8_cycle_init(hw);
8625 if (error != E1000_SUCCESS)
8626 break;
8627
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008628 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008629 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8630 hsflctl.hsf_ctrl.fldbcount = size - 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008631 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8632 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008633
8634 /* Write the last 24 bits of index into Flash Linear address field in
8635 * Flash Address */
8636 /* TODO: TBD maybe check the index against the size of flash */
8637
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008638 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008639
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008640 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008641
8642 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8643 * sequence a few more times, else read in (shift in) the Flash Data0,
8644 * the order is least significant byte first msb to lsb */
8645 if (error == E1000_SUCCESS) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008646 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008647 if (size == 1) {
8648 *data = (uint8_t)(flash_data & 0x000000FF);
8649 } else if (size == 2) {
8650 *data = (uint16_t)(flash_data & 0x0000FFFF);
8651 }
8652 break;
8653 } else {
8654 /* If we've gotten here, then things are probably completely hosed,
8655 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008656 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008657 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008658 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008659 if (hsfsts.hsf_status.flcerr == 1) {
8660 /* Repeat for some time before giving up. */
8661 continue;
8662 } else if (hsfsts.hsf_status.flcdone == 0) {
8663 DEBUGOUT("Timeout error - flash cycle did not complete.");
8664 break;
8665 }
8666 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008667 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008668
8669 return error;
8670}
8671
8672/******************************************************************************
8673 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8674 *
8675 * hw - The pointer to the hw structure
8676 * index - The index of the byte/word to read.
8677 * size - Size of data to read, 1=byte 2=word
8678 * data - The byte(s) to write to the NVM.
8679 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008680static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008681e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8682 uint16_t data)
8683{
8684 union ich8_hws_flash_status hsfsts;
8685 union ich8_hws_flash_ctrl hsflctl;
8686 uint32_t flash_linear_address;
8687 uint32_t flash_data = 0;
8688 int32_t error = -E1000_ERR_EEPROM;
8689 int32_t count = 0;
8690
8691 DEBUGFUNC("e1000_write_ich8_data");
8692
8693 if (size < 1 || size > 2 || data > size * 0xff ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008694 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008695 return error;
8696
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008697 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008698 hw->flash_base_addr;
8699
8700 do {
8701 udelay(1);
8702 /* Steps */
8703 error = e1000_ich8_cycle_init(hw);
8704 if (error != E1000_SUCCESS)
8705 break;
8706
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008707 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008708 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8709 hsflctl.hsf_ctrl.fldbcount = size -1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008710 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8711 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008712
8713 /* Write the last 24 bits of index into Flash Linear address field in
8714 * Flash Address */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008715 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008716
8717 if (size == 1)
8718 flash_data = (uint32_t)data & 0x00FF;
8719 else
8720 flash_data = (uint32_t)data;
8721
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008722 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008723
8724 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8725 * sequence a few more times else done */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008726 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008727 if (error == E1000_SUCCESS) {
8728 break;
8729 } else {
8730 /* If we're here, then things are most likely completely hosed,
8731 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008732 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008733 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008734 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008735 if (hsfsts.hsf_status.flcerr == 1) {
8736 /* Repeat for some time before giving up. */
8737 continue;
8738 } else if (hsfsts.hsf_status.flcdone == 0) {
8739 DEBUGOUT("Timeout error - flash cycle did not complete.");
8740 break;
8741 }
8742 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008743 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008744
8745 return error;
8746}
8747
8748/******************************************************************************
8749 * Reads a single byte from the NVM using the ICH8 flash access registers.
8750 *
8751 * hw - pointer to e1000_hw structure
8752 * index - The index of the byte to read.
8753 * data - Pointer to a byte to store the value read.
8754 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008755static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008756e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8757{
8758 int32_t status = E1000_SUCCESS;
8759 uint16_t word = 0;
8760
8761 status = e1000_read_ich8_data(hw, index, 1, &word);
8762 if (status == E1000_SUCCESS) {
8763 *data = (uint8_t)word;
8764 }
8765
8766 return status;
8767}
8768
8769/******************************************************************************
8770 * Writes a single byte to the NVM using the ICH8 flash access registers.
8771 * Performs verification by reading back the value and then going through
8772 * a retry algorithm before giving up.
8773 *
8774 * hw - pointer to e1000_hw structure
8775 * index - The index of the byte to write.
8776 * byte - The byte to write to the NVM.
8777 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008778static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008779e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8780{
8781 int32_t error = E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008782 int32_t program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008783
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008784 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008785
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008786 error = e1000_write_ich8_byte(hw, index, byte);
8787
8788 if (error != E1000_SUCCESS) {
8789 for (program_retries = 0; program_retries < 100; program_retries++) {
8790 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8791 error = e1000_write_ich8_byte(hw, index, byte);
8792 udelay(100);
8793 if (error == E1000_SUCCESS)
8794 break;
8795 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008796 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008797
Auke Kokd37ea5d2006-06-27 09:08:17 -07008798 if (program_retries == 100)
8799 error = E1000_ERR_EEPROM;
8800
8801 return error;
8802}
8803
8804/******************************************************************************
8805 * Writes a single byte to the NVM using the ICH8 flash access registers.
8806 *
8807 * hw - pointer to e1000_hw structure
8808 * index - The index of the byte to read.
8809 * data - The byte to write to the NVM.
8810 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008811static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008812e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8813{
8814 int32_t status = E1000_SUCCESS;
8815 uint16_t word = (uint16_t)data;
8816
8817 status = e1000_write_ich8_data(hw, index, 1, word);
8818
8819 return status;
8820}
8821
8822/******************************************************************************
8823 * Reads a word from the NVM using the ICH8 flash access registers.
8824 *
8825 * hw - pointer to e1000_hw structure
8826 * index - The starting byte index of the word to read.
8827 * data - Pointer to a word to store the value read.
8828 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008829static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008830e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8831{
8832 int32_t status = E1000_SUCCESS;
8833 status = e1000_read_ich8_data(hw, index, 2, data);
8834 return status;
8835}
8836
8837/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008838 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8839 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008840 *
8841 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008842 * bank - 0 for first bank, 1 for second bank
8843 *
8844 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8845 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8846 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008847 *****************************************************************************/
8848int32_t
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008849e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008850{
8851 union ich8_hws_flash_status hsfsts;
8852 union ich8_hws_flash_ctrl hsflctl;
8853 uint32_t flash_linear_address;
8854 int32_t count = 0;
8855 int32_t error = E1000_ERR_EEPROM;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008856 int32_t iteration;
8857 int32_t sub_sector_size = 0;
8858 int32_t bank_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008859 int32_t j = 0;
8860 int32_t error_flag = 0;
8861
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008862 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008863
8864 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8865 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8866 * consecutive sectors. The start index for the nth Hw sector can be
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008867 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008868 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8869 * The start index for the nth Hw sector can be calculated
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008870 * as bank * 4096
8871 * 10: The HW sector is 8K bytes
8872 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008873 if (hsfsts.hsf_status.berasesz == 0x0) {
8874 /* Hw sector size 256 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008875 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8876 bank_size = ICH_FLASH_SECTOR_SIZE;
8877 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008878 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008879 bank_size = ICH_FLASH_SEG_SIZE_4K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008880 iteration = 1;
8881 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008882 bank_size = ICH_FLASH_SEG_SIZE_64K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008883 iteration = 1;
8884 } else {
8885 return error;
8886 }
8887
8888 for (j = 0; j < iteration ; j++) {
8889 do {
8890 count++;
8891 /* Steps */
8892 error = e1000_ich8_cycle_init(hw);
8893 if (error != E1000_SUCCESS) {
8894 error_flag = 1;
8895 break;
8896 }
8897
8898 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8899 * Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008900 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8901 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8902 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008903
8904 /* Write the last 24 bits of an index within the block into Flash
8905 * Linear address field in Flash Address. This probably needs to
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008906 * be calculated here based off the on-chip erase sector size and
8907 * the software bank size (4, 8 or 64 KBytes) */
8908 flash_linear_address = bank * bank_size + j * sub_sector_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008909 flash_linear_address += hw->flash_base_addr;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008910 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008911
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008912 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008913
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008914 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008915 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8916 * sequence a few more times else Done */
8917 if (error == E1000_SUCCESS) {
8918 break;
8919 } else {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008920 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008921 if (hsfsts.hsf_status.flcerr == 1) {
8922 /* repeat for some time before giving up */
8923 continue;
8924 } else if (hsfsts.hsf_status.flcdone == 0) {
8925 error_flag = 1;
8926 break;
8927 }
8928 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008929 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008930 if (error_flag == 1)
8931 break;
8932 }
8933 if (error_flag != 1)
8934 error = E1000_SUCCESS;
8935 return error;
8936}
8937
Adrian Bunke4c780b2006-08-14 23:00:10 -07008938static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008939e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8940 uint32_t cnf_base_addr, uint32_t cnf_size)
8941{
8942 uint32_t ret_val = E1000_SUCCESS;
8943 uint16_t word_addr, reg_data, reg_addr;
8944 uint16_t i;
8945
8946 /* cnf_base_addr is in DWORD */
8947 word_addr = (uint16_t)(cnf_base_addr << 1);
8948
8949 /* cnf_size is returned in size of dwords */
8950 for (i = 0; i < cnf_size; i++) {
8951 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8952 if (ret_val)
8953 return ret_val;
8954
8955 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8956 if (ret_val)
8957 return ret_val;
8958
8959 ret_val = e1000_get_software_flag(hw);
8960 if (ret_val != E1000_SUCCESS)
8961 return ret_val;
8962
8963 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8964
8965 e1000_release_software_flag(hw);
8966 }
8967
8968 return ret_val;
8969}
8970
8971
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008972/******************************************************************************
8973 * This function initializes the PHY from the NVM on ICH8 platforms. This
8974 * is needed due to an issue where the NVM configuration is not properly
8975 * autoloaded after power transitions. Therefore, after each PHY reset, we
8976 * will load the configuration data out of the NVM manually.
8977 *
8978 * hw: Struct containing variables accessed by shared code
8979 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008980static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008981e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8982{
8983 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8984
8985 if (hw->phy_type != e1000_phy_igp_3)
8986 return E1000_SUCCESS;
8987
8988 /* Check if SW needs configure the PHY */
8989 reg_data = E1000_READ_REG(hw, FEXTNVM);
8990 if (!(reg_data & FEXTNVM_SW_CONFIG))
8991 return E1000_SUCCESS;
8992
8993 /* Wait for basic configuration completes before proceeding*/
8994 loop = 0;
8995 do {
8996 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8997 udelay(100);
8998 loop++;
8999 } while ((!reg_data) && (loop < 50));
9000
9001 /* Clear the Init Done bit for the next init event */
9002 reg_data = E1000_READ_REG(hw, STATUS);
9003 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9004 E1000_WRITE_REG(hw, STATUS, reg_data);
9005
9006 /* Make sure HW does not configure LCD from PHY extended configuration
9007 before SW configuration */
9008 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9009 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9010 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9011 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9012 cnf_size >>= 16;
9013 if (cnf_size) {
9014 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9015 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9016 /* cnf_base_addr is in DWORD */
9017 cnf_base_addr >>= 16;
9018
9019 /* Configure LCD from extended configuration region. */
9020 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9021 cnf_size);
9022 if (ret_val)
9023 return ret_val;
9024 }
9025 }
9026
9027 return E1000_SUCCESS;
9028}
9029