This source file includes following definitions.
- em_set_phy_type
- em_phy_init_script
- em_set_mac_type
- em_set_media_type
- em_reset_hw
- em_initialize_hardware_bits
- em_init_hw
- em_adjust_serdes_amplitude
- em_setup_link
- em_setup_fiber_serdes_link
- em_copper_link_preconfig
- em_copper_link_igp_setup
- em_copper_link_ggp_setup
- em_copper_link_mgp_setup
- em_copper_link_autoneg
- em_copper_link_postconfig
- em_setup_copper_link
- em_configure_kmrn_for_10_100
- em_configure_kmrn_for_1000
- em_phy_setup_autoneg
- em_phy_force_speed_duplex
- em_config_collision_dist
- em_config_mac_to_phy
- em_force_mac_fc
- em_config_fc_after_link_up
- em_check_for_link
- em_get_speed_and_duplex
- em_wait_autoneg
- em_raise_mdi_clk
- em_lower_mdi_clk
- em_shift_out_mdi_bits
- em_shift_in_mdi_bits
- em_swfw_sync_acquire
- em_swfw_sync_release
- em_read_phy_reg
- em_read_phy_reg_ex
- em_write_phy_reg
- em_write_phy_reg_ex
- em_read_kmrn_reg
- em_write_kmrn_reg
- em_phy_hw_reset
- em_phy_reset
- em_kumeran_lock_loss_workaround
- em_detect_gig_phy
- em_phy_reset_dsp
- em_init_eeprom_params
- em_raise_ee_clk
- em_lower_ee_clk
- em_shift_out_ee_bits
- em_shift_in_ee_bits
- em_acquire_eeprom
- em_standby_eeprom
- em_release_eeprom
- em_spi_eeprom_ready
- em_read_eeprom
- em_read_eeprom_eerd
- em_write_eeprom_eewr
- em_poll_eerd_eewr_done
- em_is_onboard_nvm_eeprom
- em_validate_eeprom_checksum
- em_update_eeprom_checksum
- em_write_eeprom
- em_write_eeprom_spi
- em_write_eeprom_microwire
- em_commit_shadow_ram
- em_read_part_num
- em_read_mac_addr
- em_init_rx_addrs
- em_mc_addr_list_update
- em_hash_mc_addr
- em_mta_set
- em_rar_set
- em_clear_vfta
- em_id_led_init
- em_clear_hw_cntrs
- em_tbi_adjust_stats
- em_get_bus_info
- em_write_reg_io
- em_get_cable_length
- em_check_downshift
- em_config_dsp_after_link_change
- em_set_phy_mode
- em_set_d3_lplu_state
- em_set_d0_lplu_state
- em_set_vco_speed
- em_host_if_read_cookie
- em_mng_enable_host_if
- em_check_mng_mode
- em_calculate_mng_checksum
- em_enable_tx_pkt_filtering
- em_polarity_reversal_workaround
- em_set_pci_express_master_disable
- em_disable_pciex_master
- em_get_auto_rd_done
- em_get_phy_cfg_done
- em_get_hw_eeprom_semaphore
- em_put_hw_eeprom_semaphore
- em_get_software_semaphore
- em_release_software_semaphore
- em_check_phy_reset_block
- em_set_pci_ex_no_snoop
- em_get_software_flag
- em_release_software_flag
- em_read_eeprom_ich8
- em_write_eeprom_ich8
- em_ich8_cycle_init
- em_ich8_flash_cycle
- em_read_ich8_data
- em_write_ich8_data
- em_read_ich8_byte
- em_verify_write_ich8_byte
- em_write_ich8_byte
- em_read_ich8_word
- em_erase_ich8_4k_segment
- em_init_lcd_from_nvm_config_region
- em_init_lcd_from_nvm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #if 0
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD: if_em_hw.c,v 1.16 2005/05/26 23:32:02 tackerman Exp $");
43 #endif
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/sockio.h>
48 #include <sys/mbuf.h>
49 #include <sys/malloc.h>
50 #include <sys/kernel.h>
51 #include <sys/device.h>
52 #include <sys/socket.h>
53
54 #include <net/if.h>
55 #include <net/if_dl.h>
56 #include <net/if_media.h>
57
58 #ifdef INET
59 #include <netinet/in.h>
60 #include <netinet/in_systm.h>
61 #include <netinet/in_var.h>
62 #include <netinet/ip.h>
63 #include <netinet/if_ether.h>
64 #endif
65
66 #include <uvm/uvm_extern.h>
67
68 #include <dev/pci/pcireg.h>
69 #include <dev/pci/pcivar.h>
70 #include <dev/pci/pcidevs.h>
71
72 #include <dev/pci/if_em_hw.h>
73
74 #define STATIC
75
76 static int32_t em_swfw_sync_acquire(struct em_hw *hw, uint16_t mask);
77 static void em_swfw_sync_release(struct em_hw *hw, uint16_t mask);
78 static int32_t em_read_kmrn_reg(struct em_hw *hw, uint32_t reg_addr, uint16_t *data);
79 static int32_t em_write_kmrn_reg(struct em_hw *hw, uint32_t reg_addr, uint16_t data);
80 static int32_t em_get_software_semaphore(struct em_hw *hw);
81 static void em_release_software_semaphore(struct em_hw *hw);
82
83 static int32_t em_check_downshift(struct em_hw *hw);
84 static void em_clear_vfta(struct em_hw *hw);
85 static int32_t em_commit_shadow_ram(struct em_hw *hw);
86 static int32_t em_config_dsp_after_link_change(struct em_hw *hw, boolean_t link_up);
87 static int32_t em_config_fc_after_link_up(struct em_hw *hw);
88 static int32_t em_detect_gig_phy(struct em_hw *hw);
89 static int32_t em_erase_ich8_4k_segment(struct em_hw *hw, uint32_t bank);
90 static int32_t em_get_auto_rd_done(struct em_hw *hw);
91 static int32_t em_get_cable_length(struct em_hw *hw, uint16_t *min_length, uint16_t *max_length);
92 static int32_t em_get_hw_eeprom_semaphore(struct em_hw *hw);
93 static int32_t em_get_phy_cfg_done(struct em_hw *hw);
94 static int32_t em_get_software_flag(struct em_hw *hw);
95 static int32_t em_ich8_cycle_init(struct em_hw *hw);
96 static int32_t em_ich8_flash_cycle(struct em_hw *hw, uint32_t timeout);
97 static int32_t em_id_led_init(struct em_hw *hw);
98 static int32_t em_init_lcd_from_nvm_config_region(struct em_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
99 static int32_t em_init_lcd_from_nvm(struct em_hw *hw);
100 static void em_init_rx_addrs(struct em_hw *hw);
101 static void em_initialize_hardware_bits(struct em_hw *hw);
102 static boolean_t em_is_onboard_nvm_eeprom(struct em_hw *hw);
103 static int32_t em_kumeran_lock_loss_workaround(struct em_hw *hw);
104 static int32_t em_mng_enable_host_if(struct em_hw *hw);
105 static int32_t em_read_eeprom_eerd(struct em_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
106 static int32_t em_write_eeprom_eewr(struct em_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
107 static int32_t em_poll_eerd_eewr_done(struct em_hw *hw, int eerd);
108 static void em_put_hw_eeprom_semaphore(struct em_hw *hw);
109 static int32_t em_read_ich8_byte(struct em_hw *hw, uint32_t index, uint8_t *data);
110 static int32_t em_verify_write_ich8_byte(struct em_hw *hw, uint32_t index, uint8_t byte);
111 static int32_t em_write_ich8_byte(struct em_hw *hw, uint32_t index, uint8_t byte);
112 static int32_t em_read_ich8_word(struct em_hw *hw, uint32_t index, uint16_t *data);
113 static int32_t em_read_ich8_data(struct em_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
114 static int32_t em_write_ich8_data(struct em_hw *hw, uint32_t index, uint32_t size, uint16_t data);
115 static int32_t em_read_eeprom_ich8(struct em_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
116 static int32_t em_write_eeprom_ich8(struct em_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
117 static void em_release_software_flag(struct em_hw *hw);
118 static int32_t em_set_d3_lplu_state(struct em_hw *hw, boolean_t active);
119 static int32_t em_set_d0_lplu_state(struct em_hw *hw, boolean_t active);
120 static int32_t em_set_pci_ex_no_snoop(struct em_hw *hw, uint32_t no_snoop);
121 static void em_set_pci_express_master_disable(struct em_hw *hw);
122 static int32_t em_wait_autoneg(struct em_hw *hw);
123 static void em_write_reg_io(struct em_hw *hw, uint32_t offset, uint32_t value);
124 static int32_t em_set_phy_type(struct em_hw *hw);
125 static void em_phy_init_script(struct em_hw *hw);
126 static int32_t em_setup_copper_link(struct em_hw *hw);
127 static int32_t em_setup_fiber_serdes_link(struct em_hw *hw);
128 static int32_t em_adjust_serdes_amplitude(struct em_hw *hw);
129 static int32_t em_phy_force_speed_duplex(struct em_hw *hw);
130 static int32_t em_config_mac_to_phy(struct em_hw *hw);
131 static void em_raise_mdi_clk(struct em_hw *hw, uint32_t *ctrl);
132 static void em_lower_mdi_clk(struct em_hw *hw, uint32_t *ctrl);
133 static void em_shift_out_mdi_bits(struct em_hw *hw, uint32_t data,
134 uint16_t count);
135 static uint16_t em_shift_in_mdi_bits(struct em_hw *hw);
136 static int32_t em_phy_reset_dsp(struct em_hw *hw);
137 static int32_t em_write_eeprom_spi(struct em_hw *hw, uint16_t offset,
138 uint16_t words, uint16_t *data);
139 static int32_t em_write_eeprom_microwire(struct em_hw *hw,
140 uint16_t offset, uint16_t words,
141 uint16_t *data);
142 static int32_t em_spi_eeprom_ready(struct em_hw *hw);
143 static void em_raise_ee_clk(struct em_hw *hw, uint32_t *eecd);
144 static void em_lower_ee_clk(struct em_hw *hw, uint32_t *eecd);
145 static void em_shift_out_ee_bits(struct em_hw *hw, uint16_t data,
146 uint16_t count);
147 static int32_t em_write_phy_reg_ex(struct em_hw *hw, uint32_t reg_addr,
148 uint16_t phy_data);
149 static int32_t em_read_phy_reg_ex(struct em_hw *hw,uint32_t reg_addr,
150 uint16_t *phy_data);
151 static uint16_t em_shift_in_ee_bits(struct em_hw *hw, uint16_t count);
152 static int32_t em_acquire_eeprom(struct em_hw *hw);
153 static void em_release_eeprom(struct em_hw *hw);
154 static void em_standby_eeprom(struct em_hw *hw);
155 static int32_t em_set_vco_speed(struct em_hw *hw);
156 static int32_t em_polarity_reversal_workaround(struct em_hw *hw);
157 static int32_t em_set_phy_mode(struct em_hw *hw);
158 static int32_t em_host_if_read_cookie(struct em_hw *hw, uint8_t *buffer);
159 static uint8_t em_calculate_mng_checksum(char *buffer, uint32_t length);
160 static int32_t em_configure_kmrn_for_10_100(struct em_hw *hw,
161 uint16_t duplex);
162 static int32_t em_configure_kmrn_for_1000(struct em_hw *hw);
163
164
165 static const
166 uint16_t em_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
167 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
168 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
169 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
170 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
171 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
172 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
173 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
174 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
175
176 static const
177 uint16_t em_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
178 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
179 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
180 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
181 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
182 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
183 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
184 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
185 104, 109, 114, 118, 121, 124};
186
187
188
189
190
191
192 STATIC int32_t
193 em_set_phy_type(struct em_hw *hw)
194 {
195 DEBUGFUNC("em_set_phy_type");
196
197 if (hw->mac_type == em_undefined)
198 return -E1000_ERR_PHY_TYPE;
199
200 switch (hw->phy_id) {
201 case M88E1000_E_PHY_ID:
202 case M88E1000_I_PHY_ID:
203 case M88E1011_I_PHY_ID:
204 case M88E1111_I_PHY_ID:
205 hw->phy_type = em_phy_m88;
206 break;
207 case IGP01E1000_I_PHY_ID:
208 if (hw->mac_type == em_82541 ||
209 hw->mac_type == em_82541_rev_2 ||
210 hw->mac_type == em_82547 ||
211 hw->mac_type == em_82547_rev_2) {
212 hw->phy_type = em_phy_igp;
213 break;
214 }
215 case IGP03E1000_E_PHY_ID:
216 hw->phy_type = em_phy_igp_3;
217 break;
218 case IFE_E_PHY_ID:
219 case IFE_PLUS_E_PHY_ID:
220 case IFE_C_E_PHY_ID:
221 hw->phy_type = em_phy_ife;
222 break;
223 case GG82563_E_PHY_ID:
224 if (hw->mac_type == em_80003es2lan) {
225 hw->phy_type = em_phy_gg82563;
226 break;
227 }
228
229 default:
230
231 hw->phy_type = em_phy_undefined;
232 return -E1000_ERR_PHY_TYPE;
233 }
234
235 return E1000_SUCCESS;
236 }
237
238
239
240
241
242
243 static void
244 em_phy_init_script(struct em_hw *hw)
245 {
246 uint32_t ret_val;
247 uint16_t phy_saved_data;
248
249 DEBUGFUNC("em_phy_init_script");
250
251 if (hw->phy_init_script) {
252 msec_delay(20);
253
254
255
256 ret_val = em_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
257
258
259 em_write_phy_reg(hw, 0x2F5B, 0x0003);
260
261 msec_delay(20);
262
263 em_write_phy_reg(hw,0x0000,0x0140);
264
265 msec_delay(5);
266
267 switch (hw->mac_type) {
268 case em_82541:
269 case em_82547:
270 em_write_phy_reg(hw, 0x1F95, 0x0001);
271
272 em_write_phy_reg(hw, 0x1F71, 0xBD21);
273
274 em_write_phy_reg(hw, 0x1F79, 0x0018);
275
276 em_write_phy_reg(hw, 0x1F30, 0x1600);
277
278 em_write_phy_reg(hw, 0x1F31, 0x0014);
279
280 em_write_phy_reg(hw, 0x1F32, 0x161C);
281
282 em_write_phy_reg(hw, 0x1F94, 0x0003);
283
284 em_write_phy_reg(hw, 0x1F96, 0x003F);
285
286 em_write_phy_reg(hw, 0x2010, 0x0008);
287 break;
288
289 case em_82541_rev_2:
290 case em_82547_rev_2:
291 em_write_phy_reg(hw, 0x1F73, 0x0099);
292 break;
293 default:
294 break;
295 }
296
297 em_write_phy_reg(hw, 0x0000, 0x3300);
298
299 msec_delay(20);
300
301
302 em_write_phy_reg(hw, 0x2F5B, phy_saved_data);
303
304 if (hw->mac_type == em_82547) {
305 uint16_t fused, fine, coarse;
306
307
308 em_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
309
310 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
311 em_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
312
313 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
314 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
315
316 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
317 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
318 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
319 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
320 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
321
322 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
323 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
324 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
325
326 em_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
327 em_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
328 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
329 }
330 }
331 }
332 }
333
334
335
336
337
338
339 int32_t
340 em_set_mac_type(struct em_hw *hw)
341 {
342 DEBUGFUNC("em_set_mac_type");
343
344 switch (hw->device_id) {
345 case E1000_DEV_ID_82542:
346 switch (hw->revision_id) {
347 case E1000_82542_2_0_REV_ID:
348 hw->mac_type = em_82542_rev2_0;
349 break;
350 case E1000_82542_2_1_REV_ID:
351 hw->mac_type = em_82542_rev2_1;
352 break;
353 default:
354
355 return -E1000_ERR_MAC_TYPE;
356 }
357 break;
358 case E1000_DEV_ID_82543GC_FIBER:
359 case E1000_DEV_ID_82543GC_COPPER:
360 hw->mac_type = em_82543;
361 break;
362 case E1000_DEV_ID_82544EI_COPPER:
363 case E1000_DEV_ID_82544EI_FIBER:
364 case E1000_DEV_ID_82544GC_COPPER:
365 case E1000_DEV_ID_82544GC_LOM:
366 hw->mac_type = em_82544;
367 break;
368 case E1000_DEV_ID_82540EM:
369 case E1000_DEV_ID_82540EM_LOM:
370 case E1000_DEV_ID_82540EP:
371 case E1000_DEV_ID_82540EP_LOM:
372 case E1000_DEV_ID_82540EP_LP:
373 hw->mac_type = em_82540;
374 break;
375 case E1000_DEV_ID_82545EM_COPPER:
376 case E1000_DEV_ID_82545EM_FIBER:
377 hw->mac_type = em_82545;
378 break;
379 case E1000_DEV_ID_82545GM_COPPER:
380 case E1000_DEV_ID_82545GM_FIBER:
381 case E1000_DEV_ID_82545GM_SERDES:
382 hw->mac_type = em_82545_rev_3;
383 break;
384 case E1000_DEV_ID_82546EB_COPPER:
385 case E1000_DEV_ID_82546EB_FIBER:
386 case E1000_DEV_ID_82546EB_QUAD_COPPER:
387 hw->mac_type = em_82546;
388 break;
389 case E1000_DEV_ID_82546GB_COPPER:
390 case E1000_DEV_ID_82546GB_FIBER:
391 case E1000_DEV_ID_82546GB_SERDES:
392 case E1000_DEV_ID_82546GB_PCIE:
393 case E1000_DEV_ID_82546GB_QUAD_COPPER:
394 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
395 case E1000_DEV_ID_82546GB_2:
396 hw->mac_type = em_82546_rev_3;
397 break;
398 case E1000_DEV_ID_82541EI:
399 case E1000_DEV_ID_82541EI_MOBILE:
400 case E1000_DEV_ID_82541ER_LOM:
401 hw->mac_type = em_82541;
402 break;
403 case E1000_DEV_ID_82541ER:
404 case E1000_DEV_ID_82541GI:
405 case E1000_DEV_ID_82541GI_LF:
406 case E1000_DEV_ID_82541GI_MOBILE:
407 hw->mac_type = em_82541_rev_2;
408 break;
409 case E1000_DEV_ID_82547EI:
410 case E1000_DEV_ID_82547EI_MOBILE:
411 hw->mac_type = em_82547;
412 break;
413 case E1000_DEV_ID_82547GI:
414 hw->mac_type = em_82547_rev_2;
415 break;
416 case E1000_DEV_ID_82571EB_AF:
417 case E1000_DEV_ID_82571EB_AT:
418 case E1000_DEV_ID_82571EB_COPPER:
419 case E1000_DEV_ID_82571EB_FIBER:
420 case E1000_DEV_ID_82571EB_SERDES:
421 case E1000_DEV_ID_82571EB_QUAD_COPPER:
422 case E1000_DEV_ID_82571EB_QUAD_FIBER:
423 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
424 hw->mac_type = em_82571;
425 break;
426 case E1000_DEV_ID_82572EI_COPPER:
427 case E1000_DEV_ID_82572EI_FIBER:
428 case E1000_DEV_ID_82572EI_SERDES:
429 case E1000_DEV_ID_82572EI:
430 hw->mac_type = em_82572;
431 break;
432 case E1000_DEV_ID_82573E:
433 case E1000_DEV_ID_82573E_IAMT:
434 case E1000_DEV_ID_82573E_PM:
435 case E1000_DEV_ID_82573L:
436 case E1000_DEV_ID_82573L_PL_1:
437 case E1000_DEV_ID_82573L_PL_2:
438 case E1000_DEV_ID_82573V_PM:
439 hw->mac_type = em_82573;
440 break;
441 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
442 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
443 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
444 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
445 hw->mac_type = em_80003es2lan;
446 break;
447 case E1000_DEV_ID_ICH8_IGP_M_AMT:
448 case E1000_DEV_ID_ICH8_IGP_AMT:
449 case E1000_DEV_ID_ICH8_IGP_C:
450 case E1000_DEV_ID_ICH8_IFE:
451 case E1000_DEV_ID_ICH8_IFE_GT:
452 case E1000_DEV_ID_ICH8_IFE_G:
453 case E1000_DEV_ID_ICH8_IGP_M:
454 hw->mac_type = em_ich8lan;
455 break;
456 default:
457
458 return -E1000_ERR_MAC_TYPE;
459 }
460
461 switch (hw->mac_type) {
462 case em_ich8lan:
463 hw->swfwhw_semaphore_present = TRUE;
464 hw->asf_firmware_present = TRUE;
465 break;
466 case em_80003es2lan:
467 hw->swfw_sync_present = TRUE;
468
469 case em_82571:
470 case em_82572:
471 case em_82573:
472 hw->eeprom_semaphore_present = TRUE;
473
474 case em_82541:
475 case em_82547:
476 case em_82541_rev_2:
477 case em_82547_rev_2:
478 hw->asf_firmware_present = TRUE;
479 break;
480 default:
481 break;
482 }
483
484 return E1000_SUCCESS;
485 }
486
487
488
489
490
491
492 void
493 em_set_media_type(struct em_hw *hw)
494 {
495 uint32_t status;
496
497 DEBUGFUNC("em_set_media_type");
498
499 if (hw->mac_type != em_82543) {
500
501 hw->tbi_compatibility_en = FALSE;
502 }
503
504 switch (hw->device_id) {
505 case E1000_DEV_ID_82545GM_SERDES:
506 case E1000_DEV_ID_82546GB_SERDES:
507 case E1000_DEV_ID_82571EB_SERDES:
508 case E1000_DEV_ID_82572EI_SERDES:
509 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
510 hw->media_type = em_media_type_internal_serdes;
511 break;
512 default:
513 switch (hw->mac_type) {
514 case em_82542_rev2_0:
515 case em_82542_rev2_1:
516 hw->media_type = em_media_type_fiber;
517 break;
518 case em_ich8lan:
519 case em_82573:
520
521
522
523 hw->media_type = em_media_type_copper;
524 break;
525 default:
526 status = E1000_READ_REG(hw, STATUS);
527 if (status & E1000_STATUS_TBIMODE) {
528 hw->media_type = em_media_type_fiber;
529
530 hw->tbi_compatibility_en = FALSE;
531 } else {
532 hw->media_type = em_media_type_copper;
533 }
534 break;
535 }
536 }
537 }
538
539
540
541
542
543
544 int32_t
545 em_reset_hw(struct em_hw *hw)
546 {
547 uint32_t ctrl;
548 uint32_t ctrl_ext;
549 uint32_t icr;
550 uint32_t manc;
551 uint32_t led_ctrl;
552 uint32_t timeout;
553 uint32_t extcnf_ctrl;
554 int32_t ret_val;
555
556 DEBUGFUNC("em_reset_hw");
557
558
559 if (hw->mac_type == em_82542_rev2_0) {
560 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
561 em_pci_clear_mwi(hw);
562 }
563
564 if (hw->bus_type == em_bus_type_pci_express) {
565
566
567
568 if (em_disable_pciex_master(hw) != E1000_SUCCESS) {
569 DEBUGOUT("PCI-E Master disable polling has failed.\n");
570 }
571 }
572
573
574 DEBUGOUT("Masking off all interrupts\n");
575 E1000_WRITE_REG(hw, IMC, 0xffffffff);
576
577
578
579
580
581 E1000_WRITE_REG(hw, RCTL, 0);
582 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
583 E1000_WRITE_FLUSH(hw);
584
585
586 hw->tbi_compatibility_on = FALSE;
587
588
589
590
591 msec_delay(10);
592
593 ctrl = E1000_READ_REG(hw, CTRL);
594
595
596 if ((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
597 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
598 msec_delay(5);
599 }
600
601
602
603 if (hw->mac_type == em_82573) {
604 timeout = 10;
605
606 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
607 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
608
609 do {
610 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
611 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
612
613 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
614 break;
615 else
616 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
617
618 msec_delay(2);
619 timeout--;
620 } while (timeout);
621 }
622
623
624 if (hw->mac_type == em_ich8lan) {
625
626 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
627
628 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
629 }
630
631
632
633
634
635
636 DEBUGOUT("Issuing a global reset to MAC\n");
637
638 switch (hw->mac_type) {
639 case em_82544:
640 case em_82540:
641 case em_82545:
642 case em_82546:
643 case em_82541:
644 case em_82541_rev_2:
645
646
647 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
648 break;
649 case em_82545_rev_3:
650 case em_82546_rev_3:
651
652 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
653 break;
654 case em_ich8lan:
655 if (!hw->phy_reset_disable &&
656 em_check_phy_reset_block(hw) == E1000_SUCCESS) {
657
658
659
660
661 ctrl |= E1000_CTRL_PHY_RST;
662 }
663
664 em_get_software_flag(hw);
665 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
666 msec_delay(5);
667 break;
668 default:
669 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
670 break;
671 }
672
673
674
675
676
677 switch (hw->mac_type) {
678 case em_82542_rev2_0:
679 case em_82542_rev2_1:
680 case em_82543:
681 case em_82544:
682
683 usec_delay(10);
684 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
685 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
686 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
687 E1000_WRITE_FLUSH(hw);
688
689 msec_delay(2);
690 break;
691 case em_82541:
692 case em_82541_rev_2:
693 case em_82547:
694 case em_82547_rev_2:
695
696 msec_delay(20);
697 break;
698 case em_82573:
699 if (em_is_onboard_nvm_eeprom(hw) == FALSE) {
700 usec_delay(10);
701 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
702 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
703 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
704 E1000_WRITE_FLUSH(hw);
705 }
706
707 default:
708
709 ret_val = em_get_auto_rd_done(hw);
710 if (ret_val)
711 return ret_val;
712 break;
713 }
714
715
716 if (hw->mac_type >= em_82540 && hw->mac_type <= em_82547_rev_2) {
717 manc = E1000_READ_REG(hw, MANC);
718 manc &= ~(E1000_MANC_ARP_EN);
719 E1000_WRITE_REG(hw, MANC, manc);
720 }
721
722 if ((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
723 em_phy_init_script(hw);
724
725
726 led_ctrl = E1000_READ_REG(hw, LEDCTL);
727 led_ctrl &= IGP_ACTIVITY_LED_MASK;
728 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
729 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
730 }
731
732
733 DEBUGOUT("Masking off all interrupts\n");
734 E1000_WRITE_REG(hw, IMC, 0xffffffff);
735
736
737 icr = E1000_READ_REG(hw, ICR);
738
739
740 if (hw->mac_type == em_82542_rev2_0) {
741 if (hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
742 em_pci_set_mwi(hw);
743 }
744
745 if (hw->mac_type == em_ich8lan) {
746 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
747 kab |= E1000_KABGTXD_BGSQLBIAS;
748 E1000_WRITE_REG(hw, KABGTXD, kab);
749 }
750
751 return E1000_SUCCESS;
752 }
753
754
755
756
757
758
759
760
761 STATIC void
762 em_initialize_hardware_bits(struct em_hw *hw)
763 {
764 if ((hw->mac_type >= em_82571) && (!hw->initialize_hw_bits_disable)) {
765
766 uint32_t reg_ctrl, reg_ctrl_ext;
767 uint32_t reg_tarc0, reg_tarc1;
768 uint32_t reg_tctl;
769 uint32_t reg_txdctl, reg_txdctl1;
770
771 reg_tarc0 = E1000_READ_REG(hw, TARC0);
772 reg_tarc0 &= ~0x78000000;
773
774 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
775 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
776 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
777
778 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
779 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
780 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
781
782 switch (hw->mac_type) {
783 case em_82571:
784 case em_82572:
785 reg_tarc1 = E1000_READ_REG(hw, TARC1);
786 reg_tctl = E1000_READ_REG(hw, TCTL);
787
788
789 reg_tarc1 &= ~0x60000000;
790
791 reg_tarc0 |= 0x07800000;
792 reg_tarc1 |= 0x07000000;
793
794 if (reg_tctl & E1000_TCTL_MULR)
795 reg_tarc1 &= ~0x10000000;
796 else
797 reg_tarc1 |= 0x10000000;
798
799 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
800 break;
801 case em_82573:
802 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
803 reg_ctrl = E1000_READ_REG(hw, CTRL);
804
805 reg_ctrl_ext &= ~0x00800000;
806 reg_ctrl_ext |= 0x00400000;
807 reg_ctrl &= ~0x20000000;
808
809 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
810 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
811 break;
812 case em_80003es2lan:
813 if ((hw->media_type == em_media_type_fiber) ||
814 (hw->media_type == em_media_type_internal_serdes)) {
815 reg_tarc0 &= ~0x00100000;
816 }
817
818 reg_tctl = E1000_READ_REG(hw, TCTL);
819 reg_tarc1 = E1000_READ_REG(hw, TARC1);
820 if (reg_tctl & E1000_TCTL_MULR)
821 reg_tarc1 &= ~0x10000000;
822 else
823 reg_tarc1 |= 0x10000000;
824
825 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
826 break;
827 case em_ich8lan:
828 if ((hw->revision_id < 3) ||
829 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
830 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
831 reg_tarc0 |= 0x30000000;
832 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
833 reg_ctrl_ext |= 0x00400000;
834 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
835
836 reg_tarc0 |= 0x0d800000;
837
838 reg_tarc1 = E1000_READ_REG(hw, TARC1);
839 reg_tctl = E1000_READ_REG(hw, TCTL);
840
841 if (reg_tctl & E1000_TCTL_MULR)
842 reg_tarc1 &= ~0x10000000;
843 else
844 reg_tarc1 |= 0x10000000;
845
846 reg_tarc1 |= 0x45000000;
847
848 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
849 break;
850 default:
851 break;
852 }
853
854 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
855 }
856 }
857
858
859
860
861
862
863
864
865
866
867
868
869 int32_t
870 em_init_hw(struct em_hw *hw)
871 {
872 uint32_t ctrl;
873 uint32_t i;
874 int32_t ret_val;
875 uint16_t pcix_cmd_word;
876 uint16_t pcix_stat_hi_word;
877 uint16_t cmd_mmrbc;
878 uint16_t stat_mmrbc;
879 uint32_t mta_size;
880 uint32_t reg_data;
881 uint32_t ctrl_ext;
882
883 DEBUGFUNC("em_init_hw");
884
885
886 if ((hw->mac_type == em_ich8lan) &&
887 ((hw->revision_id < 3) ||
888 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
889 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
890 reg_data = E1000_READ_REG(hw, STATUS);
891 reg_data &= ~0x80000000;
892 E1000_WRITE_REG(hw, STATUS, reg_data);
893 }
894
895
896 ret_val = em_id_led_init(hw);
897 if (ret_val) {
898 DEBUGOUT("Error Initializing Identification LED\n");
899 return ret_val;
900 }
901
902
903 em_set_media_type(hw);
904
905
906 em_initialize_hardware_bits(hw);
907
908
909 DEBUGOUT("Initializing the IEEE VLAN\n");
910
911 if (hw->mac_type != em_ich8lan) {
912 if (hw->mac_type < em_82545_rev_3)
913 E1000_WRITE_REG(hw, VET, 0);
914 em_clear_vfta(hw);
915 }
916
917
918 if (hw->mac_type == em_82542_rev2_0) {
919 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
920 em_pci_clear_mwi(hw);
921 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
922 E1000_WRITE_FLUSH(hw);
923 msec_delay(5);
924 }
925
926
927
928
929 em_init_rx_addrs(hw);
930
931
932 if (hw->mac_type == em_82542_rev2_0) {
933 E1000_WRITE_REG(hw, RCTL, 0);
934 E1000_WRITE_FLUSH(hw);
935 msec_delay(1);
936 if (hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
937 em_pci_set_mwi(hw);
938 }
939
940
941 DEBUGOUT("Zeroing the MTA\n");
942 mta_size = E1000_MC_TBL_SIZE;
943 if (hw->mac_type == em_ich8lan)
944 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
945 for (i = 0; i < mta_size; i++) {
946 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
947
948
949 E1000_WRITE_FLUSH(hw);
950 }
951
952
953
954
955
956
957 if (hw->dma_fairness && hw->mac_type <= em_82543) {
958 ctrl = E1000_READ_REG(hw, CTRL);
959 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
960 }
961
962 switch (hw->mac_type) {
963 case em_82545_rev_3:
964 case em_82546_rev_3:
965 break;
966 default:
967
968 if (hw->bus_type == em_bus_type_pcix) {
969 em_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
970 em_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
971 &pcix_stat_hi_word);
972 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
973 PCIX_COMMAND_MMRBC_SHIFT;
974 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
975 PCIX_STATUS_HI_MMRBC_SHIFT;
976 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
977 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
978 if (cmd_mmrbc > stat_mmrbc) {
979 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
980 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
981 em_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
982 &pcix_cmd_word);
983 }
984 }
985 break;
986 }
987
988
989 if (hw->mac_type == em_ich8lan)
990 msec_delay(15);
991
992
993 ret_val = em_setup_link(hw);
994
995
996 if (hw->mac_type > em_82544) {
997 ctrl = E1000_READ_REG(hw, TXDCTL);
998 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
999 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1000 }
1001
1002 if (hw->mac_type == em_82573) {
1003 em_enable_tx_pkt_filtering(hw);
1004 }
1005
1006 switch (hw->mac_type) {
1007 default:
1008 break;
1009 case em_80003es2lan:
1010
1011 reg_data = E1000_READ_REG(hw, TCTL);
1012 reg_data |= E1000_TCTL_RTLC;
1013 E1000_WRITE_REG(hw, TCTL, reg_data);
1014
1015
1016 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1017 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1018 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1019 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1020
1021
1022 reg_data = E1000_READ_REG(hw, TIPG);
1023 reg_data &= ~E1000_TIPG_IPGT_MASK;
1024 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1025 E1000_WRITE_REG(hw, TIPG, reg_data);
1026
1027 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1028 reg_data &= ~0x00100000;
1029 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1030
1031 case em_82571:
1032 case em_82572:
1033 case em_ich8lan:
1034 ctrl = E1000_READ_REG(hw, TXDCTL1);
1035 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1036 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1037 break;
1038 }
1039
1040 if (hw->mac_type == em_82573) {
1041 uint32_t gcr = E1000_READ_REG(hw, GCR);
1042 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1043 E1000_WRITE_REG(hw, GCR, gcr);
1044 }
1045
1046
1047
1048
1049
1050
1051 em_clear_hw_cntrs(hw);
1052
1053
1054
1055 if (hw->mac_type == em_ich8lan)
1056 em_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1057
1058 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1059 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1060 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1061
1062
1063 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1064 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1065 }
1066
1067 return ret_val;
1068 }
1069
1070
1071
1072
1073
1074
1075 static int32_t
1076 em_adjust_serdes_amplitude(struct em_hw *hw)
1077 {
1078 uint16_t eeprom_data;
1079 int32_t ret_val;
1080
1081 DEBUGFUNC("em_adjust_serdes_amplitude");
1082
1083 if (hw->media_type != em_media_type_internal_serdes)
1084 return E1000_SUCCESS;
1085
1086 switch (hw->mac_type) {
1087 case em_82545_rev_3:
1088 case em_82546_rev_3:
1089 break;
1090 default:
1091 return E1000_SUCCESS;
1092 }
1093
1094 ret_val = em_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1095 if (ret_val) {
1096 return ret_val;
1097 }
1098
1099 if (eeprom_data != EEPROM_RESERVED_WORD) {
1100
1101 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1102 ret_val = em_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1103 if (ret_val)
1104 return ret_val;
1105 }
1106
1107 return E1000_SUCCESS;
1108 }
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121 int32_t
1122 em_setup_link(struct em_hw *hw)
1123 {
1124 uint32_t ctrl_ext;
1125 int32_t ret_val;
1126 uint16_t eeprom_data;
1127
1128 DEBUGFUNC("em_setup_link");
1129
1130
1131
1132 if (em_check_phy_reset_block(hw))
1133 return E1000_SUCCESS;
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143 if (hw->fc == E1000_FC_DEFAULT) {
1144 switch (hw->mac_type) {
1145 case em_ich8lan:
1146 case em_82573:
1147 hw->fc = E1000_FC_FULL;
1148 break;
1149 default:
1150 ret_val = em_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1151 1, &eeprom_data);
1152 if (ret_val) {
1153 DEBUGOUT("EEPROM Read Error\n");
1154 return -E1000_ERR_EEPROM;
1155 }
1156 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1157 hw->fc = E1000_FC_NONE;
1158 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1159 EEPROM_WORD0F_ASM_DIR)
1160 hw->fc = E1000_FC_TX_PAUSE;
1161 else
1162 hw->fc = E1000_FC_FULL;
1163 break;
1164 }
1165 }
1166
1167
1168
1169
1170
1171 if (hw->mac_type == em_82542_rev2_0)
1172 hw->fc &= (~E1000_FC_TX_PAUSE);
1173
1174 if ((hw->mac_type < em_82543) && (hw->report_tx_early == 1))
1175 hw->fc &= (~E1000_FC_RX_PAUSE);
1176
1177 hw->original_fc = hw->fc;
1178
1179 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1180
1181
1182
1183
1184
1185
1186
1187
1188 if (hw->mac_type == em_82543) {
1189 ret_val = em_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1190 1, &eeprom_data);
1191 if (ret_val) {
1192 DEBUGOUT("EEPROM Read Error\n");
1193 return -E1000_ERR_EEPROM;
1194 }
1195 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1196 SWDPIO__EXT_SHIFT);
1197 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1198 }
1199
1200
1201 ret_val = (hw->media_type == em_media_type_copper) ?
1202 em_setup_copper_link(hw) :
1203 em_setup_fiber_serdes_link(hw);
1204
1205
1206
1207
1208
1209
1210 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1211
1212
1213 if (hw->mac_type != em_ich8lan) {
1214 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1215 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1216 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1217 }
1218
1219 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1220
1221
1222
1223
1224
1225
1226
1227 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1228 E1000_WRITE_REG(hw, FCRTL, 0);
1229 E1000_WRITE_REG(hw, FCRTH, 0);
1230 } else {
1231
1232
1233
1234 if (hw->fc_send_xon) {
1235 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1236 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1237 } else {
1238 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1239 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1240 }
1241 }
1242 return ret_val;
1243 }
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254 static int32_t
1255 em_setup_fiber_serdes_link(struct em_hw *hw)
1256 {
1257 uint32_t ctrl;
1258 uint32_t status;
1259 uint32_t txcw = 0;
1260 uint32_t i;
1261 uint32_t signal = 0;
1262 int32_t ret_val;
1263
1264 DEBUGFUNC("em_setup_fiber_serdes_link");
1265
1266
1267
1268
1269
1270
1271 if (hw->mac_type == em_82571 || hw->mac_type == em_82572)
1272 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1273
1274
1275
1276
1277
1278
1279
1280 ctrl = E1000_READ_REG(hw, CTRL);
1281 if (hw->media_type == em_media_type_fiber)
1282 signal = (hw->mac_type > em_82544) ? E1000_CTRL_SWDPIN1 : 0;
1283
1284 ret_val = em_adjust_serdes_amplitude(hw);
1285 if (ret_val)
1286 return ret_val;
1287
1288
1289 ctrl &= ~(E1000_CTRL_LRST);
1290
1291
1292 ret_val = em_set_vco_speed(hw);
1293 if (ret_val)
1294 return ret_val;
1295
1296 em_config_collision_dist(hw);
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313 switch (hw->fc) {
1314 case E1000_FC_NONE:
1315
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1317 break;
1318 case E1000_FC_RX_PAUSE:
1319
1320
1321
1322
1323
1324
1325 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1326 break;
1327 case E1000_FC_TX_PAUSE:
1328
1329
1330
1331 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1332 break;
1333 case E1000_FC_FULL:
1334
1335 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1336 break;
1337 default:
1338 DEBUGOUT("Flow control param set incorrectly\n");
1339 return -E1000_ERR_CONFIG;
1340 break;
1341 }
1342
1343
1344
1345
1346
1347
1348
1349 DEBUGOUT("Auto-negotiation enabled\n");
1350
1351 E1000_WRITE_REG(hw, TXCW, txcw);
1352 E1000_WRITE_REG(hw, CTRL, ctrl);
1353 E1000_WRITE_FLUSH(hw);
1354
1355 hw->txcw = txcw;
1356 msec_delay(1);
1357
1358
1359
1360
1361
1362
1363
1364 if (hw->media_type == em_media_type_internal_serdes ||
1365 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1366 DEBUGOUT("Looking for Link\n");
1367 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1368 msec_delay(10);
1369 status = E1000_READ_REG(hw, STATUS);
1370 if (status & E1000_STATUS_LU) break;
1371 }
1372 if (i == (LINK_UP_TIMEOUT / 10)) {
1373 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1374 hw->autoneg_failed = 1;
1375
1376
1377
1378
1379
1380 ret_val = em_check_for_link(hw);
1381 if (ret_val) {
1382 DEBUGOUT("Error while checking for link\n");
1383 return ret_val;
1384 }
1385 hw->autoneg_failed = 0;
1386 } else {
1387 hw->autoneg_failed = 0;
1388 DEBUGOUT("Valid Link Found\n");
1389 }
1390 } else {
1391 DEBUGOUT("No Signal Detected\n");
1392 }
1393 return E1000_SUCCESS;
1394 }
1395
1396
1397
1398
1399
1400
1401 static int32_t
1402 em_copper_link_preconfig(struct em_hw *hw)
1403 {
1404 uint32_t ctrl;
1405 int32_t ret_val;
1406 uint16_t phy_data;
1407
1408 DEBUGFUNC("em_copper_link_preconfig");
1409
1410 ctrl = E1000_READ_REG(hw, CTRL);
1411
1412
1413
1414
1415 if (hw->mac_type > em_82543) {
1416 ctrl |= E1000_CTRL_SLU;
1417 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1418 E1000_WRITE_REG(hw, CTRL, ctrl);
1419 } else {
1420 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1421 E1000_WRITE_REG(hw, CTRL, ctrl);
1422 ret_val = em_phy_hw_reset(hw);
1423 if (ret_val)
1424 return ret_val;
1425 }
1426
1427
1428 ret_val = em_detect_gig_phy(hw);
1429 if (ret_val) {
1430 DEBUGOUT("Error, did not detect valid phy.\n");
1431 return ret_val;
1432 }
1433 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1434
1435
1436 ret_val = em_set_phy_mode(hw);
1437 if (ret_val)
1438 return ret_val;
1439
1440 if ((hw->mac_type == em_82545_rev_3) ||
1441 (hw->mac_type == em_82546_rev_3)) {
1442 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1443 phy_data |= 0x00000008;
1444 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1445 }
1446
1447 if (hw->mac_type <= em_82543 ||
1448 hw->mac_type == em_82541 || hw->mac_type == em_82547 ||
1449 hw->mac_type == em_82541_rev_2 || hw->mac_type == em_82547_rev_2)
1450 hw->phy_reset_disable = FALSE;
1451
1452 return E1000_SUCCESS;
1453 }
1454
1455
1456
1457
1458
1459
1460
1461 static int32_t
1462 em_copper_link_igp_setup(struct em_hw *hw)
1463 {
1464 uint32_t led_ctrl;
1465 int32_t ret_val;
1466 uint16_t phy_data;
1467
1468 DEBUGFUNC("em_copper_link_igp_setup");
1469
1470 if (hw->phy_reset_disable)
1471 return E1000_SUCCESS;
1472
1473 ret_val = em_phy_reset(hw);
1474 if (ret_val) {
1475 DEBUGOUT("Error Resetting the PHY\n");
1476 return ret_val;
1477 }
1478
1479
1480 msec_delay(15);
1481 if (hw->mac_type != em_ich8lan) {
1482
1483 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1484 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1485 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1486 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1487 }
1488
1489
1490 if (hw->phy_type == em_phy_igp) {
1491
1492 ret_val = em_set_d3_lplu_state(hw, FALSE);
1493 if (ret_val) {
1494 DEBUGOUT("Error Disabling LPLU D3\n");
1495 return ret_val;
1496 }
1497 }
1498
1499
1500 ret_val = em_set_d0_lplu_state(hw, FALSE);
1501 if (ret_val) {
1502 DEBUGOUT("Error Disabling LPLU D0\n");
1503 return ret_val;
1504 }
1505
1506 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1507 if (ret_val)
1508 return ret_val;
1509
1510 if ((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
1511 hw->dsp_config_state = em_dsp_config_disabled;
1512
1513 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1514 hw->mdix = 1;
1515
1516 } else {
1517 hw->dsp_config_state = em_dsp_config_enabled;
1518 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1519
1520 switch (hw->mdix) {
1521 case 1:
1522 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1523 break;
1524 case 2:
1525 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1526 break;
1527 case 0:
1528 default:
1529 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1530 break;
1531 }
1532 }
1533 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1534 if (ret_val)
1535 return ret_val;
1536
1537
1538 if (hw->autoneg) {
1539 em_ms_type phy_ms_setting = hw->master_slave;
1540
1541 if (hw->ffe_config_state == em_ffe_config_active)
1542 hw->ffe_config_state = em_ffe_config_enabled;
1543
1544 if (hw->dsp_config_state == em_dsp_config_activated)
1545 hw->dsp_config_state = em_dsp_config_enabled;
1546
1547
1548
1549
1550 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1551
1552 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1553 &phy_data);
1554 if (ret_val)
1555 return ret_val;
1556 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1557 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1558 phy_data);
1559 if (ret_val)
1560 return ret_val;
1561
1562 ret_val = em_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1563 if (ret_val)
1564 return ret_val;
1565 phy_data &= ~CR_1000T_MS_ENABLE;
1566 ret_val = em_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1567 if (ret_val)
1568 return ret_val;
1569 }
1570
1571 ret_val = em_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1572 if (ret_val)
1573 return ret_val;
1574
1575
1576 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1577 ((phy_data & CR_1000T_MS_VALUE) ?
1578 em_ms_force_master :
1579 em_ms_force_slave) :
1580 em_ms_auto;
1581
1582 switch (phy_ms_setting) {
1583 case em_ms_force_master:
1584 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1585 break;
1586 case em_ms_force_slave:
1587 phy_data |= CR_1000T_MS_ENABLE;
1588 phy_data &= ~(CR_1000T_MS_VALUE);
1589 break;
1590 case em_ms_auto:
1591 phy_data &= ~CR_1000T_MS_ENABLE;
1592 break;
1593 default:
1594 break;
1595 }
1596 ret_val = em_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1597 if (ret_val)
1598 return ret_val;
1599 }
1600
1601 return E1000_SUCCESS;
1602 }
1603
1604
1605
1606
1607
1608
1609 static int32_t
1610 em_copper_link_ggp_setup(struct em_hw *hw)
1611 {
1612 int32_t ret_val;
1613 uint16_t phy_data;
1614 uint32_t reg_data;
1615
1616 DEBUGFUNC("em_copper_link_ggp_setup");
1617
1618 if (!hw->phy_reset_disable) {
1619
1620
1621 ret_val = em_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1622 &phy_data);
1623 if (ret_val)
1624 return ret_val;
1625
1626 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1627
1628 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1629
1630 ret_val = em_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1631 phy_data);
1632 if (ret_val)
1633 return ret_val;
1634
1635
1636
1637
1638
1639
1640
1641
1642 ret_val = em_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1643 if (ret_val)
1644 return ret_val;
1645
1646 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1647
1648 switch (hw->mdix) {
1649 case 1:
1650 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1651 break;
1652 case 2:
1653 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1654 break;
1655 case 0:
1656 default:
1657 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1658 break;
1659 }
1660
1661
1662
1663
1664
1665
1666
1667 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1668 if (hw->disable_polarity_correction == 1)
1669 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1670 ret_val = em_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1671
1672 if (ret_val)
1673 return ret_val;
1674
1675
1676 ret_val = em_phy_reset(hw);
1677 if (ret_val) {
1678 DEBUGOUT("Error Resetting the PHY\n");
1679 return ret_val;
1680 }
1681 }
1682
1683 if (hw->mac_type == em_80003es2lan) {
1684
1685 ret_val = em_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1686 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1687 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1688 if (ret_val)
1689 return ret_val;
1690
1691 ret_val = em_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1692 if (ret_val)
1693 return ret_val;
1694
1695 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1696 ret_val = em_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1697
1698 if (ret_val)
1699 return ret_val;
1700
1701 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1702 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1703 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1704
1705 ret_val = em_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1706 &phy_data);
1707 if (ret_val)
1708 return ret_val;
1709
1710
1711
1712
1713
1714 if (em_check_mng_mode(hw) == FALSE) {
1715
1716 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1717 ret_val = em_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1718 phy_data);
1719 if (ret_val)
1720 return ret_val;
1721
1722 ret_val = em_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1723 &phy_data);
1724 if (ret_val)
1725 return ret_val;
1726
1727 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1728 ret_val = em_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1729 phy_data);
1730
1731 if (ret_val)
1732 return ret_val;
1733 }
1734
1735
1736
1737
1738 ret_val = em_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1739 &phy_data);
1740 if (ret_val)
1741 return ret_val;
1742 phy_data |= GG82563_ICR_DIS_PADDING;
1743 ret_val = em_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1744 phy_data);
1745 if (ret_val)
1746 return ret_val;
1747 }
1748
1749 return E1000_SUCCESS;
1750 }
1751
1752
1753
1754
1755
1756
1757 static int32_t
1758 em_copper_link_mgp_setup(struct em_hw *hw)
1759 {
1760 int32_t ret_val;
1761 uint16_t phy_data;
1762
1763 DEBUGFUNC("em_copper_link_mgp_setup");
1764
1765 if (hw->phy_reset_disable)
1766 return E1000_SUCCESS;
1767
1768
1769 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1770 if (ret_val)
1771 return ret_val;
1772
1773 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1774
1775
1776
1777
1778
1779
1780
1781
1782 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1783
1784 switch (hw->mdix) {
1785 case 1:
1786 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1787 break;
1788 case 2:
1789 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1790 break;
1791 case 3:
1792 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1793 break;
1794 case 0:
1795 default:
1796 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1797 break;
1798 }
1799
1800
1801
1802
1803
1804
1805
1806 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1807 if (hw->disable_polarity_correction == 1)
1808 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1809 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1810 if (ret_val)
1811 return ret_val;
1812
1813 if (hw->phy_revision < M88E1011_I_REV_4) {
1814
1815
1816
1817 ret_val = em_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1818 if (ret_val)
1819 return ret_val;
1820
1821 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1822
1823 if ((hw->phy_revision == E1000_REVISION_2) &&
1824 (hw->phy_id == M88E1111_I_PHY_ID)) {
1825
1826 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1827 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1828 ret_val = em_write_phy_reg(hw,
1829 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1830 if (ret_val)
1831 return ret_val;
1832 } else {
1833
1834 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1835 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1836 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1837 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1838 ret_val = em_write_phy_reg(hw,
1839 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1840 if (ret_val)
1841 return ret_val;
1842 }
1843 }
1844
1845
1846 ret_val = em_phy_reset(hw);
1847 if (ret_val) {
1848 DEBUGOUT("Error Resetting the PHY\n");
1849 return ret_val;
1850 }
1851
1852 return E1000_SUCCESS;
1853 }
1854
1855
1856
1857
1858
1859
1860
1861 static int32_t
1862 em_copper_link_autoneg(struct em_hw *hw)
1863 {
1864 int32_t ret_val;
1865 uint16_t phy_data;
1866
1867 DEBUGFUNC("em_copper_link_autoneg");
1868
1869
1870
1871
1872 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1873
1874
1875
1876
1877 if (hw->autoneg_advertised == 0)
1878 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1879
1880
1881 if (hw->phy_type == em_phy_ife)
1882 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1883
1884 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1885 ret_val = em_phy_setup_autoneg(hw);
1886 if (ret_val) {
1887 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1888 return ret_val;
1889 }
1890 DEBUGOUT("Restarting Auto-Neg\n");
1891
1892
1893
1894
1895 ret_val = em_read_phy_reg(hw, PHY_CTRL, &phy_data);
1896 if (ret_val)
1897 return ret_val;
1898
1899 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1900 ret_val = em_write_phy_reg(hw, PHY_CTRL, phy_data);
1901 if (ret_val)
1902 return ret_val;
1903
1904
1905
1906
1907 if (hw->wait_autoneg_complete) {
1908 ret_val = em_wait_autoneg(hw);
1909 if (ret_val) {
1910 DEBUGOUT("Error while waiting for autoneg to complete\n");
1911 return ret_val;
1912 }
1913 }
1914
1915 hw->get_link_status = TRUE;
1916
1917 return E1000_SUCCESS;
1918 }
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932 static int32_t
1933 em_copper_link_postconfig(struct em_hw *hw)
1934 {
1935 int32_t ret_val;
1936 DEBUGFUNC("em_copper_link_postconfig");
1937
1938 if (hw->mac_type >= em_82544) {
1939 em_config_collision_dist(hw);
1940 } else {
1941 ret_val = em_config_mac_to_phy(hw);
1942 if (ret_val) {
1943 DEBUGOUT("Error configuring MAC to PHY settings\n");
1944 return ret_val;
1945 }
1946 }
1947 ret_val = em_config_fc_after_link_up(hw);
1948 if (ret_val) {
1949 DEBUGOUT("Error Configuring Flow Control\n");
1950 return ret_val;
1951 }
1952
1953
1954 if (hw->phy_type == em_phy_igp) {
1955 ret_val = em_config_dsp_after_link_change(hw, TRUE);
1956 if (ret_val) {
1957 DEBUGOUT("Error Configuring DSP after link up\n");
1958 return ret_val;
1959 }
1960 }
1961
1962 return E1000_SUCCESS;
1963 }
1964
1965
1966
1967
1968
1969
1970 static int32_t
1971 em_setup_copper_link(struct em_hw *hw)
1972 {
1973 int32_t ret_val;
1974 uint16_t i;
1975 uint16_t phy_data;
1976 uint16_t reg_data;
1977
1978 DEBUGFUNC("em_setup_copper_link");
1979
1980 switch (hw->mac_type) {
1981 case em_80003es2lan:
1982 case em_ich8lan:
1983
1984
1985
1986 ret_val = em_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1987 if (ret_val)
1988 return ret_val;
1989 ret_val = em_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1990 if (ret_val)
1991 return ret_val;
1992 reg_data |= 0x3F;
1993 ret_val = em_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1994 if (ret_val)
1995 return ret_val;
1996 default:
1997 break;
1998 }
1999
2000
2001 ret_val = em_copper_link_preconfig(hw);
2002 if (ret_val)
2003 return ret_val;
2004
2005 switch (hw->mac_type) {
2006 case em_80003es2lan:
2007
2008 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
2009 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2010 ret_val = em_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2011 reg_data);
2012 if (ret_val)
2013 return ret_val;
2014 break;
2015 default:
2016 break;
2017 }
2018
2019 if (hw->phy_type == em_phy_igp ||
2020 hw->phy_type == em_phy_igp_3 ||
2021 hw->phy_type == em_phy_igp_2) {
2022 ret_val = em_copper_link_igp_setup(hw);
2023 if (ret_val)
2024 return ret_val;
2025 } else if (hw->phy_type == em_phy_m88) {
2026 ret_val = em_copper_link_mgp_setup(hw);
2027 if (ret_val)
2028 return ret_val;
2029 } else if (hw->phy_type == em_phy_gg82563) {
2030 ret_val = em_copper_link_ggp_setup(hw);
2031 if (ret_val)
2032 return ret_val;
2033 }
2034
2035 if (hw->autoneg) {
2036
2037
2038 ret_val = em_copper_link_autoneg(hw);
2039 if (ret_val)
2040 return ret_val;
2041 } else {
2042
2043
2044 DEBUGOUT("Forcing speed and duplex\n");
2045 ret_val = em_phy_force_speed_duplex(hw);
2046 if (ret_val) {
2047 DEBUGOUT("Error Forcing Speed and Duplex\n");
2048 return ret_val;
2049 }
2050 }
2051
2052
2053
2054
2055 for (i = 0; i < 10; i++) {
2056 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2057 if (ret_val)
2058 return ret_val;
2059 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2060 if (ret_val)
2061 return ret_val;
2062
2063 if (phy_data & MII_SR_LINK_STATUS) {
2064
2065 ret_val = em_copper_link_postconfig(hw);
2066 if (ret_val)
2067 return ret_val;
2068
2069 DEBUGOUT("Valid link established!!!\n");
2070 return E1000_SUCCESS;
2071 }
2072 usec_delay(10);
2073 }
2074
2075 DEBUGOUT("Unable to establish link!!!\n");
2076 return E1000_SUCCESS;
2077 }
2078
2079
2080
2081
2082
2083
2084 static int32_t
2085 em_configure_kmrn_for_10_100(struct em_hw *hw, uint16_t duplex)
2086 {
2087 int32_t ret_val = E1000_SUCCESS;
2088 uint32_t tipg;
2089 uint16_t reg_data;
2090
2091 DEBUGFUNC("em_configure_kmrn_for_10_100");
2092
2093 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2094 ret_val = em_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2095 reg_data);
2096 if (ret_val)
2097 return ret_val;
2098
2099
2100 tipg = E1000_READ_REG(hw, TIPG);
2101 tipg &= ~E1000_TIPG_IPGT_MASK;
2102 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2103 E1000_WRITE_REG(hw, TIPG, tipg);
2104
2105 ret_val = em_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2106
2107 if (ret_val)
2108 return ret_val;
2109
2110 if (duplex == HALF_DUPLEX)
2111 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2112 else
2113 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2114
2115 ret_val = em_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2116
2117 return ret_val;
2118 }
2119
2120 static int32_t
2121 em_configure_kmrn_for_1000(struct em_hw *hw)
2122 {
2123 int32_t ret_val = E1000_SUCCESS;
2124 uint16_t reg_data;
2125 uint32_t tipg;
2126
2127 DEBUGFUNC("em_configure_kmrn_for_1000");
2128
2129 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2130 ret_val = em_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2131 reg_data);
2132 if (ret_val)
2133 return ret_val;
2134
2135
2136 tipg = E1000_READ_REG(hw, TIPG);
2137 tipg &= ~E1000_TIPG_IPGT_MASK;
2138 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2139 E1000_WRITE_REG(hw, TIPG, tipg);
2140
2141 ret_val = em_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2142
2143 if (ret_val)
2144 return ret_val;
2145
2146 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2147 ret_val = em_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2148
2149 return ret_val;
2150 }
2151
2152
2153
2154
2155
2156
2157 int32_t
2158 em_phy_setup_autoneg(struct em_hw *hw)
2159 {
2160 int32_t ret_val;
2161 uint16_t mii_autoneg_adv_reg;
2162 uint16_t mii_1000t_ctrl_reg;
2163
2164 DEBUGFUNC("em_phy_setup_autoneg");
2165
2166
2167 ret_val = em_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2168 if (ret_val)
2169 return ret_val;
2170
2171 if (hw->phy_type != em_phy_ife) {
2172
2173 ret_val = em_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2174 if (ret_val)
2175 return ret_val;
2176 } else
2177 mii_1000t_ctrl_reg=0;
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2191 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2192
2193 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2194
2195
2196 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2197 DEBUGOUT("Advertise 10mb Half duplex\n");
2198 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2199 }
2200
2201
2202 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2203 DEBUGOUT("Advertise 10mb Full duplex\n");
2204 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2205 }
2206
2207
2208 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2209 DEBUGOUT("Advertise 100mb Half duplex\n");
2210 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2211 }
2212
2213
2214 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2215 DEBUGOUT("Advertise 100mb Full duplex\n");
2216 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2217 }
2218
2219
2220 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2221 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2222 }
2223
2224
2225 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2226 DEBUGOUT("Advertise 1000mb Full duplex\n");
2227 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2228 if (hw->phy_type == em_phy_ife) {
2229 DEBUGOUT("em_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2230 }
2231 }
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249 switch (hw->fc) {
2250 case E1000_FC_NONE:
2251
2252
2253
2254 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2255 break;
2256 case E1000_FC_RX_PAUSE:
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2267 break;
2268 case E1000_FC_TX_PAUSE:
2269
2270
2271
2272 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2273 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2274 break;
2275 case E1000_FC_FULL:
2276
2277
2278
2279 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2280 break;
2281 default:
2282 DEBUGOUT("Flow control param set incorrectly\n");
2283 return -E1000_ERR_CONFIG;
2284 }
2285
2286 ret_val = em_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2287 if (ret_val)
2288 return ret_val;
2289
2290 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2291
2292 if (hw->phy_type != em_phy_ife) {
2293 ret_val = em_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2294 if (ret_val)
2295 return ret_val;
2296 }
2297
2298 return E1000_SUCCESS;
2299 }
2300
2301
2302
2303
2304
2305
2306 static int32_t
2307 em_phy_force_speed_duplex(struct em_hw *hw)
2308 {
2309 uint32_t ctrl;
2310 int32_t ret_val;
2311 uint16_t mii_ctrl_reg;
2312 uint16_t mii_status_reg;
2313 uint16_t phy_data;
2314 uint16_t i;
2315
2316 DEBUGFUNC("em_phy_force_speed_duplex");
2317
2318
2319 hw->fc = E1000_FC_NONE;
2320
2321 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2322
2323
2324 ctrl = E1000_READ_REG(hw, CTRL);
2325
2326
2327 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2328 ctrl &= ~(DEVICE_SPEED_MASK);
2329
2330
2331 ctrl &= ~E1000_CTRL_ASDE;
2332
2333
2334 ret_val = em_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2335 if (ret_val)
2336 return ret_val;
2337
2338
2339
2340 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2341
2342
2343 if (hw->forced_speed_duplex == em_100_full ||
2344 hw->forced_speed_duplex == em_10_full) {
2345
2346
2347
2348 ctrl |= E1000_CTRL_FD;
2349 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2350 DEBUGOUT("Full Duplex\n");
2351 } else {
2352
2353
2354
2355 ctrl &= ~E1000_CTRL_FD;
2356 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2357 DEBUGOUT("Half Duplex\n");
2358 }
2359
2360
2361 if (hw->forced_speed_duplex == em_100_full ||
2362 hw->forced_speed_duplex == em_100_half) {
2363
2364 ctrl |= E1000_CTRL_SPD_100;
2365 mii_ctrl_reg |= MII_CR_SPEED_100;
2366 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2367 DEBUGOUT("Forcing 100mb ");
2368 } else {
2369
2370 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2371 mii_ctrl_reg |= MII_CR_SPEED_10;
2372 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2373 DEBUGOUT("Forcing 10mb ");
2374 }
2375
2376 em_config_collision_dist(hw);
2377
2378
2379 E1000_WRITE_REG(hw, CTRL, ctrl);
2380
2381 if ((hw->phy_type == em_phy_m88) ||
2382 (hw->phy_type == em_phy_gg82563)) {
2383 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2384 if (ret_val)
2385 return ret_val;
2386
2387
2388
2389
2390 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2391 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2392 if (ret_val)
2393 return ret_val;
2394
2395 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2396
2397
2398 mii_ctrl_reg |= MII_CR_RESET;
2399
2400 } else if (hw->phy_type == em_phy_ife) {
2401 ret_val = em_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2402 if (ret_val)
2403 return ret_val;
2404
2405 phy_data &= ~IFE_PMC_AUTO_MDIX;
2406 phy_data &= ~IFE_PMC_FORCE_MDIX;
2407
2408 ret_val = em_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2409 if (ret_val)
2410 return ret_val;
2411 } else {
2412
2413
2414
2415 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2416 if (ret_val)
2417 return ret_val;
2418
2419 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2420 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2421
2422 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2423 if (ret_val)
2424 return ret_val;
2425 }
2426
2427
2428 ret_val = em_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2429 if (ret_val)
2430 return ret_val;
2431
2432 usec_delay(1);
2433
2434
2435
2436
2437
2438
2439
2440
2441 if (hw->wait_autoneg_complete) {
2442
2443 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2444 mii_status_reg = 0;
2445
2446
2447 for (i = PHY_FORCE_TIME; i > 0; i--) {
2448
2449
2450
2451 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2452 if (ret_val)
2453 return ret_val;
2454
2455 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2456 if (ret_val)
2457 return ret_val;
2458
2459 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2460 msec_delay(100);
2461 }
2462 if ((i == 0) &&
2463 ((hw->phy_type == em_phy_m88) ||
2464 (hw->phy_type == em_phy_gg82563))) {
2465
2466 ret_val = em_phy_reset_dsp(hw);
2467 if (ret_val) {
2468 DEBUGOUT("Error Resetting PHY DSP\n");
2469 return ret_val;
2470 }
2471 }
2472
2473 for (i = PHY_FORCE_TIME; i > 0; i--) {
2474 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2475 msec_delay(100);
2476
2477
2478
2479 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2480 if (ret_val)
2481 return ret_val;
2482
2483 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2484 if (ret_val)
2485 return ret_val;
2486 }
2487 }
2488
2489 if (hw->phy_type == em_phy_m88) {
2490
2491
2492
2493
2494 ret_val = em_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2495 if (ret_val)
2496 return ret_val;
2497
2498 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2499 ret_val = em_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2500 if (ret_val)
2501 return ret_val;
2502
2503
2504
2505
2506 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2507 if (ret_val)
2508 return ret_val;
2509
2510 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2511 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2512 if (ret_val)
2513 return ret_val;
2514
2515 if ((hw->mac_type == em_82544 || hw->mac_type == em_82543) &&
2516 (!hw->autoneg) && (hw->forced_speed_duplex == em_10_full ||
2517 hw->forced_speed_duplex == em_10_half)) {
2518 ret_val = em_polarity_reversal_workaround(hw);
2519 if (ret_val)
2520 return ret_val;
2521 }
2522 } else if (hw->phy_type == em_phy_gg82563) {
2523
2524
2525
2526 ret_val = em_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2527 if (ret_val)
2528 return ret_val;
2529
2530 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2531 if ((hw->forced_speed_duplex == em_10_full) ||
2532 (hw->forced_speed_duplex == em_10_half))
2533 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2534 else
2535 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2536
2537
2538 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2539
2540 ret_val = em_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2541 if (ret_val)
2542 return ret_val;
2543 }
2544 return E1000_SUCCESS;
2545 }
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555 void
2556 em_config_collision_dist(struct em_hw *hw)
2557 {
2558 uint32_t tctl, coll_dist;
2559
2560 DEBUGFUNC("em_config_collision_dist");
2561
2562 if (hw->mac_type < em_82543)
2563 coll_dist = E1000_COLLISION_DISTANCE_82542;
2564 else
2565 coll_dist = E1000_COLLISION_DISTANCE;
2566
2567 tctl = E1000_READ_REG(hw, TCTL);
2568
2569 tctl &= ~E1000_TCTL_COLD;
2570 tctl |= coll_dist << E1000_COLD_SHIFT;
2571
2572 E1000_WRITE_REG(hw, TCTL, tctl);
2573 E1000_WRITE_FLUSH(hw);
2574 }
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585 static int32_t
2586 em_config_mac_to_phy(struct em_hw *hw)
2587 {
2588 uint32_t ctrl;
2589 int32_t ret_val;
2590 uint16_t phy_data;
2591
2592 DEBUGFUNC("em_config_mac_to_phy");
2593
2594
2595
2596 if (hw->mac_type >= em_82544)
2597 return E1000_SUCCESS;
2598
2599
2600
2601
2602 ctrl = E1000_READ_REG(hw, CTRL);
2603 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2604 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2605
2606
2607
2608
2609 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2610 if (ret_val)
2611 return ret_val;
2612
2613 if (phy_data & M88E1000_PSSR_DPLX)
2614 ctrl |= E1000_CTRL_FD;
2615 else
2616 ctrl &= ~E1000_CTRL_FD;
2617
2618 em_config_collision_dist(hw);
2619
2620
2621
2622
2623 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2624 ctrl |= E1000_CTRL_SPD_1000;
2625 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2626 ctrl |= E1000_CTRL_SPD_100;
2627
2628
2629 E1000_WRITE_REG(hw, CTRL, ctrl);
2630 return E1000_SUCCESS;
2631 }
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644 int32_t
2645 em_force_mac_fc(struct em_hw *hw)
2646 {
2647 uint32_t ctrl;
2648
2649 DEBUGFUNC("em_force_mac_fc");
2650
2651
2652 ctrl = E1000_READ_REG(hw, CTRL);
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672 switch (hw->fc) {
2673 case E1000_FC_NONE:
2674 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2675 break;
2676 case E1000_FC_RX_PAUSE:
2677 ctrl &= (~E1000_CTRL_TFCE);
2678 ctrl |= E1000_CTRL_RFCE;
2679 break;
2680 case E1000_FC_TX_PAUSE:
2681 ctrl &= (~E1000_CTRL_RFCE);
2682 ctrl |= E1000_CTRL_TFCE;
2683 break;
2684 case E1000_FC_FULL:
2685 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2686 break;
2687 default:
2688 DEBUGOUT("Flow control param set incorrectly\n");
2689 return -E1000_ERR_CONFIG;
2690 }
2691
2692
2693 if (hw->mac_type == em_82542_rev2_0)
2694 ctrl &= (~E1000_CTRL_TFCE);
2695
2696 E1000_WRITE_REG(hw, CTRL, ctrl);
2697 return E1000_SUCCESS;
2698 }
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711 STATIC int32_t
2712 em_config_fc_after_link_up(struct em_hw *hw)
2713 {
2714 int32_t ret_val;
2715 uint16_t mii_status_reg;
2716 uint16_t mii_nway_adv_reg;
2717 uint16_t mii_nway_lp_ability_reg;
2718 uint16_t speed;
2719 uint16_t duplex;
2720
2721 DEBUGFUNC("em_config_fc_after_link_up");
2722
2723
2724
2725
2726
2727 if (((hw->media_type == em_media_type_fiber) && (hw->autoneg_failed)) ||
2728 ((hw->media_type == em_media_type_internal_serdes) &&
2729 (hw->autoneg_failed)) ||
2730 ((hw->media_type == em_media_type_copper) && (!hw->autoneg))) {
2731 ret_val = em_force_mac_fc(hw);
2732 if (ret_val) {
2733 DEBUGOUT("Error forcing flow control settings\n");
2734 return ret_val;
2735 }
2736 }
2737
2738
2739
2740
2741
2742
2743 if ((hw->media_type == em_media_type_copper) && hw->autoneg) {
2744
2745
2746
2747
2748 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2749 if (ret_val)
2750 return ret_val;
2751 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2752 if (ret_val)
2753 return ret_val;
2754
2755 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2756
2757
2758
2759
2760
2761
2762 ret_val = em_read_phy_reg(hw, PHY_AUTONEG_ADV,
2763 &mii_nway_adv_reg);
2764 if (ret_val)
2765 return ret_val;
2766 ret_val = em_read_phy_reg(hw, PHY_LP_ABILITY,
2767 &mii_nway_lp_ability_reg);
2768 if (ret_val)
2769 return ret_val;
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2806 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2807
2808
2809
2810
2811
2812
2813 if (hw->original_fc == E1000_FC_FULL) {
2814 hw->fc = E1000_FC_FULL;
2815 DEBUGOUT("Flow Control = FULL.\n");
2816 } else {
2817 hw->fc = E1000_FC_RX_PAUSE;
2818 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2819 }
2820 }
2821
2822
2823
2824
2825
2826
2827
2828
2829 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2830 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2831 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2832 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2833 hw->fc = E1000_FC_TX_PAUSE;
2834 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2835 }
2836
2837
2838
2839
2840
2841
2842
2843
2844 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2845 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2846 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2847 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2848 hw->fc = E1000_FC_RX_PAUSE;
2849 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2850 }
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871 else if ((hw->original_fc == E1000_FC_NONE||
2872 hw->original_fc == E1000_FC_TX_PAUSE) ||
2873 hw->fc_strict_ieee) {
2874 hw->fc = E1000_FC_NONE;
2875 DEBUGOUT("Flow Control = NONE.\n");
2876 } else {
2877 hw->fc = E1000_FC_RX_PAUSE;
2878 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2879 }
2880
2881
2882
2883
2884
2885 ret_val = em_get_speed_and_duplex(hw, &speed, &duplex);
2886 if (ret_val) {
2887 DEBUGOUT("Error getting link speed and duplex\n");
2888 return ret_val;
2889 }
2890
2891 if (duplex == HALF_DUPLEX)
2892 hw->fc = E1000_FC_NONE;
2893
2894
2895
2896
2897 ret_val = em_force_mac_fc(hw);
2898 if (ret_val) {
2899 DEBUGOUT("Error forcing flow control settings\n");
2900 return ret_val;
2901 }
2902 } else {
2903 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2904 }
2905 }
2906 return E1000_SUCCESS;
2907 }
2908
2909
2910
2911
2912
2913
2914
2915
2916 int32_t
2917 em_check_for_link(struct em_hw *hw)
2918 {
2919 uint32_t rxcw = 0;
2920 uint32_t ctrl;
2921 uint32_t status;
2922 uint32_t rctl;
2923 uint32_t icr;
2924 uint32_t signal = 0;
2925 int32_t ret_val;
2926 uint16_t phy_data;
2927
2928 DEBUGFUNC("em_check_for_link");
2929
2930 ctrl = E1000_READ_REG(hw, CTRL);
2931 status = E1000_READ_REG(hw, STATUS);
2932
2933
2934
2935
2936
2937 if ((hw->media_type == em_media_type_fiber) ||
2938 (hw->media_type == em_media_type_internal_serdes)) {
2939 rxcw = E1000_READ_REG(hw, RXCW);
2940
2941 if (hw->media_type == em_media_type_fiber) {
2942 signal = (hw->mac_type > em_82544) ? E1000_CTRL_SWDPIN1 : 0;
2943 if (status & E1000_STATUS_LU)
2944 hw->get_link_status = FALSE;
2945 }
2946 }
2947
2948
2949
2950
2951
2952
2953
2954 if ((hw->media_type == em_media_type_copper) && hw->get_link_status) {
2955
2956
2957
2958
2959
2960 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2961 if (ret_val)
2962 return ret_val;
2963 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2964 if (ret_val)
2965 return ret_val;
2966
2967 if (phy_data & MII_SR_LINK_STATUS) {
2968 hw->get_link_status = FALSE;
2969
2970
2971 em_check_downshift(hw);
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981 if ((hw->mac_type == em_82544 || hw->mac_type == em_82543) &&
2982 (!hw->autoneg) &&
2983 (hw->forced_speed_duplex == em_10_full ||
2984 hw->forced_speed_duplex == em_10_half)) {
2985 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2986 ret_val = em_polarity_reversal_workaround(hw);
2987 icr = E1000_READ_REG(hw, ICR);
2988 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2989 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2990 }
2991
2992 } else {
2993
2994 em_config_dsp_after_link_change(hw, FALSE);
2995 return 0;
2996 }
2997
2998
2999
3000
3001 if (!hw->autoneg) return -E1000_ERR_CONFIG;
3002
3003
3004 em_config_dsp_after_link_change(hw, TRUE);
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014 if (hw->mac_type >= em_82544)
3015 em_config_collision_dist(hw);
3016 else {
3017 ret_val = em_config_mac_to_phy(hw);
3018 if (ret_val) {
3019 DEBUGOUT("Error configuring MAC to PHY settings\n");
3020 return ret_val;
3021 }
3022 }
3023
3024
3025
3026
3027
3028 ret_val = em_config_fc_after_link_up(hw);
3029 if (ret_val) {
3030 DEBUGOUT("Error configuring flow control\n");
3031 return ret_val;
3032 }
3033
3034
3035
3036
3037
3038
3039
3040
3041 if (hw->tbi_compatibility_en) {
3042 uint16_t speed, duplex;
3043 ret_val = em_get_speed_and_duplex(hw, &speed, &duplex);
3044 if (ret_val) {
3045 DEBUGOUT("Error getting link speed and duplex\n");
3046 return ret_val;
3047 }
3048 if (speed != SPEED_1000) {
3049
3050
3051
3052 if (hw->tbi_compatibility_on) {
3053
3054 rctl = E1000_READ_REG(hw, RCTL);
3055 rctl &= ~E1000_RCTL_SBP;
3056 E1000_WRITE_REG(hw, RCTL, rctl);
3057 hw->tbi_compatibility_on = FALSE;
3058 }
3059 } else {
3060
3061
3062
3063
3064
3065 if (!hw->tbi_compatibility_on) {
3066 hw->tbi_compatibility_on = TRUE;
3067 rctl = E1000_READ_REG(hw, RCTL);
3068 rctl |= E1000_RCTL_SBP;
3069 E1000_WRITE_REG(hw, RCTL, rctl);
3070 }
3071 }
3072 }
3073 }
3074
3075
3076
3077
3078
3079
3080
3081 else if ((((hw->media_type == em_media_type_fiber) &&
3082 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3083 (hw->media_type == em_media_type_internal_serdes)) &&
3084 (!(status & E1000_STATUS_LU)) &&
3085 (!(rxcw & E1000_RXCW_C))) {
3086 if (hw->autoneg_failed == 0) {
3087 hw->autoneg_failed = 1;
3088 return 0;
3089 }
3090 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3091
3092
3093 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3094
3095
3096 ctrl = E1000_READ_REG(hw, CTRL);
3097 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3098 E1000_WRITE_REG(hw, CTRL, ctrl);
3099
3100
3101 ret_val = em_config_fc_after_link_up(hw);
3102 if (ret_val) {
3103 DEBUGOUT("Error configuring flow control\n");
3104 return ret_val;
3105 }
3106 }
3107
3108
3109
3110
3111
3112 else if (((hw->media_type == em_media_type_fiber) ||
3113 (hw->media_type == em_media_type_internal_serdes)) &&
3114 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3115 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3116 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3117 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3118
3119 hw->serdes_link_down = FALSE;
3120 }
3121
3122
3123
3124 else if ((hw->media_type == em_media_type_internal_serdes) &&
3125 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3126
3127 usec_delay(10);
3128 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3129 if (!(rxcw & E1000_RXCW_IV)) {
3130 hw->serdes_link_down = FALSE;
3131 DEBUGOUT("SERDES: Link is up.\n");
3132 }
3133 } else {
3134 hw->serdes_link_down = TRUE;
3135 DEBUGOUT("SERDES: Link is down.\n");
3136 }
3137 }
3138 if ((hw->media_type == em_media_type_internal_serdes) &&
3139 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3140 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3141 }
3142 return E1000_SUCCESS;
3143 }
3144
3145
3146
3147
3148
3149
3150
3151
3152 int32_t
3153 em_get_speed_and_duplex(struct em_hw *hw,
3154 uint16_t *speed,
3155 uint16_t *duplex)
3156 {
3157 uint32_t status;
3158 int32_t ret_val;
3159 uint16_t phy_data;
3160
3161 DEBUGFUNC("em_get_speed_and_duplex");
3162
3163 if (hw->mac_type >= em_82543) {
3164 status = E1000_READ_REG(hw, STATUS);
3165 if (status & E1000_STATUS_SPEED_1000) {
3166 *speed = SPEED_1000;
3167 DEBUGOUT("1000 Mbs, ");
3168 } else if (status & E1000_STATUS_SPEED_100) {
3169 *speed = SPEED_100;
3170 DEBUGOUT("100 Mbs, ");
3171 } else {
3172 *speed = SPEED_10;
3173 DEBUGOUT("10 Mbs, ");
3174 }
3175
3176 if (status & E1000_STATUS_FD) {
3177 *duplex = FULL_DUPLEX;
3178 DEBUGOUT("Full Duplex\n");
3179 } else {
3180 *duplex = HALF_DUPLEX;
3181 DEBUGOUT(" Half Duplex\n");
3182 }
3183 } else {
3184 DEBUGOUT("1000 Mbs, Full Duplex\n");
3185 *speed = SPEED_1000;
3186 *duplex = FULL_DUPLEX;
3187 }
3188
3189
3190
3191
3192
3193 if (hw->phy_type == em_phy_igp && hw->speed_downgraded) {
3194 ret_val = em_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3195 if (ret_val)
3196 return ret_val;
3197
3198 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3199 *duplex = HALF_DUPLEX;
3200 else {
3201 ret_val = em_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3202 if (ret_val)
3203 return ret_val;
3204 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3205 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3206 *duplex = HALF_DUPLEX;
3207 }
3208 }
3209
3210 if ((hw->mac_type == em_80003es2lan) &&
3211 (hw->media_type == em_media_type_copper)) {
3212 if (*speed == SPEED_1000)
3213 ret_val = em_configure_kmrn_for_1000(hw);
3214 else
3215 ret_val = em_configure_kmrn_for_10_100(hw, *duplex);
3216 if (ret_val)
3217 return ret_val;
3218 }
3219
3220 if ((hw->phy_type == em_phy_igp_3) && (*speed == SPEED_1000)) {
3221 ret_val = em_kumeran_lock_loss_workaround(hw);
3222 if (ret_val)
3223 return ret_val;
3224 }
3225
3226 return E1000_SUCCESS;
3227 }
3228
3229
3230
3231
3232
3233
3234 STATIC int32_t
3235 em_wait_autoneg(struct em_hw *hw)
3236 {
3237 int32_t ret_val;
3238 uint16_t i;
3239 uint16_t phy_data;
3240
3241 DEBUGFUNC("em_wait_autoneg");
3242 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3243
3244
3245 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3246
3247
3248
3249 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
3250 if (ret_val)
3251 return ret_val;
3252 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
3253 if (ret_val)
3254 return ret_val;
3255 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3256 return E1000_SUCCESS;
3257 }
3258 msec_delay(100);
3259 }
3260 return E1000_SUCCESS;
3261 }
3262
3263
3264
3265
3266
3267
3268
3269 static void
3270 em_raise_mdi_clk(struct em_hw *hw,
3271 uint32_t *ctrl)
3272 {
3273
3274
3275
3276 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3277 E1000_WRITE_FLUSH(hw);
3278 usec_delay(10);
3279 }
3280
3281
3282
3283
3284
3285
3286
3287 static void
3288 em_lower_mdi_clk(struct em_hw *hw,
3289 uint32_t *ctrl)
3290 {
3291
3292
3293
3294 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3295 E1000_WRITE_FLUSH(hw);
3296 usec_delay(10);
3297 }
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308 static void
3309 em_shift_out_mdi_bits(struct em_hw *hw,
3310 uint32_t data,
3311 uint16_t count)
3312 {
3313 uint32_t ctrl;
3314 uint32_t mask;
3315
3316
3317
3318
3319
3320 mask = 0x01;
3321 mask <<= (count - 1);
3322
3323 ctrl = E1000_READ_REG(hw, CTRL);
3324
3325
3326 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3327
3328 while (mask) {
3329
3330
3331
3332
3333
3334 if (data & mask)
3335 ctrl |= E1000_CTRL_MDIO;
3336 else
3337 ctrl &= ~E1000_CTRL_MDIO;
3338
3339 E1000_WRITE_REG(hw, CTRL, ctrl);
3340 E1000_WRITE_FLUSH(hw);
3341
3342 usec_delay(10);
3343
3344 em_raise_mdi_clk(hw, &ctrl);
3345 em_lower_mdi_clk(hw, &ctrl);
3346
3347 mask = mask >> 1;
3348 }
3349 }
3350
3351
3352
3353
3354
3355
3356
3357
3358 static uint16_t
3359 em_shift_in_mdi_bits(struct em_hw *hw)
3360 {
3361 uint32_t ctrl;
3362 uint16_t data = 0;
3363 uint8_t i;
3364
3365
3366
3367
3368
3369
3370
3371
3372 ctrl = E1000_READ_REG(hw, CTRL);
3373
3374
3375 ctrl &= ~E1000_CTRL_MDIO_DIR;
3376 ctrl &= ~E1000_CTRL_MDIO;
3377
3378 E1000_WRITE_REG(hw, CTRL, ctrl);
3379 E1000_WRITE_FLUSH(hw);
3380
3381
3382
3383
3384
3385 em_raise_mdi_clk(hw, &ctrl);
3386 em_lower_mdi_clk(hw, &ctrl);
3387
3388 for (data = 0, i = 0; i < 16; i++) {
3389 data = data << 1;
3390 em_raise_mdi_clk(hw, &ctrl);
3391 ctrl = E1000_READ_REG(hw, CTRL);
3392
3393 if (ctrl & E1000_CTRL_MDIO)
3394 data |= 1;
3395 em_lower_mdi_clk(hw, &ctrl);
3396 }
3397
3398 em_raise_mdi_clk(hw, &ctrl);
3399 em_lower_mdi_clk(hw, &ctrl);
3400
3401 return data;
3402 }
3403
3404 STATIC int32_t
3405 em_swfw_sync_acquire(struct em_hw *hw, uint16_t mask)
3406 {
3407 uint32_t swfw_sync = 0;
3408 uint32_t swmask = mask;
3409 uint32_t fwmask = mask << 16;
3410 int32_t timeout = 200;
3411
3412 DEBUGFUNC("em_swfw_sync_acquire");
3413
3414 if (hw->swfwhw_semaphore_present)
3415 return em_get_software_flag(hw);
3416
3417 if (!hw->swfw_sync_present)
3418 return em_get_hw_eeprom_semaphore(hw);
3419
3420 while (timeout) {
3421 if (em_get_hw_eeprom_semaphore(hw))
3422 return -E1000_ERR_SWFW_SYNC;
3423
3424 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3425 if (!(swfw_sync & (fwmask | swmask))) {
3426 break;
3427 }
3428
3429
3430
3431 em_put_hw_eeprom_semaphore(hw);
3432 msec_delay_irq(5);
3433 timeout--;
3434 }
3435
3436 if (!timeout) {
3437 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3438 return -E1000_ERR_SWFW_SYNC;
3439 }
3440
3441 swfw_sync |= swmask;
3442 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3443
3444 em_put_hw_eeprom_semaphore(hw);
3445 return E1000_SUCCESS;
3446 }
3447
3448 STATIC void
3449 em_swfw_sync_release(struct em_hw *hw, uint16_t mask)
3450 {
3451 uint32_t swfw_sync;
3452 uint32_t swmask = mask;
3453
3454 DEBUGFUNC("em_swfw_sync_release");
3455
3456 if (hw->swfwhw_semaphore_present) {
3457 em_release_software_flag(hw);
3458 return;
3459 }
3460
3461 if (!hw->swfw_sync_present) {
3462 em_put_hw_eeprom_semaphore(hw);
3463 return;
3464 }
3465
3466
3467
3468 while (em_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3469
3470
3471 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3472 swfw_sync &= ~swmask;
3473 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3474
3475 em_put_hw_eeprom_semaphore(hw);
3476 }
3477
3478
3479
3480
3481
3482
3483
3484 int32_t
3485 em_read_phy_reg(struct em_hw *hw,
3486 uint32_t reg_addr,
3487 uint16_t *phy_data)
3488 {
3489 uint32_t ret_val;
3490 uint16_t swfw;
3491
3492 DEBUGFUNC("em_read_phy_reg");
3493
3494 if ((hw->mac_type == em_80003es2lan) &&
3495 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3496 swfw = E1000_SWFW_PHY1_SM;
3497 } else {
3498 swfw = E1000_SWFW_PHY0_SM;
3499 }
3500 if (em_swfw_sync_acquire(hw, swfw))
3501 return -E1000_ERR_SWFW_SYNC;
3502
3503 if ((hw->phy_type == em_phy_igp ||
3504 hw->phy_type == em_phy_igp_3 ||
3505 hw->phy_type == em_phy_igp_2) &&
3506 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3507 ret_val = em_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3508 (uint16_t)reg_addr);
3509 if (ret_val) {
3510 em_swfw_sync_release(hw, swfw);
3511 return ret_val;
3512 }
3513 } else if (hw->phy_type == em_phy_gg82563) {
3514 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3515 (hw->mac_type == em_80003es2lan)) {
3516
3517 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3518 ret_val = em_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3519 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3520 } else {
3521
3522
3523
3524 ret_val = em_write_phy_reg_ex(hw,
3525 GG82563_PHY_PAGE_SELECT_ALT,
3526 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3527 }
3528
3529 if (ret_val) {
3530 em_swfw_sync_release(hw, swfw);
3531 return ret_val;
3532 }
3533 }
3534 }
3535
3536 ret_val = em_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3537 phy_data);
3538
3539 em_swfw_sync_release(hw, swfw);
3540 return ret_val;
3541 }
3542
3543 STATIC int32_t
3544 em_read_phy_reg_ex(struct em_hw *hw, uint32_t reg_addr,
3545 uint16_t *phy_data)
3546 {
3547 uint32_t i;
3548 uint32_t mdic = 0;
3549 const uint32_t phy_addr = 1;
3550
3551 DEBUGFUNC("em_read_phy_reg_ex");
3552
3553 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3554 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3555 return -E1000_ERR_PARAM;
3556 }
3557
3558 if (hw->mac_type > em_82543) {
3559
3560
3561
3562
3563 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3564 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3565 (E1000_MDIC_OP_READ));
3566
3567 E1000_WRITE_REG(hw, MDIC, mdic);
3568
3569
3570 for (i = 0; i < 64; i++) {
3571 usec_delay(50);
3572 mdic = E1000_READ_REG(hw, MDIC);
3573 if (mdic & E1000_MDIC_READY) break;
3574 }
3575 if (!(mdic & E1000_MDIC_READY)) {
3576 DEBUGOUT("MDI Read did not complete\n");
3577 return -E1000_ERR_PHY;
3578 }
3579 if (mdic & E1000_MDIC_ERROR) {
3580 DEBUGOUT("MDI Error\n");
3581 return -E1000_ERR_PHY;
3582 }
3583 *phy_data = (uint16_t) mdic;
3584 } else {
3585
3586
3587
3588
3589 em_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602 mdic = ((reg_addr) | (phy_addr << 5) |
3603 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3604
3605 em_shift_out_mdi_bits(hw, mdic, 14);
3606
3607
3608
3609
3610
3611 *phy_data = em_shift_in_mdi_bits(hw);
3612 }
3613 return E1000_SUCCESS;
3614 }
3615
3616
3617
3618
3619
3620
3621
3622
3623 int32_t
3624 em_write_phy_reg(struct em_hw *hw, uint32_t reg_addr,
3625 uint16_t phy_data)
3626 {
3627 uint32_t ret_val;
3628 uint16_t swfw;
3629
3630 DEBUGFUNC("em_write_phy_reg");
3631
3632 if ((hw->mac_type == em_80003es2lan) &&
3633 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3634 swfw = E1000_SWFW_PHY1_SM;
3635 } else {
3636 swfw = E1000_SWFW_PHY0_SM;
3637 }
3638 if (em_swfw_sync_acquire(hw, swfw))
3639 return -E1000_ERR_SWFW_SYNC;
3640
3641 if ((hw->phy_type == em_phy_igp ||
3642 hw->phy_type == em_phy_igp_3 ||
3643 hw->phy_type == em_phy_igp_2) &&
3644 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3645 ret_val = em_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3646 (uint16_t)reg_addr);
3647 if (ret_val) {
3648 em_swfw_sync_release(hw, swfw);
3649 return ret_val;
3650 }
3651 } else if (hw->phy_type == em_phy_gg82563) {
3652 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3653 (hw->mac_type == em_80003es2lan)) {
3654
3655 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3656 ret_val = em_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3657 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3658 } else {
3659
3660
3661
3662 ret_val = em_write_phy_reg_ex(hw,
3663 GG82563_PHY_PAGE_SELECT_ALT,
3664 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3665 }
3666
3667 if (ret_val) {
3668 em_swfw_sync_release(hw, swfw);
3669 return ret_val;
3670 }
3671 }
3672 }
3673
3674 ret_val = em_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3675 phy_data);
3676
3677 em_swfw_sync_release(hw, swfw);
3678 return ret_val;
3679 }
3680
3681 STATIC int32_t
3682 em_write_phy_reg_ex(struct em_hw *hw, uint32_t reg_addr,
3683 uint16_t phy_data)
3684 {
3685 uint32_t i;
3686 uint32_t mdic = 0;
3687 const uint32_t phy_addr = 1;
3688
3689 DEBUGFUNC("em_write_phy_reg_ex");
3690
3691 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3692 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3693 return -E1000_ERR_PARAM;
3694 }
3695
3696 if (hw->mac_type > em_82543) {
3697
3698
3699
3700
3701 mdic = (((uint32_t) phy_data) |
3702 (reg_addr << E1000_MDIC_REG_SHIFT) |
3703 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3704 (E1000_MDIC_OP_WRITE));
3705
3706 E1000_WRITE_REG(hw, MDIC, mdic);
3707
3708
3709 for (i = 0; i < 641; i++) {
3710 usec_delay(5);
3711 mdic = E1000_READ_REG(hw, MDIC);
3712 if (mdic & E1000_MDIC_READY) break;
3713 }
3714 if (!(mdic & E1000_MDIC_READY)) {
3715 DEBUGOUT("MDI Write did not complete\n");
3716 return -E1000_ERR_PHY;
3717 }
3718 } else {
3719
3720
3721
3722
3723
3724 em_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3725
3726
3727
3728
3729
3730
3731
3732 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3733 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3734 mdic <<= 16;
3735 mdic |= (uint32_t) phy_data;
3736
3737 em_shift_out_mdi_bits(hw, mdic, 32);
3738 }
3739
3740 return E1000_SUCCESS;
3741 }
3742
3743 STATIC int32_t
3744 em_read_kmrn_reg(struct em_hw *hw,
3745 uint32_t reg_addr,
3746 uint16_t *data)
3747 {
3748 uint32_t reg_val;
3749 uint16_t swfw;
3750 DEBUGFUNC("em_read_kmrn_reg");
3751
3752 if ((hw->mac_type == em_80003es2lan) &&
3753 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3754 swfw = E1000_SWFW_PHY1_SM;
3755 } else {
3756 swfw = E1000_SWFW_PHY0_SM;
3757 }
3758 if (em_swfw_sync_acquire(hw, swfw))
3759 return -E1000_ERR_SWFW_SYNC;
3760
3761
3762 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3763 E1000_KUMCTRLSTA_OFFSET) |
3764 E1000_KUMCTRLSTA_REN;
3765 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3766 usec_delay(2);
3767
3768
3769 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3770 *data = (uint16_t)reg_val;
3771
3772 em_swfw_sync_release(hw, swfw);
3773 return E1000_SUCCESS;
3774 }
3775
3776 STATIC int32_t
3777 em_write_kmrn_reg(struct em_hw *hw,
3778 uint32_t reg_addr,
3779 uint16_t data)
3780 {
3781 uint32_t reg_val;
3782 uint16_t swfw;
3783 DEBUGFUNC("em_write_kmrn_reg");
3784
3785 if ((hw->mac_type == em_80003es2lan) &&
3786 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3787 swfw = E1000_SWFW_PHY1_SM;
3788 } else {
3789 swfw = E1000_SWFW_PHY0_SM;
3790 }
3791 if (em_swfw_sync_acquire(hw, swfw))
3792 return -E1000_ERR_SWFW_SYNC;
3793
3794 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3795 E1000_KUMCTRLSTA_OFFSET) | data;
3796 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3797 usec_delay(2);
3798
3799 em_swfw_sync_release(hw, swfw);
3800 return E1000_SUCCESS;
3801 }
3802
3803
3804
3805
3806
3807
3808 int32_t
3809 em_phy_hw_reset(struct em_hw *hw)
3810 {
3811 uint32_t ctrl, ctrl_ext;
3812 uint32_t led_ctrl;
3813 int32_t ret_val;
3814 uint16_t swfw;
3815
3816 DEBUGFUNC("em_phy_hw_reset");
3817
3818
3819
3820 ret_val = em_check_phy_reset_block(hw);
3821 if (ret_val)
3822 return E1000_SUCCESS;
3823
3824 DEBUGOUT("Resetting Phy...\n");
3825
3826 if (hw->mac_type > em_82543) {
3827 if ((hw->mac_type == em_80003es2lan) &&
3828 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3829 swfw = E1000_SWFW_PHY1_SM;
3830 } else {
3831 swfw = E1000_SWFW_PHY0_SM;
3832 }
3833 if (em_swfw_sync_acquire(hw, swfw)) {
3834 DEBUGOUT("Unable to acquire swfw sync\n");
3835 return -E1000_ERR_SWFW_SYNC;
3836 }
3837
3838
3839
3840
3841
3842
3843 ctrl = E1000_READ_REG(hw, CTRL);
3844 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3845 E1000_WRITE_FLUSH(hw);
3846
3847 if (hw->mac_type < em_82571)
3848 msec_delay(10);
3849 else
3850 usec_delay(100);
3851
3852 E1000_WRITE_REG(hw, CTRL, ctrl);
3853 E1000_WRITE_FLUSH(hw);
3854
3855 if (hw->mac_type >= em_82571)
3856 msec_delay_irq(10);
3857 em_swfw_sync_release(hw, swfw);
3858 } else {
3859
3860
3861
3862 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3863 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3864 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3865 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3866 E1000_WRITE_FLUSH(hw);
3867 msec_delay(10);
3868 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3869 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3870 E1000_WRITE_FLUSH(hw);
3871 }
3872 usec_delay(150);
3873
3874 if ((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
3875
3876 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3877 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3878 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3879 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3880 }
3881
3882
3883 ret_val = em_get_phy_cfg_done(hw);
3884 if (ret_val != E1000_SUCCESS)
3885 return ret_val;
3886 em_release_software_semaphore(hw);
3887
3888 if ((hw->mac_type == em_ich8lan) && (hw->phy_type == em_phy_igp_3))
3889 ret_val = em_init_lcd_from_nvm(hw);
3890
3891 return ret_val;
3892 }
3893
3894
3895
3896
3897
3898
3899
3900
3901 int32_t
3902 em_phy_reset(struct em_hw *hw)
3903 {
3904 int32_t ret_val;
3905 uint16_t phy_data;
3906
3907 DEBUGFUNC("em_phy_reset");
3908
3909
3910
3911 ret_val = em_check_phy_reset_block(hw);
3912 if (ret_val)
3913 return E1000_SUCCESS;
3914
3915 switch (hw->phy_type) {
3916 case em_phy_igp:
3917 case em_phy_igp_2:
3918 case em_phy_igp_3:
3919 case em_phy_ife:
3920 ret_val = em_phy_hw_reset(hw);
3921 if (ret_val)
3922 return ret_val;
3923 break;
3924 default:
3925 ret_val = em_read_phy_reg(hw, PHY_CTRL, &phy_data);
3926 if (ret_val)
3927 return ret_val;
3928
3929 phy_data |= MII_CR_RESET;
3930 ret_val = em_write_phy_reg(hw, PHY_CTRL, phy_data);
3931 if (ret_val)
3932 return ret_val;
3933
3934 usec_delay(1);
3935 break;
3936 }
3937
3938 if (hw->phy_type == em_phy_igp || hw->phy_type == em_phy_igp_2)
3939 em_phy_init_script(hw);
3940
3941 return E1000_SUCCESS;
3942 }
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958 STATIC int32_t
3959 em_kumeran_lock_loss_workaround(struct em_hw *hw)
3960 {
3961 int32_t ret_val;
3962 int32_t reg;
3963 int32_t cnt;
3964 uint16_t phy_data;
3965
3966 if (hw->kmrn_lock_loss_workaround_disabled)
3967 return E1000_SUCCESS;
3968
3969
3970
3971
3972 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
3973 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
3974
3975 if (phy_data & MII_SR_LINK_STATUS) {
3976 for (cnt = 0; cnt < 10; cnt++) {
3977
3978 ret_val = em_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3979 if (ret_val)
3980 return ret_val;
3981
3982 ret_val = em_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3983 if (ret_val)
3984 return ret_val;
3985
3986
3987 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3988 return E1000_SUCCESS;
3989
3990
3991 em_phy_hw_reset(hw);
3992 msec_delay_irq(5);
3993 }
3994
3995 reg = E1000_READ_REG(hw, PHY_CTRL);
3996 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3997 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3998
3999
4000 return E1000_ERR_PHY;
4001 }
4002
4003 return E1000_SUCCESS;
4004 }
4005
4006
4007
4008
4009
4010
4011 STATIC int32_t
4012 em_detect_gig_phy(struct em_hw *hw)
4013 {
4014 int32_t phy_init_status, ret_val;
4015 uint16_t phy_id_high, phy_id_low;
4016 boolean_t match = FALSE;
4017
4018 DEBUGFUNC("em_detect_gig_phy");
4019
4020 if (hw->phy_id != 0)
4021 return E1000_SUCCESS;
4022
4023
4024
4025
4026 if (hw->mac_type == em_82571 ||
4027 hw->mac_type == em_82572) {
4028 hw->phy_id = IGP01E1000_I_PHY_ID;
4029 hw->phy_type = em_phy_igp_2;
4030 return E1000_SUCCESS;
4031 }
4032
4033
4034
4035
4036
4037
4038
4039 if (hw->mac_type == em_80003es2lan)
4040 hw->phy_type = em_phy_gg82563;
4041
4042
4043 ret_val = em_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4044 if (ret_val)
4045 return ret_val;
4046
4047 hw->phy_id = (uint32_t) (phy_id_high << 16);
4048 usec_delay(20);
4049 ret_val = em_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4050 if (ret_val)
4051 return ret_val;
4052
4053 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4054 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4055
4056 switch (hw->mac_type) {
4057 case em_82543:
4058 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
4059 break;
4060 case em_82544:
4061 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
4062 break;
4063 case em_82540:
4064 case em_82545:
4065 case em_82545_rev_3:
4066 case em_82546:
4067 case em_82546_rev_3:
4068 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
4069 break;
4070 case em_82541:
4071 case em_82541_rev_2:
4072 case em_82547:
4073 case em_82547_rev_2:
4074 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
4075 break;
4076 case em_82573:
4077 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
4078 break;
4079 case em_80003es2lan:
4080 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4081 break;
4082 case em_ich8lan:
4083 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4084 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4085 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4086 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4087 break;
4088 default:
4089 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4090 return -E1000_ERR_CONFIG;
4091 }
4092 phy_init_status = em_set_phy_type(hw);
4093
4094 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4095 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4096 return E1000_SUCCESS;
4097 }
4098 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4099 return -E1000_ERR_PHY;
4100 }
4101
4102
4103
4104
4105
4106
4107 static int32_t
4108 em_phy_reset_dsp(struct em_hw *hw)
4109 {
4110 int32_t ret_val;
4111 DEBUGFUNC("em_phy_reset_dsp");
4112
4113 do {
4114 if (hw->phy_type != em_phy_gg82563) {
4115 ret_val = em_write_phy_reg(hw, 29, 0x001d);
4116 if (ret_val) break;
4117 }
4118 ret_val = em_write_phy_reg(hw, 30, 0x00c1);
4119 if (ret_val) break;
4120 ret_val = em_write_phy_reg(hw, 30, 0x0000);
4121 if (ret_val) break;
4122 ret_val = E1000_SUCCESS;
4123 } while (0);
4124
4125 return ret_val;
4126 }
4127
4128
4129
4130
4131
4132
4133
4134
4135 int32_t
4136 em_init_eeprom_params(struct em_hw *hw)
4137 {
4138 struct em_eeprom_info *eeprom = &hw->eeprom;
4139 uint32_t eecd = E1000_READ_REG(hw, EECD);
4140 int32_t ret_val = E1000_SUCCESS;
4141 uint16_t eeprom_size;
4142
4143 DEBUGFUNC("em_init_eeprom_params");
4144
4145 switch (hw->mac_type) {
4146 case em_82542_rev2_0:
4147 case em_82542_rev2_1:
4148 case em_82543:
4149 case em_82544:
4150 eeprom->type = em_eeprom_microwire;
4151 eeprom->word_size = 64;
4152 eeprom->opcode_bits = 3;
4153 eeprom->address_bits = 6;
4154 eeprom->delay_usec = 50;
4155 eeprom->use_eerd = FALSE;
4156 eeprom->use_eewr = FALSE;
4157 break;
4158 case em_82540:
4159 case em_82545:
4160 case em_82545_rev_3:
4161 case em_82546:
4162 case em_82546_rev_3:
4163 eeprom->type = em_eeprom_microwire;
4164 eeprom->opcode_bits = 3;
4165 eeprom->delay_usec = 50;
4166 if (eecd & E1000_EECD_SIZE) {
4167 eeprom->word_size = 256;
4168 eeprom->address_bits = 8;
4169 } else {
4170 eeprom->word_size = 64;
4171 eeprom->address_bits = 6;
4172 }
4173 eeprom->use_eerd = FALSE;
4174 eeprom->use_eewr = FALSE;
4175 break;
4176 case em_82541:
4177 case em_82541_rev_2:
4178 case em_82547:
4179 case em_82547_rev_2:
4180 if (eecd & E1000_EECD_TYPE) {
4181 eeprom->type = em_eeprom_spi;
4182 eeprom->opcode_bits = 8;
4183 eeprom->delay_usec = 1;
4184 if (eecd & E1000_EECD_ADDR_BITS) {
4185 eeprom->page_size = 32;
4186 eeprom->address_bits = 16;
4187 } else {
4188 eeprom->page_size = 8;
4189 eeprom->address_bits = 8;
4190 }
4191 } else {
4192 eeprom->type = em_eeprom_microwire;
4193 eeprom->opcode_bits = 3;
4194 eeprom->delay_usec = 50;
4195 if (eecd & E1000_EECD_ADDR_BITS) {
4196 eeprom->word_size = 256;
4197 eeprom->address_bits = 8;
4198 } else {
4199 eeprom->word_size = 64;
4200 eeprom->address_bits = 6;
4201 }
4202 }
4203 eeprom->use_eerd = FALSE;
4204 eeprom->use_eewr = FALSE;
4205 break;
4206 case em_82571:
4207 case em_82572:
4208 eeprom->type = em_eeprom_spi;
4209 eeprom->opcode_bits = 8;
4210 eeprom->delay_usec = 1;
4211 if (eecd & E1000_EECD_ADDR_BITS) {
4212 eeprom->page_size = 32;
4213 eeprom->address_bits = 16;
4214 } else {
4215 eeprom->page_size = 8;
4216 eeprom->address_bits = 8;
4217 }
4218 eeprom->use_eerd = FALSE;
4219 eeprom->use_eewr = FALSE;
4220 break;
4221 case em_82573:
4222 eeprom->type = em_eeprom_spi;
4223 eeprom->opcode_bits = 8;
4224 eeprom->delay_usec = 1;
4225 if (eecd & E1000_EECD_ADDR_BITS) {
4226 eeprom->page_size = 32;
4227 eeprom->address_bits = 16;
4228 } else {
4229 eeprom->page_size = 8;
4230 eeprom->address_bits = 8;
4231 }
4232 eeprom->use_eerd = TRUE;
4233 eeprom->use_eewr = TRUE;
4234 if (em_is_onboard_nvm_eeprom(hw) == FALSE) {
4235 eeprom->type = em_eeprom_flash;
4236 eeprom->word_size = 2048;
4237
4238
4239
4240 eecd &= ~E1000_EECD_AUPDEN;
4241 E1000_WRITE_REG(hw, EECD, eecd);
4242 }
4243 break;
4244 case em_80003es2lan:
4245 eeprom->type = em_eeprom_spi;
4246 eeprom->opcode_bits = 8;
4247 eeprom->delay_usec = 1;
4248 if (eecd & E1000_EECD_ADDR_BITS) {
4249 eeprom->page_size = 32;
4250 eeprom->address_bits = 16;
4251 } else {
4252 eeprom->page_size = 8;
4253 eeprom->address_bits = 8;
4254 }
4255 eeprom->use_eerd = TRUE;
4256 eeprom->use_eewr = FALSE;
4257 break;
4258 case em_ich8lan:
4259 {
4260 int32_t i = 0;
4261 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
4262
4263 eeprom->type = em_eeprom_ich8;
4264 eeprom->use_eerd = FALSE;
4265 eeprom->use_eewr = FALSE;
4266 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4267
4268
4269
4270 if (hw->eeprom_shadow_ram != NULL) {
4271 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4272 hw->eeprom_shadow_ram[i].modified = FALSE;
4273 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4274 }
4275 }
4276
4277 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4278 ICH_FLASH_SECTOR_SIZE;
4279
4280 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4281 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4282
4283 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4284
4285 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4286
4287 break;
4288 }
4289 default:
4290 break;
4291 }
4292
4293 if (eeprom->type == em_eeprom_spi) {
4294
4295
4296
4297 if (hw->mac_type <= em_82547_rev_2) {
4298
4299 eeprom->word_size = 64;
4300 ret_val = em_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4301 if (ret_val)
4302 return ret_val;
4303 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4304
4305
4306
4307 if (eeprom_size)
4308 eeprom_size++;
4309 } else {
4310 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4311 E1000_EECD_SIZE_EX_SHIFT);
4312 }
4313
4314 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4315 }
4316 return ret_val;
4317 }
4318
4319
4320
4321
4322
4323
4324
4325 static void
4326 em_raise_ee_clk(struct em_hw *hw,
4327 uint32_t *eecd)
4328 {
4329
4330
4331
4332 *eecd = *eecd | E1000_EECD_SK;
4333 E1000_WRITE_REG(hw, EECD, *eecd);
4334 E1000_WRITE_FLUSH(hw);
4335 usec_delay(hw->eeprom.delay_usec);
4336 }
4337
4338
4339
4340
4341
4342
4343
4344 static void
4345 em_lower_ee_clk(struct em_hw *hw,
4346 uint32_t *eecd)
4347 {
4348
4349
4350
4351 *eecd = *eecd & ~E1000_EECD_SK;
4352 E1000_WRITE_REG(hw, EECD, *eecd);
4353 E1000_WRITE_FLUSH(hw);
4354 usec_delay(hw->eeprom.delay_usec);
4355 }
4356
4357
4358
4359
4360
4361
4362
4363
4364 static void
4365 em_shift_out_ee_bits(struct em_hw *hw,
4366 uint16_t data,
4367 uint16_t count)
4368 {
4369 struct em_eeprom_info *eeprom = &hw->eeprom;
4370 uint32_t eecd;
4371 uint32_t mask;
4372
4373
4374
4375
4376
4377 mask = 0x01 << (count - 1);
4378 eecd = E1000_READ_REG(hw, EECD);
4379 if (eeprom->type == em_eeprom_microwire) {
4380 eecd &= ~E1000_EECD_DO;
4381 } else if (eeprom->type == em_eeprom_spi) {
4382 eecd |= E1000_EECD_DO;
4383 }
4384 do {
4385
4386
4387
4388
4389
4390 eecd &= ~E1000_EECD_DI;
4391
4392 if (data & mask)
4393 eecd |= E1000_EECD_DI;
4394
4395 E1000_WRITE_REG(hw, EECD, eecd);
4396 E1000_WRITE_FLUSH(hw);
4397
4398 usec_delay(eeprom->delay_usec);
4399
4400 em_raise_ee_clk(hw, &eecd);
4401 em_lower_ee_clk(hw, &eecd);
4402
4403 mask = mask >> 1;
4404
4405 } while (mask);
4406
4407
4408 eecd &= ~E1000_EECD_DI;
4409 E1000_WRITE_REG(hw, EECD, eecd);
4410 }
4411
4412
4413
4414
4415
4416
4417 static uint16_t
4418 em_shift_in_ee_bits(struct em_hw *hw,
4419 uint16_t count)
4420 {
4421 uint32_t eecd;
4422 uint32_t i;
4423 uint16_t data;
4424
4425
4426
4427
4428
4429
4430
4431
4432 eecd = E1000_READ_REG(hw, EECD);
4433
4434 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4435 data = 0;
4436
4437 for (i = 0; i < count; i++) {
4438 data = data << 1;
4439 em_raise_ee_clk(hw, &eecd);
4440
4441 eecd = E1000_READ_REG(hw, EECD);
4442
4443 eecd &= ~(E1000_EECD_DI);
4444 if (eecd & E1000_EECD_DO)
4445 data |= 1;
4446
4447 em_lower_ee_clk(hw, &eecd);
4448 }
4449
4450 return data;
4451 }
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461 static int32_t
4462 em_acquire_eeprom(struct em_hw *hw)
4463 {
4464 struct em_eeprom_info *eeprom = &hw->eeprom;
4465 uint32_t eecd, i=0;
4466
4467 DEBUGFUNC("em_acquire_eeprom");
4468
4469 if (em_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4470 return -E1000_ERR_SWFW_SYNC;
4471 eecd = E1000_READ_REG(hw, EECD);
4472
4473 if (hw->mac_type != em_82573) {
4474
4475 if (hw->mac_type > em_82544) {
4476 eecd |= E1000_EECD_REQ;
4477 E1000_WRITE_REG(hw, EECD, eecd);
4478 eecd = E1000_READ_REG(hw, EECD);
4479 while ((!(eecd & E1000_EECD_GNT)) &&
4480 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4481 i++;
4482 usec_delay(5);
4483 eecd = E1000_READ_REG(hw, EECD);
4484 }
4485 if (!(eecd & E1000_EECD_GNT)) {
4486 eecd &= ~E1000_EECD_REQ;
4487 E1000_WRITE_REG(hw, EECD, eecd);
4488 DEBUGOUT("Could not acquire EEPROM grant\n");
4489 em_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4490 return -E1000_ERR_EEPROM;
4491 }
4492 }
4493 }
4494
4495
4496
4497 if (eeprom->type == em_eeprom_microwire) {
4498
4499 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4500 E1000_WRITE_REG(hw, EECD, eecd);
4501
4502
4503 eecd |= E1000_EECD_CS;
4504 E1000_WRITE_REG(hw, EECD, eecd);
4505 } else if (eeprom->type == em_eeprom_spi) {
4506
4507 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4508 E1000_WRITE_REG(hw, EECD, eecd);
4509 usec_delay(1);
4510 }
4511
4512 return E1000_SUCCESS;
4513 }
4514
4515
4516
4517
4518
4519
4520 static void
4521 em_standby_eeprom(struct em_hw *hw)
4522 {
4523 struct em_eeprom_info *eeprom = &hw->eeprom;
4524 uint32_t eecd;
4525
4526 eecd = E1000_READ_REG(hw, EECD);
4527
4528 if (eeprom->type == em_eeprom_microwire) {
4529 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4530 E1000_WRITE_REG(hw, EECD, eecd);
4531 E1000_WRITE_FLUSH(hw);
4532 usec_delay(eeprom->delay_usec);
4533
4534
4535 eecd |= E1000_EECD_SK;
4536 E1000_WRITE_REG(hw, EECD, eecd);
4537 E1000_WRITE_FLUSH(hw);
4538 usec_delay(eeprom->delay_usec);
4539
4540
4541 eecd |= E1000_EECD_CS;
4542 E1000_WRITE_REG(hw, EECD, eecd);
4543 E1000_WRITE_FLUSH(hw);
4544 usec_delay(eeprom->delay_usec);
4545
4546
4547 eecd &= ~E1000_EECD_SK;
4548 E1000_WRITE_REG(hw, EECD, eecd);
4549 E1000_WRITE_FLUSH(hw);
4550 usec_delay(eeprom->delay_usec);
4551 } else if (eeprom->type == em_eeprom_spi) {
4552
4553 eecd |= E1000_EECD_CS;
4554 E1000_WRITE_REG(hw, EECD, eecd);
4555 E1000_WRITE_FLUSH(hw);
4556 usec_delay(eeprom->delay_usec);
4557 eecd &= ~E1000_EECD_CS;
4558 E1000_WRITE_REG(hw, EECD, eecd);
4559 E1000_WRITE_FLUSH(hw);
4560 usec_delay(eeprom->delay_usec);
4561 }
4562 }
4563
4564
4565
4566
4567
4568
4569 static void
4570 em_release_eeprom(struct em_hw *hw)
4571 {
4572 uint32_t eecd;
4573
4574 DEBUGFUNC("em_release_eeprom");
4575
4576 eecd = E1000_READ_REG(hw, EECD);
4577
4578 if (hw->eeprom.type == em_eeprom_spi) {
4579 eecd |= E1000_EECD_CS;
4580 eecd &= ~E1000_EECD_SK;
4581
4582 E1000_WRITE_REG(hw, EECD, eecd);
4583
4584 usec_delay(hw->eeprom.delay_usec);
4585 } else if (hw->eeprom.type == em_eeprom_microwire) {
4586
4587
4588
4589 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4590
4591 E1000_WRITE_REG(hw, EECD, eecd);
4592
4593
4594 eecd |= E1000_EECD_SK;
4595 E1000_WRITE_REG(hw, EECD, eecd);
4596 E1000_WRITE_FLUSH(hw);
4597 usec_delay(hw->eeprom.delay_usec);
4598
4599
4600 eecd &= ~E1000_EECD_SK;
4601 E1000_WRITE_REG(hw, EECD, eecd);
4602 E1000_WRITE_FLUSH(hw);
4603 usec_delay(hw->eeprom.delay_usec);
4604 }
4605
4606
4607 if (hw->mac_type > em_82544) {
4608 eecd &= ~E1000_EECD_REQ;
4609 E1000_WRITE_REG(hw, EECD, eecd);
4610 }
4611
4612 em_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4613 }
4614
4615
4616
4617
4618
4619
4620 STATIC int32_t
4621 em_spi_eeprom_ready(struct em_hw *hw)
4622 {
4623 uint16_t retry_count = 0;
4624 uint8_t spi_stat_reg;
4625
4626 DEBUGFUNC("em_spi_eeprom_ready");
4627
4628
4629
4630
4631
4632
4633 retry_count = 0;
4634 do {
4635 em_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4636 hw->eeprom.opcode_bits);
4637 spi_stat_reg = (uint8_t)em_shift_in_ee_bits(hw, 8);
4638 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4639 break;
4640
4641 usec_delay(5);
4642 retry_count += 5;
4643
4644 em_standby_eeprom(hw);
4645 } while (retry_count < EEPROM_MAX_RETRY_SPI);
4646
4647
4648
4649
4650 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
4651 DEBUGOUT("SPI EEPROM Status error\n");
4652 return -E1000_ERR_EEPROM;
4653 }
4654
4655 return E1000_SUCCESS;
4656 }
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666 int32_t
4667 em_read_eeprom(struct em_hw *hw,
4668 uint16_t offset,
4669 uint16_t words,
4670 uint16_t *data)
4671 {
4672 struct em_eeprom_info *eeprom = &hw->eeprom;
4673 uint32_t i = 0;
4674
4675 DEBUGFUNC("em_read_eeprom");
4676
4677
4678 if (eeprom->word_size == 0)
4679 em_init_eeprom_params(hw);
4680
4681
4682
4683
4684 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4685 (words == 0)) {
4686 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
4687 return -E1000_ERR_EEPROM;
4688 }
4689
4690
4691
4692
4693
4694 if (em_is_onboard_nvm_eeprom(hw) == TRUE &&
4695 hw->eeprom.use_eerd == FALSE) {
4696
4697 if (em_acquire_eeprom(hw) != E1000_SUCCESS)
4698 return -E1000_ERR_EEPROM;
4699 }
4700
4701
4702 if (eeprom->use_eerd == TRUE)
4703 return em_read_eeprom_eerd(hw, offset, words, data);
4704
4705
4706 if (eeprom->type == em_eeprom_ich8)
4707 return em_read_eeprom_ich8(hw, offset, words, data);
4708
4709
4710
4711 if (eeprom->type == em_eeprom_spi) {
4712 uint16_t word_in;
4713 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4714
4715 if (em_spi_eeprom_ready(hw)) {
4716 em_release_eeprom(hw);
4717 return -E1000_ERR_EEPROM;
4718 }
4719
4720 em_standby_eeprom(hw);
4721
4722
4723 if ((eeprom->address_bits == 8) && (offset >= 128))
4724 read_opcode |= EEPROM_A8_OPCODE_SPI;
4725
4726
4727 em_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4728 em_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4729
4730
4731
4732
4733
4734
4735 for (i = 0; i < words; i++) {
4736 word_in = em_shift_in_ee_bits(hw, 16);
4737 data[i] = (word_in >> 8) | (word_in << 8);
4738 }
4739 } else if (eeprom->type == em_eeprom_microwire) {
4740 for (i = 0; i < words; i++) {
4741
4742 em_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4743 eeprom->opcode_bits);
4744 em_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4745 eeprom->address_bits);
4746
4747
4748
4749 data[i] = em_shift_in_ee_bits(hw, 16);
4750 em_standby_eeprom(hw);
4751 }
4752 }
4753
4754
4755 em_release_eeprom(hw);
4756
4757 return E1000_SUCCESS;
4758 }
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768 STATIC int32_t
4769 em_read_eeprom_eerd(struct em_hw *hw,
4770 uint16_t offset,
4771 uint16_t words,
4772 uint16_t *data)
4773 {
4774 uint32_t i, eerd = 0;
4775 int32_t error = 0;
4776
4777 for (i = 0; i < words; i++) {
4778 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4779 E1000_EEPROM_RW_REG_START;
4780
4781 E1000_WRITE_REG(hw, EERD, eerd);
4782 error = em_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
4783
4784 if (error) {
4785 break;
4786 }
4787 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
4788
4789 }
4790
4791 return error;
4792 }
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802 STATIC int32_t
4803 em_write_eeprom_eewr(struct em_hw *hw,
4804 uint16_t offset,
4805 uint16_t words,
4806 uint16_t *data)
4807 {
4808 uint32_t register_value = 0;
4809 uint32_t i = 0;
4810 int32_t error = 0;
4811
4812 if (em_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4813 return -E1000_ERR_SWFW_SYNC;
4814
4815 for (i = 0; i < words; i++) {
4816 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4817 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4818 E1000_EEPROM_RW_REG_START;
4819
4820 error = em_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4821 if (error) {
4822 break;
4823 }
4824
4825 E1000_WRITE_REG(hw, EEWR, register_value);
4826
4827 error = em_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4828
4829 if (error) {
4830 break;
4831 }
4832 }
4833
4834 em_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4835 return error;
4836 }
4837
4838
4839
4840
4841
4842
4843 STATIC int32_t
4844 em_poll_eerd_eewr_done(struct em_hw *hw, int eerd)
4845 {
4846 uint32_t attempts = 100000;
4847 uint32_t i, reg = 0;
4848 int32_t done = E1000_ERR_EEPROM;
4849
4850 for (i = 0; i < attempts; i++) {
4851 if (eerd == E1000_EEPROM_POLL_READ)
4852 reg = E1000_READ_REG(hw, EERD);
4853 else
4854 reg = E1000_READ_REG(hw, EEWR);
4855
4856 if (reg & E1000_EEPROM_RW_REG_DONE) {
4857 done = E1000_SUCCESS;
4858 break;
4859 }
4860 usec_delay(5);
4861 }
4862
4863 return done;
4864 }
4865
4866
4867
4868
4869
4870
4871 STATIC boolean_t
4872 em_is_onboard_nvm_eeprom(struct em_hw *hw)
4873 {
4874 uint32_t eecd = 0;
4875
4876 DEBUGFUNC("em_is_onboard_nvm_eeprom");
4877
4878 if (hw->mac_type == em_ich8lan)
4879 return FALSE;
4880
4881 if (hw->mac_type == em_82573) {
4882 eecd = E1000_READ_REG(hw, EECD);
4883
4884
4885 eecd = ((eecd >> 15) & 0x03);
4886
4887
4888 if (eecd == 0x03) {
4889 return FALSE;
4890 }
4891 }
4892 return TRUE;
4893 }
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904 int32_t
4905 em_validate_eeprom_checksum(struct em_hw *hw)
4906 {
4907 uint16_t checksum = 0;
4908 uint16_t i, eeprom_data;
4909
4910 DEBUGFUNC("em_validate_eeprom_checksum");
4911
4912 if ((hw->mac_type == em_82573) &&
4913 (em_is_onboard_nvm_eeprom(hw) == FALSE)) {
4914
4915
4916 em_read_eeprom(hw, 0x10, 1, &eeprom_data);
4917 if ((eeprom_data & 0x10) == 0) {
4918
4919
4920
4921
4922 em_read_eeprom(hw, 0x23, 1, &eeprom_data);
4923 if ((eeprom_data & 0x8000) == 0) {
4924 eeprom_data |= 0x8000;
4925 em_write_eeprom(hw, 0x23, 1, &eeprom_data);
4926 em_update_eeprom_checksum(hw);
4927 }
4928 }
4929 }
4930
4931 if (hw->mac_type == em_ich8lan) {
4932
4933
4934
4935
4936
4937 em_read_eeprom(hw, 0x19, 1, &eeprom_data);
4938 if ((eeprom_data & 0x40) == 0) {
4939 eeprom_data |= 0x40;
4940 em_write_eeprom(hw, 0x19, 1, &eeprom_data);
4941 em_update_eeprom_checksum(hw);
4942 }
4943 }
4944
4945 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4946 if (em_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4947 DEBUGOUT("EEPROM Read Error\n");
4948 return -E1000_ERR_EEPROM;
4949 }
4950 checksum += eeprom_data;
4951 }
4952
4953 if (checksum == (uint16_t) EEPROM_SUM)
4954 return E1000_SUCCESS;
4955 else {
4956 DEBUGOUT("EEPROM Checksum Invalid\n");
4957 return -E1000_ERR_EEPROM;
4958 }
4959 }
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969 int32_t
4970 em_update_eeprom_checksum(struct em_hw *hw)
4971 {
4972 uint32_t ctrl_ext;
4973 uint16_t checksum = 0;
4974 uint16_t i, eeprom_data;
4975
4976 DEBUGFUNC("em_update_eeprom_checksum");
4977
4978 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4979 if (em_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4980 DEBUGOUT("EEPROM Read Error\n");
4981 return -E1000_ERR_EEPROM;
4982 }
4983 checksum += eeprom_data;
4984 }
4985 checksum = (uint16_t) EEPROM_SUM - checksum;
4986 if (em_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4987 DEBUGOUT("EEPROM Write Error\n");
4988 return -E1000_ERR_EEPROM;
4989 } else if (hw->eeprom.type == em_eeprom_flash) {
4990 em_commit_shadow_ram(hw);
4991 } else if (hw->eeprom.type == em_eeprom_ich8) {
4992 em_commit_shadow_ram(hw);
4993
4994
4995 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4996 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
4997 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4998 msec_delay(10);
4999 }
5000 return E1000_SUCCESS;
5001 }
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014 int32_t
5015 em_write_eeprom(struct em_hw *hw,
5016 uint16_t offset,
5017 uint16_t words,
5018 uint16_t *data)
5019 {
5020 struct em_eeprom_info *eeprom = &hw->eeprom;
5021 int32_t status = 0;
5022
5023 DEBUGFUNC("em_write_eeprom");
5024
5025
5026 if (eeprom->word_size == 0)
5027 em_init_eeprom_params(hw);
5028
5029
5030
5031
5032 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5033 (words == 0)) {
5034 DEBUGOUT("\"words\" parameter out of bounds\n");
5035 return -E1000_ERR_EEPROM;
5036 }
5037
5038
5039 if (eeprom->use_eewr == TRUE)
5040 return em_write_eeprom_eewr(hw, offset, words, data);
5041
5042 if (eeprom->type == em_eeprom_ich8)
5043 return em_write_eeprom_ich8(hw, offset, words, data);
5044
5045
5046 if (em_acquire_eeprom(hw) != E1000_SUCCESS)
5047 return -E1000_ERR_EEPROM;
5048
5049 if (eeprom->type == em_eeprom_microwire) {
5050 status = em_write_eeprom_microwire(hw, offset, words, data);
5051 } else {
5052 status = em_write_eeprom_spi(hw, offset, words, data);
5053 msec_delay(10);
5054 }
5055
5056
5057 em_release_eeprom(hw);
5058
5059 return status;
5060 }
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071 STATIC int32_t
5072 em_write_eeprom_spi(struct em_hw *hw,
5073 uint16_t offset,
5074 uint16_t words,
5075 uint16_t *data)
5076 {
5077 struct em_eeprom_info *eeprom = &hw->eeprom;
5078 uint16_t widx = 0;
5079
5080 DEBUGFUNC("em_write_eeprom_spi");
5081
5082 while (widx < words) {
5083 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5084
5085 if (em_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5086
5087 em_standby_eeprom(hw);
5088
5089
5090 em_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5091 eeprom->opcode_bits);
5092
5093 em_standby_eeprom(hw);
5094
5095
5096 if ((eeprom->address_bits == 8) && (offset >= 128))
5097 write_opcode |= EEPROM_A8_OPCODE_SPI;
5098
5099
5100 em_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5101
5102 em_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5103 eeprom->address_bits);
5104
5105
5106
5107
5108 while (widx < words) {
5109 uint16_t word_out = data[widx];
5110 word_out = (word_out >> 8) | (word_out << 8);
5111 em_shift_out_ee_bits(hw, word_out, 16);
5112 widx++;
5113
5114
5115
5116
5117
5118 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
5119 em_standby_eeprom(hw);
5120 break;
5121 }
5122 }
5123 }
5124
5125 return E1000_SUCCESS;
5126 }
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137 STATIC int32_t
5138 em_write_eeprom_microwire(struct em_hw *hw,
5139 uint16_t offset,
5140 uint16_t words,
5141 uint16_t *data)
5142 {
5143 struct em_eeprom_info *eeprom = &hw->eeprom;
5144 uint32_t eecd;
5145 uint16_t words_written = 0;
5146 uint16_t i = 0;
5147
5148 DEBUGFUNC("em_write_eeprom_microwire");
5149
5150
5151
5152
5153
5154
5155
5156 em_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5157 (uint16_t)(eeprom->opcode_bits + 2));
5158
5159 em_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5160
5161
5162 em_standby_eeprom(hw);
5163
5164 while (words_written < words) {
5165
5166 em_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5167 eeprom->opcode_bits);
5168
5169 em_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5170 eeprom->address_bits);
5171
5172
5173 em_shift_out_ee_bits(hw, data[words_written], 16);
5174
5175
5176
5177
5178 em_standby_eeprom(hw);
5179
5180
5181
5182
5183
5184 for (i = 0; i < 200; i++) {
5185 eecd = E1000_READ_REG(hw, EECD);
5186 if (eecd & E1000_EECD_DO) break;
5187 usec_delay(50);
5188 }
5189 if (i == 200) {
5190 DEBUGOUT("EEPROM Write did not complete\n");
5191 return -E1000_ERR_EEPROM;
5192 }
5193
5194
5195 em_standby_eeprom(hw);
5196
5197 words_written++;
5198 }
5199
5200
5201
5202
5203
5204
5205
5206 em_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5207 (uint16_t)(eeprom->opcode_bits + 2));
5208
5209 em_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5210
5211 return E1000_SUCCESS;
5212 }
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224 STATIC int32_t
5225 em_commit_shadow_ram(struct em_hw *hw)
5226 {
5227 uint32_t attempts = 100000;
5228 uint32_t eecd = 0;
5229 uint32_t flop = 0;
5230 uint32_t i = 0;
5231 int32_t error = E1000_SUCCESS;
5232 uint32_t old_bank_offset = 0;
5233 uint32_t new_bank_offset = 0;
5234 uint8_t low_byte = 0;
5235 uint8_t high_byte = 0;
5236 boolean_t sector_write_failed = FALSE;
5237
5238 if (hw->mac_type == em_82573) {
5239
5240 flop = E1000_READ_REG(hw, FLOP);
5241 for (i=0; i < attempts; i++) {
5242 eecd = E1000_READ_REG(hw, EECD);
5243 if ((eecd & E1000_EECD_FLUPD) == 0) {
5244 break;
5245 }
5246 usec_delay(5);
5247 }
5248
5249 if (i == attempts) {
5250 return -E1000_ERR_EEPROM;
5251 }
5252
5253
5254 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5255 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5256 }
5257
5258
5259 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5260
5261 for (i=0; i < attempts; i++) {
5262 eecd = E1000_READ_REG(hw, EECD);
5263 if ((eecd & E1000_EECD_FLUPD) == 0) {
5264 break;
5265 }
5266 usec_delay(5);
5267 }
5268
5269 if (i == attempts) {
5270 return -E1000_ERR_EEPROM;
5271 }
5272 }
5273
5274 if (hw->mac_type == em_ich8lan && hw->eeprom_shadow_ram != NULL) {
5275
5276
5277
5278 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5279 new_bank_offset = hw->flash_bank_size * 2;
5280 old_bank_offset = 0;
5281 em_erase_ich8_4k_segment(hw, 1);
5282 } else {
5283 old_bank_offset = hw->flash_bank_size * 2;
5284 new_bank_offset = 0;
5285 em_erase_ich8_4k_segment(hw, 0);
5286 }
5287
5288 sector_write_failed = FALSE;
5289
5290
5291 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5292
5293
5294
5295 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5296 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5297 usec_delay(100);
5298 error = em_verify_write_ich8_byte(hw,
5299 (i << 1) + new_bank_offset, low_byte);
5300
5301 if (error != E1000_SUCCESS)
5302 sector_write_failed = TRUE;
5303 else {
5304 high_byte =
5305 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5306 usec_delay(100);
5307 }
5308 } else {
5309 em_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5310 &low_byte);
5311 usec_delay(100);
5312 error = em_verify_write_ich8_byte(hw,
5313 (i << 1) + new_bank_offset, low_byte);
5314
5315 if (error != E1000_SUCCESS)
5316 sector_write_failed = TRUE;
5317 else {
5318 em_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5319 &high_byte);
5320 usec_delay(100);
5321 }
5322 }
5323
5324
5325
5326
5327 if (sector_write_failed == FALSE) {
5328
5329
5330
5331
5332
5333
5334 if (i == E1000_ICH_NVM_SIG_WORD)
5335 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
5336
5337 error = em_verify_write_ich8_byte(hw,
5338 (i << 1) + new_bank_offset + 1, high_byte);
5339 if (error != E1000_SUCCESS)
5340 sector_write_failed = TRUE;
5341
5342 } else {
5343
5344
5345 break;
5346 }
5347 }
5348
5349
5350
5351 if (sector_write_failed == FALSE) {
5352
5353
5354
5355
5356 em_read_ich8_byte(hw,
5357 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5358 &high_byte);
5359 high_byte &= 0xBF;
5360 error = em_verify_write_ich8_byte(hw,
5361 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5362
5363
5364
5365
5366 if (error == E1000_SUCCESS) {
5367 error = em_verify_write_ich8_byte(hw,
5368 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
5369 }
5370
5371
5372 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5373 hw->eeprom_shadow_ram[i].modified = FALSE;
5374 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5375 }
5376 }
5377 }
5378
5379 return error;
5380 }
5381
5382
5383
5384
5385
5386
5387
5388 int32_t
5389 em_read_part_num(struct em_hw *hw,
5390 uint32_t *part_num)
5391 {
5392 uint16_t offset = EEPROM_PBA_BYTE_1;
5393 uint16_t eeprom_data;
5394
5395 DEBUGFUNC("em_read_part_num");
5396
5397
5398 if (em_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5399 DEBUGOUT("EEPROM Read Error\n");
5400 return -E1000_ERR_EEPROM;
5401 }
5402
5403 *part_num = (uint32_t) (eeprom_data << 16);
5404
5405
5406 if (em_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5407 DEBUGOUT("EEPROM Read Error\n");
5408 return -E1000_ERR_EEPROM;
5409 }
5410
5411 *part_num |= eeprom_data;
5412
5413 return E1000_SUCCESS;
5414 }
5415
5416
5417
5418
5419
5420
5421
5422 int32_t
5423 em_read_mac_addr(struct em_hw * hw)
5424 {
5425 uint16_t offset;
5426 uint16_t eeprom_data, i;
5427
5428 DEBUGFUNC("em_read_mac_addr");
5429
5430 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5431 offset = i >> 1;
5432 if (em_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5433 DEBUGOUT("EEPROM Read Error\n");
5434 return -E1000_ERR_EEPROM;
5435 }
5436 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5437 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5438 }
5439
5440 switch (hw->mac_type) {
5441 default:
5442 break;
5443 case em_82546:
5444 case em_82546_rev_3:
5445 case em_82571:
5446 case em_80003es2lan:
5447 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5448 hw->perm_mac_addr[5] ^= 0x01;
5449 break;
5450 }
5451
5452 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
5453 hw->mac_addr[i] = hw->perm_mac_addr[i];
5454 return E1000_SUCCESS;
5455 }
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466 STATIC void
5467 em_init_rx_addrs(struct em_hw *hw)
5468 {
5469 uint32_t i;
5470 uint32_t rar_num;
5471
5472 DEBUGFUNC("em_init_rx_addrs");
5473
5474
5475 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5476
5477 em_rar_set(hw, hw->mac_addr, 0);
5478
5479 rar_num = E1000_RAR_ENTRIES;
5480
5481
5482
5483
5484 if ((hw->mac_type == em_82571) && (hw->laa_is_present == TRUE))
5485 rar_num -= 1;
5486 if (hw->mac_type == em_ich8lan)
5487 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5488
5489
5490 DEBUGOUT("Clearing RAR[1-15]\n");
5491 for (i = 1; i < rar_num; i++) {
5492 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5493 E1000_WRITE_FLUSH(hw);
5494 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5495 E1000_WRITE_FLUSH(hw);
5496 }
5497 }
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513 void
5514 em_mc_addr_list_update(struct em_hw *hw,
5515 uint8_t *mc_addr_list,
5516 uint32_t mc_addr_count,
5517 uint32_t pad,
5518 uint32_t rar_used_count)
5519 {
5520 uint32_t hash_value;
5521 uint32_t i;
5522 uint32_t num_rar_entry;
5523 uint32_t num_mta_entry;
5524
5525 DEBUGFUNC("em_mc_addr_list_update");
5526
5527
5528 hw->num_mc_addrs = mc_addr_count;
5529
5530
5531 DEBUGOUT(" Clearing RAR[1-15]\n");
5532 num_rar_entry = E1000_RAR_ENTRIES;
5533 if (hw->mac_type == em_ich8lan)
5534 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
5535
5536
5537
5538
5539 if ((hw->mac_type == em_82571) && (hw->laa_is_present == TRUE))
5540 num_rar_entry -= 1;
5541
5542 for (i = rar_used_count; i < num_rar_entry; i++) {
5543 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5544 E1000_WRITE_FLUSH(hw);
5545 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5546 E1000_WRITE_FLUSH(hw);
5547 }
5548
5549
5550 DEBUGOUT(" Clearing MTA\n");
5551 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5552 if (hw->mac_type == em_ich8lan)
5553 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
5554
5555 for (i = 0; i < num_mta_entry; i++) {
5556 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5557 E1000_WRITE_FLUSH(hw);
5558 }
5559
5560
5561 for (i = 0; i < mc_addr_count; i++) {
5562 DEBUGOUT(" Adding the multicast addresses:\n");
5563 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5564 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5565 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5566 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5567 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5568 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5569 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5570
5571 hash_value = em_hash_mc_addr(hw,
5572 mc_addr_list +
5573 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5574
5575 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5576
5577
5578
5579
5580 if (rar_used_count < num_rar_entry) {
5581 em_rar_set(hw,
5582 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5583 rar_used_count);
5584 rar_used_count++;
5585 } else {
5586 em_mta_set(hw, hash_value);
5587 }
5588 }
5589 DEBUGOUT("MC Update Complete\n");
5590 }
5591
5592
5593
5594
5595
5596
5597
5598 uint32_t
5599 em_hash_mc_addr(struct em_hw *hw,
5600 uint8_t *mc_addr)
5601 {
5602 uint32_t hash_value = 0;
5603
5604
5605
5606
5607 switch (hw->mc_filter_type) {
5608
5609
5610
5611
5612 case 0:
5613 if (hw->mac_type == em_ich8lan) {
5614
5615 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5616 } else {
5617
5618 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5619 }
5620 break;
5621 case 1:
5622 if (hw->mac_type == em_ich8lan) {
5623
5624 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5625 } else {
5626
5627 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5628 }
5629 break;
5630 case 2:
5631 if (hw->mac_type == em_ich8lan) {
5632
5633 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5634 } else {
5635
5636 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5637 }
5638 break;
5639 case 3:
5640 if (hw->mac_type == em_ich8lan) {
5641
5642 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5643 } else {
5644
5645 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5646 }
5647 break;
5648 }
5649
5650 hash_value &= 0xFFF;
5651 if (hw->mac_type == em_ich8lan)
5652 hash_value &= 0x3FF;
5653
5654 return hash_value;
5655 }
5656
5657
5658
5659
5660
5661
5662
5663 void
5664 em_mta_set(struct em_hw *hw,
5665 uint32_t hash_value)
5666 {
5667 uint32_t hash_bit, hash_reg;
5668 uint32_t mta;
5669 uint32_t temp;
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679 hash_reg = (hash_value >> 5) & 0x7F;
5680 if (hw->mac_type == em_ich8lan)
5681 hash_reg &= 0x1F;
5682
5683 hash_bit = hash_value & 0x1F;
5684
5685 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5686
5687 mta |= (1 << hash_bit);
5688
5689
5690
5691
5692
5693 if ((hw->mac_type == em_82544) && ((hash_reg & 0x1) == 1)) {
5694 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5695 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5696 E1000_WRITE_FLUSH(hw);
5697 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5698 E1000_WRITE_FLUSH(hw);
5699 } else {
5700 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5701 E1000_WRITE_FLUSH(hw);
5702 }
5703 }
5704
5705
5706
5707
5708
5709
5710
5711
5712 void
5713 em_rar_set(struct em_hw *hw,
5714 uint8_t *addr,
5715 uint32_t index)
5716 {
5717 uint32_t rar_low, rar_high;
5718
5719
5720
5721
5722 rar_low = ((uint32_t) addr[0] |
5723 ((uint32_t) addr[1] << 8) |
5724 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5725 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745 switch (hw->mac_type) {
5746 case em_82571:
5747 case em_82572:
5748 case em_80003es2lan:
5749 if (hw->leave_av_bit_off == TRUE)
5750 break;
5751 default:
5752
5753 rar_high |= E1000_RAH_AV;
5754 break;
5755 }
5756
5757 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5758 E1000_WRITE_FLUSH(hw);
5759 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5760 E1000_WRITE_FLUSH(hw);
5761 }
5762
5763
5764
5765
5766
5767
5768 STATIC void
5769 em_clear_vfta(struct em_hw *hw)
5770 {
5771 uint32_t offset;
5772 uint32_t vfta_value = 0;
5773 uint32_t vfta_offset = 0;
5774 uint32_t vfta_bit_in_reg = 0;
5775
5776 if (hw->mac_type == em_ich8lan)
5777 return;
5778
5779 if (hw->mac_type == em_82573) {
5780 if (hw->mng_cookie.vlan_id != 0) {
5781
5782
5783
5784
5785 vfta_offset = (hw->mng_cookie.vlan_id >>
5786 E1000_VFTA_ENTRY_SHIFT) &
5787 E1000_VFTA_ENTRY_MASK;
5788 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5789 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5790 }
5791 }
5792 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5793
5794
5795
5796 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5797 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
5798 E1000_WRITE_FLUSH(hw);
5799 }
5800 }
5801
5802 STATIC int32_t
5803 em_id_led_init(struct em_hw * hw)
5804 {
5805 uint32_t ledctl;
5806 const uint32_t ledctl_mask = 0x000000FF;
5807 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5808 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5809 uint16_t eeprom_data, i, temp;
5810 const uint16_t led_mask = 0x0F;
5811
5812 DEBUGFUNC("em_id_led_init");
5813
5814 if (hw->mac_type < em_82540) {
5815
5816 return E1000_SUCCESS;
5817 }
5818
5819 ledctl = E1000_READ_REG(hw, LEDCTL);
5820 hw->ledctl_default = ledctl;
5821 hw->ledctl_mode1 = hw->ledctl_default;
5822 hw->ledctl_mode2 = hw->ledctl_default;
5823
5824 if (em_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5825 DEBUGOUT("EEPROM Read Error\n");
5826 return -E1000_ERR_EEPROM;
5827 }
5828
5829 if ((hw->mac_type == em_82573) &&
5830 (eeprom_data == ID_LED_RESERVED_82573))
5831 eeprom_data = ID_LED_DEFAULT_82573;
5832 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
5833 (eeprom_data == ID_LED_RESERVED_FFFF)) {
5834 if (hw->mac_type == em_ich8lan)
5835 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
5836 else
5837 eeprom_data = ID_LED_DEFAULT;
5838 }
5839
5840 for (i = 0; i < 4; i++) {
5841 temp = (eeprom_data >> (i << 2)) & led_mask;
5842 switch (temp) {
5843 case ID_LED_ON1_DEF2:
5844 case ID_LED_ON1_ON2:
5845 case ID_LED_ON1_OFF2:
5846 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5847 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5848 break;
5849 case ID_LED_OFF1_DEF2:
5850 case ID_LED_OFF1_ON2:
5851 case ID_LED_OFF1_OFF2:
5852 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5853 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5854 break;
5855 default:
5856
5857 break;
5858 }
5859 switch (temp) {
5860 case ID_LED_DEF1_ON2:
5861 case ID_LED_ON1_ON2:
5862 case ID_LED_OFF1_ON2:
5863 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5864 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5865 break;
5866 case ID_LED_DEF1_OFF2:
5867 case ID_LED_ON1_OFF2:
5868 case ID_LED_OFF1_OFF2:
5869 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5870 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5871 break;
5872 default:
5873
5874 break;
5875 }
5876 }
5877 return E1000_SUCCESS;
5878 }
5879
5880
5881
5882
5883
5884
5885 void
5886 em_clear_hw_cntrs(struct em_hw *hw)
5887 {
5888 volatile uint32_t temp;
5889
5890 temp = E1000_READ_REG(hw, CRCERRS);
5891 temp = E1000_READ_REG(hw, SYMERRS);
5892 temp = E1000_READ_REG(hw, MPC);
5893 temp = E1000_READ_REG(hw, SCC);
5894 temp = E1000_READ_REG(hw, ECOL);
5895 temp = E1000_READ_REG(hw, MCC);
5896 temp = E1000_READ_REG(hw, LATECOL);
5897 temp = E1000_READ_REG(hw, COLC);
5898 temp = E1000_READ_REG(hw, DC);
5899 temp = E1000_READ_REG(hw, SEC);
5900 temp = E1000_READ_REG(hw, RLEC);
5901 temp = E1000_READ_REG(hw, XONRXC);
5902 temp = E1000_READ_REG(hw, XONTXC);
5903 temp = E1000_READ_REG(hw, XOFFRXC);
5904 temp = E1000_READ_REG(hw, XOFFTXC);
5905 temp = E1000_READ_REG(hw, FCRUC);
5906
5907 if (hw->mac_type != em_ich8lan) {
5908 temp = E1000_READ_REG(hw, PRC64);
5909 temp = E1000_READ_REG(hw, PRC127);
5910 temp = E1000_READ_REG(hw, PRC255);
5911 temp = E1000_READ_REG(hw, PRC511);
5912 temp = E1000_READ_REG(hw, PRC1023);
5913 temp = E1000_READ_REG(hw, PRC1522);
5914 }
5915
5916 temp = E1000_READ_REG(hw, GPRC);
5917 temp = E1000_READ_REG(hw, BPRC);
5918 temp = E1000_READ_REG(hw, MPRC);
5919 temp = E1000_READ_REG(hw, GPTC);
5920 temp = E1000_READ_REG(hw, GORCL);
5921 temp = E1000_READ_REG(hw, GORCH);
5922 temp = E1000_READ_REG(hw, GOTCL);
5923 temp = E1000_READ_REG(hw, GOTCH);
5924 temp = E1000_READ_REG(hw, RNBC);
5925 temp = E1000_READ_REG(hw, RUC);
5926 temp = E1000_READ_REG(hw, RFC);
5927 temp = E1000_READ_REG(hw, ROC);
5928 temp = E1000_READ_REG(hw, RJC);
5929 temp = E1000_READ_REG(hw, TORL);
5930 temp = E1000_READ_REG(hw, TORH);
5931 temp = E1000_READ_REG(hw, TOTL);
5932 temp = E1000_READ_REG(hw, TOTH);
5933 temp = E1000_READ_REG(hw, TPR);
5934 temp = E1000_READ_REG(hw, TPT);
5935
5936 if (hw->mac_type != em_ich8lan) {
5937 temp = E1000_READ_REG(hw, PTC64);
5938 temp = E1000_READ_REG(hw, PTC127);
5939 temp = E1000_READ_REG(hw, PTC255);
5940 temp = E1000_READ_REG(hw, PTC511);
5941 temp = E1000_READ_REG(hw, PTC1023);
5942 temp = E1000_READ_REG(hw, PTC1522);
5943 }
5944
5945 temp = E1000_READ_REG(hw, MPTC);
5946 temp = E1000_READ_REG(hw, BPTC);
5947
5948 if (hw->mac_type < em_82543) return;
5949
5950 temp = E1000_READ_REG(hw, ALGNERRC);
5951 temp = E1000_READ_REG(hw, RXERRC);
5952 temp = E1000_READ_REG(hw, TNCRS);
5953 temp = E1000_READ_REG(hw, CEXTERR);
5954 temp = E1000_READ_REG(hw, TSCTC);
5955 temp = E1000_READ_REG(hw, TSCTFC);
5956
5957 if (hw->mac_type <= em_82544) return;
5958
5959 temp = E1000_READ_REG(hw, MGTPRC);
5960 temp = E1000_READ_REG(hw, MGTPDC);
5961 temp = E1000_READ_REG(hw, MGTPTC);
5962
5963 if (hw->mac_type <= em_82547_rev_2) return;
5964
5965 temp = E1000_READ_REG(hw, IAC);
5966 temp = E1000_READ_REG(hw, ICRXOC);
5967
5968 if (hw->mac_type == em_ich8lan) return;
5969
5970 temp = E1000_READ_REG(hw, ICRXPTC);
5971 temp = E1000_READ_REG(hw, ICRXATC);
5972 temp = E1000_READ_REG(hw, ICTXPTC);
5973 temp = E1000_READ_REG(hw, ICTXATC);
5974 temp = E1000_READ_REG(hw, ICTXQEC);
5975 temp = E1000_READ_REG(hw, ICTXQMTC);
5976 temp = E1000_READ_REG(hw, ICRXDMTC);
5977 }
5978
5979
5980
5981
5982
5983
5984
5985
5986 void
5987 em_tbi_adjust_stats(struct em_hw *hw,
5988 struct em_hw_stats *stats,
5989 uint32_t frame_len,
5990 uint8_t *mac_addr)
5991 {
5992 uint64_t carry_bit;
5993
5994
5995 frame_len--;
5996
5997
5998
5999
6000
6001 stats->crcerrs--;
6002
6003 stats->gprc++;
6004
6005
6006 carry_bit = 0x80000000 & stats->gorcl;
6007 stats->gorcl += frame_len;
6008
6009
6010
6011
6012
6013
6014
6015 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
6016 stats->gorch++;
6017
6018
6019
6020
6021 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6022
6023 stats->bprc++;
6024 else if (*mac_addr & 0x01)
6025
6026 stats->mprc++;
6027
6028 if (frame_len == hw->max_frame_size) {
6029
6030
6031
6032 if (stats->roc > 0)
6033 stats->roc--;
6034 }
6035
6036
6037
6038
6039 if (frame_len == 64) {
6040 stats->prc64++;
6041 stats->prc127--;
6042 } else if (frame_len == 127) {
6043 stats->prc127++;
6044 stats->prc255--;
6045 } else if (frame_len == 255) {
6046 stats->prc255++;
6047 stats->prc511--;
6048 } else if (frame_len == 511) {
6049 stats->prc511++;
6050 stats->prc1023--;
6051 } else if (frame_len == 1023) {
6052 stats->prc1023++;
6053 stats->prc1522--;
6054 } else if (frame_len == 1522) {
6055 stats->prc1522++;
6056 }
6057 }
6058
6059
6060
6061
6062
6063
6064 void
6065 em_get_bus_info(struct em_hw *hw)
6066 {
6067 int32_t ret_val;
6068 uint16_t pci_ex_link_status;
6069 uint32_t status;
6070
6071 switch (hw->mac_type) {
6072 case em_82542_rev2_0:
6073 case em_82542_rev2_1:
6074 hw->bus_type = em_bus_type_unknown;
6075 hw->bus_speed = em_bus_speed_unknown;
6076 hw->bus_width = em_bus_width_unknown;
6077 break;
6078 case em_82571:
6079 case em_82572:
6080 case em_82573:
6081 case em_80003es2lan:
6082 hw->bus_type = em_bus_type_pci_express;
6083 hw->bus_speed = em_bus_speed_2500;
6084 ret_val = em_read_pcie_cap_reg(hw,
6085 PCI_EX_LINK_STATUS,
6086 &pci_ex_link_status);
6087 if (ret_val)
6088 hw->bus_width = em_bus_width_unknown;
6089 else
6090 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6091 PCI_EX_LINK_WIDTH_SHIFT;
6092 break;
6093 case em_ich8lan:
6094 hw->bus_type = em_bus_type_pci_express;
6095 hw->bus_speed = em_bus_speed_2500;
6096 hw->bus_width = em_bus_width_pciex_1;
6097 break;
6098 default:
6099 status = E1000_READ_REG(hw, STATUS);
6100 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6101 em_bus_type_pcix : em_bus_type_pci;
6102
6103 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6104 hw->bus_speed = (hw->bus_type == em_bus_type_pci) ?
6105 em_bus_speed_66 : em_bus_speed_120;
6106 } else if (hw->bus_type == em_bus_type_pci) {
6107 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6108 em_bus_speed_66 : em_bus_speed_33;
6109 } else {
6110 switch (status & E1000_STATUS_PCIX_SPEED) {
6111 case E1000_STATUS_PCIX_SPEED_66:
6112 hw->bus_speed = em_bus_speed_66;
6113 break;
6114 case E1000_STATUS_PCIX_SPEED_100:
6115 hw->bus_speed = em_bus_speed_100;
6116 break;
6117 case E1000_STATUS_PCIX_SPEED_133:
6118 hw->bus_speed = em_bus_speed_133;
6119 break;
6120 default:
6121 hw->bus_speed = em_bus_speed_reserved;
6122 break;
6123 }
6124 }
6125 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6126 em_bus_width_64 : em_bus_width_32;
6127 break;
6128 }
6129 }
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139 STATIC void
6140 em_write_reg_io(struct em_hw *hw,
6141 uint32_t offset,
6142 uint32_t value)
6143 {
6144 unsigned long io_addr = hw->io_base;
6145 unsigned long io_data = hw->io_base + 4;
6146
6147 em_io_write(hw, io_addr, offset);
6148 em_io_write(hw, io_data, value);
6149 }
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166 STATIC int32_t
6167 em_get_cable_length(struct em_hw *hw,
6168 uint16_t *min_length,
6169 uint16_t *max_length)
6170 {
6171 int32_t ret_val;
6172 uint16_t agc_value = 0;
6173 uint16_t i, phy_data;
6174 uint16_t cable_length;
6175
6176 DEBUGFUNC("em_get_cable_length");
6177
6178 *min_length = *max_length = 0;
6179
6180
6181 if (hw->phy_type == em_phy_m88) {
6182
6183 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6184 &phy_data);
6185 if (ret_val)
6186 return ret_val;
6187 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6188 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6189
6190
6191 switch (cable_length) {
6192 case em_cable_length_50:
6193 *min_length = 0;
6194 *max_length = em_igp_cable_length_50;
6195 break;
6196 case em_cable_length_50_80:
6197 *min_length = em_igp_cable_length_50;
6198 *max_length = em_igp_cable_length_80;
6199 break;
6200 case em_cable_length_80_110:
6201 *min_length = em_igp_cable_length_80;
6202 *max_length = em_igp_cable_length_110;
6203 break;
6204 case em_cable_length_110_140:
6205 *min_length = em_igp_cable_length_110;
6206 *max_length = em_igp_cable_length_140;
6207 break;
6208 case em_cable_length_140:
6209 *min_length = em_igp_cable_length_140;
6210 *max_length = em_igp_cable_length_170;
6211 break;
6212 default:
6213 return -E1000_ERR_PHY;
6214 break;
6215 }
6216 } else if (hw->phy_type == em_phy_gg82563) {
6217 ret_val = em_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6218 &phy_data);
6219 if (ret_val)
6220 return ret_val;
6221 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6222
6223 switch (cable_length) {
6224 case em_gg_cable_length_60:
6225 *min_length = 0;
6226 *max_length = em_igp_cable_length_60;
6227 break;
6228 case em_gg_cable_length_60_115:
6229 *min_length = em_igp_cable_length_60;
6230 *max_length = em_igp_cable_length_115;
6231 break;
6232 case em_gg_cable_length_115_150:
6233 *min_length = em_igp_cable_length_115;
6234 *max_length = em_igp_cable_length_150;
6235 break;
6236 case em_gg_cable_length_150:
6237 *min_length = em_igp_cable_length_150;
6238 *max_length = em_igp_cable_length_180;
6239 break;
6240 default:
6241 return -E1000_ERR_PHY;
6242 break;
6243 }
6244 } else if (hw->phy_type == em_phy_igp) {
6245 uint16_t cur_agc_value;
6246 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6247 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6248 {IGP01E1000_PHY_AGC_A,
6249 IGP01E1000_PHY_AGC_B,
6250 IGP01E1000_PHY_AGC_C,
6251 IGP01E1000_PHY_AGC_D};
6252
6253 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6254
6255 ret_val = em_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6256 if (ret_val)
6257 return ret_val;
6258
6259 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6260
6261
6262 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6263 (cur_agc_value == 0))
6264 return -E1000_ERR_PHY;
6265
6266 agc_value += cur_agc_value;
6267
6268
6269 if (min_agc_value > cur_agc_value)
6270 min_agc_value = cur_agc_value;
6271 }
6272
6273
6274 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * em_igp_cable_length_50) {
6275 agc_value -= min_agc_value;
6276
6277
6278 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6279 } else {
6280
6281 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6282 }
6283
6284
6285 *min_length = ((em_igp_cable_length_table[agc_value] -
6286 IGP01E1000_AGC_RANGE) > 0) ?
6287 (em_igp_cable_length_table[agc_value] -
6288 IGP01E1000_AGC_RANGE) : 0;
6289 *max_length = em_igp_cable_length_table[agc_value] +
6290 IGP01E1000_AGC_RANGE;
6291 } else if (hw->phy_type == em_phy_igp_2 ||
6292 hw->phy_type == em_phy_igp_3) {
6293 uint16_t cur_agc_index, max_agc_index = 0;
6294 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6295 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6296 {IGP02E1000_PHY_AGC_A,
6297 IGP02E1000_PHY_AGC_B,
6298 IGP02E1000_PHY_AGC_C,
6299 IGP02E1000_PHY_AGC_D};
6300
6301 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6302 ret_val = em_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6303 if (ret_val)
6304 return ret_val;
6305
6306
6307
6308
6309 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6310 IGP02E1000_AGC_LENGTH_MASK;
6311
6312
6313 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6314 (cur_agc_index == 0))
6315 return -E1000_ERR_PHY;
6316
6317
6318 if (em_igp_2_cable_length_table[min_agc_index] >
6319 em_igp_2_cable_length_table[cur_agc_index])
6320 min_agc_index = cur_agc_index;
6321 if (em_igp_2_cable_length_table[max_agc_index] <
6322 em_igp_2_cable_length_table[cur_agc_index])
6323 max_agc_index = cur_agc_index;
6324
6325 agc_value += em_igp_2_cable_length_table[cur_agc_index];
6326 }
6327
6328 agc_value -= (em_igp_2_cable_length_table[min_agc_index] +
6329 em_igp_2_cable_length_table[max_agc_index]);
6330 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6331
6332
6333 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6334 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6335 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6336 }
6337
6338 return E1000_SUCCESS;
6339 }
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356 STATIC int32_t
6357 em_check_downshift(struct em_hw *hw)
6358 {
6359 int32_t ret_val;
6360 uint16_t phy_data;
6361
6362 DEBUGFUNC("em_check_downshift");
6363
6364 if (hw->phy_type == em_phy_igp ||
6365 hw->phy_type == em_phy_igp_3 ||
6366 hw->phy_type == em_phy_igp_2) {
6367 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6368 &phy_data);
6369 if (ret_val)
6370 return ret_val;
6371
6372 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6373 } else if ((hw->phy_type == em_phy_m88) ||
6374 (hw->phy_type == em_phy_gg82563)) {
6375 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6376 &phy_data);
6377 if (ret_val)
6378 return ret_val;
6379
6380 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6381 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6382 } else if (hw->phy_type == em_phy_ife) {
6383
6384 hw->speed_downgraded = FALSE;
6385 }
6386
6387 return E1000_SUCCESS;
6388 }
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402 STATIC int32_t
6403 em_config_dsp_after_link_change(struct em_hw *hw,
6404 boolean_t link_up)
6405 {
6406 int32_t ret_val;
6407 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6408 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6409 {IGP01E1000_PHY_AGC_PARAM_A,
6410 IGP01E1000_PHY_AGC_PARAM_B,
6411 IGP01E1000_PHY_AGC_PARAM_C,
6412 IGP01E1000_PHY_AGC_PARAM_D};
6413 uint16_t min_length, max_length;
6414
6415 DEBUGFUNC("em_config_dsp_after_link_change");
6416
6417 if (hw->phy_type != em_phy_igp)
6418 return E1000_SUCCESS;
6419
6420 if (link_up) {
6421 ret_val = em_get_speed_and_duplex(hw, &speed, &duplex);
6422 if (ret_val) {
6423 DEBUGOUT("Error getting link speed and duplex\n");
6424 return ret_val;
6425 }
6426
6427 if (speed == SPEED_1000) {
6428
6429 ret_val = em_get_cable_length(hw, &min_length, &max_length);
6430 if (ret_val)
6431 return ret_val;
6432
6433 if ((hw->dsp_config_state == em_dsp_config_enabled) &&
6434 min_length >= em_igp_cable_length_50) {
6435
6436 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6437 ret_val = em_read_phy_reg(hw, dsp_reg_array[i],
6438 &phy_data);
6439 if (ret_val)
6440 return ret_val;
6441
6442 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6443
6444 ret_val = em_write_phy_reg(hw, dsp_reg_array[i],
6445 phy_data);
6446 if (ret_val)
6447 return ret_val;
6448 }
6449 hw->dsp_config_state = em_dsp_config_activated;
6450 }
6451
6452 if ((hw->ffe_config_state == em_ffe_config_enabled) &&
6453 (min_length < em_igp_cable_length_50)) {
6454
6455 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6456 uint32_t idle_errs = 0;
6457
6458
6459 ret_val = em_read_phy_reg(hw, PHY_1000T_STATUS,
6460 &phy_data);
6461 if (ret_val)
6462 return ret_val;
6463
6464 for (i = 0; i < ffe_idle_err_timeout; i++) {
6465 usec_delay(1000);
6466 ret_val = em_read_phy_reg(hw, PHY_1000T_STATUS,
6467 &phy_data);
6468 if (ret_val)
6469 return ret_val;
6470
6471 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
6472 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
6473 hw->ffe_config_state = em_ffe_config_active;
6474
6475 ret_val = em_write_phy_reg(hw,
6476 IGP01E1000_PHY_DSP_FFE,
6477 IGP01E1000_PHY_DSP_FFE_CM_CP);
6478 if (ret_val)
6479 return ret_val;
6480 break;
6481 }
6482
6483 if (idle_errs)
6484 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6485 }
6486 }
6487 }
6488 } else {
6489 if (hw->dsp_config_state == em_dsp_config_activated) {
6490
6491
6492 ret_val = em_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6493
6494 if (ret_val)
6495 return ret_val;
6496
6497
6498 ret_val = em_write_phy_reg(hw, 0x2F5B, 0x0003);
6499
6500 if (ret_val)
6501 return ret_val;
6502
6503 msec_delay_irq(20);
6504
6505 ret_val = em_write_phy_reg(hw, 0x0000,
6506 IGP01E1000_IEEE_FORCE_GIGA);
6507 if (ret_val)
6508 return ret_val;
6509 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6510 ret_val = em_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
6511 if (ret_val)
6512 return ret_val;
6513
6514 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6515 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6516
6517 ret_val = em_write_phy_reg(hw,dsp_reg_array[i], phy_data);
6518 if (ret_val)
6519 return ret_val;
6520 }
6521
6522 ret_val = em_write_phy_reg(hw, 0x0000,
6523 IGP01E1000_IEEE_RESTART_AUTONEG);
6524 if (ret_val)
6525 return ret_val;
6526
6527 msec_delay_irq(20);
6528
6529
6530 ret_val = em_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6531
6532 if (ret_val)
6533 return ret_val;
6534
6535 hw->dsp_config_state = em_dsp_config_enabled;
6536 }
6537
6538 if (hw->ffe_config_state == em_ffe_config_active) {
6539
6540
6541 ret_val = em_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6542
6543 if (ret_val)
6544 return ret_val;
6545
6546
6547 ret_val = em_write_phy_reg(hw, 0x2F5B, 0x0003);
6548
6549 if (ret_val)
6550 return ret_val;
6551
6552 msec_delay_irq(20);
6553
6554 ret_val = em_write_phy_reg(hw, 0x0000,
6555 IGP01E1000_IEEE_FORCE_GIGA);
6556 if (ret_val)
6557 return ret_val;
6558 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6559 IGP01E1000_PHY_DSP_FFE_DEFAULT);
6560 if (ret_val)
6561 return ret_val;
6562
6563 ret_val = em_write_phy_reg(hw, 0x0000,
6564 IGP01E1000_IEEE_RESTART_AUTONEG);
6565 if (ret_val)
6566 return ret_val;
6567
6568 msec_delay_irq(20);
6569
6570
6571 ret_val = em_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6572
6573 if (ret_val)
6574 return ret_val;
6575
6576 hw->ffe_config_state = em_ffe_config_enabled;
6577 }
6578 }
6579 return E1000_SUCCESS;
6580 }
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590 static int32_t
6591 em_set_phy_mode(struct em_hw *hw)
6592 {
6593 int32_t ret_val;
6594 uint16_t eeprom_data;
6595
6596 DEBUGFUNC("em_set_phy_mode");
6597
6598 if ((hw->mac_type == em_82545_rev_3) &&
6599 (hw->media_type == em_media_type_copper)) {
6600 ret_val = em_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
6601 if (ret_val) {
6602 return ret_val;
6603 }
6604
6605 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
6606 (eeprom_data & EEPROM_PHY_CLASS_A)) {
6607 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
6608 if (ret_val)
6609 return ret_val;
6610 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
6611 if (ret_val)
6612 return ret_val;
6613
6614 hw->phy_reset_disable = FALSE;
6615 }
6616 }
6617
6618 return E1000_SUCCESS;
6619 }
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635 STATIC int32_t
6636 em_set_d3_lplu_state(struct em_hw *hw,
6637 boolean_t active)
6638 {
6639 uint32_t phy_ctrl = 0;
6640 int32_t ret_val;
6641 uint16_t phy_data;
6642 DEBUGFUNC("em_set_d3_lplu_state");
6643
6644 if (hw->phy_type != em_phy_igp && hw->phy_type != em_phy_igp_2
6645 && hw->phy_type != em_phy_igp_3)
6646 return E1000_SUCCESS;
6647
6648
6649
6650
6651 if (hw->mac_type == em_82541_rev_2 || hw->mac_type == em_82547_rev_2) {
6652 ret_val = em_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
6653 if (ret_val)
6654 return ret_val;
6655 } else if (hw->mac_type == em_ich8lan) {
6656
6657
6658
6659 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
6660 } else {
6661 ret_val = em_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6662 if (ret_val)
6663 return ret_val;
6664 }
6665
6666 if (!active) {
6667 if (hw->mac_type == em_82541_rev_2 ||
6668 hw->mac_type == em_82547_rev_2) {
6669 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
6670 ret_val = em_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6671 if (ret_val)
6672 return ret_val;
6673 } else {
6674 if (hw->mac_type == em_ich8lan) {
6675 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
6676 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
6677 } else {
6678 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6679 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6680 phy_data);
6681 if (ret_val)
6682 return ret_val;
6683 }
6684 }
6685
6686
6687
6688
6689
6690 if (hw->smart_speed == em_smart_speed_on) {
6691 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6692 &phy_data);
6693 if (ret_val)
6694 return ret_val;
6695
6696 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6697 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6698 phy_data);
6699 if (ret_val)
6700 return ret_val;
6701 } else if (hw->smart_speed == em_smart_speed_off) {
6702 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6703 &phy_data);
6704 if (ret_val)
6705 return ret_val;
6706
6707 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6708 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6709 phy_data);
6710 if (ret_val)
6711 return ret_val;
6712 }
6713
6714 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
6715 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
6716 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6717
6718 if (hw->mac_type == em_82541_rev_2 ||
6719 hw->mac_type == em_82547_rev_2) {
6720 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6721 ret_val = em_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6722 if (ret_val)
6723 return ret_val;
6724 } else {
6725 if (hw->mac_type == em_ich8lan) {
6726 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
6727 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
6728 } else {
6729 phy_data |= IGP02E1000_PM_D3_LPLU;
6730 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6731 phy_data);
6732 if (ret_val)
6733 return ret_val;
6734 }
6735 }
6736
6737
6738 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6739 if (ret_val)
6740 return ret_val;
6741
6742 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6743 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6744 if (ret_val)
6745 return ret_val;
6746
6747 }
6748 return E1000_SUCCESS;
6749 }
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765 STATIC int32_t
6766 em_set_d0_lplu_state(struct em_hw *hw,
6767 boolean_t active)
6768 {
6769 uint32_t phy_ctrl = 0;
6770 int32_t ret_val;
6771 uint16_t phy_data;
6772 DEBUGFUNC("em_set_d0_lplu_state");
6773
6774 if (hw->mac_type <= em_82547_rev_2)
6775 return E1000_SUCCESS;
6776
6777 if (hw->mac_type == em_ich8lan) {
6778 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
6779 } else {
6780 ret_val = em_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6781 if (ret_val)
6782 return ret_val;
6783 }
6784
6785 if (!active) {
6786 if (hw->mac_type == em_ich8lan) {
6787 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
6788 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
6789 } else {
6790 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6791 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6792 if (ret_val)
6793 return ret_val;
6794 }
6795
6796
6797
6798
6799
6800 if (hw->smart_speed == em_smart_speed_on) {
6801 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6802 &phy_data);
6803 if (ret_val)
6804 return ret_val;
6805
6806 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6807 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6808 phy_data);
6809 if (ret_val)
6810 return ret_val;
6811 } else if (hw->smart_speed == em_smart_speed_off) {
6812 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6813 &phy_data);
6814 if (ret_val)
6815 return ret_val;
6816
6817 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6818 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6819 phy_data);
6820 if (ret_val)
6821 return ret_val;
6822 }
6823
6824
6825 } else {
6826
6827 if (hw->mac_type == em_ich8lan) {
6828 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
6829 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
6830 } else {
6831 phy_data |= IGP02E1000_PM_D0_LPLU;
6832 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6833 if (ret_val)
6834 return ret_val;
6835 }
6836
6837
6838 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6839 if (ret_val)
6840 return ret_val;
6841
6842 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6843 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6844 if (ret_val)
6845 return ret_val;
6846
6847 }
6848 return E1000_SUCCESS;
6849 }
6850
6851
6852
6853
6854
6855
6856 static int32_t
6857 em_set_vco_speed(struct em_hw *hw)
6858 {
6859 int32_t ret_val;
6860 uint16_t default_page = 0;
6861 uint16_t phy_data;
6862
6863 DEBUGFUNC("em_set_vco_speed");
6864
6865 switch (hw->mac_type) {
6866 case em_82545_rev_3:
6867 case em_82546_rev_3:
6868 break;
6869 default:
6870 return E1000_SUCCESS;
6871 }
6872
6873
6874
6875 ret_val = em_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6876 if (ret_val)
6877 return ret_val;
6878
6879 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6880 if (ret_val)
6881 return ret_val;
6882
6883 ret_val = em_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6884 if (ret_val)
6885 return ret_val;
6886
6887 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6888 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6889 if (ret_val)
6890 return ret_val;
6891
6892
6893
6894 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6895 if (ret_val)
6896 return ret_val;
6897
6898 ret_val = em_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6899 if (ret_val)
6900 return ret_val;
6901
6902 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6903 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6904 if (ret_val)
6905 return ret_val;
6906
6907 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6908 if (ret_val)
6909 return ret_val;
6910
6911 return E1000_SUCCESS;
6912 }
6913
6914
6915
6916
6917
6918
6919
6920 STATIC int32_t
6921 em_host_if_read_cookie(struct em_hw * hw, uint8_t *buffer)
6922 {
6923 uint8_t i;
6924 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
6925 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6926
6927 length = (length >> 2);
6928 offset = (offset >> 2);
6929
6930 for (i = 0; i < length; i++) {
6931 *((uint32_t *) buffer + i) =
6932 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6933 }
6934 return E1000_SUCCESS;
6935 }
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947 STATIC int32_t
6948 em_mng_enable_host_if(struct em_hw * hw)
6949 {
6950 uint32_t hicr;
6951 uint8_t i;
6952
6953
6954 hicr = E1000_READ_REG(hw, HICR);
6955 if ((hicr & E1000_HICR_EN) == 0) {
6956 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6957 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6958 }
6959
6960 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6961 hicr = E1000_READ_REG(hw, HICR);
6962 if (!(hicr & E1000_HICR_C))
6963 break;
6964 msec_delay_irq(1);
6965 }
6966
6967 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
6968 DEBUGOUT("Previous command timeout failed .\n");
6969 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6970 }
6971 return E1000_SUCCESS;
6972 }
6973
6974
6975
6976
6977
6978
6979 boolean_t
6980 em_check_mng_mode(struct em_hw *hw)
6981 {
6982 uint32_t fwsm;
6983
6984 fwsm = E1000_READ_REG(hw, FWSM);
6985
6986 if (hw->mac_type == em_ich8lan) {
6987 if ((fwsm & E1000_FWSM_MODE_MASK) ==
6988 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6989 return TRUE;
6990 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
6991 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6992 return TRUE;
6993
6994 return FALSE;
6995 }
6996
6997
6998
6999
7000
7001
7002 STATIC uint8_t
7003 em_calculate_mng_checksum(char *buffer, uint32_t length)
7004 {
7005 uint8_t sum = 0;
7006 uint32_t i;
7007
7008 if (!buffer)
7009 return 0;
7010
7011 for (i=0; i < length; i++)
7012 sum += buffer[i];
7013
7014 return (uint8_t) (0 - sum);
7015 }
7016
7017
7018
7019
7020
7021
7022 boolean_t
7023 em_enable_tx_pkt_filtering(struct em_hw *hw)
7024 {
7025
7026
7027 int32_t ret_val, checksum;
7028 boolean_t tx_filter = FALSE;
7029 struct em_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7030 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7031
7032 if (em_check_mng_mode(hw)) {
7033 ret_val = em_mng_enable_host_if(hw);
7034 if (ret_val == E1000_SUCCESS) {
7035 ret_val = em_host_if_read_cookie(hw, buffer);
7036 if (ret_val == E1000_SUCCESS) {
7037 checksum = hdr->checksum;
7038 hdr->checksum = 0;
7039 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7040 checksum == em_calculate_mng_checksum((char *)buffer,
7041 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7042 if (hdr->status &
7043 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7044 tx_filter = TRUE;
7045 } else
7046 tx_filter = TRUE;
7047 } else
7048 tx_filter = TRUE;
7049 }
7050 }
7051
7052 hw->tx_pkt_filtering = tx_filter;
7053 return tx_filter;
7054 }
7055
7056
7057 static int32_t
7058 em_polarity_reversal_workaround(struct em_hw *hw)
7059 {
7060 int32_t ret_val;
7061 uint16_t mii_status_reg;
7062 uint16_t i;
7063
7064
7065
7066
7067
7068 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7069 if (ret_val)
7070 return ret_val;
7071 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7072 if (ret_val)
7073 return ret_val;
7074
7075 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7076 if (ret_val)
7077 return ret_val;
7078
7079
7080 for (i = PHY_FORCE_TIME; i > 0; i--) {
7081
7082
7083
7084
7085 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7086 if (ret_val)
7087 return ret_val;
7088
7089 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7090 if (ret_val)
7091 return ret_val;
7092
7093 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7094 msec_delay_irq(100);
7095 }
7096
7097
7098 msec_delay_irq(1000);
7099
7100
7101
7102 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7103 if (ret_val)
7104 return ret_val;
7105 msec_delay_irq(50);
7106 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7107 if (ret_val)
7108 return ret_val;
7109 msec_delay_irq(50);
7110 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7111 if (ret_val)
7112 return ret_val;
7113 msec_delay_irq(50);
7114 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7115 if (ret_val)
7116 return ret_val;
7117
7118 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7119 if (ret_val)
7120 return ret_val;
7121
7122
7123 for (i = PHY_FORCE_TIME; i > 0; i--) {
7124
7125
7126
7127
7128 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7129 if (ret_val)
7130 return ret_val;
7131
7132 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7133 if (ret_val)
7134 return ret_val;
7135
7136 if (mii_status_reg & MII_SR_LINK_STATUS) break;
7137 msec_delay_irq(100);
7138 }
7139 return E1000_SUCCESS;
7140 }
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151 STATIC void
7152 em_set_pci_express_master_disable(struct em_hw *hw)
7153 {
7154 uint32_t ctrl;
7155
7156 DEBUGFUNC("em_set_pci_express_master_disable");
7157
7158 if (hw->bus_type != em_bus_type_pci_express)
7159 return;
7160
7161 ctrl = E1000_READ_REG(hw, CTRL);
7162 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7163 E1000_WRITE_REG(hw, CTRL, ctrl);
7164 }
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177 int32_t
7178 em_disable_pciex_master(struct em_hw *hw)
7179 {
7180 int32_t timeout = MASTER_DISABLE_TIMEOUT;
7181
7182 DEBUGFUNC("em_disable_pciex_master");
7183
7184 if (hw->bus_type != em_bus_type_pci_express)
7185 return E1000_SUCCESS;
7186
7187 em_set_pci_express_master_disable(hw);
7188
7189 while (timeout) {
7190 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7191 break;
7192 else
7193 usec_delay(100);
7194 timeout--;
7195 }
7196
7197 if (!timeout) {
7198 DEBUGOUT("Master requests are pending.\n");
7199 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7200 }
7201
7202 return E1000_SUCCESS;
7203 }
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215 STATIC int32_t
7216 em_get_auto_rd_done(struct em_hw *hw)
7217 {
7218 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7219
7220 DEBUGFUNC("em_get_auto_rd_done");
7221
7222 switch (hw->mac_type) {
7223 default:
7224 msec_delay(5);
7225 break;
7226 case em_82571:
7227 case em_82572:
7228 case em_82573:
7229 case em_80003es2lan:
7230 case em_ich8lan:
7231 while (timeout) {
7232 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
7233 break;
7234 else msec_delay(1);
7235 timeout--;
7236 }
7237
7238 if (!timeout) {
7239 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7240 return -E1000_ERR_RESET;
7241 }
7242 break;
7243 }
7244
7245
7246
7247
7248 if (hw->mac_type == em_82573)
7249 msec_delay(25);
7250
7251 return E1000_SUCCESS;
7252 }
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263 STATIC int32_t
7264 em_get_phy_cfg_done(struct em_hw *hw)
7265 {
7266 int32_t timeout = PHY_CFG_TIMEOUT;
7267 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
7268
7269 DEBUGFUNC("em_get_phy_cfg_done");
7270
7271 switch (hw->mac_type) {
7272 default:
7273 msec_delay_irq(10);
7274 break;
7275 case em_80003es2lan:
7276
7277 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
7278 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7279
7280 case em_82571:
7281 case em_82572:
7282 while (timeout) {
7283 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
7284 break;
7285 else
7286 msec_delay(1);
7287 timeout--;
7288 }
7289 if (!timeout) {
7290 DEBUGOUT("MNG configuration cycle has not completed.\n");
7291 return -E1000_ERR_RESET;
7292 }
7293 break;
7294 }
7295
7296 return E1000_SUCCESS;
7297 }
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310 STATIC int32_t
7311 em_get_hw_eeprom_semaphore(struct em_hw *hw)
7312 {
7313 int32_t timeout;
7314 uint32_t swsm;
7315
7316 DEBUGFUNC("em_get_hw_eeprom_semaphore");
7317
7318 if (!hw->eeprom_semaphore_present)
7319 return E1000_SUCCESS;
7320
7321 if (hw->mac_type == em_80003es2lan) {
7322
7323 if (em_get_software_semaphore(hw) != E1000_SUCCESS)
7324 return -E1000_ERR_EEPROM;
7325 }
7326
7327
7328 timeout = hw->eeprom.word_size + 1;
7329 while (timeout) {
7330 swsm = E1000_READ_REG(hw, SWSM);
7331 swsm |= E1000_SWSM_SWESMBI;
7332 E1000_WRITE_REG(hw, SWSM, swsm);
7333
7334 swsm = E1000_READ_REG(hw, SWSM);
7335 if (swsm & E1000_SWSM_SWESMBI)
7336 break;
7337
7338 usec_delay(50);
7339 timeout--;
7340 }
7341
7342 if (!timeout) {
7343
7344 em_put_hw_eeprom_semaphore(hw);
7345 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7346 return -E1000_ERR_EEPROM;
7347 }
7348
7349 return E1000_SUCCESS;
7350 }
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360 STATIC void
7361 em_put_hw_eeprom_semaphore(struct em_hw *hw)
7362 {
7363 uint32_t swsm;
7364
7365 DEBUGFUNC("em_put_hw_eeprom_semaphore");
7366
7367 if (!hw->eeprom_semaphore_present)
7368 return;
7369
7370 swsm = E1000_READ_REG(hw, SWSM);
7371 if (hw->mac_type == em_80003es2lan) {
7372
7373 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7374 } else
7375 swsm &= ~(E1000_SWSM_SWESMBI);
7376 E1000_WRITE_REG(hw, SWSM, swsm);
7377 }
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389 STATIC int32_t
7390 em_get_software_semaphore(struct em_hw *hw)
7391 {
7392 int32_t timeout = hw->eeprom.word_size + 1;
7393 uint32_t swsm;
7394
7395 DEBUGFUNC("em_get_software_semaphore");
7396
7397 if (hw->mac_type != em_80003es2lan)
7398 return E1000_SUCCESS;
7399
7400 while (timeout) {
7401 swsm = E1000_READ_REG(hw, SWSM);
7402
7403 if (!(swsm & E1000_SWSM_SMBI))
7404 break;
7405 msec_delay_irq(1);
7406 timeout--;
7407 }
7408
7409 if (!timeout) {
7410 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
7411 return -E1000_ERR_RESET;
7412 }
7413
7414 return E1000_SUCCESS;
7415 }
7416
7417
7418
7419
7420
7421
7422
7423
7424 STATIC void
7425 em_release_software_semaphore(struct em_hw *hw)
7426 {
7427 uint32_t swsm;
7428
7429 DEBUGFUNC("em_release_software_semaphore");
7430
7431 if (hw->mac_type != em_80003es2lan)
7432 return;
7433
7434 swsm = E1000_READ_REG(hw, SWSM);
7435
7436 swsm &= ~E1000_SWSM_SMBI;
7437 E1000_WRITE_REG(hw, SWSM, swsm);
7438 }
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451 int32_t
7452 em_check_phy_reset_block(struct em_hw *hw)
7453 {
7454 uint32_t manc = 0;
7455 uint32_t fwsm = 0;
7456
7457 if (hw->mac_type == em_ich8lan) {
7458 fwsm = E1000_READ_REG(hw, FWSM);
7459 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
7460 : E1000_BLK_PHY_RESET;
7461 }
7462
7463 if (hw->mac_type > em_82547_rev_2)
7464 manc = E1000_READ_REG(hw, MANC);
7465 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
7466 E1000_BLK_PHY_RESET : E1000_SUCCESS;
7467 }
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478 STATIC int32_t
7479 em_set_pci_ex_no_snoop(struct em_hw *hw, uint32_t no_snoop)
7480 {
7481 uint32_t gcr_reg = 0;
7482
7483 DEBUGFUNC("em_set_pci_ex_no_snoop");
7484
7485 if (hw->bus_type == em_bus_type_unknown)
7486 em_get_bus_info(hw);
7487
7488 if (hw->bus_type != em_bus_type_pci_express)
7489 return E1000_SUCCESS;
7490
7491 if (no_snoop) {
7492 gcr_reg = E1000_READ_REG(hw, GCR);
7493 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
7494 gcr_reg |= no_snoop;
7495 E1000_WRITE_REG(hw, GCR, gcr_reg);
7496 }
7497 if (hw->mac_type == em_ich8lan) {
7498 uint32_t ctrl_ext;
7499
7500 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
7501
7502 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
7503 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
7504 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
7505 }
7506
7507 return E1000_SUCCESS;
7508 }
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519 STATIC int32_t
7520 em_get_software_flag(struct em_hw *hw)
7521 {
7522 int32_t timeout = PHY_CFG_TIMEOUT;
7523 uint32_t extcnf_ctrl;
7524
7525 DEBUGFUNC("em_get_software_flag");
7526
7527 if (hw->mac_type == em_ich8lan) {
7528 while (timeout) {
7529 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
7530 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
7531 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
7532
7533 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
7534 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
7535 break;
7536 msec_delay_irq(1);
7537 timeout--;
7538 }
7539
7540 if (!timeout) {
7541 DEBUGOUT("FW or HW locks the resource too long.\n");
7542 return -E1000_ERR_CONFIG;
7543 }
7544 }
7545
7546 return E1000_SUCCESS;
7547 }
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558 STATIC void
7559 em_release_software_flag(struct em_hw *hw)
7560 {
7561 uint32_t extcnf_ctrl;
7562
7563 DEBUGFUNC("em_release_software_flag");
7564
7565 if (hw->mac_type == em_ich8lan) {
7566 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
7567 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
7568 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
7569 }
7570
7571 return;
7572 }
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584 STATIC int32_t
7585 em_read_eeprom_ich8(struct em_hw *hw, uint16_t offset, uint16_t words,
7586 uint16_t *data)
7587 {
7588 int32_t error = E1000_SUCCESS;
7589 uint32_t flash_bank = 0;
7590 uint32_t act_offset = 0;
7591 uint32_t bank_offset = 0;
7592 uint16_t word = 0;
7593 uint16_t i = 0;
7594
7595
7596
7597
7598
7599
7600
7601 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
7602
7603
7604 bank_offset = flash_bank * (hw->flash_bank_size * 2);
7605
7606 error = em_get_software_flag(hw);
7607 if (error != E1000_SUCCESS)
7608 return error;
7609
7610 for (i = 0; i < words; i++) {
7611 if (hw->eeprom_shadow_ram != NULL &&
7612 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
7613 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
7614 } else {
7615
7616 act_offset = bank_offset + ((offset + i) * 2);
7617 error = em_read_ich8_word(hw, act_offset, &word);
7618 if (error != E1000_SUCCESS)
7619 break;
7620 data[i] = word;
7621 }
7622 }
7623
7624 em_release_software_flag(hw);
7625
7626 return error;
7627 }
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640 STATIC int32_t
7641 em_write_eeprom_ich8(struct em_hw *hw, uint16_t offset, uint16_t words,
7642 uint16_t *data)
7643 {
7644 uint32_t i = 0;
7645 int32_t error = E1000_SUCCESS;
7646
7647 error = em_get_software_flag(hw);
7648 if (error != E1000_SUCCESS)
7649 return error;
7650
7651
7652
7653
7654
7655
7656
7657
7658 if (hw->eeprom_shadow_ram != NULL) {
7659 for (i = 0; i < words; i++) {
7660 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
7661 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
7662 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
7663 } else {
7664 error = -E1000_ERR_EEPROM;
7665 break;
7666 }
7667 }
7668 } else {
7669
7670
7671
7672
7673 error = -E1000_ERR_EEPROM;
7674 }
7675
7676 em_release_software_flag(hw);
7677
7678 return error;
7679 }
7680
7681
7682
7683
7684
7685
7686
7687 STATIC int32_t
7688 em_ich8_cycle_init(struct em_hw *hw)
7689 {
7690 union ich8_hws_flash_status hsfsts;
7691 int32_t error = E1000_ERR_EEPROM;
7692 int32_t i = 0;
7693
7694 DEBUGFUNC("em_ich8_cycle_init");
7695
7696 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
7697
7698
7699 if (hsfsts.hsf_status.fldesvalid == 0) {
7700 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
7701 return error;
7702 }
7703
7704
7705
7706 hsfsts.hsf_status.flcerr = 1;
7707 hsfsts.hsf_status.dael = 1;
7708
7709 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720 if (hsfsts.hsf_status.flcinprog == 0) {
7721
7722
7723 hsfsts.hsf_status.flcdone = 1;
7724 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
7725 error = E1000_SUCCESS;
7726 } else {
7727
7728
7729 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
7730 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
7731 if (hsfsts.hsf_status.flcinprog == 0) {
7732 error = E1000_SUCCESS;
7733 break;
7734 }
7735 usec_delay(1);
7736 }
7737 if (error == E1000_SUCCESS) {
7738
7739
7740 hsfsts.hsf_status.flcdone = 1;
7741 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
7742 } else {
7743 DEBUGOUT("Flash controller busy, cannot get access");
7744 }
7745 }
7746 return error;
7747 }
7748
7749
7750
7751
7752
7753
7754 STATIC int32_t
7755 em_ich8_flash_cycle(struct em_hw *hw, uint32_t timeout)
7756 {
7757 union ich8_hws_flash_ctrl hsflctl;
7758 union ich8_hws_flash_status hsfsts;
7759 int32_t error = E1000_ERR_EEPROM;
7760 uint32_t i = 0;
7761
7762
7763 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
7764 hsflctl.hsf_ctrl.flcgo = 1;
7765 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
7766
7767
7768 do {
7769 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
7770 if (hsfsts.hsf_status.flcdone == 1)
7771 break;
7772 usec_delay(1);
7773 i++;
7774 } while (i < timeout);
7775 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
7776 error = E1000_SUCCESS;
7777 }
7778 return error;
7779 }
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789 STATIC int32_t
7790 em_read_ich8_data(struct em_hw *hw, uint32_t index,
7791 uint32_t size, uint16_t* data)
7792 {
7793 union ich8_hws_flash_status hsfsts;
7794 union ich8_hws_flash_ctrl hsflctl;
7795 uint32_t flash_linear_address;
7796 uint32_t flash_data = 0;
7797 int32_t error = -E1000_ERR_EEPROM;
7798 int32_t count = 0;
7799
7800 DEBUGFUNC("em_read_ich8_data");
7801
7802 if (size < 1 || size > 2 || data == 0x0 ||
7803 index > ICH_FLASH_LINEAR_ADDR_MASK)
7804 return error;
7805
7806 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
7807 hw->flash_base_addr;
7808
7809 do {
7810 usec_delay(1);
7811
7812 error = em_ich8_cycle_init(hw);
7813 if (error != E1000_SUCCESS)
7814 break;
7815
7816 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
7817
7818 hsflctl.hsf_ctrl.fldbcount = size - 1;
7819 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
7820 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
7821
7822
7823
7824
7825
7826 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
7827
7828 error = em_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
7829
7830
7831
7832
7833 if (error == E1000_SUCCESS) {
7834 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
7835 if (size == 1) {
7836 *data = (uint8_t)(flash_data & 0x000000FF);
7837 } else if (size == 2) {
7838 *data = (uint16_t)(flash_data & 0x0000FFFF);
7839 }
7840 break;
7841 } else {
7842
7843
7844
7845
7846 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
7847 if (hsfsts.hsf_status.flcerr == 1) {
7848
7849 continue;
7850 } else if (hsfsts.hsf_status.flcdone == 0) {
7851 DEBUGOUT("Timeout error - flash cycle did not complete.");
7852 break;
7853 }
7854 }
7855 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
7856
7857 return error;
7858 }
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868 STATIC int32_t
7869 em_write_ich8_data(struct em_hw *hw, uint32_t index, uint32_t size,
7870 uint16_t data)
7871 {
7872 union ich8_hws_flash_status hsfsts;
7873 union ich8_hws_flash_ctrl hsflctl;
7874 uint32_t flash_linear_address;
7875 uint32_t flash_data = 0;
7876 int32_t error = -E1000_ERR_EEPROM;
7877 int32_t count = 0;
7878
7879 DEBUGFUNC("em_write_ich8_data");
7880
7881 if (size < 1 || size > 2 || data > size * 0xff ||
7882 index > ICH_FLASH_LINEAR_ADDR_MASK)
7883 return error;
7884
7885 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
7886 hw->flash_base_addr;
7887
7888 do {
7889 usec_delay(1);
7890
7891 error = em_ich8_cycle_init(hw);
7892 if (error != E1000_SUCCESS)
7893 break;
7894
7895 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
7896
7897 hsflctl.hsf_ctrl.fldbcount = size -1;
7898 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
7899 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
7900
7901
7902
7903 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
7904
7905 if (size == 1)
7906 flash_data = (uint32_t)data & 0x00FF;
7907 else
7908 flash_data = (uint32_t)data;
7909
7910 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
7911
7912
7913
7914 error = em_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
7915 if (error == E1000_SUCCESS) {
7916 break;
7917 } else {
7918
7919
7920
7921
7922 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
7923 if (hsfsts.hsf_status.flcerr == 1) {
7924
7925 continue;
7926 } else if (hsfsts.hsf_status.flcdone == 0) {
7927 DEBUGOUT("Timeout error - flash cycle did not complete.");
7928 break;
7929 }
7930 }
7931 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
7932
7933 return error;
7934 }
7935
7936
7937
7938
7939
7940
7941
7942
7943 STATIC int32_t
7944 em_read_ich8_byte(struct em_hw *hw, uint32_t index, uint8_t* data)
7945 {
7946 int32_t status = E1000_SUCCESS;
7947 uint16_t word = 0;
7948
7949 status = em_read_ich8_data(hw, index, 1, &word);
7950 if (status == E1000_SUCCESS) {
7951 *data = (uint8_t)word;
7952 }
7953
7954 return status;
7955 }
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966 STATIC int32_t
7967 em_verify_write_ich8_byte(struct em_hw *hw, uint32_t index, uint8_t byte)
7968 {
7969 int32_t error = E1000_SUCCESS;
7970 int32_t program_retries = 0;
7971
7972 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
7973
7974 error = em_write_ich8_byte(hw, index, byte);
7975
7976 if (error != E1000_SUCCESS) {
7977 for (program_retries = 0; program_retries < 100; program_retries++) {
7978 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
7979 error = em_write_ich8_byte(hw, index, byte);
7980 usec_delay(100);
7981 if (error == E1000_SUCCESS)
7982 break;
7983 }
7984 }
7985
7986 if (program_retries == 100)
7987 error = E1000_ERR_EEPROM;
7988
7989 return error;
7990 }
7991
7992
7993
7994
7995
7996
7997
7998
7999 STATIC int32_t
8000 em_write_ich8_byte(struct em_hw *hw, uint32_t index, uint8_t data)
8001 {
8002 int32_t status = E1000_SUCCESS;
8003 uint16_t word = (uint16_t)data;
8004
8005 status = em_write_ich8_data(hw, index, 1, word);
8006
8007 return status;
8008 }
8009
8010
8011
8012
8013
8014
8015
8016
8017 STATIC int32_t
8018 em_read_ich8_word(struct em_hw *hw, uint32_t index, uint16_t *data)
8019 {
8020 int32_t status = E1000_SUCCESS;
8021 status = em_read_ich8_data(hw, index, 2, data);
8022 return status;
8023 }
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037 int32_t
8038 em_erase_ich8_4k_segment(struct em_hw *hw, uint32_t bank)
8039 {
8040 union ich8_hws_flash_status hsfsts;
8041 union ich8_hws_flash_ctrl hsflctl;
8042 uint32_t flash_linear_address;
8043 int32_t count = 0;
8044 int32_t error = E1000_ERR_EEPROM;
8045 int32_t iteration;
8046 int32_t sub_sector_size = 0;
8047 int32_t bank_size;
8048 int32_t j = 0;
8049 int32_t error_flag = 0;
8050
8051 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062 if (hsfsts.hsf_status.berasesz == 0x0) {
8063
8064 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8065 bank_size = ICH_FLASH_SECTOR_SIZE;
8066 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
8067 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8068 bank_size = ICH_FLASH_SEG_SIZE_4K;
8069 iteration = 1;
8070 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8071 bank_size = ICH_FLASH_SEG_SIZE_64K;
8072 iteration = 1;
8073 } else {
8074 return error;
8075 }
8076
8077 for (j = 0; j < iteration ; j++) {
8078 do {
8079 count++;
8080
8081 error = em_ich8_cycle_init(hw);
8082 if (error != E1000_SUCCESS) {
8083 error_flag = 1;
8084 break;
8085 }
8086
8087
8088
8089 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8090 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8091 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8092
8093
8094
8095
8096
8097 flash_linear_address = bank * bank_size + j * sub_sector_size;
8098 flash_linear_address += hw->flash_base_addr;
8099 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
8100
8101 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8102
8103 error = em_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
8104
8105
8106 if (error == E1000_SUCCESS) {
8107 break;
8108 } else {
8109 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8110 if (hsfsts.hsf_status.flcerr == 1) {
8111
8112 continue;
8113 } else if (hsfsts.hsf_status.flcdone == 0) {
8114 error_flag = 1;
8115 break;
8116 }
8117 }
8118 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8119 if (error_flag == 1)
8120 break;
8121 }
8122 if (error_flag != 1)
8123 error = E1000_SUCCESS;
8124 return error;
8125 }
8126
8127
8128 STATIC int32_t
8129 em_init_lcd_from_nvm_config_region(struct em_hw *hw,
8130 uint32_t cnf_base_addr, uint32_t cnf_size)
8131 {
8132 uint32_t ret_val = E1000_SUCCESS;
8133 uint16_t word_addr, reg_data, reg_addr;
8134 uint16_t i;
8135
8136
8137 word_addr = (uint16_t)(cnf_base_addr << 1);
8138
8139
8140 for (i = 0; i < cnf_size; i++) {
8141 ret_val = em_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
8142 if (ret_val)
8143 return ret_val;
8144
8145 ret_val = em_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
8146 if (ret_val)
8147 return ret_val;
8148
8149 ret_val = em_get_software_flag(hw);
8150 if (ret_val != E1000_SUCCESS)
8151 return ret_val;
8152
8153 ret_val = em_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8154
8155 em_release_software_flag(hw);
8156 }
8157
8158 return ret_val;
8159 }
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169 STATIC int32_t
8170 em_init_lcd_from_nvm(struct em_hw *hw)
8171 {
8172 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8173
8174 if (hw->phy_type != em_phy_igp_3)
8175 return E1000_SUCCESS;
8176
8177
8178 reg_data = E1000_READ_REG(hw, FEXTNVM);
8179 if (!(reg_data & FEXTNVM_SW_CONFIG))
8180 return E1000_SUCCESS;
8181
8182
8183 loop = 0;
8184 do {
8185 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8186 usec_delay(100);
8187 loop++;
8188 } while ((!reg_data) && (loop < 50));
8189
8190
8191 reg_data = E1000_READ_REG(hw, STATUS);
8192 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
8193 E1000_WRITE_REG(hw, STATUS, reg_data);
8194
8195
8196
8197 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
8198 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
8199 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
8200 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
8201 cnf_size >>= 16;
8202 if (cnf_size) {
8203 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
8204 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
8205
8206 cnf_base_addr >>= 16;
8207
8208
8209 ret_val = em_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
8210 cnf_size);
8211 if (ret_val)
8212 return ret_val;
8213 }
8214 }
8215
8216 return E1000_SUCCESS;
8217 }