wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1 | /************************************************************************** |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 2 | Intel Pro 1000 for ppcboot/das-u-boot |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3 | Drivers are port from Intel's Linux driver e1000-4.3.15 |
| 4 | and from Etherboot pro 1000 driver by mrakes at vivato dot net |
| 5 | tested on both gig copper and gig fiber boards |
| 6 | ***************************************************************************/ |
| 7 | /******************************************************************************* |
| 8 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 9 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 10 | Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 11 | |
| 12 | This program is free software; you can redistribute it and/or modify it |
| 13 | under the terms of the GNU General Public License as published by the Free |
| 14 | Software Foundation; either version 2 of the License, or (at your option) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 15 | any later version. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 16 | |
| 17 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 20 | more details. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 21 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 22 | You should have received a copy of the GNU General Public License along with |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 23 | this program; if not, write to the Free Software Foundation, Inc., 59 |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 24 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 26 | The full GNU General Public License is included in this distribution in the |
| 27 | file called LICENSE. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 28 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 29 | Contact Information: |
| 30 | Linux NICS <linux.nics@intel.com> |
| 31 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | |
| 33 | *******************************************************************************/ |
| 34 | /* |
| 35 | * Copyright (C) Archway Digital Solutions. |
| 36 | * |
| 37 | * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org> |
| 38 | * 2/9/2002 |
| 39 | * |
| 40 | * Copyright (C) Linux Networx. |
| 41 | * Massive upgrade to work with the new intel gigabit NICs. |
| 42 | * <ebiederman at lnxi dot com> |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 43 | * |
| 44 | * Copyright 2011 Freescale Semiconductor, Inc. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | #include "e1000.h" |
| 48 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 49 | #define TOUT_LOOP 100000 |
| 50 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 51 | #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v)) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 52 | #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 53 | |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 54 | #define E1000_DEFAULT_PCI_PBA 0x00000030 |
| 55 | #define E1000_DEFAULT_PCIE_PBA 0x000a0026 |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 56 | |
| 57 | /* NIC specific static variables go here */ |
| 58 | |
| 59 | static char tx_pool[128 + 16]; |
| 60 | static char rx_pool[128 + 16]; |
| 61 | static char packet[2096]; |
| 62 | |
| 63 | static struct e1000_tx_desc *tx_base; |
| 64 | static struct e1000_rx_desc *rx_base; |
| 65 | |
| 66 | static int tx_tail; |
| 67 | static int rx_tail, rx_last; |
| 68 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 69 | static struct pci_device_id e1000_supported[] = { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 70 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542}, |
| 71 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER}, |
| 72 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER}, |
| 73 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER}, |
| 74 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER}, |
| 75 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER}, |
| 76 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM}, |
| 77 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM}, |
| 78 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER}, |
Paul Gortmaker | 7d13b8d | 2008-07-09 17:50:45 -0400 | [diff] [blame] | 79 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER}, |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 80 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER}, |
| 81 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER}, |
| 82 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER}, |
Reinhard Arlt | 1140ea5 | 2009-12-04 09:52:17 +0100 | [diff] [blame] | 83 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER}, |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 84 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM}, |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 85 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER}, |
Wolfgang Grandegger | 8562c38 | 2008-05-28 19:55:19 +0200 | [diff] [blame] | 86 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF}, |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 87 | /* E1000 PCIe card */ |
| 88 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER}, |
| 89 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER }, |
| 90 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES }, |
| 91 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER}, |
| 92 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER}, |
| 93 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER}, |
| 94 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE}, |
| 95 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL}, |
| 96 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD}, |
| 97 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER}, |
| 98 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER}, |
| 99 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES}, |
| 100 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI}, |
| 101 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E}, |
| 102 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT}, |
| 103 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L}, |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 104 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L}, |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 105 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3}, |
| 106 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT}, |
| 107 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT}, |
| 108 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT}, |
| 109 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT}, |
Stefan Althoefer | bc6d2fc | 2008-12-20 19:40:41 +0100 | [diff] [blame] | 110 | {} |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /* Function forward declarations */ |
| 114 | static int e1000_setup_link(struct eth_device *nic); |
| 115 | static int e1000_setup_fiber_link(struct eth_device *nic); |
| 116 | static int e1000_setup_copper_link(struct eth_device *nic); |
| 117 | static int e1000_phy_setup_autoneg(struct e1000_hw *hw); |
| 118 | static void e1000_config_collision_dist(struct e1000_hw *hw); |
| 119 | static int e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 120 | static int e1000_config_fc_after_link_up(struct e1000_hw *hw); |
| 121 | static int e1000_check_for_link(struct eth_device *nic); |
| 122 | static int e1000_wait_autoneg(struct e1000_hw *hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 123 | static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed, |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 124 | uint16_t * duplex); |
| 125 | static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, |
| 126 | uint16_t * phy_data); |
| 127 | static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, |
| 128 | uint16_t phy_data); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 129 | static int32_t e1000_phy_hw_reset(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 130 | static int e1000_phy_reset(struct e1000_hw *hw); |
| 131 | static int e1000_detect_gig_phy(struct e1000_hw *hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 132 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw); |
| 133 | static void e1000_set_media_type(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 134 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 135 | static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask); |
| 136 | static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 137 | #define E1000_WRITE_REG(a, reg, value) (writel((value), ((a)->hw_addr + E1000_##reg))) |
| 138 | #define E1000_READ_REG(a, reg) (readl((a)->hw_addr + E1000_##reg)) |
| 139 | #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) (\ |
| 140 | writel((value), ((a)->hw_addr + E1000_##reg + ((offset) << 2)))) |
| 141 | #define E1000_READ_REG_ARRAY(a, reg, offset) ( \ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 142 | readl((a)->hw_addr + E1000_##reg + ((offset) << 2))) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 143 | #define E1000_WRITE_FLUSH(a) {uint32_t x; x = E1000_READ_REG(a, STATUS);} |
| 144 | |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 145 | #ifndef CONFIG_AP1000 /* remove for warnings */ |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 146 | static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset, |
| 147 | uint16_t words, |
| 148 | uint16_t *data); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 149 | /****************************************************************************** |
| 150 | * Raises the EEPROM's clock input. |
| 151 | * |
| 152 | * hw - Struct containing variables accessed by shared code |
| 153 | * eecd - EECD's current value |
| 154 | *****************************************************************************/ |
| 155 | static void |
| 156 | e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd) |
| 157 | { |
| 158 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 159 | * wait 50 microseconds. |
| 160 | */ |
| 161 | *eecd = *eecd | E1000_EECD_SK; |
| 162 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 163 | E1000_WRITE_FLUSH(hw); |
| 164 | udelay(50); |
| 165 | } |
| 166 | |
| 167 | /****************************************************************************** |
| 168 | * Lowers the EEPROM's clock input. |
| 169 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 170 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 171 | * eecd - EECD's current value |
| 172 | *****************************************************************************/ |
| 173 | static void |
| 174 | e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd) |
| 175 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 176 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 177 | * wait 50 microseconds. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 178 | */ |
| 179 | *eecd = *eecd & ~E1000_EECD_SK; |
| 180 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 181 | E1000_WRITE_FLUSH(hw); |
| 182 | udelay(50); |
| 183 | } |
| 184 | |
| 185 | /****************************************************************************** |
| 186 | * Shift data bits out to the EEPROM. |
| 187 | * |
| 188 | * hw - Struct containing variables accessed by shared code |
| 189 | * data - data to send to the EEPROM |
| 190 | * count - number of bits to shift out |
| 191 | *****************************************************************************/ |
| 192 | static void |
| 193 | e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count) |
| 194 | { |
| 195 | uint32_t eecd; |
| 196 | uint32_t mask; |
| 197 | |
| 198 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 199 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 200 | * In order to do this, "data" must be broken down into bits. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 201 | */ |
| 202 | mask = 0x01 << (count - 1); |
| 203 | eecd = E1000_READ_REG(hw, EECD); |
| 204 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 205 | do { |
| 206 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 207 | * and then raising and then lowering the clock (the SK bit controls |
| 208 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 209 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 210 | */ |
| 211 | eecd &= ~E1000_EECD_DI; |
| 212 | |
| 213 | if (data & mask) |
| 214 | eecd |= E1000_EECD_DI; |
| 215 | |
| 216 | E1000_WRITE_REG(hw, EECD, eecd); |
| 217 | E1000_WRITE_FLUSH(hw); |
| 218 | |
| 219 | udelay(50); |
| 220 | |
| 221 | e1000_raise_ee_clk(hw, &eecd); |
| 222 | e1000_lower_ee_clk(hw, &eecd); |
| 223 | |
| 224 | mask = mask >> 1; |
| 225 | |
| 226 | } while (mask); |
| 227 | |
| 228 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 229 | eecd &= ~E1000_EECD_DI; |
| 230 | E1000_WRITE_REG(hw, EECD, eecd); |
| 231 | } |
| 232 | |
| 233 | /****************************************************************************** |
| 234 | * Shift data bits in from the EEPROM |
| 235 | * |
| 236 | * hw - Struct containing variables accessed by shared code |
| 237 | *****************************************************************************/ |
| 238 | static uint16_t |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 239 | e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 240 | { |
| 241 | uint32_t eecd; |
| 242 | uint32_t i; |
| 243 | uint16_t data; |
| 244 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 245 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 246 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 247 | * input to the EEPROM (setting the SK bit), and then reading the |
| 248 | * value of the "DO" bit. During this "shifting in" process the |
| 249 | * "DI" bit should always be clear. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 250 | */ |
| 251 | |
| 252 | eecd = E1000_READ_REG(hw, EECD); |
| 253 | |
| 254 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 255 | data = 0; |
| 256 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 257 | for (i = 0; i < count; i++) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 258 | data = data << 1; |
| 259 | e1000_raise_ee_clk(hw, &eecd); |
| 260 | |
| 261 | eecd = E1000_READ_REG(hw, EECD); |
| 262 | |
| 263 | eecd &= ~(E1000_EECD_DI); |
| 264 | if (eecd & E1000_EECD_DO) |
| 265 | data |= 1; |
| 266 | |
| 267 | e1000_lower_ee_clk(hw, &eecd); |
| 268 | } |
| 269 | |
| 270 | return data; |
| 271 | } |
| 272 | |
| 273 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 274 | * Returns EEPROM to a "standby" state |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 275 | * |
| 276 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 277 | *****************************************************************************/ |
| 278 | static void |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 279 | e1000_standby_eeprom(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 280 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 281 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 282 | uint32_t eecd; |
| 283 | |
| 284 | eecd = E1000_READ_REG(hw, EECD); |
| 285 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 286 | if (eeprom->type == e1000_eeprom_microwire) { |
| 287 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 288 | E1000_WRITE_REG(hw, EECD, eecd); |
| 289 | E1000_WRITE_FLUSH(hw); |
| 290 | udelay(eeprom->delay_usec); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 291 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 292 | /* Clock high */ |
| 293 | eecd |= E1000_EECD_SK; |
| 294 | E1000_WRITE_REG(hw, EECD, eecd); |
| 295 | E1000_WRITE_FLUSH(hw); |
| 296 | udelay(eeprom->delay_usec); |
| 297 | |
| 298 | /* Select EEPROM */ |
| 299 | eecd |= E1000_EECD_CS; |
| 300 | E1000_WRITE_REG(hw, EECD, eecd); |
| 301 | E1000_WRITE_FLUSH(hw); |
| 302 | udelay(eeprom->delay_usec); |
| 303 | |
| 304 | /* Clock low */ |
| 305 | eecd &= ~E1000_EECD_SK; |
| 306 | E1000_WRITE_REG(hw, EECD, eecd); |
| 307 | E1000_WRITE_FLUSH(hw); |
| 308 | udelay(eeprom->delay_usec); |
| 309 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 310 | /* Toggle CS to flush commands */ |
| 311 | eecd |= E1000_EECD_CS; |
| 312 | E1000_WRITE_REG(hw, EECD, eecd); |
| 313 | E1000_WRITE_FLUSH(hw); |
| 314 | udelay(eeprom->delay_usec); |
| 315 | eecd &= ~E1000_EECD_CS; |
| 316 | E1000_WRITE_REG(hw, EECD, eecd); |
| 317 | E1000_WRITE_FLUSH(hw); |
| 318 | udelay(eeprom->delay_usec); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /*************************************************************************** |
| 323 | * Description: Determines if the onboard NVM is FLASH or EEPROM. |
| 324 | * |
| 325 | * hw - Struct containing variables accessed by shared code |
| 326 | ****************************************************************************/ |
| 327 | static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw) |
| 328 | { |
| 329 | uint32_t eecd = 0; |
| 330 | |
| 331 | DEBUGFUNC(); |
| 332 | |
| 333 | if (hw->mac_type == e1000_ich8lan) |
| 334 | return FALSE; |
| 335 | |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 336 | if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 337 | eecd = E1000_READ_REG(hw, EECD); |
| 338 | |
| 339 | /* Isolate bits 15 & 16 */ |
| 340 | eecd = ((eecd >> 15) & 0x03); |
| 341 | |
| 342 | /* If both bits are set, device is Flash type */ |
| 343 | if (eecd == 0x03) |
| 344 | return FALSE; |
| 345 | } |
| 346 | return TRUE; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 350 | * Prepares EEPROM for access |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 351 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 352 | * hw - Struct containing variables accessed by shared code |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 353 | * |
| 354 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 355 | * function should be called before issuing a command to the EEPROM. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 356 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 357 | static int32_t |
| 358 | e1000_acquire_eeprom(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 359 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 360 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 361 | uint32_t eecd, i = 0; |
| 362 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 363 | DEBUGFUNC(); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 364 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 365 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 366 | return -E1000_ERR_SWFW_SYNC; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 367 | eecd = E1000_READ_REG(hw, EECD); |
| 368 | |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 369 | if (hw->mac_type != e1000_82573 || hw->mac_type != e1000_82574) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 370 | /* Request EEPROM Access */ |
| 371 | if (hw->mac_type > e1000_82544) { |
| 372 | eecd |= E1000_EECD_REQ; |
| 373 | E1000_WRITE_REG(hw, EECD, eecd); |
| 374 | eecd = E1000_READ_REG(hw, EECD); |
| 375 | while ((!(eecd & E1000_EECD_GNT)) && |
| 376 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 377 | i++; |
| 378 | udelay(5); |
| 379 | eecd = E1000_READ_REG(hw, EECD); |
| 380 | } |
| 381 | if (!(eecd & E1000_EECD_GNT)) { |
| 382 | eecd &= ~E1000_EECD_REQ; |
| 383 | E1000_WRITE_REG(hw, EECD, eecd); |
| 384 | DEBUGOUT("Could not acquire EEPROM grant\n"); |
| 385 | return -E1000_ERR_EEPROM; |
| 386 | } |
| 387 | } |
| 388 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 389 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 390 | /* Setup EEPROM for Read/Write */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 391 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 392 | if (eeprom->type == e1000_eeprom_microwire) { |
| 393 | /* Clear SK and DI */ |
| 394 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
| 395 | E1000_WRITE_REG(hw, EECD, eecd); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 396 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 397 | /* Set CS */ |
| 398 | eecd |= E1000_EECD_CS; |
| 399 | E1000_WRITE_REG(hw, EECD, eecd); |
| 400 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 401 | /* Clear SK and CS */ |
| 402 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 403 | E1000_WRITE_REG(hw, EECD, eecd); |
| 404 | udelay(1); |
| 405 | } |
| 406 | |
| 407 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 411 | * Sets up eeprom variables in the hw struct. Must be called after mac_type |
| 412 | * is configured. Additionally, if this is ICH8, the flash controller GbE |
| 413 | * registers must be mapped, or this will crash. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 414 | * |
| 415 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 416 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 417 | static int32_t e1000_init_eeprom_params(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 418 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 419 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 420 | uint32_t eecd = E1000_READ_REG(hw, EECD); |
| 421 | int32_t ret_val = E1000_SUCCESS; |
| 422 | uint16_t eeprom_size; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 423 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 424 | DEBUGFUNC(); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 425 | |
| 426 | switch (hw->mac_type) { |
| 427 | case e1000_82542_rev2_0: |
| 428 | case e1000_82542_rev2_1: |
| 429 | case e1000_82543: |
| 430 | case e1000_82544: |
| 431 | eeprom->type = e1000_eeprom_microwire; |
| 432 | eeprom->word_size = 64; |
| 433 | eeprom->opcode_bits = 3; |
| 434 | eeprom->address_bits = 6; |
| 435 | eeprom->delay_usec = 50; |
| 436 | eeprom->use_eerd = FALSE; |
| 437 | eeprom->use_eewr = FALSE; |
| 438 | break; |
| 439 | case e1000_82540: |
| 440 | case e1000_82545: |
| 441 | case e1000_82545_rev_3: |
| 442 | case e1000_82546: |
| 443 | case e1000_82546_rev_3: |
| 444 | eeprom->type = e1000_eeprom_microwire; |
| 445 | eeprom->opcode_bits = 3; |
| 446 | eeprom->delay_usec = 50; |
| 447 | if (eecd & E1000_EECD_SIZE) { |
| 448 | eeprom->word_size = 256; |
| 449 | eeprom->address_bits = 8; |
| 450 | } else { |
| 451 | eeprom->word_size = 64; |
| 452 | eeprom->address_bits = 6; |
| 453 | } |
| 454 | eeprom->use_eerd = FALSE; |
| 455 | eeprom->use_eewr = FALSE; |
| 456 | break; |
| 457 | case e1000_82541: |
| 458 | case e1000_82541_rev_2: |
| 459 | case e1000_82547: |
| 460 | case e1000_82547_rev_2: |
| 461 | if (eecd & E1000_EECD_TYPE) { |
| 462 | eeprom->type = e1000_eeprom_spi; |
| 463 | eeprom->opcode_bits = 8; |
| 464 | eeprom->delay_usec = 1; |
| 465 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 466 | eeprom->page_size = 32; |
| 467 | eeprom->address_bits = 16; |
| 468 | } else { |
| 469 | eeprom->page_size = 8; |
| 470 | eeprom->address_bits = 8; |
| 471 | } |
| 472 | } else { |
| 473 | eeprom->type = e1000_eeprom_microwire; |
| 474 | eeprom->opcode_bits = 3; |
| 475 | eeprom->delay_usec = 50; |
| 476 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 477 | eeprom->word_size = 256; |
| 478 | eeprom->address_bits = 8; |
| 479 | } else { |
| 480 | eeprom->word_size = 64; |
| 481 | eeprom->address_bits = 6; |
| 482 | } |
| 483 | } |
| 484 | eeprom->use_eerd = FALSE; |
| 485 | eeprom->use_eewr = FALSE; |
| 486 | break; |
| 487 | case e1000_82571: |
| 488 | case e1000_82572: |
| 489 | eeprom->type = e1000_eeprom_spi; |
| 490 | eeprom->opcode_bits = 8; |
| 491 | eeprom->delay_usec = 1; |
| 492 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 493 | eeprom->page_size = 32; |
| 494 | eeprom->address_bits = 16; |
| 495 | } else { |
| 496 | eeprom->page_size = 8; |
| 497 | eeprom->address_bits = 8; |
| 498 | } |
| 499 | eeprom->use_eerd = FALSE; |
| 500 | eeprom->use_eewr = FALSE; |
| 501 | break; |
| 502 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 503 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 504 | eeprom->type = e1000_eeprom_spi; |
| 505 | eeprom->opcode_bits = 8; |
| 506 | eeprom->delay_usec = 1; |
| 507 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 508 | eeprom->page_size = 32; |
| 509 | eeprom->address_bits = 16; |
| 510 | } else { |
| 511 | eeprom->page_size = 8; |
| 512 | eeprom->address_bits = 8; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 513 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 514 | eeprom->use_eerd = TRUE; |
| 515 | eeprom->use_eewr = TRUE; |
| 516 | if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) { |
| 517 | eeprom->type = e1000_eeprom_flash; |
| 518 | eeprom->word_size = 2048; |
| 519 | |
| 520 | /* Ensure that the Autonomous FLASH update bit is cleared due to |
| 521 | * Flash update issue on parts which use a FLASH for NVM. */ |
| 522 | eecd &= ~E1000_EECD_AUPDEN; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 523 | E1000_WRITE_REG(hw, EECD, eecd); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 524 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 525 | break; |
| 526 | case e1000_80003es2lan: |
| 527 | eeprom->type = e1000_eeprom_spi; |
| 528 | eeprom->opcode_bits = 8; |
| 529 | eeprom->delay_usec = 1; |
| 530 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 531 | eeprom->page_size = 32; |
| 532 | eeprom->address_bits = 16; |
| 533 | } else { |
| 534 | eeprom->page_size = 8; |
| 535 | eeprom->address_bits = 8; |
| 536 | } |
| 537 | eeprom->use_eerd = TRUE; |
| 538 | eeprom->use_eewr = FALSE; |
| 539 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 540 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 541 | /* ich8lan does not support currently. if needed, please |
| 542 | * add corresponding code and functions. |
| 543 | */ |
| 544 | #if 0 |
| 545 | case e1000_ich8lan: |
| 546 | { |
| 547 | int32_t i = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 548 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 549 | eeprom->type = e1000_eeprom_ich8; |
| 550 | eeprom->use_eerd = FALSE; |
| 551 | eeprom->use_eewr = FALSE; |
| 552 | eeprom->word_size = E1000_SHADOW_RAM_WORDS; |
| 553 | uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, |
| 554 | ICH_FLASH_GFPREG); |
| 555 | /* Zero the shadow RAM structure. But don't load it from NVM |
| 556 | * so as to save time for driver init */ |
| 557 | if (hw->eeprom_shadow_ram != NULL) { |
| 558 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
| 559 | hw->eeprom_shadow_ram[i].modified = FALSE; |
| 560 | hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF; |
| 561 | } |
| 562 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 563 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 564 | hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) * |
| 565 | ICH_FLASH_SECTOR_SIZE; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 566 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 567 | hw->flash_bank_size = ((flash_size >> 16) |
| 568 | & ICH_GFPREG_BASE_MASK) + 1; |
| 569 | hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 570 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 571 | hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE; |
| 572 | |
| 573 | hw->flash_bank_size /= 2 * sizeof(uint16_t); |
| 574 | break; |
| 575 | } |
| 576 | #endif |
| 577 | default: |
| 578 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 581 | if (eeprom->type == e1000_eeprom_spi) { |
| 582 | /* eeprom_size will be an enum [0..8] that maps |
| 583 | * to eeprom sizes 128B to |
| 584 | * 32KB (incremented by powers of 2). |
| 585 | */ |
| 586 | if (hw->mac_type <= e1000_82547_rev_2) { |
| 587 | /* Set to default value for initial eeprom read. */ |
| 588 | eeprom->word_size = 64; |
| 589 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, |
| 590 | &eeprom_size); |
| 591 | if (ret_val) |
| 592 | return ret_val; |
| 593 | eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) |
| 594 | >> EEPROM_SIZE_SHIFT; |
| 595 | /* 256B eeprom size was not supported in earlier |
| 596 | * hardware, so we bump eeprom_size up one to |
| 597 | * ensure that "1" (which maps to 256B) is never |
| 598 | * the result used in the shifting logic below. */ |
| 599 | if (eeprom_size) |
| 600 | eeprom_size++; |
| 601 | } else { |
| 602 | eeprom_size = (uint16_t)((eecd & |
| 603 | E1000_EECD_SIZE_EX_MASK) >> |
| 604 | E1000_EECD_SIZE_EX_SHIFT); |
| 605 | } |
| 606 | |
| 607 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
| 608 | } |
| 609 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 612 | /****************************************************************************** |
| 613 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. |
| 614 | * |
| 615 | * hw - Struct containing variables accessed by shared code |
| 616 | *****************************************************************************/ |
| 617 | static int32_t |
| 618 | e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 619 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 620 | uint32_t attempts = 100000; |
| 621 | uint32_t i, reg = 0; |
| 622 | int32_t done = E1000_ERR_EEPROM; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 623 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 624 | for (i = 0; i < attempts; i++) { |
| 625 | if (eerd == E1000_EEPROM_POLL_READ) |
| 626 | reg = E1000_READ_REG(hw, EERD); |
| 627 | else |
| 628 | reg = E1000_READ_REG(hw, EEWR); |
| 629 | |
| 630 | if (reg & E1000_EEPROM_RW_REG_DONE) { |
| 631 | done = E1000_SUCCESS; |
| 632 | break; |
| 633 | } |
| 634 | udelay(5); |
| 635 | } |
| 636 | |
| 637 | return done; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 640 | /****************************************************************************** |
| 641 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 642 | * |
| 643 | * hw - Struct containing variables accessed by shared code |
| 644 | * offset - offset of word in the EEPROM to read |
| 645 | * data - word read from the EEPROM |
| 646 | * words - number of words to read |
| 647 | *****************************************************************************/ |
| 648 | static int32_t |
| 649 | e1000_read_eeprom_eerd(struct e1000_hw *hw, |
| 650 | uint16_t offset, |
| 651 | uint16_t words, |
| 652 | uint16_t *data) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 653 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 654 | uint32_t i, eerd = 0; |
| 655 | int32_t error = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 656 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 657 | for (i = 0; i < words; i++) { |
| 658 | eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) + |
| 659 | E1000_EEPROM_RW_REG_START; |
| 660 | |
| 661 | E1000_WRITE_REG(hw, EERD, eerd); |
| 662 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ); |
| 663 | |
| 664 | if (error) |
| 665 | break; |
| 666 | data[i] = (E1000_READ_REG(hw, EERD) >> |
| 667 | E1000_EEPROM_RW_REG_DATA); |
| 668 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 669 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 670 | |
| 671 | return error; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 674 | static void |
| 675 | e1000_release_eeprom(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 676 | { |
| 677 | uint32_t eecd; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 678 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 679 | DEBUGFUNC(); |
| 680 | |
| 681 | eecd = E1000_READ_REG(hw, EECD); |
| 682 | |
| 683 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 684 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 685 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
| 686 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 687 | E1000_WRITE_REG(hw, EECD, eecd); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 688 | |
| 689 | udelay(hw->eeprom.delay_usec); |
| 690 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
| 691 | /* cleanup eeprom */ |
| 692 | |
| 693 | /* CS on Microwire is active-high */ |
| 694 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
| 695 | |
| 696 | E1000_WRITE_REG(hw, EECD, eecd); |
| 697 | |
| 698 | /* Rising edge of clock */ |
| 699 | eecd |= E1000_EECD_SK; |
| 700 | E1000_WRITE_REG(hw, EECD, eecd); |
| 701 | E1000_WRITE_FLUSH(hw); |
| 702 | udelay(hw->eeprom.delay_usec); |
| 703 | |
| 704 | /* Falling edge of clock */ |
| 705 | eecd &= ~E1000_EECD_SK; |
| 706 | E1000_WRITE_REG(hw, EECD, eecd); |
| 707 | E1000_WRITE_FLUSH(hw); |
| 708 | udelay(hw->eeprom.delay_usec); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 709 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 710 | |
| 711 | /* Stop requesting EEPROM access */ |
| 712 | if (hw->mac_type > e1000_82544) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 713 | eecd &= ~E1000_EECD_REQ; |
| 714 | E1000_WRITE_REG(hw, EECD, eecd); |
| 715 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 716 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 717 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 718 | * Reads a 16 bit word from the EEPROM. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 719 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 720 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 721 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 722 | static int32_t |
| 723 | e1000_spi_eeprom_ready(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 724 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 725 | uint16_t retry_count = 0; |
| 726 | uint8_t spi_stat_reg; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 727 | |
| 728 | DEBUGFUNC(); |
| 729 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 730 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 731 | * EEPROM will signal that the command has been completed by clearing |
| 732 | * bit 0 of the internal status register. If it's not cleared within |
| 733 | * 5 milliseconds, then error out. |
| 734 | */ |
| 735 | retry_count = 0; |
| 736 | do { |
| 737 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 738 | hw->eeprom.opcode_bits); |
| 739 | spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8); |
| 740 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 741 | break; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 742 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 743 | udelay(5); |
| 744 | retry_count += 5; |
| 745 | |
| 746 | e1000_standby_eeprom(hw); |
| 747 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
| 748 | |
| 749 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 750 | * only 0-5mSec on 5V devices) |
| 751 | */ |
| 752 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
| 753 | DEBUGOUT("SPI EEPROM Status error\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 754 | return -E1000_ERR_EEPROM; |
| 755 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 756 | |
| 757 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 761 | * Reads a 16 bit word from the EEPROM. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 762 | * |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 763 | * hw - Struct containing variables accessed by shared code |
| 764 | * offset - offset of word in the EEPROM to read |
| 765 | * data - word read from the EEPROM |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 766 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 767 | static int32_t |
| 768 | e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset, |
| 769 | uint16_t words, uint16_t *data) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 770 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 771 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 772 | uint32_t i = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 773 | |
| 774 | DEBUGFUNC(); |
| 775 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 776 | /* If eeprom is not yet detected, do so now */ |
| 777 | if (eeprom->word_size == 0) |
| 778 | e1000_init_eeprom_params(hw); |
| 779 | |
| 780 | /* A check for invalid values: offset too large, too many words, |
| 781 | * and not enough words. |
| 782 | */ |
| 783 | if ((offset >= eeprom->word_size) || |
| 784 | (words > eeprom->word_size - offset) || |
| 785 | (words == 0)) { |
| 786 | DEBUGOUT("\"words\" parameter out of bounds." |
| 787 | "Words = %d, size = %d\n", offset, eeprom->word_size); |
| 788 | return -E1000_ERR_EEPROM; |
| 789 | } |
| 790 | |
| 791 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 792 | * directly. In this case, we need to acquire the EEPROM so that |
| 793 | * FW or other port software does not interrupt. |
| 794 | */ |
| 795 | if (e1000_is_onboard_nvm_eeprom(hw) == TRUE && |
| 796 | hw->eeprom.use_eerd == FALSE) { |
| 797 | |
| 798 | /* Prepare the EEPROM for bit-bang reading */ |
| 799 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 800 | return -E1000_ERR_EEPROM; |
| 801 | } |
| 802 | |
| 803 | /* Eerd register EEPROM access requires no eeprom aquire/release */ |
| 804 | if (eeprom->use_eerd == TRUE) |
| 805 | return e1000_read_eeprom_eerd(hw, offset, words, data); |
| 806 | |
| 807 | /* ich8lan does not support currently. if needed, please |
| 808 | * add corresponding code and functions. |
| 809 | */ |
| 810 | #if 0 |
| 811 | /* ICH EEPROM access is done via the ICH flash controller */ |
| 812 | if (eeprom->type == e1000_eeprom_ich8) |
| 813 | return e1000_read_eeprom_ich8(hw, offset, words, data); |
| 814 | #endif |
| 815 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 816 | * acquired the EEPROM at this point, so any returns should relase it */ |
| 817 | if (eeprom->type == e1000_eeprom_spi) { |
| 818 | uint16_t word_in; |
| 819 | uint8_t read_opcode = EEPROM_READ_OPCODE_SPI; |
| 820 | |
| 821 | if (e1000_spi_eeprom_ready(hw)) { |
| 822 | e1000_release_eeprom(hw); |
| 823 | return -E1000_ERR_EEPROM; |
| 824 | } |
| 825 | |
| 826 | e1000_standby_eeprom(hw); |
| 827 | |
| 828 | /* Some SPI eeproms use the 8th address bit embedded in |
| 829 | * the opcode */ |
| 830 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
| 831 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
| 832 | |
| 833 | /* Send the READ command (opcode + addr) */ |
| 834 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
| 835 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), |
| 836 | eeprom->address_bits); |
| 837 | |
| 838 | /* Read the data. The address of the eeprom internally |
| 839 | * increments with each byte (spi) being read, saving on the |
| 840 | * overhead of eeprom setup and tear-down. The address |
| 841 | * counter will roll over if reading beyond the size of |
| 842 | * the eeprom, thus allowing the entire memory to be read |
| 843 | * starting from any offset. */ |
| 844 | for (i = 0; i < words; i++) { |
| 845 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 846 | data[i] = (word_in >> 8) | (word_in << 8); |
| 847 | } |
| 848 | } else if (eeprom->type == e1000_eeprom_microwire) { |
| 849 | for (i = 0; i < words; i++) { |
| 850 | /* Send the READ command (opcode + addr) */ |
| 851 | e1000_shift_out_ee_bits(hw, |
| 852 | EEPROM_READ_OPCODE_MICROWIRE, |
| 853 | eeprom->opcode_bits); |
| 854 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i), |
| 855 | eeprom->address_bits); |
| 856 | |
| 857 | /* Read the data. For microwire, each word requires |
| 858 | * the overhead of eeprom setup and tear-down. */ |
| 859 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 860 | e1000_standby_eeprom(hw); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | /* End this read operation */ |
| 865 | e1000_release_eeprom(hw); |
| 866 | |
| 867 | return E1000_SUCCESS; |
| 868 | } |
| 869 | |
| 870 | /****************************************************************************** |
| 871 | * Verifies that the EEPROM has a valid checksum |
| 872 | * |
| 873 | * hw - Struct containing variables accessed by shared code |
| 874 | * |
| 875 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 876 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 877 | * valid. |
| 878 | *****************************************************************************/ |
| 879 | static int |
| 880 | e1000_validate_eeprom_checksum(struct eth_device *nic) |
| 881 | { |
| 882 | struct e1000_hw *hw = nic->priv; |
| 883 | uint16_t checksum = 0; |
| 884 | uint16_t i, eeprom_data; |
| 885 | |
| 886 | DEBUGFUNC(); |
| 887 | |
| 888 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 889 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
| 890 | DEBUGOUT("EEPROM Read Error\n"); |
| 891 | return -E1000_ERR_EEPROM; |
| 892 | } |
| 893 | checksum += eeprom_data; |
| 894 | } |
| 895 | |
| 896 | if (checksum == (uint16_t) EEPROM_SUM) { |
| 897 | return 0; |
| 898 | } else { |
| 899 | DEBUGOUT("EEPROM Checksum Invalid\n"); |
| 900 | return -E1000_ERR_EEPROM; |
| 901 | } |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /***************************************************************************** |
| 905 | * Set PHY to class A mode |
| 906 | * Assumes the following operations will follow to enable the new class mode. |
| 907 | * 1. Do a PHY soft reset |
| 908 | * 2. Restart auto-negotiation or force link. |
| 909 | * |
| 910 | * hw - Struct containing variables accessed by shared code |
| 911 | ****************************************************************************/ |
| 912 | static int32_t |
| 913 | e1000_set_phy_mode(struct e1000_hw *hw) |
| 914 | { |
| 915 | int32_t ret_val; |
| 916 | uint16_t eeprom_data; |
| 917 | |
| 918 | DEBUGFUNC(); |
| 919 | |
| 920 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 921 | (hw->media_type == e1000_media_type_copper)) { |
| 922 | ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, |
| 923 | 1, &eeprom_data); |
| 924 | if (ret_val) |
| 925 | return ret_val; |
| 926 | |
| 927 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 928 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
| 929 | ret_val = e1000_write_phy_reg(hw, |
| 930 | M88E1000_PHY_PAGE_SELECT, 0x000B); |
| 931 | if (ret_val) |
| 932 | return ret_val; |
| 933 | ret_val = e1000_write_phy_reg(hw, |
| 934 | M88E1000_PHY_GEN_CONTROL, 0x8104); |
| 935 | if (ret_val) |
| 936 | return ret_val; |
| 937 | |
| 938 | hw->phy_reset_disable = FALSE; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | return E1000_SUCCESS; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 943 | } |
| 944 | #endif /* #ifndef CONFIG_AP1000 */ |
| 945 | |
| 946 | /*************************************************************************** |
| 947 | * |
| 948 | * Obtaining software semaphore bit (SMBI) before resetting PHY. |
| 949 | * |
| 950 | * hw: Struct containing variables accessed by shared code |
| 951 | * |
| 952 | * returns: - E1000_ERR_RESET if fail to obtain semaphore. |
| 953 | * E1000_SUCCESS at any other case. |
| 954 | * |
| 955 | ***************************************************************************/ |
| 956 | static int32_t |
| 957 | e1000_get_software_semaphore(struct e1000_hw *hw) |
| 958 | { |
| 959 | int32_t timeout = hw->eeprom.word_size + 1; |
| 960 | uint32_t swsm; |
| 961 | |
| 962 | DEBUGFUNC(); |
| 963 | |
| 964 | if (hw->mac_type != e1000_80003es2lan) |
| 965 | return E1000_SUCCESS; |
| 966 | |
| 967 | while (timeout) { |
| 968 | swsm = E1000_READ_REG(hw, SWSM); |
| 969 | /* If SMBI bit cleared, it is now set and we hold |
| 970 | * the semaphore */ |
| 971 | if (!(swsm & E1000_SWSM_SMBI)) |
| 972 | break; |
| 973 | mdelay(1); |
| 974 | timeout--; |
| 975 | } |
| 976 | |
| 977 | if (!timeout) { |
| 978 | DEBUGOUT("Driver can't access device - SMBI bit is set.\n"); |
| 979 | return -E1000_ERR_RESET; |
| 980 | } |
| 981 | |
| 982 | return E1000_SUCCESS; |
| 983 | } |
| 984 | |
| 985 | /*************************************************************************** |
| 986 | * This function clears HW semaphore bits. |
| 987 | * |
| 988 | * hw: Struct containing variables accessed by shared code |
| 989 | * |
| 990 | * returns: - None. |
| 991 | * |
| 992 | ***************************************************************************/ |
| 993 | static void |
| 994 | e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw) |
| 995 | { |
| 996 | uint32_t swsm; |
| 997 | |
| 998 | DEBUGFUNC(); |
| 999 | |
| 1000 | if (!hw->eeprom_semaphore_present) |
| 1001 | return; |
| 1002 | |
| 1003 | swsm = E1000_READ_REG(hw, SWSM); |
| 1004 | if (hw->mac_type == e1000_80003es2lan) { |
| 1005 | /* Release both semaphores. */ |
| 1006 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); |
| 1007 | } else |
| 1008 | swsm &= ~(E1000_SWSM_SWESMBI); |
| 1009 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 1010 | } |
| 1011 | |
| 1012 | /*************************************************************************** |
| 1013 | * |
| 1014 | * Using the combination of SMBI and SWESMBI semaphore bits when resetting |
| 1015 | * adapter or Eeprom access. |
| 1016 | * |
| 1017 | * hw: Struct containing variables accessed by shared code |
| 1018 | * |
| 1019 | * returns: - E1000_ERR_EEPROM if fail to access EEPROM. |
| 1020 | * E1000_SUCCESS at any other case. |
| 1021 | * |
| 1022 | ***************************************************************************/ |
| 1023 | static int32_t |
| 1024 | e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw) |
| 1025 | { |
| 1026 | int32_t timeout; |
| 1027 | uint32_t swsm; |
| 1028 | |
| 1029 | DEBUGFUNC(); |
| 1030 | |
| 1031 | if (!hw->eeprom_semaphore_present) |
| 1032 | return E1000_SUCCESS; |
| 1033 | |
| 1034 | if (hw->mac_type == e1000_80003es2lan) { |
| 1035 | /* Get the SW semaphore. */ |
| 1036 | if (e1000_get_software_semaphore(hw) != E1000_SUCCESS) |
| 1037 | return -E1000_ERR_EEPROM; |
| 1038 | } |
| 1039 | |
| 1040 | /* Get the FW semaphore. */ |
| 1041 | timeout = hw->eeprom.word_size + 1; |
| 1042 | while (timeout) { |
| 1043 | swsm = E1000_READ_REG(hw, SWSM); |
| 1044 | swsm |= E1000_SWSM_SWESMBI; |
| 1045 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 1046 | /* if we managed to set the bit we got the semaphore. */ |
| 1047 | swsm = E1000_READ_REG(hw, SWSM); |
| 1048 | if (swsm & E1000_SWSM_SWESMBI) |
| 1049 | break; |
| 1050 | |
| 1051 | udelay(50); |
| 1052 | timeout--; |
| 1053 | } |
| 1054 | |
| 1055 | if (!timeout) { |
| 1056 | /* Release semaphores */ |
| 1057 | e1000_put_hw_eeprom_semaphore(hw); |
| 1058 | DEBUGOUT("Driver can't access the Eeprom - " |
| 1059 | "SWESMBI bit is set.\n"); |
| 1060 | return -E1000_ERR_EEPROM; |
| 1061 | } |
| 1062 | |
| 1063 | return E1000_SUCCESS; |
| 1064 | } |
| 1065 | |
| 1066 | static int32_t |
| 1067 | e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask) |
| 1068 | { |
| 1069 | uint32_t swfw_sync = 0; |
| 1070 | uint32_t swmask = mask; |
| 1071 | uint32_t fwmask = mask << 16; |
| 1072 | int32_t timeout = 200; |
| 1073 | |
| 1074 | DEBUGFUNC(); |
| 1075 | while (timeout) { |
| 1076 | if (e1000_get_hw_eeprom_semaphore(hw)) |
| 1077 | return -E1000_ERR_SWFW_SYNC; |
| 1078 | |
| 1079 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
| 1080 | if (!(swfw_sync & (fwmask | swmask))) |
| 1081 | break; |
| 1082 | |
| 1083 | /* firmware currently using resource (fwmask) */ |
| 1084 | /* or other software thread currently using resource (swmask) */ |
| 1085 | e1000_put_hw_eeprom_semaphore(hw); |
| 1086 | mdelay(5); |
| 1087 | timeout--; |
| 1088 | } |
| 1089 | |
| 1090 | if (!timeout) { |
| 1091 | DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n"); |
| 1092 | return -E1000_ERR_SWFW_SYNC; |
| 1093 | } |
| 1094 | |
| 1095 | swfw_sync |= swmask; |
| 1096 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 1097 | |
| 1098 | e1000_put_hw_eeprom_semaphore(hw); |
| 1099 | return E1000_SUCCESS; |
| 1100 | } |
| 1101 | |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1102 | static boolean_t e1000_is_second_port(struct e1000_hw *hw) |
| 1103 | { |
| 1104 | switch (hw->mac_type) { |
| 1105 | case e1000_80003es2lan: |
| 1106 | case e1000_82546: |
| 1107 | case e1000_82571: |
| 1108 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) |
| 1109 | return TRUE; |
| 1110 | /* Fallthrough */ |
| 1111 | default: |
| 1112 | return FALSE; |
| 1113 | } |
| 1114 | } |
| 1115 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1116 | /****************************************************************************** |
| 1117 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 1118 | * second function of dual function devices |
| 1119 | * |
| 1120 | * nic - Struct containing variables accessed by shared code |
| 1121 | *****************************************************************************/ |
| 1122 | static int |
| 1123 | e1000_read_mac_addr(struct eth_device *nic) |
| 1124 | { |
| 1125 | #ifndef CONFIG_AP1000 |
| 1126 | struct e1000_hw *hw = nic->priv; |
| 1127 | uint16_t offset; |
| 1128 | uint16_t eeprom_data; |
| 1129 | int i; |
| 1130 | |
| 1131 | DEBUGFUNC(); |
| 1132 | |
| 1133 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1134 | offset = i >> 1; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1135 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1136 | DEBUGOUT("EEPROM Read Error\n"); |
| 1137 | return -E1000_ERR_EEPROM; |
| 1138 | } |
| 1139 | nic->enetaddr[i] = eeprom_data & 0xff; |
| 1140 | nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff; |
| 1141 | } |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1142 | |
| 1143 | /* Invert the last bit if this is the second device */ |
| 1144 | if (e1000_is_second_port(hw)) |
| 1145 | nic->enetaddr[5] ^= 1; |
| 1146 | |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 1147 | #ifdef CONFIG_E1000_FALLBACK_MAC |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 1148 | if ( *(u32*)(nic->enetaddr) == 0 || *(u32*)(nic->enetaddr) == ~0 ) { |
| 1149 | unsigned char fb_mac[NODE_ADDRESS_SIZE] = CONFIG_E1000_FALLBACK_MAC; |
| 1150 | |
| 1151 | memcpy (nic->enetaddr, fb_mac, NODE_ADDRESS_SIZE); |
| 1152 | } |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 1153 | #endif |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 1154 | #else |
| 1155 | /* |
| 1156 | * The AP1000's e1000 has no eeprom; the MAC address is stored in the |
| 1157 | * environment variables. Currently this does not support the addition |
| 1158 | * of a PMC e1000 card, which is certainly a possibility, so this should |
| 1159 | * be updated to properly use the env variable only for the onboard e1000 |
| 1160 | */ |
| 1161 | |
| 1162 | int ii; |
| 1163 | char *s, *e; |
| 1164 | |
| 1165 | DEBUGFUNC(); |
| 1166 | |
| 1167 | s = getenv ("ethaddr"); |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 1168 | if (s == NULL) { |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 1169 | return -E1000_ERR_EEPROM; |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 1170 | } else { |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 1171 | for(ii = 0; ii < 6; ii++) { |
| 1172 | nic->enetaddr[ii] = s ? simple_strtoul (s, &e, 16) : 0; |
| 1173 | if (s){ |
| 1174 | s = (*e) ? e + 1 : e; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | /****************************************************************************** |
| 1183 | * Initializes receive address filters. |
| 1184 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1185 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1186 | * |
| 1187 | * Places the MAC address in receive address register 0 and clears the rest |
| 1188 | * of the receive addresss registers. Clears the multicast table. Assumes |
| 1189 | * the receiver is in reset when the routine is called. |
| 1190 | *****************************************************************************/ |
| 1191 | static void |
| 1192 | e1000_init_rx_addrs(struct eth_device *nic) |
| 1193 | { |
| 1194 | struct e1000_hw *hw = nic->priv; |
| 1195 | uint32_t i; |
| 1196 | uint32_t addr_low; |
| 1197 | uint32_t addr_high; |
| 1198 | |
| 1199 | DEBUGFUNC(); |
| 1200 | |
| 1201 | /* Setup the receive address. */ |
| 1202 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); |
| 1203 | addr_low = (nic->enetaddr[0] | |
| 1204 | (nic->enetaddr[1] << 8) | |
| 1205 | (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24)); |
| 1206 | |
| 1207 | addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV); |
| 1208 | |
| 1209 | E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low); |
| 1210 | E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high); |
| 1211 | |
| 1212 | /* Zero out the other 15 receive addresses. */ |
| 1213 | DEBUGOUT("Clearing RAR[1-15]\n"); |
| 1214 | for (i = 1; i < E1000_RAR_ENTRIES; i++) { |
| 1215 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
| 1216 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | /****************************************************************************** |
| 1221 | * Clears the VLAN filer table |
| 1222 | * |
| 1223 | * hw - Struct containing variables accessed by shared code |
| 1224 | *****************************************************************************/ |
| 1225 | static void |
| 1226 | e1000_clear_vfta(struct e1000_hw *hw) |
| 1227 | { |
| 1228 | uint32_t offset; |
| 1229 | |
| 1230 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) |
| 1231 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0); |
| 1232 | } |
| 1233 | |
| 1234 | /****************************************************************************** |
| 1235 | * Set the mac type member in the hw struct. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1236 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1237 | * hw - Struct containing variables accessed by shared code |
| 1238 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1239 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1240 | e1000_set_mac_type(struct e1000_hw *hw) |
| 1241 | { |
| 1242 | DEBUGFUNC(); |
| 1243 | |
| 1244 | switch (hw->device_id) { |
| 1245 | case E1000_DEV_ID_82542: |
| 1246 | switch (hw->revision_id) { |
| 1247 | case E1000_82542_2_0_REV_ID: |
| 1248 | hw->mac_type = e1000_82542_rev2_0; |
| 1249 | break; |
| 1250 | case E1000_82542_2_1_REV_ID: |
| 1251 | hw->mac_type = e1000_82542_rev2_1; |
| 1252 | break; |
| 1253 | default: |
| 1254 | /* Invalid 82542 revision ID */ |
| 1255 | return -E1000_ERR_MAC_TYPE; |
| 1256 | } |
| 1257 | break; |
| 1258 | case E1000_DEV_ID_82543GC_FIBER: |
| 1259 | case E1000_DEV_ID_82543GC_COPPER: |
| 1260 | hw->mac_type = e1000_82543; |
| 1261 | break; |
| 1262 | case E1000_DEV_ID_82544EI_COPPER: |
| 1263 | case E1000_DEV_ID_82544EI_FIBER: |
| 1264 | case E1000_DEV_ID_82544GC_COPPER: |
| 1265 | case E1000_DEV_ID_82544GC_LOM: |
| 1266 | hw->mac_type = e1000_82544; |
| 1267 | break; |
| 1268 | case E1000_DEV_ID_82540EM: |
| 1269 | case E1000_DEV_ID_82540EM_LOM: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1270 | case E1000_DEV_ID_82540EP: |
| 1271 | case E1000_DEV_ID_82540EP_LOM: |
| 1272 | case E1000_DEV_ID_82540EP_LP: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1273 | hw->mac_type = e1000_82540; |
| 1274 | break; |
| 1275 | case E1000_DEV_ID_82545EM_COPPER: |
| 1276 | case E1000_DEV_ID_82545EM_FIBER: |
| 1277 | hw->mac_type = e1000_82545; |
| 1278 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1279 | case E1000_DEV_ID_82545GM_COPPER: |
| 1280 | case E1000_DEV_ID_82545GM_FIBER: |
| 1281 | case E1000_DEV_ID_82545GM_SERDES: |
| 1282 | hw->mac_type = e1000_82545_rev_3; |
| 1283 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1284 | case E1000_DEV_ID_82546EB_COPPER: |
| 1285 | case E1000_DEV_ID_82546EB_FIBER: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1286 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1287 | hw->mac_type = e1000_82546; |
| 1288 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1289 | case E1000_DEV_ID_82546GB_COPPER: |
| 1290 | case E1000_DEV_ID_82546GB_FIBER: |
| 1291 | case E1000_DEV_ID_82546GB_SERDES: |
| 1292 | case E1000_DEV_ID_82546GB_PCIE: |
| 1293 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 1294 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1295 | hw->mac_type = e1000_82546_rev_3; |
| 1296 | break; |
| 1297 | case E1000_DEV_ID_82541EI: |
| 1298 | case E1000_DEV_ID_82541EI_MOBILE: |
| 1299 | case E1000_DEV_ID_82541ER_LOM: |
| 1300 | hw->mac_type = e1000_82541; |
| 1301 | break; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 1302 | case E1000_DEV_ID_82541ER: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1303 | case E1000_DEV_ID_82541GI: |
Wolfgang Grandegger | 8562c38 | 2008-05-28 19:55:19 +0200 | [diff] [blame] | 1304 | case E1000_DEV_ID_82541GI_LF: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1305 | case E1000_DEV_ID_82541GI_MOBILE: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 1306 | hw->mac_type = e1000_82541_rev_2; |
| 1307 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1308 | case E1000_DEV_ID_82547EI: |
| 1309 | case E1000_DEV_ID_82547EI_MOBILE: |
| 1310 | hw->mac_type = e1000_82547; |
| 1311 | break; |
| 1312 | case E1000_DEV_ID_82547GI: |
| 1313 | hw->mac_type = e1000_82547_rev_2; |
| 1314 | break; |
| 1315 | case E1000_DEV_ID_82571EB_COPPER: |
| 1316 | case E1000_DEV_ID_82571EB_FIBER: |
| 1317 | case E1000_DEV_ID_82571EB_SERDES: |
| 1318 | case E1000_DEV_ID_82571EB_SERDES_DUAL: |
| 1319 | case E1000_DEV_ID_82571EB_SERDES_QUAD: |
| 1320 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
| 1321 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
| 1322 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
| 1323 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
| 1324 | hw->mac_type = e1000_82571; |
| 1325 | break; |
| 1326 | case E1000_DEV_ID_82572EI_COPPER: |
| 1327 | case E1000_DEV_ID_82572EI_FIBER: |
| 1328 | case E1000_DEV_ID_82572EI_SERDES: |
| 1329 | case E1000_DEV_ID_82572EI: |
| 1330 | hw->mac_type = e1000_82572; |
| 1331 | break; |
| 1332 | case E1000_DEV_ID_82573E: |
| 1333 | case E1000_DEV_ID_82573E_IAMT: |
| 1334 | case E1000_DEV_ID_82573L: |
| 1335 | hw->mac_type = e1000_82573; |
| 1336 | break; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 1337 | case E1000_DEV_ID_82574L: |
| 1338 | hw->mac_type = e1000_82574; |
| 1339 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1340 | case E1000_DEV_ID_80003ES2LAN_COPPER_SPT: |
| 1341 | case E1000_DEV_ID_80003ES2LAN_SERDES_SPT: |
| 1342 | case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: |
| 1343 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
| 1344 | hw->mac_type = e1000_80003es2lan; |
| 1345 | break; |
| 1346 | case E1000_DEV_ID_ICH8_IGP_M_AMT: |
| 1347 | case E1000_DEV_ID_ICH8_IGP_AMT: |
| 1348 | case E1000_DEV_ID_ICH8_IGP_C: |
| 1349 | case E1000_DEV_ID_ICH8_IFE: |
| 1350 | case E1000_DEV_ID_ICH8_IFE_GT: |
| 1351 | case E1000_DEV_ID_ICH8_IFE_G: |
| 1352 | case E1000_DEV_ID_ICH8_IGP_M: |
| 1353 | hw->mac_type = e1000_ich8lan; |
| 1354 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1355 | default: |
| 1356 | /* Should never have loaded on this device */ |
| 1357 | return -E1000_ERR_MAC_TYPE; |
| 1358 | } |
| 1359 | return E1000_SUCCESS; |
| 1360 | } |
| 1361 | |
| 1362 | /****************************************************************************** |
| 1363 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 1364 | * |
| 1365 | * hw - Struct containing variables accessed by shared code |
| 1366 | *****************************************************************************/ |
| 1367 | void |
| 1368 | e1000_reset_hw(struct e1000_hw *hw) |
| 1369 | { |
| 1370 | uint32_t ctrl; |
| 1371 | uint32_t ctrl_ext; |
| 1372 | uint32_t icr; |
| 1373 | uint32_t manc; |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 1374 | uint32_t pba = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1375 | |
| 1376 | DEBUGFUNC(); |
| 1377 | |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 1378 | /* get the correct pba value for both PCI and PCIe*/ |
| 1379 | if (hw->mac_type < e1000_82571) |
| 1380 | pba = E1000_DEFAULT_PCI_PBA; |
| 1381 | else |
| 1382 | pba = E1000_DEFAULT_PCIE_PBA; |
| 1383 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1384 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
| 1385 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1386 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 1387 | pci_write_config_word(hw->pdev, PCI_COMMAND, |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1388 | hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 1392 | DEBUGOUT("Masking off all interrupts\n"); |
| 1393 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 1394 | |
| 1395 | /* Disable the Transmit and Receive units. Then delay to allow |
| 1396 | * any pending transactions to complete before we hit the MAC with |
| 1397 | * the global reset. |
| 1398 | */ |
| 1399 | E1000_WRITE_REG(hw, RCTL, 0); |
| 1400 | E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP); |
| 1401 | E1000_WRITE_FLUSH(hw); |
| 1402 | |
| 1403 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
| 1404 | hw->tbi_compatibility_on = FALSE; |
| 1405 | |
| 1406 | /* Delay to allow any outstanding PCI transactions to complete before |
| 1407 | * resetting the device |
| 1408 | */ |
| 1409 | mdelay(10); |
| 1410 | |
| 1411 | /* Issue a global reset to the MAC. This will reset the chip's |
| 1412 | * transmit, receive, DMA, and link units. It will not effect |
| 1413 | * the current PCI configuration. The global reset bit is self- |
| 1414 | * clearing, and should clear within a microsecond. |
| 1415 | */ |
| 1416 | DEBUGOUT("Issuing a global reset to MAC\n"); |
| 1417 | ctrl = E1000_READ_REG(hw, CTRL); |
| 1418 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1419 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1420 | |
| 1421 | /* Force a reload from the EEPROM if necessary */ |
| 1422 | if (hw->mac_type < e1000_82540) { |
| 1423 | /* Wait for reset to complete */ |
| 1424 | udelay(10); |
| 1425 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1426 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 1427 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1428 | E1000_WRITE_FLUSH(hw); |
| 1429 | /* Wait for EEPROM reload */ |
| 1430 | mdelay(2); |
| 1431 | } else { |
| 1432 | /* Wait for EEPROM reload (it happens automatically) */ |
| 1433 | mdelay(4); |
| 1434 | /* Dissable HW ARPs on ASF enabled adapters */ |
| 1435 | manc = E1000_READ_REG(hw, MANC); |
| 1436 | manc &= ~(E1000_MANC_ARP_EN); |
| 1437 | E1000_WRITE_REG(hw, MANC, manc); |
| 1438 | } |
| 1439 | |
| 1440 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 1441 | DEBUGOUT("Masking off all interrupts\n"); |
| 1442 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 1443 | |
| 1444 | /* Clear any pending interrupt events. */ |
| 1445 | icr = E1000_READ_REG(hw, ICR); |
| 1446 | |
| 1447 | /* If MWI was previously enabled, reenable it. */ |
| 1448 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1449 | pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word); |
| 1450 | } |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 1451 | E1000_WRITE_REG(hw, PBA, pba); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | /****************************************************************************** |
| 1455 | * |
| 1456 | * Initialize a number of hardware-dependent bits |
| 1457 | * |
| 1458 | * hw: Struct containing variables accessed by shared code |
| 1459 | * |
| 1460 | * This function contains hardware limitation workarounds for PCI-E adapters |
| 1461 | * |
| 1462 | *****************************************************************************/ |
| 1463 | static void |
| 1464 | e1000_initialize_hardware_bits(struct e1000_hw *hw) |
| 1465 | { |
| 1466 | if ((hw->mac_type >= e1000_82571) && |
| 1467 | (!hw->initialize_hw_bits_disable)) { |
| 1468 | /* Settings common to all PCI-express silicon */ |
| 1469 | uint32_t reg_ctrl, reg_ctrl_ext; |
| 1470 | uint32_t reg_tarc0, reg_tarc1; |
| 1471 | uint32_t reg_tctl; |
| 1472 | uint32_t reg_txdctl, reg_txdctl1; |
| 1473 | |
| 1474 | /* link autonegotiation/sync workarounds */ |
| 1475 | reg_tarc0 = E1000_READ_REG(hw, TARC0); |
| 1476 | reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 1477 | |
| 1478 | /* Enable not-done TX descriptor counting */ |
| 1479 | reg_txdctl = E1000_READ_REG(hw, TXDCTL); |
| 1480 | reg_txdctl |= E1000_TXDCTL_COUNT_DESC; |
| 1481 | E1000_WRITE_REG(hw, TXDCTL, reg_txdctl); |
| 1482 | |
| 1483 | reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1); |
| 1484 | reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC; |
| 1485 | E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1); |
| 1486 | |
| 1487 | switch (hw->mac_type) { |
| 1488 | case e1000_82571: |
| 1489 | case e1000_82572: |
| 1490 | /* Clear PHY TX compatible mode bits */ |
| 1491 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 1492 | reg_tarc1 &= ~((1 << 30)|(1 << 29)); |
| 1493 | |
| 1494 | /* link autonegotiation/sync workarounds */ |
| 1495 | reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23)); |
| 1496 | |
| 1497 | /* TX ring control fixes */ |
| 1498 | reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24)); |
| 1499 | |
| 1500 | /* Multiple read bit is reversed polarity */ |
| 1501 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 1502 | if (reg_tctl & E1000_TCTL_MULR) |
| 1503 | reg_tarc1 &= ~(1 << 28); |
| 1504 | else |
| 1505 | reg_tarc1 |= (1 << 28); |
| 1506 | |
| 1507 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 1508 | break; |
| 1509 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 1510 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1511 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1512 | reg_ctrl_ext &= ~(1 << 23); |
| 1513 | reg_ctrl_ext |= (1 << 22); |
| 1514 | |
| 1515 | /* TX byte count fix */ |
| 1516 | reg_ctrl = E1000_READ_REG(hw, CTRL); |
| 1517 | reg_ctrl &= ~(1 << 29); |
| 1518 | |
| 1519 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 1520 | E1000_WRITE_REG(hw, CTRL, reg_ctrl); |
| 1521 | break; |
| 1522 | case e1000_80003es2lan: |
| 1523 | /* improve small packet performace for fiber/serdes */ |
| 1524 | if ((hw->media_type == e1000_media_type_fiber) |
| 1525 | || (hw->media_type == |
| 1526 | e1000_media_type_internal_serdes)) { |
| 1527 | reg_tarc0 &= ~(1 << 20); |
| 1528 | } |
| 1529 | |
| 1530 | /* Multiple read bit is reversed polarity */ |
| 1531 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 1532 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 1533 | if (reg_tctl & E1000_TCTL_MULR) |
| 1534 | reg_tarc1 &= ~(1 << 28); |
| 1535 | else |
| 1536 | reg_tarc1 |= (1 << 28); |
| 1537 | |
| 1538 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 1539 | break; |
| 1540 | case e1000_ich8lan: |
| 1541 | /* Reduce concurrent DMA requests to 3 from 4 */ |
| 1542 | if ((hw->revision_id < 3) || |
| 1543 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 1544 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M))) |
| 1545 | reg_tarc0 |= ((1 << 29)|(1 << 28)); |
| 1546 | |
| 1547 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1548 | reg_ctrl_ext |= (1 << 22); |
| 1549 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 1550 | |
| 1551 | /* workaround TX hang with TSO=on */ |
| 1552 | reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23)); |
| 1553 | |
| 1554 | /* Multiple read bit is reversed polarity */ |
| 1555 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 1556 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 1557 | if (reg_tctl & E1000_TCTL_MULR) |
| 1558 | reg_tarc1 &= ~(1 << 28); |
| 1559 | else |
| 1560 | reg_tarc1 |= (1 << 28); |
| 1561 | |
| 1562 | /* workaround TX hang with TSO=on */ |
| 1563 | reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24)); |
| 1564 | |
| 1565 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 1566 | break; |
| 1567 | default: |
| 1568 | break; |
| 1569 | } |
| 1570 | |
| 1571 | E1000_WRITE_REG(hw, TARC0, reg_tarc0); |
| 1572 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | /****************************************************************************** |
| 1576 | * Performs basic configuration of the adapter. |
| 1577 | * |
| 1578 | * hw - Struct containing variables accessed by shared code |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1579 | * |
| 1580 | * Assumes that the controller has previously been reset and is in a |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1581 | * post-reset uninitialized state. Initializes the receive address registers, |
| 1582 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 1583 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 1584 | * the transmit and receive units disabled and uninitialized. |
| 1585 | *****************************************************************************/ |
| 1586 | static int |
| 1587 | e1000_init_hw(struct eth_device *nic) |
| 1588 | { |
| 1589 | struct e1000_hw *hw = nic->priv; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1590 | uint32_t ctrl; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1591 | uint32_t i; |
| 1592 | int32_t ret_val; |
| 1593 | uint16_t pcix_cmd_word; |
| 1594 | uint16_t pcix_stat_hi_word; |
| 1595 | uint16_t cmd_mmrbc; |
| 1596 | uint16_t stat_mmrbc; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1597 | uint32_t mta_size; |
| 1598 | uint32_t reg_data; |
| 1599 | uint32_t ctrl_ext; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1600 | DEBUGFUNC(); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1601 | /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */ |
| 1602 | if ((hw->mac_type == e1000_ich8lan) && |
| 1603 | ((hw->revision_id < 3) || |
| 1604 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 1605 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) { |
| 1606 | reg_data = E1000_READ_REG(hw, STATUS); |
| 1607 | reg_data &= ~0x80000000; |
| 1608 | E1000_WRITE_REG(hw, STATUS, reg_data); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1609 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1610 | /* Do not need initialize Identification LED */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1611 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1612 | /* Set the media type and TBI compatibility */ |
| 1613 | e1000_set_media_type(hw); |
| 1614 | |
| 1615 | /* Must be called after e1000_set_media_type |
| 1616 | * because media_type is used */ |
| 1617 | e1000_initialize_hardware_bits(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1618 | |
| 1619 | /* Disabling VLAN filtering. */ |
| 1620 | DEBUGOUT("Initializing the IEEE VLAN\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1621 | /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */ |
| 1622 | if (hw->mac_type != e1000_ich8lan) { |
| 1623 | if (hw->mac_type < e1000_82545_rev_3) |
| 1624 | E1000_WRITE_REG(hw, VET, 0); |
| 1625 | e1000_clear_vfta(hw); |
| 1626 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1627 | |
| 1628 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ |
| 1629 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1630 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 1631 | pci_write_config_word(hw->pdev, PCI_COMMAND, |
| 1632 | hw-> |
| 1633 | pci_cmd_word & ~PCI_COMMAND_INVALIDATE); |
| 1634 | E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST); |
| 1635 | E1000_WRITE_FLUSH(hw); |
| 1636 | mdelay(5); |
| 1637 | } |
| 1638 | |
| 1639 | /* Setup the receive address. This involves initializing all of the Receive |
| 1640 | * Address Registers (RARs 0 - 15). |
| 1641 | */ |
| 1642 | e1000_init_rx_addrs(nic); |
| 1643 | |
| 1644 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ |
| 1645 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1646 | E1000_WRITE_REG(hw, RCTL, 0); |
| 1647 | E1000_WRITE_FLUSH(hw); |
| 1648 | mdelay(1); |
| 1649 | pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word); |
| 1650 | } |
| 1651 | |
| 1652 | /* Zero out the Multicast HASH table */ |
| 1653 | DEBUGOUT("Zeroing the MTA\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1654 | mta_size = E1000_MC_TBL_SIZE; |
| 1655 | if (hw->mac_type == e1000_ich8lan) |
| 1656 | mta_size = E1000_MC_TBL_SIZE_ICH8LAN; |
| 1657 | for (i = 0; i < mta_size; i++) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1658 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1659 | /* use write flush to prevent Memory Write Block (MWB) from |
| 1660 | * occuring when accessing our register space */ |
| 1661 | E1000_WRITE_FLUSH(hw); |
| 1662 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1663 | #if 0 |
| 1664 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 1665 | * determines if the adapter gives priority to receives, or if it |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1666 | * gives equal priority to transmits and receives. Valid only on |
| 1667 | * 82542 and 82543 silicon. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1668 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1669 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1670 | ctrl = E1000_READ_REG(hw, CTRL); |
| 1671 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR); |
| 1672 | } |
| 1673 | #endif |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1674 | switch (hw->mac_type) { |
| 1675 | case e1000_82545_rev_3: |
| 1676 | case e1000_82546_rev_3: |
| 1677 | break; |
| 1678 | default: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1679 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1680 | if (hw->bus_type == e1000_bus_type_pcix) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1681 | pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER, |
| 1682 | &pcix_cmd_word); |
| 1683 | pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI, |
| 1684 | &pcix_stat_hi_word); |
| 1685 | cmd_mmrbc = |
| 1686 | (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >> |
| 1687 | PCIX_COMMAND_MMRBC_SHIFT; |
| 1688 | stat_mmrbc = |
| 1689 | (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >> |
| 1690 | PCIX_STATUS_HI_MMRBC_SHIFT; |
| 1691 | if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K) |
| 1692 | stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K; |
| 1693 | if (cmd_mmrbc > stat_mmrbc) { |
| 1694 | pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK; |
| 1695 | pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT; |
| 1696 | pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER, |
| 1697 | pcix_cmd_word); |
| 1698 | } |
| 1699 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1700 | break; |
| 1701 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1702 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1703 | /* More time needed for PHY to initialize */ |
| 1704 | if (hw->mac_type == e1000_ich8lan) |
| 1705 | mdelay(15); |
| 1706 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1707 | /* Call a subroutine to configure the link and setup flow control. */ |
| 1708 | ret_val = e1000_setup_link(nic); |
| 1709 | |
| 1710 | /* Set the transmit descriptor write-back policy */ |
| 1711 | if (hw->mac_type > e1000_82544) { |
| 1712 | ctrl = E1000_READ_REG(hw, TXDCTL); |
| 1713 | ctrl = |
| 1714 | (ctrl & ~E1000_TXDCTL_WTHRESH) | |
| 1715 | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 1716 | E1000_WRITE_REG(hw, TXDCTL, ctrl); |
| 1717 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1718 | |
| 1719 | switch (hw->mac_type) { |
| 1720 | default: |
| 1721 | break; |
| 1722 | case e1000_80003es2lan: |
| 1723 | /* Enable retransmit on late collisions */ |
| 1724 | reg_data = E1000_READ_REG(hw, TCTL); |
| 1725 | reg_data |= E1000_TCTL_RTLC; |
| 1726 | E1000_WRITE_REG(hw, TCTL, reg_data); |
| 1727 | |
| 1728 | /* Configure Gigabit Carry Extend Padding */ |
| 1729 | reg_data = E1000_READ_REG(hw, TCTL_EXT); |
| 1730 | reg_data &= ~E1000_TCTL_EXT_GCEX_MASK; |
| 1731 | reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX; |
| 1732 | E1000_WRITE_REG(hw, TCTL_EXT, reg_data); |
| 1733 | |
| 1734 | /* Configure Transmit Inter-Packet Gap */ |
| 1735 | reg_data = E1000_READ_REG(hw, TIPG); |
| 1736 | reg_data &= ~E1000_TIPG_IPGT_MASK; |
| 1737 | reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 1738 | E1000_WRITE_REG(hw, TIPG, reg_data); |
| 1739 | |
| 1740 | reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001); |
| 1741 | reg_data &= ~0x00100000; |
| 1742 | E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data); |
| 1743 | /* Fall through */ |
| 1744 | case e1000_82571: |
| 1745 | case e1000_82572: |
| 1746 | case e1000_ich8lan: |
| 1747 | ctrl = E1000_READ_REG(hw, TXDCTL1); |
| 1748 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) |
| 1749 | | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 1750 | E1000_WRITE_REG(hw, TXDCTL1, ctrl); |
| 1751 | break; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 1752 | case e1000_82573: |
| 1753 | case e1000_82574: |
| 1754 | reg_data = E1000_READ_REG(hw, GCR); |
| 1755 | reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX; |
| 1756 | E1000_WRITE_REG(hw, GCR, reg_data); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1757 | } |
| 1758 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1759 | #if 0 |
| 1760 | /* Clear all of the statistics registers (clear on read). It is |
| 1761 | * important that we do this after we have tried to establish link |
| 1762 | * because the symbol error count will increment wildly if there |
| 1763 | * is no link. |
| 1764 | */ |
| 1765 | e1000_clear_hw_cntrs(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1766 | |
| 1767 | /* ICH8 No-snoop bits are opposite polarity. |
| 1768 | * Set to snoop by default after reset. */ |
| 1769 | if (hw->mac_type == e1000_ich8lan) |
| 1770 | e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1771 | #endif |
| 1772 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1773 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 1774 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
| 1775 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1776 | /* Relaxed ordering must be disabled to avoid a parity |
| 1777 | * error crash in a PCI slot. */ |
| 1778 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 1779 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1780 | } |
| 1781 | |
| 1782 | return ret_val; |
| 1783 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1784 | |
| 1785 | /****************************************************************************** |
| 1786 | * Configures flow control and link settings. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1787 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1788 | * hw - Struct containing variables accessed by shared code |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1789 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1790 | * Determines which flow control settings to use. Calls the apropriate media- |
| 1791 | * specific link configuration function. Configures the flow control settings. |
| 1792 | * Assuming the adapter has a valid link partner, a valid link should be |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1793 | * established. Assumes the hardware has previously been reset and the |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1794 | * transmitter and receiver are not enabled. |
| 1795 | *****************************************************************************/ |
| 1796 | static int |
| 1797 | e1000_setup_link(struct eth_device *nic) |
| 1798 | { |
| 1799 | struct e1000_hw *hw = nic->priv; |
| 1800 | uint32_t ctrl_ext; |
| 1801 | int32_t ret_val; |
| 1802 | uint16_t eeprom_data; |
| 1803 | |
| 1804 | DEBUGFUNC(); |
| 1805 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1806 | /* In the case of the phy reset being blocked, we already have a link. |
| 1807 | * We do not have to set it up again. */ |
| 1808 | if (e1000_check_phy_reset_block(hw)) |
| 1809 | return E1000_SUCCESS; |
| 1810 | |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 1811 | #ifndef CONFIG_AP1000 |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1812 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 1813 | * that determine the hardware's default PAUSE (flow control) mode, |
| 1814 | * a bit that determines whether the HW defaults to enabling or |
| 1815 | * disabling auto-negotiation, and the direction of the |
| 1816 | * SW defined pins. If there is no SW over-ride of the flow |
| 1817 | * control setting, then the variable hw->fc will |
| 1818 | * be initialized based on a value in the EEPROM. |
| 1819 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1820 | if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, |
| 1821 | &eeprom_data) < 0) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1822 | DEBUGOUT("EEPROM Read Error\n"); |
| 1823 | return -E1000_ERR_EEPROM; |
| 1824 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 1825 | #else |
| 1826 | /* we have to hardcode the proper value for our hardware. */ |
| 1827 | /* this value is for the 82540EM pci card used for prototyping, and it works. */ |
| 1828 | eeprom_data = 0xb220; |
| 1829 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1830 | |
| 1831 | if (hw->fc == e1000_fc_default) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1832 | switch (hw->mac_type) { |
| 1833 | case e1000_ich8lan: |
| 1834 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 1835 | case e1000_82574: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1836 | hw->fc = e1000_fc_full; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1837 | break; |
| 1838 | default: |
| 1839 | #ifndef CONFIG_AP1000 |
| 1840 | ret_val = e1000_read_eeprom(hw, |
| 1841 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1842 | if (ret_val) { |
| 1843 | DEBUGOUT("EEPROM Read Error\n"); |
| 1844 | return -E1000_ERR_EEPROM; |
| 1845 | } |
| 1846 | #else |
| 1847 | eeprom_data = 0xb220; |
| 1848 | #endif |
| 1849 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
| 1850 | hw->fc = e1000_fc_none; |
| 1851 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 1852 | EEPROM_WORD0F_ASM_DIR) |
| 1853 | hw->fc = e1000_fc_tx_pause; |
| 1854 | else |
| 1855 | hw->fc = e1000_fc_full; |
| 1856 | break; |
| 1857 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | /* We want to save off the original Flow Control configuration just |
| 1861 | * in case we get disconnected and then reconnected into a different |
| 1862 | * hub or switch with different Flow Control capabilities. |
| 1863 | */ |
| 1864 | if (hw->mac_type == e1000_82542_rev2_0) |
| 1865 | hw->fc &= (~e1000_fc_tx_pause); |
| 1866 | |
| 1867 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
| 1868 | hw->fc &= (~e1000_fc_rx_pause); |
| 1869 | |
| 1870 | hw->original_fc = hw->fc; |
| 1871 | |
| 1872 | DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc); |
| 1873 | |
| 1874 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 1875 | * polarity value for the SW controlled pins, and setup the |
| 1876 | * Extended Device Control reg with that info. |
| 1877 | * This is needed because one of the SW controlled pins is used for |
| 1878 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 1879 | * or e1000_phy_setup() is called. |
| 1880 | */ |
| 1881 | if (hw->mac_type == e1000_82543) { |
| 1882 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 1883 | SWDPIO__EXT_SHIFT); |
| 1884 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1885 | } |
| 1886 | |
| 1887 | /* Call the necessary subroutine to configure the link. */ |
| 1888 | ret_val = (hw->media_type == e1000_media_type_fiber) ? |
| 1889 | e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic); |
| 1890 | if (ret_val < 0) { |
| 1891 | return ret_val; |
| 1892 | } |
| 1893 | |
| 1894 | /* Initialize the flow control address, type, and PAUSE timer |
| 1895 | * registers to their default values. This is done even if flow |
| 1896 | * control is disabled, because it does not hurt anything to |
| 1897 | * initialize these registers. |
| 1898 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1899 | DEBUGOUT("Initializing the Flow Control address, type" |
| 1900 | "and timer regs\n"); |
| 1901 | |
| 1902 | /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */ |
| 1903 | if (hw->mac_type != e1000_ich8lan) { |
| 1904 | E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE); |
| 1905 | E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 1906 | E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW); |
| 1907 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1908 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1909 | E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time); |
| 1910 | |
| 1911 | /* Set the flow control receive threshold registers. Normally, |
| 1912 | * these registers will be set to a default threshold that may be |
| 1913 | * adjusted later by the driver's runtime code. However, if the |
| 1914 | * ability to transmit pause frames in not enabled, then these |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1915 | * registers will be set to 0. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1916 | */ |
| 1917 | if (!(hw->fc & e1000_fc_tx_pause)) { |
| 1918 | E1000_WRITE_REG(hw, FCRTL, 0); |
| 1919 | E1000_WRITE_REG(hw, FCRTH, 0); |
| 1920 | } else { |
| 1921 | /* We need to set up the Receive Threshold high and low water marks |
| 1922 | * as well as (optionally) enabling the transmission of XON frames. |
| 1923 | */ |
| 1924 | if (hw->fc_send_xon) { |
| 1925 | E1000_WRITE_REG(hw, FCRTL, |
| 1926 | (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 1927 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 1928 | } else { |
| 1929 | E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water); |
| 1930 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 1931 | } |
| 1932 | } |
| 1933 | return ret_val; |
| 1934 | } |
| 1935 | |
| 1936 | /****************************************************************************** |
| 1937 | * Sets up link for a fiber based adapter |
| 1938 | * |
| 1939 | * hw - Struct containing variables accessed by shared code |
| 1940 | * |
| 1941 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 1942 | * link. Assumes the hardware has been previously reset and the transmitter |
| 1943 | * and receiver are not enabled. |
| 1944 | *****************************************************************************/ |
| 1945 | static int |
| 1946 | e1000_setup_fiber_link(struct eth_device *nic) |
| 1947 | { |
| 1948 | struct e1000_hw *hw = nic->priv; |
| 1949 | uint32_t ctrl; |
| 1950 | uint32_t status; |
| 1951 | uint32_t txcw = 0; |
| 1952 | uint32_t i; |
| 1953 | uint32_t signal; |
| 1954 | int32_t ret_val; |
| 1955 | |
| 1956 | DEBUGFUNC(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1957 | /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be |
| 1958 | * set when the optics detect a signal. On older adapters, it will be |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1959 | * cleared when there is a signal |
| 1960 | */ |
| 1961 | ctrl = E1000_READ_REG(hw, CTRL); |
| 1962 | if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS)) |
| 1963 | signal = E1000_CTRL_SWDPIN1; |
| 1964 | else |
| 1965 | signal = 0; |
| 1966 | |
| 1967 | printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal, |
| 1968 | ctrl); |
| 1969 | /* Take the link out of reset */ |
| 1970 | ctrl &= ~(E1000_CTRL_LRST); |
| 1971 | |
| 1972 | e1000_config_collision_dist(hw); |
| 1973 | |
| 1974 | /* Check for a software override of the flow control settings, and setup |
| 1975 | * the device accordingly. If auto-negotiation is enabled, then software |
| 1976 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 1977 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1978 | * auto-negotiation is disabled, then software will have to manually |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1979 | * configure the two flow control enable bits in the CTRL register. |
| 1980 | * |
| 1981 | * The possible values of the "fc" parameter are: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 1982 | * 0: Flow control is completely disabled |
| 1983 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 1984 | * not send pause frames). |
| 1985 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 1986 | * not support receiving pause frames). |
| 1987 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1988 | */ |
| 1989 | switch (hw->fc) { |
| 1990 | case e1000_fc_none: |
| 1991 | /* Flow control is completely disabled by a software over-ride. */ |
| 1992 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 1993 | break; |
| 1994 | case e1000_fc_rx_pause: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1995 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 1996 | * software over-ride. Since there really isn't a way to advertise |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1997 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 1998 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 1999 | * disable the adapter's ability to send PAUSE frames. |
| 2000 | */ |
| 2001 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 2002 | break; |
| 2003 | case e1000_fc_tx_pause: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2004 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2005 | * software over-ride. |
| 2006 | */ |
| 2007 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 2008 | break; |
| 2009 | case e1000_fc_full: |
| 2010 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 2011 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 2012 | break; |
| 2013 | default: |
| 2014 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 2015 | return -E1000_ERR_CONFIG; |
| 2016 | break; |
| 2017 | } |
| 2018 | |
| 2019 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 2020 | * will be in reset, because we previously reset the chip). This will |
| 2021 | * restart auto-negotiation. If auto-neogtiation is successful then the |
| 2022 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 2023 | * and TFCE) will be set according to their negotiated value. |
| 2024 | */ |
| 2025 | DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw); |
| 2026 | |
| 2027 | E1000_WRITE_REG(hw, TXCW, txcw); |
| 2028 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2029 | E1000_WRITE_FLUSH(hw); |
| 2030 | |
| 2031 | hw->txcw = txcw; |
| 2032 | mdelay(1); |
| 2033 | |
| 2034 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2035 | * indication in the Device Status Register. Time-out if a link isn't |
| 2036 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2037 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 2038 | */ |
| 2039 | if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
| 2040 | DEBUGOUT("Looking for Link\n"); |
| 2041 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
| 2042 | mdelay(10); |
| 2043 | status = E1000_READ_REG(hw, STATUS); |
| 2044 | if (status & E1000_STATUS_LU) |
| 2045 | break; |
| 2046 | } |
| 2047 | if (i == (LINK_UP_TIMEOUT / 10)) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2048 | /* AutoNeg failed to achieve a link, so we'll call |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2049 | * e1000_check_for_link. This routine will force the link up if we |
| 2050 | * detect a signal. This will allow us to communicate with |
| 2051 | * non-autonegotiating link partners. |
| 2052 | */ |
| 2053 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); |
| 2054 | hw->autoneg_failed = 1; |
| 2055 | ret_val = e1000_check_for_link(nic); |
| 2056 | if (ret_val < 0) { |
| 2057 | DEBUGOUT("Error while checking for link\n"); |
| 2058 | return ret_val; |
| 2059 | } |
| 2060 | hw->autoneg_failed = 0; |
| 2061 | } else { |
| 2062 | hw->autoneg_failed = 0; |
| 2063 | DEBUGOUT("Valid Link Found\n"); |
| 2064 | } |
| 2065 | } else { |
| 2066 | DEBUGOUT("No Signal Detected\n"); |
| 2067 | return -E1000_ERR_NOLINK; |
| 2068 | } |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2073 | * Make sure we have a valid PHY and change PHY mode before link setup. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2074 | * |
| 2075 | * hw - Struct containing variables accessed by shared code |
| 2076 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2077 | static int32_t |
| 2078 | e1000_copper_link_preconfig(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2079 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2080 | uint32_t ctrl; |
| 2081 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2082 | uint16_t phy_data; |
| 2083 | |
| 2084 | DEBUGFUNC(); |
| 2085 | |
| 2086 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2087 | /* With 82543, we need to force speed and duplex on the MAC equal to what |
| 2088 | * the PHY speed and duplex configuration is. In addition, we need to |
| 2089 | * perform a hardware reset on the PHY to take it out of reset. |
| 2090 | */ |
| 2091 | if (hw->mac_type > e1000_82543) { |
| 2092 | ctrl |= E1000_CTRL_SLU; |
| 2093 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 2094 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2095 | } else { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2096 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
| 2097 | | E1000_CTRL_SLU); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2098 | E1000_WRITE_REG(hw, CTRL, ctrl); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2099 | ret_val = e1000_phy_hw_reset(hw); |
| 2100 | if (ret_val) |
| 2101 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | /* Make sure we have a valid PHY */ |
| 2105 | ret_val = e1000_detect_gig_phy(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2106 | if (ret_val) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2107 | DEBUGOUT("Error, did not detect valid phy.\n"); |
| 2108 | return ret_val; |
| 2109 | } |
| 2110 | DEBUGOUT("Phy ID = %x \n", hw->phy_id); |
| 2111 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2112 | #ifndef CONFIG_AP1000 |
| 2113 | /* Set PHY to class A mode (if necessary) */ |
| 2114 | ret_val = e1000_set_phy_mode(hw); |
| 2115 | if (ret_val) |
| 2116 | return ret_val; |
| 2117 | #endif |
| 2118 | if ((hw->mac_type == e1000_82545_rev_3) || |
| 2119 | (hw->mac_type == e1000_82546_rev_3)) { |
| 2120 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, |
| 2121 | &phy_data); |
| 2122 | phy_data |= 0x00000008; |
| 2123 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, |
| 2124 | phy_data); |
| 2125 | } |
| 2126 | |
| 2127 | if (hw->mac_type <= e1000_82543 || |
| 2128 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 2129 | hw->mac_type == e1000_82541_rev_2 |
| 2130 | || hw->mac_type == e1000_82547_rev_2) |
| 2131 | hw->phy_reset_disable = FALSE; |
| 2132 | |
| 2133 | return E1000_SUCCESS; |
| 2134 | } |
| 2135 | |
| 2136 | /***************************************************************************** |
| 2137 | * |
| 2138 | * This function sets the lplu state according to the active flag. When |
| 2139 | * activating lplu this function also disables smart speed and vise versa. |
| 2140 | * lplu will not be activated unless the device autonegotiation advertisment |
| 2141 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 2142 | * hw: Struct containing variables accessed by shared code |
| 2143 | * active - true to enable lplu false to disable lplu. |
| 2144 | * |
| 2145 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 2146 | * E1000_SUCCESS at any other case. |
| 2147 | * |
| 2148 | ****************************************************************************/ |
| 2149 | |
| 2150 | static int32_t |
| 2151 | e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active) |
| 2152 | { |
| 2153 | uint32_t phy_ctrl = 0; |
| 2154 | int32_t ret_val; |
| 2155 | uint16_t phy_data; |
| 2156 | DEBUGFUNC(); |
| 2157 | |
| 2158 | if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2 |
| 2159 | && hw->phy_type != e1000_phy_igp_3) |
| 2160 | return E1000_SUCCESS; |
| 2161 | |
| 2162 | /* During driver activity LPLU should not be used or it will attain link |
| 2163 | * from the lowest speeds starting from 10Mbps. The capability is used |
| 2164 | * for Dx transitions and states */ |
| 2165 | if (hw->mac_type == e1000_82541_rev_2 |
| 2166 | || hw->mac_type == e1000_82547_rev_2) { |
| 2167 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 2168 | &phy_data); |
| 2169 | if (ret_val) |
| 2170 | return ret_val; |
| 2171 | } else if (hw->mac_type == e1000_ich8lan) { |
| 2172 | /* MAC writes into PHY register based on the state transition |
| 2173 | * and start auto-negotiation. SW driver can overwrite the |
| 2174 | * settings in CSR PHY power control E1000_PHY_CTRL register. */ |
| 2175 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
| 2176 | } else { |
| 2177 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 2178 | &phy_data); |
| 2179 | if (ret_val) |
| 2180 | return ret_val; |
| 2181 | } |
| 2182 | |
| 2183 | if (!active) { |
| 2184 | if (hw->mac_type == e1000_82541_rev_2 || |
| 2185 | hw->mac_type == e1000_82547_rev_2) { |
| 2186 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 2187 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 2188 | phy_data); |
| 2189 | if (ret_val) |
| 2190 | return ret_val; |
| 2191 | } else { |
| 2192 | if (hw->mac_type == e1000_ich8lan) { |
| 2193 | phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU; |
| 2194 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 2195 | } else { |
| 2196 | phy_data &= ~IGP02E1000_PM_D3_LPLU; |
| 2197 | ret_val = e1000_write_phy_reg(hw, |
| 2198 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2199 | if (ret_val) |
| 2200 | return ret_val; |
| 2201 | } |
| 2202 | } |
| 2203 | |
| 2204 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 2205 | * Dx states where the power conservation is most important. During |
| 2206 | * driver activity we should enable SmartSpeed, so performance is |
| 2207 | * maintained. */ |
| 2208 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 2209 | ret_val = e1000_read_phy_reg(hw, |
| 2210 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2211 | if (ret_val) |
| 2212 | return ret_val; |
| 2213 | |
| 2214 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 2215 | ret_val = e1000_write_phy_reg(hw, |
| 2216 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2217 | if (ret_val) |
| 2218 | return ret_val; |
| 2219 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 2220 | ret_val = e1000_read_phy_reg(hw, |
| 2221 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2222 | if (ret_val) |
| 2223 | return ret_val; |
| 2224 | |
| 2225 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2226 | ret_val = e1000_write_phy_reg(hw, |
| 2227 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2228 | if (ret_val) |
| 2229 | return ret_val; |
| 2230 | } |
| 2231 | |
| 2232 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) |
| 2233 | || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) || |
| 2234 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { |
| 2235 | |
| 2236 | if (hw->mac_type == e1000_82541_rev_2 || |
| 2237 | hw->mac_type == e1000_82547_rev_2) { |
| 2238 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 2239 | ret_val = e1000_write_phy_reg(hw, |
| 2240 | IGP01E1000_GMII_FIFO, phy_data); |
| 2241 | if (ret_val) |
| 2242 | return ret_val; |
| 2243 | } else { |
| 2244 | if (hw->mac_type == e1000_ich8lan) { |
| 2245 | phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU; |
| 2246 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 2247 | } else { |
| 2248 | phy_data |= IGP02E1000_PM_D3_LPLU; |
| 2249 | ret_val = e1000_write_phy_reg(hw, |
| 2250 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2251 | if (ret_val) |
| 2252 | return ret_val; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 2257 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 2258 | &phy_data); |
| 2259 | if (ret_val) |
| 2260 | return ret_val; |
| 2261 | |
| 2262 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2263 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 2264 | phy_data); |
| 2265 | if (ret_val) |
| 2266 | return ret_val; |
| 2267 | } |
| 2268 | return E1000_SUCCESS; |
| 2269 | } |
| 2270 | |
| 2271 | /***************************************************************************** |
| 2272 | * |
| 2273 | * This function sets the lplu d0 state according to the active flag. When |
| 2274 | * activating lplu this function also disables smart speed and vise versa. |
| 2275 | * lplu will not be activated unless the device autonegotiation advertisment |
| 2276 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 2277 | * hw: Struct containing variables accessed by shared code |
| 2278 | * active - true to enable lplu false to disable lplu. |
| 2279 | * |
| 2280 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 2281 | * E1000_SUCCESS at any other case. |
| 2282 | * |
| 2283 | ****************************************************************************/ |
| 2284 | |
| 2285 | static int32_t |
| 2286 | e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active) |
| 2287 | { |
| 2288 | uint32_t phy_ctrl = 0; |
| 2289 | int32_t ret_val; |
| 2290 | uint16_t phy_data; |
| 2291 | DEBUGFUNC(); |
| 2292 | |
| 2293 | if (hw->mac_type <= e1000_82547_rev_2) |
| 2294 | return E1000_SUCCESS; |
| 2295 | |
| 2296 | if (hw->mac_type == e1000_ich8lan) { |
| 2297 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
| 2298 | } else { |
| 2299 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 2300 | &phy_data); |
| 2301 | if (ret_val) |
| 2302 | return ret_val; |
| 2303 | } |
| 2304 | |
| 2305 | if (!active) { |
| 2306 | if (hw->mac_type == e1000_ich8lan) { |
| 2307 | phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU; |
| 2308 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 2309 | } else { |
| 2310 | phy_data &= ~IGP02E1000_PM_D0_LPLU; |
| 2311 | ret_val = e1000_write_phy_reg(hw, |
| 2312 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2313 | if (ret_val) |
| 2314 | return ret_val; |
| 2315 | } |
| 2316 | |
| 2317 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 2318 | * Dx states where the power conservation is most important. During |
| 2319 | * driver activity we should enable SmartSpeed, so performance is |
| 2320 | * maintained. */ |
| 2321 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 2322 | ret_val = e1000_read_phy_reg(hw, |
| 2323 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2324 | if (ret_val) |
| 2325 | return ret_val; |
| 2326 | |
| 2327 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 2328 | ret_val = e1000_write_phy_reg(hw, |
| 2329 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2330 | if (ret_val) |
| 2331 | return ret_val; |
| 2332 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 2333 | ret_val = e1000_read_phy_reg(hw, |
| 2334 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2335 | if (ret_val) |
| 2336 | return ret_val; |
| 2337 | |
| 2338 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2339 | ret_val = e1000_write_phy_reg(hw, |
| 2340 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2341 | if (ret_val) |
| 2342 | return ret_val; |
| 2343 | } |
| 2344 | |
| 2345 | |
| 2346 | } else { |
| 2347 | |
| 2348 | if (hw->mac_type == e1000_ich8lan) { |
| 2349 | phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU; |
| 2350 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 2351 | } else { |
| 2352 | phy_data |= IGP02E1000_PM_D0_LPLU; |
| 2353 | ret_val = e1000_write_phy_reg(hw, |
| 2354 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2355 | if (ret_val) |
| 2356 | return ret_val; |
| 2357 | } |
| 2358 | |
| 2359 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 2360 | ret_val = e1000_read_phy_reg(hw, |
| 2361 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2362 | if (ret_val) |
| 2363 | return ret_val; |
| 2364 | |
| 2365 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2366 | ret_val = e1000_write_phy_reg(hw, |
| 2367 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2368 | if (ret_val) |
| 2369 | return ret_val; |
| 2370 | |
| 2371 | } |
| 2372 | return E1000_SUCCESS; |
| 2373 | } |
| 2374 | |
| 2375 | /******************************************************************** |
| 2376 | * Copper link setup for e1000_phy_igp series. |
| 2377 | * |
| 2378 | * hw - Struct containing variables accessed by shared code |
| 2379 | *********************************************************************/ |
| 2380 | static int32_t |
| 2381 | e1000_copper_link_igp_setup(struct e1000_hw *hw) |
| 2382 | { |
| 2383 | uint32_t led_ctrl; |
| 2384 | int32_t ret_val; |
| 2385 | uint16_t phy_data; |
| 2386 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 2387 | DEBUGFUNC(); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2388 | |
| 2389 | if (hw->phy_reset_disable) |
| 2390 | return E1000_SUCCESS; |
| 2391 | |
| 2392 | ret_val = e1000_phy_reset(hw); |
| 2393 | if (ret_val) { |
| 2394 | DEBUGOUT("Error Resetting the PHY\n"); |
| 2395 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2396 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2397 | |
| 2398 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
| 2399 | mdelay(15); |
| 2400 | if (hw->mac_type != e1000_ich8lan) { |
| 2401 | /* Configure activity LED after PHY reset */ |
| 2402 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 2403 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 2404 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 2405 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 2406 | } |
| 2407 | |
| 2408 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 2409 | if (hw->phy_type == e1000_phy_igp) { |
| 2410 | /* disable lplu d3 during driver init */ |
| 2411 | ret_val = e1000_set_d3_lplu_state(hw, FALSE); |
| 2412 | if (ret_val) { |
| 2413 | DEBUGOUT("Error Disabling LPLU D3\n"); |
| 2414 | return ret_val; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | /* disable lplu d0 during driver init */ |
| 2419 | ret_val = e1000_set_d0_lplu_state(hw, FALSE); |
| 2420 | if (ret_val) { |
| 2421 | DEBUGOUT("Error Disabling LPLU D0\n"); |
| 2422 | return ret_val; |
| 2423 | } |
| 2424 | /* Configure mdi-mdix settings */ |
| 2425 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 2426 | if (ret_val) |
| 2427 | return ret_val; |
| 2428 | |
| 2429 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 2430 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 2431 | /* Force MDI for earlier revs of the IGP PHY */ |
| 2432 | phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
| 2433 | | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 2434 | hw->mdix = 1; |
| 2435 | |
| 2436 | } else { |
| 2437 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 2438 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 2439 | |
| 2440 | switch (hw->mdix) { |
| 2441 | case 1: |
| 2442 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 2443 | break; |
| 2444 | case 2: |
| 2445 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 2446 | break; |
| 2447 | case 0: |
| 2448 | default: |
| 2449 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 2450 | break; |
| 2451 | } |
| 2452 | } |
| 2453 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
| 2454 | if (ret_val) |
| 2455 | return ret_val; |
| 2456 | |
| 2457 | /* set auto-master slave resolution settings */ |
| 2458 | if (hw->autoneg) { |
| 2459 | e1000_ms_type phy_ms_setting = hw->master_slave; |
| 2460 | |
| 2461 | if (hw->ffe_config_state == e1000_ffe_config_active) |
| 2462 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 2463 | |
| 2464 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
| 2465 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 2466 | |
| 2467 | /* when autonegotiation advertisment is only 1000Mbps then we |
| 2468 | * should disable SmartSpeed and enable Auto MasterSlave |
| 2469 | * resolution as hardware default. */ |
| 2470 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 2471 | /* Disable SmartSpeed */ |
| 2472 | ret_val = e1000_read_phy_reg(hw, |
| 2473 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2474 | if (ret_val) |
| 2475 | return ret_val; |
| 2476 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2477 | ret_val = e1000_write_phy_reg(hw, |
| 2478 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2479 | if (ret_val) |
| 2480 | return ret_val; |
| 2481 | /* Set auto Master/Slave resolution process */ |
| 2482 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, |
| 2483 | &phy_data); |
| 2484 | if (ret_val) |
| 2485 | return ret_val; |
| 2486 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 2487 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
| 2488 | phy_data); |
| 2489 | if (ret_val) |
| 2490 | return ret_val; |
| 2491 | } |
| 2492 | |
| 2493 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 2494 | if (ret_val) |
| 2495 | return ret_val; |
| 2496 | |
| 2497 | /* load defaults for future use */ |
| 2498 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 2499 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 2500 | e1000_ms_force_master : |
| 2501 | e1000_ms_force_slave) : |
| 2502 | e1000_ms_auto; |
| 2503 | |
| 2504 | switch (phy_ms_setting) { |
| 2505 | case e1000_ms_force_master: |
| 2506 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 2507 | break; |
| 2508 | case e1000_ms_force_slave: |
| 2509 | phy_data |= CR_1000T_MS_ENABLE; |
| 2510 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 2511 | break; |
| 2512 | case e1000_ms_auto: |
| 2513 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 2514 | default: |
| 2515 | break; |
| 2516 | } |
| 2517 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
| 2518 | if (ret_val) |
| 2519 | return ret_val; |
| 2520 | } |
| 2521 | |
| 2522 | return E1000_SUCCESS; |
| 2523 | } |
| 2524 | |
| 2525 | /***************************************************************************** |
| 2526 | * This function checks the mode of the firmware. |
| 2527 | * |
| 2528 | * returns - TRUE when the mode is IAMT or FALSE. |
| 2529 | ****************************************************************************/ |
| 2530 | boolean_t |
| 2531 | e1000_check_mng_mode(struct e1000_hw *hw) |
| 2532 | { |
| 2533 | uint32_t fwsm; |
| 2534 | DEBUGFUNC(); |
| 2535 | |
| 2536 | fwsm = E1000_READ_REG(hw, FWSM); |
| 2537 | |
| 2538 | if (hw->mac_type == e1000_ich8lan) { |
| 2539 | if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 2540 | (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
| 2541 | return TRUE; |
| 2542 | } else if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 2543 | (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
| 2544 | return TRUE; |
| 2545 | |
| 2546 | return FALSE; |
| 2547 | } |
| 2548 | |
| 2549 | static int32_t |
| 2550 | e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data) |
| 2551 | { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2552 | uint16_t swfw = E1000_SWFW_PHY0_SM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2553 | uint32_t reg_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2554 | DEBUGFUNC(); |
| 2555 | |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2556 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2557 | swfw = E1000_SWFW_PHY1_SM; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2558 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2559 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 2560 | return -E1000_ERR_SWFW_SYNC; |
| 2561 | |
| 2562 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) |
| 2563 | & E1000_KUMCTRLSTA_OFFSET) | data; |
| 2564 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 2565 | udelay(2); |
| 2566 | |
| 2567 | return E1000_SUCCESS; |
| 2568 | } |
| 2569 | |
| 2570 | static int32_t |
| 2571 | e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data) |
| 2572 | { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2573 | uint16_t swfw = E1000_SWFW_PHY0_SM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2574 | uint32_t reg_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2575 | DEBUGFUNC(); |
| 2576 | |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2577 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2578 | swfw = E1000_SWFW_PHY1_SM; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2579 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2580 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 2581 | return -E1000_ERR_SWFW_SYNC; |
| 2582 | |
| 2583 | /* Write register address */ |
| 2584 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) & |
| 2585 | E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN; |
| 2586 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 2587 | udelay(2); |
| 2588 | |
| 2589 | /* Read the data returned */ |
| 2590 | reg_val = E1000_READ_REG(hw, KUMCTRLSTA); |
| 2591 | *data = (uint16_t)reg_val; |
| 2592 | |
| 2593 | return E1000_SUCCESS; |
| 2594 | } |
| 2595 | |
| 2596 | /******************************************************************** |
| 2597 | * Copper link setup for e1000_phy_gg82563 series. |
| 2598 | * |
| 2599 | * hw - Struct containing variables accessed by shared code |
| 2600 | *********************************************************************/ |
| 2601 | static int32_t |
| 2602 | e1000_copper_link_ggp_setup(struct e1000_hw *hw) |
| 2603 | { |
| 2604 | int32_t ret_val; |
| 2605 | uint16_t phy_data; |
| 2606 | uint32_t reg_data; |
| 2607 | |
| 2608 | DEBUGFUNC(); |
| 2609 | |
| 2610 | if (!hw->phy_reset_disable) { |
| 2611 | /* Enable CRS on TX for half-duplex operation. */ |
| 2612 | ret_val = e1000_read_phy_reg(hw, |
| 2613 | GG82563_PHY_MAC_SPEC_CTRL, &phy_data); |
| 2614 | if (ret_val) |
| 2615 | return ret_val; |
| 2616 | |
| 2617 | phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX; |
| 2618 | /* Use 25MHz for both link down and 1000BASE-T for Tx clock */ |
| 2619 | phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ; |
| 2620 | |
| 2621 | ret_val = e1000_write_phy_reg(hw, |
| 2622 | GG82563_PHY_MAC_SPEC_CTRL, phy_data); |
| 2623 | if (ret_val) |
| 2624 | return ret_val; |
| 2625 | |
| 2626 | /* Options: |
| 2627 | * MDI/MDI-X = 0 (default) |
| 2628 | * 0 - Auto for all speeds |
| 2629 | * 1 - MDI mode |
| 2630 | * 2 - MDI-X mode |
| 2631 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 2632 | */ |
| 2633 | ret_val = e1000_read_phy_reg(hw, |
| 2634 | GG82563_PHY_SPEC_CTRL, &phy_data); |
| 2635 | if (ret_val) |
| 2636 | return ret_val; |
| 2637 | |
| 2638 | phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK; |
| 2639 | |
| 2640 | switch (hw->mdix) { |
| 2641 | case 1: |
| 2642 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI; |
| 2643 | break; |
| 2644 | case 2: |
| 2645 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX; |
| 2646 | break; |
| 2647 | case 0: |
| 2648 | default: |
| 2649 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO; |
| 2650 | break; |
| 2651 | } |
| 2652 | |
| 2653 | /* Options: |
| 2654 | * disable_polarity_correction = 0 (default) |
| 2655 | * Automatic Correction for Reversed Cable Polarity |
| 2656 | * 0 - Disabled |
| 2657 | * 1 - Enabled |
| 2658 | */ |
| 2659 | phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE; |
| 2660 | ret_val = e1000_write_phy_reg(hw, |
| 2661 | GG82563_PHY_SPEC_CTRL, phy_data); |
| 2662 | |
| 2663 | if (ret_val) |
| 2664 | return ret_val; |
| 2665 | |
| 2666 | /* SW Reset the PHY so all changes take effect */ |
| 2667 | ret_val = e1000_phy_reset(hw); |
| 2668 | if (ret_val) { |
| 2669 | DEBUGOUT("Error Resetting the PHY\n"); |
| 2670 | return ret_val; |
| 2671 | } |
| 2672 | } /* phy_reset_disable */ |
| 2673 | |
| 2674 | if (hw->mac_type == e1000_80003es2lan) { |
| 2675 | /* Bypass RX and TX FIFO's */ |
| 2676 | ret_val = e1000_write_kmrn_reg(hw, |
| 2677 | E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL, |
| 2678 | E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
| 2679 | | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS); |
| 2680 | if (ret_val) |
| 2681 | return ret_val; |
| 2682 | |
| 2683 | ret_val = e1000_read_phy_reg(hw, |
| 2684 | GG82563_PHY_SPEC_CTRL_2, &phy_data); |
| 2685 | if (ret_val) |
| 2686 | return ret_val; |
| 2687 | |
| 2688 | phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG; |
| 2689 | ret_val = e1000_write_phy_reg(hw, |
| 2690 | GG82563_PHY_SPEC_CTRL_2, phy_data); |
| 2691 | |
| 2692 | if (ret_val) |
| 2693 | return ret_val; |
| 2694 | |
| 2695 | reg_data = E1000_READ_REG(hw, CTRL_EXT); |
| 2696 | reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK); |
| 2697 | E1000_WRITE_REG(hw, CTRL_EXT, reg_data); |
| 2698 | |
| 2699 | ret_val = e1000_read_phy_reg(hw, |
| 2700 | GG82563_PHY_PWR_MGMT_CTRL, &phy_data); |
| 2701 | if (ret_val) |
| 2702 | return ret_val; |
| 2703 | |
| 2704 | /* Do not init these registers when the HW is in IAMT mode, since the |
| 2705 | * firmware will have already initialized them. We only initialize |
| 2706 | * them if the HW is not in IAMT mode. |
| 2707 | */ |
| 2708 | if (e1000_check_mng_mode(hw) == FALSE) { |
| 2709 | /* Enable Electrical Idle on the PHY */ |
| 2710 | phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE; |
| 2711 | ret_val = e1000_write_phy_reg(hw, |
| 2712 | GG82563_PHY_PWR_MGMT_CTRL, phy_data); |
| 2713 | if (ret_val) |
| 2714 | return ret_val; |
| 2715 | |
| 2716 | ret_val = e1000_read_phy_reg(hw, |
| 2717 | GG82563_PHY_KMRN_MODE_CTRL, &phy_data); |
| 2718 | if (ret_val) |
| 2719 | return ret_val; |
| 2720 | |
| 2721 | phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2722 | ret_val = e1000_write_phy_reg(hw, |
| 2723 | GG82563_PHY_KMRN_MODE_CTRL, phy_data); |
| 2724 | |
| 2725 | if (ret_val) |
| 2726 | return ret_val; |
| 2727 | } |
| 2728 | |
| 2729 | /* Workaround: Disable padding in Kumeran interface in the MAC |
| 2730 | * and in the PHY to avoid CRC errors. |
| 2731 | */ |
| 2732 | ret_val = e1000_read_phy_reg(hw, |
| 2733 | GG82563_PHY_INBAND_CTRL, &phy_data); |
| 2734 | if (ret_val) |
| 2735 | return ret_val; |
| 2736 | phy_data |= GG82563_ICR_DIS_PADDING; |
| 2737 | ret_val = e1000_write_phy_reg(hw, |
| 2738 | GG82563_PHY_INBAND_CTRL, phy_data); |
| 2739 | if (ret_val) |
| 2740 | return ret_val; |
| 2741 | } |
| 2742 | return E1000_SUCCESS; |
| 2743 | } |
| 2744 | |
| 2745 | /******************************************************************** |
| 2746 | * Copper link setup for e1000_phy_m88 series. |
| 2747 | * |
| 2748 | * hw - Struct containing variables accessed by shared code |
| 2749 | *********************************************************************/ |
| 2750 | static int32_t |
| 2751 | e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
| 2752 | { |
| 2753 | int32_t ret_val; |
| 2754 | uint16_t phy_data; |
| 2755 | |
| 2756 | DEBUGFUNC(); |
| 2757 | |
| 2758 | if (hw->phy_reset_disable) |
| 2759 | return E1000_SUCCESS; |
| 2760 | |
| 2761 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 2762 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 2763 | if (ret_val) |
| 2764 | return ret_val; |
| 2765 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2766 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 2767 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2768 | /* Options: |
| 2769 | * MDI/MDI-X = 0 (default) |
| 2770 | * 0 - Auto for all speeds |
| 2771 | * 1 - MDI mode |
| 2772 | * 2 - MDI-X mode |
| 2773 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 2774 | */ |
| 2775 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2776 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2777 | switch (hw->mdix) { |
| 2778 | case 1: |
| 2779 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 2780 | break; |
| 2781 | case 2: |
| 2782 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 2783 | break; |
| 2784 | case 3: |
| 2785 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 2786 | break; |
| 2787 | case 0: |
| 2788 | default: |
| 2789 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 2790 | break; |
| 2791 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2792 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2793 | /* Options: |
| 2794 | * disable_polarity_correction = 0 (default) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2795 | * Automatic Correction for Reversed Cable Polarity |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2796 | * 0 - Disabled |
| 2797 | * 1 - Enabled |
| 2798 | */ |
| 2799 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2800 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 2801 | if (ret_val) |
| 2802 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2803 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2804 | if (hw->phy_revision < M88E1011_I_REV_4) { |
| 2805 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 2806 | * to 25MHz clock. |
| 2807 | */ |
| 2808 | ret_val = e1000_read_phy_reg(hw, |
| 2809 | M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
| 2810 | if (ret_val) |
| 2811 | return ret_val; |
| 2812 | |
| 2813 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 2814 | |
| 2815 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 2816 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 2817 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 2818 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 2819 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 2820 | ret_val = e1000_write_phy_reg(hw, |
| 2821 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 2822 | if (ret_val) |
| 2823 | return ret_val; |
| 2824 | } else { |
| 2825 | /* Configure Master and Slave downshift values */ |
| 2826 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
| 2827 | | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 2828 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
| 2829 | | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 2830 | ret_val = e1000_write_phy_reg(hw, |
| 2831 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 2832 | if (ret_val) |
| 2833 | return ret_val; |
| 2834 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | /* SW Reset the PHY so all changes take effect */ |
| 2838 | ret_val = e1000_phy_reset(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2839 | if (ret_val) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2840 | DEBUGOUT("Error Resetting the PHY\n"); |
| 2841 | return ret_val; |
| 2842 | } |
| 2843 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2844 | return E1000_SUCCESS; |
| 2845 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2846 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2847 | /******************************************************************** |
| 2848 | * Setup auto-negotiation and flow control advertisements, |
| 2849 | * and then perform auto-negotiation. |
| 2850 | * |
| 2851 | * hw - Struct containing variables accessed by shared code |
| 2852 | *********************************************************************/ |
| 2853 | static int32_t |
| 2854 | e1000_copper_link_autoneg(struct e1000_hw *hw) |
| 2855 | { |
| 2856 | int32_t ret_val; |
| 2857 | uint16_t phy_data; |
| 2858 | |
| 2859 | DEBUGFUNC(); |
| 2860 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2861 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 2862 | * parameter. If this variable is zero, then set it to the default. |
| 2863 | */ |
| 2864 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 2865 | |
| 2866 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 2867 | * by the calling code so we set to advertise full capability. |
| 2868 | */ |
| 2869 | if (hw->autoneg_advertised == 0) |
| 2870 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 2871 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2872 | /* IFE phy only supports 10/100 */ |
| 2873 | if (hw->phy_type == e1000_phy_ife) |
| 2874 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; |
| 2875 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2876 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); |
| 2877 | ret_val = e1000_phy_setup_autoneg(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2878 | if (ret_val) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2879 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); |
| 2880 | return ret_val; |
| 2881 | } |
| 2882 | DEBUGOUT("Restarting Auto-Neg\n"); |
| 2883 | |
| 2884 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 2885 | * the Auto Neg Restart bit in the PHY control register. |
| 2886 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2887 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 2888 | if (ret_val) |
| 2889 | return ret_val; |
| 2890 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2891 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2892 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 2893 | if (ret_val) |
| 2894 | return ret_val; |
| 2895 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2896 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 2897 | * check at a later time (for example, callback routine). |
| 2898 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2899 | /* If we do not wait for autonegtation to complete I |
| 2900 | * do not see a valid link status. |
| 2901 | * wait_autoneg_complete = 1 . |
| 2902 | */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2903 | if (hw->wait_autoneg_complete) { |
| 2904 | ret_val = e1000_wait_autoneg(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2905 | if (ret_val) { |
| 2906 | DEBUGOUT("Error while waiting for autoneg" |
| 2907 | "to complete\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2908 | return ret_val; |
| 2909 | } |
| 2910 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2911 | |
| 2912 | hw->get_link_status = TRUE; |
| 2913 | |
| 2914 | return E1000_SUCCESS; |
| 2915 | } |
| 2916 | |
| 2917 | /****************************************************************************** |
| 2918 | * Config the MAC and the PHY after link is up. |
| 2919 | * 1) Set up the MAC to the current PHY speed/duplex |
| 2920 | * if we are on 82543. If we |
| 2921 | * are on newer silicon, we only need to configure |
| 2922 | * collision distance in the Transmit Control Register. |
| 2923 | * 2) Set up flow control on the MAC to that established with |
| 2924 | * the link partner. |
| 2925 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
| 2926 | * |
| 2927 | * hw - Struct containing variables accessed by shared code |
| 2928 | ******************************************************************************/ |
| 2929 | static int32_t |
| 2930 | e1000_copper_link_postconfig(struct e1000_hw *hw) |
| 2931 | { |
| 2932 | int32_t ret_val; |
| 2933 | DEBUGFUNC(); |
| 2934 | |
| 2935 | if (hw->mac_type >= e1000_82544) { |
| 2936 | e1000_config_collision_dist(hw); |
| 2937 | } else { |
| 2938 | ret_val = e1000_config_mac_to_phy(hw); |
| 2939 | if (ret_val) { |
| 2940 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 2941 | return ret_val; |
| 2942 | } |
| 2943 | } |
| 2944 | ret_val = e1000_config_fc_after_link_up(hw); |
| 2945 | if (ret_val) { |
| 2946 | DEBUGOUT("Error Configuring Flow Control\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2947 | return ret_val; |
| 2948 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2949 | return E1000_SUCCESS; |
| 2950 | } |
| 2951 | |
| 2952 | /****************************************************************************** |
| 2953 | * Detects which PHY is present and setup the speed and duplex |
| 2954 | * |
| 2955 | * hw - Struct containing variables accessed by shared code |
| 2956 | ******************************************************************************/ |
| 2957 | static int |
| 2958 | e1000_setup_copper_link(struct eth_device *nic) |
| 2959 | { |
| 2960 | struct e1000_hw *hw = nic->priv; |
| 2961 | int32_t ret_val; |
| 2962 | uint16_t i; |
| 2963 | uint16_t phy_data; |
| 2964 | uint16_t reg_data; |
| 2965 | |
| 2966 | DEBUGFUNC(); |
| 2967 | |
| 2968 | switch (hw->mac_type) { |
| 2969 | case e1000_80003es2lan: |
| 2970 | case e1000_ich8lan: |
| 2971 | /* Set the mac to wait the maximum time between each |
| 2972 | * iteration and increase the max iterations when |
| 2973 | * polling the phy; this fixes erroneous timeouts at 10Mbps. */ |
| 2974 | ret_val = e1000_write_kmrn_reg(hw, |
| 2975 | GG82563_REG(0x34, 4), 0xFFFF); |
| 2976 | if (ret_val) |
| 2977 | return ret_val; |
| 2978 | ret_val = e1000_read_kmrn_reg(hw, |
| 2979 | GG82563_REG(0x34, 9), ®_data); |
| 2980 | if (ret_val) |
| 2981 | return ret_val; |
| 2982 | reg_data |= 0x3F; |
| 2983 | ret_val = e1000_write_kmrn_reg(hw, |
| 2984 | GG82563_REG(0x34, 9), reg_data); |
| 2985 | if (ret_val) |
| 2986 | return ret_val; |
| 2987 | default: |
| 2988 | break; |
| 2989 | } |
| 2990 | |
| 2991 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 2992 | ret_val = e1000_copper_link_preconfig(hw); |
| 2993 | if (ret_val) |
| 2994 | return ret_val; |
| 2995 | switch (hw->mac_type) { |
| 2996 | case e1000_80003es2lan: |
| 2997 | /* Kumeran registers are written-only */ |
| 2998 | reg_data = |
| 2999 | E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT; |
| 3000 | reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING; |
| 3001 | ret_val = e1000_write_kmrn_reg(hw, |
| 3002 | E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data); |
| 3003 | if (ret_val) |
| 3004 | return ret_val; |
| 3005 | break; |
| 3006 | default: |
| 3007 | break; |
| 3008 | } |
| 3009 | |
| 3010 | if (hw->phy_type == e1000_phy_igp || |
| 3011 | hw->phy_type == e1000_phy_igp_3 || |
| 3012 | hw->phy_type == e1000_phy_igp_2) { |
| 3013 | ret_val = e1000_copper_link_igp_setup(hw); |
| 3014 | if (ret_val) |
| 3015 | return ret_val; |
| 3016 | } else if (hw->phy_type == e1000_phy_m88) { |
| 3017 | ret_val = e1000_copper_link_mgp_setup(hw); |
| 3018 | if (ret_val) |
| 3019 | return ret_val; |
| 3020 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 3021 | ret_val = e1000_copper_link_ggp_setup(hw); |
| 3022 | if (ret_val) |
| 3023 | return ret_val; |
| 3024 | } |
| 3025 | |
| 3026 | /* always auto */ |
| 3027 | /* Setup autoneg and flow control advertisement |
| 3028 | * and perform autonegotiation */ |
| 3029 | ret_val = e1000_copper_link_autoneg(hw); |
| 3030 | if (ret_val) |
| 3031 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3032 | |
| 3033 | /* Check link status. Wait up to 100 microseconds for link to become |
| 3034 | * valid. |
| 3035 | */ |
| 3036 | for (i = 0; i < 10; i++) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3037 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3038 | if (ret_val) |
| 3039 | return ret_val; |
| 3040 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3041 | if (ret_val) |
| 3042 | return ret_val; |
| 3043 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3044 | if (phy_data & MII_SR_LINK_STATUS) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3045 | /* Config the MAC and PHY after link is up */ |
| 3046 | ret_val = e1000_copper_link_postconfig(hw); |
| 3047 | if (ret_val) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3048 | return ret_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3049 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3050 | DEBUGOUT("Valid link established!!!\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3051 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3052 | } |
| 3053 | udelay(10); |
| 3054 | } |
| 3055 | |
| 3056 | DEBUGOUT("Unable to establish link!!!\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3057 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /****************************************************************************** |
| 3061 | * Configures PHY autoneg and flow control advertisement settings |
| 3062 | * |
| 3063 | * hw - Struct containing variables accessed by shared code |
| 3064 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3065 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3066 | e1000_phy_setup_autoneg(struct e1000_hw *hw) |
| 3067 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3068 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3069 | uint16_t mii_autoneg_adv_reg; |
| 3070 | uint16_t mii_1000t_ctrl_reg; |
| 3071 | |
| 3072 | DEBUGFUNC(); |
| 3073 | |
| 3074 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3075 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
| 3076 | if (ret_val) |
| 3077 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3078 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3079 | if (hw->phy_type != e1000_phy_ife) { |
| 3080 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
| 3081 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, |
| 3082 | &mii_1000t_ctrl_reg); |
| 3083 | if (ret_val) |
| 3084 | return ret_val; |
| 3085 | } else |
| 3086 | mii_1000t_ctrl_reg = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3087 | |
| 3088 | /* Need to parse both autoneg_advertised and fc and set up |
| 3089 | * the appropriate PHY registers. First we will parse for |
| 3090 | * autoneg_advertised software override. Since we can advertise |
| 3091 | * a plethora of combinations, we need to check each bit |
| 3092 | * individually. |
| 3093 | */ |
| 3094 | |
| 3095 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 3096 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3097 | * the 1000Base-T Control Register (Address 9). |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3098 | */ |
| 3099 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 3100 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
| 3101 | |
| 3102 | DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised); |
| 3103 | |
| 3104 | /* Do we want to advertise 10 Mb Half Duplex? */ |
| 3105 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
| 3106 | DEBUGOUT("Advertise 10mb Half duplex\n"); |
| 3107 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 3108 | } |
| 3109 | |
| 3110 | /* Do we want to advertise 10 Mb Full Duplex? */ |
| 3111 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
| 3112 | DEBUGOUT("Advertise 10mb Full duplex\n"); |
| 3113 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 3114 | } |
| 3115 | |
| 3116 | /* Do we want to advertise 100 Mb Half Duplex? */ |
| 3117 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
| 3118 | DEBUGOUT("Advertise 100mb Half duplex\n"); |
| 3119 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 3120 | } |
| 3121 | |
| 3122 | /* Do we want to advertise 100 Mb Full Duplex? */ |
| 3123 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
| 3124 | DEBUGOUT("Advertise 100mb Full duplex\n"); |
| 3125 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 3126 | } |
| 3127 | |
| 3128 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
| 3129 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
| 3130 | DEBUGOUT |
| 3131 | ("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 3132 | } |
| 3133 | |
| 3134 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
| 3135 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
| 3136 | DEBUGOUT("Advertise 1000mb Full duplex\n"); |
| 3137 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 3138 | } |
| 3139 | |
| 3140 | /* Check for a software override of the flow control settings, and |
| 3141 | * setup the PHY advertisement registers accordingly. If |
| 3142 | * auto-negotiation is enabled, then software will have to set the |
| 3143 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 3144 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 3145 | * |
| 3146 | * The possible values of the "fc" parameter are: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3147 | * 0: Flow control is completely disabled |
| 3148 | * 1: Rx flow control is enabled (we can receive pause frames |
| 3149 | * but not send pause frames). |
| 3150 | * 2: Tx flow control is enabled (we can send pause frames |
| 3151 | * but we do not support receiving pause frames). |
| 3152 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3153 | * other: No software override. The flow control configuration |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3154 | * in the EEPROM is used. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3155 | */ |
| 3156 | switch (hw->fc) { |
| 3157 | case e1000_fc_none: /* 0 */ |
| 3158 | /* Flow control (RX & TX) is completely disabled by a |
| 3159 | * software over-ride. |
| 3160 | */ |
| 3161 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 3162 | break; |
| 3163 | case e1000_fc_rx_pause: /* 1 */ |
| 3164 | /* RX Flow control is enabled, and TX Flow control is |
| 3165 | * disabled, by a software over-ride. |
| 3166 | */ |
| 3167 | /* Since there really isn't a way to advertise that we are |
| 3168 | * capable of RX Pause ONLY, we will advertise that we |
| 3169 | * support both symmetric and asymmetric RX PAUSE. Later |
| 3170 | * (in e1000_config_fc_after_link_up) we will disable the |
| 3171 | *hw's ability to send PAUSE frames. |
| 3172 | */ |
| 3173 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 3174 | break; |
| 3175 | case e1000_fc_tx_pause: /* 2 */ |
| 3176 | /* TX Flow control is enabled, and RX Flow control is |
| 3177 | * disabled, by a software over-ride. |
| 3178 | */ |
| 3179 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 3180 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 3181 | break; |
| 3182 | case e1000_fc_full: /* 3 */ |
| 3183 | /* Flow control (both RX and TX) is enabled by a software |
| 3184 | * over-ride. |
| 3185 | */ |
| 3186 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 3187 | break; |
| 3188 | default: |
| 3189 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 3190 | return -E1000_ERR_CONFIG; |
| 3191 | } |
| 3192 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3193 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
| 3194 | if (ret_val) |
| 3195 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3196 | |
| 3197 | DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
| 3198 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3199 | if (hw->phy_type != e1000_phy_ife) { |
| 3200 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
| 3201 | mii_1000t_ctrl_reg); |
| 3202 | if (ret_val) |
| 3203 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3204 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3205 | |
| 3206 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /****************************************************************************** |
| 3210 | * Sets the collision distance in the Transmit Control register |
| 3211 | * |
| 3212 | * hw - Struct containing variables accessed by shared code |
| 3213 | * |
| 3214 | * Link should have been established previously. Reads the speed and duplex |
| 3215 | * information from the Device Status register. |
| 3216 | ******************************************************************************/ |
| 3217 | static void |
| 3218 | e1000_config_collision_dist(struct e1000_hw *hw) |
| 3219 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3220 | uint32_t tctl, coll_dist; |
| 3221 | |
| 3222 | DEBUGFUNC(); |
| 3223 | |
| 3224 | if (hw->mac_type < e1000_82543) |
| 3225 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 3226 | else |
| 3227 | coll_dist = E1000_COLLISION_DISTANCE; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3228 | |
| 3229 | tctl = E1000_READ_REG(hw, TCTL); |
| 3230 | |
| 3231 | tctl &= ~E1000_TCTL_COLD; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3232 | tctl |= coll_dist << E1000_COLD_SHIFT; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3233 | |
| 3234 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 3235 | E1000_WRITE_FLUSH(hw); |
| 3236 | } |
| 3237 | |
| 3238 | /****************************************************************************** |
| 3239 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 3240 | * |
| 3241 | * hw - Struct containing variables accessed by shared code |
| 3242 | * mii_reg - data to write to the MII control register |
| 3243 | * |
| 3244 | * The contents of the PHY register containing the needed information need to |
| 3245 | * be passed in. |
| 3246 | ******************************************************************************/ |
| 3247 | static int |
| 3248 | e1000_config_mac_to_phy(struct e1000_hw *hw) |
| 3249 | { |
| 3250 | uint32_t ctrl; |
| 3251 | uint16_t phy_data; |
| 3252 | |
| 3253 | DEBUGFUNC(); |
| 3254 | |
| 3255 | /* Read the Device Control Register and set the bits to Force Speed |
| 3256 | * and Duplex. |
| 3257 | */ |
| 3258 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3259 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 3260 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
| 3261 | |
| 3262 | /* Set up duplex in the Device Control and Transmit Control |
| 3263 | * registers depending on negotiated values. |
| 3264 | */ |
| 3265 | if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) { |
| 3266 | DEBUGOUT("PHY Read Error\n"); |
| 3267 | return -E1000_ERR_PHY; |
| 3268 | } |
| 3269 | if (phy_data & M88E1000_PSSR_DPLX) |
| 3270 | ctrl |= E1000_CTRL_FD; |
| 3271 | else |
| 3272 | ctrl &= ~E1000_CTRL_FD; |
| 3273 | |
| 3274 | e1000_config_collision_dist(hw); |
| 3275 | |
| 3276 | /* Set up speed in the Device Control register depending on |
| 3277 | * negotiated values. |
| 3278 | */ |
| 3279 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
| 3280 | ctrl |= E1000_CTRL_SPD_1000; |
| 3281 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) |
| 3282 | ctrl |= E1000_CTRL_SPD_100; |
| 3283 | /* Write the configured values back to the Device Control Reg. */ |
| 3284 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3285 | return 0; |
| 3286 | } |
| 3287 | |
| 3288 | /****************************************************************************** |
| 3289 | * Forces the MAC's flow control settings. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3290 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3291 | * hw - Struct containing variables accessed by shared code |
| 3292 | * |
| 3293 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 3294 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 3295 | * software when a Copper PHY is used because autonegotiation is managed |
| 3296 | * by the PHY rather than the MAC. Software must also configure these |
| 3297 | * bits when link is forced on a fiber connection. |
| 3298 | *****************************************************************************/ |
| 3299 | static int |
| 3300 | e1000_force_mac_fc(struct e1000_hw *hw) |
| 3301 | { |
| 3302 | uint32_t ctrl; |
| 3303 | |
| 3304 | DEBUGFUNC(); |
| 3305 | |
| 3306 | /* Get the current configuration of the Device Control Register */ |
| 3307 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3308 | |
| 3309 | /* Because we didn't get link via the internal auto-negotiation |
| 3310 | * mechanism (we either forced link or we got link via PHY |
| 3311 | * auto-neg), we have to manually enable/disable transmit an |
| 3312 | * receive flow control. |
| 3313 | * |
| 3314 | * The "Case" statement below enables/disable flow control |
| 3315 | * according to the "hw->fc" parameter. |
| 3316 | * |
| 3317 | * The possible values of the "fc" parameter are: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3318 | * 0: Flow control is completely disabled |
| 3319 | * 1: Rx flow control is enabled (we can receive pause |
| 3320 | * frames but not send pause frames). |
| 3321 | * 2: Tx flow control is enabled (we can send pause frames |
| 3322 | * frames but we do not receive pause frames). |
| 3323 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3324 | * other: No other values should be possible at this point. |
| 3325 | */ |
| 3326 | |
| 3327 | switch (hw->fc) { |
| 3328 | case e1000_fc_none: |
| 3329 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 3330 | break; |
| 3331 | case e1000_fc_rx_pause: |
| 3332 | ctrl &= (~E1000_CTRL_TFCE); |
| 3333 | ctrl |= E1000_CTRL_RFCE; |
| 3334 | break; |
| 3335 | case e1000_fc_tx_pause: |
| 3336 | ctrl &= (~E1000_CTRL_RFCE); |
| 3337 | ctrl |= E1000_CTRL_TFCE; |
| 3338 | break; |
| 3339 | case e1000_fc_full: |
| 3340 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 3341 | break; |
| 3342 | default: |
| 3343 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 3344 | return -E1000_ERR_CONFIG; |
| 3345 | } |
| 3346 | |
| 3347 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
| 3348 | if (hw->mac_type == e1000_82542_rev2_0) |
| 3349 | ctrl &= (~E1000_CTRL_TFCE); |
| 3350 | |
| 3351 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3352 | return 0; |
| 3353 | } |
| 3354 | |
| 3355 | /****************************************************************************** |
| 3356 | * Configures flow control settings after link is established |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3357 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3358 | * hw - Struct containing variables accessed by shared code |
| 3359 | * |
| 3360 | * Should be called immediately after a valid link has been established. |
| 3361 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 3362 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 3363 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
| 3364 | * and RFCE bits will be automaticaly set to the negotiated flow control mode. |
| 3365 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3366 | static int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3367 | e1000_config_fc_after_link_up(struct e1000_hw *hw) |
| 3368 | { |
| 3369 | int32_t ret_val; |
| 3370 | uint16_t mii_status_reg; |
| 3371 | uint16_t mii_nway_adv_reg; |
| 3372 | uint16_t mii_nway_lp_ability_reg; |
| 3373 | uint16_t speed; |
| 3374 | uint16_t duplex; |
| 3375 | |
| 3376 | DEBUGFUNC(); |
| 3377 | |
| 3378 | /* Check for the case where we have fiber media and auto-neg failed |
| 3379 | * so we had to force link. In this case, we need to force the |
| 3380 | * configuration of the MAC to match the "fc" parameter. |
| 3381 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3382 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) |
| 3383 | || ((hw->media_type == e1000_media_type_internal_serdes) |
| 3384 | && (hw->autoneg_failed)) |
| 3385 | || ((hw->media_type == e1000_media_type_copper) |
| 3386 | && (!hw->autoneg))) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3387 | ret_val = e1000_force_mac_fc(hw); |
| 3388 | if (ret_val < 0) { |
| 3389 | DEBUGOUT("Error forcing flow control settings\n"); |
| 3390 | return ret_val; |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /* Check for the case where we have copper media and auto-neg is |
| 3395 | * enabled. In this case, we need to check and see if Auto-Neg |
| 3396 | * has completed, and if so, how the PHY and link partner has |
| 3397 | * flow control configured. |
| 3398 | */ |
| 3399 | if (hw->media_type == e1000_media_type_copper) { |
| 3400 | /* Read the MII Status Register and check to see if AutoNeg |
| 3401 | * has completed. We read this twice because this reg has |
| 3402 | * some "sticky" (latched) bits. |
| 3403 | */ |
| 3404 | if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) { |
| 3405 | DEBUGOUT("PHY Read Error \n"); |
| 3406 | return -E1000_ERR_PHY; |
| 3407 | } |
| 3408 | if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) { |
| 3409 | DEBUGOUT("PHY Read Error \n"); |
| 3410 | return -E1000_ERR_PHY; |
| 3411 | } |
| 3412 | |
| 3413 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
| 3414 | /* The AutoNeg process has completed, so we now need to |
| 3415 | * read both the Auto Negotiation Advertisement Register |
| 3416 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 3417 | * Register (Address 5) to determine how flow control was |
| 3418 | * negotiated. |
| 3419 | */ |
| 3420 | if (e1000_read_phy_reg |
| 3421 | (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) { |
| 3422 | DEBUGOUT("PHY Read Error\n"); |
| 3423 | return -E1000_ERR_PHY; |
| 3424 | } |
| 3425 | if (e1000_read_phy_reg |
| 3426 | (hw, PHY_LP_ABILITY, |
| 3427 | &mii_nway_lp_ability_reg) < 0) { |
| 3428 | DEBUGOUT("PHY Read Error\n"); |
| 3429 | return -E1000_ERR_PHY; |
| 3430 | } |
| 3431 | |
| 3432 | /* Two bits in the Auto Negotiation Advertisement Register |
| 3433 | * (Address 4) and two bits in the Auto Negotiation Base |
| 3434 | * Page Ability Register (Address 5) determine flow control |
| 3435 | * for both the PHY and the link partner. The following |
| 3436 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 3437 | * 1999, describes these PAUSE resolution bits and how flow |
| 3438 | * control is determined based upon these settings. |
| 3439 | * NOTE: DC = Don't Care |
| 3440 | * |
| 3441 | * LOCAL DEVICE | LINK PARTNER |
| 3442 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 3443 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3444 | * 0 | 0 | DC | DC | e1000_fc_none |
| 3445 | * 0 | 1 | 0 | DC | e1000_fc_none |
| 3446 | * 0 | 1 | 1 | 0 | e1000_fc_none |
| 3447 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause |
| 3448 | * 1 | 0 | 0 | DC | e1000_fc_none |
| 3449 | * 1 | DC | 1 | DC | e1000_fc_full |
| 3450 | * 1 | 1 | 0 | 0 | e1000_fc_none |
| 3451 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3452 | * |
| 3453 | */ |
| 3454 | /* Are both PAUSE bits set to 1? If so, this implies |
| 3455 | * Symmetric Flow Control is enabled at both ends. The |
| 3456 | * ASM_DIR bits are irrelevant per the spec. |
| 3457 | * |
| 3458 | * For Symmetric Flow Control: |
| 3459 | * |
| 3460 | * LOCAL DEVICE | LINK PARTNER |
| 3461 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 3462 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3463 | * 1 | DC | 1 | DC | e1000_fc_full |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3464 | * |
| 3465 | */ |
| 3466 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 3467 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
| 3468 | /* Now we need to check if the user selected RX ONLY |
| 3469 | * of pause frames. In this case, we had to advertise |
| 3470 | * FULL flow control because we could not advertise RX |
| 3471 | * ONLY. Hence, we must now check to see if we need to |
| 3472 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 3473 | */ |
| 3474 | if (hw->original_fc == e1000_fc_full) { |
| 3475 | hw->fc = e1000_fc_full; |
| 3476 | DEBUGOUT("Flow Control = FULL.\r\n"); |
| 3477 | } else { |
| 3478 | hw->fc = e1000_fc_rx_pause; |
| 3479 | DEBUGOUT |
| 3480 | ("Flow Control = RX PAUSE frames only.\r\n"); |
| 3481 | } |
| 3482 | } |
| 3483 | /* For receiving PAUSE frames ONLY. |
| 3484 | * |
| 3485 | * LOCAL DEVICE | LINK PARTNER |
| 3486 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 3487 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3488 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3489 | * |
| 3490 | */ |
| 3491 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 3492 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 3493 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 3494 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 3495 | { |
| 3496 | hw->fc = e1000_fc_tx_pause; |
| 3497 | DEBUGOUT |
| 3498 | ("Flow Control = TX PAUSE frames only.\r\n"); |
| 3499 | } |
| 3500 | /* For transmitting PAUSE frames ONLY. |
| 3501 | * |
| 3502 | * LOCAL DEVICE | LINK PARTNER |
| 3503 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 3504 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3505 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3506 | * |
| 3507 | */ |
| 3508 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 3509 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 3510 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 3511 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 3512 | { |
| 3513 | hw->fc = e1000_fc_rx_pause; |
| 3514 | DEBUGOUT |
| 3515 | ("Flow Control = RX PAUSE frames only.\r\n"); |
| 3516 | } |
| 3517 | /* Per the IEEE spec, at this point flow control should be |
| 3518 | * disabled. However, we want to consider that we could |
| 3519 | * be connected to a legacy switch that doesn't advertise |
| 3520 | * desired flow control, but can be forced on the link |
| 3521 | * partner. So if we advertised no flow control, that is |
| 3522 | * what we will resolve to. If we advertised some kind of |
| 3523 | * receive capability (Rx Pause Only or Full Flow Control) |
| 3524 | * and the link partner advertised none, we will configure |
| 3525 | * ourselves to enable Rx Flow Control only. We can do |
| 3526 | * this safely for two reasons: If the link partner really |
| 3527 | * didn't want flow control enabled, and we enable Rx, no |
| 3528 | * harm done since we won't be receiving any PAUSE frames |
| 3529 | * anyway. If the intent on the link partner was to have |
| 3530 | * flow control enabled, then by us enabling RX only, we |
| 3531 | * can at least receive pause frames and process them. |
| 3532 | * This is a good idea because in most cases, since we are |
| 3533 | * predominantly a server NIC, more times than not we will |
| 3534 | * be asked to delay transmission of packets than asking |
| 3535 | * our link partner to pause transmission of frames. |
| 3536 | */ |
| 3537 | else if (hw->original_fc == e1000_fc_none || |
| 3538 | hw->original_fc == e1000_fc_tx_pause) { |
| 3539 | hw->fc = e1000_fc_none; |
| 3540 | DEBUGOUT("Flow Control = NONE.\r\n"); |
| 3541 | } else { |
| 3542 | hw->fc = e1000_fc_rx_pause; |
| 3543 | DEBUGOUT |
| 3544 | ("Flow Control = RX PAUSE frames only.\r\n"); |
| 3545 | } |
| 3546 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3547 | /* Now we need to do one last check... If we auto- |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3548 | * negotiated to HALF DUPLEX, flow control should not be |
| 3549 | * enabled per IEEE 802.3 spec. |
| 3550 | */ |
| 3551 | e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 3552 | |
| 3553 | if (duplex == HALF_DUPLEX) |
| 3554 | hw->fc = e1000_fc_none; |
| 3555 | |
| 3556 | /* Now we call a subroutine to actually force the MAC |
| 3557 | * controller to use the correct flow control settings. |
| 3558 | */ |
| 3559 | ret_val = e1000_force_mac_fc(hw); |
| 3560 | if (ret_val < 0) { |
| 3561 | DEBUGOUT |
| 3562 | ("Error forcing flow control settings\n"); |
| 3563 | return ret_val; |
| 3564 | } |
| 3565 | } else { |
| 3566 | DEBUGOUT |
| 3567 | ("Copper PHY and Auto Neg has not completed.\r\n"); |
| 3568 | } |
| 3569 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3570 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | /****************************************************************************** |
| 3574 | * Checks to see if the link status of the hardware has changed. |
| 3575 | * |
| 3576 | * hw - Struct containing variables accessed by shared code |
| 3577 | * |
| 3578 | * Called by any function that needs to check the link status of the adapter. |
| 3579 | *****************************************************************************/ |
| 3580 | static int |
| 3581 | e1000_check_for_link(struct eth_device *nic) |
| 3582 | { |
| 3583 | struct e1000_hw *hw = nic->priv; |
| 3584 | uint32_t rxcw; |
| 3585 | uint32_t ctrl; |
| 3586 | uint32_t status; |
| 3587 | uint32_t rctl; |
| 3588 | uint32_t signal; |
| 3589 | int32_t ret_val; |
| 3590 | uint16_t phy_data; |
| 3591 | uint16_t lp_capability; |
| 3592 | |
| 3593 | DEBUGFUNC(); |
| 3594 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3595 | /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be |
| 3596 | * set when the optics detect a signal. On older adapters, it will be |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3597 | * cleared when there is a signal |
| 3598 | */ |
| 3599 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3600 | if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS)) |
| 3601 | signal = E1000_CTRL_SWDPIN1; |
| 3602 | else |
| 3603 | signal = 0; |
| 3604 | |
| 3605 | status = E1000_READ_REG(hw, STATUS); |
| 3606 | rxcw = E1000_READ_REG(hw, RXCW); |
| 3607 | DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw); |
| 3608 | |
| 3609 | /* If we have a copper PHY then we only want to go out to the PHY |
| 3610 | * registers to see if Auto-Neg has completed and/or if our link |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3611 | * status has changed. The get_link_status flag will be set if we |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3612 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 3613 | * Errors. |
| 3614 | */ |
| 3615 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
| 3616 | /* First we want to see if the MII Status Register reports |
| 3617 | * link. If so, then we want to get the current speed/duplex |
| 3618 | * of the PHY. |
| 3619 | * Read the register twice since the link bit is sticky. |
| 3620 | */ |
| 3621 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 3622 | DEBUGOUT("PHY Read Error\n"); |
| 3623 | return -E1000_ERR_PHY; |
| 3624 | } |
| 3625 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 3626 | DEBUGOUT("PHY Read Error\n"); |
| 3627 | return -E1000_ERR_PHY; |
| 3628 | } |
| 3629 | |
| 3630 | if (phy_data & MII_SR_LINK_STATUS) { |
| 3631 | hw->get_link_status = FALSE; |
| 3632 | } else { |
| 3633 | /* No link detected */ |
| 3634 | return -E1000_ERR_NOLINK; |
| 3635 | } |
| 3636 | |
| 3637 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 3638 | * have Si on board that is 82544 or newer, Auto |
| 3639 | * Speed Detection takes care of MAC speed/duplex |
| 3640 | * configuration. So we only need to configure Collision |
| 3641 | * Distance in the MAC. Otherwise, we need to force |
| 3642 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 3643 | * settings. |
| 3644 | */ |
| 3645 | if (hw->mac_type >= e1000_82544) |
| 3646 | e1000_config_collision_dist(hw); |
| 3647 | else { |
| 3648 | ret_val = e1000_config_mac_to_phy(hw); |
| 3649 | if (ret_val < 0) { |
| 3650 | DEBUGOUT |
| 3651 | ("Error configuring MAC to PHY settings\n"); |
| 3652 | return ret_val; |
| 3653 | } |
| 3654 | } |
| 3655 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3656 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3657 | * need to restore the desired flow control settings because we may |
| 3658 | * have had to re-autoneg with a different link partner. |
| 3659 | */ |
| 3660 | ret_val = e1000_config_fc_after_link_up(hw); |
| 3661 | if (ret_val < 0) { |
| 3662 | DEBUGOUT("Error configuring flow control\n"); |
| 3663 | return ret_val; |
| 3664 | } |
| 3665 | |
| 3666 | /* At this point we know that we are on copper and we have |
| 3667 | * auto-negotiated link. These are conditions for checking the link |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3668 | * parter capability register. We use the link partner capability to |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3669 | * determine if TBI Compatibility needs to be turned on or off. If |
| 3670 | * the link partner advertises any speed in addition to Gigabit, then |
| 3671 | * we assume that they are GMII-based, and TBI compatibility is not |
| 3672 | * needed. If no other speeds are advertised, we assume the link |
| 3673 | * partner is TBI-based, and we turn on TBI Compatibility. |
| 3674 | */ |
| 3675 | if (hw->tbi_compatibility_en) { |
| 3676 | if (e1000_read_phy_reg |
| 3677 | (hw, PHY_LP_ABILITY, &lp_capability) < 0) { |
| 3678 | DEBUGOUT("PHY Read Error\n"); |
| 3679 | return -E1000_ERR_PHY; |
| 3680 | } |
| 3681 | if (lp_capability & (NWAY_LPAR_10T_HD_CAPS | |
| 3682 | NWAY_LPAR_10T_FD_CAPS | |
| 3683 | NWAY_LPAR_100TX_HD_CAPS | |
| 3684 | NWAY_LPAR_100TX_FD_CAPS | |
| 3685 | NWAY_LPAR_100T4_CAPS)) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3686 | /* If our link partner advertises anything in addition to |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3687 | * gigabit, we do not need to enable TBI compatibility. |
| 3688 | */ |
| 3689 | if (hw->tbi_compatibility_on) { |
| 3690 | /* If we previously were in the mode, turn it off. */ |
| 3691 | rctl = E1000_READ_REG(hw, RCTL); |
| 3692 | rctl &= ~E1000_RCTL_SBP; |
| 3693 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 3694 | hw->tbi_compatibility_on = FALSE; |
| 3695 | } |
| 3696 | } else { |
| 3697 | /* If TBI compatibility is was previously off, turn it on. For |
| 3698 | * compatibility with a TBI link partner, we will store bad |
| 3699 | * packets. Some frames have an additional byte on the end and |
| 3700 | * will look like CRC errors to to the hardware. |
| 3701 | */ |
| 3702 | if (!hw->tbi_compatibility_on) { |
| 3703 | hw->tbi_compatibility_on = TRUE; |
| 3704 | rctl = E1000_READ_REG(hw, RCTL); |
| 3705 | rctl |= E1000_RCTL_SBP; |
| 3706 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | /* If we don't have link (auto-negotiation failed or link partner cannot |
| 3712 | * auto-negotiate), the cable is plugged in (we have signal), and our |
| 3713 | * link partner is not trying to auto-negotiate with us (we are receiving |
| 3714 | * idles or data), we need to force link up. We also need to give |
| 3715 | * auto-negotiation time to complete, in case the cable was just plugged |
| 3716 | * in. The autoneg_failed flag does this. |
| 3717 | */ |
| 3718 | else if ((hw->media_type == e1000_media_type_fiber) && |
| 3719 | (!(status & E1000_STATUS_LU)) && |
| 3720 | ((ctrl & E1000_CTRL_SWDPIN1) == signal) && |
| 3721 | (!(rxcw & E1000_RXCW_C))) { |
| 3722 | if (hw->autoneg_failed == 0) { |
| 3723 | hw->autoneg_failed = 1; |
| 3724 | return 0; |
| 3725 | } |
| 3726 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n"); |
| 3727 | |
| 3728 | /* Disable auto-negotiation in the TXCW register */ |
| 3729 | E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
| 3730 | |
| 3731 | /* Force link-up and also force full-duplex. */ |
| 3732 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3733 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
| 3734 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3735 | |
| 3736 | /* Configure Flow Control after forcing link up. */ |
| 3737 | ret_val = e1000_config_fc_after_link_up(hw); |
| 3738 | if (ret_val < 0) { |
| 3739 | DEBUGOUT("Error configuring flow control\n"); |
| 3740 | return ret_val; |
| 3741 | } |
| 3742 | } |
| 3743 | /* If we are forcing link and we are receiving /C/ ordered sets, re-enable |
| 3744 | * auto-negotiation in the TXCW register and disable forced link in the |
| 3745 | * Device Control register in an attempt to auto-negotiate with our link |
| 3746 | * partner. |
| 3747 | */ |
| 3748 | else if ((hw->media_type == e1000_media_type_fiber) && |
| 3749 | (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
| 3750 | DEBUGOUT |
| 3751 | ("RXing /C/, enable AutoNeg and stop forcing link.\r\n"); |
| 3752 | E1000_WRITE_REG(hw, TXCW, hw->txcw); |
| 3753 | E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU)); |
| 3754 | } |
| 3755 | return 0; |
| 3756 | } |
| 3757 | |
| 3758 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3759 | * Configure the MAC-to-PHY interface for 10/100Mbps |
| 3760 | * |
| 3761 | * hw - Struct containing variables accessed by shared code |
| 3762 | ******************************************************************************/ |
| 3763 | static int32_t |
| 3764 | e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex) |
| 3765 | { |
| 3766 | int32_t ret_val = E1000_SUCCESS; |
| 3767 | uint32_t tipg; |
| 3768 | uint16_t reg_data; |
| 3769 | |
| 3770 | DEBUGFUNC(); |
| 3771 | |
| 3772 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT; |
| 3773 | ret_val = e1000_write_kmrn_reg(hw, |
| 3774 | E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data); |
| 3775 | if (ret_val) |
| 3776 | return ret_val; |
| 3777 | |
| 3778 | /* Configure Transmit Inter-Packet Gap */ |
| 3779 | tipg = E1000_READ_REG(hw, TIPG); |
| 3780 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 3781 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100; |
| 3782 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 3783 | |
| 3784 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 3785 | |
| 3786 | if (ret_val) |
| 3787 | return ret_val; |
| 3788 | |
| 3789 | if (duplex == HALF_DUPLEX) |
| 3790 | reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER; |
| 3791 | else |
| 3792 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 3793 | |
| 3794 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 3795 | |
| 3796 | return ret_val; |
| 3797 | } |
| 3798 | |
| 3799 | static int32_t |
| 3800 | e1000_configure_kmrn_for_1000(struct e1000_hw *hw) |
| 3801 | { |
| 3802 | int32_t ret_val = E1000_SUCCESS; |
| 3803 | uint16_t reg_data; |
| 3804 | uint32_t tipg; |
| 3805 | |
| 3806 | DEBUGFUNC(); |
| 3807 | |
| 3808 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT; |
| 3809 | ret_val = e1000_write_kmrn_reg(hw, |
| 3810 | E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data); |
| 3811 | if (ret_val) |
| 3812 | return ret_val; |
| 3813 | |
| 3814 | /* Configure Transmit Inter-Packet Gap */ |
| 3815 | tipg = E1000_READ_REG(hw, TIPG); |
| 3816 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 3817 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 3818 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 3819 | |
| 3820 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 3821 | |
| 3822 | if (ret_val) |
| 3823 | return ret_val; |
| 3824 | |
| 3825 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 3826 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 3827 | |
| 3828 | return ret_val; |
| 3829 | } |
| 3830 | |
| 3831 | /****************************************************************************** |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3832 | * Detects the current speed and duplex settings of the hardware. |
| 3833 | * |
| 3834 | * hw - Struct containing variables accessed by shared code |
| 3835 | * speed - Speed of the connection |
| 3836 | * duplex - Duplex setting of the connection |
| 3837 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3838 | static int |
| 3839 | e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed, |
| 3840 | uint16_t *duplex) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3841 | { |
| 3842 | uint32_t status; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3843 | int32_t ret_val; |
| 3844 | uint16_t phy_data; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3845 | |
| 3846 | DEBUGFUNC(); |
| 3847 | |
| 3848 | if (hw->mac_type >= e1000_82543) { |
| 3849 | status = E1000_READ_REG(hw, STATUS); |
| 3850 | if (status & E1000_STATUS_SPEED_1000) { |
| 3851 | *speed = SPEED_1000; |
| 3852 | DEBUGOUT("1000 Mbs, "); |
| 3853 | } else if (status & E1000_STATUS_SPEED_100) { |
| 3854 | *speed = SPEED_100; |
| 3855 | DEBUGOUT("100 Mbs, "); |
| 3856 | } else { |
| 3857 | *speed = SPEED_10; |
| 3858 | DEBUGOUT("10 Mbs, "); |
| 3859 | } |
| 3860 | |
| 3861 | if (status & E1000_STATUS_FD) { |
| 3862 | *duplex = FULL_DUPLEX; |
| 3863 | DEBUGOUT("Full Duplex\r\n"); |
| 3864 | } else { |
| 3865 | *duplex = HALF_DUPLEX; |
| 3866 | DEBUGOUT(" Half Duplex\r\n"); |
| 3867 | } |
| 3868 | } else { |
| 3869 | DEBUGOUT("1000 Mbs, Full Duplex\r\n"); |
| 3870 | *speed = SPEED_1000; |
| 3871 | *duplex = FULL_DUPLEX; |
| 3872 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3873 | |
| 3874 | /* IGP01 PHY may advertise full duplex operation after speed downgrade |
| 3875 | * even if it is operating at half duplex. Here we set the duplex |
| 3876 | * settings to match the duplex in the link partner's capabilities. |
| 3877 | */ |
| 3878 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
| 3879 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
| 3880 | if (ret_val) |
| 3881 | return ret_val; |
| 3882 | |
| 3883 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
| 3884 | *duplex = HALF_DUPLEX; |
| 3885 | else { |
| 3886 | ret_val = e1000_read_phy_reg(hw, |
| 3887 | PHY_LP_ABILITY, &phy_data); |
| 3888 | if (ret_val) |
| 3889 | return ret_val; |
| 3890 | if ((*speed == SPEED_100 && |
| 3891 | !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) |
| 3892 | || (*speed == SPEED_10 |
| 3893 | && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 3894 | *duplex = HALF_DUPLEX; |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3899 | (hw->media_type == e1000_media_type_copper)) { |
| 3900 | if (*speed == SPEED_1000) |
| 3901 | ret_val = e1000_configure_kmrn_for_1000(hw); |
| 3902 | else |
| 3903 | ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex); |
| 3904 | if (ret_val) |
| 3905 | return ret_val; |
| 3906 | } |
| 3907 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | /****************************************************************************** |
| 3911 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 3912 | * |
| 3913 | * hw - Struct containing variables accessed by shared code |
| 3914 | ******************************************************************************/ |
| 3915 | static int |
| 3916 | e1000_wait_autoneg(struct e1000_hw *hw) |
| 3917 | { |
| 3918 | uint16_t i; |
| 3919 | uint16_t phy_data; |
| 3920 | |
| 3921 | DEBUGFUNC(); |
| 3922 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); |
| 3923 | |
| 3924 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
| 3925 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
| 3926 | /* Read the MII Status Register and wait for Auto-Neg |
| 3927 | * Complete bit to be set. |
| 3928 | */ |
| 3929 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 3930 | DEBUGOUT("PHY Read Error\n"); |
| 3931 | return -E1000_ERR_PHY; |
| 3932 | } |
| 3933 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 3934 | DEBUGOUT("PHY Read Error\n"); |
| 3935 | return -E1000_ERR_PHY; |
| 3936 | } |
| 3937 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
| 3938 | DEBUGOUT("Auto-Neg complete.\n"); |
| 3939 | return 0; |
| 3940 | } |
| 3941 | mdelay(100); |
| 3942 | } |
| 3943 | DEBUGOUT("Auto-Neg timedout.\n"); |
| 3944 | return -E1000_ERR_TIMEOUT; |
| 3945 | } |
| 3946 | |
| 3947 | /****************************************************************************** |
| 3948 | * Raises the Management Data Clock |
| 3949 | * |
| 3950 | * hw - Struct containing variables accessed by shared code |
| 3951 | * ctrl - Device control register's current value |
| 3952 | ******************************************************************************/ |
| 3953 | static void |
| 3954 | e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl) |
| 3955 | { |
| 3956 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 3957 | * bit), and then delay 2 microseconds. |
| 3958 | */ |
| 3959 | E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 3960 | E1000_WRITE_FLUSH(hw); |
| 3961 | udelay(2); |
| 3962 | } |
| 3963 | |
| 3964 | /****************************************************************************** |
| 3965 | * Lowers the Management Data Clock |
| 3966 | * |
| 3967 | * hw - Struct containing variables accessed by shared code |
| 3968 | * ctrl - Device control register's current value |
| 3969 | ******************************************************************************/ |
| 3970 | static void |
| 3971 | e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl) |
| 3972 | { |
| 3973 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 3974 | * bit), and then delay 2 microseconds. |
| 3975 | */ |
| 3976 | E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 3977 | E1000_WRITE_FLUSH(hw); |
| 3978 | udelay(2); |
| 3979 | } |
| 3980 | |
| 3981 | /****************************************************************************** |
| 3982 | * Shifts data bits out to the PHY |
| 3983 | * |
| 3984 | * hw - Struct containing variables accessed by shared code |
| 3985 | * data - Data to send out to the PHY |
| 3986 | * count - Number of bits to shift out |
| 3987 | * |
| 3988 | * Bits are shifted out in MSB to LSB order. |
| 3989 | ******************************************************************************/ |
| 3990 | static void |
| 3991 | e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count) |
| 3992 | { |
| 3993 | uint32_t ctrl; |
| 3994 | uint32_t mask; |
| 3995 | |
| 3996 | /* We need to shift "count" number of bits out to the PHY. So, the value |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3997 | * in the "data" parameter will be shifted out to the PHY one bit at a |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3998 | * time. In order to do this, "data" must be broken down into bits. |
| 3999 | */ |
| 4000 | mask = 0x01; |
| 4001 | mask <<= (count - 1); |
| 4002 | |
| 4003 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4004 | |
| 4005 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 4006 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
| 4007 | |
| 4008 | while (mask) { |
| 4009 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 4010 | * then raising and lowering the Management Data Clock. A "0" is |
| 4011 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 4012 | * raising and lowering the clock. |
| 4013 | */ |
| 4014 | if (data & mask) |
| 4015 | ctrl |= E1000_CTRL_MDIO; |
| 4016 | else |
| 4017 | ctrl &= ~E1000_CTRL_MDIO; |
| 4018 | |
| 4019 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4020 | E1000_WRITE_FLUSH(hw); |
| 4021 | |
| 4022 | udelay(2); |
| 4023 | |
| 4024 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4025 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4026 | |
| 4027 | mask = mask >> 1; |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | /****************************************************************************** |
| 4032 | * Shifts data bits in from the PHY |
| 4033 | * |
| 4034 | * hw - Struct containing variables accessed by shared code |
| 4035 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4036 | * Bits are shifted in in MSB to LSB order. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4037 | ******************************************************************************/ |
| 4038 | static uint16_t |
| 4039 | e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
| 4040 | { |
| 4041 | uint32_t ctrl; |
| 4042 | uint16_t data = 0; |
| 4043 | uint8_t i; |
| 4044 | |
| 4045 | /* In order to read a register from the PHY, we need to shift in a total |
| 4046 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 4047 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 4048 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 4049 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 4050 | * and then reading the value of the MDIO bit. |
| 4051 | */ |
| 4052 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4053 | |
| 4054 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 4055 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 4056 | ctrl &= ~E1000_CTRL_MDIO; |
| 4057 | |
| 4058 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4059 | E1000_WRITE_FLUSH(hw); |
| 4060 | |
| 4061 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 4062 | * the turnaround bits. The first clock occurred when we clocked out the |
| 4063 | * last bit of the Register Address. |
| 4064 | */ |
| 4065 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4066 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4067 | |
| 4068 | for (data = 0, i = 0; i < 16; i++) { |
| 4069 | data = data << 1; |
| 4070 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4071 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4072 | /* Check to see if we shifted in a "1". */ |
| 4073 | if (ctrl & E1000_CTRL_MDIO) |
| 4074 | data |= 1; |
| 4075 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4076 | } |
| 4077 | |
| 4078 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4079 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4080 | |
| 4081 | return data; |
| 4082 | } |
| 4083 | |
| 4084 | /***************************************************************************** |
| 4085 | * Reads the value from a PHY register |
| 4086 | * |
| 4087 | * hw - Struct containing variables accessed by shared code |
| 4088 | * reg_addr - address of the PHY register to read |
| 4089 | ******************************************************************************/ |
| 4090 | static int |
| 4091 | e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data) |
| 4092 | { |
| 4093 | uint32_t i; |
| 4094 | uint32_t mdic = 0; |
| 4095 | const uint32_t phy_addr = 1; |
| 4096 | |
| 4097 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
| 4098 | DEBUGOUT("PHY Address %d is out of range\n", reg_addr); |
| 4099 | return -E1000_ERR_PARAM; |
| 4100 | } |
| 4101 | |
| 4102 | if (hw->mac_type > e1000_82543) { |
| 4103 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 4104 | * Control register. The MAC will take care of interfacing with the |
| 4105 | * PHY to retrieve the desired data. |
| 4106 | */ |
| 4107 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 4108 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 4109 | (E1000_MDIC_OP_READ)); |
| 4110 | |
| 4111 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 4112 | |
| 4113 | /* Poll the ready bit to see if the MDI read completed */ |
| 4114 | for (i = 0; i < 64; i++) { |
| 4115 | udelay(10); |
| 4116 | mdic = E1000_READ_REG(hw, MDIC); |
| 4117 | if (mdic & E1000_MDIC_READY) |
| 4118 | break; |
| 4119 | } |
| 4120 | if (!(mdic & E1000_MDIC_READY)) { |
| 4121 | DEBUGOUT("MDI Read did not complete\n"); |
| 4122 | return -E1000_ERR_PHY; |
| 4123 | } |
| 4124 | if (mdic & E1000_MDIC_ERROR) { |
| 4125 | DEBUGOUT("MDI Error\n"); |
| 4126 | return -E1000_ERR_PHY; |
| 4127 | } |
| 4128 | *phy_data = (uint16_t) mdic; |
| 4129 | } else { |
| 4130 | /* We must first send a preamble through the MDIO pin to signal the |
| 4131 | * beginning of an MII instruction. This is done by sending 32 |
| 4132 | * consecutive "1" bits. |
| 4133 | */ |
| 4134 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 4135 | |
| 4136 | /* Now combine the next few fields that are required for a read |
| 4137 | * operation. We use this method instead of calling the |
| 4138 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 4139 | * a MII read instruction consists of a shift out of 14 bits and is |
| 4140 | * defined as follows: |
| 4141 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 4142 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 4143 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 4144 | * READ operation is performed. These two bits are thrown away |
| 4145 | * followed by a shift in of 16 bits which contains the desired data. |
| 4146 | */ |
| 4147 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 4148 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
| 4149 | |
| 4150 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
| 4151 | |
| 4152 | /* Now that we've shifted out the read command to the MII, we need to |
| 4153 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 4154 | * register address. |
| 4155 | */ |
| 4156 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 4157 | } |
| 4158 | return 0; |
| 4159 | } |
| 4160 | |
| 4161 | /****************************************************************************** |
| 4162 | * Writes a value to a PHY register |
| 4163 | * |
| 4164 | * hw - Struct containing variables accessed by shared code |
| 4165 | * reg_addr - address of the PHY register to write |
| 4166 | * data - data to write to the PHY |
| 4167 | ******************************************************************************/ |
| 4168 | static int |
| 4169 | e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data) |
| 4170 | { |
| 4171 | uint32_t i; |
| 4172 | uint32_t mdic = 0; |
| 4173 | const uint32_t phy_addr = 1; |
| 4174 | |
| 4175 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
| 4176 | DEBUGOUT("PHY Address %d is out of range\n", reg_addr); |
| 4177 | return -E1000_ERR_PARAM; |
| 4178 | } |
| 4179 | |
| 4180 | if (hw->mac_type > e1000_82543) { |
| 4181 | /* Set up Op-code, Phy Address, register address, and data intended |
| 4182 | * for the PHY register in the MDI Control register. The MAC will take |
| 4183 | * care of interfacing with the PHY to send the desired data. |
| 4184 | */ |
| 4185 | mdic = (((uint32_t) phy_data) | |
| 4186 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 4187 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 4188 | (E1000_MDIC_OP_WRITE)); |
| 4189 | |
| 4190 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 4191 | |
| 4192 | /* Poll the ready bit to see if the MDI read completed */ |
| 4193 | for (i = 0; i < 64; i++) { |
| 4194 | udelay(10); |
| 4195 | mdic = E1000_READ_REG(hw, MDIC); |
| 4196 | if (mdic & E1000_MDIC_READY) |
| 4197 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4198 | } |
| 4199 | if (!(mdic & E1000_MDIC_READY)) { |
| 4200 | DEBUGOUT("MDI Write did not complete\n"); |
| 4201 | return -E1000_ERR_PHY; |
| 4202 | } |
| 4203 | } else { |
| 4204 | /* We'll need to use the SW defined pins to shift the write command |
| 4205 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 4206 | * beginning of the MII instruction. This is done by sending 32 |
| 4207 | * consecutive "1" bits. |
| 4208 | */ |
| 4209 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 4210 | |
| 4211 | /* Now combine the remaining required fields that will indicate a |
| 4212 | * write operation. We use this method instead of calling the |
| 4213 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 4214 | * format of a MII write instruction is as follows: |
| 4215 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 4216 | */ |
| 4217 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 4218 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 4219 | mdic <<= 16; |
| 4220 | mdic |= (uint32_t) phy_data; |
| 4221 | |
| 4222 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 4223 | } |
| 4224 | return 0; |
| 4225 | } |
| 4226 | |
| 4227 | /****************************************************************************** |
| 4228 | * Checks if PHY reset is blocked due to SOL/IDER session, for example. |
| 4229 | * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to |
| 4230 | * the caller to figure out how to deal with it. |
| 4231 | * |
| 4232 | * hw - Struct containing variables accessed by shared code |
| 4233 | * |
| 4234 | * returns: - E1000_BLK_PHY_RESET |
| 4235 | * E1000_SUCCESS |
| 4236 | * |
| 4237 | *****************************************************************************/ |
| 4238 | int32_t |
| 4239 | e1000_check_phy_reset_block(struct e1000_hw *hw) |
| 4240 | { |
| 4241 | uint32_t manc = 0; |
| 4242 | uint32_t fwsm = 0; |
| 4243 | |
| 4244 | if (hw->mac_type == e1000_ich8lan) { |
| 4245 | fwsm = E1000_READ_REG(hw, FWSM); |
| 4246 | return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS |
| 4247 | : E1000_BLK_PHY_RESET; |
| 4248 | } |
| 4249 | |
| 4250 | if (hw->mac_type > e1000_82547_rev_2) |
| 4251 | manc = E1000_READ_REG(hw, MANC); |
| 4252 | return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? |
| 4253 | E1000_BLK_PHY_RESET : E1000_SUCCESS; |
| 4254 | } |
| 4255 | |
| 4256 | /*************************************************************************** |
| 4257 | * Checks if the PHY configuration is done |
| 4258 | * |
| 4259 | * hw: Struct containing variables accessed by shared code |
| 4260 | * |
| 4261 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 4262 | * E1000_SUCCESS at any other case. |
| 4263 | * |
| 4264 | ***************************************************************************/ |
| 4265 | static int32_t |
| 4266 | e1000_get_phy_cfg_done(struct e1000_hw *hw) |
| 4267 | { |
| 4268 | int32_t timeout = PHY_CFG_TIMEOUT; |
| 4269 | uint32_t cfg_mask = E1000_EEPROM_CFG_DONE; |
| 4270 | |
| 4271 | DEBUGFUNC(); |
| 4272 | |
| 4273 | switch (hw->mac_type) { |
| 4274 | default: |
| 4275 | mdelay(10); |
| 4276 | break; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4277 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4278 | case e1000_80003es2lan: |
| 4279 | /* Separate *_CFG_DONE_* bit for each port */ |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4280 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4281 | cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4282 | /* Fall Through */ |
| 4283 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4284 | case e1000_82571: |
| 4285 | case e1000_82572: |
| 4286 | while (timeout) { |
| 4287 | if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask) |
| 4288 | break; |
| 4289 | else |
| 4290 | mdelay(1); |
| 4291 | timeout--; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4292 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4293 | if (!timeout) { |
| 4294 | DEBUGOUT("MNG configuration cycle has not " |
| 4295 | "completed.\n"); |
| 4296 | return -E1000_ERR_RESET; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4297 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4298 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4299 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4300 | |
| 4301 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | /****************************************************************************** |
| 4305 | * Returns the PHY to the power-on reset state |
| 4306 | * |
| 4307 | * hw - Struct containing variables accessed by shared code |
| 4308 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4309 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4310 | e1000_phy_hw_reset(struct e1000_hw *hw) |
| 4311 | { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4312 | uint16_t swfw = E1000_SWFW_PHY0_SM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4313 | uint32_t ctrl, ctrl_ext; |
| 4314 | uint32_t led_ctrl; |
| 4315 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4316 | |
| 4317 | DEBUGFUNC(); |
| 4318 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4319 | /* In the case of the phy reset being blocked, it's not an error, we |
| 4320 | * simply return success without performing the reset. */ |
| 4321 | ret_val = e1000_check_phy_reset_block(hw); |
| 4322 | if (ret_val) |
| 4323 | return E1000_SUCCESS; |
| 4324 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4325 | DEBUGOUT("Resetting Phy...\n"); |
| 4326 | |
| 4327 | if (hw->mac_type > e1000_82543) { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4328 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4329 | swfw = E1000_SWFW_PHY1_SM; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4330 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4331 | if (e1000_swfw_sync_acquire(hw, swfw)) { |
| 4332 | DEBUGOUT("Unable to acquire swfw sync\n"); |
| 4333 | return -E1000_ERR_SWFW_SYNC; |
| 4334 | } |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4335 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4336 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 4337 | * bit. Then, take it out of reset. |
| 4338 | */ |
| 4339 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4340 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 4341 | E1000_WRITE_FLUSH(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4342 | |
| 4343 | if (hw->mac_type < e1000_82571) |
| 4344 | udelay(10); |
| 4345 | else |
| 4346 | udelay(100); |
| 4347 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4348 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4349 | E1000_WRITE_FLUSH(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4350 | |
| 4351 | if (hw->mac_type >= e1000_82571) |
| 4352 | mdelay(10); |
| 4353 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4354 | } else { |
| 4355 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 4356 | * bit to put the PHY into reset. Then, take it out of reset. |
| 4357 | */ |
| 4358 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 4359 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 4360 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
| 4361 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 4362 | E1000_WRITE_FLUSH(hw); |
| 4363 | mdelay(10); |
| 4364 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
| 4365 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 4366 | E1000_WRITE_FLUSH(hw); |
| 4367 | } |
| 4368 | udelay(150); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4369 | |
| 4370 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 4371 | /* Configure activity LED after PHY reset */ |
| 4372 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 4373 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 4374 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 4375 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 4376 | } |
| 4377 | |
| 4378 | /* Wait for FW to finish PHY configuration. */ |
| 4379 | ret_val = e1000_get_phy_cfg_done(hw); |
| 4380 | if (ret_val != E1000_SUCCESS) |
| 4381 | return ret_val; |
| 4382 | |
| 4383 | return ret_val; |
| 4384 | } |
| 4385 | |
| 4386 | /****************************************************************************** |
| 4387 | * IGP phy init script - initializes the GbE PHY |
| 4388 | * |
| 4389 | * hw - Struct containing variables accessed by shared code |
| 4390 | *****************************************************************************/ |
| 4391 | static void |
| 4392 | e1000_phy_init_script(struct e1000_hw *hw) |
| 4393 | { |
| 4394 | uint32_t ret_val; |
| 4395 | uint16_t phy_saved_data; |
| 4396 | DEBUGFUNC(); |
| 4397 | |
| 4398 | if (hw->phy_init_script) { |
| 4399 | mdelay(20); |
| 4400 | |
| 4401 | /* Save off the current value of register 0x2F5B to be |
| 4402 | * restored at the end of this routine. */ |
| 4403 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 4404 | |
| 4405 | /* Disabled the PHY transmitter */ |
| 4406 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 4407 | |
| 4408 | mdelay(20); |
| 4409 | |
| 4410 | e1000_write_phy_reg(hw, 0x0000, 0x0140); |
| 4411 | |
| 4412 | mdelay(5); |
| 4413 | |
| 4414 | switch (hw->mac_type) { |
| 4415 | case e1000_82541: |
| 4416 | case e1000_82547: |
| 4417 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 4418 | |
| 4419 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 4420 | |
| 4421 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 4422 | |
| 4423 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 4424 | |
| 4425 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 4426 | |
| 4427 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 4428 | |
| 4429 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 4430 | |
| 4431 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 4432 | |
| 4433 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 4434 | break; |
| 4435 | |
| 4436 | case e1000_82541_rev_2: |
| 4437 | case e1000_82547_rev_2: |
| 4438 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 4439 | break; |
| 4440 | default: |
| 4441 | break; |
| 4442 | } |
| 4443 | |
| 4444 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 4445 | |
| 4446 | mdelay(20); |
| 4447 | |
| 4448 | /* Now enable the transmitter */ |
| 4449 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 4450 | |
| 4451 | if (hw->mac_type == e1000_82547) { |
| 4452 | uint16_t fused, fine, coarse; |
| 4453 | |
| 4454 | /* Move to analog registers page */ |
| 4455 | e1000_read_phy_reg(hw, |
| 4456 | IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused); |
| 4457 | |
| 4458 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
| 4459 | e1000_read_phy_reg(hw, |
| 4460 | IGP01E1000_ANALOG_FUSE_STATUS, &fused); |
| 4461 | |
| 4462 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 4463 | coarse = fused |
| 4464 | & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
| 4465 | |
| 4466 | if (coarse > |
| 4467 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
| 4468 | coarse -= |
| 4469 | IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 4470 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
| 4471 | } else if (coarse |
| 4472 | == IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
| 4473 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
| 4474 | |
| 4475 | fused = (fused |
| 4476 | & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 4477 | (fine |
| 4478 | & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 4479 | (coarse |
| 4480 | & IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
| 4481 | |
| 4482 | e1000_write_phy_reg(hw, |
| 4483 | IGP01E1000_ANALOG_FUSE_CONTROL, fused); |
| 4484 | e1000_write_phy_reg(hw, |
| 4485 | IGP01E1000_ANALOG_FUSE_BYPASS, |
| 4486 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 4487 | } |
| 4488 | } |
| 4489 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | /****************************************************************************** |
| 4493 | * Resets the PHY |
| 4494 | * |
| 4495 | * hw - Struct containing variables accessed by shared code |
| 4496 | * |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4497 | * Sets bit 15 of the MII Control register |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4498 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4499 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4500 | e1000_phy_reset(struct e1000_hw *hw) |
| 4501 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4502 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4503 | uint16_t phy_data; |
| 4504 | |
| 4505 | DEBUGFUNC(); |
| 4506 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4507 | /* In the case of the phy reset being blocked, it's not an error, we |
| 4508 | * simply return success without performing the reset. */ |
| 4509 | ret_val = e1000_check_phy_reset_block(hw); |
| 4510 | if (ret_val) |
| 4511 | return E1000_SUCCESS; |
| 4512 | |
| 4513 | switch (hw->phy_type) { |
| 4514 | case e1000_phy_igp: |
| 4515 | case e1000_phy_igp_2: |
| 4516 | case e1000_phy_igp_3: |
| 4517 | case e1000_phy_ife: |
| 4518 | ret_val = e1000_phy_hw_reset(hw); |
| 4519 | if (ret_val) |
| 4520 | return ret_val; |
| 4521 | break; |
| 4522 | default: |
| 4523 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 4524 | if (ret_val) |
| 4525 | return ret_val; |
| 4526 | |
| 4527 | phy_data |= MII_CR_RESET; |
| 4528 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 4529 | if (ret_val) |
| 4530 | return ret_val; |
| 4531 | |
| 4532 | udelay(1); |
| 4533 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4534 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4535 | |
| 4536 | if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2) |
| 4537 | e1000_phy_init_script(hw); |
| 4538 | |
| 4539 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4540 | } |
| 4541 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4542 | static int e1000_set_phy_type (struct e1000_hw *hw) |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4543 | { |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4544 | DEBUGFUNC (); |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4545 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4546 | if (hw->mac_type == e1000_undefined) |
| 4547 | return -E1000_ERR_PHY_TYPE; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4548 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4549 | switch (hw->phy_id) { |
| 4550 | case M88E1000_E_PHY_ID: |
| 4551 | case M88E1000_I_PHY_ID: |
| 4552 | case M88E1011_I_PHY_ID: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4553 | case M88E1111_I_PHY_ID: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4554 | hw->phy_type = e1000_phy_m88; |
| 4555 | break; |
| 4556 | case IGP01E1000_I_PHY_ID: |
| 4557 | if (hw->mac_type == e1000_82541 || |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4558 | hw->mac_type == e1000_82541_rev_2 || |
| 4559 | hw->mac_type == e1000_82547 || |
| 4560 | hw->mac_type == e1000_82547_rev_2) { |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4561 | hw->phy_type = e1000_phy_igp; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4562 | hw->phy_type = e1000_phy_igp; |
| 4563 | break; |
| 4564 | } |
| 4565 | case IGP03E1000_E_PHY_ID: |
| 4566 | hw->phy_type = e1000_phy_igp_3; |
| 4567 | break; |
| 4568 | case IFE_E_PHY_ID: |
| 4569 | case IFE_PLUS_E_PHY_ID: |
| 4570 | case IFE_C_E_PHY_ID: |
| 4571 | hw->phy_type = e1000_phy_ife; |
| 4572 | break; |
| 4573 | case GG82563_E_PHY_ID: |
| 4574 | if (hw->mac_type == e1000_80003es2lan) { |
| 4575 | hw->phy_type = e1000_phy_gg82563; |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4576 | break; |
| 4577 | } |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 4578 | case BME1000_E_PHY_ID: |
| 4579 | hw->phy_type = e1000_phy_bm; |
| 4580 | break; |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4581 | /* Fall Through */ |
| 4582 | default: |
| 4583 | /* Should never have loaded on this device */ |
| 4584 | hw->phy_type = e1000_phy_undefined; |
| 4585 | return -E1000_ERR_PHY_TYPE; |
| 4586 | } |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4587 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4588 | return E1000_SUCCESS; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4589 | } |
| 4590 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4591 | /****************************************************************************** |
| 4592 | * Probes the expected PHY address for known PHY IDs |
| 4593 | * |
| 4594 | * hw - Struct containing variables accessed by shared code |
| 4595 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4596 | static int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4597 | e1000_detect_gig_phy(struct e1000_hw *hw) |
| 4598 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4599 | int32_t phy_init_status, ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4600 | uint16_t phy_id_high, phy_id_low; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4601 | boolean_t match = FALSE; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4602 | |
| 4603 | DEBUGFUNC(); |
| 4604 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4605 | /* The 82571 firmware may still be configuring the PHY. In this |
| 4606 | * case, we cannot access the PHY until the configuration is done. So |
| 4607 | * we explicitly set the PHY values. */ |
| 4608 | if (hw->mac_type == e1000_82571 || |
| 4609 | hw->mac_type == e1000_82572) { |
| 4610 | hw->phy_id = IGP01E1000_I_PHY_ID; |
| 4611 | hw->phy_type = e1000_phy_igp_2; |
| 4612 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4613 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4614 | |
| 4615 | /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a |
| 4616 | * work- around that forces PHY page 0 to be set or the reads fail. |
| 4617 | * The rest of the code in this routine uses e1000_read_phy_reg to |
| 4618 | * read the PHY ID. So for ESB-2 we need to have this set so our |
| 4619 | * reads won't fail. If the attached PHY is not a e1000_phy_gg82563, |
| 4620 | * the routines below will figure this out as well. */ |
| 4621 | if (hw->mac_type == e1000_80003es2lan) |
| 4622 | hw->phy_type = e1000_phy_gg82563; |
| 4623 | |
| 4624 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 4625 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
| 4626 | if (ret_val) |
| 4627 | return ret_val; |
| 4628 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4629 | hw->phy_id = (uint32_t) (phy_id_high << 16); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4630 | udelay(20); |
| 4631 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
| 4632 | if (ret_val) |
| 4633 | return ret_val; |
| 4634 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4635 | hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4636 | hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4637 | |
| 4638 | switch (hw->mac_type) { |
| 4639 | case e1000_82543: |
| 4640 | if (hw->phy_id == M88E1000_E_PHY_ID) |
| 4641 | match = TRUE; |
| 4642 | break; |
| 4643 | case e1000_82544: |
| 4644 | if (hw->phy_id == M88E1000_I_PHY_ID) |
| 4645 | match = TRUE; |
| 4646 | break; |
| 4647 | case e1000_82540: |
| 4648 | case e1000_82545: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4649 | case e1000_82545_rev_3: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4650 | case e1000_82546: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4651 | case e1000_82546_rev_3: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4652 | if (hw->phy_id == M88E1011_I_PHY_ID) |
| 4653 | match = TRUE; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4654 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4655 | case e1000_82541: |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4656 | case e1000_82541_rev_2: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4657 | case e1000_82547: |
| 4658 | case e1000_82547_rev_2: |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4659 | if(hw->phy_id == IGP01E1000_I_PHY_ID) |
| 4660 | match = TRUE; |
| 4661 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4662 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4663 | case e1000_82573: |
| 4664 | if (hw->phy_id == M88E1111_I_PHY_ID) |
| 4665 | match = TRUE; |
| 4666 | break; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 4667 | case e1000_82574: |
| 4668 | if (hw->phy_id == BME1000_E_PHY_ID) |
| 4669 | match = TRUE; |
| 4670 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4671 | case e1000_80003es2lan: |
| 4672 | if (hw->phy_id == GG82563_E_PHY_ID) |
| 4673 | match = TRUE; |
| 4674 | break; |
| 4675 | case e1000_ich8lan: |
| 4676 | if (hw->phy_id == IGP03E1000_E_PHY_ID) |
| 4677 | match = TRUE; |
| 4678 | if (hw->phy_id == IFE_E_PHY_ID) |
| 4679 | match = TRUE; |
| 4680 | if (hw->phy_id == IFE_PLUS_E_PHY_ID) |
| 4681 | match = TRUE; |
| 4682 | if (hw->phy_id == IFE_C_E_PHY_ID) |
| 4683 | match = TRUE; |
| 4684 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4685 | default: |
| 4686 | DEBUGOUT("Invalid MAC type %d\n", hw->mac_type); |
| 4687 | return -E1000_ERR_CONFIG; |
| 4688 | } |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4689 | |
| 4690 | phy_init_status = e1000_set_phy_type(hw); |
| 4691 | |
| 4692 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4693 | DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id); |
| 4694 | return 0; |
| 4695 | } |
| 4696 | DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id); |
| 4697 | return -E1000_ERR_PHY; |
| 4698 | } |
| 4699 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4700 | /***************************************************************************** |
| 4701 | * Set media type and TBI compatibility. |
| 4702 | * |
| 4703 | * hw - Struct containing variables accessed by shared code |
| 4704 | * **************************************************************************/ |
| 4705 | void |
| 4706 | e1000_set_media_type(struct e1000_hw *hw) |
| 4707 | { |
| 4708 | uint32_t status; |
| 4709 | |
| 4710 | DEBUGFUNC(); |
| 4711 | |
| 4712 | if (hw->mac_type != e1000_82543) { |
| 4713 | /* tbi_compatibility is only valid on 82543 */ |
| 4714 | hw->tbi_compatibility_en = FALSE; |
| 4715 | } |
| 4716 | |
| 4717 | switch (hw->device_id) { |
| 4718 | case E1000_DEV_ID_82545GM_SERDES: |
| 4719 | case E1000_DEV_ID_82546GB_SERDES: |
| 4720 | case E1000_DEV_ID_82571EB_SERDES: |
| 4721 | case E1000_DEV_ID_82571EB_SERDES_DUAL: |
| 4722 | case E1000_DEV_ID_82571EB_SERDES_QUAD: |
| 4723 | case E1000_DEV_ID_82572EI_SERDES: |
| 4724 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
| 4725 | hw->media_type = e1000_media_type_internal_serdes; |
| 4726 | break; |
| 4727 | default: |
| 4728 | switch (hw->mac_type) { |
| 4729 | case e1000_82542_rev2_0: |
| 4730 | case e1000_82542_rev2_1: |
| 4731 | hw->media_type = e1000_media_type_fiber; |
| 4732 | break; |
| 4733 | case e1000_ich8lan: |
| 4734 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 4735 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4736 | /* The STATUS_TBIMODE bit is reserved or reused |
| 4737 | * for the this device. |
| 4738 | */ |
| 4739 | hw->media_type = e1000_media_type_copper; |
| 4740 | break; |
| 4741 | default: |
| 4742 | status = E1000_READ_REG(hw, STATUS); |
| 4743 | if (status & E1000_STATUS_TBIMODE) { |
| 4744 | hw->media_type = e1000_media_type_fiber; |
| 4745 | /* tbi_compatibility not valid on fiber */ |
| 4746 | hw->tbi_compatibility_en = FALSE; |
| 4747 | } else { |
| 4748 | hw->media_type = e1000_media_type_copper; |
| 4749 | } |
| 4750 | break; |
| 4751 | } |
| 4752 | } |
| 4753 | } |
| 4754 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4755 | /** |
| 4756 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 4757 | * |
| 4758 | * e1000_sw_init initializes the Adapter private data structure. |
| 4759 | * Fields are initialized based on PCI device information and |
| 4760 | * OS network device settings (MTU size). |
| 4761 | **/ |
| 4762 | |
| 4763 | static int |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 4764 | e1000_sw_init(struct eth_device *nic) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4765 | { |
| 4766 | struct e1000_hw *hw = (typeof(hw)) nic->priv; |
| 4767 | int result; |
| 4768 | |
| 4769 | /* PCI config space info */ |
| 4770 | pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id); |
| 4771 | pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id); |
| 4772 | pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID, |
| 4773 | &hw->subsystem_vendor_id); |
| 4774 | pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id); |
| 4775 | |
| 4776 | pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id); |
| 4777 | pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 4778 | |
| 4779 | /* identify the MAC */ |
| 4780 | result = e1000_set_mac_type(hw); |
| 4781 | if (result) { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 4782 | E1000_ERR(hw->nic, "Unknown MAC Type\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4783 | return result; |
| 4784 | } |
| 4785 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4786 | switch (hw->mac_type) { |
| 4787 | default: |
| 4788 | break; |
| 4789 | case e1000_82541: |
| 4790 | case e1000_82547: |
| 4791 | case e1000_82541_rev_2: |
| 4792 | case e1000_82547_rev_2: |
| 4793 | hw->phy_init_script = 1; |
| 4794 | break; |
| 4795 | } |
| 4796 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4797 | /* flow control settings */ |
| 4798 | hw->fc_high_water = E1000_FC_HIGH_THRESH; |
| 4799 | hw->fc_low_water = E1000_FC_LOW_THRESH; |
| 4800 | hw->fc_pause_time = E1000_FC_PAUSE_TIME; |
| 4801 | hw->fc_send_xon = 1; |
| 4802 | |
| 4803 | /* Media type - copper or fiber */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4804 | e1000_set_media_type(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4805 | |
| 4806 | if (hw->mac_type >= e1000_82543) { |
| 4807 | uint32_t status = E1000_READ_REG(hw, STATUS); |
| 4808 | |
| 4809 | if (status & E1000_STATUS_TBIMODE) { |
| 4810 | DEBUGOUT("fiber interface\n"); |
| 4811 | hw->media_type = e1000_media_type_fiber; |
| 4812 | } else { |
| 4813 | DEBUGOUT("copper interface\n"); |
| 4814 | hw->media_type = e1000_media_type_copper; |
| 4815 | } |
| 4816 | } else { |
| 4817 | hw->media_type = e1000_media_type_fiber; |
| 4818 | } |
| 4819 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4820 | hw->tbi_compatibility_en = TRUE; |
| 4821 | hw->wait_autoneg_complete = TRUE; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4822 | if (hw->mac_type < e1000_82543) |
| 4823 | hw->report_tx_early = 0; |
| 4824 | else |
| 4825 | hw->report_tx_early = 1; |
| 4826 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4827 | return E1000_SUCCESS; |
| 4828 | } |
| 4829 | |
| 4830 | void |
| 4831 | fill_rx(struct e1000_hw *hw) |
| 4832 | { |
| 4833 | struct e1000_rx_desc *rd; |
| 4834 | |
| 4835 | rx_last = rx_tail; |
| 4836 | rd = rx_base + rx_tail; |
| 4837 | rx_tail = (rx_tail + 1) % 8; |
| 4838 | memset(rd, 0, 16); |
| 4839 | rd->buffer_addr = cpu_to_le64((u32) & packet); |
| 4840 | E1000_WRITE_REG(hw, RDT, rx_tail); |
| 4841 | } |
| 4842 | |
| 4843 | /** |
| 4844 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 4845 | * @adapter: board private structure |
| 4846 | * |
| 4847 | * Configure the Tx unit of the MAC after a reset. |
| 4848 | **/ |
| 4849 | |
| 4850 | static void |
| 4851 | e1000_configure_tx(struct e1000_hw *hw) |
| 4852 | { |
| 4853 | unsigned long ptr; |
| 4854 | unsigned long tctl; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4855 | unsigned long tipg, tarc; |
| 4856 | uint32_t ipgr1, ipgr2; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4857 | |
| 4858 | ptr = (u32) tx_pool; |
| 4859 | if (ptr & 0xf) |
| 4860 | ptr = (ptr + 0x10) & (~0xf); |
| 4861 | |
| 4862 | tx_base = (typeof(tx_base)) ptr; |
| 4863 | |
| 4864 | E1000_WRITE_REG(hw, TDBAL, (u32) tx_base); |
| 4865 | E1000_WRITE_REG(hw, TDBAH, 0); |
| 4866 | |
| 4867 | E1000_WRITE_REG(hw, TDLEN, 128); |
| 4868 | |
| 4869 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 4870 | E1000_WRITE_REG(hw, TDH, 0); |
| 4871 | E1000_WRITE_REG(hw, TDT, 0); |
| 4872 | tx_tail = 0; |
| 4873 | |
| 4874 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4875 | if (hw->mac_type <= e1000_82547_rev_2 && |
| 4876 | (hw->media_type == e1000_media_type_fiber || |
| 4877 | hw->media_type == e1000_media_type_internal_serdes)) |
| 4878 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 4879 | else |
| 4880 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 4881 | |
| 4882 | /* Set the default values for the Tx Inter Packet Gap timer */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4883 | switch (hw->mac_type) { |
| 4884 | case e1000_82542_rev2_0: |
| 4885 | case e1000_82542_rev2_1: |
| 4886 | tipg = DEFAULT_82542_TIPG_IPGT; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4887 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 4888 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
| 4889 | break; |
| 4890 | case e1000_80003es2lan: |
| 4891 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 4892 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4893 | break; |
| 4894 | default: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4895 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 4896 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 4897 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4898 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4899 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 4900 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4901 | E1000_WRITE_REG(hw, TIPG, tipg); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4902 | /* Program the Transmit Control Register */ |
| 4903 | tctl = E1000_READ_REG(hw, TCTL); |
| 4904 | tctl &= ~E1000_TCTL_CT; |
| 4905 | tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | |
| 4906 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4907 | |
| 4908 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 4909 | tarc = E1000_READ_REG(hw, TARC0); |
| 4910 | /* set the speed mode bit, we'll clear it if we're not at |
| 4911 | * gigabit link later */ |
| 4912 | /* git bit can be set to 1*/ |
| 4913 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 4914 | tarc = E1000_READ_REG(hw, TARC0); |
| 4915 | tarc |= 1; |
| 4916 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 4917 | tarc = E1000_READ_REG(hw, TARC1); |
| 4918 | tarc |= 1; |
| 4919 | E1000_WRITE_REG(hw, TARC1, tarc); |
| 4920 | } |
| 4921 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4922 | |
| 4923 | e1000_config_collision_dist(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4924 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 4925 | hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4926 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4927 | /* Need to set up RS bit */ |
| 4928 | if (hw->mac_type < e1000_82543) |
| 4929 | hw->txd_cmd |= E1000_TXD_CMD_RPS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4930 | else |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4931 | hw->txd_cmd |= E1000_TXD_CMD_RS; |
| 4932 | E1000_WRITE_REG(hw, TCTL, tctl); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | /** |
| 4936 | * e1000_setup_rctl - configure the receive control register |
| 4937 | * @adapter: Board private structure |
| 4938 | **/ |
| 4939 | static void |
| 4940 | e1000_setup_rctl(struct e1000_hw *hw) |
| 4941 | { |
| 4942 | uint32_t rctl; |
| 4943 | |
| 4944 | rctl = E1000_READ_REG(hw, RCTL); |
| 4945 | |
| 4946 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 4947 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4948 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
| 4949 | | E1000_RCTL_RDMTS_HALF; /* | |
| 4950 | (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4951 | |
| 4952 | if (hw->tbi_compatibility_on == 1) |
| 4953 | rctl |= E1000_RCTL_SBP; |
| 4954 | else |
| 4955 | rctl &= ~E1000_RCTL_SBP; |
| 4956 | |
| 4957 | rctl &= ~(E1000_RCTL_SZ_4096); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4958 | rctl |= E1000_RCTL_SZ_2048; |
| 4959 | rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4960 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 4961 | } |
| 4962 | |
| 4963 | /** |
| 4964 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 4965 | * @adapter: board private structure |
| 4966 | * |
| 4967 | * Configure the Rx unit of the MAC after a reset. |
| 4968 | **/ |
| 4969 | static void |
| 4970 | e1000_configure_rx(struct e1000_hw *hw) |
| 4971 | { |
| 4972 | unsigned long ptr; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4973 | unsigned long rctl, ctrl_ext; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4974 | rx_tail = 0; |
| 4975 | /* make sure receives are disabled while setting up the descriptors */ |
| 4976 | rctl = E1000_READ_REG(hw, RCTL); |
| 4977 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4978 | if (hw->mac_type >= e1000_82540) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4979 | /* Set the interrupt throttling rate. Value is calculated |
| 4980 | * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */ |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4981 | #define MAX_INTS_PER_SEC 8000 |
| 4982 | #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4983 | E1000_WRITE_REG(hw, ITR, DEFAULT_ITR); |
| 4984 | } |
| 4985 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4986 | if (hw->mac_type >= e1000_82571) { |
| 4987 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 4988 | /* Reset delay timers after every interrupt */ |
| 4989 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
| 4990 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 4991 | E1000_WRITE_FLUSH(hw); |
| 4992 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4993 | /* Setup the Base and Length of the Rx Descriptor Ring */ |
| 4994 | ptr = (u32) rx_pool; |
| 4995 | if (ptr & 0xf) |
| 4996 | ptr = (ptr + 0x10) & (~0xf); |
| 4997 | rx_base = (typeof(rx_base)) ptr; |
| 4998 | E1000_WRITE_REG(hw, RDBAL, (u32) rx_base); |
| 4999 | E1000_WRITE_REG(hw, RDBAH, 0); |
| 5000 | |
| 5001 | E1000_WRITE_REG(hw, RDLEN, 128); |
| 5002 | |
| 5003 | /* Setup the HW Rx Head and Tail Descriptor Pointers */ |
| 5004 | E1000_WRITE_REG(hw, RDH, 0); |
| 5005 | E1000_WRITE_REG(hw, RDT, 0); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5006 | /* Enable Receives */ |
| 5007 | |
| 5008 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 5009 | fill_rx(hw); |
| 5010 | } |
| 5011 | |
| 5012 | /************************************************************************** |
| 5013 | POLL - Wait for a frame |
| 5014 | ***************************************************************************/ |
| 5015 | static int |
| 5016 | e1000_poll(struct eth_device *nic) |
| 5017 | { |
| 5018 | struct e1000_hw *hw = nic->priv; |
| 5019 | struct e1000_rx_desc *rd; |
| 5020 | /* return true if there's an ethernet packet ready to read */ |
| 5021 | rd = rx_base + rx_last; |
| 5022 | if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD) |
| 5023 | return 0; |
| 5024 | /*DEBUGOUT("recv: packet len=%d \n", rd->length); */ |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 5025 | NetReceive((uchar *)packet, le32_to_cpu(rd->length)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5026 | fill_rx(hw); |
| 5027 | return 1; |
| 5028 | } |
| 5029 | |
| 5030 | /************************************************************************** |
| 5031 | TRANSMIT - Transmit a frame |
| 5032 | ***************************************************************************/ |
| 5033 | static int |
| 5034 | e1000_transmit(struct eth_device *nic, volatile void *packet, int length) |
| 5035 | { |
Wolfgang Denk | f83102e | 2010-11-22 09:48:45 +0100 | [diff] [blame] | 5036 | void * nv_packet = (void *)packet; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5037 | struct e1000_hw *hw = nic->priv; |
| 5038 | struct e1000_tx_desc *txp; |
| 5039 | int i = 0; |
| 5040 | |
| 5041 | txp = tx_base + tx_tail; |
| 5042 | tx_tail = (tx_tail + 1) % 8; |
| 5043 | |
Wolfgang Denk | f83102e | 2010-11-22 09:48:45 +0100 | [diff] [blame] | 5044 | txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet)); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5045 | txp->lower.data = cpu_to_le32(hw->txd_cmd | length); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5046 | txp->upper.data = 0; |
| 5047 | E1000_WRITE_REG(hw, TDT, tx_tail); |
| 5048 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5049 | E1000_WRITE_FLUSH(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5050 | while (!(le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)) { |
| 5051 | if (i++ > TOUT_LOOP) { |
| 5052 | DEBUGOUT("e1000: tx timeout\n"); |
| 5053 | return 0; |
| 5054 | } |
| 5055 | udelay(10); /* give the nic a chance to write to the register */ |
| 5056 | } |
| 5057 | return 1; |
| 5058 | } |
| 5059 | |
| 5060 | /*reset function*/ |
| 5061 | static inline int |
| 5062 | e1000_reset(struct eth_device *nic) |
| 5063 | { |
| 5064 | struct e1000_hw *hw = nic->priv; |
| 5065 | |
| 5066 | e1000_reset_hw(hw); |
| 5067 | if (hw->mac_type >= e1000_82544) { |
| 5068 | E1000_WRITE_REG(hw, WUC, 0); |
| 5069 | } |
| 5070 | return e1000_init_hw(nic); |
| 5071 | } |
| 5072 | |
| 5073 | /************************************************************************** |
| 5074 | DISABLE - Turn off ethernet interface |
| 5075 | ***************************************************************************/ |
| 5076 | static void |
| 5077 | e1000_disable(struct eth_device *nic) |
| 5078 | { |
| 5079 | struct e1000_hw *hw = nic->priv; |
| 5080 | |
| 5081 | /* Turn off the ethernet interface */ |
| 5082 | E1000_WRITE_REG(hw, RCTL, 0); |
| 5083 | E1000_WRITE_REG(hw, TCTL, 0); |
| 5084 | |
| 5085 | /* Clear the transmit ring */ |
| 5086 | E1000_WRITE_REG(hw, TDH, 0); |
| 5087 | E1000_WRITE_REG(hw, TDT, 0); |
| 5088 | |
| 5089 | /* Clear the receive ring */ |
| 5090 | E1000_WRITE_REG(hw, RDH, 0); |
| 5091 | E1000_WRITE_REG(hw, RDT, 0); |
| 5092 | |
| 5093 | /* put the card in its initial state */ |
| 5094 | #if 0 |
| 5095 | E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST); |
| 5096 | #endif |
| 5097 | mdelay(10); |
| 5098 | |
| 5099 | } |
| 5100 | |
| 5101 | /************************************************************************** |
| 5102 | INIT - set up ethernet interface(s) |
| 5103 | ***************************************************************************/ |
| 5104 | static int |
| 5105 | e1000_init(struct eth_device *nic, bd_t * bis) |
| 5106 | { |
| 5107 | struct e1000_hw *hw = nic->priv; |
| 5108 | int ret_val = 0; |
| 5109 | |
| 5110 | ret_val = e1000_reset(nic); |
| 5111 | if (ret_val < 0) { |
| 5112 | if ((ret_val == -E1000_ERR_NOLINK) || |
| 5113 | (ret_val == -E1000_ERR_TIMEOUT)) { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5114 | E1000_ERR(hw->nic, "Valid Link not detected\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5115 | } else { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5116 | E1000_ERR(hw->nic, "Hardware Initialization Failed\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5117 | } |
| 5118 | return 0; |
| 5119 | } |
| 5120 | e1000_configure_tx(hw); |
| 5121 | e1000_setup_rctl(hw); |
| 5122 | e1000_configure_rx(hw); |
| 5123 | return 1; |
| 5124 | } |
| 5125 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5126 | /****************************************************************************** |
| 5127 | * Gets the current PCI bus type of hardware |
| 5128 | * |
| 5129 | * hw - Struct containing variables accessed by shared code |
| 5130 | *****************************************************************************/ |
| 5131 | void e1000_get_bus_type(struct e1000_hw *hw) |
| 5132 | { |
| 5133 | uint32_t status; |
| 5134 | |
| 5135 | switch (hw->mac_type) { |
| 5136 | case e1000_82542_rev2_0: |
| 5137 | case e1000_82542_rev2_1: |
| 5138 | hw->bus_type = e1000_bus_type_pci; |
| 5139 | break; |
| 5140 | case e1000_82571: |
| 5141 | case e1000_82572: |
| 5142 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 5143 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5144 | case e1000_80003es2lan: |
| 5145 | hw->bus_type = e1000_bus_type_pci_express; |
| 5146 | break; |
| 5147 | case e1000_ich8lan: |
| 5148 | hw->bus_type = e1000_bus_type_pci_express; |
| 5149 | break; |
| 5150 | default: |
| 5151 | status = E1000_READ_REG(hw, STATUS); |
| 5152 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 5153 | e1000_bus_type_pcix : e1000_bus_type_pci; |
| 5154 | break; |
| 5155 | } |
| 5156 | } |
| 5157 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5158 | /************************************************************************** |
| 5159 | PROBE - Look for an adapter, this routine's visible to the outside |
| 5160 | You should omit the last argument struct pci_device * for a non-PCI NIC |
| 5161 | ***************************************************************************/ |
| 5162 | int |
| 5163 | e1000_initialize(bd_t * bis) |
| 5164 | { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5165 | unsigned int i; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5166 | pci_dev_t devno; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5167 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 5168 | DEBUGFUNC(); |
| 5169 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5170 | /* Find and probe all the matching PCI devices */ |
| 5171 | for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) { |
| 5172 | u32 val; |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5173 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5174 | /* |
| 5175 | * These will never get freed due to errors, this allows us to |
| 5176 | * perform SPI EEPROM programming from U-boot, for example. |
| 5177 | */ |
| 5178 | struct eth_device *nic = malloc(sizeof(*nic)); |
| 5179 | struct e1000_hw *hw = malloc(sizeof(*hw)); |
| 5180 | if (!nic || !hw) { |
| 5181 | printf("e1000#%u: Out of Memory!\n", i); |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5182 | free(nic); |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5183 | free(hw); |
| 5184 | continue; |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5185 | } |
| 5186 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5187 | /* Make sure all of the fields are initially zeroed */ |
Matthew McClintock | 5761ce4 | 2010-11-15 18:02:53 -0600 | [diff] [blame] | 5188 | memset(nic, 0, sizeof(*nic)); |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5189 | memset(hw, 0, sizeof(*hw)); |
| 5190 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5191 | /* Assign the passed-in values */ |
| 5192 | hw->cardnum = i; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5193 | hw->pdev = devno; |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5194 | hw->nic = nic; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5195 | nic->priv = hw; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5196 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5197 | /* Generate a card name */ |
| 5198 | sprintf(nic->name, "e1000#%u", hw->cardnum); |
| 5199 | |
| 5200 | /* Print a debug message with the IO base address */ |
| 5201 | pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val); |
| 5202 | E1000_DBG(nic, "iobase 0x%08x\n", val & 0xfffffff0); |
| 5203 | |
| 5204 | /* Try to enable I/O accesses and bus-mastering */ |
| 5205 | val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 5206 | pci_write_config_dword(devno, PCI_COMMAND, val); |
| 5207 | |
| 5208 | /* Make sure it worked */ |
| 5209 | pci_read_config_dword(devno, PCI_COMMAND, &val); |
| 5210 | if (!(val & PCI_COMMAND_MEMORY)) { |
| 5211 | E1000_ERR(nic, "Can't enable I/O memory\n"); |
| 5212 | continue; |
| 5213 | } |
| 5214 | if (!(val & PCI_COMMAND_MASTER)) { |
| 5215 | E1000_ERR(nic, "Can't enable bus-mastering\n"); |
| 5216 | continue; |
| 5217 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5218 | |
| 5219 | /* Are these variables needed? */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5220 | hw->fc = e1000_fc_default; |
| 5221 | hw->original_fc = e1000_fc_default; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5222 | hw->autoneg_failed = 0; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5223 | hw->autoneg = 1; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5224 | hw->get_link_status = TRUE; |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5225 | hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0, |
| 5226 | PCI_REGION_MEM); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5227 | hw->mac_type = e1000_undefined; |
| 5228 | |
| 5229 | /* MAC and Phy settings */ |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5230 | if (e1000_sw_init(nic) < 0) { |
| 5231 | E1000_ERR(nic, "Software init failed\n"); |
| 5232 | continue; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5233 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5234 | if (e1000_check_phy_reset_block(hw)) |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5235 | E1000_ERR(nic, "PHY Reset is blocked!\n"); |
| 5236 | |
| 5237 | /* Basic init was OK, reset the hardware */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5238 | e1000_reset_hw(hw); |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5239 | |
| 5240 | /* Validate the EEPROM and get chipset information */ |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 5241 | #if !(defined(CONFIG_AP1000) || defined(CONFIG_MVBC_1G)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5242 | if (e1000_init_eeprom_params(hw)) { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5243 | E1000_ERR(nic, "EEPROM is invalid!\n"); |
| 5244 | continue; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5245 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5246 | if (e1000_validate_eeprom_checksum(nic) < 0) { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5247 | E1000_ERR(nic, "EEPROM checksum is bad!\n"); |
| 5248 | continue; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5249 | } |
Wolfgang Denk | 56811f6 | 2005-10-09 01:04:33 +0200 | [diff] [blame] | 5250 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5251 | e1000_read_mac_addr(nic); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5252 | e1000_get_bus_type(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5253 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5254 | printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ", |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5255 | nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2], |
| 5256 | nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]); |
| 5257 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5258 | /* Set up the function pointers and register the device */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5259 | nic->init = e1000_init; |
| 5260 | nic->recv = e1000_poll; |
| 5261 | nic->send = e1000_transmit; |
| 5262 | nic->halt = e1000_disable; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5263 | eth_register(nic); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5264 | } |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame^] | 5265 | |
| 5266 | return i; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5267 | } |