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
31#include "e1000_mac.h"
32#include "e1000_phy.h"
33
34static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
35static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
36 u16 *phy_ctrl);
37static s32 igb_wait_autoneg(struct e1000_hw *hw);
38static s32 igb_set_master_slave_mode(struct e1000_hw *hw);
39
40
41static const u16 e1000_m88_cable_length_table[] = {
42 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
43#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
44 (sizeof(e1000_m88_cable_length_table) / \
45 sizeof(e1000_m88_cable_length_table[0]))
46
47static const u16 e1000_igp_2_cable_length_table[] = {
48 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
49 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
50 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
51 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
52 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
53 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
54 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
55 104, 109, 114, 118, 121, 124};
56#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
57 (sizeof(e1000_igp_2_cable_length_table) / \
58 sizeof(e1000_igp_2_cable_length_table[0]))
59
60
61
62
63
64
65
66
67
68s32 igb_check_reset_block(struct e1000_hw *hw)
69{
70 u32 manc;
71
72 manc = rd32(E1000_MANC);
73
74 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0;
75}
76
77
78
79
80
81
82
83
84s32 igb_get_phy_id(struct e1000_hw *hw)
85{
86 struct e1000_phy_info *phy = &hw->phy;
87 s32 ret_val = 0;
88 u16 phy_id;
89
90 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
91 if (ret_val)
92 goto out;
93
94 phy->id = (u32)(phy_id << 16);
95 udelay(20);
96 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
97 if (ret_val)
98 goto out;
99
100 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
101 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
102
103out:
104 return ret_val;
105}
106
107
108
109
110
111
112
113static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
114{
115 s32 ret_val = 0;
116
117 if (!(hw->phy.ops.write_reg))
118 goto out;
119
120 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
121 if (ret_val)
122 goto out;
123
124 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
125
126out:
127 return ret_val;
128}
129
130
131
132
133
134
135
136
137
138
139s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
140{
141 struct e1000_phy_info *phy = &hw->phy;
142 u32 i, mdic = 0;
143 s32 ret_val = 0;
144
145 if (offset > MAX_PHY_REG_ADDRESS) {
146 hw_dbg("PHY Address %d is out of range\n", offset);
147 ret_val = -E1000_ERR_PARAM;
148 goto out;
149 }
150
151
152
153
154
155 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
156 (phy->addr << E1000_MDIC_PHY_SHIFT) |
157 (E1000_MDIC_OP_READ));
158
159 wr32(E1000_MDIC, mdic);
160
161
162
163
164
165 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
166 udelay(50);
167 mdic = rd32(E1000_MDIC);
168 if (mdic & E1000_MDIC_READY)
169 break;
170 }
171 if (!(mdic & E1000_MDIC_READY)) {
172 hw_dbg("MDI Read did not complete\n");
173 ret_val = -E1000_ERR_PHY;
174 goto out;
175 }
176 if (mdic & E1000_MDIC_ERROR) {
177 hw_dbg("MDI Error\n");
178 ret_val = -E1000_ERR_PHY;
179 goto out;
180 }
181 *data = (u16) mdic;
182
183out:
184 return ret_val;
185}
186
187
188
189
190
191
192
193
194
195s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
196{
197 struct e1000_phy_info *phy = &hw->phy;
198 u32 i, mdic = 0;
199 s32 ret_val = 0;
200
201 if (offset > MAX_PHY_REG_ADDRESS) {
202 hw_dbg("PHY Address %d is out of range\n", offset);
203 ret_val = -E1000_ERR_PARAM;
204 goto out;
205 }
206
207
208
209
210
211 mdic = (((u32)data) |
212 (offset << E1000_MDIC_REG_SHIFT) |
213 (phy->addr << E1000_MDIC_PHY_SHIFT) |
214 (E1000_MDIC_OP_WRITE));
215
216 wr32(E1000_MDIC, mdic);
217
218
219
220
221
222 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
223 udelay(50);
224 mdic = rd32(E1000_MDIC);
225 if (mdic & E1000_MDIC_READY)
226 break;
227 }
228 if (!(mdic & E1000_MDIC_READY)) {
229 hw_dbg("MDI Write did not complete\n");
230 ret_val = -E1000_ERR_PHY;
231 goto out;
232 }
233 if (mdic & E1000_MDIC_ERROR) {
234 hw_dbg("MDI Error\n");
235 ret_val = -E1000_ERR_PHY;
236 goto out;
237 }
238
239out:
240 return ret_val;
241}
242
243
244
245
246
247
248
249
250
251
252s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
253{
254 struct e1000_phy_info *phy = &hw->phy;
255 u32 i, i2ccmd = 0;
256
257
258
259
260
261 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
262 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
263 (E1000_I2CCMD_OPCODE_READ));
264
265 wr32(E1000_I2CCMD, i2ccmd);
266
267
268 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
269 udelay(50);
270 i2ccmd = rd32(E1000_I2CCMD);
271 if (i2ccmd & E1000_I2CCMD_READY)
272 break;
273 }
274 if (!(i2ccmd & E1000_I2CCMD_READY)) {
275 hw_dbg("I2CCMD Read did not complete\n");
276 return -E1000_ERR_PHY;
277 }
278 if (i2ccmd & E1000_I2CCMD_ERROR) {
279 hw_dbg("I2CCMD Error bit set\n");
280 return -E1000_ERR_PHY;
281 }
282
283
284 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
285
286 return 0;
287}
288
289
290
291
292
293
294
295
296
297s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
298{
299 struct e1000_phy_info *phy = &hw->phy;
300 u32 i, i2ccmd = 0;
301 u16 phy_data_swapped;
302
303
304 if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
305 hw_dbg("PHY I2C Address %d is out of range.\n",
306 hw->phy.addr);
307 return -E1000_ERR_CONFIG;
308 }
309
310
311 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
312
313
314
315
316
317 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
318 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
319 E1000_I2CCMD_OPCODE_WRITE |
320 phy_data_swapped);
321
322 wr32(E1000_I2CCMD, i2ccmd);
323
324
325 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
326 udelay(50);
327 i2ccmd = rd32(E1000_I2CCMD);
328 if (i2ccmd & E1000_I2CCMD_READY)
329 break;
330 }
331 if (!(i2ccmd & E1000_I2CCMD_READY)) {
332 hw_dbg("I2CCMD Write did not complete\n");
333 return -E1000_ERR_PHY;
334 }
335 if (i2ccmd & E1000_I2CCMD_ERROR) {
336 hw_dbg("I2CCMD Error bit set\n");
337 return -E1000_ERR_PHY;
338 }
339
340 return 0;
341}
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
357{
358 u32 i = 0;
359 u32 i2ccmd = 0;
360 u32 data_local = 0;
361
362 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
363 hw_dbg("I2CCMD command address exceeds upper limit\n");
364 return -E1000_ERR_PHY;
365 }
366
367
368
369
370
371 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
372 E1000_I2CCMD_OPCODE_READ);
373
374 wr32(E1000_I2CCMD, i2ccmd);
375
376
377 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
378 udelay(50);
379 data_local = rd32(E1000_I2CCMD);
380 if (data_local & E1000_I2CCMD_READY)
381 break;
382 }
383 if (!(data_local & E1000_I2CCMD_READY)) {
384 hw_dbg("I2CCMD Read did not complete\n");
385 return -E1000_ERR_PHY;
386 }
387 if (data_local & E1000_I2CCMD_ERROR) {
388 hw_dbg("I2CCMD Error bit set\n");
389 return -E1000_ERR_PHY;
390 }
391 *data = (u8) data_local & 0xFF;
392
393 return 0;
394}
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409s32 e1000_write_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 data)
410{
411 u32 i = 0;
412 u32 i2ccmd = 0;
413 u32 data_local = 0;
414
415 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
416 hw_dbg("I2CCMD command address exceeds upper limit\n");
417 return -E1000_ERR_PHY;
418 }
419
420
421
422
423
424
425
426
427
428 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
429 E1000_I2CCMD_OPCODE_READ);
430
431 wr32(E1000_I2CCMD, i2ccmd);
432 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
433 udelay(50);
434
435
436
437 i2ccmd = rd32(E1000_I2CCMD);
438 if (i2ccmd & E1000_I2CCMD_READY) {
439
440 if ((i2ccmd & E1000_I2CCMD_OPCODE_READ) ==
441 E1000_I2CCMD_OPCODE_READ) {
442
443
444
445 data_local = i2ccmd & 0xFF00;
446 data_local |= data;
447 i2ccmd = ((offset <<
448 E1000_I2CCMD_REG_ADDR_SHIFT) |
449 E1000_I2CCMD_OPCODE_WRITE | data_local);
450 wr32(E1000_I2CCMD, i2ccmd);
451 } else {
452 break;
453 }
454 }
455 }
456 if (!(i2ccmd & E1000_I2CCMD_READY)) {
457 hw_dbg("I2CCMD Write did not complete\n");
458 return -E1000_ERR_PHY;
459 }
460 if (i2ccmd & E1000_I2CCMD_ERROR) {
461 hw_dbg("I2CCMD Error bit set\n");
462 return -E1000_ERR_PHY;
463 }
464 return 0;
465}
466
467
468
469
470
471
472
473
474
475
476
477s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
478{
479 s32 ret_val = 0;
480
481 if (!(hw->phy.ops.acquire))
482 goto out;
483
484 ret_val = hw->phy.ops.acquire(hw);
485 if (ret_val)
486 goto out;
487
488 if (offset > MAX_PHY_MULTI_PAGE_REG) {
489 ret_val = igb_write_phy_reg_mdic(hw,
490 IGP01E1000_PHY_PAGE_SELECT,
491 (u16)offset);
492 if (ret_val) {
493 hw->phy.ops.release(hw);
494 goto out;
495 }
496 }
497
498 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
499 data);
500
501 hw->phy.ops.release(hw);
502
503out:
504 return ret_val;
505}
506
507
508
509
510
511
512
513
514
515
516s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
517{
518 s32 ret_val = 0;
519
520 if (!(hw->phy.ops.acquire))
521 goto out;
522
523 ret_val = hw->phy.ops.acquire(hw);
524 if (ret_val)
525 goto out;
526
527 if (offset > MAX_PHY_MULTI_PAGE_REG) {
528 ret_val = igb_write_phy_reg_mdic(hw,
529 IGP01E1000_PHY_PAGE_SELECT,
530 (u16)offset);
531 if (ret_val) {
532 hw->phy.ops.release(hw);
533 goto out;
534 }
535 }
536
537 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
538 data);
539
540 hw->phy.ops.release(hw);
541
542out:
543 return ret_val;
544}
545
546
547
548
549
550
551
552s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
553{
554 struct e1000_phy_info *phy = &hw->phy;
555 s32 ret_val;
556 u16 phy_data;
557
558 if (phy->reset_disable) {
559 ret_val = 0;
560 goto out;
561 }
562
563 if (phy->type == e1000_phy_82580) {
564 ret_val = hw->phy.ops.reset(hw);
565 if (ret_val) {
566 hw_dbg("Error resetting the PHY.\n");
567 goto out;
568 }
569 }
570
571
572 ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
573 if (ret_val)
574 goto out;
575
576 phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
577
578
579 phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
580
581 ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
582 if (ret_val)
583 goto out;
584
585
586 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
587 if (ret_val)
588 goto out;
589 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
590
591
592
593
594
595 switch (hw->phy.mdix) {
596 case 1:
597 break;
598 case 2:
599 phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX;
600 break;
601 case 0:
602 default:
603 phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX;
604 break;
605 }
606 ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
607
608out:
609 return ret_val;
610}
611
612
613
614
615
616
617
618
619s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
620{
621 struct e1000_phy_info *phy = &hw->phy;
622 s32 ret_val;
623 u16 phy_data;
624
625 if (phy->reset_disable) {
626 ret_val = 0;
627 goto out;
628 }
629
630
631 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
632 if (ret_val)
633 goto out;
634
635 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
636
637
638
639
640
641
642
643
644 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
645
646 switch (phy->mdix) {
647 case 1:
648 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
649 break;
650 case 2:
651 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
652 break;
653 case 3:
654 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
655 break;
656 case 0:
657 default:
658 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
659 break;
660 }
661
662
663
664
665
666
667
668 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
669 if (phy->disable_polarity_correction == 1)
670 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
671
672 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
673 if (ret_val)
674 goto out;
675
676 if (phy->revision < E1000_REVISION_4) {
677
678
679
680 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
681 &phy_data);
682 if (ret_val)
683 goto out;
684
685 phy_data |= M88E1000_EPSCR_TX_CLK_25;
686
687 if ((phy->revision == E1000_REVISION_2) &&
688 (phy->id == M88E1111_I_PHY_ID)) {
689
690 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
691 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
692 } else {
693
694 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
695 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
696 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
697 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
698 }
699 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
700 phy_data);
701 if (ret_val)
702 goto out;
703 }
704
705
706 ret_val = igb_phy_sw_reset(hw);
707 if (ret_val) {
708 hw_dbg("Error committing the PHY changes\n");
709 goto out;
710 }
711
712out:
713 return ret_val;
714}
715
716
717
718
719
720
721
722
723s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw)
724{
725 struct e1000_phy_info *phy = &hw->phy;
726 s32 ret_val;
727 u16 phy_data;
728
729 if (phy->reset_disable)
730 return 0;
731
732
733 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
734 if (ret_val)
735 return ret_val;
736
737
738
739
740
741
742
743
744 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
745
746 switch (phy->mdix) {
747 case 1:
748 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
749 break;
750 case 2:
751 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
752 break;
753 case 3:
754
755 if (phy->id != M88E1112_E_PHY_ID) {
756 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
757 break;
758 }
759 case 0:
760 default:
761 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
762 break;
763 }
764
765
766
767
768
769
770
771 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
772 if (phy->disable_polarity_correction == 1)
773 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
774
775
776 if (phy->id == M88E1543_E_PHY_ID) {
777 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
778 ret_val =
779 phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
780 if (ret_val)
781 return ret_val;
782
783 ret_val = igb_phy_sw_reset(hw);
784 if (ret_val) {
785 hw_dbg("Error committing the PHY changes\n");
786 return ret_val;
787 }
788 }
789
790 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
791 phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
792 phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
793
794 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
795 if (ret_val)
796 return ret_val;
797
798
799 ret_val = igb_phy_sw_reset(hw);
800 if (ret_val) {
801 hw_dbg("Error committing the PHY changes\n");
802 return ret_val;
803 }
804 ret_val = igb_set_master_slave_mode(hw);
805 if (ret_val)
806 return ret_val;
807
808 return 0;
809}
810
811
812
813
814
815
816
817
818s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
819{
820 struct e1000_phy_info *phy = &hw->phy;
821 s32 ret_val;
822 u16 data;
823
824 if (phy->reset_disable) {
825 ret_val = 0;
826 goto out;
827 }
828
829 ret_val = phy->ops.reset(hw);
830 if (ret_val) {
831 hw_dbg("Error resetting the PHY.\n");
832 goto out;
833 }
834
835
836
837
838 msleep(100);
839
840
841
842
843 if (phy->type == e1000_phy_igp) {
844
845 if (phy->ops.set_d3_lplu_state)
846 ret_val = phy->ops.set_d3_lplu_state(hw, false);
847 if (ret_val) {
848 hw_dbg("Error Disabling LPLU D3\n");
849 goto out;
850 }
851 }
852
853
854 ret_val = phy->ops.set_d0_lplu_state(hw, false);
855 if (ret_val) {
856 hw_dbg("Error Disabling LPLU D0\n");
857 goto out;
858 }
859
860 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
861 if (ret_val)
862 goto out;
863
864 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
865
866 switch (phy->mdix) {
867 case 1:
868 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
869 break;
870 case 2:
871 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
872 break;
873 case 0:
874 default:
875 data |= IGP01E1000_PSCR_AUTO_MDIX;
876 break;
877 }
878 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
879 if (ret_val)
880 goto out;
881
882
883 if (hw->mac.autoneg) {
884
885
886
887
888 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
889
890 ret_val = phy->ops.read_reg(hw,
891 IGP01E1000_PHY_PORT_CONFIG,
892 &data);
893 if (ret_val)
894 goto out;
895
896 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
897 ret_val = phy->ops.write_reg(hw,
898 IGP01E1000_PHY_PORT_CONFIG,
899 data);
900 if (ret_val)
901 goto out;
902
903
904 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
905 if (ret_val)
906 goto out;
907
908 data &= ~CR_1000T_MS_ENABLE;
909 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
910 if (ret_val)
911 goto out;
912 }
913
914 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
915 if (ret_val)
916 goto out;
917
918
919 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
920 ((data & CR_1000T_MS_VALUE) ?
921 e1000_ms_force_master :
922 e1000_ms_force_slave) :
923 e1000_ms_auto;
924
925 switch (phy->ms_type) {
926 case e1000_ms_force_master:
927 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
928 break;
929 case e1000_ms_force_slave:
930 data |= CR_1000T_MS_ENABLE;
931 data &= ~(CR_1000T_MS_VALUE);
932 break;
933 case e1000_ms_auto:
934 data &= ~CR_1000T_MS_ENABLE;
935 default:
936 break;
937 }
938 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
939 if (ret_val)
940 goto out;
941 }
942
943out:
944 return ret_val;
945}
946
947
948
949
950
951
952
953
954
955
956static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
957{
958 struct e1000_phy_info *phy = &hw->phy;
959 s32 ret_val;
960 u16 phy_ctrl;
961
962
963
964
965 phy->autoneg_advertised &= phy->autoneg_mask;
966
967
968
969
970 if (phy->autoneg_advertised == 0)
971 phy->autoneg_advertised = phy->autoneg_mask;
972
973 hw_dbg("Reconfiguring auto-neg advertisement params\n");
974 ret_val = igb_phy_setup_autoneg(hw);
975 if (ret_val) {
976 hw_dbg("Error Setting up Auto-Negotiation\n");
977 goto out;
978 }
979 hw_dbg("Restarting Auto-Neg\n");
980
981
982
983
984 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
985 if (ret_val)
986 goto out;
987
988 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
989 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
990 if (ret_val)
991 goto out;
992
993
994
995
996 if (phy->autoneg_wait_to_complete) {
997 ret_val = igb_wait_autoneg(hw);
998 if (ret_val) {
999 hw_dbg("Error while waiting for "
1000 "autoneg to complete\n");
1001 goto out;
1002 }
1003 }
1004
1005 hw->mac.get_link_status = true;
1006
1007out:
1008 return ret_val;
1009}
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
1021{
1022 struct e1000_phy_info *phy = &hw->phy;
1023 s32 ret_val;
1024 u16 mii_autoneg_adv_reg;
1025 u16 mii_1000t_ctrl_reg = 0;
1026
1027 phy->autoneg_advertised &= phy->autoneg_mask;
1028
1029
1030 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1031 if (ret_val)
1032 goto out;
1033
1034 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1035
1036 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
1037 &mii_1000t_ctrl_reg);
1038 if (ret_val)
1039 goto out;
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
1054 NWAY_AR_100TX_HD_CAPS |
1055 NWAY_AR_10T_FD_CAPS |
1056 NWAY_AR_10T_HD_CAPS);
1057 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
1058
1059 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
1060
1061
1062 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
1063 hw_dbg("Advertise 10mb Half duplex\n");
1064 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1065 }
1066
1067
1068 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
1069 hw_dbg("Advertise 10mb Full duplex\n");
1070 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1071 }
1072
1073
1074 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
1075 hw_dbg("Advertise 100mb Half duplex\n");
1076 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1077 }
1078
1079
1080 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
1081 hw_dbg("Advertise 100mb Full duplex\n");
1082 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1083 }
1084
1085
1086 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
1087 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
1088
1089
1090 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
1091 hw_dbg("Advertise 1000mb Full duplex\n");
1092 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1093 }
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112 switch (hw->fc.current_mode) {
1113 case e1000_fc_none:
1114
1115
1116
1117 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1118 break;
1119 case e1000_fc_rx_pause:
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1130 break;
1131 case e1000_fc_tx_pause:
1132
1133
1134
1135 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1136 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1137 break;
1138 case e1000_fc_full:
1139
1140
1141
1142 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1143 break;
1144 default:
1145 hw_dbg("Flow control param set incorrectly\n");
1146 ret_val = -E1000_ERR_CONFIG;
1147 goto out;
1148 }
1149
1150 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1151 if (ret_val)
1152 goto out;
1153
1154 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1155
1156 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1157 ret_val = phy->ops.write_reg(hw,
1158 PHY_1000T_CTRL,
1159 mii_1000t_ctrl_reg);
1160 if (ret_val)
1161 goto out;
1162 }
1163
1164out:
1165 return ret_val;
1166}
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177s32 igb_setup_copper_link(struct e1000_hw *hw)
1178{
1179 s32 ret_val;
1180 bool link;
1181
1182 if (hw->mac.autoneg) {
1183
1184
1185
1186 ret_val = igb_copper_link_autoneg(hw);
1187 if (ret_val)
1188 goto out;
1189 } else {
1190
1191
1192
1193 hw_dbg("Forcing Speed and Duplex\n");
1194 ret_val = hw->phy.ops.force_speed_duplex(hw);
1195 if (ret_val) {
1196 hw_dbg("Error Forcing Speed and Duplex\n");
1197 goto out;
1198 }
1199 }
1200
1201
1202
1203
1204 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
1205 if (ret_val)
1206 goto out;
1207
1208 if (link) {
1209 hw_dbg("Valid link established!!!\n");
1210 igb_config_collision_dist(hw);
1211 ret_val = igb_config_fc_after_link_up(hw);
1212 } else {
1213 hw_dbg("Unable to establish link!!!\n");
1214 }
1215
1216out:
1217 return ret_val;
1218}
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1229{
1230 struct e1000_phy_info *phy = &hw->phy;
1231 s32 ret_val;
1232 u16 phy_data;
1233 bool link;
1234
1235 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1236 if (ret_val)
1237 goto out;
1238
1239 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1240
1241 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1242 if (ret_val)
1243 goto out;
1244
1245
1246
1247
1248 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1249 if (ret_val)
1250 goto out;
1251
1252 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1253 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1254
1255 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1256 if (ret_val)
1257 goto out;
1258
1259 hw_dbg("IGP PSCR: %X\n", phy_data);
1260
1261 udelay(1);
1262
1263 if (phy->autoneg_wait_to_complete) {
1264 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
1265
1266 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
1267 if (ret_val)
1268 goto out;
1269
1270 if (!link)
1271 hw_dbg("Link taking longer than expected.\n");
1272
1273
1274 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
1275 if (ret_val)
1276 goto out;
1277 }
1278
1279out:
1280 return ret_val;
1281}
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1294{
1295 struct e1000_phy_info *phy = &hw->phy;
1296 s32 ret_val;
1297 u16 phy_data;
1298 bool link;
1299
1300
1301 if (phy->type != e1000_phy_i210) {
1302
1303
1304
1305 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
1306 &phy_data);
1307 if (ret_val)
1308 goto out;
1309
1310 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1311 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1312 phy_data);
1313 if (ret_val)
1314 goto out;
1315
1316 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
1317 }
1318
1319 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1320 if (ret_val)
1321 goto out;
1322
1323 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1324
1325 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1326 if (ret_val)
1327 goto out;
1328
1329
1330 ret_val = igb_phy_sw_reset(hw);
1331 if (ret_val)
1332 goto out;
1333
1334 if (phy->autoneg_wait_to_complete) {
1335 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
1336
1337 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
1338 if (ret_val)
1339 goto out;
1340
1341 if (!link) {
1342 bool reset_dsp = true;
1343
1344 switch (hw->phy.id) {
1345 case I347AT4_E_PHY_ID:
1346 case M88E1112_E_PHY_ID:
1347 case I210_I_PHY_ID:
1348 reset_dsp = false;
1349 break;
1350 default:
1351 if (hw->phy.type != e1000_phy_m88)
1352 reset_dsp = false;
1353 break;
1354 }
1355 if (!reset_dsp)
1356 hw_dbg("Link taking longer than expected.\n");
1357 else {
1358
1359
1360
1361 ret_val = phy->ops.write_reg(hw,
1362 M88E1000_PHY_PAGE_SELECT,
1363 0x001d);
1364 if (ret_val)
1365 goto out;
1366 ret_val = igb_phy_reset_dsp(hw);
1367 if (ret_val)
1368 goto out;
1369 }
1370 }
1371
1372
1373 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
1374 100000, &link);
1375 if (ret_val)
1376 goto out;
1377 }
1378
1379 if (hw->phy.type != e1000_phy_m88 ||
1380 hw->phy.id == I347AT4_E_PHY_ID ||
1381 hw->phy.id == M88E1112_E_PHY_ID ||
1382 hw->phy.id == I210_I_PHY_ID)
1383 goto out;
1384
1385 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1386 if (ret_val)
1387 goto out;
1388
1389
1390
1391
1392
1393 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1394 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1395 if (ret_val)
1396 goto out;
1397
1398
1399
1400
1401 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1402 if (ret_val)
1403 goto out;
1404
1405 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1406 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1407
1408out:
1409 return ret_val;
1410}
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1425 u16 *phy_ctrl)
1426{
1427 struct e1000_mac_info *mac = &hw->mac;
1428 u32 ctrl;
1429
1430
1431 hw->fc.current_mode = e1000_fc_none;
1432
1433
1434 ctrl = rd32(E1000_CTRL);
1435 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1436 ctrl &= ~E1000_CTRL_SPD_SEL;
1437
1438
1439 ctrl &= ~E1000_CTRL_ASDE;
1440
1441
1442 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1443
1444
1445 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1446 ctrl &= ~E1000_CTRL_FD;
1447 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1448 hw_dbg("Half Duplex\n");
1449 } else {
1450 ctrl |= E1000_CTRL_FD;
1451 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1452 hw_dbg("Full Duplex\n");
1453 }
1454
1455
1456 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1457 ctrl |= E1000_CTRL_SPD_100;
1458 *phy_ctrl |= MII_CR_SPEED_100;
1459 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1460 hw_dbg("Forcing 100mb\n");
1461 } else {
1462 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1463 *phy_ctrl |= MII_CR_SPEED_10;
1464 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1465 hw_dbg("Forcing 10mb\n");
1466 }
1467
1468 igb_config_collision_dist(hw);
1469
1470 wr32(E1000_CTRL, ctrl);
1471}
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1488{
1489 struct e1000_phy_info *phy = &hw->phy;
1490 s32 ret_val = 0;
1491 u16 data;
1492
1493 if (!(hw->phy.ops.read_reg))
1494 goto out;
1495
1496 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1497 if (ret_val)
1498 goto out;
1499
1500 if (!active) {
1501 data &= ~IGP02E1000_PM_D3_LPLU;
1502 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1503 data);
1504 if (ret_val)
1505 goto out;
1506
1507
1508
1509
1510
1511 if (phy->smart_speed == e1000_smart_speed_on) {
1512 ret_val = phy->ops.read_reg(hw,
1513 IGP01E1000_PHY_PORT_CONFIG,
1514 &data);
1515 if (ret_val)
1516 goto out;
1517
1518 data |= IGP01E1000_PSCFR_SMART_SPEED;
1519 ret_val = phy->ops.write_reg(hw,
1520 IGP01E1000_PHY_PORT_CONFIG,
1521 data);
1522 if (ret_val)
1523 goto out;
1524 } else if (phy->smart_speed == e1000_smart_speed_off) {
1525 ret_val = phy->ops.read_reg(hw,
1526 IGP01E1000_PHY_PORT_CONFIG,
1527 &data);
1528 if (ret_val)
1529 goto out;
1530
1531 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1532 ret_val = phy->ops.write_reg(hw,
1533 IGP01E1000_PHY_PORT_CONFIG,
1534 data);
1535 if (ret_val)
1536 goto out;
1537 }
1538 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1539 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1540 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1541 data |= IGP02E1000_PM_D3_LPLU;
1542 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1543 data);
1544 if (ret_val)
1545 goto out;
1546
1547
1548 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1549 &data);
1550 if (ret_val)
1551 goto out;
1552
1553 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1554 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1555 data);
1556 }
1557
1558out:
1559 return ret_val;
1560}
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570s32 igb_check_downshift(struct e1000_hw *hw)
1571{
1572 struct e1000_phy_info *phy = &hw->phy;
1573 s32 ret_val;
1574 u16 phy_data, offset, mask;
1575
1576 switch (phy->type) {
1577 case e1000_phy_i210:
1578 case e1000_phy_m88:
1579 case e1000_phy_gg82563:
1580 offset = M88E1000_PHY_SPEC_STATUS;
1581 mask = M88E1000_PSSR_DOWNSHIFT;
1582 break;
1583 case e1000_phy_igp_2:
1584 case e1000_phy_igp:
1585 case e1000_phy_igp_3:
1586 offset = IGP01E1000_PHY_LINK_HEALTH;
1587 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1588 break;
1589 default:
1590
1591 phy->speed_downgraded = false;
1592 ret_val = 0;
1593 goto out;
1594 }
1595
1596 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1597
1598 if (!ret_val)
1599 phy->speed_downgraded = (phy_data & mask) ? true : false;
1600
1601out:
1602 return ret_val;
1603}
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613s32 igb_check_polarity_m88(struct e1000_hw *hw)
1614{
1615 struct e1000_phy_info *phy = &hw->phy;
1616 s32 ret_val;
1617 u16 data;
1618
1619 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
1620
1621 if (!ret_val)
1622 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1623 ? e1000_rev_polarity_reversed
1624 : e1000_rev_polarity_normal;
1625
1626 return ret_val;
1627}
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1639{
1640 struct e1000_phy_info *phy = &hw->phy;
1641 s32 ret_val;
1642 u16 data, offset, mask;
1643
1644
1645
1646
1647 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1648 if (ret_val)
1649 goto out;
1650
1651 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1652 IGP01E1000_PSSR_SPEED_1000MBPS) {
1653 offset = IGP01E1000_PHY_PCS_INIT_REG;
1654 mask = IGP01E1000_PHY_POLARITY_MASK;
1655 } else {
1656
1657
1658
1659 offset = IGP01E1000_PHY_PORT_STATUS;
1660 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1661 }
1662
1663 ret_val = phy->ops.read_reg(hw, offset, &data);
1664
1665 if (!ret_val)
1666 phy->cable_polarity = (data & mask)
1667 ? e1000_rev_polarity_reversed
1668 : e1000_rev_polarity_normal;
1669
1670out:
1671 return ret_val;
1672}
1673
1674
1675
1676
1677
1678
1679
1680
1681static s32 igb_wait_autoneg(struct e1000_hw *hw)
1682{
1683 s32 ret_val = 0;
1684 u16 i, phy_status;
1685
1686
1687 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1688 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1689 if (ret_val)
1690 break;
1691 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1692 if (ret_val)
1693 break;
1694 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1695 break;
1696 msleep(100);
1697 }
1698
1699
1700
1701
1702 return ret_val;
1703}
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1715 u32 usec_interval, bool *success)
1716{
1717 s32 ret_val = 0;
1718 u16 i, phy_status;
1719
1720 for (i = 0; i < iterations; i++) {
1721
1722
1723
1724
1725 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1726 if (ret_val && usec_interval > 0) {
1727
1728
1729
1730
1731 if (usec_interval >= 1000)
1732 mdelay(usec_interval/1000);
1733 else
1734 udelay(usec_interval);
1735 }
1736 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1737 if (ret_val)
1738 break;
1739 if (phy_status & MII_SR_LINK_STATUS)
1740 break;
1741 if (usec_interval >= 1000)
1742 mdelay(usec_interval/1000);
1743 else
1744 udelay(usec_interval);
1745 }
1746
1747 *success = (i < iterations) ? true : false;
1748
1749 return ret_val;
1750}
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1768{
1769 struct e1000_phy_info *phy = &hw->phy;
1770 s32 ret_val;
1771 u16 phy_data, index;
1772
1773 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1774 if (ret_val)
1775 goto out;
1776
1777 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1778 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1779 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1780 ret_val = -E1000_ERR_PHY;
1781 goto out;
1782 }
1783
1784 phy->min_cable_length = e1000_m88_cable_length_table[index];
1785 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1786
1787 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1788
1789out:
1790 return ret_val;
1791}
1792
1793s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
1794{
1795 struct e1000_phy_info *phy = &hw->phy;
1796 s32 ret_val;
1797 u16 phy_data, phy_data2, index, default_page, is_cm;
1798
1799 switch (hw->phy.id) {
1800 case I210_I_PHY_ID:
1801
1802 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
1803 (I347AT4_PCDL + phy->addr),
1804 &phy_data);
1805 if (ret_val)
1806 return ret_val;
1807
1808
1809 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
1810 I347AT4_PCDC, &phy_data2);
1811 if (ret_val)
1812 return ret_val;
1813
1814 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
1815
1816
1817 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1818 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1819 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1820 break;
1821 case M88E1543_E_PHY_ID:
1822 case I347AT4_E_PHY_ID:
1823
1824 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1825 &default_page);
1826 if (ret_val)
1827 goto out;
1828
1829 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
1830 if (ret_val)
1831 goto out;
1832
1833
1834 ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
1835 &phy_data);
1836 if (ret_val)
1837 goto out;
1838
1839
1840 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
1841 if (ret_val)
1842 goto out;
1843
1844 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
1845
1846
1847 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1848 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1849 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1850
1851
1852 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1853 default_page);
1854 if (ret_val)
1855 goto out;
1856 break;
1857 case M88E1112_E_PHY_ID:
1858
1859 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1860 &default_page);
1861 if (ret_val)
1862 goto out;
1863
1864 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
1865 if (ret_val)
1866 goto out;
1867
1868 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
1869 &phy_data);
1870 if (ret_val)
1871 goto out;
1872
1873 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1874 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1875 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1876 ret_val = -E1000_ERR_PHY;
1877 goto out;
1878 }
1879
1880 phy->min_cable_length = e1000_m88_cable_length_table[index];
1881 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1882
1883 phy->cable_length = (phy->min_cable_length +
1884 phy->max_cable_length) / 2;
1885
1886
1887 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1888 default_page);
1889 if (ret_val)
1890 goto out;
1891
1892 break;
1893 default:
1894 ret_val = -E1000_ERR_PHY;
1895 goto out;
1896 }
1897
1898out:
1899 return ret_val;
1900}
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1914{
1915 struct e1000_phy_info *phy = &hw->phy;
1916 s32 ret_val = 0;
1917 u16 phy_data, i, agc_value = 0;
1918 u16 cur_agc_index, max_agc_index = 0;
1919 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1920 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1921 IGP02E1000_PHY_AGC_A,
1922 IGP02E1000_PHY_AGC_B,
1923 IGP02E1000_PHY_AGC_C,
1924 IGP02E1000_PHY_AGC_D
1925 };
1926
1927
1928 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1929 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
1930 if (ret_val)
1931 goto out;
1932
1933
1934
1935
1936
1937
1938 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1939 IGP02E1000_AGC_LENGTH_MASK;
1940
1941
1942 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1943 (cur_agc_index == 0)) {
1944 ret_val = -E1000_ERR_PHY;
1945 goto out;
1946 }
1947
1948
1949 if (e1000_igp_2_cable_length_table[min_agc_index] >
1950 e1000_igp_2_cable_length_table[cur_agc_index])
1951 min_agc_index = cur_agc_index;
1952 if (e1000_igp_2_cable_length_table[max_agc_index] <
1953 e1000_igp_2_cable_length_table[cur_agc_index])
1954 max_agc_index = cur_agc_index;
1955
1956 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1957 }
1958
1959 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1960 e1000_igp_2_cable_length_table[max_agc_index]);
1961 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1962
1963
1964 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1965 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1966 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1967
1968 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1969
1970out:
1971 return ret_val;
1972}
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1985{
1986 struct e1000_phy_info *phy = &hw->phy;
1987 s32 ret_val;
1988 u16 phy_data;
1989 bool link;
1990
1991 if (phy->media_type != e1000_media_type_copper) {
1992 hw_dbg("Phy info is only valid for copper media\n");
1993 ret_val = -E1000_ERR_CONFIG;
1994 goto out;
1995 }
1996
1997 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1998 if (ret_val)
1999 goto out;
2000
2001 if (!link) {
2002 hw_dbg("Phy info is only valid if link is up\n");
2003 ret_val = -E1000_ERR_CONFIG;
2004 goto out;
2005 }
2006
2007 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2008 if (ret_val)
2009 goto out;
2010
2011 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
2012 ? true : false;
2013
2014 ret_val = igb_check_polarity_m88(hw);
2015 if (ret_val)
2016 goto out;
2017
2018 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2019 if (ret_val)
2020 goto out;
2021
2022 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
2023
2024 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
2025 ret_val = phy->ops.get_cable_length(hw);
2026 if (ret_val)
2027 goto out;
2028
2029 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
2030 if (ret_val)
2031 goto out;
2032
2033 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
2034 ? e1000_1000t_rx_status_ok
2035 : e1000_1000t_rx_status_not_ok;
2036
2037 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
2038 ? e1000_1000t_rx_status_ok
2039 : e1000_1000t_rx_status_not_ok;
2040 } else {
2041
2042 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2043 phy->local_rx = e1000_1000t_rx_status_undefined;
2044 phy->remote_rx = e1000_1000t_rx_status_undefined;
2045 }
2046
2047out:
2048 return ret_val;
2049}
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060s32 igb_get_phy_info_igp(struct e1000_hw *hw)
2061{
2062 struct e1000_phy_info *phy = &hw->phy;
2063 s32 ret_val;
2064 u16 data;
2065 bool link;
2066
2067 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2068 if (ret_val)
2069 goto out;
2070
2071 if (!link) {
2072 hw_dbg("Phy info is only valid if link is up\n");
2073 ret_val = -E1000_ERR_CONFIG;
2074 goto out;
2075 }
2076
2077 phy->polarity_correction = true;
2078
2079 ret_val = igb_check_polarity_igp(hw);
2080 if (ret_val)
2081 goto out;
2082
2083 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2084 if (ret_val)
2085 goto out;
2086
2087 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
2088
2089 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2090 IGP01E1000_PSSR_SPEED_1000MBPS) {
2091 ret_val = phy->ops.get_cable_length(hw);
2092 if (ret_val)
2093 goto out;
2094
2095 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2096 if (ret_val)
2097 goto out;
2098
2099 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2100 ? e1000_1000t_rx_status_ok
2101 : e1000_1000t_rx_status_not_ok;
2102
2103 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2104 ? e1000_1000t_rx_status_ok
2105 : e1000_1000t_rx_status_not_ok;
2106 } else {
2107 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2108 phy->local_rx = e1000_1000t_rx_status_undefined;
2109 phy->remote_rx = e1000_1000t_rx_status_undefined;
2110 }
2111
2112out:
2113 return ret_val;
2114}
2115
2116
2117
2118
2119
2120
2121
2122
2123s32 igb_phy_sw_reset(struct e1000_hw *hw)
2124{
2125 s32 ret_val = 0;
2126 u16 phy_ctrl;
2127
2128 if (!(hw->phy.ops.read_reg))
2129 goto out;
2130
2131 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
2132 if (ret_val)
2133 goto out;
2134
2135 phy_ctrl |= MII_CR_RESET;
2136 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
2137 if (ret_val)
2138 goto out;
2139
2140 udelay(1);
2141
2142out:
2143 return ret_val;
2144}
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155s32 igb_phy_hw_reset(struct e1000_hw *hw)
2156{
2157 struct e1000_phy_info *phy = &hw->phy;
2158 s32 ret_val;
2159 u32 ctrl;
2160
2161 ret_val = igb_check_reset_block(hw);
2162 if (ret_val) {
2163 ret_val = 0;
2164 goto out;
2165 }
2166
2167 ret_val = phy->ops.acquire(hw);
2168 if (ret_val)
2169 goto out;
2170
2171 ctrl = rd32(E1000_CTRL);
2172 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2173 wrfl();
2174
2175 udelay(phy->reset_delay_us);
2176
2177 wr32(E1000_CTRL, ctrl);
2178 wrfl();
2179
2180 udelay(150);
2181
2182 phy->ops.release(hw);
2183
2184 ret_val = phy->ops.get_cfg_done(hw);
2185
2186out:
2187 return ret_val;
2188}
2189
2190
2191
2192
2193
2194
2195
2196s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
2197{
2198 hw_dbg("Running IGP 3 PHY init script\n");
2199
2200
2201
2202 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2203
2204 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
2205
2206 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2207
2208 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2209
2210 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
2211
2212 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
2213
2214 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
2215
2216 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2217
2218 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2219
2220 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2221
2222 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
2223
2224 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
2225
2226 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
2227
2228 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
2229
2230 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2231
2232 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
2233
2234 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
2235
2236 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
2237
2238 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2239
2240 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2241
2242 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2243
2244 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2245
2246 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
2247
2248 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
2249
2250 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
2251
2252 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
2253
2254
2255
2256 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
2257
2258 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
2259
2260
2261
2262 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
2263
2264 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
2265
2266 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
2267
2268 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
2269
2270 return 0;
2271}
2272
2273
2274
2275
2276
2277
2278
2279
2280void igb_power_up_phy_copper(struct e1000_hw *hw)
2281{
2282 u16 mii_reg = 0;
2283 u16 power_reg = 0;
2284
2285
2286 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2287 mii_reg &= ~MII_CR_POWER_DOWN;
2288 if (hw->phy.type == e1000_phy_i210) {
2289 hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg);
2290 power_reg &= ~GS40G_CS_POWER_DOWN;
2291 hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg);
2292 }
2293 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2294}
2295
2296
2297
2298
2299
2300
2301
2302
2303void igb_power_down_phy_copper(struct e1000_hw *hw)
2304{
2305 u16 mii_reg = 0;
2306 u16 power_reg = 0;
2307
2308
2309 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2310 mii_reg |= MII_CR_POWER_DOWN;
2311
2312
2313 if (hw->phy.type == e1000_phy_i210) {
2314 hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg);
2315 power_reg |= GS40G_CS_POWER_DOWN;
2316 hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg);
2317 }
2318 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2319 msleep(1);
2320}
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330static s32 igb_check_polarity_82580(struct e1000_hw *hw)
2331{
2332 struct e1000_phy_info *phy = &hw->phy;
2333 s32 ret_val;
2334 u16 data;
2335
2336
2337 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2338
2339 if (!ret_val)
2340 phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
2341 ? e1000_rev_polarity_reversed
2342 : e1000_rev_polarity_normal;
2343
2344 return ret_val;
2345}
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
2356{
2357 struct e1000_phy_info *phy = &hw->phy;
2358 s32 ret_val;
2359 u16 phy_data;
2360 bool link;
2361
2362 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
2363 if (ret_val)
2364 goto out;
2365
2366 igb_phy_force_speed_duplex_setup(hw, &phy_data);
2367
2368 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
2369 if (ret_val)
2370 goto out;
2371
2372
2373
2374
2375 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
2376 if (ret_val)
2377 goto out;
2378
2379 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
2380
2381 ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
2382 if (ret_val)
2383 goto out;
2384
2385 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
2386
2387 udelay(1);
2388
2389 if (phy->autoneg_wait_to_complete) {
2390 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2391
2392 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
2393 if (ret_val)
2394 goto out;
2395
2396 if (!link)
2397 hw_dbg("Link taking longer than expected.\n");
2398
2399
2400 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
2401 if (ret_val)
2402 goto out;
2403 }
2404
2405out:
2406 return ret_val;
2407}
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418s32 igb_get_phy_info_82580(struct e1000_hw *hw)
2419{
2420 struct e1000_phy_info *phy = &hw->phy;
2421 s32 ret_val;
2422 u16 data;
2423 bool link;
2424
2425 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2426 if (ret_val)
2427 goto out;
2428
2429 if (!link) {
2430 hw_dbg("Phy info is only valid if link is up\n");
2431 ret_val = -E1000_ERR_CONFIG;
2432 goto out;
2433 }
2434
2435 phy->polarity_correction = true;
2436
2437 ret_val = igb_check_polarity_82580(hw);
2438 if (ret_val)
2439 goto out;
2440
2441 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2442 if (ret_val)
2443 goto out;
2444
2445 phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
2446
2447 if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
2448 I82580_PHY_STATUS2_SPEED_1000MBPS) {
2449 ret_val = hw->phy.ops.get_cable_length(hw);
2450 if (ret_val)
2451 goto out;
2452
2453 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2454 if (ret_val)
2455 goto out;
2456
2457 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2458 ? e1000_1000t_rx_status_ok
2459 : e1000_1000t_rx_status_not_ok;
2460
2461 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2462 ? e1000_1000t_rx_status_ok
2463 : e1000_1000t_rx_status_not_ok;
2464 } else {
2465 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2466 phy->local_rx = e1000_1000t_rx_status_undefined;
2467 phy->remote_rx = e1000_1000t_rx_status_undefined;
2468 }
2469
2470out:
2471 return ret_val;
2472}
2473
2474
2475
2476
2477
2478
2479
2480
2481s32 igb_get_cable_length_82580(struct e1000_hw *hw)
2482{
2483 struct e1000_phy_info *phy = &hw->phy;
2484 s32 ret_val;
2485 u16 phy_data, length;
2486
2487 ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data);
2488 if (ret_val)
2489 goto out;
2490
2491 length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >>
2492 I82580_DSTATUS_CABLE_LENGTH_SHIFT;
2493
2494 if (length == E1000_CABLE_LENGTH_UNDEFINED)
2495 ret_val = -E1000_ERR_PHY;
2496
2497 phy->cable_length = length;
2498
2499out:
2500 return ret_val;
2501}
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513s32 igb_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data)
2514{
2515 s32 ret_val;
2516 u16 page = offset >> GS40G_PAGE_SHIFT;
2517
2518 offset = offset & GS40G_OFFSET_MASK;
2519 ret_val = hw->phy.ops.acquire(hw);
2520 if (ret_val)
2521 return ret_val;
2522
2523 ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
2524 if (ret_val)
2525 goto release;
2526 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2527
2528release:
2529 hw->phy.ops.release(hw);
2530 return ret_val;
2531}
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543s32 igb_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data)
2544{
2545 s32 ret_val;
2546 u16 page = offset >> GS40G_PAGE_SHIFT;
2547
2548 offset = offset & GS40G_OFFSET_MASK;
2549 ret_val = hw->phy.ops.acquire(hw);
2550 if (ret_val)
2551 return ret_val;
2552
2553 ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
2554 if (ret_val)
2555 goto release;
2556 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2557
2558release:
2559 hw->phy.ops.release(hw);
2560 return ret_val;
2561}
2562
2563
2564
2565
2566
2567
2568
2569static s32 igb_set_master_slave_mode(struct e1000_hw *hw)
2570{
2571 s32 ret_val;
2572 u16 phy_data;
2573
2574
2575 ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
2576 if (ret_val)
2577 return ret_val;
2578
2579
2580 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
2581 ((phy_data & CR_1000T_MS_VALUE) ?
2582 e1000_ms_force_master :
2583 e1000_ms_force_slave) : e1000_ms_auto;
2584
2585 switch (hw->phy.ms_type) {
2586 case e1000_ms_force_master:
2587 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2588 break;
2589 case e1000_ms_force_slave:
2590 phy_data |= CR_1000T_MS_ENABLE;
2591 phy_data &= ~(CR_1000T_MS_VALUE);
2592 break;
2593 case e1000_ms_auto:
2594 phy_data &= ~CR_1000T_MS_ENABLE;
2595
2596 default:
2597 break;
2598 }
2599
2600 return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
2601}
2602