e1000_mac.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003   Intel PRO/1000 Linux driver
00004   Copyright(c) 1999 - 2008 Intel Corporation.
00005 
00006   This program is free software; you can redistribute it and/or modify it
00007   under the terms and conditions of the GNU General Public License,
00008   version 2, as published by the Free Software Foundation.
00009 
00010   This program is distributed in the hope it will be useful, but WITHOUT
00011   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013   more details.
00014 
00015   You should have received a copy of the GNU General Public License along with
00016   this program; if not, write to the Free Software Foundation, Inc.,
00017   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019   The full GNU General Public License is included in this distribution in
00020   the file called "COPYING".
00021 
00022   Contact Information:
00023   Linux NICS <linux.nics@intel.com>
00024   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
00025   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
00026 
00027 *******************************************************************************/
00028 
00029 FILE_LICENCE ( GPL2_OR_LATER );
00030 
00031 #include "e1000_api.h"
00032 
00033 static s32 e1000_validate_mdi_setting_generic(struct e1000_hw *hw);
00034 static void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw);
00035 
00036 /**
00037  *  e1000_init_mac_ops_generic - Initialize MAC function pointers
00038  *  @hw: pointer to the HW structure
00039  *
00040  *  Setups up the function pointers to no-op functions
00041  **/
00042 void e1000_init_mac_ops_generic(struct e1000_hw *hw)
00043 {
00044         struct e1000_mac_info *mac = &hw->mac;
00045         DEBUGFUNC("e1000_init_mac_ops_generic");
00046 
00047         /* General Setup */
00048         mac->ops.init_params = e1000_null_ops_generic;
00049         mac->ops.init_hw = e1000_null_ops_generic;
00050         mac->ops.reset_hw = e1000_null_ops_generic;
00051         mac->ops.setup_physical_interface = e1000_null_ops_generic;
00052         mac->ops.get_bus_info = e1000_null_ops_generic;
00053         mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pcie;
00054         mac->ops.read_mac_addr = e1000_read_mac_addr_generic;
00055         mac->ops.config_collision_dist = e1000_config_collision_dist_generic;
00056         mac->ops.clear_hw_cntrs = e1000_null_mac_generic;
00057         /* LED */
00058         mac->ops.cleanup_led = e1000_null_ops_generic;
00059         mac->ops.setup_led = e1000_null_ops_generic;
00060         mac->ops.blink_led = e1000_null_ops_generic;
00061         mac->ops.led_on = e1000_null_ops_generic;
00062         mac->ops.led_off = e1000_null_ops_generic;
00063         /* LINK */
00064         mac->ops.setup_link = e1000_null_ops_generic;
00065         mac->ops.get_link_up_info = e1000_null_link_info;
00066         mac->ops.check_for_link = e1000_null_ops_generic;
00067         mac->ops.wait_autoneg = e1000_wait_autoneg_generic;
00068 #if 0
00069         /* Management */
00070         mac->ops.check_mng_mode = e1000_null_mng_mode;
00071         mac->ops.mng_host_if_write = e1000_mng_host_if_write_generic;
00072         mac->ops.mng_write_cmd_header = e1000_mng_write_cmd_header_generic;
00073         mac->ops.mng_enable_host_if = e1000_mng_enable_host_if_generic;
00074 #endif
00075         /* VLAN, MC, etc. */
00076         mac->ops.update_mc_addr_list = e1000_null_update_mc;
00077         mac->ops.clear_vfta = e1000_null_mac_generic;
00078         mac->ops.write_vfta = e1000_null_write_vfta;
00079         mac->ops.mta_set = e1000_null_mta_set;
00080         mac->ops.rar_set = e1000_rar_set_generic;
00081         mac->ops.validate_mdi_setting = e1000_validate_mdi_setting_generic;
00082 }
00083 
00084 /**
00085  *  e1000_null_ops_generic - No-op function, returns 0
00086  *  @hw: pointer to the HW structure
00087  **/
00088 s32 e1000_null_ops_generic(struct e1000_hw *hw __unused)
00089 {
00090         DEBUGFUNC("e1000_null_ops_generic");
00091         return E1000_SUCCESS;
00092 }
00093 
00094 /**
00095  *  e1000_null_mac_generic - No-op function, return void
00096  *  @hw: pointer to the HW structure
00097  **/
00098 void e1000_null_mac_generic(struct e1000_hw *hw __unused)
00099 {
00100         DEBUGFUNC("e1000_null_mac_generic");
00101         return;
00102 }
00103 
00104 /**
00105  *  e1000_null_link_info - No-op function, return 0
00106  *  @hw: pointer to the HW structure
00107  **/
00108 s32 e1000_null_link_info(struct e1000_hw *hw __unused,
00109                          u16 *s __unused, u16 *d __unused)
00110 {
00111         DEBUGFUNC("e1000_null_link_info");
00112         return E1000_SUCCESS;
00113 }
00114 
00115 /**
00116  *  e1000_null_mng_mode - No-op function, return false
00117  *  @hw: pointer to the HW structure
00118  **/
00119 bool e1000_null_mng_mode(struct e1000_hw *hw __unused)
00120 {
00121         DEBUGFUNC("e1000_null_mng_mode");
00122         return false;
00123 }
00124 
00125 /**
00126  *  e1000_null_update_mc - No-op function, return void
00127  *  @hw: pointer to the HW structure
00128  **/
00129 void e1000_null_update_mc(struct e1000_hw *hw __unused,
00130                           u8 *h __unused, u32 a __unused)
00131 {
00132         DEBUGFUNC("e1000_null_update_mc");
00133         return;
00134 }
00135 
00136 /**
00137  *  e1000_null_write_vfta - No-op function, return void
00138  *  @hw: pointer to the HW structure
00139  **/
00140 void e1000_null_write_vfta(struct e1000_hw *hw __unused,
00141                            u32 a __unused, u32 b __unused)
00142 {
00143         DEBUGFUNC("e1000_null_write_vfta");
00144         return;
00145 }
00146 
00147 /**
00148  *  e1000_null_set_mta - No-op function, return void
00149  *  @hw: pointer to the HW structure
00150  **/
00151 void e1000_null_mta_set(struct e1000_hw *hw __unused, u32 a __unused)
00152 {
00153         DEBUGFUNC("e1000_null_mta_set");
00154         return;
00155 }
00156 
00157 /**
00158  *  e1000_null_rar_set - No-op function, return void
00159  *  @hw: pointer to the HW structure
00160  **/
00161 void e1000_null_rar_set(struct e1000_hw *hw __unused, u8 *h __unused,
00162                         u32 a __unused)
00163 {
00164         DEBUGFUNC("e1000_null_rar_set");
00165         return;
00166 }
00167 
00168 /**
00169  *  e1000_get_bus_info_pci_generic - Get PCI(x) bus information
00170  *  @hw: pointer to the HW structure
00171  *
00172  *  Determines and stores the system bus information for a particular
00173  *  network interface.  The following bus information is determined and stored:
00174  *  bus speed, bus width, type (PCI/PCIx), and PCI(-x) function.
00175  **/
00176 s32 e1000_get_bus_info_pci_generic(struct e1000_hw *hw __unused)
00177 {
00178 #if 0
00179         struct e1000_mac_info *mac = &hw->mac;
00180         struct e1000_bus_info *bus = &hw->bus;
00181         u32 status = E1000_READ_REG(hw, E1000_STATUS);
00182         s32 ret_val = E1000_SUCCESS;
00183 
00184         DEBUGFUNC("e1000_get_bus_info_pci_generic");
00185 
00186         /* PCI or PCI-X? */
00187         bus->type = (status & E1000_STATUS_PCIX_MODE)
00188                         ? e1000_bus_type_pcix
00189                         : e1000_bus_type_pci;
00190 
00191         /* Bus speed */
00192         if (bus->type == e1000_bus_type_pci) {
00193                 bus->speed = (status & E1000_STATUS_PCI66)
00194                              ? e1000_bus_speed_66
00195                              : e1000_bus_speed_33;
00196         } else {
00197                 switch (status & E1000_STATUS_PCIX_SPEED) {
00198                 case E1000_STATUS_PCIX_SPEED_66:
00199                         bus->speed = e1000_bus_speed_66;
00200                         break;
00201                 case E1000_STATUS_PCIX_SPEED_100:
00202                         bus->speed = e1000_bus_speed_100;
00203                         break;
00204                 case E1000_STATUS_PCIX_SPEED_133:
00205                         bus->speed = e1000_bus_speed_133;
00206                         break;
00207                 default:
00208                         bus->speed = e1000_bus_speed_reserved;
00209                         break;
00210                 }
00211         }
00212 
00213         /* Bus width */
00214         bus->width = (status & E1000_STATUS_BUS64)
00215                      ? e1000_bus_width_64
00216                      : e1000_bus_width_32;
00217 
00218         /* Which PCI(-X) function? */
00219         mac->ops.set_lan_id(hw);
00220 
00221         return ret_val;
00222 #endif
00223         return 0;
00224 }
00225 
00226 /**
00227  *  e1000_get_bus_info_pcie_generic - Get PCIe bus information
00228  *  @hw: pointer to the HW structure
00229  *
00230  *  Determines and stores the system bus information for a particular
00231  *  network interface.  The following bus information is determined and stored:
00232  *  bus speed, bus width, type (PCIe), and PCIe function.
00233  **/
00234 s32 e1000_get_bus_info_pcie_generic(struct e1000_hw *hw __unused)
00235 {
00236 #if 0
00237         struct e1000_mac_info *mac = &hw->mac;
00238         struct e1000_bus_info *bus = &hw->bus;
00239 
00240         s32 ret_val;
00241         u16 pcie_link_status;
00242 
00243         DEBUGFUNC("e1000_get_bus_info_pcie_generic");
00244 
00245         bus->type = e1000_bus_type_pci_express;
00246         bus->speed = e1000_bus_speed_2500;
00247 
00248         ret_val = e1000_read_pcie_cap_reg(hw,
00249                                           PCIE_LINK_STATUS,
00250                                           &pcie_link_status);
00251         if (ret_val)
00252                 bus->width = e1000_bus_width_unknown;
00253         else
00254                 bus->width = (enum e1000_bus_width)((pcie_link_status &
00255                                                 PCIE_LINK_WIDTH_MASK) >>
00256                                                PCIE_LINK_WIDTH_SHIFT);
00257 
00258         mac->ops.set_lan_id(hw);
00259 
00260         return E1000_SUCCESS;
00261 #endif
00262         return 0;
00263 }
00264 
00265 /**
00266  *  e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
00267  *
00268  *  @hw: pointer to the HW structure
00269  *
00270  *  Determines the LAN function id by reading memory-mapped registers
00271  *  and swaps the port value if requested.
00272  **/
00273 static void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
00274 {
00275         struct e1000_bus_info *bus = &hw->bus;
00276         u32 reg;
00277 
00278         /*
00279          * The status register reports the correct function number
00280          * for the device regardless of function swap state.
00281          */
00282         reg = E1000_READ_REG(hw, E1000_STATUS);
00283         bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
00284 }
00285 
00286 /**
00287  *  e1000_set_lan_id_multi_port_pci - Set LAN id for PCI multiple port devices
00288  *  @hw: pointer to the HW structure
00289  *
00290  *  Determines the LAN function id by reading PCI config space.
00291  **/
00292 void e1000_set_lan_id_multi_port_pci(struct e1000_hw *hw)
00293 {
00294         struct e1000_bus_info *bus = &hw->bus;
00295         u16 pci_header_type;
00296         u32 status;
00297 
00298         e1000_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
00299         if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
00300                 status = E1000_READ_REG(hw, E1000_STATUS);
00301                 bus->func = (status & E1000_STATUS_FUNC_MASK)
00302                             >> E1000_STATUS_FUNC_SHIFT;
00303         } else {
00304                 bus->func = 0;
00305         }
00306 }
00307 
00308 /**
00309  *  e1000_set_lan_id_single_port - Set LAN id for a single port device
00310  *  @hw: pointer to the HW structure
00311  *
00312  *  Sets the LAN function id to zero for a single port device.
00313  **/
00314 void e1000_set_lan_id_single_port(struct e1000_hw *hw)
00315 {
00316         struct e1000_bus_info *bus = &hw->bus;
00317 
00318         bus->func = 0;
00319 }
00320 
00321 /**
00322  *  e1000_clear_vfta_generic - Clear VLAN filter table
00323  *  @hw: pointer to the HW structure
00324  *
00325  *  Clears the register array which contains the VLAN filter table by
00326  *  setting all the values to 0.
00327  **/
00328 void e1000_clear_vfta_generic(struct e1000_hw *hw)
00329 {
00330         u32 offset;
00331 
00332         DEBUGFUNC("e1000_clear_vfta_generic");
00333 
00334         for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
00335                 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
00336                 E1000_WRITE_FLUSH(hw);
00337         }
00338 }
00339 
00340 /**
00341  *  e1000_write_vfta_generic - Write value to VLAN filter table
00342  *  @hw: pointer to the HW structure
00343  *  @offset: register offset in VLAN filter table
00344  *  @value: register value written to VLAN filter table
00345  *
00346  *  Writes value at the given offset in the register array which stores
00347  *  the VLAN filter table.
00348  **/
00349 void e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
00350 {
00351         DEBUGFUNC("e1000_write_vfta_generic");
00352 
00353         E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
00354         E1000_WRITE_FLUSH(hw);
00355 }
00356 
00357 /**
00358  *  e1000_init_rx_addrs_generic - Initialize receive address's
00359  *  @hw: pointer to the HW structure
00360  *  @rar_count: receive address registers
00361  *
00362  *  Setups the receive address registers by setting the base receive address
00363  *  register to the devices MAC address and clearing all the other receive
00364  *  address registers to 0.
00365  **/
00366 void e1000_init_rx_addrs_generic(struct e1000_hw *hw, u16 rar_count)
00367 {
00368         u32 i;
00369         u8 mac_addr[ETH_ADDR_LEN] = {0};
00370 
00371         DEBUGFUNC("e1000_init_rx_addrs_generic");
00372 
00373         /* Setup the receive address */
00374         DEBUGOUT("Programming MAC Address into RAR[0]\n");
00375 
00376         hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
00377 
00378         /* Zero out the other (rar_entry_count - 1) receive addresses */
00379         DEBUGOUT1("Clearing RAR[1-%u]\n", rar_count-1);
00380         for (i = 1; i < rar_count; i++)
00381                 hw->mac.ops.rar_set(hw, mac_addr, i);
00382 }
00383 
00384 /**
00385  *  e1000_check_alt_mac_addr_generic - Check for alternate MAC addr
00386  *  @hw: pointer to the HW structure
00387  *
00388  *  Checks the nvm for an alternate MAC address.  An alternate MAC address
00389  *  can be setup by pre-boot software and must be treated like a permanent
00390  *  address and must override the actual permanent MAC address. If an
00391  *  alternate MAC address is found it is programmed into RAR0, replacing
00392  *  the permanent address that was installed into RAR0 by the Si on reset.
00393  *  This function will return SUCCESS unless it encounters an error while
00394  *  reading the EEPROM.
00395  **/
00396 s32 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw)
00397 {
00398         u32 i;
00399         s32 ret_val = E1000_SUCCESS;
00400         u16 offset, nvm_alt_mac_addr_offset, nvm_data;
00401         u8 alt_mac_addr[ETH_ADDR_LEN];
00402 
00403         DEBUGFUNC("e1000_check_alt_mac_addr_generic");
00404 
00405         ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
00406                                  &nvm_alt_mac_addr_offset);
00407         if (ret_val) {
00408                 DEBUGOUT("NVM Read Error\n");
00409                 goto out;
00410         }
00411 
00412         if (nvm_alt_mac_addr_offset == 0xFFFF) {
00413                 /* There is no Alternate MAC Address */
00414                 goto out;
00415         }
00416 
00417         if (hw->bus.func == E1000_FUNC_1)
00418                 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
00419         for (i = 0; i < ETH_ADDR_LEN; i += 2) {
00420                 offset = nvm_alt_mac_addr_offset + (i >> 1);
00421                 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
00422                 if (ret_val) {
00423                         DEBUGOUT("NVM Read Error\n");
00424                         goto out;
00425                 }
00426 
00427                 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
00428                 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
00429         }
00430 
00431         /* if multicast bit is set, the alternate address will not be used */
00432         if (alt_mac_addr[0] & 0x01) {
00433                 DEBUGOUT("Ignoring Alternate Mac Address with MC bit set\n");
00434                 goto out;
00435         }
00436 
00437         /*
00438          * We have a valid alternate MAC address, and we want to treat it the
00439          * same as the normal permanent MAC address stored by the HW into the
00440          * RAR. Do this by mapping this address into RAR0.
00441          */
00442         hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
00443 
00444 out:
00445         return ret_val;
00446 }
00447 
00448 /**
00449  *  e1000_rar_set_generic - Set receive address register
00450  *  @hw: pointer to the HW structure
00451  *  @addr: pointer to the receive address
00452  *  @index: receive address array register
00453  *
00454  *  Sets the receive address array register at index to the address passed
00455  *  in by addr.
00456  **/
00457 void e1000_rar_set_generic(struct e1000_hw *hw, u8 *addr, u32 index)
00458 {
00459         u32 rar_low, rar_high;
00460 
00461         DEBUGFUNC("e1000_rar_set_generic");
00462 
00463         /*
00464          * HW expects these in little endian so we reverse the byte order
00465          * from network order (big endian) to little endian
00466          */
00467         rar_low = ((u32) addr[0] |
00468                    ((u32) addr[1] << 8) |
00469                    ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
00470 
00471         rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
00472 
00473         /* If MAC address zero, no need to set the AV bit */
00474         if (rar_low || rar_high)
00475                 rar_high |= E1000_RAH_AV;
00476 
00477         /*
00478          * Some bridges will combine consecutive 32-bit writes into
00479          * a single burst write, which will malfunction on some parts.
00480          * The flushes avoid this.
00481          */
00482         E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
00483         E1000_WRITE_FLUSH(hw);
00484         E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
00485         E1000_WRITE_FLUSH(hw);
00486 }
00487 
00488 /**
00489  *  e1000_mta_set_generic - Set multicast filter table address
00490  *  @hw: pointer to the HW structure
00491  *  @hash_value: determines the MTA register and bit to set
00492  *
00493  *  The multicast table address is a register array of 32-bit registers.
00494  *  The hash_value is used to determine what register the bit is in, the
00495  *  current value is read, the new bit is OR'd in and the new value is
00496  *  written back into the register.
00497  **/
00498 void e1000_mta_set_generic(struct e1000_hw *hw, u32 hash_value)
00499 {
00500         u32 hash_bit, hash_reg, mta;
00501 
00502         DEBUGFUNC("e1000_mta_set_generic");
00503         /*
00504          * The MTA is a register array of 32-bit registers. It is
00505          * treated like an array of (32*mta_reg_count) bits.  We want to
00506          * set bit BitArray[hash_value]. So we figure out what register
00507          * the bit is in, read it, OR in the new bit, then write
00508          * back the new value.  The (hw->mac.mta_reg_count - 1) serves as a
00509          * mask to bits 31:5 of the hash value which gives us the
00510          * register we're modifying.  The hash bit within that register
00511          * is determined by the lower 5 bits of the hash value.
00512          */
00513         hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
00514         hash_bit = hash_value & 0x1F;
00515 
00516         mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
00517 
00518         mta |= (1 << hash_bit);
00519 
00520         E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
00521         E1000_WRITE_FLUSH(hw);
00522 }
00523 
00524 /**
00525  *  e1000_update_mc_addr_list_generic - Update Multicast addresses
00526  *  @hw: pointer to the HW structure
00527  *  @mc_addr_list: array of multicast addresses to program
00528  *  @mc_addr_count: number of multicast addresses to program
00529  *
00530  *  Updates entire Multicast Table Array.
00531  *  The caller must have a packed mc_addr_list of multicast addresses.
00532  **/
00533 void e1000_update_mc_addr_list_generic(struct e1000_hw *hw,
00534                                        u8 *mc_addr_list, u32 mc_addr_count)
00535 {
00536         u32 hash_value, hash_bit, hash_reg;
00537         int i;
00538 
00539         DEBUGFUNC("e1000_update_mc_addr_list_generic");
00540 
00541         /* clear mta_shadow */
00542         memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
00543 
00544         /* update mta_shadow from mc_addr_list */
00545         for (i = 0; (u32) i < mc_addr_count; i++) {
00546                 hash_value = e1000_hash_mc_addr_generic(hw, mc_addr_list);
00547 
00548                 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
00549                 hash_bit = hash_value & 0x1F;
00550 
00551                 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
00552                 mc_addr_list += (ETH_ADDR_LEN);
00553         }
00554 
00555         /* replace the entire MTA table */
00556         for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
00557                 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]);
00558         E1000_WRITE_FLUSH(hw);
00559 }
00560 
00561 /**
00562  *  e1000_hash_mc_addr_generic - Generate a multicast hash value
00563  *  @hw: pointer to the HW structure
00564  *  @mc_addr: pointer to a multicast address
00565  *
00566  *  Generates a multicast address hash value which is used to determine
00567  *  the multicast filter table array address and new table value.  See
00568  *  e1000_mta_set_generic()
00569  **/
00570 u32 e1000_hash_mc_addr_generic(struct e1000_hw *hw, u8 *mc_addr)
00571 {
00572         u32 hash_value, hash_mask;
00573         u8 bit_shift = 0;
00574 
00575         DEBUGFUNC("e1000_hash_mc_addr_generic");
00576 
00577         /* Register count multiplied by bits per register */
00578         hash_mask = (hw->mac.mta_reg_count * 32) - 1;
00579 
00580         /*
00581          * For a mc_filter_type of 0, bit_shift is the number of left-shifts
00582          * where 0xFF would still fall within the hash mask.
00583          */
00584         while (hash_mask >> bit_shift != 0xFF)
00585                 bit_shift++;
00586 
00587         /*
00588          * The portion of the address that is used for the hash table
00589          * is determined by the mc_filter_type setting.
00590          * The algorithm is such that there is a total of 8 bits of shifting.
00591          * The bit_shift for a mc_filter_type of 0 represents the number of
00592          * left-shifts where the MSB of mc_addr[5] would still fall within
00593          * the hash_mask.  Case 0 does this exactly.  Since there are a total
00594          * of 8 bits of shifting, then mc_addr[4] will shift right the
00595          * remaining number of bits. Thus 8 - bit_shift.  The rest of the
00596          * cases are a variation of this algorithm...essentially raising the
00597          * number of bits to shift mc_addr[5] left, while still keeping the
00598          * 8-bit shifting total.
00599          *
00600          * For example, given the following Destination MAC Address and an
00601          * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
00602          * we can see that the bit_shift for case 0 is 4.  These are the hash
00603          * values resulting from each mc_filter_type...
00604          * [0] [1] [2] [3] [4] [5]
00605          * 01  AA  00  12  34  56
00606          * LSB                 MSB
00607          *
00608          * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
00609          * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
00610          * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
00611          * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
00612          */
00613         switch (hw->mac.mc_filter_type) {
00614         default:
00615         case 0:
00616                 break;
00617         case 1:
00618                 bit_shift += 1;
00619                 break;
00620         case 2:
00621                 bit_shift += 2;
00622                 break;
00623         case 3:
00624                 bit_shift += 4;
00625                 break;
00626         }
00627 
00628         hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
00629                                   (((u16) mc_addr[5]) << bit_shift)));
00630 
00631         return hash_value;
00632 }
00633 
00634 /**
00635  *  e1000_pcix_mmrbc_workaround_generic - Fix incorrect MMRBC value
00636  *  @hw: pointer to the HW structure
00637  *
00638  *  In certain situations, a system BIOS may report that the PCIx maximum
00639  *  memory read byte count (MMRBC) value is higher than than the actual
00640  *  value. We check the PCIx command register with the current PCIx status
00641  *  register.
00642  **/
00643 void e1000_pcix_mmrbc_workaround_generic(struct e1000_hw *hw)
00644 {
00645         u16 cmd_mmrbc;
00646         u16 pcix_cmd;
00647         u16 pcix_stat_hi_word;
00648         u16 stat_mmrbc;
00649 
00650         DEBUGFUNC("e1000_pcix_mmrbc_workaround_generic");
00651 
00652         /* Workaround for PCI-X issue when BIOS sets MMRBC incorrectly */
00653         if (hw->bus.type != e1000_bus_type_pcix)
00654                 return;
00655 
00656         e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd);
00657         e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
00658         cmd_mmrbc = (pcix_cmd & PCIX_COMMAND_MMRBC_MASK) >>
00659                      PCIX_COMMAND_MMRBC_SHIFT;
00660         stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
00661                       PCIX_STATUS_HI_MMRBC_SHIFT;
00662         if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
00663                 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
00664         if (cmd_mmrbc > stat_mmrbc) {
00665                 pcix_cmd &= ~PCIX_COMMAND_MMRBC_MASK;
00666                 pcix_cmd |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
00667                 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd);
00668         }
00669 }
00670 
00671 /**
00672  *  e1000_clear_hw_cntrs_base_generic - Clear base hardware counters
00673  *  @hw: pointer to the HW structure
00674  *
00675  *  Clears the base hardware counters by reading the counter registers.
00676  **/
00677 void e1000_clear_hw_cntrs_base_generic(struct e1000_hw *hw __unused)
00678 {
00679         DEBUGFUNC("e1000_clear_hw_cntrs_base_generic");
00680 
00681 #if 0
00682         E1000_READ_REG(hw, E1000_CRCERRS);
00683         E1000_READ_REG(hw, E1000_SYMERRS);
00684         E1000_READ_REG(hw, E1000_MPC);
00685         E1000_READ_REG(hw, E1000_SCC);
00686         E1000_READ_REG(hw, E1000_ECOL);
00687         E1000_READ_REG(hw, E1000_MCC);
00688         E1000_READ_REG(hw, E1000_LATECOL);
00689         E1000_READ_REG(hw, E1000_COLC);
00690         E1000_READ_REG(hw, E1000_DC);
00691         E1000_READ_REG(hw, E1000_SEC);
00692         E1000_READ_REG(hw, E1000_RLEC);
00693         E1000_READ_REG(hw, E1000_XONRXC);
00694         E1000_READ_REG(hw, E1000_XONTXC);
00695         E1000_READ_REG(hw, E1000_XOFFRXC);
00696         E1000_READ_REG(hw, E1000_XOFFTXC);
00697         E1000_READ_REG(hw, E1000_FCRUC);
00698         E1000_READ_REG(hw, E1000_GPRC);
00699         E1000_READ_REG(hw, E1000_BPRC);
00700         E1000_READ_REG(hw, E1000_MPRC);
00701         E1000_READ_REG(hw, E1000_GPTC);
00702         E1000_READ_REG(hw, E1000_GORCL);
00703         E1000_READ_REG(hw, E1000_GORCH);
00704         E1000_READ_REG(hw, E1000_GOTCL);
00705         E1000_READ_REG(hw, E1000_GOTCH);
00706         E1000_READ_REG(hw, E1000_RNBC);
00707         E1000_READ_REG(hw, E1000_RUC);
00708         E1000_READ_REG(hw, E1000_RFC);
00709         E1000_READ_REG(hw, E1000_ROC);
00710         E1000_READ_REG(hw, E1000_RJC);
00711         E1000_READ_REG(hw, E1000_TORL);
00712         E1000_READ_REG(hw, E1000_TORH);
00713         E1000_READ_REG(hw, E1000_TOTL);
00714         E1000_READ_REG(hw, E1000_TOTH);
00715         E1000_READ_REG(hw, E1000_TPR);
00716         E1000_READ_REG(hw, E1000_TPT);
00717         E1000_READ_REG(hw, E1000_MPTC);
00718         E1000_READ_REG(hw, E1000_BPTC);
00719 #endif
00720 }
00721 
00722 /**
00723  *  e1000_check_for_copper_link_generic - Check for link (Copper)
00724  *  @hw: pointer to the HW structure
00725  *
00726  *  Checks to see of the link status of the hardware has changed.  If a
00727  *  change in link status has been detected, then we read the PHY registers
00728  *  to get the current speed/duplex if link exists.
00729  **/
00730 s32 e1000_check_for_copper_link_generic(struct e1000_hw *hw)
00731 {
00732         struct e1000_mac_info *mac = &hw->mac;
00733         s32 ret_val;
00734         bool link;
00735 
00736         DEBUGFUNC("e1000_check_for_copper_link");
00737 
00738         /*
00739          * We only want to go out to the PHY registers to see if Auto-Neg
00740          * has completed and/or if our link status has changed.  The
00741          * get_link_status flag is set upon receiving a Link Status
00742          * Change or Rx Sequence Error interrupt.
00743          */
00744         if (!mac->get_link_status) {
00745                 ret_val = E1000_SUCCESS;
00746                 goto out;
00747         }
00748 
00749         /*
00750          * First we want to see if the MII Status Register reports
00751          * link.  If so, then we want to get the current speed/duplex
00752          * of the PHY.
00753          */
00754         ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
00755         if (ret_val)
00756                 goto out;
00757 
00758         if (!link)
00759                 goto out; /* No link detected */
00760 
00761         mac->get_link_status = false;
00762 
00763         /*
00764          * Check if there was DownShift, must be checked
00765          * immediately after link-up
00766          */
00767         e1000_check_downshift_generic(hw);
00768 
00769         /*
00770          * If we are forcing speed/duplex, then we simply return since
00771          * we have already determined whether we have link or not.
00772          */
00773         if (!mac->autoneg) {
00774                 ret_val = -E1000_ERR_CONFIG;
00775                 goto out;
00776         }
00777 
00778         /*
00779          * Auto-Neg is enabled.  Auto Speed Detection takes care
00780          * of MAC speed/duplex configuration.  So we only need to
00781          * configure Collision Distance in the MAC.
00782          */
00783         e1000_config_collision_dist_generic(hw);
00784 
00785         /*
00786          * Configure Flow Control now that Auto-Neg has completed.
00787          * First, we need to restore the desired flow control
00788          * settings because we may have had to re-autoneg with a
00789          * different link partner.
00790          */
00791         ret_val = e1000_config_fc_after_link_up_generic(hw);
00792         if (ret_val)
00793                 DEBUGOUT("Error configuring flow control\n");
00794 
00795 out:
00796         return ret_val;
00797 }
00798 
00799 /**
00800  *  e1000_check_for_fiber_link_generic - Check for link (Fiber)
00801  *  @hw: pointer to the HW structure
00802  *
00803  *  Checks for link up on the hardware.  If link is not up and we have
00804  *  a signal, then we need to force link up.
00805  **/
00806 s32 e1000_check_for_fiber_link_generic(struct e1000_hw *hw)
00807 {
00808         struct e1000_mac_info *mac = &hw->mac;
00809         u32 rxcw;
00810         u32 ctrl;
00811         u32 status;
00812         s32 ret_val = E1000_SUCCESS;
00813 
00814         DEBUGFUNC("e1000_check_for_fiber_link_generic");
00815 
00816         ctrl = E1000_READ_REG(hw, E1000_CTRL);
00817         status = E1000_READ_REG(hw, E1000_STATUS);
00818         rxcw = E1000_READ_REG(hw, E1000_RXCW);
00819 
00820         /*
00821          * If we don't have link (auto-negotiation failed or link partner
00822          * cannot auto-negotiate), the cable is plugged in (we have signal),
00823          * and our link partner is not trying to auto-negotiate with us (we
00824          * are receiving idles or data), we need to force link up. We also
00825          * need to give auto-negotiation time to complete, in case the cable
00826          * was just plugged in. The autoneg_failed flag does this.
00827          */
00828         /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
00829         if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
00830             (!(rxcw & E1000_RXCW_C))) {
00831                 if (mac->autoneg_failed == 0) {
00832                         mac->autoneg_failed = 1;
00833                         goto out;
00834                 }
00835                 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
00836 
00837                 /* Disable auto-negotiation in the TXCW register */
00838                 E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
00839 
00840                 /* Force link-up and also force full-duplex. */
00841                 ctrl = E1000_READ_REG(hw, E1000_CTRL);
00842                 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
00843                 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
00844 
00845                 /* Configure Flow Control after forcing link up. */
00846                 ret_val = e1000_config_fc_after_link_up_generic(hw);
00847                 if (ret_val) {
00848                         DEBUGOUT("Error configuring flow control\n");
00849                         goto out;
00850                 }
00851         } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
00852                 /*
00853                  * If we are forcing link and we are receiving /C/ ordered
00854                  * sets, re-enable auto-negotiation in the TXCW register
00855                  * and disable forced link in the Device Control register
00856                  * in an attempt to auto-negotiate with our link partner.
00857                  */
00858                 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
00859                 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
00860                 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
00861 
00862                 mac->serdes_has_link = true;
00863         }
00864 
00865 out:
00866         return ret_val;
00867 }
00868 
00869 /**
00870  *  e1000_check_for_serdes_link_generic - Check for link (Serdes)
00871  *  @hw: pointer to the HW structure
00872  *
00873  *  Checks for link up on the hardware.  If link is not up and we have
00874  *  a signal, then we need to force link up.
00875  **/
00876 s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
00877 {
00878         struct e1000_mac_info *mac = &hw->mac;
00879         u32 rxcw;
00880         u32 ctrl;
00881         u32 status;
00882         s32 ret_val = E1000_SUCCESS;
00883 
00884         DEBUGFUNC("e1000_check_for_serdes_link_generic");
00885 
00886         ctrl = E1000_READ_REG(hw, E1000_CTRL);
00887         status = E1000_READ_REG(hw, E1000_STATUS);
00888         rxcw = E1000_READ_REG(hw, E1000_RXCW);
00889 
00890         /*
00891          * If we don't have link (auto-negotiation failed or link partner
00892          * cannot auto-negotiate), and our link partner is not trying to
00893          * auto-negotiate with us (we are receiving idles or data),
00894          * we need to force link up. We also need to give auto-negotiation
00895          * time to complete.
00896          */
00897         /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
00898         if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
00899                 if (mac->autoneg_failed == 0) {
00900                         mac->autoneg_failed = 1;
00901                         goto out;
00902                 }
00903                 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
00904 
00905                 /* Disable auto-negotiation in the TXCW register */
00906                 E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
00907 
00908                 /* Force link-up and also force full-duplex. */
00909                 ctrl = E1000_READ_REG(hw, E1000_CTRL);
00910                 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
00911                 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
00912 
00913                 /* Configure Flow Control after forcing link up. */
00914                 ret_val = e1000_config_fc_after_link_up_generic(hw);
00915                 if (ret_val) {
00916                         DEBUGOUT("Error configuring flow control\n");
00917                         goto out;
00918                 }
00919         } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
00920                 /*
00921                  * If we are forcing link and we are receiving /C/ ordered
00922                  * sets, re-enable auto-negotiation in the TXCW register
00923                  * and disable forced link in the Device Control register
00924                  * in an attempt to auto-negotiate with our link partner.
00925                  */
00926                 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
00927                 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
00928                 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
00929 
00930                 mac->serdes_has_link = true;
00931         } else if (!(E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW))) {
00932                 /*
00933                  * If we force link for non-auto-negotiation switch, check
00934                  * link status based on MAC synchronization for internal
00935                  * serdes media type.
00936                  */
00937                 /* SYNCH bit and IV bit are sticky. */
00938                 usec_delay(10);
00939                 rxcw = E1000_READ_REG(hw, E1000_RXCW);
00940                 if (rxcw & E1000_RXCW_SYNCH) {
00941                         if (!(rxcw & E1000_RXCW_IV)) {
00942                                 mac->serdes_has_link = true;
00943                                 DEBUGOUT("SERDES: Link up - forced.\n");
00944                         }
00945                 } else {
00946                         mac->serdes_has_link = false;
00947                         DEBUGOUT("SERDES: Link down - force failed.\n");
00948                 }
00949         }
00950 
00951         if (E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW)) {
00952                 status = E1000_READ_REG(hw, E1000_STATUS);
00953                 if (status & E1000_STATUS_LU) {
00954                         /* SYNCH bit and IV bit are sticky, so reread rxcw. */
00955                         usec_delay(10);
00956                         rxcw = E1000_READ_REG(hw, E1000_RXCW);
00957                         if (rxcw & E1000_RXCW_SYNCH) {
00958                                 if (!(rxcw & E1000_RXCW_IV)) {
00959                                         mac->serdes_has_link = true;
00960                                         DEBUGOUT("SERDES: Link up - autoneg "
00961                                            "completed sucessfully.\n");
00962                                 } else {
00963                                         mac->serdes_has_link = false;
00964                                         DEBUGOUT("SERDES: Link down - invalid"
00965                                            "codewords detected in autoneg.\n");
00966                                 }
00967                         } else {
00968                                 mac->serdes_has_link = false;
00969                                 DEBUGOUT("SERDES: Link down - no sync.\n");
00970                         }
00971                 } else {
00972                         mac->serdes_has_link = false;
00973                         DEBUGOUT("SERDES: Link down - autoneg failed\n");
00974                 }
00975         }
00976 
00977 out:
00978         return ret_val;
00979 }
00980 
00981 /**
00982  *  e1000_setup_link_generic - Setup flow control and link settings
00983  *  @hw: pointer to the HW structure
00984  *
00985  *  Determines which flow control settings to use, then configures flow
00986  *  control.  Calls the appropriate media-specific link configuration
00987  *  function.  Assuming the adapter has a valid link partner, a valid link
00988  *  should be established.  Assumes the hardware has previously been reset
00989  *  and the transmitter and receiver are not enabled.
00990  **/
00991 s32 e1000_setup_link_generic(struct e1000_hw *hw)
00992 {
00993         s32 ret_val = E1000_SUCCESS;
00994 
00995         DEBUGFUNC("e1000_setup_link_generic");
00996 
00997         /*
00998          * In the case of the phy reset being blocked, we already have a link.
00999          * We do not need to set it up again.
01000          */
01001         if (hw->phy.ops.check_reset_block)
01002                 if (hw->phy.ops.check_reset_block(hw))
01003                         goto out;
01004 
01005         /*
01006          * If requested flow control is set to default, set flow control
01007          * based on the EEPROM flow control settings.
01008          */
01009         if (hw->fc.requested_mode == e1000_fc_default) {
01010                 ret_val = e1000_set_default_fc_generic(hw);
01011                 if (ret_val)
01012                         goto out;
01013         }
01014 
01015         /*
01016          * Save off the requested flow control mode for use later.  Depending
01017          * on the link partner's capabilities, we may or may not use this mode.
01018          */
01019         hw->fc.current_mode = hw->fc.requested_mode;
01020 
01021         DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
01022                 hw->fc.current_mode);
01023 
01024         /* Call the necessary media_type subroutine to configure the link. */
01025         ret_val = hw->mac.ops.setup_physical_interface(hw);
01026         if (ret_val)
01027                 goto out;
01028 
01029         /*
01030          * Initialize the flow control address, type, and PAUSE timer
01031          * registers to their default values.  This is done even if flow
01032          * control is disabled, because it does not hurt anything to
01033          * initialize these registers.
01034          */
01035         DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
01036         E1000_WRITE_REG(hw, E1000_FCT, FLOW_CONTROL_TYPE);
01037         E1000_WRITE_REG(hw, E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
01038         E1000_WRITE_REG(hw, E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
01039 
01040         E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
01041 
01042         ret_val = e1000_set_fc_watermarks_generic(hw);
01043 
01044 out:
01045         return ret_val;
01046 }
01047 
01048 /**
01049  *  e1000_setup_fiber_serdes_link_generic - Setup link for fiber/serdes
01050  *  @hw: pointer to the HW structure
01051  *
01052  *  Configures collision distance and flow control for fiber and serdes
01053  *  links.  Upon successful setup, poll for link.
01054  **/
01055 s32 e1000_setup_fiber_serdes_link_generic(struct e1000_hw *hw)
01056 {
01057         u32 ctrl;
01058         s32 ret_val = E1000_SUCCESS;
01059 
01060         DEBUGFUNC("e1000_setup_fiber_serdes_link_generic");
01061 
01062         ctrl = E1000_READ_REG(hw, E1000_CTRL);
01063 
01064         /* Take the link out of reset */
01065         ctrl &= ~E1000_CTRL_LRST;
01066 
01067         e1000_config_collision_dist_generic(hw);
01068 
01069         ret_val = e1000_commit_fc_settings_generic(hw);
01070         if (ret_val)
01071                 goto out;
01072 
01073         /*
01074          * Since auto-negotiation is enabled, take the link out of reset (the
01075          * link will be in reset, because we previously reset the chip). This
01076          * will restart auto-negotiation.  If auto-negotiation is successful
01077          * then the link-up status bit will be set and the flow control enable
01078          * bits (RFCE and TFCE) will be set according to their negotiated value.
01079          */
01080         DEBUGOUT("Auto-negotiation enabled\n");
01081 
01082         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
01083         E1000_WRITE_FLUSH(hw);
01084         msec_delay(1);
01085 
01086         /*
01087          * For these adapters, the SW definable pin 1 is set when the optics
01088          * detect a signal.  If we have a signal, then poll for a "Link-Up"
01089          * indication.
01090          */
01091         if (hw->phy.media_type == e1000_media_type_internal_serdes ||
01092             (E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) {
01093                 ret_val = e1000_poll_fiber_serdes_link_generic(hw);
01094         } else {
01095                 DEBUGOUT("No signal detected\n");
01096         }
01097 
01098 out:
01099         return ret_val;
01100 }
01101 
01102 /**
01103  *  e1000_config_collision_dist_generic - Configure collision distance
01104  *  @hw: pointer to the HW structure
01105  *
01106  *  Configures the collision distance to the default value and is used
01107  *  during link setup. Currently no func pointer exists and all
01108  *  implementations are handled in the generic version of this function.
01109  **/
01110 void e1000_config_collision_dist_generic(struct e1000_hw *hw)
01111 {
01112         u32 tctl;
01113 
01114         DEBUGFUNC("e1000_config_collision_dist_generic");
01115 
01116         tctl = E1000_READ_REG(hw, E1000_TCTL);
01117 
01118         tctl &= ~E1000_TCTL_COLD;
01119         tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
01120 
01121         E1000_WRITE_REG(hw, E1000_TCTL, tctl);
01122         E1000_WRITE_FLUSH(hw);
01123 }
01124 
01125 /**
01126  *  e1000_poll_fiber_serdes_link_generic - Poll for link up
01127  *  @hw: pointer to the HW structure
01128  *
01129  *  Polls for link up by reading the status register, if link fails to come
01130  *  up with auto-negotiation, then the link is forced if a signal is detected.
01131  **/
01132 s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
01133 {
01134         struct e1000_mac_info *mac = &hw->mac;
01135         u32 i, status;
01136         s32 ret_val = E1000_SUCCESS;
01137 
01138         DEBUGFUNC("e1000_poll_fiber_serdes_link_generic");
01139 
01140         /*
01141          * If we have a signal (the cable is plugged in, or assumed true for
01142          * serdes media) then poll for a "Link-Up" indication in the Device
01143          * Status Register.  Time-out if a link isn't seen in 500 milliseconds
01144          * seconds (Auto-negotiation should complete in less than 500
01145          * milliseconds even if the other end is doing it in SW).
01146          */
01147         for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
01148                 msec_delay(10);
01149                 status = E1000_READ_REG(hw, E1000_STATUS);
01150                 if (status & E1000_STATUS_LU)
01151                         break;
01152         }
01153         if (i == FIBER_LINK_UP_LIMIT) {
01154                 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
01155                 mac->autoneg_failed = 1;
01156                 /*
01157                  * AutoNeg failed to achieve a link, so we'll call
01158                  * mac->check_for_link. This routine will force the
01159                  * link up if we detect a signal. This will allow us to
01160                  * communicate with non-autonegotiating link partners.
01161                  */
01162                 ret_val = hw->mac.ops.check_for_link(hw);
01163                 if (ret_val) {
01164                         DEBUGOUT("Error while checking for link\n");
01165                         goto out;
01166                 }
01167                 mac->autoneg_failed = 0;
01168         } else {
01169                 mac->autoneg_failed = 0;
01170                 DEBUGOUT("Valid Link Found\n");
01171         }
01172 
01173 out:
01174         return ret_val;
01175 }
01176 
01177 /**
01178  *  e1000_commit_fc_settings_generic - Configure flow control
01179  *  @hw: pointer to the HW structure
01180  *
01181  *  Write the flow control settings to the Transmit Config Word Register (TXCW)
01182  *  base on the flow control settings in e1000_mac_info.
01183  **/
01184 s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
01185 {
01186         struct e1000_mac_info *mac = &hw->mac;
01187         u32 txcw;
01188         s32 ret_val = E1000_SUCCESS;
01189 
01190         DEBUGFUNC("e1000_commit_fc_settings_generic");
01191 
01192         /*
01193          * Check for a software override of the flow control settings, and
01194          * setup the device accordingly.  If auto-negotiation is enabled, then
01195          * software will have to set the "PAUSE" bits to the correct value in
01196          * the Transmit Config Word Register (TXCW) and re-start auto-
01197          * negotiation.  However, if auto-negotiation is disabled, then
01198          * software will have to manually configure the two flow control enable
01199          * bits in the CTRL register.
01200          *
01201          * The possible values of the "fc" parameter are:
01202          *      0:  Flow control is completely disabled
01203          *      1:  Rx flow control is enabled (we can receive pause frames,
01204          *          but not send pause frames).
01205          *      2:  Tx flow control is enabled (we can send pause frames but we
01206          *          do not support receiving pause frames).
01207          *      3:  Both Rx and Tx flow control (symmetric) are enabled.
01208          */
01209         switch (hw->fc.current_mode) {
01210         case e1000_fc_none:
01211                 /* Flow control completely disabled by a software over-ride. */
01212                 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
01213                 break;
01214         case e1000_fc_rx_pause:
01215                 /*
01216                  * Rx Flow control is enabled and Tx Flow control is disabled
01217                  * by a software over-ride. Since there really isn't a way to
01218                  * advertise that we are capable of Rx Pause ONLY, we will
01219                  * advertise that we support both symmetric and asymmetric RX
01220                  * PAUSE.  Later, we will disable the adapter's ability to send
01221                  * PAUSE frames.
01222                  */
01223                 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
01224                 break;
01225         case e1000_fc_tx_pause:
01226                 /*
01227                  * Tx Flow control is enabled, and Rx Flow control is disabled,
01228                  * by a software over-ride.
01229                  */
01230                 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
01231                 break;
01232         case e1000_fc_full:
01233                 /*
01234                  * Flow control (both Rx and Tx) is enabled by a software
01235                  * over-ride.
01236                  */
01237                 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
01238                 break;
01239         default:
01240                 DEBUGOUT("Flow control param set incorrectly\n");
01241                 ret_val = -E1000_ERR_CONFIG;
01242                 goto out;
01243                 break;
01244         }
01245 
01246         E1000_WRITE_REG(hw, E1000_TXCW, txcw);
01247         mac->txcw = txcw;
01248 
01249 out:
01250         return ret_val;
01251 }
01252 
01253 /**
01254  *  e1000_set_fc_watermarks_generic - Set flow control high/low watermarks
01255  *  @hw: pointer to the HW structure
01256  *
01257  *  Sets the flow control high/low threshold (watermark) registers.  If
01258  *  flow control XON frame transmission is enabled, then set XON frame
01259  *  transmission as well.
01260  **/
01261 s32 e1000_set_fc_watermarks_generic(struct e1000_hw *hw)
01262 {
01263         s32 ret_val = E1000_SUCCESS;
01264         u32 fcrtl = 0, fcrth = 0;
01265 
01266         DEBUGFUNC("e1000_set_fc_watermarks_generic");
01267 
01268         /*
01269          * Set the flow control receive threshold registers.  Normally,
01270          * these registers will be set to a default threshold that may be
01271          * adjusted later by the driver's runtime code.  However, if the
01272          * ability to transmit pause frames is not enabled, then these
01273          * registers will be set to 0.
01274          */
01275         if (hw->fc.current_mode & e1000_fc_tx_pause) {
01276                 /*
01277                  * We need to set up the Receive Threshold high and low water
01278                  * marks as well as (optionally) enabling the transmission of
01279                  * XON frames.
01280                  */
01281                 fcrtl = hw->fc.low_water;
01282                 if (hw->fc.send_xon)
01283                         fcrtl |= E1000_FCRTL_XONE;
01284 
01285                 fcrth = hw->fc.high_water;
01286         }
01287         E1000_WRITE_REG(hw, E1000_FCRTL, fcrtl);
01288         E1000_WRITE_REG(hw, E1000_FCRTH, fcrth);
01289 
01290         return ret_val;
01291 }
01292 
01293 /**
01294  *  e1000_set_default_fc_generic - Set flow control default values
01295  *  @hw: pointer to the HW structure
01296  *
01297  *  Read the EEPROM for the default values for flow control and store the
01298  *  values.
01299  **/
01300 s32 e1000_set_default_fc_generic(struct e1000_hw *hw)
01301 {
01302         s32 ret_val = E1000_SUCCESS;
01303         u16 nvm_data;
01304 
01305         DEBUGFUNC("e1000_set_default_fc_generic");
01306 
01307         /*
01308          * Read and store word 0x0F of the EEPROM. This word contains bits
01309          * that determine the hardware's default PAUSE (flow control) mode,
01310          * a bit that determines whether the HW defaults to enabling or
01311          * disabling auto-negotiation, and the direction of the
01312          * SW defined pins. If there is no SW over-ride of the flow
01313          * control setting, then the variable hw->fc will
01314          * be initialized based on a value in the EEPROM.
01315          */
01316         ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
01317 
01318         if (ret_val) {
01319                 DEBUGOUT("NVM Read Error\n");
01320                 goto out;
01321         }
01322 
01323         if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
01324                 hw->fc.requested_mode = e1000_fc_none;
01325         else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
01326                  NVM_WORD0F_ASM_DIR)
01327                 hw->fc.requested_mode = e1000_fc_tx_pause;
01328         else
01329                 hw->fc.requested_mode = e1000_fc_full;
01330 
01331 out:
01332         return ret_val;
01333 }
01334 
01335 /**
01336  *  e1000_force_mac_fc_generic - Force the MAC's flow control settings
01337  *  @hw: pointer to the HW structure
01338  *
01339  *  Force the MAC's flow control settings.  Sets the TFCE and RFCE bits in the
01340  *  device control register to reflect the adapter settings.  TFCE and RFCE
01341  *  need to be explicitly set by software when a copper PHY is used because
01342  *  autonegotiation is managed by the PHY rather than the MAC.  Software must
01343  *  also configure these bits when link is forced on a fiber connection.
01344  **/
01345 s32 e1000_force_mac_fc_generic(struct e1000_hw *hw)
01346 {
01347         u32 ctrl;
01348         s32 ret_val = E1000_SUCCESS;
01349 
01350         DEBUGFUNC("e1000_force_mac_fc_generic");
01351 
01352         ctrl = E1000_READ_REG(hw, E1000_CTRL);
01353 
01354         /*
01355          * Because we didn't get link via the internal auto-negotiation
01356          * mechanism (we either forced link or we got link via PHY
01357          * auto-neg), we have to manually enable/disable transmit an
01358          * receive flow control.
01359          *
01360          * The "Case" statement below enables/disable flow control
01361          * according to the "hw->fc.current_mode" parameter.
01362          *
01363          * The possible values of the "fc" parameter are:
01364          *      0:  Flow control is completely disabled
01365          *      1:  Rx flow control is enabled (we can receive pause
01366          *          frames but not send pause frames).
01367          *      2:  Tx flow control is enabled (we can send pause frames
01368          *          frames but we do not receive pause frames).
01369          *      3:  Both Rx and Tx flow control (symmetric) is enabled.
01370          *  other:  No other values should be possible at this point.
01371          */
01372         DEBUGOUT1("hw->fc.current_mode = %u\n", hw->fc.current_mode);
01373 
01374         switch (hw->fc.current_mode) {
01375         case e1000_fc_none:
01376                 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
01377                 break;
01378         case e1000_fc_rx_pause:
01379                 ctrl &= (~E1000_CTRL_TFCE);
01380                 ctrl |= E1000_CTRL_RFCE;
01381                 break;
01382         case e1000_fc_tx_pause:
01383                 ctrl &= (~E1000_CTRL_RFCE);
01384                 ctrl |= E1000_CTRL_TFCE;
01385                 break;
01386         case e1000_fc_full:
01387                 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
01388                 break;
01389         default:
01390                 DEBUGOUT("Flow control param set incorrectly\n");
01391                 ret_val = -E1000_ERR_CONFIG;
01392                 goto out;
01393         }
01394 
01395         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
01396 
01397 out:
01398         return ret_val;
01399 }
01400 
01401 /**
01402  *  e1000_config_fc_after_link_up_generic - Configures flow control after link
01403  *  @hw: pointer to the HW structure
01404  *
01405  *  Checks the status of auto-negotiation after link up to ensure that the
01406  *  speed and duplex were not forced.  If the link needed to be forced, then
01407  *  flow control needs to be forced also.  If auto-negotiation is enabled
01408  *  and did not fail, then we configure flow control based on our link
01409  *  partner.
01410  **/
01411 s32 e1000_config_fc_after_link_up_generic(struct e1000_hw *hw)
01412 {
01413         struct e1000_mac_info *mac = &hw->mac;
01414         s32 ret_val = E1000_SUCCESS;
01415         u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
01416         u16 speed, duplex;
01417 
01418         DEBUGFUNC("e1000_config_fc_after_link_up_generic");
01419 
01420         /*
01421          * Check for the case where we have fiber media and auto-neg failed
01422          * so we had to force link.  In this case, we need to force the
01423          * configuration of the MAC to match the "fc" parameter.
01424          */
01425         if (mac->autoneg_failed) {
01426                 if (hw->phy.media_type == e1000_media_type_fiber ||
01427                     hw->phy.media_type == e1000_media_type_internal_serdes)
01428                         ret_val = e1000_force_mac_fc_generic(hw);
01429         } else {
01430                 if (hw->phy.media_type == e1000_media_type_copper)
01431                         ret_val = e1000_force_mac_fc_generic(hw);
01432         }
01433 
01434         if (ret_val) {
01435                 DEBUGOUT("Error forcing flow control settings\n");
01436                 goto out;
01437         }
01438 
01439         /*
01440          * Check for the case where we have copper media and auto-neg is
01441          * enabled.  In this case, we need to check and see if Auto-Neg
01442          * has completed, and if so, how the PHY and link partner has
01443          * flow control configured.
01444          */
01445         if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
01446                 /*
01447                  * Read the MII Status Register and check to see if AutoNeg
01448                  * has completed.  We read this twice because this reg has
01449                  * some "sticky" (latched) bits.
01450                  */
01451                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
01452                 if (ret_val)
01453                         goto out;
01454                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
01455                 if (ret_val)
01456                         goto out;
01457 
01458                 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
01459                         DEBUGOUT("Copper PHY and Auto Neg "
01460                                  "has not completed.\n");
01461                         goto out;
01462                 }
01463 
01464                 /*
01465                  * The AutoNeg process has completed, so we now need to
01466                  * read both the Auto Negotiation Advertisement
01467                  * Register (Address 4) and the Auto_Negotiation Base
01468                  * Page Ability Register (Address 5) to determine how
01469                  * flow control was negotiated.
01470                  */
01471                 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
01472                                              &mii_nway_adv_reg);
01473                 if (ret_val)
01474                         goto out;
01475                 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
01476                                              &mii_nway_lp_ability_reg);
01477                 if (ret_val)
01478                         goto out;
01479 
01480                 /*
01481                  * Two bits in the Auto Negotiation Advertisement Register
01482                  * (Address 4) and two bits in the Auto Negotiation Base
01483                  * Page Ability Register (Address 5) determine flow control
01484                  * for both the PHY and the link partner.  The following
01485                  * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
01486                  * 1999, describes these PAUSE resolution bits and how flow
01487                  * control is determined based upon these settings.
01488                  * NOTE:  DC = Don't Care
01489                  *
01490                  *   LOCAL DEVICE  |   LINK PARTNER
01491                  * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
01492                  *-------|---------|-------|---------|--------------------
01493                  *   0   |    0    |  DC   |   DC    | e1000_fc_none
01494                  *   0   |    1    |   0   |   DC    | e1000_fc_none
01495                  *   0   |    1    |   1   |    0    | e1000_fc_none
01496                  *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
01497                  *   1   |    0    |   0   |   DC    | e1000_fc_none
01498                  *   1   |   DC    |   1   |   DC    | e1000_fc_full
01499                  *   1   |    1    |   0   |    0    | e1000_fc_none
01500                  *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
01501                  *
01502                  * Are both PAUSE bits set to 1?  If so, this implies
01503                  * Symmetric Flow Control is enabled at both ends.  The
01504                  * ASM_DIR bits are irrelevant per the spec.
01505                  *
01506                  * For Symmetric Flow Control:
01507                  *
01508                  *   LOCAL DEVICE  |   LINK PARTNER
01509                  * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
01510                  *-------|---------|-------|---------|--------------------
01511                  *   1   |   DC    |   1   |   DC    | E1000_fc_full
01512                  *
01513                  */
01514                 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
01515                     (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
01516                         /*
01517                          * Now we need to check if the user selected Rx ONLY
01518                          * of pause frames.  In this case, we had to advertise
01519                          * FULL flow control because we could not advertise RX
01520                          * ONLY. Hence, we must now check to see if we need to
01521                          * turn OFF  the TRANSMISSION of PAUSE frames.
01522                          */
01523                         if (hw->fc.requested_mode == e1000_fc_full) {
01524                                 hw->fc.current_mode = e1000_fc_full;
01525                                 DEBUGOUT("Flow Control = FULL.\r\n");
01526                         } else {
01527                                 hw->fc.current_mode = e1000_fc_rx_pause;
01528                                 DEBUGOUT("Flow Control = "
01529                                          "RX PAUSE frames only.\r\n");
01530                         }
01531                 }
01532                 /*
01533                  * For receiving PAUSE frames ONLY.
01534                  *
01535                  *   LOCAL DEVICE  |   LINK PARTNER
01536                  * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
01537                  *-------|---------|-------|---------|--------------------
01538                  *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
01539                  */
01540                 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
01541                           (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
01542                           (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
01543                           (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
01544                         hw->fc.current_mode = e1000_fc_tx_pause;
01545                         DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
01546                 }
01547                 /*
01548                  * For transmitting PAUSE frames ONLY.
01549                  *
01550                  *   LOCAL DEVICE  |   LINK PARTNER
01551                  * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
01552                  *-------|---------|-------|---------|--------------------
01553                  *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
01554                  */
01555                 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
01556                          (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
01557                          !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
01558                          (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
01559                         hw->fc.current_mode = e1000_fc_rx_pause;
01560                         DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
01561                 } else {
01562                         /*
01563                          * Per the IEEE spec, at this point flow control
01564                          * should be disabled.
01565                          */
01566                         hw->fc.current_mode = e1000_fc_none;
01567                         DEBUGOUT("Flow Control = NONE.\r\n");
01568                 }
01569 
01570                 /*
01571                  * Now we need to do one last check...  If we auto-
01572                  * negotiated to HALF DUPLEX, flow control should not be
01573                  * enabled per IEEE 802.3 spec.
01574                  */
01575                 ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
01576                 if (ret_val) {
01577                         DEBUGOUT("Error getting link speed and duplex\n");
01578                         goto out;
01579                 }
01580 
01581                 if (duplex == HALF_DUPLEX)
01582                         hw->fc.current_mode = e1000_fc_none;
01583 
01584                 /*
01585                  * Now we call a subroutine to actually force the MAC
01586                  * controller to use the correct flow control settings.
01587                  */
01588                 ret_val = e1000_force_mac_fc_generic(hw);
01589                 if (ret_val) {
01590                         DEBUGOUT("Error forcing flow control settings\n");
01591                         goto out;
01592                 }
01593         }
01594 
01595 out:
01596         return ret_val;
01597 }
01598 
01599 /**
01600  *  e1000_get_speed_and_duplex_copper_generic - Retrieve current speed/duplex
01601  *  @hw: pointer to the HW structure
01602  *  @speed: stores the current speed
01603  *  @duplex: stores the current duplex
01604  *
01605  *  Read the status register for the current speed/duplex and store the current
01606  *  speed and duplex for copper connections.
01607  **/
01608 s32 e1000_get_speed_and_duplex_copper_generic(struct e1000_hw *hw, u16 *speed,
01609                                               u16 *duplex)
01610 {
01611         u32 status;
01612 
01613         DEBUGFUNC("e1000_get_speed_and_duplex_copper_generic");
01614 
01615         status = E1000_READ_REG(hw, E1000_STATUS);
01616         if (status & E1000_STATUS_SPEED_1000) {
01617                 *speed = SPEED_1000;
01618                 DEBUGOUT("1000 Mbs, ");
01619         } else if (status & E1000_STATUS_SPEED_100) {
01620                 *speed = SPEED_100;
01621                 DEBUGOUT("100 Mbs, ");
01622         } else {
01623                 *speed = SPEED_10;
01624                 DEBUGOUT("10 Mbs, ");
01625         }
01626 
01627         if (status & E1000_STATUS_FD) {
01628                 *duplex = FULL_DUPLEX;
01629                 DEBUGOUT("Full Duplex\n");
01630         } else {
01631                 *duplex = HALF_DUPLEX;
01632                 DEBUGOUT("Half Duplex\n");
01633         }
01634 
01635         return E1000_SUCCESS;
01636 }
01637 
01638 /**
01639  *  e1000_get_speed_and_duplex_fiber_generic - Retrieve current speed/duplex
01640  *  @hw: pointer to the HW structure
01641  *  @speed: stores the current speed
01642  *  @duplex: stores the current duplex
01643  *
01644  *  Sets the speed and duplex to gigabit full duplex (the only possible option)
01645  *  for fiber/serdes links.
01646  **/
01647 s32 e1000_get_speed_and_duplex_fiber_serdes_generic(struct e1000_hw *hw __unused,
01648                                                     u16 *speed, u16 *duplex)
01649 {
01650         DEBUGFUNC("e1000_get_speed_and_duplex_fiber_serdes_generic");
01651 
01652         *speed = SPEED_1000;
01653         *duplex = FULL_DUPLEX;
01654 
01655         return E1000_SUCCESS;
01656 }
01657 
01658 /**
01659  *  e1000_get_hw_semaphore_generic - Acquire hardware semaphore
01660  *  @hw: pointer to the HW structure
01661  *
01662  *  Acquire the HW semaphore to access the PHY or NVM
01663  **/
01664 s32 e1000_get_hw_semaphore_generic(struct e1000_hw *hw __unused)
01665 {
01666 #if 0
01667         u32 swsm;
01668         s32 ret_val = E1000_SUCCESS;
01669         s32 timeout = hw->nvm.word_size + 1;
01670         s32 i = 0;
01671 
01672         DEBUGFUNC("e1000_get_hw_semaphore_generic");
01673 
01674         /* Get the SW semaphore */
01675         while (i < timeout) {
01676                 swsm = E1000_READ_REG(hw, E1000_SWSM);
01677                 if (!(swsm & E1000_SWSM_SMBI))
01678                         break;
01679 
01680                 usec_delay(50);
01681                 i++;
01682         }
01683 
01684         if (i == timeout) {
01685                 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
01686                 ret_val = -E1000_ERR_NVM;
01687                 goto out;
01688         }
01689 
01690         /* Get the FW semaphore. */
01691         for (i = 0; i < timeout; i++) {
01692                 swsm = E1000_READ_REG(hw, E1000_SWSM);
01693                 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
01694 
01695                 /* Semaphore acquired if bit latched */
01696                 if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI)
01697                         break;
01698 
01699                 usec_delay(50);
01700         }
01701 
01702         if (i == timeout) {
01703                 /* Release semaphores */
01704                 e1000_put_hw_semaphore_generic(hw);
01705                 DEBUGOUT("Driver can't access the NVM\n");
01706                 ret_val = -E1000_ERR_NVM;
01707                 goto out;
01708         }
01709 
01710 out:
01711         return ret_val;
01712 #endif
01713         return 0;
01714 }
01715 
01716 /**
01717  *  e1000_put_hw_semaphore_generic - Release hardware semaphore
01718  *  @hw: pointer to the HW structure
01719  *
01720  *  Release hardware semaphore used to access the PHY or NVM
01721  **/
01722 void e1000_put_hw_semaphore_generic(struct e1000_hw *hw __unused)
01723 {
01724 #if 0
01725         u32 swsm;
01726 
01727         DEBUGFUNC("e1000_put_hw_semaphore_generic");
01728 
01729         swsm = E1000_READ_REG(hw, E1000_SWSM);
01730 
01731         swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
01732 
01733         E1000_WRITE_REG(hw, E1000_SWSM, swsm);
01734 #endif
01735 }
01736 
01737 /**
01738  *  e1000_get_auto_rd_done_generic - Check for auto read completion
01739  *  @hw: pointer to the HW structure
01740  *
01741  *  Check EEPROM for Auto Read done bit.
01742  **/
01743 s32 e1000_get_auto_rd_done_generic(struct e1000_hw *hw)
01744 {
01745         s32 i = 0;
01746         s32 ret_val = E1000_SUCCESS;
01747 
01748         DEBUGFUNC("e1000_get_auto_rd_done_generic");
01749 
01750         while (i < AUTO_READ_DONE_TIMEOUT) {
01751                 if (E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_AUTO_RD)
01752                         break;
01753                 msec_delay(1);
01754                 i++;
01755         }
01756 
01757         if (i == AUTO_READ_DONE_TIMEOUT) {
01758                 DEBUGOUT("Auto read by HW from NVM has not completed.\n");
01759                 ret_val = -E1000_ERR_RESET;
01760                 goto out;
01761         }
01762 
01763 out:
01764         return ret_val;
01765 }
01766 
01767 /**
01768  *  e1000_valid_led_default_generic - Verify a valid default LED config
01769  *  @hw: pointer to the HW structure
01770  *  @data: pointer to the NVM (EEPROM)
01771  *
01772  *  Read the EEPROM for the current default LED configuration.  If the
01773  *  LED configuration is not valid, set to a valid LED configuration.
01774  **/
01775 s32 e1000_valid_led_default_generic(struct e1000_hw *hw, u16 *data)
01776 {
01777         s32 ret_val;
01778 
01779         DEBUGFUNC("e1000_valid_led_default_generic");
01780 
01781         ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
01782         if (ret_val) {
01783                 DEBUGOUT("NVM Read Error\n");
01784                 goto out;
01785         }
01786 
01787         if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
01788                 *data = ID_LED_DEFAULT;
01789 
01790 out:
01791         return ret_val;
01792 }
01793 
01794 /**
01795  *  e1000_id_led_init_generic -
01796  *  @hw: pointer to the HW structure
01797  *
01798  **/
01799 s32 e1000_id_led_init_generic(struct e1000_hw *hw __unused)
01800 {
01801 #if 0
01802         struct e1000_mac_info *mac = &hw->mac;
01803         s32 ret_val;
01804         const u32 ledctl_mask = 0x000000FF;
01805         const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
01806         const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
01807         u16 data, i, temp;
01808         const u16 led_mask = 0x0F;
01809 
01810         DEBUGFUNC("e1000_id_led_init_generic");
01811 
01812         ret_val = hw->nvm.ops.valid_led_default(hw, &data);
01813         if (ret_val)
01814                 goto out;
01815 
01816         mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL);
01817         mac->ledctl_mode1 = mac->ledctl_default;
01818         mac->ledctl_mode2 = mac->ledctl_default;
01819 
01820         for (i = 0; i < 4; i++) {
01821                 temp = (data >> (i << 2)) & led_mask;
01822                 switch (temp) {
01823                 case ID_LED_ON1_DEF2:
01824                 case ID_LED_ON1_ON2:
01825                 case ID_LED_ON1_OFF2:
01826                         mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
01827                         mac->ledctl_mode1 |= ledctl_on << (i << 3);
01828                         break;
01829                 case ID_LED_OFF1_DEF2:
01830                 case ID_LED_OFF1_ON2:
01831                 case ID_LED_OFF1_OFF2:
01832                         mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
01833                         mac->ledctl_mode1 |= ledctl_off << (i << 3);
01834                         break;
01835                 default:
01836                         /* Do nothing */
01837                         break;
01838                 }
01839                 switch (temp) {
01840                 case ID_LED_DEF1_ON2:
01841                 case ID_LED_ON1_ON2:
01842                 case ID_LED_OFF1_ON2:
01843                         mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
01844                         mac->ledctl_mode2 |= ledctl_on << (i << 3);
01845                         break;
01846                 case ID_LED_DEF1_OFF2:
01847                 case ID_LED_ON1_OFF2:
01848                 case ID_LED_OFF1_OFF2:
01849                         mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
01850                         mac->ledctl_mode2 |= ledctl_off << (i << 3);
01851                         break;
01852                 default:
01853                         /* Do nothing */
01854                         break;
01855                 }
01856         }
01857 
01858 out:
01859         return ret_val;
01860 #endif
01861         return 0;
01862 }
01863 
01864 /**
01865  *  e1000_setup_led_generic - Configures SW controllable LED
01866  *  @hw: pointer to the HW structure
01867  *
01868  *  This prepares the SW controllable LED for use and saves the current state
01869  *  of the LED so it can be later restored.
01870  **/
01871 s32 e1000_setup_led_generic(struct e1000_hw *hw __unused)
01872 {
01873 #if 0
01874         u32 ledctl;
01875         s32 ret_val = E1000_SUCCESS;
01876 
01877         DEBUGFUNC("e1000_setup_led_generic");
01878 
01879         if (hw->mac.ops.setup_led != e1000_setup_led_generic) {
01880                 ret_val = -E1000_ERR_CONFIG;
01881                 goto out;
01882         }
01883 
01884         if (hw->phy.media_type == e1000_media_type_fiber) {
01885                 ledctl = E1000_READ_REG(hw, E1000_LEDCTL);
01886                 hw->mac.ledctl_default = ledctl;
01887                 /* Turn off LED0 */
01888                 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
01889                             E1000_LEDCTL_LED0_BLINK |
01890                             E1000_LEDCTL_LED0_MODE_MASK);
01891                 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
01892                            E1000_LEDCTL_LED0_MODE_SHIFT);
01893                 E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);
01894         } else if (hw->phy.media_type == e1000_media_type_copper) {
01895                 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
01896         }
01897 
01898 out:
01899         return ret_val;
01900 #endif
01901         return 0;
01902 }
01903 
01904 /**
01905  *  e1000_cleanup_led_generic - Set LED config to default operation
01906  *  @hw: pointer to the HW structure
01907  *
01908  *  Remove the current LED configuration and set the LED configuration
01909  *  to the default value, saved from the EEPROM.
01910  **/
01911 s32 e1000_cleanup_led_generic(struct e1000_hw *hw __unused)
01912 {
01913 #if 0
01914         s32 ret_val = E1000_SUCCESS;
01915 
01916         DEBUGFUNC("e1000_cleanup_led_generic");
01917 
01918         if (hw->mac.ops.cleanup_led != e1000_cleanup_led_generic) {
01919                 ret_val = -E1000_ERR_CONFIG;
01920                 goto out;
01921         }
01922 
01923         E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
01924 
01925 out:
01926         return ret_val;
01927 #endif
01928         return 0;
01929 }
01930 
01931 /**
01932  *  e1000_blink_led_generic - Blink LED
01933  *  @hw: pointer to the HW structure
01934  *
01935  *  Blink the LEDs which are set to be on.
01936  **/
01937 s32 e1000_blink_led_generic(struct e1000_hw *hw __unused)
01938 {
01939 #if 0
01940         u32 ledctl_blink = 0;
01941         u32 i;
01942 
01943         DEBUGFUNC("e1000_blink_led_generic");
01944 
01945         if (hw->phy.media_type == e1000_media_type_fiber) {
01946                 /* always blink LED0 for PCI-E fiber */
01947                 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
01948                      (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
01949         } else {
01950                 /*
01951                  * set the blink bit for each LED that's "on" (0x0E)
01952                  * in ledctl_mode2
01953                  */
01954                 ledctl_blink = hw->mac.ledctl_mode2;
01955                 for (i = 0; i < 4; i++)
01956                         if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
01957                             E1000_LEDCTL_MODE_LED_ON)
01958                                 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
01959                                                  (i * 8));
01960         }
01961 
01962         E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl_blink);
01963 
01964         return E1000_SUCCESS;
01965 #endif
01966         return 0;
01967 }
01968 
01969 /**
01970  *  e1000_led_on_generic - Turn LED on
01971  *  @hw: pointer to the HW structure
01972  *
01973  *  Turn LED on.
01974  **/
01975 s32 e1000_led_on_generic(struct e1000_hw *hw __unused)
01976 {
01977 #if 0
01978         u32 ctrl;
01979 
01980         DEBUGFUNC("e1000_led_on_generic");
01981 
01982         switch (hw->phy.media_type) {
01983         case e1000_media_type_fiber:
01984                 ctrl = E1000_READ_REG(hw, E1000_CTRL);
01985                 ctrl &= ~E1000_CTRL_SWDPIN0;
01986                 ctrl |= E1000_CTRL_SWDPIO0;
01987                 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
01988                 break;
01989         case e1000_media_type_copper:
01990                 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
01991                 break;
01992         default:
01993                 break;
01994         }
01995 
01996         return E1000_SUCCESS;
01997 #endif
01998         return 0;
01999 }
02000 
02001 /**
02002  *  e1000_led_off_generic - Turn LED off
02003  *  @hw: pointer to the HW structure
02004  *
02005  *  Turn LED off.
02006  **/
02007 s32 e1000_led_off_generic(struct e1000_hw *hw __unused)
02008 {
02009 #if 0
02010         u32 ctrl;
02011 
02012         DEBUGFUNC("e1000_led_off_generic");
02013 
02014         switch (hw->phy.media_type) {
02015         case e1000_media_type_fiber:
02016                 ctrl = E1000_READ_REG(hw, E1000_CTRL);
02017                 ctrl |= E1000_CTRL_SWDPIN0;
02018                 ctrl |= E1000_CTRL_SWDPIO0;
02019                 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
02020                 break;
02021         case e1000_media_type_copper:
02022                 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
02023                 break;
02024         default:
02025                 break;
02026         }
02027 
02028         return E1000_SUCCESS;
02029 #endif
02030         return 0;
02031 }
02032 
02033 /**
02034  *  e1000_set_pcie_no_snoop_generic - Set PCI-express capabilities
02035  *  @hw: pointer to the HW structure
02036  *  @no_snoop: bitmap of snoop events
02037  *
02038  *  Set the PCI-express register to snoop for events enabled in 'no_snoop'.
02039  **/
02040 void e1000_set_pcie_no_snoop_generic(struct e1000_hw *hw, u32 no_snoop)
02041 {
02042         u32 gcr;
02043 
02044         DEBUGFUNC("e1000_set_pcie_no_snoop_generic");
02045 
02046         if (hw->bus.type != e1000_bus_type_pci_express)
02047                 goto out;
02048 
02049         if (no_snoop) {
02050                 gcr = E1000_READ_REG(hw, E1000_GCR);
02051                 gcr &= ~(PCIE_NO_SNOOP_ALL);
02052                 gcr |= no_snoop;
02053                 E1000_WRITE_REG(hw, E1000_GCR, gcr);
02054         }
02055 out:
02056         return;
02057 }
02058 
02059 /**
02060  *  e1000_disable_pcie_master_generic - Disables PCI-express master access
02061  *  @hw: pointer to the HW structure
02062  *
02063  *  Returns 0 (E1000_SUCCESS) if successful, else returns -10
02064  *  (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
02065  *  the master requests to be disabled.
02066  *
02067  *  Disables PCI-Express master access and verifies there are no pending
02068  *  requests.
02069  **/
02070 s32 e1000_disable_pcie_master_generic(struct e1000_hw *hw)
02071 {
02072         u32 ctrl;
02073         s32 timeout = MASTER_DISABLE_TIMEOUT;
02074         s32 ret_val = E1000_SUCCESS;
02075 
02076         DEBUGFUNC("e1000_disable_pcie_master_generic");
02077 
02078         if (hw->bus.type != e1000_bus_type_pci_express)
02079                 goto out;
02080 
02081         ctrl = E1000_READ_REG(hw, E1000_CTRL);
02082         ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
02083         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
02084 
02085         while (timeout) {
02086                 if (!(E1000_READ_REG(hw, E1000_STATUS) &
02087                       E1000_STATUS_GIO_MASTER_ENABLE))
02088                         break;
02089                 usec_delay(100);
02090                 timeout--;
02091         }
02092 
02093         if (!timeout) {
02094                 DEBUGOUT("Master requests are pending.\n");
02095                 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
02096                 goto out;
02097         }
02098 
02099 out:
02100         return ret_val;
02101 }
02102 
02103 /**
02104  *  e1000_reset_adaptive_generic - Reset Adaptive Interframe Spacing
02105  *  @hw: pointer to the HW structure
02106  *
02107  *  Reset the Adaptive Interframe Spacing throttle to default values.
02108  **/
02109 void e1000_reset_adaptive_generic(struct e1000_hw *hw)
02110 {
02111         struct e1000_mac_info *mac = &hw->mac;
02112 
02113         DEBUGFUNC("e1000_reset_adaptive_generic");
02114 
02115         if (!mac->adaptive_ifs) {
02116                 DEBUGOUT("Not in Adaptive IFS mode!\n");
02117                 goto out;
02118         }
02119 
02120         mac->current_ifs_val = 0;
02121         mac->ifs_min_val = IFS_MIN;
02122         mac->ifs_max_val = IFS_MAX;
02123         mac->ifs_step_size = IFS_STEP;
02124         mac->ifs_ratio = IFS_RATIO;
02125 
02126         mac->in_ifs_mode = false;
02127         E1000_WRITE_REG(hw, E1000_AIT, 0);
02128 out:
02129         return;
02130 }
02131 
02132 /**
02133  *  e1000_update_adaptive_generic - Update Adaptive Interframe Spacing
02134  *  @hw: pointer to the HW structure
02135  *
02136  *  Update the Adaptive Interframe Spacing Throttle value based on the
02137  *  time between transmitted packets and time between collisions.
02138  **/
02139 void e1000_update_adaptive_generic(struct e1000_hw *hw)
02140 {
02141         struct e1000_mac_info *mac = &hw->mac;
02142 
02143         DEBUGFUNC("e1000_update_adaptive_generic");
02144 
02145         if (!mac->adaptive_ifs) {
02146                 DEBUGOUT("Not in Adaptive IFS mode!\n");
02147                 goto out;
02148         }
02149 
02150         if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
02151                 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
02152                         mac->in_ifs_mode = true;
02153                         if (mac->current_ifs_val < mac->ifs_max_val) {
02154                                 if (!mac->current_ifs_val)
02155                                         mac->current_ifs_val = mac->ifs_min_val;
02156                                 else
02157                                         mac->current_ifs_val +=
02158                                                 mac->ifs_step_size;
02159                                 E1000_WRITE_REG(hw, E1000_AIT, mac->current_ifs_val);
02160                         }
02161                 }
02162         } else {
02163                 if (mac->in_ifs_mode &&
02164                     (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
02165                         mac->current_ifs_val = 0;
02166                         mac->in_ifs_mode = false;
02167                         E1000_WRITE_REG(hw, E1000_AIT, 0);
02168                 }
02169         }
02170 out:
02171         return;
02172 }
02173 
02174 /**
02175  *  e1000_validate_mdi_setting_generic - Verify MDI/MDIx settings
02176  *  @hw: pointer to the HW structure
02177  *
02178  *  Verify that when not using auto-negotiation that MDI/MDIx is correctly
02179  *  set, which is forced to MDI mode only.
02180  **/
02181 static s32 e1000_validate_mdi_setting_generic(struct e1000_hw *hw)
02182 {
02183         s32 ret_val = E1000_SUCCESS;
02184 
02185         DEBUGFUNC("e1000_validate_mdi_setting_generic");
02186 
02187         if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
02188                 DEBUGOUT("Invalid MDI setting detected\n");
02189                 hw->phy.mdix = 1;
02190                 ret_val = -E1000_ERR_CONFIG;
02191                 goto out;
02192         }
02193 
02194 out:
02195         return ret_val;
02196 }

Generated on Tue Apr 6 20:00:57 2010 for gPXE by  doxygen 1.5.7.1