Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel PRO/1000 Linux driver |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2008 Intel Corporation. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
| 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/netdevice.h> |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 30 | #include <linux/pci.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 31 | |
| 32 | #include "e1000.h" |
| 33 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 34 | /* |
| 35 | * This is the only thing that needs to be changed to adjust the |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 36 | * maximum number of ports that the driver can manage. |
| 37 | */ |
| 38 | |
| 39 | #define E1000_MAX_NIC 32 |
| 40 | |
| 41 | #define OPTION_UNSET -1 |
| 42 | #define OPTION_DISABLED 0 |
| 43 | #define OPTION_ENABLED 1 |
| 44 | |
| 45 | #define COPYBREAK_DEFAULT 256 |
| 46 | unsigned int copybreak = COPYBREAK_DEFAULT; |
| 47 | module_param(copybreak, uint, 0644); |
| 48 | MODULE_PARM_DESC(copybreak, |
| 49 | "Maximum size of packet that is copied to a new buffer on receive"); |
| 50 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 51 | /* |
| 52 | * All parameters are treated the same, as an integer array of values. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 53 | * This macro just reduces the need to repeat the same declaration code |
| 54 | * over and over (plus this helps to avoid typo bugs). |
| 55 | */ |
| 56 | |
| 57 | #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET } |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 58 | #define E1000_PARAM(X, desc) \ |
| 59 | static int __devinitdata X[E1000_MAX_NIC+1] \ |
| 60 | = E1000_PARAM_INIT; \ |
| 61 | static unsigned int num_##X; \ |
| 62 | module_param_array_named(X, X, int, &num_##X, 0); \ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 63 | MODULE_PARM_DESC(X, desc); |
| 64 | |
| 65 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Transmit Interrupt Delay in units of 1.024 microseconds |
| 68 | * Tx interrupt delay needs to typically be set to something non zero |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 69 | * |
| 70 | * Valid Range: 0-65535 |
| 71 | */ |
| 72 | E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay"); |
| 73 | #define DEFAULT_TIDV 8 |
| 74 | #define MAX_TXDELAY 0xFFFF |
| 75 | #define MIN_TXDELAY 0 |
| 76 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 77 | /* |
| 78 | * Transmit Absolute Interrupt Delay in units of 1.024 microseconds |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 79 | * |
| 80 | * Valid Range: 0-65535 |
| 81 | */ |
| 82 | E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay"); |
| 83 | #define DEFAULT_TADV 32 |
| 84 | #define MAX_TXABSDELAY 0xFFFF |
| 85 | #define MIN_TXABSDELAY 0 |
| 86 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 87 | /* |
| 88 | * Receive Interrupt Delay in units of 1.024 microseconds |
| 89 | * hardware will likely hang if you set this to anything but zero. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 90 | * |
| 91 | * Valid Range: 0-65535 |
| 92 | */ |
| 93 | E1000_PARAM(RxIntDelay, "Receive Interrupt Delay"); |
| 94 | #define DEFAULT_RDTR 0 |
| 95 | #define MAX_RXDELAY 0xFFFF |
| 96 | #define MIN_RXDELAY 0 |
| 97 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Receive Absolute Interrupt Delay in units of 1.024 microseconds |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 100 | * |
| 101 | * Valid Range: 0-65535 |
| 102 | */ |
| 103 | E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay"); |
| 104 | #define DEFAULT_RADV 8 |
| 105 | #define MAX_RXABSDELAY 0xFFFF |
| 106 | #define MIN_RXABSDELAY 0 |
| 107 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 108 | /* |
| 109 | * Interrupt Throttle Rate (interrupts/sec) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 110 | * |
| 111 | * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative) |
| 112 | */ |
| 113 | E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate"); |
| 114 | #define DEFAULT_ITR 3 |
| 115 | #define MAX_ITR 100000 |
| 116 | #define MIN_ITR 100 |
| 117 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Enable Smart Power Down of the PHY |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 120 | * |
| 121 | * Valid Range: 0, 1 |
| 122 | * |
| 123 | * Default Value: 0 (disabled) |
| 124 | */ |
| 125 | E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down"); |
| 126 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 127 | /* |
| 128 | * Enable Kumeran Lock Loss workaround |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 129 | * |
| 130 | * Valid Range: 0, 1 |
| 131 | * |
| 132 | * Default Value: 1 (enabled) |
| 133 | */ |
| 134 | E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround"); |
| 135 | |
| 136 | struct e1000_option { |
| 137 | enum { enable_option, range_option, list_option } type; |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 138 | const char *name; |
| 139 | const char *err; |
| 140 | int def; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 141 | union { |
| 142 | struct { /* range_option info */ |
| 143 | int min; |
| 144 | int max; |
| 145 | } r; |
| 146 | struct { /* list_option info */ |
| 147 | int nr; |
| 148 | struct e1000_opt_list { int i; char *str; } *p; |
| 149 | } l; |
| 150 | } arg; |
| 151 | }; |
| 152 | |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 153 | static int __devinit e1000_validate_option(unsigned int *value, |
| 154 | const struct e1000_option *opt, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 155 | struct e1000_adapter *adapter) |
| 156 | { |
| 157 | if (*value == OPTION_UNSET) { |
| 158 | *value = opt->def; |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | switch (opt->type) { |
| 163 | case enable_option: |
| 164 | switch (*value) { |
| 165 | case OPTION_ENABLED: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 166 | e_info("%s Enabled\n", opt->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | case OPTION_DISABLED: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 169 | e_info("%s Disabled\n", opt->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | break; |
| 173 | case range_option: |
| 174 | if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 175 | e_info("%s set to %i\n", opt->name, *value); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | break; |
| 179 | case list_option: { |
| 180 | int i; |
| 181 | struct e1000_opt_list *ent; |
| 182 | |
| 183 | for (i = 0; i < opt->arg.l.nr; i++) { |
| 184 | ent = &opt->arg.l.p[i]; |
| 185 | if (*value == ent->i) { |
| 186 | if (ent->str[0] != '\0') |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 187 | e_info("%s\n", ent->str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | break; |
| 193 | default: |
| 194 | BUG(); |
| 195 | } |
| 196 | |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 197 | e_info("Invalid %s value specified (%i) %s\n", opt->name, *value, |
| 198 | opt->err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 199 | *value = opt->def; |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * e1000e_check_options - Range Checking for Command Line Parameters |
| 205 | * @adapter: board private structure |
| 206 | * |
| 207 | * This routine checks all command line parameters for valid user |
| 208 | * input. If an invalid value is given, or if no user specified |
| 209 | * value exists, a default value is used. The final value is stored |
| 210 | * in a variable in the adapter structure. |
| 211 | **/ |
| 212 | void __devinit e1000e_check_options(struct e1000_adapter *adapter) |
| 213 | { |
| 214 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 215 | int bd = adapter->bd_number; |
| 216 | |
| 217 | if (bd >= E1000_MAX_NIC) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 218 | e_notice("Warning: no configuration for board #%i\n", bd); |
| 219 | e_notice("Using defaults for all values\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | { /* Transmit Interrupt Delay */ |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 223 | const struct e1000_option opt = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 224 | .type = range_option, |
| 225 | .name = "Transmit Interrupt Delay", |
| 226 | .err = "using default of " |
| 227 | __MODULE_STRING(DEFAULT_TIDV), |
| 228 | .def = DEFAULT_TIDV, |
| 229 | .arg = { .r = { .min = MIN_TXDELAY, |
| 230 | .max = MAX_TXDELAY } } |
| 231 | }; |
| 232 | |
| 233 | if (num_TxIntDelay > bd) { |
| 234 | adapter->tx_int_delay = TxIntDelay[bd]; |
| 235 | e1000_validate_option(&adapter->tx_int_delay, &opt, |
| 236 | adapter); |
| 237 | } else { |
| 238 | adapter->tx_int_delay = opt.def; |
| 239 | } |
| 240 | } |
| 241 | { /* Transmit Absolute Interrupt Delay */ |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 242 | const struct e1000_option opt = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 243 | .type = range_option, |
| 244 | .name = "Transmit Absolute Interrupt Delay", |
| 245 | .err = "using default of " |
| 246 | __MODULE_STRING(DEFAULT_TADV), |
| 247 | .def = DEFAULT_TADV, |
| 248 | .arg = { .r = { .min = MIN_TXABSDELAY, |
| 249 | .max = MAX_TXABSDELAY } } |
| 250 | }; |
| 251 | |
| 252 | if (num_TxAbsIntDelay > bd) { |
| 253 | adapter->tx_abs_int_delay = TxAbsIntDelay[bd]; |
| 254 | e1000_validate_option(&adapter->tx_abs_int_delay, &opt, |
| 255 | adapter); |
| 256 | } else { |
| 257 | adapter->tx_abs_int_delay = opt.def; |
| 258 | } |
| 259 | } |
| 260 | { /* Receive Interrupt Delay */ |
| 261 | struct e1000_option opt = { |
| 262 | .type = range_option, |
| 263 | .name = "Receive Interrupt Delay", |
| 264 | .err = "using default of " |
| 265 | __MODULE_STRING(DEFAULT_RDTR), |
| 266 | .def = DEFAULT_RDTR, |
| 267 | .arg = { .r = { .min = MIN_RXDELAY, |
| 268 | .max = MAX_RXDELAY } } |
| 269 | }; |
| 270 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 271 | if (num_RxIntDelay > bd) { |
| 272 | adapter->rx_int_delay = RxIntDelay[bd]; |
| 273 | e1000_validate_option(&adapter->rx_int_delay, &opt, |
| 274 | adapter); |
| 275 | } else { |
| 276 | adapter->rx_int_delay = opt.def; |
| 277 | } |
| 278 | } |
| 279 | { /* Receive Absolute Interrupt Delay */ |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 280 | const struct e1000_option opt = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 281 | .type = range_option, |
| 282 | .name = "Receive Absolute Interrupt Delay", |
| 283 | .err = "using default of " |
| 284 | __MODULE_STRING(DEFAULT_RADV), |
| 285 | .def = DEFAULT_RADV, |
| 286 | .arg = { .r = { .min = MIN_RXABSDELAY, |
| 287 | .max = MAX_RXABSDELAY } } |
| 288 | }; |
| 289 | |
| 290 | if (num_RxAbsIntDelay > bd) { |
| 291 | adapter->rx_abs_int_delay = RxAbsIntDelay[bd]; |
| 292 | e1000_validate_option(&adapter->rx_abs_int_delay, &opt, |
| 293 | adapter); |
| 294 | } else { |
| 295 | adapter->rx_abs_int_delay = opt.def; |
| 296 | } |
| 297 | } |
| 298 | { /* Interrupt Throttling Rate */ |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 299 | const struct e1000_option opt = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 300 | .type = range_option, |
| 301 | .name = "Interrupt Throttling Rate (ints/sec)", |
| 302 | .err = "using default of " |
| 303 | __MODULE_STRING(DEFAULT_ITR), |
| 304 | .def = DEFAULT_ITR, |
| 305 | .arg = { .r = { .min = MIN_ITR, |
| 306 | .max = MAX_ITR } } |
| 307 | }; |
| 308 | |
| 309 | if (num_InterruptThrottleRate > bd) { |
| 310 | adapter->itr = InterruptThrottleRate[bd]; |
| 311 | switch (adapter->itr) { |
| 312 | case 0: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 313 | e_info("%s turned off\n", opt.name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 314 | break; |
| 315 | case 1: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 316 | e_info("%s set to dynamic mode\n", opt.name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 317 | adapter->itr_setting = adapter->itr; |
| 318 | adapter->itr = 20000; |
| 319 | break; |
| 320 | case 3: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 321 | e_info("%s set to dynamic conservative mode\n", |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 322 | opt.name); |
| 323 | adapter->itr_setting = adapter->itr; |
| 324 | adapter->itr = 20000; |
| 325 | break; |
| 326 | default: |
| 327 | e1000_validate_option(&adapter->itr, &opt, |
| 328 | adapter); |
| 329 | /* |
Bruce Allan | 2d06cad | 2008-08-08 18:35:51 -0700 | [diff] [blame^] | 330 | * Save the setting, because the dynamic bits |
| 331 | * change itr. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 332 | */ |
Bruce Allan | 2d06cad | 2008-08-08 18:35:51 -0700 | [diff] [blame^] | 333 | if (e1000_validate_option(&adapter->itr, &opt, |
| 334 | adapter) && |
| 335 | (adapter->itr == 3)) { |
| 336 | /* |
| 337 | * In case of invalid user value, |
| 338 | * default to conservative mode. |
| 339 | */ |
| 340 | adapter->itr_setting = adapter->itr; |
| 341 | adapter->itr = 20000; |
| 342 | } else { |
| 343 | /* |
| 344 | * Clear the lower two bits because |
| 345 | * they are used as control. |
| 346 | */ |
| 347 | adapter->itr_setting = |
| 348 | adapter->itr & ~3; |
| 349 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 350 | break; |
| 351 | } |
| 352 | } else { |
| 353 | adapter->itr_setting = opt.def; |
| 354 | adapter->itr = 20000; |
| 355 | } |
| 356 | } |
| 357 | { /* Smart Power Down */ |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 358 | const struct e1000_option opt = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 359 | .type = enable_option, |
| 360 | .name = "PHY Smart Power Down", |
| 361 | .err = "defaulting to Disabled", |
| 362 | .def = OPTION_DISABLED |
| 363 | }; |
| 364 | |
| 365 | if (num_SmartPowerDownEnable > bd) { |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 366 | unsigned int spd = SmartPowerDownEnable[bd]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 367 | e1000_validate_option(&spd, &opt, adapter); |
| 368 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) |
| 369 | && spd) |
| 370 | adapter->flags |= FLAG_SMART_POWER_DOWN; |
| 371 | } |
| 372 | } |
| 373 | { /* Kumeran Lock Loss Workaround */ |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 374 | const struct e1000_option opt = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 375 | .type = enable_option, |
| 376 | .name = "Kumeran Lock Loss Workaround", |
| 377 | .err = "defaulting to Enabled", |
| 378 | .def = OPTION_ENABLED |
| 379 | }; |
| 380 | |
| 381 | if (num_KumeranLockLoss > bd) { |
Stephen Hemminger | 5a9147b | 2007-10-29 10:46:05 -0700 | [diff] [blame] | 382 | unsigned int kmrn_lock_loss = KumeranLockLoss[bd]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 383 | e1000_validate_option(&kmrn_lock_loss, &opt, adapter); |
| 384 | if (hw->mac.type == e1000_ich8lan) |
| 385 | e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, |
| 386 | kmrn_lock_loss); |
| 387 | } else { |
| 388 | if (hw->mac.type == e1000_ich8lan) |
| 389 | e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, |
| 390 | opt.def); |
| 391 | } |
| 392 | } |
| 393 | } |