00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 FILE_LICENCE ( GPL2_ONLY );
00029
00030 #include "igb.h"
00031
00032 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
00033
00034 #if 0
00035
00036 static const u16 e1000_m88_cable_length_table[] =
00037 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
00038 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
00039 (sizeof(e1000_m88_cable_length_table) / \
00040 sizeof(e1000_m88_cable_length_table[0]))
00041
00042 static const u16 e1000_igp_2_cable_length_table[] =
00043 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
00044 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
00045 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
00046 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
00047 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
00048 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
00049 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
00050 104, 109, 114, 118, 121, 124};
00051 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
00052 (sizeof(e1000_igp_2_cable_length_table) / \
00053 sizeof(e1000_igp_2_cable_length_table[0]))
00054 #endif
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 s32 igb_check_reset_block_generic(struct e1000_hw *hw)
00065 {
00066 u32 manc;
00067
00068 DEBUGFUNC("igb_check_reset_block");
00069
00070 manc = E1000_READ_REG(hw, E1000_MANC);
00071
00072 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
00073 E1000_BLK_PHY_RESET : E1000_SUCCESS;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083 s32 igb_get_phy_id(struct e1000_hw *hw)
00084 {
00085 struct e1000_phy_info *phy = &hw->phy;
00086 s32 ret_val = E1000_SUCCESS;
00087 u16 phy_id;
00088
00089 DEBUGFUNC("igb_get_phy_id");
00090
00091 if (!(phy->ops.read_reg))
00092 goto out;
00093
00094 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
00095 if (ret_val)
00096 goto out;
00097
00098 phy->id = (u32)(phy_id << 16);
00099 usec_delay(20);
00100 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
00101 if (ret_val)
00102 goto out;
00103
00104 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
00105 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
00106
00107 out:
00108 return ret_val;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 s32 igb_phy_reset_dsp_generic(struct e1000_hw *hw)
00118 {
00119 s32 ret_val = E1000_SUCCESS;
00120
00121 DEBUGFUNC("igb_phy_reset_dsp_generic");
00122
00123 if (!(hw->phy.ops.write_reg))
00124 goto out;
00125
00126 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
00127 if (ret_val)
00128 goto out;
00129
00130 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
00131
00132 out:
00133 return ret_val;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
00146 {
00147 struct e1000_phy_info *phy = &hw->phy;
00148 u32 i, mdic = 0;
00149 s32 ret_val = E1000_SUCCESS;
00150
00151 DEBUGFUNC("igb_read_phy_reg_mdic");
00152
00153
00154
00155
00156
00157
00158 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
00159 (phy->addr << E1000_MDIC_PHY_SHIFT) |
00160 (E1000_MDIC_OP_READ));
00161
00162 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
00163
00164
00165
00166
00167
00168
00169 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
00170 usec_delay(50);
00171 mdic = E1000_READ_REG(hw, E1000_MDIC);
00172 if (mdic & E1000_MDIC_READY)
00173 break;
00174 }
00175 if (!(mdic & E1000_MDIC_READY)) {
00176 DEBUGOUT("MDI Read did not complete\n");
00177 ret_val = -E1000_ERR_PHY;
00178 goto out;
00179 }
00180 if (mdic & E1000_MDIC_ERROR) {
00181 DEBUGOUT("MDI Error\n");
00182 ret_val = -E1000_ERR_PHY;
00183 goto out;
00184 }
00185 *data = (u16) mdic;
00186
00187 out:
00188 return ret_val;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
00200 {
00201 struct e1000_phy_info *phy = &hw->phy;
00202 u32 i, mdic = 0;
00203 s32 ret_val = E1000_SUCCESS;
00204
00205 DEBUGFUNC("igb_write_phy_reg_mdic");
00206
00207
00208
00209
00210
00211
00212 mdic = (((u32)data) |
00213 (offset << E1000_MDIC_REG_SHIFT) |
00214 (phy->addr << E1000_MDIC_PHY_SHIFT) |
00215 (E1000_MDIC_OP_WRITE));
00216
00217 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
00218
00219
00220
00221
00222
00223
00224 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
00225 usec_delay(50);
00226 mdic = E1000_READ_REG(hw, E1000_MDIC);
00227 if (mdic & E1000_MDIC_READY)
00228 break;
00229 }
00230 if (!(mdic & E1000_MDIC_READY)) {
00231 DEBUGOUT("MDI Write did not complete\n");
00232 ret_val = -E1000_ERR_PHY;
00233 goto out;
00234 }
00235 if (mdic & E1000_MDIC_ERROR) {
00236 DEBUGOUT("MDI Error\n");
00237 ret_val = -E1000_ERR_PHY;
00238 goto out;
00239 }
00240
00241 out:
00242 return ret_val;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
00255 {
00256 struct e1000_phy_info *phy = &hw->phy;
00257 u32 i, i2ccmd = 0;
00258
00259 DEBUGFUNC("igb_read_phy_reg_i2c");
00260
00261
00262
00263
00264
00265
00266 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
00267 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
00268 (E1000_I2CCMD_OPCODE_READ));
00269
00270 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
00271
00272
00273 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
00274 usec_delay(50);
00275 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
00276 if (i2ccmd & E1000_I2CCMD_READY)
00277 break;
00278 }
00279 if (!(i2ccmd & E1000_I2CCMD_READY)) {
00280 DEBUGOUT("I2CCMD Read did not complete\n");
00281 return -E1000_ERR_PHY;
00282 }
00283 if (i2ccmd & E1000_I2CCMD_ERROR) {
00284 DEBUGOUT("I2CCMD Error bit set\n");
00285 return -E1000_ERR_PHY;
00286 }
00287
00288
00289 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
00290
00291 return E1000_SUCCESS;
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
00303 {
00304 struct e1000_phy_info *phy = &hw->phy;
00305 u32 i, i2ccmd = 0;
00306 u16 phy_data_swapped;
00307
00308 DEBUGFUNC("igb_write_phy_reg_i2c");
00309
00310
00311 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
00312
00313
00314
00315
00316
00317
00318 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
00319 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
00320 E1000_I2CCMD_OPCODE_WRITE |
00321 phy_data_swapped);
00322
00323 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
00324
00325
00326 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
00327 usec_delay(50);
00328 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
00329 if (i2ccmd & E1000_I2CCMD_READY)
00330 break;
00331 }
00332 if (!(i2ccmd & E1000_I2CCMD_READY)) {
00333 DEBUGOUT("I2CCMD Write did not complete\n");
00334 return -E1000_ERR_PHY;
00335 }
00336 if (i2ccmd & E1000_I2CCMD_ERROR) {
00337 DEBUGOUT("I2CCMD Error bit set\n");
00338 return -E1000_ERR_PHY;
00339 }
00340
00341 return E1000_SUCCESS;
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 s32 igb_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
00355 {
00356 s32 ret_val = E1000_SUCCESS;
00357
00358 DEBUGFUNC("igb_read_phy_reg_m88");
00359
00360 if (!(hw->phy.ops.acquire))
00361 goto out;
00362
00363 ret_val = hw->phy.ops.acquire(hw);
00364 if (ret_val)
00365 goto out;
00366
00367 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00368 data);
00369
00370 hw->phy.ops.release(hw);
00371
00372 out:
00373 return ret_val;
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 s32 igb_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
00386 {
00387 s32 ret_val = E1000_SUCCESS;
00388
00389 DEBUGFUNC("igb_write_phy_reg_m88");
00390
00391 if (!(hw->phy.ops.acquire))
00392 goto out;
00393
00394 ret_val = hw->phy.ops.acquire(hw);
00395 if (ret_val)
00396 goto out;
00397
00398 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00399 data);
00400
00401 hw->phy.ops.release(hw);
00402
00403 out:
00404 return ret_val;
00405 }
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 static s32 __igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
00419 bool locked)
00420 {
00421 s32 ret_val = E1000_SUCCESS;
00422
00423 DEBUGFUNC("__igb_read_phy_reg_igp");
00424
00425 if (!locked) {
00426 if (!(hw->phy.ops.acquire))
00427 goto out;
00428
00429 ret_val = hw->phy.ops.acquire(hw);
00430 if (ret_val)
00431 goto out;
00432 }
00433
00434 if (offset > MAX_PHY_MULTI_PAGE_REG) {
00435 ret_val = igb_write_phy_reg_mdic(hw,
00436 IGP01E1000_PHY_PAGE_SELECT,
00437 (u16)offset);
00438 if (ret_val)
00439 goto release;
00440 }
00441
00442 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00443 data);
00444
00445 release:
00446 if (!locked)
00447 hw->phy.ops.release(hw);
00448 out:
00449 return ret_val;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461 s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
00462 {
00463 return __igb_read_phy_reg_igp(hw, offset, data, false);
00464 }
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 s32 igb_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
00476 {
00477 return __igb_read_phy_reg_igp(hw, offset, data, true);
00478 }
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 static s32 __igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
00491 bool locked)
00492 {
00493 s32 ret_val = E1000_SUCCESS;
00494
00495 DEBUGFUNC("igb_write_phy_reg_igp");
00496
00497 if (!locked) {
00498 if (!(hw->phy.ops.acquire))
00499 goto out;
00500
00501 ret_val = hw->phy.ops.acquire(hw);
00502 if (ret_val)
00503 goto out;
00504 }
00505
00506 if (offset > MAX_PHY_MULTI_PAGE_REG) {
00507 ret_val = igb_write_phy_reg_mdic(hw,
00508 IGP01E1000_PHY_PAGE_SELECT,
00509 (u16)offset);
00510 if (ret_val)
00511 goto release;
00512 }
00513
00514 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00515 data);
00516
00517 release:
00518 if (!locked)
00519 hw->phy.ops.release(hw);
00520
00521 out:
00522 return ret_val;
00523 }
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534 s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
00535 {
00536 return __igb_write_phy_reg_igp(hw, offset, data, false);
00537 }
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 s32 igb_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
00549 {
00550 return __igb_write_phy_reg_igp(hw, offset, data, true);
00551 }
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564 static s32 __igb_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
00565 bool locked)
00566 {
00567 u32 kmrnctrlsta;
00568 s32 ret_val = E1000_SUCCESS;
00569
00570 DEBUGFUNC("__igb_read_kmrn_reg");
00571
00572 if (!locked) {
00573 if (!(hw->phy.ops.acquire))
00574 goto out;
00575
00576 ret_val = hw->phy.ops.acquire(hw);
00577 if (ret_val)
00578 goto out;
00579 }
00580
00581 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
00582 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
00583 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
00584
00585 usec_delay(2);
00586
00587 kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
00588 *data = (u16)kmrnctrlsta;
00589
00590 if (!locked)
00591 hw->phy.ops.release(hw);
00592
00593 out:
00594 return ret_val;
00595 }
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607 s32 igb_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
00608 {
00609 return __igb_read_kmrn_reg(hw, offset, data, false);
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622 s32 igb_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
00623 {
00624 return __igb_read_kmrn_reg(hw, offset, data, true);
00625 }
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638 static s32 __igb_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
00639 bool locked)
00640 {
00641 u32 kmrnctrlsta;
00642 s32 ret_val = E1000_SUCCESS;
00643
00644 DEBUGFUNC("igb_write_kmrn_reg_generic");
00645
00646 if (!locked) {
00647 if (!(hw->phy.ops.acquire))
00648 goto out;
00649
00650 ret_val = hw->phy.ops.acquire(hw);
00651 if (ret_val)
00652 goto out;
00653 }
00654
00655 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
00656 E1000_KMRNCTRLSTA_OFFSET) | data;
00657 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
00658
00659 usec_delay(2);
00660
00661 if (!locked)
00662 hw->phy.ops.release(hw);
00663
00664 out:
00665 return ret_val;
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 s32 igb_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
00678 {
00679 return __igb_write_kmrn_reg(hw, offset, data, false);
00680 }
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691 s32 igb_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
00692 {
00693 return __igb_write_kmrn_reg(hw, offset, data, true);
00694 }
00695
00696
00697
00698
00699
00700
00701
00702
00703 s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
00704 {
00705 struct e1000_phy_info *phy = &hw->phy;
00706 s32 ret_val;
00707 u16 phy_data;
00708
00709 DEBUGFUNC("igb_copper_link_setup_m88");
00710
00711 if (phy->reset_disable) {
00712 ret_val = E1000_SUCCESS;
00713 goto out;
00714 }
00715
00716
00717 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
00718 if (ret_val)
00719 goto out;
00720
00721 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
00732
00733 switch (phy->mdix) {
00734 case 1:
00735 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
00736 break;
00737 case 2:
00738 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
00739 break;
00740 case 3:
00741 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
00742 break;
00743 case 0:
00744 default:
00745 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
00746 break;
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
00757 if (phy->disable_polarity_correction == 1)
00758 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
00759
00760 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
00761 if (ret_val)
00762 goto out;
00763
00764 if (phy->revision < E1000_REVISION_4) {
00765
00766
00767
00768
00769 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
00770 &phy_data);
00771 if (ret_val)
00772 goto out;
00773
00774 phy_data |= M88E1000_EPSCR_TX_CLK_25;
00775
00776 if ((phy->revision == E1000_REVISION_2) &&
00777 (phy->id == M88E1111_I_PHY_ID)) {
00778
00779 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
00780 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
00781 } else {
00782
00783 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
00784 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
00785 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
00786 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
00787 }
00788 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
00789 phy_data);
00790 if (ret_val)
00791 goto out;
00792 }
00793
00794
00795 ret_val = phy->ops.commit(hw);
00796 if (ret_val) {
00797 DEBUGOUT("Error committing the PHY changes\n");
00798 goto out;
00799 }
00800
00801 out:
00802 return ret_val;
00803 }
00804
00805
00806
00807
00808
00809
00810
00811
00812 s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
00813 {
00814 struct e1000_phy_info *phy = &hw->phy;
00815 s32 ret_val;
00816 u16 data;
00817
00818 DEBUGFUNC("igb_copper_link_setup_igp");
00819
00820 if (phy->reset_disable) {
00821 ret_val = E1000_SUCCESS;
00822 goto out;
00823 }
00824
00825 ret_val = hw->phy.ops.reset(hw);
00826 if (ret_val) {
00827 DEBUGOUT("Error resetting the PHY.\n");
00828 goto out;
00829 }
00830
00831
00832
00833
00834
00835 msec_delay(100);
00836
00837
00838
00839
00840
00841 if (phy->type == e1000_phy_igp) {
00842
00843 ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
00844 if (ret_val) {
00845 DEBUGOUT("Error Disabling LPLU D3\n");
00846 goto out;
00847 }
00848 }
00849
00850
00851 if (hw->phy.ops.set_d0_lplu_state) {
00852 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
00853 if (ret_val) {
00854 DEBUGOUT("Error Disabling LPLU D0\n");
00855 goto out;
00856 }
00857 }
00858
00859 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
00860 if (ret_val)
00861 goto out;
00862
00863 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
00864
00865 switch (phy->mdix) {
00866 case 1:
00867 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
00868 break;
00869 case 2:
00870 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
00871 break;
00872 case 0:
00873 default:
00874 data |= IGP01E1000_PSCR_AUTO_MDIX;
00875 break;
00876 }
00877 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
00878 if (ret_val)
00879 goto out;
00880
00881
00882 if (hw->mac.autoneg) {
00883
00884
00885
00886
00887
00888 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
00889
00890 ret_val = phy->ops.read_reg(hw,
00891 IGP01E1000_PHY_PORT_CONFIG,
00892 &data);
00893 if (ret_val)
00894 goto out;
00895
00896 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
00897 ret_val = phy->ops.write_reg(hw,
00898 IGP01E1000_PHY_PORT_CONFIG,
00899 data);
00900 if (ret_val)
00901 goto out;
00902
00903
00904 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
00905 if (ret_val)
00906 goto out;
00907
00908 data &= ~CR_1000T_MS_ENABLE;
00909 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
00910 if (ret_val)
00911 goto out;
00912 }
00913
00914 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
00915 if (ret_val)
00916 goto out;
00917
00918
00919 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
00920 ((data & CR_1000T_MS_VALUE) ?
00921 e1000_ms_force_master :
00922 e1000_ms_force_slave) :
00923 e1000_ms_auto;
00924
00925 switch (phy->ms_type) {
00926 case e1000_ms_force_master:
00927 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
00928 break;
00929 case e1000_ms_force_slave:
00930 data |= CR_1000T_MS_ENABLE;
00931 data &= ~(CR_1000T_MS_VALUE);
00932 break;
00933 case e1000_ms_auto:
00934 data &= ~CR_1000T_MS_ENABLE;
00935 default:
00936 break;
00937 }
00938 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
00939 if (ret_val)
00940 goto out;
00941 }
00942
00943 out:
00944 return ret_val;
00945 }
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 s32 igb_copper_link_autoneg(struct e1000_hw *hw)
00957 {
00958 struct e1000_phy_info *phy = &hw->phy;
00959 s32 ret_val;
00960 u16 phy_ctrl;
00961
00962 DEBUGFUNC("igb_copper_link_autoneg");
00963
00964
00965
00966
00967
00968 phy->autoneg_advertised &= phy->autoneg_mask;
00969
00970
00971
00972
00973
00974 if (phy->autoneg_advertised == 0)
00975 phy->autoneg_advertised = phy->autoneg_mask;
00976
00977 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
00978 ret_val = igb_phy_setup_autoneg(hw);
00979 if (ret_val) {
00980 DEBUGOUT("Error Setting up Auto-Negotiation\n");
00981 goto out;
00982 }
00983 DEBUGOUT("Restarting Auto-Neg\n");
00984
00985
00986
00987
00988
00989 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
00990 if (ret_val)
00991 goto out;
00992
00993 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
00994 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
00995 if (ret_val)
00996 goto out;
00997
00998
00999
01000
01001
01002 if (phy->autoneg_wait_to_complete) {
01003 ret_val = hw->mac.ops.wait_autoneg(hw);
01004 if (ret_val) {
01005 DEBUGOUT("Error while waiting for "
01006 "autoneg to complete\n");
01007 goto out;
01008 }
01009 }
01010
01011 hw->mac.get_link_status = true;
01012
01013 out:
01014 return ret_val;
01015 }
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
01027 {
01028 struct e1000_phy_info *phy = &hw->phy;
01029 s32 ret_val;
01030 u16 mii_autoneg_adv_reg;
01031 u16 mii_1000t_ctrl_reg = 0;
01032
01033 DEBUGFUNC("igb_phy_setup_autoneg");
01034
01035 phy->autoneg_advertised &= phy->autoneg_mask;
01036
01037
01038 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
01039 if (ret_val)
01040 goto out;
01041
01042 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
01043
01044 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
01045 &mii_1000t_ctrl_reg);
01046 if (ret_val)
01047 goto out;
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
01064 NWAY_AR_100TX_HD_CAPS |
01065 NWAY_AR_10T_FD_CAPS |
01066 NWAY_AR_10T_HD_CAPS);
01067 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
01068
01069 DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
01070
01071
01072 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
01073 DEBUGOUT("Advertise 10mb Half duplex\n");
01074 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
01075 }
01076
01077
01078 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
01079 DEBUGOUT("Advertise 10mb Full duplex\n");
01080 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
01081 }
01082
01083
01084 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
01085 DEBUGOUT("Advertise 100mb Half duplex\n");
01086 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
01087 }
01088
01089
01090 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
01091 DEBUGOUT("Advertise 100mb Full duplex\n");
01092 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
01093 }
01094
01095
01096 if (phy->autoneg_advertised & ADVERTISE_1000_HALF) {
01097 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
01098 }
01099
01100 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
01101 DEBUGOUT("Advertise 1000mb Full duplex\n");
01102 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
01103 }
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 switch (hw->fc.current_mode) {
01124 case e1000_fc_none:
01125
01126
01127
01128
01129 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
01130 break;
01131 case e1000_fc_rx_pause:
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
01143 break;
01144 case e1000_fc_tx_pause:
01145
01146
01147
01148
01149 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
01150 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
01151 break;
01152 case e1000_fc_full:
01153
01154
01155
01156
01157 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
01158 break;
01159 default:
01160 DEBUGOUT("Flow control param set incorrectly\n");
01161 ret_val = -E1000_ERR_CONFIG;
01162 goto out;
01163 }
01164
01165 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
01166 if (ret_val)
01167 goto out;
01168
01169 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
01170
01171 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
01172 ret_val = phy->ops.write_reg(hw,
01173 PHY_1000T_CTRL,
01174 mii_1000t_ctrl_reg);
01175 if (ret_val)
01176 goto out;
01177 }
01178
01179 out:
01180 return ret_val;
01181 }
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192 s32 igb_setup_copper_link_generic(struct e1000_hw *hw)
01193 {
01194 s32 ret_val;
01195 bool link;
01196
01197 DEBUGFUNC("igb_setup_copper_link_generic");
01198
01199 if (hw->mac.autoneg) {
01200
01201
01202
01203
01204 ret_val = igb_copper_link_autoneg(hw);
01205 if (ret_val)
01206 goto out;
01207 } else {
01208 #if 0
01209
01210
01211
01212
01213 DEBUGOUT("Forcing Speed and Duplex\n");
01214 ret_val = hw->phy.ops.force_speed_duplex(hw);
01215 if (ret_val) {
01216 DEBUGOUT("Error Forcing Speed and Duplex\n");
01217 goto out;
01218 }
01219 #endif
01220 }
01221
01222
01223
01224
01225
01226 ret_val = igb_phy_has_link_generic(hw,
01227 COPPER_LINK_UP_LIMIT,
01228 10,
01229 &link);
01230 if (ret_val)
01231 goto out;
01232
01233 if (link) {
01234 DEBUGOUT("Valid link established!!!\n");
01235 igb_config_collision_dist_generic(hw);
01236 ret_val = igb_config_fc_after_link_up_generic(hw);
01237 } else {
01238 DEBUGOUT("Unable to establish link!!!\n");
01239 }
01240
01241 out:
01242 return ret_val;
01243 }
01244
01245 #if 0
01246
01247
01248
01249
01250
01251
01252
01253
01254 s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
01255 {
01256 struct e1000_phy_info *phy = &hw->phy;
01257 s32 ret_val;
01258 u16 phy_data;
01259 bool link;
01260
01261 DEBUGFUNC("igb_phy_force_speed_duplex_igp");
01262
01263 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
01264 if (ret_val)
01265 goto out;
01266
01267 igb_phy_force_speed_duplex_setup(hw, &phy_data);
01268
01269 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
01270 if (ret_val)
01271 goto out;
01272
01273
01274
01275
01276
01277 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
01278 if (ret_val)
01279 goto out;
01280
01281 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
01282 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
01283
01284 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
01285 if (ret_val)
01286 goto out;
01287
01288 DEBUGOUT1("IGP PSCR: %X\n", phy_data);
01289
01290 usec_delay(1);
01291
01292 if (phy->autoneg_wait_to_complete) {
01293 DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
01294
01295 ret_val = igb_phy_has_link_generic(hw,
01296 PHY_FORCE_LIMIT,
01297 100000,
01298 &link);
01299 if (ret_val)
01300 goto out;
01301
01302 if (!link) {
01303 DEBUGOUT("Link taking longer than expected.\n");
01304 }
01305
01306 ret_val = igb_phy_has_link_generic(hw,
01307 PHY_FORCE_LIMIT,
01308 100000,
01309 &link);
01310 if (ret_val)
01311 goto out;
01312 }
01313
01314 out:
01315 return ret_val;
01316 }
01317 #endif
01318
01319 #if 0
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330 s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
01331 {
01332 struct e1000_phy_info *phy = &hw->phy;
01333 s32 ret_val;
01334 u16 phy_data;
01335 bool link;
01336
01337 DEBUGFUNC("igb_phy_force_speed_duplex_m88");
01338
01339
01340
01341
01342
01343 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
01344 if (ret_val)
01345 goto out;
01346
01347 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
01348 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
01349 if (ret_val)
01350 goto out;
01351
01352 DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
01353
01354 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
01355 if (ret_val)
01356 goto out;
01357
01358 igb_phy_force_speed_duplex_setup(hw, &phy_data);
01359
01360 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
01361 if (ret_val)
01362 goto out;
01363
01364
01365 ret_val = hw->phy.ops.commit(hw);
01366 if (ret_val)
01367 goto out;
01368
01369 if (phy->autoneg_wait_to_complete) {
01370 DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
01371
01372 ret_val = igb_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
01373 100000, &link);
01374 if (ret_val)
01375 goto out;
01376
01377 if (!link) {
01378
01379
01380
01381
01382 ret_val = phy->ops.write_reg(hw,
01383 M88E1000_PHY_PAGE_SELECT,
01384 0x001d);
01385 if (ret_val)
01386 goto out;
01387 ret_val = igb_phy_reset_dsp_generic(hw);
01388 if (ret_val)
01389 goto out;
01390 }
01391
01392
01393 ret_val = igb_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
01394 100000, &link);
01395 if (ret_val)
01396 goto out;
01397 }
01398
01399 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
01400 if (ret_val)
01401 goto out;
01402
01403
01404
01405
01406
01407
01408 phy_data |= M88E1000_EPSCR_TX_CLK_25;
01409 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
01410 if (ret_val)
01411 goto out;
01412
01413
01414
01415
01416
01417 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
01418 if (ret_val)
01419 goto out;
01420
01421 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
01422 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
01423
01424 out:
01425 return ret_val;
01426 }
01427 #endif
01428
01429 #if 0
01430
01431
01432
01433
01434
01435
01436
01437
01438 s32 igb_phy_force_speed_duplex_ife(struct e1000_hw *hw)
01439 {
01440 struct e1000_phy_info *phy = &hw->phy;
01441 s32 ret_val;
01442 u16 data;
01443 bool link;
01444
01445 DEBUGFUNC("igb_phy_force_speed_duplex_ife");
01446
01447 if (phy->type != e1000_phy_ife) {
01448 ret_val = igb_phy_force_speed_duplex_igp(hw);
01449 goto out;
01450 }
01451
01452 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
01453 if (ret_val)
01454 goto out;
01455
01456 igb_phy_force_speed_duplex_setup(hw, &data);
01457
01458 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
01459 if (ret_val)
01460 goto out;
01461
01462
01463 ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
01464 if (ret_val)
01465 goto out;
01466
01467 data &= ~IFE_PMC_AUTO_MDIX;
01468 data &= ~IFE_PMC_FORCE_MDIX;
01469
01470 ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
01471 if (ret_val)
01472 goto out;
01473
01474 DEBUGOUT1("IFE PMC: %X\n", data);
01475
01476 usec_delay(1);
01477
01478 if (phy->autoneg_wait_to_complete) {
01479 DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
01480
01481 ret_val = igb_phy_has_link_generic(hw,
01482 PHY_FORCE_LIMIT,
01483 100000,
01484 &link);
01485 if (ret_val)
01486 goto out;
01487
01488 if (!link) {
01489 DEBUGOUT("Link taking longer than expected.\n");
01490 }
01491
01492 ret_val = igb_phy_has_link_generic(hw,
01493 PHY_FORCE_LIMIT,
01494 100000,
01495 &link);
01496 if (ret_val)
01497 goto out;
01498 }
01499
01500 out:
01501 return ret_val;
01502 }
01503 #endif
01504
01505 #if 0
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518 void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
01519 {
01520 struct e1000_mac_info *mac = &hw->mac;
01521 u32 ctrl;
01522
01523 DEBUGFUNC("igb_phy_force_speed_duplex_setup");
01524
01525
01526 hw->fc.current_mode = e1000_fc_none;
01527
01528
01529 ctrl = E1000_READ_REG(hw, E1000_CTRL);
01530 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
01531 ctrl &= ~E1000_CTRL_SPD_SEL;
01532
01533
01534 ctrl &= ~E1000_CTRL_ASDE;
01535
01536
01537 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
01538
01539
01540 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
01541 ctrl &= ~E1000_CTRL_FD;
01542 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
01543 DEBUGOUT("Half Duplex\n");
01544 } else {
01545 ctrl |= E1000_CTRL_FD;
01546 *phy_ctrl |= MII_CR_FULL_DUPLEX;
01547 DEBUGOUT("Full Duplex\n");
01548 }
01549
01550
01551 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
01552 ctrl |= E1000_CTRL_SPD_100;
01553 *phy_ctrl |= MII_CR_SPEED_100;
01554 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
01555 DEBUGOUT("Forcing 100mb\n");
01556 } else {
01557 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
01558 *phy_ctrl |= MII_CR_SPEED_10;
01559 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
01560 DEBUGOUT("Forcing 10mb\n");
01561 }
01562
01563 igb_config_collision_dist_generic(hw);
01564
01565 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
01566 }
01567 #endif
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583 s32 igb_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
01584 {
01585 struct e1000_phy_info *phy = &hw->phy;
01586 s32 ret_val = E1000_SUCCESS;
01587 u16 data;
01588
01589 DEBUGFUNC("igb_set_d3_lplu_state_generic");
01590
01591 if (!(hw->phy.ops.read_reg))
01592 goto out;
01593
01594 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
01595 if (ret_val)
01596 goto out;
01597
01598 if (!active) {
01599 data &= ~IGP02E1000_PM_D3_LPLU;
01600 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
01601 data);
01602 if (ret_val)
01603 goto out;
01604
01605
01606
01607
01608
01609
01610 if (phy->smart_speed == e1000_smart_speed_on) {
01611 ret_val = phy->ops.read_reg(hw,
01612 IGP01E1000_PHY_PORT_CONFIG,
01613 &data);
01614 if (ret_val)
01615 goto out;
01616
01617 data |= IGP01E1000_PSCFR_SMART_SPEED;
01618 ret_val = phy->ops.write_reg(hw,
01619 IGP01E1000_PHY_PORT_CONFIG,
01620 data);
01621 if (ret_val)
01622 goto out;
01623 } else if (phy->smart_speed == e1000_smart_speed_off) {
01624 ret_val = phy->ops.read_reg(hw,
01625 IGP01E1000_PHY_PORT_CONFIG,
01626 &data);
01627 if (ret_val)
01628 goto out;
01629
01630 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
01631 ret_val = phy->ops.write_reg(hw,
01632 IGP01E1000_PHY_PORT_CONFIG,
01633 data);
01634 if (ret_val)
01635 goto out;
01636 }
01637 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
01638 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
01639 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
01640 data |= IGP02E1000_PM_D3_LPLU;
01641 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
01642 data);
01643 if (ret_val)
01644 goto out;
01645
01646
01647 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
01648 &data);
01649 if (ret_val)
01650 goto out;
01651
01652 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
01653 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
01654 data);
01655 }
01656
01657 out:
01658 return ret_val;
01659 }
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669 s32 igb_check_downshift_generic(struct e1000_hw *hw)
01670 {
01671 struct e1000_phy_info *phy = &hw->phy;
01672 s32 ret_val;
01673 u16 phy_data, offset, mask;
01674
01675 DEBUGFUNC("igb_check_downshift_generic");
01676
01677 switch (phy->type) {
01678 case e1000_phy_m88:
01679 case e1000_phy_gg82563:
01680 offset = M88E1000_PHY_SPEC_STATUS;
01681 mask = M88E1000_PSSR_DOWNSHIFT;
01682 break;
01683 case e1000_phy_igp_2:
01684 case e1000_phy_igp:
01685 case e1000_phy_igp_3:
01686 offset = IGP01E1000_PHY_LINK_HEALTH;
01687 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
01688 break;
01689 default:
01690
01691 phy->speed_downgraded = false;
01692 ret_val = E1000_SUCCESS;
01693 goto out;
01694 }
01695
01696 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
01697
01698 if (!ret_val)
01699 phy->speed_downgraded = (phy_data & mask) ? true : false;
01700
01701 out:
01702 return ret_val;
01703 }
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713 s32 igb_check_polarity_m88(struct e1000_hw *hw)
01714 {
01715 struct e1000_phy_info *phy = &hw->phy;
01716 s32 ret_val;
01717 u16 data;
01718
01719 DEBUGFUNC("igb_check_polarity_m88");
01720
01721 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
01722
01723 if (!ret_val)
01724 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
01725 ? e1000_rev_polarity_reversed
01726 : e1000_rev_polarity_normal;
01727
01728 return ret_val;
01729 }
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740 s32 igb_check_polarity_igp(struct e1000_hw *hw)
01741 {
01742 struct e1000_phy_info *phy = &hw->phy;
01743 s32 ret_val;
01744 u16 data, offset, mask;
01745
01746 DEBUGFUNC("igb_check_polarity_igp");
01747
01748
01749
01750
01751
01752 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
01753 if (ret_val)
01754 goto out;
01755
01756 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
01757 IGP01E1000_PSSR_SPEED_1000MBPS) {
01758 offset = IGP01E1000_PHY_PCS_INIT_REG;
01759 mask = IGP01E1000_PHY_POLARITY_MASK;
01760 } else {
01761
01762
01763
01764
01765 offset = IGP01E1000_PHY_PORT_STATUS;
01766 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
01767 }
01768
01769 ret_val = phy->ops.read_reg(hw, offset, &data);
01770
01771 if (!ret_val)
01772 phy->cable_polarity = (data & mask)
01773 ? e1000_rev_polarity_reversed
01774 : e1000_rev_polarity_normal;
01775
01776 out:
01777 return ret_val;
01778 }
01779
01780
01781
01782
01783
01784
01785
01786 s32 igb_check_polarity_ife(struct e1000_hw *hw)
01787 {
01788 struct e1000_phy_info *phy = &hw->phy;
01789 s32 ret_val;
01790 u16 phy_data, offset, mask;
01791
01792 DEBUGFUNC("igb_check_polarity_ife");
01793
01794
01795
01796
01797 if (phy->polarity_correction) {
01798 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
01799 mask = IFE_PESC_POLARITY_REVERSED;
01800 } else {
01801 offset = IFE_PHY_SPECIAL_CONTROL;
01802 mask = IFE_PSC_FORCE_POLARITY;
01803 }
01804
01805 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
01806
01807 if (!ret_val)
01808 phy->cable_polarity = (phy_data & mask)
01809 ? e1000_rev_polarity_reversed
01810 : e1000_rev_polarity_normal;
01811
01812 return ret_val;
01813 }
01814
01815
01816
01817
01818
01819
01820
01821
01822 s32 igb_wait_autoneg_generic(struct e1000_hw *hw)
01823 {
01824 s32 ret_val = E1000_SUCCESS;
01825 u16 i, phy_status;
01826
01827 DEBUGFUNC("igb_wait_autoneg_generic");
01828
01829 if (!(hw->phy.ops.read_reg))
01830 return E1000_SUCCESS;
01831
01832
01833 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
01834 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01835 if (ret_val)
01836 break;
01837 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01838 if (ret_val)
01839 break;
01840 if (phy_status & MII_SR_AUTONEG_COMPLETE)
01841 break;
01842 msec_delay(100);
01843 }
01844
01845
01846
01847
01848
01849 return ret_val;
01850 }
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861 s32 igb_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
01862 u32 usec_interval, bool *success)
01863 {
01864 s32 ret_val = E1000_SUCCESS;
01865 u16 i, phy_status;
01866
01867 DEBUGFUNC("igb_phy_has_link_generic");
01868
01869 if (!(hw->phy.ops.read_reg))
01870 return E1000_SUCCESS;
01871
01872 for (i = 0; i < iterations; i++) {
01873
01874
01875
01876
01877
01878 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01879 if (ret_val) {
01880
01881
01882
01883
01884
01885 usec_delay(usec_interval);
01886 }
01887 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01888 if (ret_val)
01889 break;
01890 if (phy_status & MII_SR_LINK_STATUS)
01891 break;
01892 if (usec_interval >= 1000)
01893 msec_delay_irq(usec_interval/1000);
01894 else
01895 usec_delay(usec_interval);
01896 }
01897
01898 *success = (i < iterations) ? true : false;
01899
01900 return ret_val;
01901 }
01902
01903 #if 0
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919 s32 igb_get_cable_length_m88(struct e1000_hw *hw)
01920 {
01921 struct e1000_phy_info *phy = &hw->phy;
01922 s32 ret_val;
01923 u16 phy_data, index;
01924
01925 DEBUGFUNC("igb_get_cable_length_m88");
01926
01927 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
01928 if (ret_val)
01929 goto out;
01930
01931 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
01932 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
01933 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
01934 ret_val = -E1000_ERR_PHY;
01935 goto out;
01936 }
01937
01938 phy->min_cable_length = e1000_m88_cable_length_table[index];
01939 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
01940
01941 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
01942
01943 out:
01944 return ret_val;
01945 }
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958 s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
01959 {
01960 struct e1000_phy_info *phy = &hw->phy;
01961 s32 ret_val = E1000_SUCCESS;
01962 u16 phy_data, i, agc_value = 0;
01963 u16 cur_agc_index, max_agc_index = 0;
01964 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
01965 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
01966 {IGP02E1000_PHY_AGC_A,
01967 IGP02E1000_PHY_AGC_B,
01968 IGP02E1000_PHY_AGC_C,
01969 IGP02E1000_PHY_AGC_D};
01970
01971 DEBUGFUNC("igb_get_cable_length_igp_2");
01972
01973
01974 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
01975 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
01976 if (ret_val)
01977 goto out;
01978
01979
01980
01981
01982
01983
01984
01985 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
01986 IGP02E1000_AGC_LENGTH_MASK;
01987
01988
01989 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
01990 (cur_agc_index == 0)) {
01991 ret_val = -E1000_ERR_PHY;
01992 goto out;
01993 }
01994
01995
01996 if (e1000_igp_2_cable_length_table[min_agc_index] >
01997 e1000_igp_2_cable_length_table[cur_agc_index])
01998 min_agc_index = cur_agc_index;
01999 if (e1000_igp_2_cable_length_table[max_agc_index] <
02000 e1000_igp_2_cable_length_table[cur_agc_index])
02001 max_agc_index = cur_agc_index;
02002
02003 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
02004 }
02005
02006 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
02007 e1000_igp_2_cable_length_table[max_agc_index]);
02008 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
02009
02010
02011 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
02012 (agc_value - IGP02E1000_AGC_RANGE) : 0;
02013 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
02014
02015 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
02016
02017 out:
02018 return ret_val;
02019 }
02020 #endif
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032 s32 igb_get_phy_info_m88(struct e1000_hw *hw)
02033 {
02034 struct e1000_phy_info *phy = &hw->phy;
02035 s32 ret_val;
02036 u16 phy_data;
02037 bool link;
02038
02039 DEBUGFUNC("igb_get_phy_info_m88");
02040
02041 if (phy->media_type != e1000_media_type_copper) {
02042 DEBUGOUT("Phy info is only valid for copper media\n");
02043 ret_val = -E1000_ERR_CONFIG;
02044 goto out;
02045 }
02046
02047 ret_val = igb_phy_has_link_generic(hw, 1, 0, &link);
02048 if (ret_val)
02049 goto out;
02050
02051 if (!link) {
02052 DEBUGOUT("Phy info is only valid if link is up\n");
02053 ret_val = -E1000_ERR_CONFIG;
02054 goto out;
02055 }
02056
02057 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
02058 if (ret_val)
02059 goto out;
02060
02061 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
02062 ? true : false;
02063
02064 ret_val = igb_check_polarity_m88(hw);
02065 if (ret_val)
02066 goto out;
02067
02068 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
02069 if (ret_val)
02070 goto out;
02071
02072 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
02073
02074 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
02075 #if 0
02076 ret_val = hw->phy.ops.get_cable_length(hw);
02077 #endif
02078 ret_val = -E1000_ERR_CONFIG;
02079 if (ret_val)
02080 goto out;
02081 #if 0
02082 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
02083 if (ret_val)
02084 goto out;
02085
02086 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
02087 ? e1000_1000t_rx_status_ok
02088 : e1000_1000t_rx_status_not_ok;
02089
02090 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
02091 ? e1000_1000t_rx_status_ok
02092 : e1000_1000t_rx_status_not_ok;
02093 #endif
02094 } else {
02095
02096 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
02097 phy->local_rx = e1000_1000t_rx_status_undefined;
02098 phy->remote_rx = e1000_1000t_rx_status_undefined;
02099 }
02100
02101 out:
02102 return ret_val;
02103 }
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114 s32 igb_get_phy_info_igp(struct e1000_hw *hw)
02115 {
02116 struct e1000_phy_info *phy = &hw->phy;
02117 s32 ret_val;
02118 u16 data;
02119 bool link;
02120
02121 DEBUGFUNC("igb_get_phy_info_igp");
02122
02123 ret_val = igb_phy_has_link_generic(hw, 1, 0, &link);
02124 if (ret_val)
02125 goto out;
02126
02127 if (!link) {
02128 DEBUGOUT("Phy info is only valid if link is up\n");
02129 ret_val = -E1000_ERR_CONFIG;
02130 goto out;
02131 }
02132
02133 phy->polarity_correction = true;
02134
02135 ret_val = igb_check_polarity_igp(hw);
02136 if (ret_val)
02137 goto out;
02138
02139 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
02140 if (ret_val)
02141 goto out;
02142
02143 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
02144
02145 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
02146 IGP01E1000_PSSR_SPEED_1000MBPS) {
02147 #if 0
02148 ret_val = phy->ops.get_cable_length(hw);
02149 #endif
02150 ret_val = -E1000_ERR_CONFIG;
02151 if (ret_val)
02152 goto out;
02153 #if 0
02154 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
02155 if (ret_val)
02156 goto out;
02157
02158 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
02159 ? e1000_1000t_rx_status_ok
02160 : e1000_1000t_rx_status_not_ok;
02161
02162 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
02163 ? e1000_1000t_rx_status_ok
02164 : e1000_1000t_rx_status_not_ok;
02165 #endif
02166 } else {
02167 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
02168 phy->local_rx = e1000_1000t_rx_status_undefined;
02169 phy->remote_rx = e1000_1000t_rx_status_undefined;
02170 }
02171
02172 out:
02173 return ret_val;
02174 }
02175
02176
02177
02178
02179
02180
02181
02182
02183 s32 igb_phy_sw_reset_generic(struct e1000_hw *hw)
02184 {
02185 s32 ret_val = E1000_SUCCESS;
02186 u16 phy_ctrl;
02187
02188 DEBUGFUNC("igb_phy_sw_reset_generic");
02189
02190 if (!(hw->phy.ops.read_reg))
02191 goto out;
02192
02193 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
02194 if (ret_val)
02195 goto out;
02196
02197 phy_ctrl |= MII_CR_RESET;
02198 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
02199 if (ret_val)
02200 goto out;
02201
02202 usec_delay(1);
02203
02204 out:
02205 return ret_val;
02206 }
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217 s32 igb_phy_hw_reset_generic(struct e1000_hw *hw)
02218 {
02219 struct e1000_phy_info *phy = &hw->phy;
02220 s32 ret_val = E1000_SUCCESS;
02221 u32 ctrl;
02222
02223 DEBUGFUNC("igb_phy_hw_reset_generic");
02224
02225 ret_val = phy->ops.check_reset_block(hw);
02226 if (ret_val) {
02227 ret_val = E1000_SUCCESS;
02228 goto out;
02229 }
02230
02231 ret_val = phy->ops.acquire(hw);
02232 if (ret_val)
02233 goto out;
02234
02235 ctrl = E1000_READ_REG(hw, E1000_CTRL);
02236 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
02237 E1000_WRITE_FLUSH(hw);
02238
02239 usec_delay(phy->reset_delay_us);
02240
02241 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
02242 E1000_WRITE_FLUSH(hw);
02243
02244 usec_delay(150);
02245
02246 phy->ops.release(hw);
02247
02248 ret_val = phy->ops.get_cfg_done(hw);
02249
02250 out:
02251 return ret_val;
02252 }
02253
02254
02255
02256
02257
02258
02259
02260
02261 s32 igb_get_cfg_done_generic(struct e1000_hw *hw __unused)
02262 {
02263 DEBUGFUNC("igb_get_cfg_done_generic");
02264
02265 msec_delay_irq(10);
02266
02267 return E1000_SUCCESS;
02268 }
02269
02270
02271
02272
02273
02274
02275
02276 s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
02277 {
02278 DEBUGOUT("Running IGP 3 PHY init script\n");
02279
02280
02281
02282 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
02283
02284 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
02285
02286 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
02287
02288 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
02289
02290 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
02291
02292 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
02293
02294 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
02295
02296 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
02297
02298 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
02299
02300 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
02301
02302 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
02303
02304 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
02305
02306 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
02307
02308 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
02309
02310 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
02311
02312 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
02313
02314 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
02315
02316 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
02317
02318 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
02319
02320 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
02321
02322 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
02323
02324 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
02325
02326 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
02327
02328 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
02329
02330 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
02331
02332 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
02333
02334
02335
02336
02337 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
02338
02339 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
02340
02341
02342
02343
02344 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
02345
02346 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
02347
02348 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
02349
02350 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
02351
02352 return E1000_SUCCESS;
02353 }
02354
02355
02356
02357
02358
02359
02360
02361 enum e1000_phy_type igb_get_phy_type_from_id(u32 phy_id)
02362 {
02363 enum e1000_phy_type phy_type = e1000_phy_unknown;
02364
02365 switch (phy_id) {
02366 case M88E1000_I_PHY_ID:
02367 case M88E1000_E_PHY_ID:
02368 case M88E1111_I_PHY_ID:
02369 case M88E1011_I_PHY_ID:
02370 phy_type = e1000_phy_m88;
02371 break;
02372 case IGP01E1000_I_PHY_ID:
02373 phy_type = e1000_phy_igp_2;
02374 break;
02375 case GG82563_E_PHY_ID:
02376 phy_type = e1000_phy_gg82563;
02377 break;
02378 case IGP03E1000_E_PHY_ID:
02379 phy_type = e1000_phy_igp_3;
02380 break;
02381 case IFE_E_PHY_ID:
02382 case IFE_PLUS_E_PHY_ID:
02383 case IFE_C_E_PHY_ID:
02384 phy_type = e1000_phy_ife;
02385 break;
02386 default:
02387 phy_type = e1000_phy_unknown;
02388 break;
02389 }
02390 return phy_type;
02391 }
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401 s32 igb_determine_phy_address(struct e1000_hw *hw)
02402 {
02403 s32 ret_val = -E1000_ERR_PHY_TYPE;
02404 u32 phy_addr = 0;
02405 u32 i;
02406 enum e1000_phy_type phy_type = e1000_phy_unknown;
02407
02408 hw->phy.id = phy_type;
02409
02410 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
02411 hw->phy.addr = phy_addr;
02412 i = 0;
02413
02414 do {
02415 igb_get_phy_id(hw);
02416 phy_type = igb_get_phy_type_from_id(hw->phy.id);
02417
02418
02419
02420
02421
02422 if (phy_type != e1000_phy_unknown) {
02423 ret_val = E1000_SUCCESS;
02424 goto out;
02425 }
02426 msec_delay(1);
02427 i++;
02428 } while (i < 10);
02429 }
02430
02431 out:
02432 return ret_val;
02433 }
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443 void igb_power_up_phy_copper(struct e1000_hw *hw)
02444 {
02445 u16 mii_reg = 0;
02446
02447
02448 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
02449 mii_reg &= ~MII_CR_POWER_DOWN;
02450 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
02451 }
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461 void igb_power_down_phy_copper(struct e1000_hw *hw)
02462 {
02463 u16 mii_reg = 0;
02464
02465
02466 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
02467 mii_reg |= MII_CR_POWER_DOWN;
02468 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
02469 msec_delay(1);
02470 }