| Jie Yang | a6a5325 | 2008-07-18 11:37:13 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright(c) 2007 Atheros Corporation. All rights reserved. | 
|  | 3 | * | 
|  | 4 | * Derived from Intel e1000 driver | 
|  | 5 | * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. | 
|  | 6 | * | 
|  | 7 | * This program is free software; you can redistribute it and/or modify it | 
|  | 8 | * under the terms of the GNU General Public License as published by the Free | 
|  | 9 | * Software Foundation; either version 2 of the License, or (at your option) | 
|  | 10 | * any later version. | 
|  | 11 | * | 
|  | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT | 
|  | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 14 | * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
|  | 15 | * more details. | 
|  | 16 | * | 
|  | 17 | * You should have received a copy of the GNU General Public License along with | 
|  | 18 | * this program; if not, write to the Free Software Foundation, Inc., 59 | 
|  | 19 | * Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
|  | 20 | */ | 
|  | 21 |  | 
|  | 22 | #include <linux/netdevice.h> | 
|  | 23 |  | 
|  | 24 | #include "atl1e.h" | 
|  | 25 |  | 
|  | 26 | /* This is the only thing that needs to be changed to adjust the | 
|  | 27 | * maximum number of ports that the driver can manage. | 
|  | 28 | */ | 
|  | 29 |  | 
|  | 30 | #define ATL1E_MAX_NIC 32 | 
|  | 31 |  | 
|  | 32 | #define OPTION_UNSET    -1 | 
|  | 33 | #define OPTION_DISABLED 0 | 
|  | 34 | #define OPTION_ENABLED  1 | 
|  | 35 |  | 
|  | 36 | /* All parameters are treated the same, as an integer array of values. | 
|  | 37 | * This macro just reduces the need to repeat the same declaration code | 
|  | 38 | * over and over (plus this helps to avoid typo bugs). | 
|  | 39 | */ | 
|  | 40 | #define ATL1E_PARAM_INIT { [0 ... ATL1E_MAX_NIC] = OPTION_UNSET } | 
|  | 41 |  | 
|  | 42 | #define ATL1E_PARAM(x, desc) \ | 
|  | 43 | static int __devinitdata x[ATL1E_MAX_NIC + 1] = ATL1E_PARAM_INIT; \ | 
|  | 44 | static int num_##x; \ | 
|  | 45 | module_param_array_named(x, x, int, &num_##x, 0); \ | 
|  | 46 | MODULE_PARM_DESC(x, desc); | 
|  | 47 |  | 
|  | 48 | /* Transmit Memory count | 
|  | 49 | * | 
|  | 50 | * Valid Range: 64-2048 | 
|  | 51 | * | 
|  | 52 | * Default Value: 128 | 
|  | 53 | */ | 
|  | 54 | #define ATL1E_MIN_TX_DESC_CNT		32 | 
|  | 55 | #define ATL1E_MAX_TX_DESC_CNT		1020 | 
|  | 56 | #define ATL1E_DEFAULT_TX_DESC_CNT	128 | 
|  | 57 | ATL1E_PARAM(tx_desc_cnt, "Transmit description count"); | 
|  | 58 |  | 
|  | 59 | /* Receive Memory Block Count | 
|  | 60 | * | 
|  | 61 | * Valid Range: 16-512 | 
|  | 62 | * | 
|  | 63 | * Default Value: 128 | 
|  | 64 | */ | 
|  | 65 | #define ATL1E_MIN_RX_MEM_SIZE		8    /* 8KB   */ | 
|  | 66 | #define ATL1E_MAX_RX_MEM_SIZE		1024 /* 1MB   */ | 
|  | 67 | #define ATL1E_DEFAULT_RX_MEM_SIZE	256  /* 128KB */ | 
|  | 68 | ATL1E_PARAM(rx_mem_size, "memory size of rx buffer(KB)"); | 
|  | 69 |  | 
|  | 70 | /* User Specified MediaType Override | 
|  | 71 | * | 
|  | 72 | * Valid Range: 0-5 | 
|  | 73 | *  - 0    - auto-negotiate at all supported speeds | 
|  | 74 | *  - 1    - only link at 100Mbps Full Duplex | 
|  | 75 | *  - 2    - only link at 100Mbps Half Duplex | 
|  | 76 | *  - 3    - only link at 10Mbps Full Duplex | 
|  | 77 | *  - 4    - only link at 10Mbps Half Duplex | 
|  | 78 | * Default Value: 0 | 
|  | 79 | */ | 
|  | 80 |  | 
|  | 81 | ATL1E_PARAM(media_type, "MediaType Select"); | 
|  | 82 |  | 
|  | 83 | /* Interrupt Moderate Timer in units of 2 us | 
|  | 84 | * | 
|  | 85 | * Valid Range: 10-65535 | 
|  | 86 | * | 
|  | 87 | * Default Value: 45000(90ms) | 
|  | 88 | */ | 
|  | 89 | #define INT_MOD_DEFAULT_CNT             100 /* 200us */ | 
|  | 90 | #define INT_MOD_MAX_CNT                 65000 | 
|  | 91 | #define INT_MOD_MIN_CNT                 50 | 
|  | 92 | ATL1E_PARAM(int_mod_timer, "Interrupt Moderator Timer"); | 
|  | 93 |  | 
|  | 94 | #define AUTONEG_ADV_DEFAULT  0x2F | 
|  | 95 | #define AUTONEG_ADV_MASK     0x2F | 
|  | 96 | #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL | 
|  | 97 |  | 
|  | 98 | #define FLASH_VENDOR_DEFAULT    0 | 
|  | 99 | #define FLASH_VENDOR_MIN        0 | 
|  | 100 | #define FLASH_VENDOR_MAX        2 | 
|  | 101 |  | 
|  | 102 | struct atl1e_option { | 
|  | 103 | enum { enable_option, range_option, list_option } type; | 
|  | 104 | char *name; | 
|  | 105 | char *err; | 
|  | 106 | int  def; | 
|  | 107 | union { | 
|  | 108 | struct { /* range_option info */ | 
|  | 109 | int min; | 
|  | 110 | int max; | 
|  | 111 | } r; | 
|  | 112 | struct { /* list_option info */ | 
|  | 113 | int nr; | 
|  | 114 | struct atl1e_opt_list { int i; char *str; } *p; | 
|  | 115 | } l; | 
|  | 116 | } arg; | 
|  | 117 | }; | 
|  | 118 |  | 
|  | 119 | static int __devinit atl1e_validate_option(int *value, struct atl1e_option *opt, struct pci_dev *pdev) | 
|  | 120 | { | 
|  | 121 | if (*value == OPTION_UNSET) { | 
|  | 122 | *value = opt->def; | 
|  | 123 | return 0; | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | switch (opt->type) { | 
|  | 127 | case enable_option: | 
|  | 128 | switch (*value) { | 
|  | 129 | case OPTION_ENABLED: | 
|  | 130 | dev_info(&pdev->dev, "%s Enabled\n", opt->name); | 
|  | 131 | return 0; | 
|  | 132 | case OPTION_DISABLED: | 
|  | 133 | dev_info(&pdev->dev, "%s Disabled\n", opt->name); | 
|  | 134 | return 0; | 
|  | 135 | } | 
|  | 136 | break; | 
|  | 137 | case range_option: | 
|  | 138 | if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { | 
|  | 139 | dev_info(&pdev->dev, "%s set to %i\n", opt->name, *value); | 
|  | 140 | return 0; | 
|  | 141 | } | 
|  | 142 | break; | 
|  | 143 | case list_option:{ | 
|  | 144 | int i; | 
|  | 145 | struct atl1e_opt_list *ent; | 
|  | 146 |  | 
|  | 147 | for (i = 0; i < opt->arg.l.nr; i++) { | 
|  | 148 | ent = &opt->arg.l.p[i]; | 
|  | 149 | if (*value == ent->i) { | 
|  | 150 | if (ent->str[0] != '\0') | 
|  | 151 | dev_info(&pdev->dev, "%s\n", | 
|  | 152 | ent->str); | 
|  | 153 | return 0; | 
|  | 154 | } | 
|  | 155 | } | 
|  | 156 | break; | 
|  | 157 | } | 
|  | 158 | default: | 
|  | 159 | BUG(); | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | dev_info(&pdev->dev, "Invalid %s specified (%i) %s\n", | 
|  | 163 | opt->name, *value, opt->err); | 
|  | 164 | *value = opt->def; | 
|  | 165 | return -1; | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | /* | 
|  | 169 | * atl1e_check_options - Range Checking for Command Line Parameters | 
|  | 170 | * @adapter: board private structure | 
|  | 171 | * | 
|  | 172 | * This routine checks all command line parameters for valid user | 
|  | 173 | * input.  If an invalid value is given, or if no user specified | 
|  | 174 | * value exists, a default value is used.  The final value is stored | 
|  | 175 | * in a variable in the adapter structure. | 
|  | 176 | */ | 
|  | 177 | void __devinit atl1e_check_options(struct atl1e_adapter *adapter) | 
|  | 178 | { | 
|  | 179 | struct pci_dev *pdev = adapter->pdev; | 
|  | 180 | int bd = adapter->bd_number; | 
|  | 181 | if (bd >= ATL1E_MAX_NIC) { | 
|  | 182 | dev_notice(&pdev->dev, "no configuration for board #%i\n", bd); | 
|  | 183 | dev_notice(&pdev->dev, "Using defaults for all values\n"); | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | { 		/* Transmit Ring Size */ | 
|  | 187 | struct atl1e_option opt = { | 
|  | 188 | .type = range_option, | 
|  | 189 | .name = "Transmit Ddescription Count", | 
|  | 190 | .err  = "using default of " | 
|  | 191 | __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT), | 
|  | 192 | .def  = ATL1E_DEFAULT_TX_DESC_CNT, | 
|  | 193 | .arg  = { .r = { .min = ATL1E_MIN_TX_DESC_CNT, | 
|  | 194 | .max = ATL1E_MAX_TX_DESC_CNT} } | 
|  | 195 | }; | 
|  | 196 | int val; | 
|  | 197 | if (num_tx_desc_cnt > bd) { | 
|  | 198 | val = tx_desc_cnt[bd]; | 
|  | 199 | atl1e_validate_option(&val, &opt, pdev); | 
|  | 200 | adapter->tx_ring.count = (u16) val & 0xFFFC; | 
|  | 201 | } else | 
|  | 202 | adapter->tx_ring.count = (u16)opt.def; | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | { 		/* Receive Memory Block Count */ | 
|  | 206 | struct atl1e_option opt = { | 
|  | 207 | .type = range_option, | 
|  | 208 | .name = "Memory size of rx buffer(KB)", | 
|  | 209 | .err  = "using default of " | 
|  | 210 | __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE), | 
|  | 211 | .def  = ATL1E_DEFAULT_RX_MEM_SIZE, | 
|  | 212 | .arg  = { .r = { .min = ATL1E_MIN_RX_MEM_SIZE, | 
|  | 213 | .max = ATL1E_MAX_RX_MEM_SIZE} } | 
|  | 214 | }; | 
|  | 215 | int val; | 
|  | 216 | if (num_rx_mem_size > bd) { | 
|  | 217 | val = rx_mem_size[bd]; | 
|  | 218 | atl1e_validate_option(&val, &opt, pdev); | 
|  | 219 | adapter->rx_ring.page_size = (u32)val * 1024; | 
|  | 220 | } else { | 
|  | 221 | adapter->rx_ring.page_size = (u32)opt.def * 1024; | 
|  | 222 | } | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | { 		/* Interrupt Moderate Timer */ | 
|  | 226 | struct atl1e_option opt = { | 
|  | 227 | .type = range_option, | 
|  | 228 | .name = "Interrupt Moderate Timer", | 
|  | 229 | .err  = "using default of " | 
|  | 230 | __MODULE_STRING(INT_MOD_DEFAULT_CNT), | 
|  | 231 | .def  = INT_MOD_DEFAULT_CNT, | 
|  | 232 | .arg  = { .r = { .min = INT_MOD_MIN_CNT, | 
|  | 233 | .max = INT_MOD_MAX_CNT} } | 
|  | 234 | } ; | 
|  | 235 | int val; | 
|  | 236 | if (num_int_mod_timer > bd) { | 
|  | 237 | val = int_mod_timer[bd]; | 
|  | 238 | atl1e_validate_option(&val, &opt, pdev); | 
|  | 239 | adapter->hw.imt = (u16) val; | 
|  | 240 | } else | 
|  | 241 | adapter->hw.imt = (u16)(opt.def); | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | { 		/* MediaType */ | 
|  | 245 | struct atl1e_option opt = { | 
|  | 246 | .type = range_option, | 
|  | 247 | .name = "Speed/Duplex Selection", | 
|  | 248 | .err  = "using default of " | 
|  | 249 | __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR), | 
|  | 250 | .def  = MEDIA_TYPE_AUTO_SENSOR, | 
|  | 251 | .arg  = { .r = { .min = MEDIA_TYPE_AUTO_SENSOR, | 
|  | 252 | .max = MEDIA_TYPE_10M_HALF} } | 
|  | 253 | } ; | 
|  | 254 | int val; | 
|  | 255 | if (num_media_type > bd) { | 
|  | 256 | val = media_type[bd]; | 
|  | 257 | atl1e_validate_option(&val, &opt, pdev); | 
|  | 258 | adapter->hw.media_type = (u16) val; | 
|  | 259 | } else | 
|  | 260 | adapter->hw.media_type = (u16)(opt.def); | 
|  | 261 |  | 
|  | 262 | } | 
|  | 263 | } |