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 "e1000e.h"
00032
00033 static u32 e1000e_hash_mc_addr_generic(struct e1000_hw *hw, u8 *mc_addr);
00034 static s32 e1000e_set_default_fc_generic(struct e1000_hw *hw);
00035 static s32 e1000e_commit_fc_settings_generic(struct e1000_hw *hw);
00036 static s32 e1000e_poll_fiber_serdes_link_generic(struct e1000_hw *hw);
00037 static s32 e1000e_validate_mdi_setting_generic(struct e1000_hw *hw);
00038 static void e1000e_set_lan_id_multi_port_pcie(struct e1000_hw *hw);
00039
00040
00041
00042
00043
00044
00045
00046 void e1000e_init_mac_ops_generic(struct e1000_hw *hw)
00047 {
00048 struct e1000_mac_info *mac = &hw->mac;
00049
00050 mac->ops.set_lan_id = e1000e_set_lan_id_multi_port_pcie;
00051 mac->ops.read_mac_addr = e1000e_read_mac_addr_generic;
00052 mac->ops.config_collision_dist = e1000e_config_collision_dist;
00053
00054 mac->ops.wait_autoneg = e1000e_wait_autoneg;
00055
00056 #if 0
00057 mac->ops.mng_host_if_write = e1000e_mng_host_if_write_generic;
00058 mac->ops.mng_write_cmd_header = e1000e_mng_write_cmd_header_generic;
00059 mac->ops.mng_enable_host_if = e1000e_mng_enable_host_if_generic;
00060 #endif
00061
00062 mac->ops.rar_set = e1000e_rar_set;
00063 mac->ops.validate_mdi_setting = e1000e_validate_mdi_setting_generic;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
00075 {
00076 struct e1000_mac_info *mac = &hw->mac;
00077 struct e1000_bus_info *bus = &hw->bus;
00078
00079 s32 ret_val;
00080 u16 pcie_link_status;
00081
00082 bus->type = e1000_bus_type_pci_express;
00083 bus->speed = e1000_bus_speed_2500;
00084
00085 ret_val = e1000e_read_pcie_cap_reg(hw,
00086 PCIE_LINK_STATUS,
00087 &pcie_link_status);
00088 if (ret_val)
00089 bus->width = e1000_bus_width_unknown;
00090 else
00091 bus->width = (enum e1000_bus_width)((pcie_link_status &
00092 PCIE_LINK_WIDTH_MASK) >>
00093 PCIE_LINK_WIDTH_SHIFT);
00094
00095 mac->ops.set_lan_id(hw);
00096
00097 return E1000_SUCCESS;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 static void e1000e_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
00109 {
00110 struct e1000_bus_info *bus = &hw->bus;
00111 u32 reg;
00112
00113
00114
00115
00116
00117 reg = er32(STATUS);
00118 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 void e1000e_set_lan_id_single_port(struct e1000_hw *hw)
00128 {
00129 struct e1000_bus_info *bus = &hw->bus;
00130
00131 bus->func = 0;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141 void e1000e_clear_vfta_generic(struct e1000_hw *hw)
00142 {
00143 u32 offset;
00144
00145 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
00146 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
00147 e1e_flush();
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 void e1000e_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
00161 {
00162 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
00163 e1e_flush();
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
00176 {
00177 u32 i;
00178 u8 mac_addr[ETH_ADDR_LEN] = {0};
00179
00180
00181 e_dbg("Programming MAC Address into RAR[0]\n");
00182
00183 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
00184
00185
00186 e_dbg("Clearing RAR[1-%u]\n", rar_count-1);
00187 for (i = 1; i < rar_count; i++)
00188 hw->mac.ops.rar_set(hw, mac_addr, i);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 s32 e1000e_check_alt_mac_addr_generic(struct e1000_hw *hw)
00204 {
00205 u32 i;
00206 s32 ret_val = E1000_SUCCESS;
00207 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
00208 u8 alt_mac_addr[ETH_ADDR_LEN];
00209
00210 ret_val = e1000e_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
00211 &nvm_alt_mac_addr_offset);
00212 if (ret_val) {
00213 e_dbg("NVM Read Error\n");
00214 goto out;
00215 }
00216
00217 if (nvm_alt_mac_addr_offset == 0xFFFF) {
00218
00219 goto out;
00220 }
00221
00222 if (hw->bus.func == E1000_FUNC_1)
00223 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
00224 for (i = 0; i < ETH_ADDR_LEN; i += 2) {
00225 offset = nvm_alt_mac_addr_offset + (i >> 1);
00226 ret_val = e1000e_read_nvm(hw, offset, 1, &nvm_data);
00227 if (ret_val) {
00228 e_dbg("NVM Read Error\n");
00229 goto out;
00230 }
00231
00232 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
00233 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
00234 }
00235
00236
00237 if (alt_mac_addr[0] & 0x01) {
00238 e_dbg("Ignoring Alternate Mac Address with MC bit set\n");
00239 goto out;
00240 }
00241
00242
00243
00244
00245
00246
00247 hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
00248
00249 out:
00250 return ret_val;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 void e1000e_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
00263 {
00264 u32 rar_low, rar_high;
00265
00266
00267
00268
00269
00270 rar_low = ((u32) addr[0] |
00271 ((u32) addr[1] << 8) |
00272 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
00273
00274 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
00275
00276
00277 if (rar_low || rar_high)
00278 rar_high |= E1000_RAH_AV;
00279
00280
00281
00282
00283
00284
00285 ew32(RAL(index), rar_low);
00286 e1e_flush();
00287 ew32(RAH(index), rar_high);
00288 e1e_flush();
00289 }
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 void e1000e_mta_set_generic(struct e1000_hw *hw, u32 hash_value)
00302 {
00303 u32 hash_bit, hash_reg, mta;
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
00316 hash_bit = hash_value & 0x1F;
00317
00318 mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
00319
00320 mta |= (1 << hash_bit);
00321
00322 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
00323 e1e_flush();
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 void e1000e_update_mc_addr_list_generic(struct e1000_hw *hw,
00336 u8 *mc_addr_list, u32 mc_addr_count)
00337 {
00338 u32 hash_value, hash_bit, hash_reg;
00339 int i;
00340
00341
00342 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
00343
00344
00345 for (i = 0; (u32) i < mc_addr_count; i++) {
00346 hash_value = e1000e_hash_mc_addr_generic(hw, mc_addr_list);
00347
00348 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
00349 hash_bit = hash_value & 0x1F;
00350
00351 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
00352 mc_addr_list += (ETH_ADDR_LEN);
00353 }
00354
00355
00356 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
00357 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]);
00358 e1e_flush();
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 static u32 e1000e_hash_mc_addr_generic(struct e1000_hw *hw, u8 *mc_addr)
00371 {
00372 u32 hash_value, hash_mask;
00373 u8 bit_shift = 0;
00374
00375
00376 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
00377
00378
00379
00380
00381
00382 while (hash_mask >> bit_shift != 0xFF)
00383 bit_shift++;
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 switch (hw->mac.mc_filter_type) {
00412 default:
00413 case 0:
00414 break;
00415 case 1:
00416 bit_shift += 1;
00417 break;
00418 case 2:
00419 bit_shift += 2;
00420 break;
00421 case 3:
00422 bit_shift += 4;
00423 break;
00424 }
00425
00426 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
00427 (((u16) mc_addr[5]) << bit_shift)));
00428
00429 return hash_value;
00430 }
00431
00432
00433
00434
00435
00436
00437
00438 void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw __unused)
00439 {
00440 #if 0
00441 er32(CRCERRS);
00442 er32(SYMERRS);
00443 er32(MPC);
00444 er32(SCC);
00445 er32(ECOL);
00446 er32(MCC);
00447 er32(LATECOL);
00448 er32(COLC);
00449 er32(DC);
00450 er32(SEC);
00451 er32(RLEC);
00452 er32(XONRXC);
00453 er32(XONTXC);
00454 er32(XOFFRXC);
00455 er32(XOFFTXC);
00456 er32(FCRUC);
00457 er32(GPRC);
00458 er32(BPRC);
00459 er32(MPRC);
00460 er32(GPTC);
00461 er32(GORCL);
00462 er32(GORCH);
00463 er32(GOTCL);
00464 er32(GOTCH);
00465 er32(RNBC);
00466 er32(RUC);
00467 er32(RFC);
00468 er32(ROC);
00469 er32(RJC);
00470 er32(TORL);
00471 er32(TORH);
00472 er32(TOTL);
00473 er32(TOTH);
00474 er32(TPR);
00475 er32(TPT);
00476 er32(MPTC);
00477 er32(BPTC);
00478 #endif
00479 }
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
00490 {
00491 struct e1000_mac_info *mac = &hw->mac;
00492 s32 ret_val;
00493 bool link;
00494
00495
00496
00497
00498
00499
00500
00501 if (!mac->get_link_status) {
00502 ret_val = E1000_SUCCESS;
00503 goto out;
00504 }
00505
00506
00507
00508
00509
00510
00511 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
00512 if (ret_val)
00513 goto out;
00514
00515 if (!link)
00516 goto out;
00517
00518 mac->get_link_status = false;
00519
00520
00521
00522
00523
00524 e1000e_check_downshift(hw);
00525
00526
00527
00528
00529
00530 if (!mac->autoneg) {
00531 ret_val = -E1000_ERR_CONFIG;
00532 goto out;
00533 }
00534
00535
00536
00537
00538
00539
00540 e1000e_config_collision_dist(hw);
00541
00542
00543
00544
00545
00546
00547
00548 ret_val = e1000e_config_fc_after_link_up(hw);
00549 if (ret_val)
00550 e_dbg("Error configuring flow control\n");
00551
00552 out:
00553 return ret_val;
00554 }
00555
00556
00557
00558
00559
00560
00561
00562
00563 s32 e1000e_check_for_fiber_link(struct e1000_hw *hw)
00564 {
00565 struct e1000_mac_info *mac = &hw->mac;
00566 u32 rxcw;
00567 u32 ctrl;
00568 u32 status;
00569 s32 ret_val = E1000_SUCCESS;
00570
00571 ctrl = er32(CTRL);
00572 status = er32(STATUS);
00573 rxcw = er32(RXCW);
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
00585 (!(rxcw & E1000_RXCW_C))) {
00586 if (mac->autoneg_failed == 0) {
00587 mac->autoneg_failed = 1;
00588 goto out;
00589 }
00590 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
00591
00592
00593 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
00594
00595
00596 ctrl = er32(CTRL);
00597 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
00598 ew32(CTRL, ctrl);
00599
00600
00601 ret_val = e1000e_config_fc_after_link_up(hw);
00602 if (ret_val) {
00603 e_dbg("Error configuring flow control\n");
00604 goto out;
00605 }
00606 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
00607
00608
00609
00610
00611
00612
00613 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
00614 ew32(TXCW, mac->txcw);
00615 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
00616
00617 mac->serdes_has_link = true;
00618 }
00619
00620 out:
00621 return ret_val;
00622 }
00623
00624
00625
00626
00627
00628
00629
00630
00631 s32 e1000e_check_for_serdes_link(struct e1000_hw *hw)
00632 {
00633 struct e1000_mac_info *mac = &hw->mac;
00634 u32 rxcw;
00635 u32 ctrl;
00636 u32 status;
00637 s32 ret_val = E1000_SUCCESS;
00638
00639 ctrl = er32(CTRL);
00640 status = er32(STATUS);
00641 rxcw = er32(RXCW);
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
00652 if (mac->autoneg_failed == 0) {
00653 mac->autoneg_failed = 1;
00654 goto out;
00655 }
00656 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
00657
00658
00659 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
00660
00661
00662 ctrl = er32(CTRL);
00663 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
00664 ew32(CTRL, ctrl);
00665
00666
00667 ret_val = e1000e_config_fc_after_link_up(hw);
00668 if (ret_val) {
00669 e_dbg("Error configuring flow control\n");
00670 goto out;
00671 }
00672 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
00673
00674
00675
00676
00677
00678
00679 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
00680 ew32(TXCW, mac->txcw);
00681 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
00682
00683 mac->serdes_has_link = true;
00684 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
00685
00686
00687
00688
00689
00690
00691 udelay(10);
00692 rxcw = er32(RXCW);
00693 if (rxcw & E1000_RXCW_SYNCH) {
00694 if (!(rxcw & E1000_RXCW_IV)) {
00695 mac->serdes_has_link = true;
00696 e_dbg("SERDES: Link up - forced.\n");
00697 }
00698 } else {
00699 mac->serdes_has_link = false;
00700 e_dbg("SERDES: Link down - force failed.\n");
00701 }
00702 }
00703
00704 if (E1000_TXCW_ANE & er32(TXCW)) {
00705 status = er32(STATUS);
00706 if (status & E1000_STATUS_LU) {
00707
00708 udelay(10);
00709 rxcw = er32(RXCW);
00710 if (rxcw & E1000_RXCW_SYNCH) {
00711 if (!(rxcw & E1000_RXCW_IV)) {
00712 mac->serdes_has_link = true;
00713 e_dbg("SERDES: Link up - autoneg "
00714 "completed sucessfully.\n");
00715 } else {
00716 mac->serdes_has_link = false;
00717 e_dbg("SERDES: Link down - invalid"
00718 "codewords detected in autoneg.\n");
00719 }
00720 } else {
00721 mac->serdes_has_link = false;
00722 e_dbg("SERDES: Link down - no sync.\n");
00723 }
00724 } else {
00725 mac->serdes_has_link = false;
00726 e_dbg("SERDES: Link down - autoneg failed\n");
00727 }
00728 }
00729
00730 out:
00731 return ret_val;
00732 }
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744 s32 e1000e_setup_link(struct e1000_hw *hw)
00745 {
00746 s32 ret_val = E1000_SUCCESS;
00747
00748
00749
00750
00751
00752 if (hw->phy.ops.check_reset_block)
00753 if (e1000e_check_reset_block(hw))
00754 goto out;
00755
00756
00757
00758
00759
00760 if (hw->fc.requested_mode == e1000_fc_default) {
00761 ret_val = e1000e_set_default_fc_generic(hw);
00762 if (ret_val)
00763 goto out;
00764 }
00765
00766
00767
00768
00769
00770 hw->fc.current_mode = hw->fc.requested_mode;
00771
00772 e_dbg("After fix-ups FlowControl is now = %x\n",
00773 hw->fc.current_mode);
00774
00775
00776 ret_val = hw->mac.ops.setup_physical_interface(hw);
00777 if (ret_val)
00778 goto out;
00779
00780
00781
00782
00783
00784
00785
00786 e_dbg("Initializing the Flow Control address, type and timer regs\n");
00787 ew32(FCT, FLOW_CONTROL_TYPE);
00788 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
00789 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
00790
00791 ew32(FCTTV, hw->fc.pause_time);
00792
00793 ret_val = e1000e_set_fc_watermarks(hw);
00794
00795 out:
00796 return ret_val;
00797 }
00798
00799
00800
00801
00802
00803
00804
00805
00806 s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw)
00807 {
00808 u32 ctrl;
00809 s32 ret_val = E1000_SUCCESS;
00810
00811 ctrl = er32(CTRL);
00812
00813
00814 ctrl &= ~E1000_CTRL_LRST;
00815
00816 e1000e_config_collision_dist(hw);
00817
00818 ret_val = e1000e_commit_fc_settings_generic(hw);
00819 if (ret_val)
00820 goto out;
00821
00822
00823
00824
00825
00826
00827
00828
00829 e_dbg("Auto-negotiation enabled\n");
00830
00831 ew32(CTRL, ctrl);
00832 e1e_flush();
00833 msleep(1);
00834
00835
00836
00837
00838
00839
00840 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
00841 (er32(CTRL) & E1000_CTRL_SWDPIN1)) {
00842 ret_val = e1000e_poll_fiber_serdes_link_generic(hw);
00843 } else {
00844 e_dbg("No signal detected\n");
00845 }
00846
00847 out:
00848 return ret_val;
00849 }
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859 void e1000e_config_collision_dist(struct e1000_hw *hw)
00860 {
00861 u32 tctl;
00862
00863 tctl = er32(TCTL);
00864
00865 tctl &= ~E1000_TCTL_COLD;
00866 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
00867
00868 ew32(TCTL, tctl);
00869 e1e_flush();
00870 }
00871
00872
00873
00874
00875
00876
00877
00878
00879 static s32 e1000e_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
00880 {
00881 struct e1000_mac_info *mac = &hw->mac;
00882 u32 i, status;
00883 s32 ret_val = E1000_SUCCESS;
00884
00885
00886
00887
00888
00889
00890
00891
00892 for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
00893 msleep(10);
00894 status = er32(STATUS);
00895 if (status & E1000_STATUS_LU)
00896 break;
00897 }
00898 if (i == FIBER_LINK_UP_LIMIT) {
00899 e_dbg("Never got a valid link from auto-neg!!!\n");
00900 mac->autoneg_failed = 1;
00901
00902
00903
00904
00905
00906
00907 ret_val = hw->mac.ops.check_for_link(hw);
00908 if (ret_val) {
00909 e_dbg("Error while checking for link\n");
00910 goto out;
00911 }
00912 mac->autoneg_failed = 0;
00913 } else {
00914 mac->autoneg_failed = 0;
00915 e_dbg("Valid Link Found\n");
00916 }
00917
00918 out:
00919 return ret_val;
00920 }
00921
00922
00923
00924
00925
00926
00927
00928
00929 static s32 e1000e_commit_fc_settings_generic(struct e1000_hw *hw)
00930 {
00931 struct e1000_mac_info *mac = &hw->mac;
00932 u32 txcw;
00933 s32 ret_val = E1000_SUCCESS;
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952 switch (hw->fc.current_mode) {
00953 case e1000_fc_none:
00954
00955 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
00956 break;
00957 case e1000_fc_rx_pause:
00958
00959
00960
00961
00962
00963
00964
00965
00966 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
00967 break;
00968 case e1000_fc_tx_pause:
00969
00970
00971
00972
00973 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
00974 break;
00975 case e1000_fc_full:
00976
00977
00978
00979
00980 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
00981 break;
00982 default:
00983 e_dbg("Flow control param set incorrectly\n");
00984 ret_val = -E1000_ERR_CONFIG;
00985 goto out;
00986 break;
00987 }
00988
00989 ew32(TXCW, txcw);
00990 mac->txcw = txcw;
00991
00992 out:
00993 return ret_val;
00994 }
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004 s32 e1000e_set_fc_watermarks(struct e1000_hw *hw)
01005 {
01006 s32 ret_val = E1000_SUCCESS;
01007 u32 fcrtl = 0, fcrth = 0;
01008
01009
01010
01011
01012
01013
01014
01015
01016 if (hw->fc.current_mode & e1000_fc_tx_pause) {
01017
01018
01019
01020
01021
01022 fcrtl = hw->fc.low_water;
01023 if (hw->fc.send_xon)
01024 fcrtl |= E1000_FCRTL_XONE;
01025
01026 fcrth = hw->fc.high_water;
01027 }
01028 ew32(FCRTL, fcrtl);
01029 ew32(FCRTH, fcrth);
01030
01031 return ret_val;
01032 }
01033
01034
01035
01036
01037
01038
01039
01040
01041 static s32 e1000e_set_default_fc_generic(struct e1000_hw *hw)
01042 {
01043 s32 ret_val = E1000_SUCCESS;
01044 u16 nvm_data;
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055 ret_val = e1000e_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
01056
01057 if (ret_val) {
01058 e_dbg("NVM Read Error\n");
01059 goto out;
01060 }
01061
01062 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
01063 hw->fc.requested_mode = e1000_fc_none;
01064 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
01065 NVM_WORD0F_ASM_DIR)
01066 hw->fc.requested_mode = e1000_fc_tx_pause;
01067 else
01068 hw->fc.requested_mode = e1000_fc_full;
01069
01070 out:
01071 return ret_val;
01072 }
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084 s32 e1000e_force_mac_fc(struct e1000_hw *hw)
01085 {
01086 u32 ctrl;
01087 s32 ret_val = E1000_SUCCESS;
01088
01089 ctrl = er32(CTRL);
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109 e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
01110
01111 switch (hw->fc.current_mode) {
01112 case e1000_fc_none:
01113 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
01114 break;
01115 case e1000_fc_rx_pause:
01116 ctrl &= (~E1000_CTRL_TFCE);
01117 ctrl |= E1000_CTRL_RFCE;
01118 break;
01119 case e1000_fc_tx_pause:
01120 ctrl &= (~E1000_CTRL_RFCE);
01121 ctrl |= E1000_CTRL_TFCE;
01122 break;
01123 case e1000_fc_full:
01124 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
01125 break;
01126 default:
01127 e_dbg("Flow control param set incorrectly\n");
01128 ret_val = -E1000_ERR_CONFIG;
01129 goto out;
01130 }
01131
01132 ew32(CTRL, ctrl);
01133
01134 out:
01135 return ret_val;
01136 }
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148 s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw)
01149 {
01150 struct e1000_mac_info *mac = &hw->mac;
01151 s32 ret_val = E1000_SUCCESS;
01152 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
01153 u16 speed, duplex;
01154
01155
01156
01157
01158
01159
01160 if (mac->autoneg_failed) {
01161 if (hw->phy.media_type == e1000_media_type_fiber ||
01162 hw->phy.media_type == e1000_media_type_internal_serdes)
01163 ret_val = e1000e_force_mac_fc(hw);
01164 } else {
01165 if (hw->phy.media_type == e1000_media_type_copper)
01166 ret_val = e1000e_force_mac_fc(hw);
01167 }
01168
01169 if (ret_val) {
01170 e_dbg("Error forcing flow control settings\n");
01171 goto out;
01172 }
01173
01174
01175
01176
01177
01178
01179
01180 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
01181
01182
01183
01184
01185
01186 ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
01187 if (ret_val)
01188 goto out;
01189 ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
01190 if (ret_val)
01191 goto out;
01192
01193 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
01194 e_dbg("Copper PHY and Auto Neg "
01195 "has not completed.\n");
01196 goto out;
01197 }
01198
01199
01200
01201
01202
01203
01204
01205
01206 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV,
01207 &mii_nway_adv_reg);
01208 if (ret_val)
01209 goto out;
01210 ret_val = e1e_rphy(hw, PHY_LP_ABILITY,
01211 &mii_nway_lp_ability_reg);
01212 if (ret_val)
01213 goto out;
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
01250 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
01251
01252
01253
01254
01255
01256
01257
01258 if (hw->fc.requested_mode == e1000_fc_full) {
01259 hw->fc.current_mode = e1000_fc_full;
01260 e_dbg("Flow Control = FULL.\r\n");
01261 } else {
01262 hw->fc.current_mode = e1000_fc_rx_pause;
01263 e_dbg("Flow Control = "
01264 "RX PAUSE frames only.\r\n");
01265 }
01266 }
01267
01268
01269
01270
01271
01272
01273
01274
01275 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
01276 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
01277 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
01278 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
01279 hw->fc.current_mode = e1000_fc_tx_pause;
01280 e_dbg("Flow Control = TX PAUSE frames only.\r\n");
01281 }
01282
01283
01284
01285
01286
01287
01288
01289
01290 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
01291 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
01292 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
01293 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
01294 hw->fc.current_mode = e1000_fc_rx_pause;
01295 e_dbg("Flow Control = RX PAUSE frames only.\r\n");
01296 } else {
01297
01298
01299
01300
01301 hw->fc.current_mode = e1000_fc_none;
01302 e_dbg("Flow Control = NONE.\r\n");
01303 }
01304
01305
01306
01307
01308
01309
01310 ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
01311 if (ret_val) {
01312 e_dbg("Error getting link speed and duplex\n");
01313 goto out;
01314 }
01315
01316 if (duplex == HALF_DUPLEX)
01317 hw->fc.current_mode = e1000_fc_none;
01318
01319
01320
01321
01322
01323 ret_val = e1000e_force_mac_fc(hw);
01324 if (ret_val) {
01325 e_dbg("Error forcing flow control settings\n");
01326 goto out;
01327 }
01328 }
01329
01330 out:
01331 return ret_val;
01332 }
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343 s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
01344 u16 *duplex)
01345 {
01346 u32 status;
01347
01348 status = er32(STATUS);
01349 if (status & E1000_STATUS_SPEED_1000) {
01350 *speed = SPEED_1000;
01351 e_dbg("1000 Mbs, ");
01352 } else if (status & E1000_STATUS_SPEED_100) {
01353 *speed = SPEED_100;
01354 e_dbg("100 Mbs, ");
01355 } else {
01356 *speed = SPEED_10;
01357 e_dbg("10 Mbs, ");
01358 }
01359
01360 if (status & E1000_STATUS_FD) {
01361 *duplex = FULL_DUPLEX;
01362 e_dbg("Full Duplex\n");
01363 } else {
01364 *duplex = HALF_DUPLEX;
01365 e_dbg("Half Duplex\n");
01366 }
01367
01368 return E1000_SUCCESS;
01369 }
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380 s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw __unused,
01381 u16 *speed, u16 *duplex)
01382 {
01383 *speed = SPEED_1000;
01384 *duplex = FULL_DUPLEX;
01385
01386 return E1000_SUCCESS;
01387 }
01388
01389
01390
01391
01392
01393
01394
01395 s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
01396 {
01397 u32 swsm;
01398 s32 ret_val = E1000_SUCCESS;
01399 s32 timeout = hw->nvm.word_size + 1;
01400 s32 i = 0;
01401
01402
01403 while (i < timeout) {
01404 swsm = er32(SWSM);
01405 if (!(swsm & E1000_SWSM_SMBI))
01406 break;
01407
01408 udelay(50);
01409 i++;
01410 }
01411
01412 if (i == timeout) {
01413 e_dbg("Driver can't access device - SMBI bit is set.\n");
01414 ret_val = -E1000_ERR_NVM;
01415 goto out;
01416 }
01417
01418
01419 for (i = 0; i < timeout; i++) {
01420 swsm = er32(SWSM);
01421 ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
01422
01423
01424 if (er32(SWSM) & E1000_SWSM_SWESMBI)
01425 break;
01426
01427 udelay(50);
01428 }
01429
01430 if (i == timeout) {
01431
01432 e1000e_put_hw_semaphore(hw);
01433 e_dbg("Driver can't access the NVM\n");
01434 ret_val = -E1000_ERR_NVM;
01435 goto out;
01436 }
01437
01438 out:
01439 return ret_val;
01440 }
01441
01442
01443
01444
01445
01446
01447
01448 void e1000e_put_hw_semaphore(struct e1000_hw *hw)
01449 {
01450 u32 swsm;
01451
01452 swsm = er32(SWSM);
01453 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
01454 ew32(SWSM, swsm);
01455 }
01456
01457
01458
01459
01460
01461
01462 s32 e1000e_get_auto_rd_done(struct e1000_hw *hw)
01463 {
01464 s32 i = 0;
01465 s32 ret_val = E1000_SUCCESS;
01466
01467 while (i < AUTO_READ_DONE_TIMEOUT) {
01468 if (er32(EECD) & E1000_EECD_AUTO_RD)
01469 break;
01470 msleep(1);
01471 i++;
01472 }
01473
01474 if (i == AUTO_READ_DONE_TIMEOUT) {
01475 e_dbg("Auto read by HW from NVM has not completed.\n");
01476 ret_val = -E1000_ERR_RESET;
01477 goto out;
01478 }
01479
01480 out:
01481 return ret_val;
01482 }
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492 s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data)
01493 {
01494 s32 ret_val;
01495
01496 ret_val = e1000e_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
01497 if (ret_val) {
01498 e_dbg("NVM Read Error\n");
01499 goto out;
01500 }
01501
01502 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
01503 *data = ID_LED_DEFAULT;
01504
01505 out:
01506 return ret_val;
01507 }
01508
01509
01510
01511
01512
01513
01514 s32 e1000e_id_led_init(struct e1000_hw *hw __unused)
01515 {
01516 #if 0
01517 struct e1000_mac_info *mac = &hw->mac;
01518 s32 ret_val;
01519 const u32 ledctl_mask = 0x000000FF;
01520 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
01521 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
01522 u16 data, i, temp;
01523 const u16 led_mask = 0x0F;
01524
01525 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
01526 if (ret_val)
01527 goto out;
01528
01529 mac->ledctl_default = er32(LEDCTL);
01530 mac->ledctl_mode1 = mac->ledctl_default;
01531 mac->ledctl_mode2 = mac->ledctl_default;
01532
01533 for (i = 0; i < 4; i++) {
01534 temp = (data >> (i << 2)) & led_mask;
01535 switch (temp) {
01536 case ID_LED_ON1_DEF2:
01537 case ID_LED_ON1_ON2:
01538 case ID_LED_ON1_OFF2:
01539 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
01540 mac->ledctl_mode1 |= ledctl_on << (i << 3);
01541 break;
01542 case ID_LED_OFF1_DEF2:
01543 case ID_LED_OFF1_ON2:
01544 case ID_LED_OFF1_OFF2:
01545 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
01546 mac->ledctl_mode1 |= ledctl_off << (i << 3);
01547 break;
01548 default:
01549
01550 break;
01551 }
01552 switch (temp) {
01553 case ID_LED_DEF1_ON2:
01554 case ID_LED_ON1_ON2:
01555 case ID_LED_OFF1_ON2:
01556 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
01557 mac->ledctl_mode2 |= ledctl_on << (i << 3);
01558 break;
01559 case ID_LED_DEF1_OFF2:
01560 case ID_LED_ON1_OFF2:
01561 case ID_LED_OFF1_OFF2:
01562 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
01563 mac->ledctl_mode2 |= ledctl_off << (i << 3);
01564 break;
01565 default:
01566
01567 break;
01568 }
01569 }
01570
01571 out:
01572 return ret_val;
01573 #endif
01574 return E1000_SUCCESS;
01575 }
01576
01577
01578
01579
01580
01581
01582
01583
01584 s32 e1000e_setup_led_generic(struct e1000_hw *hw __unused)
01585 {
01586 #if 0
01587 u32 ledctl;
01588 s32 ret_val = E1000_SUCCESS;
01589
01590 if (hw->mac.ops.setup_led != e1000e_setup_led_generic) {
01591 ret_val = -E1000_ERR_CONFIG;
01592 goto out;
01593 }
01594
01595 if (hw->phy.media_type == e1000_media_type_fiber) {
01596 ledctl = er32(LEDCTL);
01597 hw->mac.ledctl_default = ledctl;
01598
01599 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
01600 E1000_LEDCTL_LED0_BLINK |
01601 E1000_LEDCTL_LED0_MODE_MASK);
01602 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
01603 E1000_LEDCTL_LED0_MODE_SHIFT);
01604 ew32(LEDCTL, ledctl);
01605 } else if (hw->phy.media_type == e1000_media_type_copper) {
01606 ew32(LEDCTL, hw->mac.ledctl_mode1);
01607 }
01608
01609 out:
01610 return ret_val;
01611 #endif
01612 return E1000_SUCCESS;
01613 }
01614
01615
01616
01617
01618
01619
01620
01621
01622 s32 e1000e_cleanup_led_generic(struct e1000_hw *hw __unused)
01623 {
01624 #if 0
01625 s32 ret_val = E1000_SUCCESS;
01626
01627 if (hw->mac.ops.cleanup_led != e1000e_cleanup_led_generic) {
01628 ret_val = -E1000_ERR_CONFIG;
01629 goto out;
01630 }
01631
01632 ew32(LEDCTL, hw->mac.ledctl_default);
01633
01634 out:
01635 return ret_val;
01636 #endif
01637 return E1000_SUCCESS;
01638 }
01639
01640
01641
01642
01643
01644
01645
01646 s32 e1000e_blink_led(struct e1000_hw *hw __unused)
01647 {
01648 #if 0
01649 u32 ledctl_blink = 0;
01650 u32 i;
01651
01652 if (hw->phy.media_type == e1000_media_type_fiber) {
01653
01654 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
01655 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
01656 } else {
01657
01658
01659
01660
01661 ledctl_blink = hw->mac.ledctl_mode2;
01662 for (i = 0; i < 4; i++)
01663 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
01664 E1000_LEDCTL_MODE_LED_ON)
01665 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
01666 (i * 8));
01667 }
01668
01669 ew32(LEDCTL, ledctl_blink);
01670 #endif
01671 return E1000_SUCCESS;
01672 }
01673
01674
01675
01676
01677
01678
01679
01680 s32 e1000e_led_on_generic(struct e1000_hw *hw __unused)
01681 {
01682 #if 0
01683 u32 ctrl;
01684
01685 switch (hw->phy.media_type) {
01686 case e1000_media_type_fiber:
01687 ctrl = er32(CTRL);
01688 ctrl &= ~E1000_CTRL_SWDPIN0;
01689 ctrl |= E1000_CTRL_SWDPIO0;
01690 ew32(CTRL, ctrl);
01691 break;
01692 case e1000_media_type_copper:
01693 ew32(LEDCTL, hw->mac.ledctl_mode2);
01694 break;
01695 default:
01696 break;
01697 }
01698 #endif
01699 return E1000_SUCCESS;
01700 }
01701
01702
01703
01704
01705
01706
01707
01708 s32 e1000e_led_off_generic(struct e1000_hw *hw __unused)
01709 {
01710 #if 0
01711 u32 ctrl;
01712
01713 switch (hw->phy.media_type) {
01714 case e1000_media_type_fiber:
01715 ctrl = er32(CTRL);
01716 ctrl |= E1000_CTRL_SWDPIN0;
01717 ctrl |= E1000_CTRL_SWDPIO0;
01718 ew32(CTRL, ctrl);
01719 break;
01720 case e1000_media_type_copper:
01721 ew32(LEDCTL, hw->mac.ledctl_mode1);
01722 break;
01723 default:
01724 break;
01725 }
01726 #endif
01727 return E1000_SUCCESS;
01728 }
01729
01730
01731
01732
01733
01734
01735
01736
01737 void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop)
01738 {
01739 u32 gcr;
01740
01741 if (hw->bus.type != e1000_bus_type_pci_express)
01742 goto out;
01743
01744 if (no_snoop) {
01745 gcr = er32(GCR);
01746 gcr &= ~(PCIE_NO_SNOOP_ALL);
01747 gcr |= no_snoop;
01748 ew32(GCR, gcr);
01749 }
01750 out:
01751 return;
01752 }
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765 s32 e1000e_disable_pcie_master(struct e1000_hw *hw)
01766 {
01767 u32 ctrl;
01768 s32 timeout = MASTER_DISABLE_TIMEOUT;
01769 s32 ret_val = E1000_SUCCESS;
01770
01771 if (hw->bus.type != e1000_bus_type_pci_express)
01772 goto out;
01773
01774 ctrl = er32(CTRL);
01775 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
01776 ew32(CTRL, ctrl);
01777
01778 while (timeout) {
01779 if (!(er32(STATUS) &
01780 E1000_STATUS_GIO_MASTER_ENABLE))
01781 break;
01782 udelay(100);
01783 timeout--;
01784 }
01785
01786 if (!timeout) {
01787 e_dbg("Master requests are pending.\n");
01788 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
01789 goto out;
01790 }
01791
01792 out:
01793 return ret_val;
01794 }
01795
01796
01797
01798
01799
01800
01801
01802 void e1000e_reset_adaptive(struct e1000_hw *hw)
01803 {
01804 struct e1000_mac_info *mac = &hw->mac;
01805
01806 if (!mac->adaptive_ifs) {
01807 e_dbg("Not in Adaptive IFS mode!\n");
01808 goto out;
01809 }
01810
01811 mac->current_ifs_val = 0;
01812 mac->ifs_min_val = IFS_MIN;
01813 mac->ifs_max_val = IFS_MAX;
01814 mac->ifs_step_size = IFS_STEP;
01815 mac->ifs_ratio = IFS_RATIO;
01816
01817 mac->in_ifs_mode = false;
01818 ew32(AIT, 0);
01819 out:
01820 return;
01821 }
01822
01823
01824
01825
01826
01827
01828
01829
01830 void e1000e_update_adaptive(struct e1000_hw *hw)
01831 {
01832 struct e1000_mac_info *mac = &hw->mac;
01833
01834 if (!mac->adaptive_ifs) {
01835 e_dbg("Not in Adaptive IFS mode!\n");
01836 goto out;
01837 }
01838
01839 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
01840 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
01841 mac->in_ifs_mode = true;
01842 if (mac->current_ifs_val < mac->ifs_max_val) {
01843 if (!mac->current_ifs_val)
01844 mac->current_ifs_val = mac->ifs_min_val;
01845 else
01846 mac->current_ifs_val +=
01847 mac->ifs_step_size;
01848 ew32(AIT, mac->current_ifs_val);
01849 }
01850 }
01851 } else {
01852 if (mac->in_ifs_mode &&
01853 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
01854 mac->current_ifs_val = 0;
01855 mac->in_ifs_mode = false;
01856 ew32(AIT, 0);
01857 }
01858 }
01859 out:
01860 return;
01861 }
01862
01863
01864
01865
01866
01867
01868
01869
01870 static s32 e1000e_validate_mdi_setting_generic(struct e1000_hw *hw)
01871 {
01872 s32 ret_val = E1000_SUCCESS;
01873
01874 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
01875 e_dbg("Invalid MDI setting detected\n");
01876 hw->phy.mdix = 1;
01877 ret_val = -E1000_ERR_CONFIG;
01878 goto out;
01879 }
01880
01881 out:
01882 return ret_val;
01883 }