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