Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Agere Systems Inc. |
| 3 | * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs |
| 4 | * |
| 5 | * Copyright © 2005 Agere Systems Inc. |
| 6 | * All rights reserved. |
| 7 | * http://www.agere.com |
| 8 | * |
| 9 | *------------------------------------------------------------------------------ |
| 10 | * |
| 11 | * et131x_config.c - Handles parsing of configuration data during |
| 12 | * initialization. |
| 13 | * |
| 14 | *------------------------------------------------------------------------------ |
| 15 | * |
| 16 | * SOFTWARE LICENSE |
| 17 | * |
| 18 | * This software is provided subject to the following terms and conditions, |
| 19 | * which you should read carefully before using the software. Using this |
| 20 | * software indicates your acceptance of these terms and conditions. If you do |
| 21 | * not agree with these terms and conditions, do not use the software. |
| 22 | * |
| 23 | * Copyright © 2005 Agere Systems Inc. |
| 24 | * All rights reserved. |
| 25 | * |
| 26 | * Redistribution and use in source or binary forms, with or without |
| 27 | * modifications, are permitted provided that the following conditions are met: |
| 28 | * |
| 29 | * . Redistributions of source code must retain the above copyright notice, this |
| 30 | * list of conditions and the following Disclaimer as comments in the code as |
| 31 | * well as in the documentation and/or other materials provided with the |
| 32 | * distribution. |
| 33 | * |
| 34 | * . Redistributions in binary form must reproduce the above copyright notice, |
| 35 | * this list of conditions and the following Disclaimer in the documentation |
| 36 | * and/or other materials provided with the distribution. |
| 37 | * |
| 38 | * . Neither the name of Agere Systems Inc. nor the names of the contributors |
| 39 | * may be used to endorse or promote products derived from this software |
| 40 | * without specific prior written permission. |
| 41 | * |
| 42 | * Disclaimer |
| 43 | * |
| 44 | * THIS SOFTWARE IS PROVIDED AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 45 | * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF |
| 46 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY |
| 47 | * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN |
| 48 | * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY |
| 49 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 50 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 51 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 52 | * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT |
| 53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 54 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 55 | * DAMAGE. |
| 56 | * |
| 57 | */ |
| 58 | |
| 59 | #include "et131x_version.h" |
| 60 | #include "et131x_debug.h" |
| 61 | #include "et131x_defs.h" |
| 62 | |
| 63 | #include <linux/init.h> |
| 64 | #include <linux/module.h> |
| 65 | #include <linux/types.h> |
| 66 | #include <linux/kernel.h> |
| 67 | |
| 68 | #include <linux/sched.h> |
| 69 | #include <linux/ptrace.h> |
| 70 | #include <linux/slab.h> |
| 71 | #include <linux/ctype.h> |
| 72 | #include <linux/string.h> |
| 73 | #include <linux/timer.h> |
| 74 | #include <linux/interrupt.h> |
| 75 | #include <linux/in.h> |
| 76 | #include <linux/delay.h> |
| 77 | #include <asm/io.h> |
| 78 | #include <asm/system.h> |
| 79 | #include <asm/bitops.h> |
| 80 | |
| 81 | #include <linux/netdevice.h> |
| 82 | #include <linux/etherdevice.h> |
| 83 | #include <linux/skbuff.h> |
| 84 | #include <linux/if_arp.h> |
| 85 | #include <linux/ioport.h> |
| 86 | |
| 87 | #include "et1310_phy.h" |
| 88 | #include "et1310_pm.h" |
| 89 | #include "et1310_jagcore.h" |
| 90 | |
| 91 | #include "et131x_adapter.h" |
| 92 | #include "et131x_initpci.h" |
| 93 | #include "et131x_config.h" |
| 94 | |
| 95 | #include "et1310_tx.h" |
| 96 | |
| 97 | /* Data for debugging facilities */ |
| 98 | #ifdef CONFIG_ET131X_DEBUG |
| 99 | extern dbg_info_t *et131x_dbginfo; |
| 100 | #endif /* CONFIG_ET131X_DEBUG */ |
| 101 | |
| 102 | /* Defines for Parameter Default/Min/Max vaules */ |
| 103 | #define PARM_SPEED_DUPLEX_DEF 0 |
| 104 | #define PARM_SPEED_DUPLEX_MIN 0 |
| 105 | #define PARM_SPEED_DUPLEX_MAX 5 |
| 106 | |
| 107 | #define PARM_VLAN_TAG_DEF 0 |
| 108 | #define PARM_VLAN_TAG_MIN 0 |
| 109 | #define PARM_VLAN_TAG_MAX 4095 |
| 110 | |
| 111 | #define PARM_FLOW_CTL_DEF 0 |
| 112 | #define PARM_FLOW_CTL_MIN 0 |
| 113 | #define PARM_FLOW_CTL_MAX 3 |
| 114 | |
| 115 | #define PARM_WOL_LINK_DEF 3 |
| 116 | #define PARM_WOL_LINK_MIN 0 |
| 117 | #define PARM_WOL_LINK_MAX 3 |
| 118 | |
| 119 | #define PARM_WOL_MATCH_DEF 7 |
| 120 | #define PARM_WOL_MATCH_MIN 0 |
| 121 | #define PARM_WOL_MATCH_MAX 7 |
| 122 | |
| 123 | #define PARM_JUMBO_PKT_DEF 1514 |
| 124 | #define PARM_JUMBO_PKT_MIN 1514 |
| 125 | #define PARM_JUMBO_PKT_MAX 9216 |
| 126 | |
| 127 | #define PARM_PHY_COMA_DEF 0 |
| 128 | #define PARM_PHY_COMA_MIN 0 |
| 129 | #define PARM_PHY_COMA_MAX 1 |
| 130 | |
| 131 | #define PARM_RX_NUM_BUFS_DEF 4 |
| 132 | #define PARM_RX_NUM_BUFS_MIN 1 |
| 133 | #define PARM_RX_NUM_BUFS_MAX 64 |
| 134 | |
| 135 | #define PARM_RX_TIME_INT_DEF 10 |
| 136 | #define PARM_RX_TIME_INT_MIN 2 |
| 137 | #define PARM_RX_TIME_INT_MAX 320 |
| 138 | |
| 139 | #define PARM_TX_NUM_BUFS_DEF 4 |
| 140 | #define PARM_TX_NUM_BUFS_MIN 1 |
| 141 | #define PARM_TX_NUM_BUFS_MAX 40 |
| 142 | |
| 143 | #define PARM_TX_TIME_INT_DEF 40 |
| 144 | #define PARM_TX_TIME_INT_MIN 1 |
| 145 | #define PARM_TX_TIME_INT_MAX 140 |
| 146 | |
| 147 | #define PARM_RX_MEM_END_DEF 0x2bc |
| 148 | #define PARM_RX_MEM_END_MIN 0 |
| 149 | #define PARM_RX_MEM_END_MAX 0x3ff |
| 150 | |
| 151 | #define PARM_MAC_STAT_DEF 1 |
| 152 | #define PARM_MAC_STAT_MIN 0 |
| 153 | #define PARM_MAC_STAT_MAX 1 |
| 154 | |
| 155 | #define PARM_SC_GAIN_DEF 7 |
| 156 | #define PARM_SC_GAIN_MIN 0 |
| 157 | #define PARM_SC_GAIN_MAX 7 |
| 158 | |
| 159 | #define PARM_PM_WOL_DEF 0 |
| 160 | #define PARM_PM_WOL_MIN 0 |
| 161 | #define PARM_PM_WOL_MAX 1 |
| 162 | |
| 163 | #define PARM_NMI_DISABLE_DEF 0 |
| 164 | #define PARM_NMI_DISABLE_MIN 0 |
| 165 | #define PARM_NMI_DISABLE_MAX 2 |
| 166 | |
| 167 | #define PARM_DMA_CACHE_DEF 0 |
| 168 | #define PARM_DMA_CACHE_MIN 0 |
| 169 | #define PARM_DMA_CACHE_MAX 15 |
| 170 | |
| 171 | #define PARM_PHY_LOOPBK_DEF 0 |
| 172 | #define PARM_PHY_LOOPBK_MIN 0 |
| 173 | #define PARM_PHY_LOOPBK_MAX 1 |
| 174 | |
| 175 | #define PARM_MAC_ADDRESS_DEF { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 } |
| 176 | |
| 177 | /* Module parameter for disabling NMI |
| 178 | * et131x_speed_set : |
| 179 | * Set Link speed and dublex manually (0-5) [0] |
| 180 | * 1 : 10Mb Half-Duplex |
| 181 | * 2 : 10Mb Full-Duplex |
| 182 | * 3 : 100Mb Half-Duplex |
| 183 | * 4 : 100Mb Full-Duplex |
| 184 | * 5 : 1000Mb Full-Duplex |
| 185 | * 0 : Auto Speed Auto Dublex // default |
| 186 | */ |
| 187 | static u32 et131x_nmi_disable = PARM_NMI_DISABLE_DEF; |
| 188 | module_param(et131x_nmi_disable, uint, 0); |
| 189 | MODULE_PARM_DESC(et131x_nmi_disable, "Disable NMI (0-2) [0]"); |
| 190 | |
| 191 | /* Module parameter for manual speed setting |
| 192 | * et131x_nmi_disable : |
| 193 | * Disable NMI (0-2) [0] |
| 194 | * 0 : |
| 195 | * 1 : |
| 196 | * 2 : |
| 197 | */ |
| 198 | static u32 et131x_speed_set = PARM_SPEED_DUPLEX_DEF; |
| 199 | module_param(et131x_speed_set, uint, 0); |
| 200 | MODULE_PARM_DESC(et131x_speed_set, |
| 201 | "Set Link speed and dublex manually (0-5) [0] \n 1 : 10Mb Half-Duplex \n 2 : 10Mb Full-Duplex \n 3 : 100Mb Half-Duplex \n 4 : 100Mb Full-Duplex \n 5 : 1000Mb Full-Duplex \n 0 : Auto Speed Auto Dublex"); |
| 202 | |
| 203 | /** |
| 204 | * et131x_config_parse |
| 205 | * @pAdapter: pointer to the private adapter struct |
| 206 | * |
| 207 | * Parses a configuration from some location (module parameters, for example) |
| 208 | * into the private adapter struct |
| 209 | */ |
| 210 | void et131x_config_parse(struct et131x_adapter *pAdapter) |
| 211 | { |
| 212 | uint8_t macAddrDef[] = PARM_MAC_ADDRESS_DEF; |
| 213 | |
| 214 | DBG_ENTER(et131x_dbginfo); |
| 215 | |
| 216 | /* |
| 217 | * The NDIS driver uses the registry to store persistent per-device |
| 218 | * configuration, and reads this configuration into the appropriate |
| 219 | * elements of the private adapter structure on initialization. |
| 220 | * Because Linux has no analog to the registry, use this function to |
| 221 | * initialize the private adapter structure with a default |
| 222 | * configuration. |
| 223 | * |
| 224 | * One other possibility is to use a series of module parameters which |
| 225 | * can be passed in by the caller when the module is initialized. |
| 226 | * However, this implementation does not allow for seperate |
| 227 | * configurations in the event multiple devices are present, and hence |
| 228 | * will not suffice. |
| 229 | * |
| 230 | * If another method is derived which addresses this problem, this is |
| 231 | * where it should be implemented. |
| 232 | */ |
| 233 | |
| 234 | /* Set the private adapter struct with default values for the |
| 235 | * corresponding parameters |
| 236 | */ |
| 237 | if (et131x_speed_set != PARM_SPEED_DUPLEX_DEF) { |
| 238 | DBG_VERBOSE(et131x_dbginfo, "Speed set manually to : %d \n", |
| 239 | et131x_speed_set); |
| 240 | pAdapter->SpeedDuplex = et131x_speed_set; |
| 241 | } else { |
| 242 | pAdapter->SpeedDuplex = PARM_SPEED_DUPLEX_DEF; |
| 243 | } |
| 244 | |
| 245 | // pAdapter->SpeedDuplex = PARM_SPEED_DUPLEX_DEF; |
| 246 | |
| 247 | pAdapter->RegistryVlanTag = PARM_VLAN_TAG_DEF; |
| 248 | pAdapter->RegistryFlowControl = PARM_FLOW_CTL_DEF; |
| 249 | pAdapter->RegistryWOLLink = PARM_WOL_LINK_DEF; |
| 250 | pAdapter->RegistryWOLMatch = PARM_WOL_MATCH_DEF; |
| 251 | pAdapter->RegistryJumboPacket = PARM_JUMBO_PKT_DEF; |
| 252 | pAdapter->RegistryPhyComa = PARM_PHY_COMA_DEF; |
| 253 | pAdapter->RegistryRxNumBuffers = PARM_RX_NUM_BUFS_DEF; |
| 254 | pAdapter->RegistryRxTimeInterval = PARM_RX_TIME_INT_DEF; |
| 255 | pAdapter->RegistryTxNumBuffers = PARM_TX_NUM_BUFS_DEF; |
| 256 | pAdapter->RegistryTxTimeInterval = PARM_TX_TIME_INT_DEF; |
| 257 | pAdapter->RegistryRxMemEnd = PARM_RX_MEM_END_DEF; |
| 258 | pAdapter->RegistryMACStat = PARM_MAC_STAT_DEF; |
| 259 | pAdapter->RegistrySCGain = PARM_SC_GAIN_DEF; |
| 260 | pAdapter->RegistryPMWOL = PARM_PM_WOL_DEF; |
| 261 | |
| 262 | if (et131x_nmi_disable != PARM_NMI_DISABLE_DEF) { |
| 263 | pAdapter->RegistryNMIDisable = et131x_nmi_disable; |
| 264 | } else { |
| 265 | pAdapter->RegistryNMIDisable = PARM_NMI_DISABLE_DEF; |
| 266 | } |
| 267 | |
| 268 | pAdapter->RegistryDMACache = PARM_DMA_CACHE_DEF; |
| 269 | pAdapter->RegistryPhyLoopbk = PARM_PHY_LOOPBK_DEF; |
| 270 | |
| 271 | /* Set the MAC address to a default */ |
| 272 | memcpy(pAdapter->CurrentAddress, macAddrDef, ETH_ALEN); |
| 273 | pAdapter->bOverrideAddress = false; |
| 274 | |
| 275 | DBG_TRACE(et131x_dbginfo, |
| 276 | "Default MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 277 | pAdapter->CurrentAddress[0], pAdapter->CurrentAddress[1], |
| 278 | pAdapter->CurrentAddress[2], pAdapter->CurrentAddress[3], |
| 279 | pAdapter->CurrentAddress[4], pAdapter->CurrentAddress[5]); |
| 280 | |
| 281 | /* Decode SpeedDuplex |
| 282 | * |
| 283 | * Set up as if we are auto negotiating always and then change if we |
| 284 | * go into force mode |
| 285 | */ |
| 286 | pAdapter->AiForceSpeed = 0; // Auto speed |
| 287 | pAdapter->AiForceDpx = 0; // Auto FDX |
| 288 | |
| 289 | /* If we are the 10/100 device, and gigabit is somehow requested then |
| 290 | * knock it down to 100 full. |
| 291 | */ |
| 292 | if ((pAdapter->DeviceID == ET131X_PCI_DEVICE_ID_FAST) && |
| 293 | (pAdapter->SpeedDuplex == 5)) { |
| 294 | pAdapter->SpeedDuplex = 4; |
| 295 | } |
| 296 | |
| 297 | switch (pAdapter->SpeedDuplex) { |
| 298 | case 1: // 10Mb Half-Duplex |
| 299 | pAdapter->AiForceSpeed = 10; |
| 300 | pAdapter->AiForceDpx = 1; |
| 301 | break; |
| 302 | |
| 303 | case 2: // 10Mb Full-Duplex |
| 304 | pAdapter->AiForceSpeed = 10; |
| 305 | pAdapter->AiForceDpx = 2; |
| 306 | break; |
| 307 | |
| 308 | case 3: // 100Mb Half-Duplex |
| 309 | pAdapter->AiForceSpeed = 100; |
| 310 | pAdapter->AiForceDpx = 1; |
| 311 | break; |
| 312 | |
| 313 | case 4: // 100Mb Full-Duplex |
| 314 | pAdapter->AiForceSpeed = 100; |
| 315 | pAdapter->AiForceDpx = 2; |
| 316 | break; |
| 317 | |
| 318 | case 5: // 1000Mb Full-Duplex |
| 319 | pAdapter->AiForceSpeed = 1000; |
| 320 | pAdapter->AiForceDpx = 2; |
| 321 | break; |
| 322 | } |
| 323 | |
| 324 | DBG_LEAVE(et131x_dbginfo); |
| 325 | } |