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
41#include "e1000.h"
42
43
44
45union ich8_hws_flash_status {
46 struct ich8_hsfsts {
47 u16 flcdone:1;
48 u16 flcerr:1;
49 u16 dael:1;
50 u16 berasesz:2;
51 u16 flcinprog:1;
52 u16 reserved1:2;
53 u16 reserved2:6;
54 u16 fldesvalid:1;
55 u16 flockdn:1;
56 } hsf_status;
57 u16 regval;
58};
59
60
61
62union ich8_hws_flash_ctrl {
63 struct ich8_hsflctl {
64 u16 flcgo:1;
65 u16 flcycle:2;
66 u16 reserved:5;
67 u16 fldbcount:2;
68 u16 flockdn:6;
69 } hsf_ctrl;
70 u16 regval;
71};
72
73
74union ich8_hws_flash_regacc {
75 struct ich8_flracc {
76 u32 grra:8;
77 u32 grwa:8;
78 u32 gmrag:8;
79 u32 gmwag:8;
80 } hsf_flregacc;
81 u16 regval;
82};
83
84
85union ich8_flash_protected_range {
86 struct ich8_pr {
87 u32 base:13;
88 u32 reserved1:2;
89 u32 rpe:1;
90 u32 limit:13;
91 u32 reserved2:2;
92 u32 wpe:1;
93 } range;
94 u32 regval;
95};
96
97static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
98static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
99static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
100static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
101 u32 offset, u8 byte);
102static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
103 u8 *data);
104static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
105 u16 *data);
106static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
107 u8 size, u16 *data);
108static s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
109 u32 *data);
110static s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw,
111 u32 offset, u32 *data);
112static s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw,
113 u32 offset, u32 data);
114static s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
115 u32 offset, u32 dword);
116static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
117static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
118static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
119static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
120static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
121static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
122static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
123static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
124static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
125static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
126static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
127static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
128static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
129static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
130static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
131static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
132static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
133static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
134static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw);
135static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
136static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
137static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force);
138static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
139static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
140
141static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
142{
143 return readw(hw->flash_address + reg);
144}
145
146static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
147{
148 return readl(hw->flash_address + reg);
149}
150
151static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
152{
153 writew(val, hw->flash_address + reg);
154}
155
156static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
157{
158 writel(val, hw->flash_address + reg);
159}
160
161#define er16flash(reg) __er16flash(hw, (reg))
162#define er32flash(reg) __er32flash(hw, (reg))
163#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
164#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
165
166
167
168
169
170
171
172
173
174
175
176static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
177{
178 u16 phy_reg = 0;
179 u32 phy_id = 0;
180 s32 ret_val = 0;
181 u16 retry_count;
182 u32 mac_reg = 0;
183
184 for (retry_count = 0; retry_count < 2; retry_count++) {
185 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
186 if (ret_val || (phy_reg == 0xFFFF))
187 continue;
188 phy_id = (u32)(phy_reg << 16);
189
190 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
191 if (ret_val || (phy_reg == 0xFFFF)) {
192 phy_id = 0;
193 continue;
194 }
195 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
196 break;
197 }
198
199 if (hw->phy.id) {
200 if (hw->phy.id == phy_id)
201 goto out;
202 } else if (phy_id) {
203 hw->phy.id = phy_id;
204 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
205 goto out;
206 }
207
208
209
210
211 if (hw->mac.type < e1000_pch_lpt) {
212 hw->phy.ops.release(hw);
213 ret_val = e1000_set_mdio_slow_mode_hv(hw);
214 if (!ret_val)
215 ret_val = e1000e_get_phy_id(hw);
216 hw->phy.ops.acquire(hw);
217 }
218
219 if (ret_val)
220 return false;
221out:
222 if (hw->mac.type >= e1000_pch_lpt) {
223
224 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
225
226 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
227 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
228 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
229
230
231 mac_reg = er32(CTRL_EXT);
232 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
233 ew32(CTRL_EXT, mac_reg);
234 }
235 }
236
237 return true;
238}
239
240
241
242
243
244
245
246
247static void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
248{
249 u32 mac_reg;
250
251
252 mac_reg = er32(FEXTNVM3);
253 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
254 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
255 ew32(FEXTNVM3, mac_reg);
256
257
258 mac_reg = er32(CTRL);
259 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
260 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
261 ew32(CTRL, mac_reg);
262 e1e_flush();
263 usleep_range(10, 20);
264 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
265 ew32(CTRL, mac_reg);
266 e1e_flush();
267
268 if (hw->mac.type < e1000_pch_lpt) {
269 msleep(50);
270 } else {
271 u16 count = 20;
272
273 do {
274 usleep_range(5000, 10000);
275 } while (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LPCD) && count--);
276
277 msleep(30);
278 }
279}
280
281
282
283
284
285
286
287
288static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
289{
290 struct e1000_adapter *adapter = hw->adapter;
291 u32 mac_reg, fwsm = er32(FWSM);
292 s32 ret_val;
293
294
295
296
297 e1000_gate_hw_phy_config_ich8lan(hw, true);
298
299
300
301
302 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
303 e1000_disable_ulp_lpt_lp(hw, true);
304
305 ret_val = hw->phy.ops.acquire(hw);
306 if (ret_val) {
307 e_dbg("Failed to initialize PHY flow\n");
308 goto out;
309 }
310
311
312
313
314
315 switch (hw->mac.type) {
316 case e1000_pch_lpt:
317 case e1000_pch_spt:
318 case e1000_pch_cnp:
319 if (e1000_phy_is_accessible_pchlan(hw))
320 break;
321
322
323
324
325 mac_reg = er32(CTRL_EXT);
326 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
327 ew32(CTRL_EXT, mac_reg);
328
329
330
331
332
333 msleep(50);
334
335
336 case e1000_pch2lan:
337 if (e1000_phy_is_accessible_pchlan(hw))
338 break;
339
340
341 case e1000_pchlan:
342 if ((hw->mac.type == e1000_pchlan) &&
343 (fwsm & E1000_ICH_FWSM_FW_VALID))
344 break;
345
346 if (hw->phy.ops.check_reset_block(hw)) {
347 e_dbg("Required LANPHYPC toggle blocked by ME\n");
348 ret_val = -E1000_ERR_PHY;
349 break;
350 }
351
352
353 e1000_toggle_lanphypc_pch_lpt(hw);
354 if (hw->mac.type >= e1000_pch_lpt) {
355 if (e1000_phy_is_accessible_pchlan(hw))
356 break;
357
358
359
360
361 mac_reg = er32(CTRL_EXT);
362 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
363 ew32(CTRL_EXT, mac_reg);
364
365 if (e1000_phy_is_accessible_pchlan(hw))
366 break;
367
368 ret_val = -E1000_ERR_PHY;
369 }
370 break;
371 default:
372 break;
373 }
374
375 hw->phy.ops.release(hw);
376 if (!ret_val) {
377
378
379 if (hw->phy.ops.check_reset_block(hw)) {
380 e_err("Reset blocked by ME\n");
381 goto out;
382 }
383
384
385
386
387
388
389 ret_val = e1000e_phy_hw_reset_generic(hw);
390 if (ret_val)
391 goto out;
392
393
394
395
396
397
398
399 ret_val = hw->phy.ops.check_reset_block(hw);
400 if (ret_val)
401 e_err("ME blocked access to PHY after reset\n");
402 }
403
404out:
405
406 if ((hw->mac.type == e1000_pch2lan) &&
407 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
408 usleep_range(10000, 20000);
409 e1000_gate_hw_phy_config_ich8lan(hw, false);
410 }
411
412 return ret_val;
413}
414
415
416
417
418
419
420
421static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
422{
423 struct e1000_phy_info *phy = &hw->phy;
424 s32 ret_val;
425
426 phy->addr = 1;
427 phy->reset_delay_us = 100;
428
429 phy->ops.set_page = e1000_set_page_igp;
430 phy->ops.read_reg = e1000_read_phy_reg_hv;
431 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
432 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
433 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
434 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
435 phy->ops.write_reg = e1000_write_phy_reg_hv;
436 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
437 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
438 phy->ops.power_up = e1000_power_up_phy_copper;
439 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
440 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
441
442 phy->id = e1000_phy_unknown;
443
444 ret_val = e1000_init_phy_workarounds_pchlan(hw);
445 if (ret_val)
446 return ret_val;
447
448 if (phy->id == e1000_phy_unknown)
449 switch (hw->mac.type) {
450 default:
451 ret_val = e1000e_get_phy_id(hw);
452 if (ret_val)
453 return ret_val;
454 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
455 break;
456
457 case e1000_pch2lan:
458 case e1000_pch_lpt:
459 case e1000_pch_spt:
460 case e1000_pch_cnp:
461
462
463
464 ret_val = e1000_set_mdio_slow_mode_hv(hw);
465 if (ret_val)
466 return ret_val;
467 ret_val = e1000e_get_phy_id(hw);
468 if (ret_val)
469 return ret_val;
470 break;
471 }
472 phy->type = e1000e_get_phy_type_from_id(phy->id);
473
474 switch (phy->type) {
475 case e1000_phy_82577:
476 case e1000_phy_82579:
477 case e1000_phy_i217:
478 phy->ops.check_polarity = e1000_check_polarity_82577;
479 phy->ops.force_speed_duplex =
480 e1000_phy_force_speed_duplex_82577;
481 phy->ops.get_cable_length = e1000_get_cable_length_82577;
482 phy->ops.get_info = e1000_get_phy_info_82577;
483 phy->ops.commit = e1000e_phy_sw_reset;
484 break;
485 case e1000_phy_82578:
486 phy->ops.check_polarity = e1000_check_polarity_m88;
487 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
488 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
489 phy->ops.get_info = e1000e_get_phy_info_m88;
490 break;
491 default:
492 ret_val = -E1000_ERR_PHY;
493 break;
494 }
495
496 return ret_val;
497}
498
499
500
501
502
503
504
505static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
506{
507 struct e1000_phy_info *phy = &hw->phy;
508 s32 ret_val;
509 u16 i = 0;
510
511 phy->addr = 1;
512 phy->reset_delay_us = 100;
513
514 phy->ops.power_up = e1000_power_up_phy_copper;
515 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
516
517
518
519
520 ret_val = e1000e_determine_phy_address(hw);
521 if (ret_val) {
522 phy->ops.write_reg = e1000e_write_phy_reg_bm;
523 phy->ops.read_reg = e1000e_read_phy_reg_bm;
524 ret_val = e1000e_determine_phy_address(hw);
525 if (ret_val) {
526 e_dbg("Cannot determine PHY addr. Erroring out\n");
527 return ret_val;
528 }
529 }
530
531 phy->id = 0;
532 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
533 (i++ < 100)) {
534 usleep_range(1000, 2000);
535 ret_val = e1000e_get_phy_id(hw);
536 if (ret_val)
537 return ret_val;
538 }
539
540
541 switch (phy->id) {
542 case IGP03E1000_E_PHY_ID:
543 phy->type = e1000_phy_igp_3;
544 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
545 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
546 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
547 phy->ops.get_info = e1000e_get_phy_info_igp;
548 phy->ops.check_polarity = e1000_check_polarity_igp;
549 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
550 break;
551 case IFE_E_PHY_ID:
552 case IFE_PLUS_E_PHY_ID:
553 case IFE_C_E_PHY_ID:
554 phy->type = e1000_phy_ife;
555 phy->autoneg_mask = E1000_ALL_NOT_GIG;
556 phy->ops.get_info = e1000_get_phy_info_ife;
557 phy->ops.check_polarity = e1000_check_polarity_ife;
558 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
559 break;
560 case BME1000_E_PHY_ID:
561 phy->type = e1000_phy_bm;
562 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
563 phy->ops.read_reg = e1000e_read_phy_reg_bm;
564 phy->ops.write_reg = e1000e_write_phy_reg_bm;
565 phy->ops.commit = e1000e_phy_sw_reset;
566 phy->ops.get_info = e1000e_get_phy_info_m88;
567 phy->ops.check_polarity = e1000_check_polarity_m88;
568 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
569 break;
570 default:
571 return -E1000_ERR_PHY;
572 }
573
574 return 0;
575}
576
577
578
579
580
581
582
583
584static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
585{
586 struct e1000_nvm_info *nvm = &hw->nvm;
587 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
588 u32 gfpreg, sector_base_addr, sector_end_addr;
589 u16 i;
590 u32 nvm_size;
591
592 nvm->type = e1000_nvm_flash_sw;
593
594 if (hw->mac.type >= e1000_pch_spt) {
595
596
597
598
599
600
601 nvm->flash_base_addr = 0;
602 nvm_size = (((er32(STRAP) >> 1) & 0x1F) + 1)
603 * NVM_SIZE_MULTIPLIER;
604 nvm->flash_bank_size = nvm_size / 2;
605
606 nvm->flash_bank_size /= sizeof(u16);
607
608 hw->flash_address = hw->hw_addr + E1000_FLASH_BASE_ADDR;
609 } else {
610
611 if (!hw->flash_address) {
612 e_dbg("ERROR: Flash registers not mapped\n");
613 return -E1000_ERR_CONFIG;
614 }
615
616 gfpreg = er32flash(ICH_FLASH_GFPREG);
617
618
619
620
621
622 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
623 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
624
625
626 nvm->flash_base_addr = sector_base_addr
627 << FLASH_SECTOR_ADDR_SHIFT;
628
629
630
631
632 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
633 << FLASH_SECTOR_ADDR_SHIFT);
634 nvm->flash_bank_size /= 2;
635
636 nvm->flash_bank_size /= sizeof(u16);
637 }
638
639 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
640
641
642 for (i = 0; i < nvm->word_size; i++) {
643 dev_spec->shadow_ram[i].modified = false;
644 dev_spec->shadow_ram[i].value = 0xFFFF;
645 }
646
647 return 0;
648}
649
650
651
652
653
654
655
656
657static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
658{
659 struct e1000_mac_info *mac = &hw->mac;
660
661
662 hw->phy.media_type = e1000_media_type_copper;
663
664
665 mac->mta_reg_count = 32;
666
667 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
668 if (mac->type == e1000_ich8lan)
669 mac->rar_entry_count--;
670
671 mac->has_fwsm = true;
672
673 mac->arc_subsystem_valid = false;
674
675 mac->adaptive_ifs = true;
676
677
678 switch (mac->type) {
679 case e1000_ich8lan:
680 case e1000_ich9lan:
681 case e1000_ich10lan:
682
683 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
684
685 mac->ops.id_led_init = e1000e_id_led_init_generic;
686
687 mac->ops.blink_led = e1000e_blink_led_generic;
688
689 mac->ops.setup_led = e1000e_setup_led_generic;
690
691 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
692
693 mac->ops.led_on = e1000_led_on_ich8lan;
694 mac->ops.led_off = e1000_led_off_ich8lan;
695 break;
696 case e1000_pch2lan:
697 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
698 mac->ops.rar_set = e1000_rar_set_pch2lan;
699
700 case e1000_pch_lpt:
701 case e1000_pch_spt:
702 case e1000_pch_cnp:
703 case e1000_pchlan:
704
705 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
706
707 mac->ops.id_led_init = e1000_id_led_init_pchlan;
708
709 mac->ops.setup_led = e1000_setup_led_pchlan;
710
711 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
712
713 mac->ops.led_on = e1000_led_on_pchlan;
714 mac->ops.led_off = e1000_led_off_pchlan;
715 break;
716 default:
717 break;
718 }
719
720 if (mac->type >= e1000_pch_lpt) {
721 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
722 mac->ops.rar_set = e1000_rar_set_pch_lpt;
723 mac->ops.setup_physical_interface =
724 e1000_setup_copper_link_pch_lpt;
725 mac->ops.rar_get_count = e1000_rar_get_count_pch_lpt;
726 }
727
728
729 if (mac->type == e1000_ich8lan)
730 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
731
732 return 0;
733}
734
735
736
737
738
739
740
741
742
743
744static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
745 u16 *data, bool read)
746{
747 s32 ret_val;
748
749 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
750 if (ret_val)
751 return ret_val;
752
753 if (read)
754 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
755 else
756 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
757
758 return ret_val;
759}
760
761
762
763
764
765
766
767
768
769s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
770{
771 return __e1000_access_emi_reg_locked(hw, addr, data, true);
772}
773
774
775
776
777
778
779
780
781
782s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
783{
784 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
785}
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
802{
803 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
804 s32 ret_val;
805 u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
806
807 switch (hw->phy.type) {
808 case e1000_phy_82579:
809 lpa = I82579_EEE_LP_ABILITY;
810 pcs_status = I82579_EEE_PCS_STATUS;
811 adv_addr = I82579_EEE_ADVERTISEMENT;
812 break;
813 case e1000_phy_i217:
814 lpa = I217_EEE_LP_ABILITY;
815 pcs_status = I217_EEE_PCS_STATUS;
816 adv_addr = I217_EEE_ADVERTISEMENT;
817 break;
818 default:
819 return 0;
820 }
821
822 ret_val = hw->phy.ops.acquire(hw);
823 if (ret_val)
824 return ret_val;
825
826 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
827 if (ret_val)
828 goto release;
829
830
831 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
832
833
834 if (!dev_spec->eee_disable) {
835
836 ret_val = e1000_read_emi_reg_locked(hw, lpa,
837 &dev_spec->eee_lp_ability);
838 if (ret_val)
839 goto release;
840
841
842 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
843 if (ret_val)
844 goto release;
845
846
847
848
849 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
850 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
851
852 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
853 e1e_rphy_locked(hw, MII_LPA, &data);
854 if (data & LPA_100FULL)
855 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
856 else
857
858
859
860
861 dev_spec->eee_lp_ability &=
862 ~I82579_EEE_100_SUPPORTED;
863 }
864 }
865
866 if (hw->phy.type == e1000_phy_82579) {
867 ret_val = e1000_read_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
868 &data);
869 if (ret_val)
870 goto release;
871
872 data &= ~I82579_LPI_100_PLL_SHUT;
873 ret_val = e1000_write_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
874 data);
875 }
876
877
878 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
879 if (ret_val)
880 goto release;
881
882 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
883release:
884 hw->phy.ops.release(hw);
885
886 return ret_val;
887}
888
889
890
891
892
893
894
895
896
897
898
899
900static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
901{
902 u32 fextnvm6 = er32(FEXTNVM6);
903 u32 status = er32(STATUS);
904 s32 ret_val = 0;
905 u16 reg;
906
907 if (link && (status & E1000_STATUS_SPEED_1000)) {
908 ret_val = hw->phy.ops.acquire(hw);
909 if (ret_val)
910 return ret_val;
911
912 ret_val =
913 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
914 ®);
915 if (ret_val)
916 goto release;
917
918 ret_val =
919 e1000e_write_kmrn_reg_locked(hw,
920 E1000_KMRNCTRLSTA_K1_CONFIG,
921 reg &
922 ~E1000_KMRNCTRLSTA_K1_ENABLE);
923 if (ret_val)
924 goto release;
925
926 usleep_range(10, 20);
927
928 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
929
930 ret_val =
931 e1000e_write_kmrn_reg_locked(hw,
932 E1000_KMRNCTRLSTA_K1_CONFIG,
933 reg);
934release:
935 hw->phy.ops.release(hw);
936 } else {
937
938 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
939
940 if ((hw->phy.revision > 5) || !link ||
941 ((status & E1000_STATUS_SPEED_100) &&
942 (status & E1000_STATUS_FD)))
943 goto update_fextnvm6;
944
945 ret_val = e1e_rphy(hw, I217_INBAND_CTRL, ®);
946 if (ret_val)
947 return ret_val;
948
949
950 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
951
952 if (status & E1000_STATUS_SPEED_100) {
953
954 reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
955
956
957 fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
958 } else {
959
960 reg |= 50 <<
961 I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
962
963
964 fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
965 }
966
967 ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
968 if (ret_val)
969 return ret_val;
970
971update_fextnvm6:
972 ew32(FEXTNVM6, fextnvm6);
973 }
974
975 return ret_val;
976}
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
995{
996 u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
997 link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
998 u16 lat_enc = 0;
999
1000 if (link) {
1001 u16 speed, duplex, scale = 0;
1002 u16 max_snoop, max_nosnoop;
1003 u16 max_ltr_enc;
1004 u64 value;
1005 u32 rxa;
1006
1007 if (!hw->adapter->max_frame_size) {
1008 e_dbg("max_frame_size not set.\n");
1009 return -E1000_ERR_CONFIG;
1010 }
1011
1012 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
1013 if (!speed) {
1014 e_dbg("Speed not set.\n");
1015 return -E1000_ERR_CONFIG;
1016 }
1017
1018
1019 rxa = er32(PBA) & E1000_PBA_RXA_MASK;
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029 rxa *= 512;
1030 value = (rxa > hw->adapter->max_frame_size) ?
1031 (rxa - hw->adapter->max_frame_size) * (16000 / speed) :
1032 0;
1033
1034 while (value > PCI_LTR_VALUE_MASK) {
1035 scale++;
1036 value = DIV_ROUND_UP(value, BIT(5));
1037 }
1038 if (scale > E1000_LTRV_SCALE_MAX) {
1039 e_dbg("Invalid LTR latency scale %d\n", scale);
1040 return -E1000_ERR_CONFIG;
1041 }
1042 lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
1043
1044
1045 pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
1046 &max_snoop);
1047 pci_read_config_word(hw->adapter->pdev,
1048 E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
1049 max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
1050
1051 if (lat_enc > max_ltr_enc)
1052 lat_enc = max_ltr_enc;
1053 }
1054
1055
1056 reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
1057 ew32(LTRV, reg);
1058
1059 return 0;
1060}
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
1073{
1074 u32 mac_reg;
1075 s32 ret_val = 0;
1076 u16 phy_reg;
1077 u16 oem_reg = 0;
1078
1079 if ((hw->mac.type < e1000_pch_lpt) ||
1080 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
1081 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
1082 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
1083 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
1084 (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
1085 return 0;
1086
1087 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
1088
1089 mac_reg = er32(H2ME);
1090 mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
1091 ew32(H2ME, mac_reg);
1092
1093 goto out;
1094 }
1095
1096 if (!to_sx) {
1097 int i = 0;
1098
1099
1100 while (!(er32(FEXT) & E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
1101
1102 if (er32(STATUS) & E1000_STATUS_LU)
1103 return -E1000_ERR_PHY;
1104
1105 if (i++ == 100)
1106 break;
1107
1108 msleep(50);
1109 }
1110 e_dbg("CABLE_DISCONNECTED %s set after %dmsec\n",
1111 (er32(FEXT) &
1112 E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not", i * 50);
1113 }
1114
1115 ret_val = hw->phy.ops.acquire(hw);
1116 if (ret_val)
1117 goto out;
1118
1119
1120 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
1121 if (ret_val)
1122 goto release;
1123 phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
1124 e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
1125
1126
1127 mac_reg = er32(CTRL_EXT);
1128 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
1129 ew32(CTRL_EXT, mac_reg);
1130
1131
1132
1133
1134 if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6)) {
1135 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_OEM_BITS,
1136 &oem_reg);
1137 if (ret_val)
1138 goto release;
1139
1140 phy_reg = oem_reg;
1141 phy_reg |= HV_OEM_BITS_LPLU | HV_OEM_BITS_GBE_DIS;
1142
1143 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
1144 phy_reg);
1145
1146 if (ret_val)
1147 goto release;
1148 }
1149
1150
1151
1152
1153 ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
1154 if (ret_val)
1155 goto release;
1156 phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
1157 I218_ULP_CONFIG1_DISABLE_SMB_PERST);
1158 if (to_sx) {
1159 if (er32(WUFC) & E1000_WUFC_LNKC)
1160 phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
1161 else
1162 phy_reg &= ~I218_ULP_CONFIG1_WOL_HOST;
1163
1164 phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
1165 phy_reg &= ~I218_ULP_CONFIG1_INBAND_EXIT;
1166 } else {
1167 phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
1168 phy_reg &= ~I218_ULP_CONFIG1_STICKY_ULP;
1169 phy_reg &= ~I218_ULP_CONFIG1_WOL_HOST;
1170 }
1171 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1172
1173
1174 mac_reg = er32(FEXTNVM7);
1175 mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
1176 ew32(FEXTNVM7, mac_reg);
1177
1178
1179 phy_reg |= I218_ULP_CONFIG1_START;
1180 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1181
1182 if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6) &&
1183 to_sx && (er32(STATUS) & E1000_STATUS_LU)) {
1184 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
1185 oem_reg);
1186 if (ret_val)
1187 goto release;
1188 }
1189
1190release:
1191 hw->phy.ops.release(hw);
1192out:
1193 if (ret_val)
1194 e_dbg("Error in ULP enable flow: %d\n", ret_val);
1195 else
1196 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
1197
1198 return ret_val;
1199}
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
1217{
1218 s32 ret_val = 0;
1219 u32 mac_reg;
1220 u16 phy_reg;
1221 int i = 0;
1222
1223 if ((hw->mac.type < e1000_pch_lpt) ||
1224 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
1225 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
1226 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
1227 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
1228 (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
1229 return 0;
1230
1231 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
1232 if (force) {
1233
1234 mac_reg = er32(H2ME);
1235 mac_reg &= ~E1000_H2ME_ULP;
1236 mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
1237 ew32(H2ME, mac_reg);
1238 }
1239
1240
1241 while (er32(FWSM) & E1000_FWSM_ULP_CFG_DONE) {
1242 if (i++ == 30) {
1243 ret_val = -E1000_ERR_PHY;
1244 goto out;
1245 }
1246
1247 usleep_range(10000, 20000);
1248 }
1249 e_dbg("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
1250
1251 if (force) {
1252 mac_reg = er32(H2ME);
1253 mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
1254 ew32(H2ME, mac_reg);
1255 } else {
1256
1257 mac_reg = er32(H2ME);
1258 mac_reg &= ~E1000_H2ME_ULP;
1259 ew32(H2ME, mac_reg);
1260 }
1261
1262 goto out;
1263 }
1264
1265 ret_val = hw->phy.ops.acquire(hw);
1266 if (ret_val)
1267 goto out;
1268
1269 if (force)
1270
1271 e1000_toggle_lanphypc_pch_lpt(hw);
1272
1273
1274 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
1275 if (ret_val) {
1276
1277
1278
1279 mac_reg = er32(CTRL_EXT);
1280 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
1281 ew32(CTRL_EXT, mac_reg);
1282
1283 msleep(50);
1284
1285 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
1286 &phy_reg);
1287 if (ret_val)
1288 goto release;
1289 }
1290 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
1291 e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
1292
1293
1294 mac_reg = er32(CTRL_EXT);
1295 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
1296 ew32(CTRL_EXT, mac_reg);
1297
1298
1299
1300
1301 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
1302 if (ret_val)
1303 goto release;
1304 phy_reg |= HV_PM_CTRL_K1_ENABLE;
1305 e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
1306
1307
1308 ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
1309 if (ret_val)
1310 goto release;
1311 phy_reg &= ~(I218_ULP_CONFIG1_IND |
1312 I218_ULP_CONFIG1_STICKY_ULP |
1313 I218_ULP_CONFIG1_RESET_TO_SMBUS |
1314 I218_ULP_CONFIG1_WOL_HOST |
1315 I218_ULP_CONFIG1_INBAND_EXIT |
1316 I218_ULP_CONFIG1_EN_ULP_LANPHYPC |
1317 I218_ULP_CONFIG1_DIS_CLR_STICKY_ON_PERST |
1318 I218_ULP_CONFIG1_DISABLE_SMB_PERST);
1319 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1320
1321
1322 phy_reg |= I218_ULP_CONFIG1_START;
1323 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1324
1325
1326 mac_reg = er32(FEXTNVM7);
1327 mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
1328 ew32(FEXTNVM7, mac_reg);
1329
1330release:
1331 hw->phy.ops.release(hw);
1332 if (force) {
1333 e1000_phy_hw_reset(hw);
1334 msleep(50);
1335 }
1336out:
1337 if (ret_val)
1338 e_dbg("Error in ULP disable flow: %d\n", ret_val);
1339 else
1340 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
1341
1342 return ret_val;
1343}
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1354{
1355 struct e1000_mac_info *mac = &hw->mac;
1356 s32 ret_val, tipg_reg = 0;
1357 u16 emi_addr, emi_val = 0;
1358 bool link;
1359 u16 phy_reg;
1360
1361
1362
1363
1364
1365
1366 if (!mac->get_link_status)
1367 return 0;
1368 mac->get_link_status = false;
1369
1370
1371
1372
1373
1374 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1375 if (ret_val)
1376 goto out;
1377
1378 if (hw->mac.type == e1000_pchlan) {
1379 ret_val = e1000_k1_gig_workaround_hv(hw, link);
1380 if (ret_val)
1381 goto out;
1382 }
1383
1384
1385
1386
1387
1388 if ((hw->mac.type >= e1000_pch2lan) && link) {
1389 u16 speed, duplex;
1390
1391 e1000e_get_speed_and_duplex_copper(hw, &speed, &duplex);
1392 tipg_reg = er32(TIPG);
1393 tipg_reg &= ~E1000_TIPG_IPGT_MASK;
1394
1395 if (duplex == HALF_DUPLEX && speed == SPEED_10) {
1396 tipg_reg |= 0xFF;
1397
1398 emi_val = 0;
1399 } else if (hw->mac.type >= e1000_pch_spt &&
1400 duplex == FULL_DUPLEX && speed != SPEED_1000) {
1401 tipg_reg |= 0xC;
1402 emi_val = 1;
1403 } else {
1404
1405
1406 tipg_reg |= 0x08;
1407 emi_val = 1;
1408 }
1409
1410 ew32(TIPG, tipg_reg);
1411
1412 ret_val = hw->phy.ops.acquire(hw);
1413 if (ret_val)
1414 goto out;
1415
1416 if (hw->mac.type == e1000_pch2lan)
1417 emi_addr = I82579_RX_CONFIG;
1418 else
1419 emi_addr = I217_RX_CONFIG;
1420 ret_val = e1000_write_emi_reg_locked(hw, emi_addr, emi_val);
1421
1422 if (hw->mac.type >= e1000_pch_lpt) {
1423 u16 phy_reg;
1424
1425 e1e_rphy_locked(hw, I217_PLL_CLOCK_GATE_REG, &phy_reg);
1426 phy_reg &= ~I217_PLL_CLOCK_GATE_MASK;
1427 if (speed == SPEED_100 || speed == SPEED_10)
1428 phy_reg |= 0x3E8;
1429 else
1430 phy_reg |= 0xFA;
1431 e1e_wphy_locked(hw, I217_PLL_CLOCK_GATE_REG, phy_reg);
1432 }
1433 hw->phy.ops.release(hw);
1434
1435 if (ret_val)
1436 goto out;
1437
1438 if (hw->mac.type >= e1000_pch_spt) {
1439 u16 data;
1440 u16 ptr_gap;
1441
1442 if (speed == SPEED_1000) {
1443 ret_val = hw->phy.ops.acquire(hw);
1444 if (ret_val)
1445 goto out;
1446
1447 ret_val = e1e_rphy_locked(hw,
1448 PHY_REG(776, 20),
1449 &data);
1450 if (ret_val) {
1451 hw->phy.ops.release(hw);
1452 goto out;
1453 }
1454
1455 ptr_gap = (data & (0x3FF << 2)) >> 2;
1456 if (ptr_gap < 0x18) {
1457 data &= ~(0x3FF << 2);
1458 data |= (0x18 << 2);
1459 ret_val =
1460 e1e_wphy_locked(hw,
1461 PHY_REG(776, 20),
1462 data);
1463 }
1464 hw->phy.ops.release(hw);
1465 if (ret_val)
1466 goto out;
1467 } else {
1468 ret_val = hw->phy.ops.acquire(hw);
1469 if (ret_val)
1470 goto out;
1471
1472 ret_val = e1e_wphy_locked(hw,
1473 PHY_REG(776, 20),
1474 0xC023);
1475 hw->phy.ops.release(hw);
1476 if (ret_val)
1477 goto out;
1478
1479 }
1480 }
1481 }
1482
1483
1484
1485
1486
1487
1488 if (hw->mac.type >= e1000_pch_lpt) {
1489 u32 mac_reg;
1490
1491 mac_reg = er32(FEXTNVM4);
1492 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
1493 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
1494 ew32(FEXTNVM4, mac_reg);
1495 }
1496
1497
1498 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
1499 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
1500 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
1501 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
1502 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1503 if (ret_val)
1504 goto out;
1505 }
1506 if (hw->mac.type >= e1000_pch_lpt) {
1507
1508
1509
1510 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1511 if (ret_val)
1512 goto out;
1513 }
1514
1515
1516 hw->dev_spec.ich8lan.eee_lp_ability = 0;
1517
1518 if (hw->mac.type >= e1000_pch_lpt) {
1519 u32 fextnvm6 = er32(FEXTNVM6);
1520
1521 if (hw->mac.type == e1000_pch_spt) {
1522
1523 u32 pcieanacfg = er32(PCIEANACFG);
1524
1525 if (pcieanacfg & E1000_FEXTNVM6_K1_OFF_ENABLE)
1526 fextnvm6 |= E1000_FEXTNVM6_K1_OFF_ENABLE;
1527 else
1528 fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
1529 }
1530
1531 ew32(FEXTNVM6, fextnvm6);
1532 }
1533
1534 if (!link)
1535 goto out;
1536
1537 switch (hw->mac.type) {
1538 case e1000_pch2lan:
1539 ret_val = e1000_k1_workaround_lv(hw);
1540 if (ret_val)
1541 return ret_val;
1542
1543 case e1000_pchlan:
1544 if (hw->phy.type == e1000_phy_82578) {
1545 ret_val = e1000_link_stall_workaround_hv(hw);
1546 if (ret_val)
1547 return ret_val;
1548 }
1549
1550
1551
1552
1553
1554
1555 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
1556 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
1557
1558 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1559 phy_reg |= BIT(HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1560
1561 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1562 break;
1563 default:
1564 break;
1565 }
1566
1567
1568
1569
1570 e1000e_check_downshift(hw);
1571
1572
1573 if (hw->phy.type > e1000_phy_82579) {
1574 ret_val = e1000_set_eee_pchlan(hw);
1575 if (ret_val)
1576 return ret_val;
1577 }
1578
1579
1580
1581
1582 if (!mac->autoneg)
1583 return -E1000_ERR_CONFIG;
1584
1585
1586
1587
1588
1589 mac->ops.config_collision_dist(hw);
1590
1591
1592
1593
1594
1595
1596 ret_val = e1000e_config_fc_after_link_up(hw);
1597 if (ret_val)
1598 e_dbg("Error configuring flow control\n");
1599
1600 return ret_val;
1601
1602out:
1603 mac->get_link_status = true;
1604 return ret_val;
1605}
1606
1607static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
1608{
1609 struct e1000_hw *hw = &adapter->hw;
1610 s32 rc;
1611
1612 rc = e1000_init_mac_params_ich8lan(hw);
1613 if (rc)
1614 return rc;
1615
1616 rc = e1000_init_nvm_params_ich8lan(hw);
1617 if (rc)
1618 return rc;
1619
1620 switch (hw->mac.type) {
1621 case e1000_ich8lan:
1622 case e1000_ich9lan:
1623 case e1000_ich10lan:
1624 rc = e1000_init_phy_params_ich8lan(hw);
1625 break;
1626 case e1000_pchlan:
1627 case e1000_pch2lan:
1628 case e1000_pch_lpt:
1629 case e1000_pch_spt:
1630 case e1000_pch_cnp:
1631 rc = e1000_init_phy_params_pchlan(hw);
1632 break;
1633 default:
1634 break;
1635 }
1636 if (rc)
1637 return rc;
1638
1639
1640
1641
1642 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1643 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1644 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
1645 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1646 adapter->max_hw_frame_size = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
1647
1648 hw->mac.ops.blink_led = NULL;
1649 }
1650
1651 if ((adapter->hw.mac.type == e1000_ich8lan) &&
1652 (adapter->hw.phy.type != e1000_phy_ife))
1653 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1654
1655
1656 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1657 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1658 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1659
1660 return 0;
1661}
1662
1663static DEFINE_MUTEX(nvm_mutex);
1664
1665
1666
1667
1668
1669
1670
1671static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
1672{
1673 mutex_lock(&nvm_mutex);
1674
1675 return 0;
1676}
1677
1678
1679
1680
1681
1682
1683
1684static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
1685{
1686 mutex_unlock(&nvm_mutex);
1687}
1688
1689
1690
1691
1692
1693
1694
1695
1696static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1697{
1698 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1699 s32 ret_val = 0;
1700
1701 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1702 &hw->adapter->state)) {
1703 e_dbg("contention for Phy access\n");
1704 return -E1000_ERR_PHY;
1705 }
1706
1707 while (timeout) {
1708 extcnf_ctrl = er32(EXTCNF_CTRL);
1709 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1710 break;
1711
1712 mdelay(1);
1713 timeout--;
1714 }
1715
1716 if (!timeout) {
1717 e_dbg("SW has already locked the resource.\n");
1718 ret_val = -E1000_ERR_CONFIG;
1719 goto out;
1720 }
1721
1722 timeout = SW_FLAG_TIMEOUT;
1723
1724 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1725 ew32(EXTCNF_CTRL, extcnf_ctrl);
1726
1727 while (timeout) {
1728 extcnf_ctrl = er32(EXTCNF_CTRL);
1729 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1730 break;
1731
1732 mdelay(1);
1733 timeout--;
1734 }
1735
1736 if (!timeout) {
1737 e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
1738 er32(FWSM), extcnf_ctrl);
1739 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1740 ew32(EXTCNF_CTRL, extcnf_ctrl);
1741 ret_val = -E1000_ERR_CONFIG;
1742 goto out;
1743 }
1744
1745out:
1746 if (ret_val)
1747 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
1748
1749 return ret_val;
1750}
1751
1752
1753
1754
1755
1756
1757
1758
1759static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1760{
1761 u32 extcnf_ctrl;
1762
1763 extcnf_ctrl = er32(EXTCNF_CTRL);
1764
1765 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1766 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1767 ew32(EXTCNF_CTRL, extcnf_ctrl);
1768 } else {
1769 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1770 }
1771
1772 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
1773}
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1784{
1785 u32 fwsm;
1786
1787 fwsm = er32(FWSM);
1788 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1789 ((fwsm & E1000_FWSM_MODE_MASK) ==
1790 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1791}
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1802{
1803 u32 fwsm;
1804
1805 fwsm = er32(FWSM);
1806 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1807 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1808}
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1822{
1823 u32 rar_low, rar_high;
1824
1825
1826
1827
1828 rar_low = ((u32)addr[0] |
1829 ((u32)addr[1] << 8) |
1830 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1831
1832 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1833
1834
1835 if (rar_low || rar_high)
1836 rar_high |= E1000_RAH_AV;
1837
1838 if (index == 0) {
1839 ew32(RAL(index), rar_low);
1840 e1e_flush();
1841 ew32(RAH(index), rar_high);
1842 e1e_flush();
1843 return 0;
1844 }
1845
1846
1847
1848
1849 if (index < (u32)(hw->mac.rar_entry_count)) {
1850 s32 ret_val;
1851
1852 ret_val = e1000_acquire_swflag_ich8lan(hw);
1853 if (ret_val)
1854 goto out;
1855
1856 ew32(SHRAL(index - 1), rar_low);
1857 e1e_flush();
1858 ew32(SHRAH(index - 1), rar_high);
1859 e1e_flush();
1860
1861 e1000_release_swflag_ich8lan(hw);
1862
1863
1864 if ((er32(SHRAL(index - 1)) == rar_low) &&
1865 (er32(SHRAH(index - 1)) == rar_high))
1866 return 0;
1867
1868 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1869 (index - 1), er32(FWSM));
1870 }
1871
1872out:
1873 e_dbg("Failed to write receive address at index %d\n", index);
1874 return -E1000_ERR_CONFIG;
1875}
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw)
1888{
1889 u32 wlock_mac;
1890 u32 num_entries;
1891
1892 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1893 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1894
1895 switch (wlock_mac) {
1896 case 0:
1897
1898 num_entries = hw->mac.rar_entry_count;
1899 break;
1900 case 1:
1901
1902 num_entries = 1;
1903 break;
1904 default:
1905
1906 num_entries = wlock_mac + 1;
1907 break;
1908 }
1909
1910 return num_entries;
1911}
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1925{
1926 u32 rar_low, rar_high;
1927 u32 wlock_mac;
1928
1929
1930
1931
1932 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1933 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1934
1935 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1936
1937
1938 if (rar_low || rar_high)
1939 rar_high |= E1000_RAH_AV;
1940
1941 if (index == 0) {
1942 ew32(RAL(index), rar_low);
1943 e1e_flush();
1944 ew32(RAH(index), rar_high);
1945 e1e_flush();
1946 return 0;
1947 }
1948
1949
1950
1951
1952 if (index < hw->mac.rar_entry_count) {
1953 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1954 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1955
1956
1957 if (wlock_mac == 1)
1958 goto out;
1959
1960 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1961 s32 ret_val;
1962
1963 ret_val = e1000_acquire_swflag_ich8lan(hw);
1964
1965 if (ret_val)
1966 goto out;
1967
1968 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1969 e1e_flush();
1970 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1971 e1e_flush();
1972
1973 e1000_release_swflag_ich8lan(hw);
1974
1975
1976 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1977 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1978 return 0;
1979 }
1980 }
1981
1982out:
1983 e_dbg("Failed to write receive address at index %d\n", index);
1984 return -E1000_ERR_CONFIG;
1985}
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1996{
1997 bool blocked = false;
1998 int i = 0;
1999
2000 while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
2001 (i++ < 30))
2002 usleep_range(10000, 20000);
2003 return blocked ? E1000_BLK_PHY_RESET : 0;
2004}
2005
2006
2007
2008
2009
2010
2011
2012
2013static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
2014{
2015 u16 phy_data;
2016 u32 strap = er32(STRAP);
2017 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
2018 E1000_STRAP_SMT_FREQ_SHIFT;
2019 s32 ret_val;
2020
2021 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
2022
2023 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
2024 if (ret_val)
2025 return ret_val;
2026
2027 phy_data &= ~HV_SMB_ADDR_MASK;
2028 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
2029 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
2030
2031 if (hw->phy.type == e1000_phy_i217) {
2032
2033 if (freq--) {
2034 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
2035 phy_data |= (freq & BIT(0)) <<
2036 HV_SMB_ADDR_FREQ_LOW_SHIFT;
2037 phy_data |= (freq & BIT(1)) <<
2038 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
2039 } else {
2040 e_dbg("Unsupported SMB frequency in PHY\n");
2041 }
2042 }
2043
2044 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
2045}
2046
2047
2048
2049
2050
2051
2052
2053
2054static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
2055{
2056 struct e1000_phy_info *phy = &hw->phy;
2057 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
2058 s32 ret_val = 0;
2059 u16 word_addr, reg_data, reg_addr, phy_page = 0;
2060
2061
2062
2063
2064
2065
2066
2067 switch (hw->mac.type) {
2068 case e1000_ich8lan:
2069 if (phy->type != e1000_phy_igp_3)
2070 return ret_val;
2071
2072 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
2073 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
2074 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
2075 break;
2076 }
2077
2078 case e1000_pchlan:
2079 case e1000_pch2lan:
2080 case e1000_pch_lpt:
2081 case e1000_pch_spt:
2082 case e1000_pch_cnp:
2083 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
2084 break;
2085 default:
2086 return ret_val;
2087 }
2088
2089 ret_val = hw->phy.ops.acquire(hw);
2090 if (ret_val)
2091 return ret_val;
2092
2093 data = er32(FEXTNVM);
2094 if (!(data & sw_cfg_mask))
2095 goto release;
2096
2097
2098
2099
2100 data = er32(EXTCNF_CTRL);
2101 if ((hw->mac.type < e1000_pch2lan) &&
2102 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
2103 goto release;
2104
2105 cnf_size = er32(EXTCNF_SIZE);
2106 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
2107 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
2108 if (!cnf_size)
2109 goto release;
2110
2111 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
2112 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
2113
2114 if (((hw->mac.type == e1000_pchlan) &&
2115 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
2116 (hw->mac.type > e1000_pchlan)) {
2117
2118
2119
2120
2121
2122 ret_val = e1000_write_smbus_addr(hw);
2123 if (ret_val)
2124 goto release;
2125
2126 data = er32(LEDCTL);
2127 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
2128 (u16)data);
2129 if (ret_val)
2130 goto release;
2131 }
2132
2133
2134
2135
2136 word_addr = (u16)(cnf_base_addr << 1);
2137
2138 for (i = 0; i < cnf_size; i++) {
2139 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, ®_data);
2140 if (ret_val)
2141 goto release;
2142
2143 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
2144 1, ®_addr);
2145 if (ret_val)
2146 goto release;
2147
2148
2149 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
2150 phy_page = reg_data;
2151 continue;
2152 }
2153
2154 reg_addr &= PHY_REG_MASK;
2155 reg_addr |= phy_page;
2156
2157 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
2158 if (ret_val)
2159 goto release;
2160 }
2161
2162release:
2163 hw->phy.ops.release(hw);
2164 return ret_val;
2165}
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
2178{
2179 s32 ret_val = 0;
2180 u16 status_reg = 0;
2181 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
2182
2183 if (hw->mac.type != e1000_pchlan)
2184 return 0;
2185
2186
2187 ret_val = hw->phy.ops.acquire(hw);
2188 if (ret_val)
2189 return ret_val;
2190
2191
2192 if (link) {
2193 if (hw->phy.type == e1000_phy_82578) {
2194 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
2195 &status_reg);
2196 if (ret_val)
2197 goto release;
2198
2199 status_reg &= (BM_CS_STATUS_LINK_UP |
2200 BM_CS_STATUS_RESOLVED |
2201 BM_CS_STATUS_SPEED_MASK);
2202
2203 if (status_reg == (BM_CS_STATUS_LINK_UP |
2204 BM_CS_STATUS_RESOLVED |
2205 BM_CS_STATUS_SPEED_1000))
2206 k1_enable = false;
2207 }
2208
2209 if (hw->phy.type == e1000_phy_82577) {
2210 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
2211 if (ret_val)
2212 goto release;
2213
2214 status_reg &= (HV_M_STATUS_LINK_UP |
2215 HV_M_STATUS_AUTONEG_COMPLETE |
2216 HV_M_STATUS_SPEED_MASK);
2217
2218 if (status_reg == (HV_M_STATUS_LINK_UP |
2219 HV_M_STATUS_AUTONEG_COMPLETE |
2220 HV_M_STATUS_SPEED_1000))
2221 k1_enable = false;
2222 }
2223
2224
2225 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
2226 if (ret_val)
2227 goto release;
2228
2229 } else {
2230
2231 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
2232 if (ret_val)
2233 goto release;
2234 }
2235
2236 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
2237
2238release:
2239 hw->phy.ops.release(hw);
2240
2241 return ret_val;
2242}
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
2255{
2256 s32 ret_val;
2257 u32 ctrl_reg = 0;
2258 u32 ctrl_ext = 0;
2259 u32 reg = 0;
2260 u16 kmrn_reg = 0;
2261
2262 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
2263 &kmrn_reg);
2264 if (ret_val)
2265 return ret_val;
2266
2267 if (k1_enable)
2268 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
2269 else
2270 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
2271
2272 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
2273 kmrn_reg);
2274 if (ret_val)
2275 return ret_val;
2276
2277 usleep_range(20, 40);
2278 ctrl_ext = er32(CTRL_EXT);
2279 ctrl_reg = er32(CTRL);
2280
2281 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2282 reg |= E1000_CTRL_FRCSPD;
2283 ew32(CTRL, reg);
2284
2285 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
2286 e1e_flush();
2287 usleep_range(20, 40);
2288 ew32(CTRL, ctrl_reg);
2289 ew32(CTRL_EXT, ctrl_ext);
2290 e1e_flush();
2291 usleep_range(20, 40);
2292
2293 return 0;
2294}
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
2306{
2307 s32 ret_val = 0;
2308 u32 mac_reg;
2309 u16 oem_reg;
2310
2311 if (hw->mac.type < e1000_pchlan)
2312 return ret_val;
2313
2314 ret_val = hw->phy.ops.acquire(hw);
2315 if (ret_val)
2316 return ret_val;
2317
2318 if (hw->mac.type == e1000_pchlan) {
2319 mac_reg = er32(EXTCNF_CTRL);
2320 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
2321 goto release;
2322 }
2323
2324 mac_reg = er32(FEXTNVM);
2325 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
2326 goto release;
2327
2328 mac_reg = er32(PHY_CTRL);
2329
2330 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
2331 if (ret_val)
2332 goto release;
2333
2334 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
2335
2336 if (d0_state) {
2337 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
2338 oem_reg |= HV_OEM_BITS_GBE_DIS;
2339
2340 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
2341 oem_reg |= HV_OEM_BITS_LPLU;
2342 } else {
2343 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
2344 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
2345 oem_reg |= HV_OEM_BITS_GBE_DIS;
2346
2347 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
2348 E1000_PHY_CTRL_NOND0A_LPLU))
2349 oem_reg |= HV_OEM_BITS_LPLU;
2350 }
2351
2352
2353 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
2354 !hw->phy.ops.check_reset_block(hw))
2355 oem_reg |= HV_OEM_BITS_RESTART_AN;
2356
2357 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
2358
2359release:
2360 hw->phy.ops.release(hw);
2361
2362 return ret_val;
2363}
2364
2365
2366
2367
2368
2369static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
2370{
2371 s32 ret_val;
2372 u16 data;
2373
2374 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
2375 if (ret_val)
2376 return ret_val;
2377
2378 data |= HV_KMRN_MDIO_SLOW;
2379
2380 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
2381
2382 return ret_val;
2383}
2384
2385
2386
2387
2388
2389static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2390{
2391 s32 ret_val = 0;
2392 u16 phy_data;
2393
2394 if (hw->mac.type != e1000_pchlan)
2395 return 0;
2396
2397
2398 if (hw->phy.type == e1000_phy_82577) {
2399 ret_val = e1000_set_mdio_slow_mode_hv(hw);
2400 if (ret_val)
2401 return ret_val;
2402 }
2403
2404 if (((hw->phy.type == e1000_phy_82577) &&
2405 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
2406 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
2407
2408 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
2409 if (ret_val)
2410 return ret_val;
2411
2412
2413 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
2414 if (ret_val)
2415 return ret_val;
2416 }
2417
2418 if (hw->phy.type == e1000_phy_82578) {
2419
2420
2421
2422 if (hw->phy.revision < 2) {
2423 e1000e_phy_sw_reset(hw);
2424 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
2425 if (ret_val)
2426 return ret_val;
2427 }
2428 }
2429
2430
2431 ret_val = hw->phy.ops.acquire(hw);
2432 if (ret_val)
2433 return ret_val;
2434
2435 hw->phy.addr = 1;
2436 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
2437 hw->phy.ops.release(hw);
2438 if (ret_val)
2439 return ret_val;
2440
2441
2442
2443
2444 ret_val = e1000_k1_gig_workaround_hv(hw, true);
2445 if (ret_val)
2446 return ret_val;
2447
2448
2449 ret_val = hw->phy.ops.acquire(hw);
2450 if (ret_val)
2451 return ret_val;
2452 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
2453 if (ret_val)
2454 goto release;
2455 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
2456 if (ret_val)
2457 goto release;
2458
2459
2460 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
2461release:
2462 hw->phy.ops.release(hw);
2463
2464 return ret_val;
2465}
2466
2467
2468
2469
2470
2471void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
2472{
2473 u32 mac_reg;
2474 u16 i, phy_reg = 0;
2475 s32 ret_val;
2476
2477 ret_val = hw->phy.ops.acquire(hw);
2478 if (ret_val)
2479 return;
2480 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2481 if (ret_val)
2482 goto release;
2483
2484
2485 for (i = 0; i < (hw->mac.rar_entry_count); i++) {
2486 mac_reg = er32(RAL(i));
2487 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
2488 (u16)(mac_reg & 0xFFFF));
2489 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
2490 (u16)((mac_reg >> 16) & 0xFFFF));
2491
2492 mac_reg = er32(RAH(i));
2493 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
2494 (u16)(mac_reg & 0xFFFF));
2495 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
2496 (u16)((mac_reg & E1000_RAH_AV)
2497 >> 16));
2498 }
2499
2500 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2501
2502release:
2503 hw->phy.ops.release(hw);
2504}
2505
2506
2507
2508
2509
2510
2511
2512s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
2513{
2514 s32 ret_val = 0;
2515 u16 phy_reg, data;
2516 u32 mac_reg;
2517 u16 i;
2518
2519 if (hw->mac.type < e1000_pch2lan)
2520 return 0;
2521
2522
2523 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
2524 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | BIT(14));
2525 if (ret_val)
2526 return ret_val;
2527
2528 if (enable) {
2529
2530
2531
2532 for (i = 0; i < hw->mac.rar_entry_count; i++) {
2533 u8 mac_addr[ETH_ALEN] = { 0 };
2534 u32 addr_high, addr_low;
2535
2536 addr_high = er32(RAH(i));
2537 if (!(addr_high & E1000_RAH_AV))
2538 continue;
2539 addr_low = er32(RAL(i));
2540 mac_addr[0] = (addr_low & 0xFF);
2541 mac_addr[1] = ((addr_low >> 8) & 0xFF);
2542 mac_addr[2] = ((addr_low >> 16) & 0xFF);
2543 mac_addr[3] = ((addr_low >> 24) & 0xFF);
2544 mac_addr[4] = (addr_high & 0xFF);
2545 mac_addr[5] = ((addr_high >> 8) & 0xFF);
2546
2547 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
2548 }
2549
2550
2551 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
2552
2553
2554 mac_reg = er32(FFLT_DBG);
2555 mac_reg &= ~BIT(14);
2556 mac_reg |= (7 << 15);
2557 ew32(FFLT_DBG, mac_reg);
2558
2559 mac_reg = er32(RCTL);
2560 mac_reg |= E1000_RCTL_SECRC;
2561 ew32(RCTL, mac_reg);
2562
2563 ret_val = e1000e_read_kmrn_reg(hw,
2564 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2565 &data);
2566 if (ret_val)
2567 return ret_val;
2568 ret_val = e1000e_write_kmrn_reg(hw,
2569 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2570 data | BIT(0));
2571 if (ret_val)
2572 return ret_val;
2573 ret_val = e1000e_read_kmrn_reg(hw,
2574 E1000_KMRNCTRLSTA_HD_CTRL,
2575 &data);
2576 if (ret_val)
2577 return ret_val;
2578 data &= ~(0xF << 8);
2579 data |= (0xB << 8);
2580 ret_val = e1000e_write_kmrn_reg(hw,
2581 E1000_KMRNCTRLSTA_HD_CTRL,
2582 data);
2583 if (ret_val)
2584 return ret_val;
2585
2586
2587 e1e_rphy(hw, PHY_REG(769, 23), &data);
2588 data &= ~(0x7F << 5);
2589 data |= (0x37 << 5);
2590 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2591 if (ret_val)
2592 return ret_val;
2593 e1e_rphy(hw, PHY_REG(769, 16), &data);
2594 data &= ~BIT(13);
2595 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2596 if (ret_val)
2597 return ret_val;
2598 e1e_rphy(hw, PHY_REG(776, 20), &data);
2599 data &= ~(0x3FF << 2);
2600 data |= (E1000_TX_PTR_GAP << 2);
2601 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2602 if (ret_val)
2603 return ret_val;
2604 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
2605 if (ret_val)
2606 return ret_val;
2607 e1e_rphy(hw, HV_PM_CTRL, &data);
2608 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | BIT(10));
2609 if (ret_val)
2610 return ret_val;
2611 } else {
2612
2613 mac_reg = er32(FFLT_DBG);
2614 mac_reg &= ~(0xF << 14);
2615 ew32(FFLT_DBG, mac_reg);
2616
2617 mac_reg = er32(RCTL);
2618 mac_reg &= ~E1000_RCTL_SECRC;
2619 ew32(RCTL, mac_reg);
2620
2621 ret_val = e1000e_read_kmrn_reg(hw,
2622 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2623 &data);
2624 if (ret_val)
2625 return ret_val;
2626 ret_val = e1000e_write_kmrn_reg(hw,
2627 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2628 data & ~BIT(0));
2629 if (ret_val)
2630 return ret_val;
2631 ret_val = e1000e_read_kmrn_reg(hw,
2632 E1000_KMRNCTRLSTA_HD_CTRL,
2633 &data);
2634 if (ret_val)
2635 return ret_val;
2636 data &= ~(0xF << 8);
2637 data |= (0xB << 8);
2638 ret_val = e1000e_write_kmrn_reg(hw,
2639 E1000_KMRNCTRLSTA_HD_CTRL,
2640 data);
2641 if (ret_val)
2642 return ret_val;
2643
2644
2645 e1e_rphy(hw, PHY_REG(769, 23), &data);
2646 data &= ~(0x7F << 5);
2647 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2648 if (ret_val)
2649 return ret_val;
2650 e1e_rphy(hw, PHY_REG(769, 16), &data);
2651 data |= BIT(13);
2652 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2653 if (ret_val)
2654 return ret_val;
2655 e1e_rphy(hw, PHY_REG(776, 20), &data);
2656 data &= ~(0x3FF << 2);
2657 data |= (0x8 << 2);
2658 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2659 if (ret_val)
2660 return ret_val;
2661 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2662 if (ret_val)
2663 return ret_val;
2664 e1e_rphy(hw, HV_PM_CTRL, &data);
2665 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~BIT(10));
2666 if (ret_val)
2667 return ret_val;
2668 }
2669
2670
2671 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~BIT(14));
2672}
2673
2674
2675
2676
2677
2678static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2679{
2680 s32 ret_val = 0;
2681
2682 if (hw->mac.type != e1000_pch2lan)
2683 return 0;
2684
2685
2686 ret_val = e1000_set_mdio_slow_mode_hv(hw);
2687 if (ret_val)
2688 return ret_val;
2689
2690 ret_val = hw->phy.ops.acquire(hw);
2691 if (ret_val)
2692 return ret_val;
2693
2694 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
2695 if (ret_val)
2696 goto release;
2697
2698 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
2699release:
2700 hw->phy.ops.release(hw);
2701
2702 return ret_val;
2703}
2704
2705
2706
2707
2708
2709
2710
2711
2712static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2713{
2714 s32 ret_val = 0;
2715 u16 status_reg = 0;
2716
2717 if (hw->mac.type != e1000_pch2lan)
2718 return 0;
2719
2720
2721 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2722 if (ret_val)
2723 return ret_val;
2724
2725 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2726 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2727 if (status_reg &
2728 (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
2729 u16 pm_phy_reg;
2730
2731
2732 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2733 if (ret_val)
2734 return ret_val;
2735 pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
2736 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2737 if (ret_val)
2738 return ret_val;
2739 } else {
2740 u32 mac_reg;
2741
2742 mac_reg = er32(FEXTNVM4);
2743 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2744 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2745 ew32(FEXTNVM4, mac_reg);
2746 }
2747 }
2748
2749 return ret_val;
2750}
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2761{
2762 u32 extcnf_ctrl;
2763
2764 if (hw->mac.type < e1000_pch2lan)
2765 return;
2766
2767 extcnf_ctrl = er32(EXTCNF_CTRL);
2768
2769 if (gate)
2770 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2771 else
2772 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2773
2774 ew32(EXTCNF_CTRL, extcnf_ctrl);
2775}
2776
2777
2778
2779
2780
2781
2782
2783
2784static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2785{
2786 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2787
2788
2789 do {
2790 data = er32(STATUS);
2791 data &= E1000_STATUS_LAN_INIT_DONE;
2792 usleep_range(100, 200);
2793 } while ((!data) && --loop);
2794
2795
2796
2797
2798
2799 if (loop == 0)
2800 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
2801
2802
2803 data = er32(STATUS);
2804 data &= ~E1000_STATUS_LAN_INIT_DONE;
2805 ew32(STATUS, data);
2806}
2807
2808
2809
2810
2811
2812static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
2813{
2814 s32 ret_val = 0;
2815 u16 reg;
2816
2817 if (hw->phy.ops.check_reset_block(hw))
2818 return 0;
2819
2820
2821 usleep_range(10000, 20000);
2822
2823
2824 switch (hw->mac.type) {
2825 case e1000_pchlan:
2826 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2827 if (ret_val)
2828 return ret_val;
2829 break;
2830 case e1000_pch2lan:
2831 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2832 if (ret_val)
2833 return ret_val;
2834 break;
2835 default:
2836 break;
2837 }
2838
2839
2840 if (hw->mac.type >= e1000_pchlan) {
2841 e1e_rphy(hw, BM_PORT_GEN_CFG, ®);
2842 reg &= ~BM_WUC_HOST_WU_BIT;
2843 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2844 }
2845
2846
2847 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2848 if (ret_val)
2849 return ret_val;
2850
2851
2852 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
2853
2854 if (hw->mac.type == e1000_pch2lan) {
2855
2856 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
2857 usleep_range(10000, 20000);
2858 e1000_gate_hw_phy_config_ich8lan(hw, false);
2859 }
2860
2861
2862 ret_val = hw->phy.ops.acquire(hw);
2863 if (ret_val)
2864 return ret_val;
2865 ret_val = e1000_write_emi_reg_locked(hw,
2866 I82579_LPI_UPDATE_TIMER,
2867 0x1387);
2868 hw->phy.ops.release(hw);
2869 }
2870
2871 return ret_val;
2872}
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2883{
2884 s32 ret_val = 0;
2885
2886
2887 if ((hw->mac.type == e1000_pch2lan) &&
2888 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2889 e1000_gate_hw_phy_config_ich8lan(hw, true);
2890
2891 ret_val = e1000e_phy_hw_reset_generic(hw);
2892 if (ret_val)
2893 return ret_val;
2894
2895 return e1000_post_phy_reset_ich8lan(hw);
2896}
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2910{
2911 s32 ret_val;
2912 u16 oem_reg;
2913
2914 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2915 if (ret_val)
2916 return ret_val;
2917
2918 if (active)
2919 oem_reg |= HV_OEM_BITS_LPLU;
2920 else
2921 oem_reg &= ~HV_OEM_BITS_LPLU;
2922
2923 if (!hw->phy.ops.check_reset_block(hw))
2924 oem_reg |= HV_OEM_BITS_RESTART_AN;
2925
2926 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
2927}
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2943{
2944 struct e1000_phy_info *phy = &hw->phy;
2945 u32 phy_ctrl;
2946 s32 ret_val = 0;
2947 u16 data;
2948
2949 if (phy->type == e1000_phy_ife)
2950 return 0;
2951
2952 phy_ctrl = er32(PHY_CTRL);
2953
2954 if (active) {
2955 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2956 ew32(PHY_CTRL, phy_ctrl);
2957
2958 if (phy->type != e1000_phy_igp_3)
2959 return 0;
2960
2961
2962
2963
2964 if (hw->mac.type == e1000_ich8lan)
2965 e1000e_gig_downshift_workaround_ich8lan(hw);
2966
2967
2968 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
2969 if (ret_val)
2970 return ret_val;
2971 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2972 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2973 if (ret_val)
2974 return ret_val;
2975 } else {
2976 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2977 ew32(PHY_CTRL, phy_ctrl);
2978
2979 if (phy->type != e1000_phy_igp_3)
2980 return 0;
2981
2982
2983
2984
2985
2986
2987 if (phy->smart_speed == e1000_smart_speed_on) {
2988 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2989 &data);
2990 if (ret_val)
2991 return ret_val;
2992
2993 data |= IGP01E1000_PSCFR_SMART_SPEED;
2994 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2995 data);
2996 if (ret_val)
2997 return ret_val;
2998 } else if (phy->smart_speed == e1000_smart_speed_off) {
2999 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
3000 &data);
3001 if (ret_val)
3002 return ret_val;
3003
3004 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
3005 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
3006 data);
3007 if (ret_val)
3008 return ret_val;
3009 }
3010 }
3011
3012 return 0;
3013}
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
3029{
3030 struct e1000_phy_info *phy = &hw->phy;
3031 u32 phy_ctrl;
3032 s32 ret_val = 0;
3033 u16 data;
3034
3035 phy_ctrl = er32(PHY_CTRL);
3036
3037 if (!active) {
3038 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
3039 ew32(PHY_CTRL, phy_ctrl);
3040
3041 if (phy->type != e1000_phy_igp_3)
3042 return 0;
3043
3044
3045
3046
3047
3048
3049 if (phy->smart_speed == e1000_smart_speed_on) {
3050 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
3051 &data);
3052 if (ret_val)
3053 return ret_val;
3054
3055 data |= IGP01E1000_PSCFR_SMART_SPEED;
3056 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
3057 data);
3058 if (ret_val)
3059 return ret_val;
3060 } else if (phy->smart_speed == e1000_smart_speed_off) {
3061 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
3062 &data);
3063 if (ret_val)
3064 return ret_val;
3065
3066 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
3067 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
3068 data);
3069 if (ret_val)
3070 return ret_val;
3071 }
3072 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
3073 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
3074 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
3075 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
3076 ew32(PHY_CTRL, phy_ctrl);
3077
3078 if (phy->type != e1000_phy_igp_3)
3079 return 0;
3080
3081
3082
3083
3084 if (hw->mac.type == e1000_ich8lan)
3085 e1000e_gig_downshift_workaround_ich8lan(hw);
3086
3087
3088 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
3089 if (ret_val)
3090 return ret_val;
3091
3092 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
3093 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
3094 }
3095
3096 return ret_val;
3097}
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
3108{
3109 u32 eecd;
3110 struct e1000_nvm_info *nvm = &hw->nvm;
3111 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
3112 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
3113 u32 nvm_dword = 0;
3114 u8 sig_byte = 0;
3115 s32 ret_val;
3116
3117 switch (hw->mac.type) {
3118 case e1000_pch_spt:
3119 case e1000_pch_cnp:
3120 bank1_offset = nvm->flash_bank_size;
3121 act_offset = E1000_ICH_NVM_SIG_WORD;
3122
3123
3124 *bank = 0;
3125
3126
3127 ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset,
3128 &nvm_dword);
3129 if (ret_val)
3130 return ret_val;
3131 sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
3132 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
3133 E1000_ICH_NVM_SIG_VALUE) {
3134 *bank = 0;
3135 return 0;
3136 }
3137
3138
3139 ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset +
3140 bank1_offset,
3141 &nvm_dword);
3142 if (ret_val)
3143 return ret_val;
3144 sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
3145 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
3146 E1000_ICH_NVM_SIG_VALUE) {
3147 *bank = 1;
3148 return 0;
3149 }
3150
3151 e_dbg("ERROR: No valid NVM bank present\n");
3152 return -E1000_ERR_NVM;
3153 case e1000_ich8lan:
3154 case e1000_ich9lan:
3155 eecd = er32(EECD);
3156 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
3157 E1000_EECD_SEC1VAL_VALID_MASK) {
3158 if (eecd & E1000_EECD_SEC1VAL)
3159 *bank = 1;
3160 else
3161 *bank = 0;
3162
3163 return 0;
3164 }
3165 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
3166
3167 default:
3168
3169 *bank = 0;
3170
3171
3172 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
3173 &sig_byte);
3174 if (ret_val)
3175 return ret_val;
3176 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
3177 E1000_ICH_NVM_SIG_VALUE) {
3178 *bank = 0;
3179 return 0;
3180 }
3181
3182
3183 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
3184 bank1_offset,
3185 &sig_byte);
3186 if (ret_val)
3187 return ret_val;
3188 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
3189 E1000_ICH_NVM_SIG_VALUE) {
3190 *bank = 1;
3191 return 0;
3192 }
3193
3194 e_dbg("ERROR: No valid NVM bank present\n");
3195 return -E1000_ERR_NVM;
3196 }
3197}
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208static s32 e1000_read_nvm_spt(struct e1000_hw *hw, u16 offset, u16 words,
3209 u16 *data)
3210{
3211 struct e1000_nvm_info *nvm = &hw->nvm;
3212 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3213 u32 act_offset;
3214 s32 ret_val = 0;
3215 u32 bank = 0;
3216 u32 dword = 0;
3217 u16 offset_to_read;
3218 u16 i;
3219
3220 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
3221 (words == 0)) {
3222 e_dbg("nvm parameter(s) out of bounds\n");
3223 ret_val = -E1000_ERR_NVM;
3224 goto out;
3225 }
3226
3227 nvm->ops.acquire(hw);
3228
3229 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
3230 if (ret_val) {
3231 e_dbg("Could not detect valid bank, assuming bank 0\n");
3232 bank = 0;
3233 }
3234
3235 act_offset = (bank) ? nvm->flash_bank_size : 0;
3236 act_offset += offset;
3237
3238 ret_val = 0;
3239
3240 for (i = 0; i < words; i += 2) {
3241 if (words - i == 1) {
3242 if (dev_spec->shadow_ram[offset + i].modified) {
3243 data[i] =
3244 dev_spec->shadow_ram[offset + i].value;
3245 } else {
3246 offset_to_read = act_offset + i -
3247 ((act_offset + i) % 2);
3248 ret_val =
3249 e1000_read_flash_dword_ich8lan(hw,
3250 offset_to_read,
3251 &dword);
3252 if (ret_val)
3253 break;
3254 if ((act_offset + i) % 2 == 0)
3255 data[i] = (u16)(dword & 0xFFFF);
3256 else
3257 data[i] = (u16)((dword >> 16) & 0xFFFF);
3258 }
3259 } else {
3260 offset_to_read = act_offset + i;
3261 if (!(dev_spec->shadow_ram[offset + i].modified) ||
3262 !(dev_spec->shadow_ram[offset + i + 1].modified)) {
3263 ret_val =
3264 e1000_read_flash_dword_ich8lan(hw,
3265 offset_to_read,
3266 &dword);
3267 if (ret_val)
3268 break;
3269 }
3270 if (dev_spec->shadow_ram[offset + i].modified)
3271 data[i] =
3272 dev_spec->shadow_ram[offset + i].value;
3273 else
3274 data[i] = (u16)(dword & 0xFFFF);
3275 if (dev_spec->shadow_ram[offset + i].modified)
3276 data[i + 1] =
3277 dev_spec->shadow_ram[offset + i + 1].value;
3278 else
3279 data[i + 1] = (u16)(dword >> 16 & 0xFFFF);
3280 }
3281 }
3282
3283 nvm->ops.release(hw);
3284
3285out:
3286 if (ret_val)
3287 e_dbg("NVM read error: %d\n", ret_val);
3288
3289 return ret_val;
3290}
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
3302 u16 *data)
3303{
3304 struct e1000_nvm_info *nvm = &hw->nvm;
3305 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3306 u32 act_offset;
3307 s32 ret_val = 0;
3308 u32 bank = 0;
3309 u16 i, word;
3310
3311 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
3312 (words == 0)) {
3313 e_dbg("nvm parameter(s) out of bounds\n");
3314 ret_val = -E1000_ERR_NVM;
3315 goto out;
3316 }
3317
3318 nvm->ops.acquire(hw);
3319
3320 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
3321 if (ret_val) {
3322 e_dbg("Could not detect valid bank, assuming bank 0\n");
3323 bank = 0;
3324 }
3325
3326 act_offset = (bank) ? nvm->flash_bank_size : 0;
3327 act_offset += offset;
3328
3329 ret_val = 0;
3330 for (i = 0; i < words; i++) {
3331 if (dev_spec->shadow_ram[offset + i].modified) {
3332 data[i] = dev_spec->shadow_ram[offset + i].value;
3333 } else {
3334 ret_val = e1000_read_flash_word_ich8lan(hw,
3335 act_offset + i,
3336 &word);
3337 if (ret_val)
3338 break;
3339 data[i] = word;
3340 }
3341 }
3342
3343 nvm->ops.release(hw);
3344
3345out:
3346 if (ret_val)
3347 e_dbg("NVM read error: %d\n", ret_val);
3348
3349 return ret_val;
3350}
3351
3352
3353
3354
3355
3356
3357
3358
3359static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
3360{
3361 union ich8_hws_flash_status hsfsts;
3362 s32 ret_val = -E1000_ERR_NVM;
3363
3364 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3365
3366
3367 if (!hsfsts.hsf_status.fldesvalid) {
3368 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
3369 return -E1000_ERR_NVM;
3370 }
3371
3372
3373 hsfsts.hsf_status.flcerr = 1;
3374 hsfsts.hsf_status.dael = 1;
3375 if (hw->mac.type >= e1000_pch_spt)
3376 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval & 0xFFFF);
3377 else
3378 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388 if (!hsfsts.hsf_status.flcinprog) {
3389
3390
3391
3392
3393 hsfsts.hsf_status.flcdone = 1;
3394 if (hw->mac.type >= e1000_pch_spt)
3395 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval & 0xFFFF);
3396 else
3397 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3398 ret_val = 0;
3399 } else {
3400 s32 i;
3401
3402
3403
3404
3405 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
3406 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3407 if (!hsfsts.hsf_status.flcinprog) {
3408 ret_val = 0;
3409 break;
3410 }
3411 udelay(1);
3412 }
3413 if (!ret_val) {
3414
3415
3416
3417 hsfsts.hsf_status.flcdone = 1;
3418 if (hw->mac.type >= e1000_pch_spt)
3419 ew32flash(ICH_FLASH_HSFSTS,
3420 hsfsts.regval & 0xFFFF);
3421 else
3422 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3423 } else {
3424 e_dbg("Flash controller busy, cannot get access\n");
3425 }
3426 }
3427
3428 return ret_val;
3429}
3430
3431
3432
3433
3434
3435
3436
3437
3438static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
3439{
3440 union ich8_hws_flash_ctrl hsflctl;
3441 union ich8_hws_flash_status hsfsts;
3442 u32 i = 0;
3443
3444
3445 if (hw->mac.type >= e1000_pch_spt)
3446 hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
3447 else
3448 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3449 hsflctl.hsf_ctrl.flcgo = 1;
3450
3451 if (hw->mac.type >= e1000_pch_spt)
3452 ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
3453 else
3454 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3455
3456
3457 do {
3458 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3459 if (hsfsts.hsf_status.flcdone)
3460 break;
3461 udelay(1);
3462 } while (i++ < timeout);
3463
3464 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
3465 return 0;
3466
3467 return -E1000_ERR_NVM;
3468}
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479static s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw, u32 offset,
3480 u32 *data)
3481{
3482
3483 offset <<= 1;
3484 return e1000_read_flash_data32_ich8lan(hw, offset, data);
3485}
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
3497 u16 *data)
3498{
3499
3500 offset <<= 1;
3501
3502 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
3503}
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3514 u8 *data)
3515{
3516 s32 ret_val;
3517 u16 word = 0;
3518
3519
3520
3521
3522 if (hw->mac.type >= e1000_pch_spt)
3523 return -E1000_ERR_NVM;
3524 else
3525 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
3526
3527 if (ret_val)
3528 return ret_val;
3529
3530 *data = (u8)word;
3531
3532 return 0;
3533}
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3545 u8 size, u16 *data)
3546{
3547 union ich8_hws_flash_status hsfsts;
3548 union ich8_hws_flash_ctrl hsflctl;
3549 u32 flash_linear_addr;
3550 u32 flash_data = 0;
3551 s32 ret_val = -E1000_ERR_NVM;
3552 u8 count = 0;
3553
3554 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
3555 return -E1000_ERR_NVM;
3556
3557 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3558 hw->nvm.flash_base_addr);
3559
3560 do {
3561 udelay(1);
3562
3563 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3564 if (ret_val)
3565 break;
3566
3567 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3568
3569 hsflctl.hsf_ctrl.fldbcount = size - 1;
3570 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
3571 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3572
3573 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3574
3575 ret_val =
3576 e1000_flash_cycle_ich8lan(hw,
3577 ICH_FLASH_READ_COMMAND_TIMEOUT);
3578
3579
3580
3581
3582
3583
3584 if (!ret_val) {
3585 flash_data = er32flash(ICH_FLASH_FDATA0);
3586 if (size == 1)
3587 *data = (u8)(flash_data & 0x000000FF);
3588 else if (size == 2)
3589 *data = (u16)(flash_data & 0x0000FFFF);
3590 break;
3591 } else {
3592
3593
3594
3595
3596
3597 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3598 if (hsfsts.hsf_status.flcerr) {
3599
3600 continue;
3601 } else if (!hsfsts.hsf_status.flcdone) {
3602 e_dbg("Timeout error - flash cycle did not complete.\n");
3603 break;
3604 }
3605 }
3606 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3607
3608 return ret_val;
3609}
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620static s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
3621 u32 *data)
3622{
3623 union ich8_hws_flash_status hsfsts;
3624 union ich8_hws_flash_ctrl hsflctl;
3625 u32 flash_linear_addr;
3626 s32 ret_val = -E1000_ERR_NVM;
3627 u8 count = 0;
3628
3629 if (offset > ICH_FLASH_LINEAR_ADDR_MASK || hw->mac.type < e1000_pch_spt)
3630 return -E1000_ERR_NVM;
3631 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3632 hw->nvm.flash_base_addr);
3633
3634 do {
3635 udelay(1);
3636
3637 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3638 if (ret_val)
3639 break;
3640
3641
3642
3643 hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
3644
3645
3646 hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
3647 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
3648
3649
3650
3651 ew32flash(ICH_FLASH_HSFSTS, (u32)hsflctl.regval << 16);
3652 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3653
3654 ret_val =
3655 e1000_flash_cycle_ich8lan(hw,
3656 ICH_FLASH_READ_COMMAND_TIMEOUT);
3657
3658
3659
3660
3661
3662
3663 if (!ret_val) {
3664 *data = er32flash(ICH_FLASH_FDATA0);
3665 break;
3666 } else {
3667
3668
3669
3670
3671
3672 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3673 if (hsfsts.hsf_status.flcerr) {
3674
3675 continue;
3676 } else if (!hsfsts.hsf_status.flcdone) {
3677 e_dbg("Timeout error - flash cycle did not complete.\n");
3678 break;
3679 }
3680 }
3681 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3682
3683 return ret_val;
3684}
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
3696 u16 *data)
3697{
3698 struct e1000_nvm_info *nvm = &hw->nvm;
3699 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3700 u16 i;
3701
3702 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
3703 (words == 0)) {
3704 e_dbg("nvm parameter(s) out of bounds\n");
3705 return -E1000_ERR_NVM;
3706 }
3707
3708 nvm->ops.acquire(hw);
3709
3710 for (i = 0; i < words; i++) {
3711 dev_spec->shadow_ram[offset + i].modified = true;
3712 dev_spec->shadow_ram[offset + i].value = data[i];
3713 }
3714
3715 nvm->ops.release(hw);
3716
3717 return 0;
3718}
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731static s32 e1000_update_nvm_checksum_spt(struct e1000_hw *hw)
3732{
3733 struct e1000_nvm_info *nvm = &hw->nvm;
3734 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3735 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
3736 s32 ret_val;
3737 u32 dword = 0;
3738
3739 ret_val = e1000e_update_nvm_checksum_generic(hw);
3740 if (ret_val)
3741 goto out;
3742
3743 if (nvm->type != e1000_nvm_flash_sw)
3744 goto out;
3745
3746 nvm->ops.acquire(hw);
3747
3748
3749
3750
3751
3752 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
3753 if (ret_val) {
3754 e_dbg("Could not detect valid bank, assuming bank 0\n");
3755 bank = 0;
3756 }
3757
3758 if (bank == 0) {
3759 new_bank_offset = nvm->flash_bank_size;
3760 old_bank_offset = 0;
3761 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
3762 if (ret_val)
3763 goto release;
3764 } else {
3765 old_bank_offset = nvm->flash_bank_size;
3766 new_bank_offset = 0;
3767 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
3768 if (ret_val)
3769 goto release;
3770 }
3771 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i += 2) {
3772
3773
3774
3775
3776 ret_val = e1000_read_flash_dword_ich8lan(hw,
3777 i + old_bank_offset,
3778 &dword);
3779
3780 if (dev_spec->shadow_ram[i].modified) {
3781 dword &= 0xffff0000;
3782 dword |= (dev_spec->shadow_ram[i].value & 0xffff);
3783 }
3784 if (dev_spec->shadow_ram[i + 1].modified) {
3785 dword &= 0x0000ffff;
3786 dword |= ((dev_spec->shadow_ram[i + 1].value & 0xffff)
3787 << 16);
3788 }
3789 if (ret_val)
3790 break;
3791
3792
3793
3794
3795
3796
3797
3798
3799 if (i == E1000_ICH_NVM_SIG_WORD - 1)
3800 dword |= E1000_ICH_NVM_SIG_MASK << 16;
3801
3802
3803 act_offset = (i + new_bank_offset) << 1;
3804
3805 usleep_range(100, 200);
3806
3807
3808 act_offset = i + new_bank_offset;
3809 ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset,
3810 dword);
3811 if (ret_val)
3812 break;
3813 }
3814
3815
3816
3817
3818 if (ret_val) {
3819
3820 e_dbg("Flash commit failed.\n");
3821 goto release;
3822 }
3823
3824
3825
3826
3827
3828
3829 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
3830
3831
3832 --act_offset;
3833 ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
3834
3835 if (ret_val)
3836 goto release;
3837
3838 dword &= 0xBFFFFFFF;
3839 ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
3840
3841 if (ret_val)
3842 goto release;
3843
3844
3845
3846
3847
3848
3849 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3850
3851
3852 act_offset = old_bank_offset + E1000_ICH_NVM_SIG_WORD - 1;
3853 ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
3854
3855 if (ret_val)
3856 goto release;
3857
3858 dword &= 0x00FFFFFF;
3859 ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
3860
3861 if (ret_val)
3862 goto release;
3863
3864
3865 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
3866 dev_spec->shadow_ram[i].modified = false;
3867 dev_spec->shadow_ram[i].value = 0xFFFF;
3868 }
3869
3870release:
3871 nvm->ops.release(hw);
3872
3873
3874
3875
3876 if (!ret_val) {
3877 nvm->ops.reload(hw);
3878 usleep_range(10000, 20000);
3879 }
3880
3881out:
3882 if (ret_val)
3883 e_dbg("NVM update error: %d\n", ret_val);
3884
3885 return ret_val;
3886}
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
3900{
3901 struct e1000_nvm_info *nvm = &hw->nvm;
3902 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3903 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
3904 s32 ret_val;
3905 u16 data = 0;
3906
3907 ret_val = e1000e_update_nvm_checksum_generic(hw);
3908 if (ret_val)
3909 goto out;
3910
3911 if (nvm->type != e1000_nvm_flash_sw)
3912 goto out;
3913
3914 nvm->ops.acquire(hw);
3915
3916
3917
3918
3919
3920 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
3921 if (ret_val) {
3922 e_dbg("Could not detect valid bank, assuming bank 0\n");
3923 bank = 0;
3924 }
3925
3926 if (bank == 0) {
3927 new_bank_offset = nvm->flash_bank_size;
3928 old_bank_offset = 0;
3929 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
3930 if (ret_val)
3931 goto release;
3932 } else {
3933 old_bank_offset = nvm->flash_bank_size;
3934 new_bank_offset = 0;
3935 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
3936 if (ret_val)
3937 goto release;
3938 }
3939 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
3940 if (dev_spec->shadow_ram[i].modified) {
3941 data = dev_spec->shadow_ram[i].value;
3942 } else {
3943 ret_val = e1000_read_flash_word_ich8lan(hw, i +
3944 old_bank_offset,
3945 &data);
3946 if (ret_val)
3947 break;
3948 }
3949
3950
3951
3952
3953
3954
3955
3956
3957 if (i == E1000_ICH_NVM_SIG_WORD)
3958 data |= E1000_ICH_NVM_SIG_MASK;
3959
3960
3961 act_offset = (i + new_bank_offset) << 1;
3962
3963 usleep_range(100, 200);
3964
3965 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3966 act_offset,
3967 (u8)data);
3968 if (ret_val)
3969 break;
3970
3971 usleep_range(100, 200);
3972 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3973 act_offset + 1,
3974 (u8)(data >> 8));
3975 if (ret_val)
3976 break;
3977 }
3978
3979
3980
3981
3982 if (ret_val) {
3983
3984 e_dbg("Flash commit failed.\n");
3985 goto release;
3986 }
3987
3988
3989
3990
3991
3992
3993 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
3994 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
3995 if (ret_val)
3996 goto release;
3997
3998 data &= 0xBFFF;
3999 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
4000 act_offset * 2 + 1,
4001 (u8)(data >> 8));
4002 if (ret_val)
4003 goto release;
4004
4005
4006
4007
4008
4009
4010 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
4011 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
4012 if (ret_val)
4013 goto release;
4014
4015
4016 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
4017 dev_spec->shadow_ram[i].modified = false;
4018 dev_spec->shadow_ram[i].value = 0xFFFF;
4019 }
4020
4021release:
4022 nvm->ops.release(hw);
4023
4024
4025
4026
4027 if (!ret_val) {
4028 nvm->ops.reload(hw);
4029 usleep_range(10000, 20000);
4030 }
4031
4032out:
4033 if (ret_val)
4034 e_dbg("NVM update error: %d\n", ret_val);
4035
4036 return ret_val;
4037}
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
4048{
4049 s32 ret_val;
4050 u16 data;
4051 u16 word;
4052 u16 valid_csum_mask;
4053
4054
4055
4056
4057
4058
4059 switch (hw->mac.type) {
4060 case e1000_pch_lpt:
4061 case e1000_pch_spt:
4062 case e1000_pch_cnp:
4063 word = NVM_COMPAT;
4064 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
4065 break;
4066 default:
4067 word = NVM_FUTURE_INIT_WORD1;
4068 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
4069 break;
4070 }
4071
4072 ret_val = e1000_read_nvm(hw, word, 1, &data);
4073 if (ret_val)
4074 return ret_val;
4075
4076 if (!(data & valid_csum_mask)) {
4077 data |= valid_csum_mask;
4078 ret_val = e1000_write_nvm(hw, word, 1, &data);
4079 if (ret_val)
4080 return ret_val;
4081 ret_val = e1000e_update_nvm_checksum(hw);
4082 if (ret_val)
4083 return ret_val;
4084 }
4085
4086 return e1000e_validate_nvm_checksum_generic(hw);
4087}
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
4100{
4101 struct e1000_nvm_info *nvm = &hw->nvm;
4102 union ich8_flash_protected_range pr0;
4103 union ich8_hws_flash_status hsfsts;
4104 u32 gfpreg;
4105
4106 nvm->ops.acquire(hw);
4107
4108 gfpreg = er32flash(ICH_FLASH_GFPREG);
4109
4110
4111 pr0.regval = er32flash(ICH_FLASH_PR0);
4112 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
4113 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
4114 pr0.range.wpe = true;
4115 ew32flash(ICH_FLASH_PR0, pr0.regval);
4116
4117
4118
4119
4120
4121
4122 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
4123 hsfsts.hsf_status.flockdn = true;
4124 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
4125
4126 nvm->ops.release(hw);
4127}
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
4139 u8 size, u16 data)
4140{
4141 union ich8_hws_flash_status hsfsts;
4142 union ich8_hws_flash_ctrl hsflctl;
4143 u32 flash_linear_addr;
4144 u32 flash_data = 0;
4145 s32 ret_val;
4146 u8 count = 0;
4147
4148 if (hw->mac.type >= e1000_pch_spt) {
4149 if (size != 4 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
4150 return -E1000_ERR_NVM;
4151 } else {
4152 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
4153 return -E1000_ERR_NVM;
4154 }
4155
4156 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
4157 hw->nvm.flash_base_addr);
4158
4159 do {
4160 udelay(1);
4161
4162 ret_val = e1000_flash_cycle_init_ich8lan(hw);
4163 if (ret_val)
4164 break;
4165
4166
4167
4168 if (hw->mac.type >= e1000_pch_spt)
4169 hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
4170 else
4171 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
4172
4173
4174 hsflctl.hsf_ctrl.fldbcount = size - 1;
4175 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
4176
4177
4178
4179
4180 if (hw->mac.type >= e1000_pch_spt)
4181 ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
4182 else
4183 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
4184
4185 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
4186
4187 if (size == 1)
4188 flash_data = (u32)data & 0x00FF;
4189 else
4190 flash_data = (u32)data;
4191
4192 ew32flash(ICH_FLASH_FDATA0, flash_data);
4193
4194
4195
4196
4197 ret_val =
4198 e1000_flash_cycle_ich8lan(hw,
4199 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
4200 if (!ret_val)
4201 break;
4202
4203
4204
4205
4206
4207
4208 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
4209 if (hsfsts.hsf_status.flcerr)
4210
4211 continue;
4212 if (!hsfsts.hsf_status.flcdone) {
4213 e_dbg("Timeout error - flash cycle did not complete.\n");
4214 break;
4215 }
4216 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
4217
4218 return ret_val;
4219}
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229static s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
4230 u32 data)
4231{
4232 union ich8_hws_flash_status hsfsts;
4233 union ich8_hws_flash_ctrl hsflctl;
4234 u32 flash_linear_addr;
4235 s32 ret_val;
4236 u8 count = 0;
4237
4238 if (hw->mac.type >= e1000_pch_spt) {
4239 if (offset > ICH_FLASH_LINEAR_ADDR_MASK)
4240 return -E1000_ERR_NVM;
4241 }
4242 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
4243 hw->nvm.flash_base_addr);
4244 do {
4245 udelay(1);
4246
4247 ret_val = e1000_flash_cycle_init_ich8lan(hw);
4248 if (ret_val)
4249 break;
4250
4251
4252
4253
4254 if (hw->mac.type >= e1000_pch_spt)
4255 hsflctl.regval = er32flash(ICH_FLASH_HSFSTS)
4256 >> 16;
4257 else
4258 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
4259
4260 hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
4261 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
4262
4263
4264
4265
4266
4267 if (hw->mac.type >= e1000_pch_spt)
4268 ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
4269 else
4270 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
4271
4272 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
4273
4274 ew32flash(ICH_FLASH_FDATA0, data);
4275
4276
4277
4278
4279 ret_val =
4280 e1000_flash_cycle_ich8lan(hw,
4281 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
4282
4283 if (!ret_val)
4284 break;
4285
4286
4287
4288
4289
4290
4291 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
4292
4293 if (hsfsts.hsf_status.flcerr)
4294
4295 continue;
4296 if (!hsfsts.hsf_status.flcdone) {
4297 e_dbg("Timeout error - flash cycle did not complete.\n");
4298 break;
4299 }
4300 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
4301
4302 return ret_val;
4303}
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
4314 u8 data)
4315{
4316 u16 word = (u16)data;
4317
4318 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
4319}
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330static s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
4331 u32 offset, u32 dword)
4332{
4333 s32 ret_val;
4334 u16 program_retries;
4335
4336
4337 offset <<= 1;
4338 ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
4339
4340 if (!ret_val)
4341 return ret_val;
4342 for (program_retries = 0; program_retries < 100; program_retries++) {
4343 e_dbg("Retrying Byte %8.8X at offset %u\n", dword, offset);
4344 usleep_range(100, 200);
4345 ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
4346 if (!ret_val)
4347 break;
4348 }
4349 if (program_retries == 100)
4350 return -E1000_ERR_NVM;
4351
4352 return 0;
4353}
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
4365 u32 offset, u8 byte)
4366{
4367 s32 ret_val;
4368 u16 program_retries;
4369
4370 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
4371 if (!ret_val)
4372 return ret_val;
4373
4374 for (program_retries = 0; program_retries < 100; program_retries++) {
4375 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
4376 usleep_range(100, 200);
4377 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
4378 if (!ret_val)
4379 break;
4380 }
4381 if (program_retries == 100)
4382 return -E1000_ERR_NVM;
4383
4384 return 0;
4385}
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
4396{
4397 struct e1000_nvm_info *nvm = &hw->nvm;
4398 union ich8_hws_flash_status hsfsts;
4399 union ich8_hws_flash_ctrl hsflctl;
4400 u32 flash_linear_addr;
4401
4402 u32 flash_bank_size = nvm->flash_bank_size * 2;
4403 s32 ret_val;
4404 s32 count = 0;
4405 s32 j, iteration, sector_size;
4406
4407 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421 switch (hsfsts.hsf_status.berasesz) {
4422 case 0:
4423
4424 sector_size = ICH_FLASH_SEG_SIZE_256;
4425 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
4426 break;
4427 case 1:
4428 sector_size = ICH_FLASH_SEG_SIZE_4K;
4429 iteration = 1;
4430 break;
4431 case 2:
4432 sector_size = ICH_FLASH_SEG_SIZE_8K;
4433 iteration = 1;
4434 break;
4435 case 3:
4436 sector_size = ICH_FLASH_SEG_SIZE_64K;
4437 iteration = 1;
4438 break;
4439 default:
4440 return -E1000_ERR_NVM;
4441 }
4442
4443
4444 flash_linear_addr = hw->nvm.flash_base_addr;
4445 flash_linear_addr += (bank) ? flash_bank_size : 0;
4446
4447 for (j = 0; j < iteration; j++) {
4448 do {
4449 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
4450
4451
4452 ret_val = e1000_flash_cycle_init_ich8lan(hw);
4453 if (ret_val)
4454 return ret_val;
4455
4456
4457
4458
4459 if (hw->mac.type >= e1000_pch_spt)
4460 hsflctl.regval =
4461 er32flash(ICH_FLASH_HSFSTS) >> 16;
4462 else
4463 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
4464
4465 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
4466 if (hw->mac.type >= e1000_pch_spt)
4467 ew32flash(ICH_FLASH_HSFSTS,
4468 hsflctl.regval << 16);
4469 else
4470 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
4471
4472
4473
4474
4475
4476 flash_linear_addr += (j * sector_size);
4477 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
4478
4479 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
4480 if (!ret_val)
4481 break;
4482
4483
4484
4485
4486
4487 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
4488 if (hsfsts.hsf_status.flcerr)
4489
4490 continue;
4491 else if (!hsfsts.hsf_status.flcdone)
4492 return ret_val;
4493 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
4494 }
4495
4496 return 0;
4497}
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
4509{
4510 s32 ret_val;
4511
4512 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
4513 if (ret_val) {
4514 e_dbg("NVM Read Error\n");
4515 return ret_val;
4516 }
4517
4518 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
4519 *data = ID_LED_DEFAULT_ICH8LAN;
4520
4521 return 0;
4522}
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
4538{
4539 struct e1000_mac_info *mac = &hw->mac;
4540 s32 ret_val;
4541 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
4542 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
4543 u16 data, i, temp, shift;
4544
4545
4546 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
4547 if (ret_val)
4548 return ret_val;
4549
4550 mac->ledctl_default = er32(LEDCTL);
4551 mac->ledctl_mode1 = mac->ledctl_default;
4552 mac->ledctl_mode2 = mac->ledctl_default;
4553
4554 for (i = 0; i < 4; i++) {
4555 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
4556 shift = (i * 5);
4557 switch (temp) {
4558 case ID_LED_ON1_DEF2:
4559 case ID_LED_ON1_ON2:
4560 case ID_LED_ON1_OFF2:
4561 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
4562 mac->ledctl_mode1 |= (ledctl_on << shift);
4563 break;
4564 case ID_LED_OFF1_DEF2:
4565 case ID_LED_OFF1_ON2:
4566 case ID_LED_OFF1_OFF2:
4567 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
4568 mac->ledctl_mode1 |= (ledctl_off << shift);
4569 break;
4570 default:
4571
4572 break;
4573 }
4574 switch (temp) {
4575 case ID_LED_DEF1_ON2:
4576 case ID_LED_ON1_ON2:
4577 case ID_LED_OFF1_ON2:
4578 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
4579 mac->ledctl_mode2 |= (ledctl_on << shift);
4580 break;
4581 case ID_LED_DEF1_OFF2:
4582 case ID_LED_ON1_OFF2:
4583 case ID_LED_OFF1_OFF2:
4584 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
4585 mac->ledctl_mode2 |= (ledctl_off << shift);
4586 break;
4587 default:
4588
4589 break;
4590 }
4591 }
4592
4593 return 0;
4594}
4595
4596
4597
4598
4599
4600
4601
4602
4603static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
4604{
4605 struct e1000_bus_info *bus = &hw->bus;
4606 s32 ret_val;
4607
4608 ret_val = e1000e_get_bus_info_pcie(hw);
4609
4610
4611
4612
4613
4614
4615 if (bus->width == e1000_bus_width_unknown)
4616 bus->width = e1000_bus_width_pcie_x1;
4617
4618 return ret_val;
4619}
4620
4621
4622
4623
4624
4625
4626
4627
4628static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
4629{
4630 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4631 u16 kum_cfg;
4632 u32 ctrl, reg;
4633 s32 ret_val;
4634
4635
4636
4637
4638 ret_val = e1000e_disable_pcie_master(hw);
4639 if (ret_val)
4640 e_dbg("PCI-E Master disable polling has failed.\n");
4641
4642 e_dbg("Masking off all interrupts\n");
4643 ew32(IMC, 0xffffffff);
4644
4645
4646
4647
4648
4649 ew32(RCTL, 0);
4650 ew32(TCTL, E1000_TCTL_PSP);
4651 e1e_flush();
4652
4653 usleep_range(10000, 20000);
4654
4655
4656 if (hw->mac.type == e1000_ich8lan) {
4657
4658 ew32(PBA, E1000_PBA_8K);
4659
4660 ew32(PBS, E1000_PBS_16K);
4661 }
4662
4663 if (hw->mac.type == e1000_pchlan) {
4664
4665 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
4666 if (ret_val)
4667 return ret_val;
4668
4669 if (kum_cfg & E1000_NVM_K1_ENABLE)
4670 dev_spec->nvm_k1_enabled = true;
4671 else
4672 dev_spec->nvm_k1_enabled = false;
4673 }
4674
4675 ctrl = er32(CTRL);
4676
4677 if (!hw->phy.ops.check_reset_block(hw)) {
4678
4679
4680
4681
4682 ctrl |= E1000_CTRL_PHY_RST;
4683
4684
4685
4686
4687 if ((hw->mac.type == e1000_pch2lan) &&
4688 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
4689 e1000_gate_hw_phy_config_ich8lan(hw, true);
4690 }
4691 ret_val = e1000_acquire_swflag_ich8lan(hw);
4692 e_dbg("Issuing a global reset to ich8lan\n");
4693 ew32(CTRL, (ctrl | E1000_CTRL_RST));
4694
4695 msleep(20);
4696
4697
4698 if (hw->mac.type == e1000_pch2lan) {
4699 reg = er32(FEXTNVM3);
4700 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
4701 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
4702 ew32(FEXTNVM3, reg);
4703 }
4704
4705 if (!ret_val)
4706 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
4707
4708 if (ctrl & E1000_CTRL_PHY_RST) {
4709 ret_val = hw->phy.ops.get_cfg_done(hw);
4710 if (ret_val)
4711 return ret_val;
4712
4713 ret_val = e1000_post_phy_reset_ich8lan(hw);
4714 if (ret_val)
4715 return ret_val;
4716 }
4717
4718
4719
4720
4721
4722 if (hw->mac.type == e1000_pchlan)
4723 ew32(CRC_OFFSET, 0x65656565);
4724
4725 ew32(IMC, 0xffffffff);
4726 er32(ICR);
4727
4728 reg = er32(KABGTXD);
4729 reg |= E1000_KABGTXD_BGSQLBIAS;
4730 ew32(KABGTXD, reg);
4731
4732 return 0;
4733}
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
4748{
4749 struct e1000_mac_info *mac = &hw->mac;
4750 u32 ctrl_ext, txdctl, snoop;
4751 s32 ret_val;
4752 u16 i;
4753
4754 e1000_initialize_hw_bits_ich8lan(hw);
4755
4756
4757 ret_val = mac->ops.id_led_init(hw);
4758
4759 if (ret_val)
4760 e_dbg("Error initializing identification LED\n");
4761
4762
4763 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
4764
4765
4766 e_dbg("Zeroing the MTA\n");
4767 for (i = 0; i < mac->mta_reg_count; i++)
4768 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
4769
4770
4771
4772
4773
4774 if (hw->phy.type == e1000_phy_82578) {
4775 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
4776 i &= ~BM_WUC_HOST_WU_BIT;
4777 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
4778 ret_val = e1000_phy_hw_reset_ich8lan(hw);
4779 if (ret_val)
4780 return ret_val;
4781 }
4782
4783
4784 ret_val = mac->ops.setup_link(hw);
4785
4786
4787 txdctl = er32(TXDCTL(0));
4788 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
4789 E1000_TXDCTL_FULL_TX_DESC_WB);
4790 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
4791 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
4792 ew32(TXDCTL(0), txdctl);
4793 txdctl = er32(TXDCTL(1));
4794 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
4795 E1000_TXDCTL_FULL_TX_DESC_WB);
4796 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
4797 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
4798 ew32(TXDCTL(1), txdctl);
4799
4800
4801
4802
4803 if (mac->type == e1000_ich8lan)
4804 snoop = PCIE_ICH8_SNOOP_ALL;
4805 else
4806 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
4807 e1000e_set_pcie_no_snoop(hw, snoop);
4808
4809 ctrl_ext = er32(CTRL_EXT);
4810 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
4811 ew32(CTRL_EXT, ctrl_ext);
4812
4813
4814
4815
4816
4817
4818 e1000_clear_hw_cntrs_ich8lan(hw);
4819
4820 return ret_val;
4821}
4822
4823
4824
4825
4826
4827
4828
4829
4830static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
4831{
4832 u32 reg;
4833
4834
4835 reg = er32(CTRL_EXT);
4836 reg |= BIT(22);
4837
4838 if (hw->mac.type >= e1000_pchlan)
4839 reg |= E1000_CTRL_EXT_PHYPDEN;
4840 ew32(CTRL_EXT, reg);
4841
4842
4843 reg = er32(TXDCTL(0));
4844 reg |= BIT(22);
4845 ew32(TXDCTL(0), reg);
4846
4847
4848 reg = er32(TXDCTL(1));
4849 reg |= BIT(22);
4850 ew32(TXDCTL(1), reg);
4851
4852
4853 reg = er32(TARC(0));
4854 if (hw->mac.type == e1000_ich8lan)
4855 reg |= BIT(28) | BIT(29);
4856 reg |= BIT(23) | BIT(24) | BIT(26) | BIT(27);
4857 ew32(TARC(0), reg);
4858
4859
4860 reg = er32(TARC(1));
4861 if (er32(TCTL) & E1000_TCTL_MULR)
4862 reg &= ~BIT(28);
4863 else
4864 reg |= BIT(28);
4865 reg |= BIT(24) | BIT(26) | BIT(30);
4866 ew32(TARC(1), reg);
4867
4868
4869 if (hw->mac.type == e1000_ich8lan) {
4870 reg = er32(STATUS);
4871 reg &= ~BIT(31);
4872 ew32(STATUS, reg);
4873 }
4874
4875
4876
4877
4878 reg = er32(RFCTL);
4879 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
4880
4881
4882
4883
4884 if (hw->mac.type == e1000_ich8lan)
4885 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
4886 ew32(RFCTL, reg);
4887
4888
4889 if (hw->mac.type >= e1000_pch_lpt) {
4890 reg = er32(PBECCSTS);
4891 reg |= E1000_PBECCSTS_ECC_ENABLE;
4892 ew32(PBECCSTS, reg);
4893
4894 reg = er32(CTRL);
4895 reg |= E1000_CTRL_MEHE;
4896 ew32(CTRL, reg);
4897 }
4898}
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
4911{
4912 s32 ret_val;
4913
4914 if (hw->phy.ops.check_reset_block(hw))
4915 return 0;
4916
4917
4918
4919
4920
4921 if (hw->fc.requested_mode == e1000_fc_default) {
4922
4923 if (hw->mac.type == e1000_pchlan)
4924 hw->fc.requested_mode = e1000_fc_rx_pause;
4925 else
4926 hw->fc.requested_mode = e1000_fc_full;
4927 }
4928
4929
4930
4931
4932 hw->fc.current_mode = hw->fc.requested_mode;
4933
4934 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
4935
4936
4937 ret_val = hw->mac.ops.setup_physical_interface(hw);
4938 if (ret_val)
4939 return ret_val;
4940
4941 ew32(FCTTV, hw->fc.pause_time);
4942 if ((hw->phy.type == e1000_phy_82578) ||
4943 (hw->phy.type == e1000_phy_82579) ||
4944 (hw->phy.type == e1000_phy_i217) ||
4945 (hw->phy.type == e1000_phy_82577)) {
4946 ew32(FCRTV_PCH, hw->fc.refresh_time);
4947
4948 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
4949 hw->fc.pause_time);
4950 if (ret_val)
4951 return ret_val;
4952 }
4953
4954 return e1000e_set_fc_watermarks(hw);
4955}
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
4966{
4967 u32 ctrl;
4968 s32 ret_val;
4969 u16 reg_data;
4970
4971 ctrl = er32(CTRL);
4972 ctrl |= E1000_CTRL_SLU;
4973 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4974 ew32(CTRL, ctrl);
4975
4976
4977
4978
4979
4980 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
4981 if (ret_val)
4982 return ret_val;
4983 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
4984 ®_data);
4985 if (ret_val)
4986 return ret_val;
4987 reg_data |= 0x3F;
4988 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
4989 reg_data);
4990 if (ret_val)
4991 return ret_val;
4992
4993 switch (hw->phy.type) {
4994 case e1000_phy_igp_3:
4995 ret_val = e1000e_copper_link_setup_igp(hw);
4996 if (ret_val)
4997 return ret_val;
4998 break;
4999 case e1000_phy_bm:
5000 case e1000_phy_82578:
5001 ret_val = e1000e_copper_link_setup_m88(hw);
5002 if (ret_val)
5003 return ret_val;
5004 break;
5005 case e1000_phy_82577:
5006 case e1000_phy_82579:
5007 ret_val = e1000_copper_link_setup_82577(hw);
5008 if (ret_val)
5009 return ret_val;
5010 break;
5011 case e1000_phy_ife:
5012 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, ®_data);
5013 if (ret_val)
5014 return ret_val;
5015
5016 reg_data &= ~IFE_PMC_AUTO_MDIX;
5017
5018 switch (hw->phy.mdix) {
5019 case 1:
5020 reg_data &= ~IFE_PMC_FORCE_MDIX;
5021 break;
5022 case 2:
5023 reg_data |= IFE_PMC_FORCE_MDIX;
5024 break;
5025 case 0:
5026 default:
5027 reg_data |= IFE_PMC_AUTO_MDIX;
5028 break;
5029 }
5030 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
5031 if (ret_val)
5032 return ret_val;
5033 break;
5034 default:
5035 break;
5036 }
5037
5038 return e1000e_setup_copper_link(hw);
5039}
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
5050{
5051 u32 ctrl;
5052 s32 ret_val;
5053
5054 ctrl = er32(CTRL);
5055 ctrl |= E1000_CTRL_SLU;
5056 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
5057 ew32(CTRL, ctrl);
5058
5059 ret_val = e1000_copper_link_setup_82577(hw);
5060 if (ret_val)
5061 return ret_val;
5062
5063 return e1000e_setup_copper_link(hw);
5064}
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
5077 u16 *duplex)
5078{
5079 s32 ret_val;
5080
5081 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
5082 if (ret_val)
5083 return ret_val;
5084
5085 if ((hw->mac.type == e1000_ich8lan) &&
5086 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
5087 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
5088 }
5089
5090 return ret_val;
5091}
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
5109{
5110 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
5111 u32 phy_ctrl;
5112 s32 ret_val;
5113 u16 i, data;
5114 bool link;
5115
5116 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
5117 return 0;
5118
5119
5120
5121
5122
5123 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
5124 if (!link)
5125 return 0;
5126
5127 for (i = 0; i < 10; i++) {
5128
5129 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
5130 if (ret_val)
5131 return ret_val;
5132
5133 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
5134 if (ret_val)
5135 return ret_val;
5136
5137
5138 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
5139 return 0;
5140
5141
5142 e1000_phy_hw_reset(hw);
5143 mdelay(5);
5144 }
5145
5146 phy_ctrl = er32(PHY_CTRL);
5147 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
5148 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
5149 ew32(PHY_CTRL, phy_ctrl);
5150
5151
5152
5153
5154 e1000e_gig_downshift_workaround_ich8lan(hw);
5155
5156
5157 return -E1000_ERR_PHY;
5158}
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
5169 bool state)
5170{
5171 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
5172
5173 if (hw->mac.type != e1000_ich8lan) {
5174 e_dbg("Workaround applies to ICH8 only.\n");
5175 return;
5176 }
5177
5178 dev_spec->kmrn_lock_loss_workaround_enabled = state;
5179}
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
5192{
5193 u32 reg;
5194 u16 data;
5195 u8 retry = 0;
5196
5197 if (hw->phy.type != e1000_phy_igp_3)
5198 return;
5199
5200
5201 do {
5202
5203 reg = er32(PHY_CTRL);
5204 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
5205 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
5206 ew32(PHY_CTRL, reg);
5207
5208
5209
5210
5211 if (hw->mac.type == e1000_ich8lan)
5212 e1000e_gig_downshift_workaround_ich8lan(hw);
5213
5214
5215 e1e_rphy(hw, IGP3_VR_CTRL, &data);
5216 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
5217 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
5218
5219
5220 e1e_rphy(hw, IGP3_VR_CTRL, &data);
5221 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
5222 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
5223 break;
5224
5225
5226 reg = er32(CTRL);
5227 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
5228 retry++;
5229 } while (retry);
5230}
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
5243{
5244 s32 ret_val;
5245 u16 reg_data;
5246
5247 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
5248 return;
5249
5250 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
5251 ®_data);
5252 if (ret_val)
5253 return;
5254 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
5255 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
5256 reg_data);
5257 if (ret_val)
5258 return;
5259 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
5260 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
5261}
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
5278{
5279 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
5280 u32 phy_ctrl;
5281 s32 ret_val;
5282
5283 phy_ctrl = er32(PHY_CTRL);
5284 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
5285
5286 if (hw->phy.type == e1000_phy_i217) {
5287 u16 phy_reg, device_id = hw->adapter->pdev->device;
5288
5289 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
5290 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
5291 (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
5292 (device_id == E1000_DEV_ID_PCH_I218_V3) ||
5293 (hw->mac.type >= e1000_pch_spt)) {
5294 u32 fextnvm6 = er32(FEXTNVM6);
5295
5296 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
5297 }
5298
5299 ret_val = hw->phy.ops.acquire(hw);
5300 if (ret_val)
5301 goto out;
5302
5303 if (!dev_spec->eee_disable) {
5304 u16 eee_advert;
5305
5306 ret_val =
5307 e1000_read_emi_reg_locked(hw,
5308 I217_EEE_ADVERTISEMENT,
5309 &eee_advert);
5310 if (ret_val)
5311 goto release;
5312
5313
5314
5315
5316
5317
5318 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
5319 (dev_spec->eee_lp_ability &
5320 I82579_EEE_100_SUPPORTED) &&
5321 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL)) {
5322 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
5323 E1000_PHY_CTRL_NOND0A_LPLU);
5324
5325
5326 e1e_rphy_locked(hw,
5327 I217_LPI_GPIO_CTRL, &phy_reg);
5328 phy_reg |= I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
5329 e1e_wphy_locked(hw,
5330 I217_LPI_GPIO_CTRL, phy_reg);
5331 }
5332 }
5333
5334
5335
5336
5337
5338
5339
5340
5341 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
5342
5343 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
5344 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
5345 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
5346
5347
5348
5349
5350 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
5351 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
5352 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
5353
5354
5355 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
5356 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
5357 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
5358 }
5359
5360
5361
5362
5363 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
5364 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
5365 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
5366
5367release:
5368 hw->phy.ops.release(hw);
5369 }
5370out:
5371 ew32(PHY_CTRL, phy_ctrl);
5372
5373 if (hw->mac.type == e1000_ich8lan)
5374 e1000e_gig_downshift_workaround_ich8lan(hw);
5375
5376 if (hw->mac.type >= e1000_pchlan) {
5377 e1000_oem_bits_config_ich8lan(hw, false);
5378
5379
5380 if (hw->mac.type == e1000_pchlan)
5381 e1000e_phy_hw_reset_generic(hw);
5382
5383 ret_val = hw->phy.ops.acquire(hw);
5384 if (ret_val)
5385 return;
5386 e1000_write_smbus_addr(hw);
5387 hw->phy.ops.release(hw);
5388 }
5389}
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
5402{
5403 s32 ret_val;
5404
5405 if (hw->mac.type < e1000_pch2lan)
5406 return;
5407
5408 ret_val = e1000_init_phy_workarounds_pchlan(hw);
5409 if (ret_val) {
5410 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
5411 return;
5412 }
5413
5414
5415
5416
5417
5418
5419 if (hw->phy.type == e1000_phy_i217) {
5420 u16 phy_reg;
5421
5422 ret_val = hw->phy.ops.acquire(hw);
5423 if (ret_val) {
5424 e_dbg("Failed to setup iRST\n");
5425 return;
5426 }
5427
5428
5429 e1e_rphy_locked(hw, I217_LPI_GPIO_CTRL, &phy_reg);
5430 phy_reg &= ~I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
5431 e1e_wphy_locked(hw, I217_LPI_GPIO_CTRL, phy_reg);
5432
5433 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
5434
5435
5436
5437 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
5438 if (ret_val)
5439 goto release;
5440 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
5441 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
5442
5443
5444 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
5445 }
5446
5447 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
5448 if (ret_val)
5449 goto release;
5450 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
5451 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
5452release:
5453 if (ret_val)
5454 e_dbg("Error %d in resume workarounds\n", ret_val);
5455 hw->phy.ops.release(hw);
5456 }
5457}
5458
5459
5460
5461
5462
5463
5464
5465static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
5466{
5467 if (hw->phy.type == e1000_phy_ife)
5468 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
5469
5470 ew32(LEDCTL, hw->mac.ledctl_default);
5471 return 0;
5472}
5473
5474
5475
5476
5477
5478
5479
5480static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
5481{
5482 if (hw->phy.type == e1000_phy_ife)
5483 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
5484 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
5485
5486 ew32(LEDCTL, hw->mac.ledctl_mode2);
5487 return 0;
5488}
5489
5490
5491
5492
5493
5494
5495
5496static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
5497{
5498 if (hw->phy.type == e1000_phy_ife)
5499 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
5500 (IFE_PSCL_PROBE_MODE |
5501 IFE_PSCL_PROBE_LEDS_OFF));
5502
5503 ew32(LEDCTL, hw->mac.ledctl_mode1);
5504 return 0;
5505}
5506
5507
5508
5509
5510
5511
5512
5513static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
5514{
5515 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
5516}
5517
5518
5519
5520
5521
5522
5523
5524static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
5525{
5526 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
5527}
5528
5529
5530
5531
5532
5533
5534
5535static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
5536{
5537 u16 data = (u16)hw->mac.ledctl_mode2;
5538 u32 i, led;
5539
5540
5541
5542
5543 if (!(er32(STATUS) & E1000_STATUS_LU)) {
5544 for (i = 0; i < 3; i++) {
5545 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
5546 if ((led & E1000_PHY_LED0_MODE_MASK) !=
5547 E1000_LEDCTL_MODE_LINK_UP)
5548 continue;
5549 if (led & E1000_PHY_LED0_IVRT)
5550 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
5551 else
5552 data |= (E1000_PHY_LED0_IVRT << (i * 5));
5553 }
5554 }
5555
5556 return e1e_wphy(hw, HV_LED_CONFIG, data);
5557}
5558
5559
5560
5561
5562
5563
5564
5565static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
5566{
5567 u16 data = (u16)hw->mac.ledctl_mode1;
5568 u32 i, led;
5569
5570
5571
5572
5573 if (!(er32(STATUS) & E1000_STATUS_LU)) {
5574 for (i = 0; i < 3; i++) {
5575 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
5576 if ((led & E1000_PHY_LED0_MODE_MASK) !=
5577 E1000_LEDCTL_MODE_LINK_UP)
5578 continue;
5579 if (led & E1000_PHY_LED0_IVRT)
5580 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
5581 else
5582 data |= (E1000_PHY_LED0_IVRT << (i * 5));
5583 }
5584 }
5585
5586 return e1e_wphy(hw, HV_LED_CONFIG, data);
5587}
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
5602{
5603 s32 ret_val = 0;
5604 u32 bank = 0;
5605 u32 status;
5606
5607 e1000e_get_cfg_done_generic(hw);
5608
5609
5610 if (hw->mac.type >= e1000_ich10lan) {
5611 e1000_lan_init_done_ich8lan(hw);
5612 } else {
5613 ret_val = e1000e_get_auto_rd_done(hw);
5614 if (ret_val) {
5615
5616
5617
5618
5619 e_dbg("Auto Read Done did not complete\n");
5620 ret_val = 0;
5621 }
5622 }
5623
5624
5625 status = er32(STATUS);
5626 if (status & E1000_STATUS_PHYRA)
5627 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
5628 else
5629 e_dbg("PHY Reset Asserted not set - needs delay\n");
5630
5631
5632 if (hw->mac.type <= e1000_ich9lan) {
5633 if (!(er32(EECD) & E1000_EECD_PRES) &&
5634 (hw->phy.type == e1000_phy_igp_3)) {
5635 e1000e_phy_init_script_igp3(hw);
5636 }
5637 } else {
5638 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
5639
5640 e_dbg("EEPROM not present\n");
5641 ret_val = -E1000_ERR_CONFIG;
5642 }
5643 }
5644
5645 return ret_val;
5646}
5647
5648
5649
5650
5651
5652
5653
5654
5655static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
5656{
5657
5658 if (!(hw->mac.ops.check_mng_mode(hw) ||
5659 hw->phy.ops.check_reset_block(hw)))
5660 e1000_power_down_phy_copper(hw);
5661}
5662
5663
5664
5665
5666
5667
5668
5669
5670static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
5671{
5672 u16 phy_data;
5673 s32 ret_val;
5674
5675 e1000e_clear_hw_cntrs_base(hw);
5676
5677 er32(ALGNERRC);
5678 er32(RXERRC);
5679 er32(TNCRS);
5680 er32(CEXTERR);
5681 er32(TSCTC);
5682 er32(TSCTFC);
5683
5684 er32(MGTPRC);
5685 er32(MGTPDC);
5686 er32(MGTPTC);
5687
5688 er32(IAC);
5689 er32(ICRXOC);
5690
5691
5692 if ((hw->phy.type == e1000_phy_82578) ||
5693 (hw->phy.type == e1000_phy_82579) ||
5694 (hw->phy.type == e1000_phy_i217) ||
5695 (hw->phy.type == e1000_phy_82577)) {
5696 ret_val = hw->phy.ops.acquire(hw);
5697 if (ret_val)
5698 return;
5699 ret_val = hw->phy.ops.set_page(hw,
5700 HV_STATS_PAGE << IGP_PAGE_SHIFT);
5701 if (ret_val)
5702 goto release;
5703 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
5704 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
5705 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
5706 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
5707 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
5708 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
5709 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
5710 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
5711 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
5712 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
5713 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
5714 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
5715 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
5716 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
5717release:
5718 hw->phy.ops.release(hw);
5719 }
5720}
5721
5722static const struct e1000_mac_operations ich8_mac_ops = {
5723
5724 .check_for_link = e1000_check_for_copper_link_ich8lan,
5725
5726 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
5727 .get_bus_info = e1000_get_bus_info_ich8lan,
5728 .set_lan_id = e1000_set_lan_id_single_port,
5729 .get_link_up_info = e1000_get_link_up_info_ich8lan,
5730
5731
5732 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
5733 .reset_hw = e1000_reset_hw_ich8lan,
5734 .init_hw = e1000_init_hw_ich8lan,
5735 .setup_link = e1000_setup_link_ich8lan,
5736 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
5737
5738 .config_collision_dist = e1000e_config_collision_dist_generic,
5739 .rar_set = e1000e_rar_set_generic,
5740 .rar_get_count = e1000e_rar_get_count_generic,
5741};
5742
5743static const struct e1000_phy_operations ich8_phy_ops = {
5744 .acquire = e1000_acquire_swflag_ich8lan,
5745 .check_reset_block = e1000_check_reset_block_ich8lan,
5746 .commit = NULL,
5747 .get_cfg_done = e1000_get_cfg_done_ich8lan,
5748 .get_cable_length = e1000e_get_cable_length_igp_2,
5749 .read_reg = e1000e_read_phy_reg_igp,
5750 .release = e1000_release_swflag_ich8lan,
5751 .reset = e1000_phy_hw_reset_ich8lan,
5752 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
5753 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
5754 .write_reg = e1000e_write_phy_reg_igp,
5755};
5756
5757static const struct e1000_nvm_operations ich8_nvm_ops = {
5758 .acquire = e1000_acquire_nvm_ich8lan,
5759 .read = e1000_read_nvm_ich8lan,
5760 .release = e1000_release_nvm_ich8lan,
5761 .reload = e1000e_reload_nvm_generic,
5762 .update = e1000_update_nvm_checksum_ich8lan,
5763 .valid_led_default = e1000_valid_led_default_ich8lan,
5764 .validate = e1000_validate_nvm_checksum_ich8lan,
5765 .write = e1000_write_nvm_ich8lan,
5766};
5767
5768static const struct e1000_nvm_operations spt_nvm_ops = {
5769 .acquire = e1000_acquire_nvm_ich8lan,
5770 .release = e1000_release_nvm_ich8lan,
5771 .read = e1000_read_nvm_spt,
5772 .update = e1000_update_nvm_checksum_spt,
5773 .reload = e1000e_reload_nvm_generic,
5774 .valid_led_default = e1000_valid_led_default_ich8lan,
5775 .validate = e1000_validate_nvm_checksum_ich8lan,
5776 .write = e1000_write_nvm_ich8lan,
5777};
5778
5779const struct e1000_info e1000_ich8_info = {
5780 .mac = e1000_ich8lan,
5781 .flags = FLAG_HAS_WOL
5782 | FLAG_IS_ICH
5783 | FLAG_HAS_CTRLEXT_ON_LOAD
5784 | FLAG_HAS_AMT
5785 | FLAG_HAS_FLASH
5786 | FLAG_APME_IN_WUC,
5787 .pba = 8,
5788 .max_hw_frame_size = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN,
5789 .get_variants = e1000_get_variants_ich8lan,
5790 .mac_ops = &ich8_mac_ops,
5791 .phy_ops = &ich8_phy_ops,
5792 .nvm_ops = &ich8_nvm_ops,
5793};
5794
5795const struct e1000_info e1000_ich9_info = {
5796 .mac = e1000_ich9lan,
5797 .flags = FLAG_HAS_JUMBO_FRAMES
5798 | FLAG_IS_ICH
5799 | FLAG_HAS_WOL
5800 | FLAG_HAS_CTRLEXT_ON_LOAD
5801 | FLAG_HAS_AMT
5802 | FLAG_HAS_FLASH
5803 | FLAG_APME_IN_WUC,
5804 .pba = 18,
5805 .max_hw_frame_size = DEFAULT_JUMBO,
5806 .get_variants = e1000_get_variants_ich8lan,
5807 .mac_ops = &ich8_mac_ops,
5808 .phy_ops = &ich8_phy_ops,
5809 .nvm_ops = &ich8_nvm_ops,
5810};
5811
5812const struct e1000_info e1000_ich10_info = {
5813 .mac = e1000_ich10lan,
5814 .flags = FLAG_HAS_JUMBO_FRAMES
5815 | FLAG_IS_ICH
5816 | FLAG_HAS_WOL
5817 | FLAG_HAS_CTRLEXT_ON_LOAD
5818 | FLAG_HAS_AMT
5819 | FLAG_HAS_FLASH
5820 | FLAG_APME_IN_WUC,
5821 .pba = 18,
5822 .max_hw_frame_size = DEFAULT_JUMBO,
5823 .get_variants = e1000_get_variants_ich8lan,
5824 .mac_ops = &ich8_mac_ops,
5825 .phy_ops = &ich8_phy_ops,
5826 .nvm_ops = &ich8_nvm_ops,
5827};
5828
5829const struct e1000_info e1000_pch_info = {
5830 .mac = e1000_pchlan,
5831 .flags = FLAG_IS_ICH
5832 | FLAG_HAS_WOL
5833 | FLAG_HAS_CTRLEXT_ON_LOAD
5834 | FLAG_HAS_AMT
5835 | FLAG_HAS_FLASH
5836 | FLAG_HAS_JUMBO_FRAMES
5837 | FLAG_DISABLE_FC_PAUSE_TIME
5838 | FLAG_APME_IN_WUC,
5839 .flags2 = FLAG2_HAS_PHY_STATS,
5840 .pba = 26,
5841 .max_hw_frame_size = 4096,
5842 .get_variants = e1000_get_variants_ich8lan,
5843 .mac_ops = &ich8_mac_ops,
5844 .phy_ops = &ich8_phy_ops,
5845 .nvm_ops = &ich8_nvm_ops,
5846};
5847
5848const struct e1000_info e1000_pch2_info = {
5849 .mac = e1000_pch2lan,
5850 .flags = FLAG_IS_ICH
5851 | FLAG_HAS_WOL
5852 | FLAG_HAS_HW_TIMESTAMP
5853 | FLAG_HAS_CTRLEXT_ON_LOAD
5854 | FLAG_HAS_AMT
5855 | FLAG_HAS_FLASH
5856 | FLAG_HAS_JUMBO_FRAMES
5857 | FLAG_APME_IN_WUC,
5858 .flags2 = FLAG2_HAS_PHY_STATS
5859 | FLAG2_HAS_EEE
5860 | FLAG2_CHECK_SYSTIM_OVERFLOW,
5861 .pba = 26,
5862 .max_hw_frame_size = 9022,
5863 .get_variants = e1000_get_variants_ich8lan,
5864 .mac_ops = &ich8_mac_ops,
5865 .phy_ops = &ich8_phy_ops,
5866 .nvm_ops = &ich8_nvm_ops,
5867};
5868
5869const struct e1000_info e1000_pch_lpt_info = {
5870 .mac = e1000_pch_lpt,
5871 .flags = FLAG_IS_ICH
5872 | FLAG_HAS_WOL
5873 | FLAG_HAS_HW_TIMESTAMP
5874 | FLAG_HAS_CTRLEXT_ON_LOAD
5875 | FLAG_HAS_AMT
5876 | FLAG_HAS_FLASH
5877 | FLAG_HAS_JUMBO_FRAMES
5878 | FLAG_APME_IN_WUC,
5879 .flags2 = FLAG2_HAS_PHY_STATS
5880 | FLAG2_HAS_EEE
5881 | FLAG2_CHECK_SYSTIM_OVERFLOW,
5882 .pba = 26,
5883 .max_hw_frame_size = 9022,
5884 .get_variants = e1000_get_variants_ich8lan,
5885 .mac_ops = &ich8_mac_ops,
5886 .phy_ops = &ich8_phy_ops,
5887 .nvm_ops = &ich8_nvm_ops,
5888};
5889
5890const struct e1000_info e1000_pch_spt_info = {
5891 .mac = e1000_pch_spt,
5892 .flags = FLAG_IS_ICH
5893 | FLAG_HAS_WOL
5894 | FLAG_HAS_HW_TIMESTAMP
5895 | FLAG_HAS_CTRLEXT_ON_LOAD
5896 | FLAG_HAS_AMT
5897 | FLAG_HAS_FLASH
5898 | FLAG_HAS_JUMBO_FRAMES
5899 | FLAG_APME_IN_WUC,
5900 .flags2 = FLAG2_HAS_PHY_STATS
5901 | FLAG2_HAS_EEE,
5902 .pba = 26,
5903 .max_hw_frame_size = 9022,
5904 .get_variants = e1000_get_variants_ich8lan,
5905 .mac_ops = &ich8_mac_ops,
5906 .phy_ops = &ich8_phy_ops,
5907 .nvm_ops = &spt_nvm_ops,
5908};
5909
5910const struct e1000_info e1000_pch_cnp_info = {
5911 .mac = e1000_pch_cnp,
5912 .flags = FLAG_IS_ICH
5913 | FLAG_HAS_WOL
5914 | FLAG_HAS_HW_TIMESTAMP
5915 | FLAG_HAS_CTRLEXT_ON_LOAD
5916 | FLAG_HAS_AMT
5917 | FLAG_HAS_FLASH
5918 | FLAG_HAS_JUMBO_FRAMES
5919 | FLAG_APME_IN_WUC,
5920 .flags2 = FLAG2_HAS_PHY_STATS
5921 | FLAG2_HAS_EEE,
5922 .pba = 26,
5923 .max_hw_frame_size = 9022,
5924 .get_variants = e1000_get_variants_ich8lan,
5925 .mac_ops = &ich8_mac_ops,
5926 .phy_ops = &ich8_phy_ops,
5927 .nvm_ops = &spt_nvm_ops,
5928};
5929