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