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#include <linux/if_ether.h>
29#include <linux/delay.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33
34#include "e1000_mac.h"
35
36#include "igb.h"
37
38static s32 igb_set_default_fc(struct e1000_hw *hw);
39static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
40
41
42
43
44
45
46
47
48
49s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
50{
51 struct e1000_bus_info *bus = &hw->bus;
52 s32 ret_val;
53 u32 reg;
54 u16 pcie_link_status;
55
56 bus->type = e1000_bus_type_pci_express;
57
58 ret_val = igb_read_pcie_cap_reg(hw,
59 PCI_EXP_LNKSTA,
60 &pcie_link_status);
61 if (ret_val) {
62 bus->width = e1000_bus_width_unknown;
63 bus->speed = e1000_bus_speed_unknown;
64 } else {
65 switch (pcie_link_status & PCI_EXP_LNKSTA_CLS) {
66 case PCI_EXP_LNKSTA_CLS_2_5GB:
67 bus->speed = e1000_bus_speed_2500;
68 break;
69 case PCI_EXP_LNKSTA_CLS_5_0GB:
70 bus->speed = e1000_bus_speed_5000;
71 break;
72 default:
73 bus->speed = e1000_bus_speed_unknown;
74 break;
75 }
76
77 bus->width = (enum e1000_bus_width)((pcie_link_status &
78 PCI_EXP_LNKSTA_NLW) >>
79 PCI_EXP_LNKSTA_NLW_SHIFT);
80 }
81
82 reg = rd32(E1000_STATUS);
83 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
84
85 return 0;
86}
87
88
89
90
91
92
93
94
95void igb_clear_vfta(struct e1000_hw *hw)
96{
97 u32 offset;
98
99 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
100 array_wr32(E1000_VFTA, offset, 0);
101 wrfl();
102 }
103}
104
105
106
107
108
109
110
111
112
113
114static void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
115{
116 array_wr32(E1000_VFTA, offset, value);
117 wrfl();
118}
119
120
121
122
123
124
125
126
127
128
129
130
131
132void igb_clear_vfta_i350(struct e1000_hw *hw)
133{
134 u32 offset;
135 int i;
136
137 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
138 for (i = 0; i < 10; i++)
139 array_wr32(E1000_VFTA, offset, 0);
140
141 wrfl();
142 }
143}
144
145
146
147
148
149
150
151
152
153
154static void igb_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
155{
156 int i;
157
158 for (i = 0; i < 10; i++)
159 array_wr32(E1000_VFTA, offset, value);
160
161 wrfl();
162}
163
164
165
166
167
168
169
170
171
172
173void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
174{
175 u32 i;
176 u8 mac_addr[ETH_ALEN] = {0};
177
178
179 hw_dbg("Programming MAC Address into RAR[0]\n");
180
181 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
182
183
184 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
185 for (i = 1; i < rar_count; i++)
186 hw->mac.ops.rar_set(hw, mac_addr, i);
187}
188
189
190
191
192
193
194
195
196
197
198s32 igb_vfta_set(struct e1000_hw *hw, u32 vid, bool add)
199{
200 u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
201 u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
202 u32 vfta;
203 struct igb_adapter *adapter = hw->back;
204 s32 ret_val = 0;
205
206 vfta = adapter->shadow_vfta[index];
207
208
209 if ((!!(vfta & mask)) == add) {
210 ret_val = -E1000_ERR_CONFIG;
211 } else {
212 if (add)
213 vfta |= mask;
214 else
215 vfta &= ~mask;
216 }
217 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
218 igb_write_vfta_i350(hw, index, vfta);
219 else
220 igb_write_vfta(hw, index, vfta);
221 adapter->shadow_vfta[index] = vfta;
222
223 return ret_val;
224}
225
226
227
228
229
230
231
232
233
234
235
236
237s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
238{
239 u32 i;
240 s32 ret_val = 0;
241 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
242 u8 alt_mac_addr[ETH_ALEN];
243
244
245
246
247 if (hw->mac.type >= e1000_82580)
248 goto out;
249
250 ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
251 &nvm_alt_mac_addr_offset);
252 if (ret_val) {
253 hw_dbg("NVM Read Error\n");
254 goto out;
255 }
256
257 if ((nvm_alt_mac_addr_offset == 0xFFFF) ||
258 (nvm_alt_mac_addr_offset == 0x0000))
259
260 goto out;
261
262 if (hw->bus.func == E1000_FUNC_1)
263 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
264 if (hw->bus.func == E1000_FUNC_2)
265 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN2;
266
267 if (hw->bus.func == E1000_FUNC_3)
268 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN3;
269 for (i = 0; i < ETH_ALEN; i += 2) {
270 offset = nvm_alt_mac_addr_offset + (i >> 1);
271 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
272 if (ret_val) {
273 hw_dbg("NVM Read Error\n");
274 goto out;
275 }
276
277 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
278 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
279 }
280
281
282 if (is_multicast_ether_addr(alt_mac_addr)) {
283 hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
284 goto out;
285 }
286
287
288
289
290
291 hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
292
293out:
294 return ret_val;
295}
296
297
298
299
300
301
302
303
304
305
306void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
307{
308 u32 rar_low, rar_high;
309
310
311
312
313 rar_low = ((u32) addr[0] |
314 ((u32) addr[1] << 8) |
315 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
316
317 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
318
319
320 if (rar_low || rar_high)
321 rar_high |= E1000_RAH_AV;
322
323
324
325
326
327 wr32(E1000_RAL(index), rar_low);
328 wrfl();
329 wr32(E1000_RAH(index), rar_high);
330 wrfl();
331}
332
333
334
335
336
337
338
339
340
341
342
343void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
344{
345 u32 hash_bit, hash_reg, mta;
346
347
348
349
350
351
352
353
354
355
356 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
357 hash_bit = hash_value & 0x1F;
358
359 mta = array_rd32(E1000_MTA, hash_reg);
360
361 mta |= (1 << hash_bit);
362
363 array_wr32(E1000_MTA, hash_reg, mta);
364 wrfl();
365}
366
367
368
369
370
371
372
373
374
375
376static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
377{
378 u32 hash_value, hash_mask;
379 u8 bit_shift = 0;
380
381
382 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
383
384
385
386
387 while (hash_mask >> bit_shift != 0xFF)
388 bit_shift++;
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415 switch (hw->mac.mc_filter_type) {
416 default:
417 case 0:
418 break;
419 case 1:
420 bit_shift += 1;
421 break;
422 case 2:
423 bit_shift += 2;
424 break;
425 case 3:
426 bit_shift += 4;
427 break;
428 }
429
430 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
431 (((u16) mc_addr[5]) << bit_shift)));
432
433 return hash_value;
434}
435
436
437
438
439
440
441
442
443
444
445void igb_update_mc_addr_list(struct e1000_hw *hw,
446 u8 *mc_addr_list, u32 mc_addr_count)
447{
448 u32 hash_value, hash_bit, hash_reg;
449 int i;
450
451
452 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
453
454
455 for (i = 0; (u32) i < mc_addr_count; i++) {
456 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
457
458 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
459 hash_bit = hash_value & 0x1F;
460
461 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
462 mc_addr_list += (ETH_ALEN);
463 }
464
465
466 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
467 array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]);
468 wrfl();
469}
470
471
472
473
474
475
476
477void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
478{
479 rd32(E1000_CRCERRS);
480 rd32(E1000_SYMERRS);
481 rd32(E1000_MPC);
482 rd32(E1000_SCC);
483 rd32(E1000_ECOL);
484 rd32(E1000_MCC);
485 rd32(E1000_LATECOL);
486 rd32(E1000_COLC);
487 rd32(E1000_DC);
488 rd32(E1000_SEC);
489 rd32(E1000_RLEC);
490 rd32(E1000_XONRXC);
491 rd32(E1000_XONTXC);
492 rd32(E1000_XOFFRXC);
493 rd32(E1000_XOFFTXC);
494 rd32(E1000_FCRUC);
495 rd32(E1000_GPRC);
496 rd32(E1000_BPRC);
497 rd32(E1000_MPRC);
498 rd32(E1000_GPTC);
499 rd32(E1000_GORCL);
500 rd32(E1000_GORCH);
501 rd32(E1000_GOTCL);
502 rd32(E1000_GOTCH);
503 rd32(E1000_RNBC);
504 rd32(E1000_RUC);
505 rd32(E1000_RFC);
506 rd32(E1000_ROC);
507 rd32(E1000_RJC);
508 rd32(E1000_TORL);
509 rd32(E1000_TORH);
510 rd32(E1000_TOTL);
511 rd32(E1000_TOTH);
512 rd32(E1000_TPR);
513 rd32(E1000_TPT);
514 rd32(E1000_MPTC);
515 rd32(E1000_BPTC);
516}
517
518
519
520
521
522
523
524
525
526s32 igb_check_for_copper_link(struct e1000_hw *hw)
527{
528 struct e1000_mac_info *mac = &hw->mac;
529 s32 ret_val;
530 bool link;
531
532
533
534
535
536
537 if (!mac->get_link_status) {
538 ret_val = 0;
539 goto out;
540 }
541
542
543
544
545
546 ret_val = igb_phy_has_link(hw, 1, 0, &link);
547 if (ret_val)
548 goto out;
549
550 if (!link)
551 goto out;
552
553 mac->get_link_status = false;
554
555
556
557
558 igb_check_downshift(hw);
559
560
561
562
563 if (!mac->autoneg) {
564 ret_val = -E1000_ERR_CONFIG;
565 goto out;
566 }
567
568
569
570
571
572 igb_config_collision_dist(hw);
573
574
575
576
577
578
579 ret_val = igb_config_fc_after_link_up(hw);
580 if (ret_val)
581 hw_dbg("Error configuring flow control\n");
582
583out:
584 return ret_val;
585}
586
587
588
589
590
591
592
593
594
595
596
597s32 igb_setup_link(struct e1000_hw *hw)
598{
599 s32 ret_val = 0;
600
601
602
603
604 if (igb_check_reset_block(hw))
605 goto out;
606
607
608
609
610 if (hw->fc.requested_mode == e1000_fc_default) {
611 ret_val = igb_set_default_fc(hw);
612 if (ret_val)
613 goto out;
614 }
615
616
617
618
619
620 hw->fc.current_mode = hw->fc.requested_mode;
621
622 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
623
624
625 ret_val = hw->mac.ops.setup_physical_interface(hw);
626 if (ret_val)
627 goto out;
628
629
630
631
632
633
634 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
635 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
636 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
637 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
638
639 wr32(E1000_FCTTV, hw->fc.pause_time);
640
641 ret_val = igb_set_fc_watermarks(hw);
642
643out:
644
645 return ret_val;
646}
647
648
649
650
651
652
653
654
655
656void igb_config_collision_dist(struct e1000_hw *hw)
657{
658 u32 tctl;
659
660 tctl = rd32(E1000_TCTL);
661
662 tctl &= ~E1000_TCTL_COLD;
663 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
664
665 wr32(E1000_TCTL, tctl);
666 wrfl();
667}
668
669
670
671
672
673
674
675
676
677static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
678{
679 s32 ret_val = 0;
680 u32 fcrtl = 0, fcrth = 0;
681
682
683
684
685
686
687
688 if (hw->fc.current_mode & e1000_fc_tx_pause) {
689
690
691
692
693 fcrtl = hw->fc.low_water;
694 if (hw->fc.send_xon)
695 fcrtl |= E1000_FCRTL_XONE;
696
697 fcrth = hw->fc.high_water;
698 }
699 wr32(E1000_FCRTL, fcrtl);
700 wr32(E1000_FCRTH, fcrth);
701
702 return ret_val;
703}
704
705
706
707
708
709
710
711
712static s32 igb_set_default_fc(struct e1000_hw *hw)
713{
714 s32 ret_val = 0;
715 u16 lan_offset;
716 u16 nvm_data;
717
718
719
720
721
722
723
724
725
726 if (hw->mac.type == e1000_i350) {
727 lan_offset = NVM_82580_LAN_FUNC_OFFSET(hw->bus.func);
728 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG
729 + lan_offset, 1, &nvm_data);
730 } else {
731 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG,
732 1, &nvm_data);
733 }
734
735 if (ret_val) {
736 hw_dbg("NVM Read Error\n");
737 goto out;
738 }
739
740 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
741 hw->fc.requested_mode = e1000_fc_none;
742 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
743 NVM_WORD0F_ASM_DIR)
744 hw->fc.requested_mode = e1000_fc_tx_pause;
745 else
746 hw->fc.requested_mode = e1000_fc_full;
747
748out:
749 return ret_val;
750}
751
752
753
754
755
756
757
758
759
760
761
762s32 igb_force_mac_fc(struct e1000_hw *hw)
763{
764 u32 ctrl;
765 s32 ret_val = 0;
766
767 ctrl = rd32(E1000_CTRL);
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786 hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
787
788 switch (hw->fc.current_mode) {
789 case e1000_fc_none:
790 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
791 break;
792 case e1000_fc_rx_pause:
793 ctrl &= (~E1000_CTRL_TFCE);
794 ctrl |= E1000_CTRL_RFCE;
795 break;
796 case e1000_fc_tx_pause:
797 ctrl &= (~E1000_CTRL_RFCE);
798 ctrl |= E1000_CTRL_TFCE;
799 break;
800 case e1000_fc_full:
801 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
802 break;
803 default:
804 hw_dbg("Flow control param set incorrectly\n");
805 ret_val = -E1000_ERR_CONFIG;
806 goto out;
807 }
808
809 wr32(E1000_CTRL, ctrl);
810
811out:
812 return ret_val;
813}
814
815
816
817
818
819
820
821
822
823
824
825s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
826{
827 struct e1000_mac_info *mac = &hw->mac;
828 s32 ret_val = 0;
829 u32 pcs_status_reg, pcs_adv_reg, pcs_lp_ability_reg, pcs_ctrl_reg;
830 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
831 u16 speed, duplex;
832
833
834
835
836
837 if (mac->autoneg_failed) {
838 if (hw->phy.media_type == e1000_media_type_internal_serdes)
839 ret_val = igb_force_mac_fc(hw);
840 } else {
841 if (hw->phy.media_type == e1000_media_type_copper)
842 ret_val = igb_force_mac_fc(hw);
843 }
844
845 if (ret_val) {
846 hw_dbg("Error forcing flow control settings\n");
847 goto out;
848 }
849
850
851
852
853
854
855 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
856
857
858
859
860 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
861 &mii_status_reg);
862 if (ret_val)
863 goto out;
864 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
865 &mii_status_reg);
866 if (ret_val)
867 goto out;
868
869 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
870 hw_dbg("Copper PHY and Auto Neg "
871 "has not completed.\n");
872 goto out;
873 }
874
875
876
877
878
879
880
881 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
882 &mii_nway_adv_reg);
883 if (ret_val)
884 goto out;
885 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
886 &mii_nway_lp_ability_reg);
887 if (ret_val)
888 goto out;
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
924 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
925
926
927
928
929
930
931 if (hw->fc.requested_mode == e1000_fc_full) {
932 hw->fc.current_mode = e1000_fc_full;
933 hw_dbg("Flow Control = FULL.\r\n");
934 } else {
935 hw->fc.current_mode = e1000_fc_rx_pause;
936 hw_dbg("Flow Control = "
937 "RX PAUSE frames only.\r\n");
938 }
939 }
940
941
942
943
944
945
946
947 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
948 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
949 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
950 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
951 hw->fc.current_mode = e1000_fc_tx_pause;
952 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
953 }
954
955
956
957
958
959
960
961 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
962 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
963 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
964 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
965 hw->fc.current_mode = e1000_fc_rx_pause;
966 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
967 }
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988 else if ((hw->fc.requested_mode == e1000_fc_none) ||
989 (hw->fc.requested_mode == e1000_fc_tx_pause) ||
990 (hw->fc.strict_ieee)) {
991 hw->fc.current_mode = e1000_fc_none;
992 hw_dbg("Flow Control = NONE.\r\n");
993 } else {
994 hw->fc.current_mode = e1000_fc_rx_pause;
995 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
996 }
997
998
999
1000
1001
1002 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
1003 if (ret_val) {
1004 hw_dbg("Error getting link speed and duplex\n");
1005 goto out;
1006 }
1007
1008 if (duplex == HALF_DUPLEX)
1009 hw->fc.current_mode = e1000_fc_none;
1010
1011
1012
1013
1014 ret_val = igb_force_mac_fc(hw);
1015 if (ret_val) {
1016 hw_dbg("Error forcing flow control settings\n");
1017 goto out;
1018 }
1019 }
1020
1021
1022
1023
1024
1025 if ((hw->phy.media_type == e1000_media_type_internal_serdes)
1026 && mac->autoneg) {
1027
1028
1029
1030 pcs_status_reg = rd32(E1000_PCS_LSTAT);
1031
1032 if (!(pcs_status_reg & E1000_PCS_LSTS_AN_COMPLETE)) {
1033 hw_dbg("PCS Auto Neg has not completed.\n");
1034 return ret_val;
1035 }
1036
1037
1038
1039
1040
1041
1042
1043 pcs_adv_reg = rd32(E1000_PCS_ANADV);
1044 pcs_lp_ability_reg = rd32(E1000_PCS_LPAB);
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079 if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
1080 (pcs_lp_ability_reg & E1000_TXCW_PAUSE)) {
1081
1082
1083
1084
1085
1086
1087 if (hw->fc.requested_mode == e1000_fc_full) {
1088 hw->fc.current_mode = e1000_fc_full;
1089 hw_dbg("Flow Control = FULL.\n");
1090 } else {
1091 hw->fc.current_mode = e1000_fc_rx_pause;
1092 hw_dbg("Flow Control = Rx PAUSE frames only.\n");
1093 }
1094 }
1095
1096
1097
1098
1099
1100
1101
1102 else if (!(pcs_adv_reg & E1000_TXCW_PAUSE) &&
1103 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
1104 (pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
1105 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
1106 hw->fc.current_mode = e1000_fc_tx_pause;
1107 hw_dbg("Flow Control = Tx PAUSE frames only.\n");
1108 }
1109
1110
1111
1112
1113
1114
1115
1116 else if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
1117 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
1118 !(pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
1119 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
1120 hw->fc.current_mode = e1000_fc_rx_pause;
1121 hw_dbg("Flow Control = Rx PAUSE frames only.\n");
1122 } else {
1123
1124
1125
1126 hw->fc.current_mode = e1000_fc_none;
1127 hw_dbg("Flow Control = NONE.\n");
1128 }
1129
1130
1131
1132
1133 pcs_ctrl_reg = rd32(E1000_PCS_LCTL);
1134 pcs_ctrl_reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1135 wr32(E1000_PCS_LCTL, pcs_ctrl_reg);
1136
1137 ret_val = igb_force_mac_fc(hw);
1138 if (ret_val) {
1139 hw_dbg("Error forcing flow control settings\n");
1140 return ret_val;
1141 }
1142 }
1143
1144out:
1145 return ret_val;
1146}
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
1158 u16 *duplex)
1159{
1160 u32 status;
1161
1162 status = rd32(E1000_STATUS);
1163 if (status & E1000_STATUS_SPEED_1000) {
1164 *speed = SPEED_1000;
1165 hw_dbg("1000 Mbs, ");
1166 } else if (status & E1000_STATUS_SPEED_100) {
1167 *speed = SPEED_100;
1168 hw_dbg("100 Mbs, ");
1169 } else {
1170 *speed = SPEED_10;
1171 hw_dbg("10 Mbs, ");
1172 }
1173
1174 if (status & E1000_STATUS_FD) {
1175 *duplex = FULL_DUPLEX;
1176 hw_dbg("Full Duplex\n");
1177 } else {
1178 *duplex = HALF_DUPLEX;
1179 hw_dbg("Half Duplex\n");
1180 }
1181
1182 return 0;
1183}
1184
1185
1186
1187
1188
1189
1190
1191s32 igb_get_hw_semaphore(struct e1000_hw *hw)
1192{
1193 u32 swsm;
1194 s32 ret_val = 0;
1195 s32 timeout = hw->nvm.word_size + 1;
1196 s32 i = 0;
1197
1198
1199 while (i < timeout) {
1200 swsm = rd32(E1000_SWSM);
1201 if (!(swsm & E1000_SWSM_SMBI))
1202 break;
1203
1204 udelay(50);
1205 i++;
1206 }
1207
1208 if (i == timeout) {
1209 hw_dbg("Driver can't access device - SMBI bit is set.\n");
1210 ret_val = -E1000_ERR_NVM;
1211 goto out;
1212 }
1213
1214
1215 for (i = 0; i < timeout; i++) {
1216 swsm = rd32(E1000_SWSM);
1217 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
1218
1219
1220 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
1221 break;
1222
1223 udelay(50);
1224 }
1225
1226 if (i == timeout) {
1227
1228 igb_put_hw_semaphore(hw);
1229 hw_dbg("Driver can't access the NVM\n");
1230 ret_val = -E1000_ERR_NVM;
1231 goto out;
1232 }
1233
1234out:
1235 return ret_val;
1236}
1237
1238
1239
1240
1241
1242
1243
1244void igb_put_hw_semaphore(struct e1000_hw *hw)
1245{
1246 u32 swsm;
1247
1248 swsm = rd32(E1000_SWSM);
1249
1250 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1251
1252 wr32(E1000_SWSM, swsm);
1253}
1254
1255
1256
1257
1258
1259
1260
1261s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1262{
1263 s32 i = 0;
1264 s32 ret_val = 0;
1265
1266
1267 while (i < AUTO_READ_DONE_TIMEOUT) {
1268 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1269 break;
1270 msleep(1);
1271 i++;
1272 }
1273
1274 if (i == AUTO_READ_DONE_TIMEOUT) {
1275 hw_dbg("Auto read by HW from NVM has not completed.\n");
1276 ret_val = -E1000_ERR_RESET;
1277 goto out;
1278 }
1279
1280out:
1281 return ret_val;
1282}
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1293{
1294 s32 ret_val;
1295
1296 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1297 if (ret_val) {
1298 hw_dbg("NVM Read Error\n");
1299 goto out;
1300 }
1301
1302 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1303 switch(hw->phy.media_type) {
1304 case e1000_media_type_internal_serdes:
1305 *data = ID_LED_DEFAULT_82575_SERDES;
1306 break;
1307 case e1000_media_type_copper:
1308 default:
1309 *data = ID_LED_DEFAULT;
1310 break;
1311 }
1312 }
1313out:
1314 return ret_val;
1315}
1316
1317
1318
1319
1320
1321
1322s32 igb_id_led_init(struct e1000_hw *hw)
1323{
1324 struct e1000_mac_info *mac = &hw->mac;
1325 s32 ret_val;
1326 const u32 ledctl_mask = 0x000000FF;
1327 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1328 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1329 u16 data, i, temp;
1330 const u16 led_mask = 0x0F;
1331
1332
1333 if ((hw->mac.type == e1000_i210) ||
1334 (hw->mac.type == e1000_i211))
1335 ret_val = igb_valid_led_default_i210(hw, &data);
1336 else
1337 ret_val = igb_valid_led_default(hw, &data);
1338
1339 if (ret_val)
1340 goto out;
1341
1342 mac->ledctl_default = rd32(E1000_LEDCTL);
1343 mac->ledctl_mode1 = mac->ledctl_default;
1344 mac->ledctl_mode2 = mac->ledctl_default;
1345
1346 for (i = 0; i < 4; i++) {
1347 temp = (data >> (i << 2)) & led_mask;
1348 switch (temp) {
1349 case ID_LED_ON1_DEF2:
1350 case ID_LED_ON1_ON2:
1351 case ID_LED_ON1_OFF2:
1352 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1353 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1354 break;
1355 case ID_LED_OFF1_DEF2:
1356 case ID_LED_OFF1_ON2:
1357 case ID_LED_OFF1_OFF2:
1358 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1359 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1360 break;
1361 default:
1362
1363 break;
1364 }
1365 switch (temp) {
1366 case ID_LED_DEF1_ON2:
1367 case ID_LED_ON1_ON2:
1368 case ID_LED_OFF1_ON2:
1369 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1370 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1371 break;
1372 case ID_LED_DEF1_OFF2:
1373 case ID_LED_ON1_OFF2:
1374 case ID_LED_OFF1_OFF2:
1375 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1376 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1377 break;
1378 default:
1379
1380 break;
1381 }
1382 }
1383
1384out:
1385 return ret_val;
1386}
1387
1388
1389
1390
1391
1392
1393
1394
1395s32 igb_cleanup_led(struct e1000_hw *hw)
1396{
1397 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1398 return 0;
1399}
1400
1401
1402
1403
1404
1405
1406
1407s32 igb_blink_led(struct e1000_hw *hw)
1408{
1409 u32 ledctl_blink = 0;
1410 u32 i;
1411
1412 if (hw->phy.media_type == e1000_media_type_fiber) {
1413
1414 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1415 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1416 } else {
1417
1418
1419
1420
1421
1422
1423 ledctl_blink = hw->mac.ledctl_mode2;
1424 for (i = 0; i < 32; i += 8) {
1425 u32 mode = (hw->mac.ledctl_mode2 >> i) &
1426 E1000_LEDCTL_LED0_MODE_MASK;
1427 u32 led_default = hw->mac.ledctl_default >> i;
1428
1429 if ((!(led_default & E1000_LEDCTL_LED0_IVRT) &&
1430 (mode == E1000_LEDCTL_MODE_LED_ON)) ||
1431 ((led_default & E1000_LEDCTL_LED0_IVRT) &&
1432 (mode == E1000_LEDCTL_MODE_LED_OFF))) {
1433 ledctl_blink &=
1434 ~(E1000_LEDCTL_LED0_MODE_MASK << i);
1435 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK |
1436 E1000_LEDCTL_MODE_LED_ON) << i;
1437 }
1438 }
1439 }
1440
1441 wr32(E1000_LEDCTL, ledctl_blink);
1442
1443 return 0;
1444}
1445
1446
1447
1448
1449
1450
1451
1452s32 igb_led_off(struct e1000_hw *hw)
1453{
1454 switch (hw->phy.media_type) {
1455 case e1000_media_type_copper:
1456 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1457 break;
1458 default:
1459 break;
1460 }
1461
1462 return 0;
1463}
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476s32 igb_disable_pcie_master(struct e1000_hw *hw)
1477{
1478 u32 ctrl;
1479 s32 timeout = MASTER_DISABLE_TIMEOUT;
1480 s32 ret_val = 0;
1481
1482 if (hw->bus.type != e1000_bus_type_pci_express)
1483 goto out;
1484
1485 ctrl = rd32(E1000_CTRL);
1486 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1487 wr32(E1000_CTRL, ctrl);
1488
1489 while (timeout) {
1490 if (!(rd32(E1000_STATUS) &
1491 E1000_STATUS_GIO_MASTER_ENABLE))
1492 break;
1493 udelay(100);
1494 timeout--;
1495 }
1496
1497 if (!timeout) {
1498 hw_dbg("Master requests are pending.\n");
1499 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1500 goto out;
1501 }
1502
1503out:
1504 return ret_val;
1505}
1506
1507
1508
1509
1510
1511
1512
1513
1514s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1515{
1516 s32 ret_val = 0;
1517
1518
1519 if (hw->mac.type >= e1000_82580)
1520 goto out;
1521
1522 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
1523 hw_dbg("Invalid MDI setting detected\n");
1524 hw->phy.mdix = 1;
1525 ret_val = -E1000_ERR_CONFIG;
1526 goto out;
1527 }
1528
1529out:
1530 return ret_val;
1531}
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1545 u32 offset, u8 data)
1546{
1547 u32 i, regvalue = 0;
1548 s32 ret_val = 0;
1549
1550
1551 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1552 wr32(reg, regvalue);
1553
1554
1555 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1556 udelay(5);
1557 regvalue = rd32(reg);
1558 if (regvalue & E1000_GEN_CTL_READY)
1559 break;
1560 }
1561 if (!(regvalue & E1000_GEN_CTL_READY)) {
1562 hw_dbg("Reg %08x did not indicate ready\n", reg);
1563 ret_val = -E1000_ERR_PHY;
1564 goto out;
1565 }
1566
1567out:
1568 return ret_val;
1569}
1570
1571
1572
1573
1574
1575
1576
1577
1578bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1579{
1580 u32 manc;
1581 u32 fwsm, factps;
1582 bool ret_val = false;
1583
1584 if (!hw->mac.asf_firmware_present)
1585 goto out;
1586
1587 manc = rd32(E1000_MANC);
1588
1589 if (!(manc & E1000_MANC_RCV_TCO_EN))
1590 goto out;
1591
1592 if (hw->mac.arc_subsystem_valid) {
1593 fwsm = rd32(E1000_FWSM);
1594 factps = rd32(E1000_FACTPS);
1595
1596 if (!(factps & E1000_FACTPS_MNGCG) &&
1597 ((fwsm & E1000_FWSM_MODE_MASK) ==
1598 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1599 ret_val = true;
1600 goto out;
1601 }
1602 } else {
1603 if ((manc & E1000_MANC_SMBUS_EN) &&
1604 !(manc & E1000_MANC_ASF_EN)) {
1605 ret_val = true;
1606 goto out;
1607 }
1608 }
1609
1610out:
1611 return ret_val;
1612}
1613