1 /******************************************************************************* 2 3 Intel PRO/1000 Linux driver 4 Copyright(c) 1999 - 2013 Intel Corporation. 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> 30 #include <linux/module.h> 31 #include <linux/pci.h> 32 33 #include "e1000.h" 34 35 /* This is the only thing that needs to be changed to adjust the 36 * maximum number of ports that the driver can manage. 37 */ 38 #define E1000_MAX_NIC 32 39 40 #define OPTION_UNSET -1 41 #define OPTION_DISABLED 0 42 #define OPTION_ENABLED 1 43 44 #define COPYBREAK_DEFAULT 256 45 unsigned int copybreak = COPYBREAK_DEFAULT; 46 module_param(copybreak, uint, 0644); 47 MODULE_PARM_DESC(copybreak, 48 "Maximum size of packet that is copied to a new buffer on receive"); 49 50 /* All parameters are treated the same, as an integer array of values. 51 * This macro just reduces the need to repeat the same declaration code 52 * over and over (plus this helps to avoid typo bugs). 53 */ 54 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET } 55 #define E1000_PARAM(X, desc) \ 56 static int X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \ 57 static unsigned int num_##X; \ 58 module_param_array_named(X, X, int, &num_##X, 0); \ 59 MODULE_PARM_DESC(X, desc); 60 61 /* Transmit Interrupt Delay in units of 1.024 microseconds 62 * Tx interrupt delay needs to typically be set to something non-zero 63 * 64 * Valid Range: 0-65535 65 */ 66 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay"); 67 #define DEFAULT_TIDV 8 68 #define MAX_TXDELAY 0xFFFF 69 #define MIN_TXDELAY 0 70 71 /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds 72 * 73 * Valid Range: 0-65535 74 */ 75 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay"); 76 #define DEFAULT_TADV 32 77 #define MAX_TXABSDELAY 0xFFFF 78 #define MIN_TXABSDELAY 0 79 80 /* Receive Interrupt Delay in units of 1.024 microseconds 81 * hardware will likely hang if you set this to anything but zero. 82 * 83 * Valid Range: 0-65535 84 */ 85 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay"); 86 #define MAX_RXDELAY 0xFFFF 87 #define MIN_RXDELAY 0 88 89 /* Receive Absolute Interrupt Delay in units of 1.024 microseconds 90 * 91 * Valid Range: 0-65535 92 */ 93 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay"); 94 #define MAX_RXABSDELAY 0xFFFF 95 #define MIN_RXABSDELAY 0 96 97 /* Interrupt Throttle Rate (interrupts/sec) 98 * 99 * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative 100 */ 101 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate"); 102 #define DEFAULT_ITR 3 103 #define MAX_ITR 100000 104 #define MIN_ITR 100 105 106 /* IntMode (Interrupt Mode) 107 * 108 * Valid Range: varies depending on kernel configuration & hardware support 109 * 110 * legacy=0, MSI=1, MSI-X=2 111 * 112 * When MSI/MSI-X support is enabled in kernel- 113 * Default Value: 2 (MSI-X) when supported by hardware, 1 (MSI) otherwise 114 * When MSI/MSI-X support is not enabled in kernel- 115 * Default Value: 0 (legacy) 116 * 117 * When a mode is specified that is not allowed/supported, it will be 118 * demoted to the most advanced interrupt mode available. 119 */ 120 E1000_PARAM(IntMode, "Interrupt Mode"); 121 #define MAX_INTMODE 2 122 #define MIN_INTMODE 0 123 124 /* Enable Smart Power Down of the PHY 125 * 126 * Valid Range: 0, 1 127 * 128 * Default Value: 0 (disabled) 129 */ 130 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down"); 131 132 /* Enable Kumeran Lock Loss workaround 133 * 134 * Valid Range: 0, 1 135 * 136 * Default Value: 1 (enabled) 137 */ 138 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround"); 139 140 /* Write Protect NVM 141 * 142 * Valid Range: 0, 1 143 * 144 * Default Value: 1 (enabled) 145 */ 146 E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]"); 147 148 /* Enable CRC Stripping 149 * 150 * Valid Range: 0, 1 151 * 152 * Default Value: 1 (enabled) 153 */ 154 E1000_PARAM(CrcStripping, 155 "Enable CRC Stripping, disable if your BMC needs the CRC"); 156 157 struct e1000_option { 158 enum { enable_option, range_option, list_option } type; 159 const char *name; 160 const char *err; 161 int def; 162 union { 163 struct { /* range_option info */ 164 int min; 165 int max; 166 } r; 167 struct { /* list_option info */ 168 int nr; 169 struct e1000_opt_list { int i; char *str; } *p; 170 } l; 171 } arg; 172 }; 173 174 static int e1000_validate_option(unsigned int *value, 175 const struct e1000_option *opt, 176 struct e1000_adapter *adapter) 177 { 178 if (*value == OPTION_UNSET) { 179 *value = opt->def; 180 return 0; 181 } 182 183 switch (opt->type) { 184 case enable_option: 185 switch (*value) { 186 case OPTION_ENABLED: 187 dev_info(&adapter->pdev->dev, "%s Enabled\n", 188 opt->name); 189 return 0; 190 case OPTION_DISABLED: 191 dev_info(&adapter->pdev->dev, "%s Disabled\n", 192 opt->name); 193 return 0; 194 } 195 break; 196 case range_option: 197 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { 198 dev_info(&adapter->pdev->dev, "%s set to %i\n", 199 opt->name, *value); 200 return 0; 201 } 202 break; 203 case list_option: { 204 int i; 205 struct e1000_opt_list *ent; 206 207 for (i = 0; i < opt->arg.l.nr; i++) { 208 ent = &opt->arg.l.p[i]; 209 if (*value == ent->i) { 210 if (ent->str[0] != '\0') 211 dev_info(&adapter->pdev->dev, "%s\n", 212 ent->str); 213 return 0; 214 } 215 } 216 } 217 break; 218 default: 219 BUG(); 220 } 221 222 dev_info(&adapter->pdev->dev, "Invalid %s value specified (%i) %s\n", 223 opt->name, *value, opt->err); 224 *value = opt->def; 225 return -1; 226 } 227 228 /** 229 * e1000e_check_options - Range Checking for Command Line Parameters 230 * @adapter: board private structure 231 * 232 * This routine checks all command line parameters for valid user 233 * input. If an invalid value is given, or if no user specified 234 * value exists, a default value is used. The final value is stored 235 * in a variable in the adapter structure. 236 **/ 237 void e1000e_check_options(struct e1000_adapter *adapter) 238 { 239 struct e1000_hw *hw = &adapter->hw; 240 int bd = adapter->bd_number; 241 242 if (bd >= E1000_MAX_NIC) { 243 dev_notice(&adapter->pdev->dev, 244 "Warning: no configuration for board #%i\n", bd); 245 dev_notice(&adapter->pdev->dev, 246 "Using defaults for all values\n"); 247 } 248 249 { /* Transmit Interrupt Delay */ 250 static const struct e1000_option opt = { 251 .type = range_option, 252 .name = "Transmit Interrupt Delay", 253 .err = "using default of " 254 __MODULE_STRING(DEFAULT_TIDV), 255 .def = DEFAULT_TIDV, 256 .arg = { .r = { .min = MIN_TXDELAY, 257 .max = MAX_TXDELAY } } 258 }; 259 260 if (num_TxIntDelay > bd) { 261 adapter->tx_int_delay = TxIntDelay[bd]; 262 e1000_validate_option(&adapter->tx_int_delay, &opt, 263 adapter); 264 } else { 265 adapter->tx_int_delay = opt.def; 266 } 267 } 268 { /* Transmit Absolute Interrupt Delay */ 269 static const struct e1000_option opt = { 270 .type = range_option, 271 .name = "Transmit Absolute Interrupt Delay", 272 .err = "using default of " 273 __MODULE_STRING(DEFAULT_TADV), 274 .def = DEFAULT_TADV, 275 .arg = { .r = { .min = MIN_TXABSDELAY, 276 .max = MAX_TXABSDELAY } } 277 }; 278 279 if (num_TxAbsIntDelay > bd) { 280 adapter->tx_abs_int_delay = TxAbsIntDelay[bd]; 281 e1000_validate_option(&adapter->tx_abs_int_delay, &opt, 282 adapter); 283 } else { 284 adapter->tx_abs_int_delay = opt.def; 285 } 286 } 287 { /* Receive Interrupt Delay */ 288 static struct e1000_option opt = { 289 .type = range_option, 290 .name = "Receive Interrupt Delay", 291 .err = "using default of " 292 __MODULE_STRING(DEFAULT_RDTR), 293 .def = DEFAULT_RDTR, 294 .arg = { .r = { .min = MIN_RXDELAY, 295 .max = MAX_RXDELAY } } 296 }; 297 298 if (num_RxIntDelay > bd) { 299 adapter->rx_int_delay = RxIntDelay[bd]; 300 e1000_validate_option(&adapter->rx_int_delay, &opt, 301 adapter); 302 } else { 303 adapter->rx_int_delay = opt.def; 304 } 305 } 306 { /* Receive Absolute Interrupt Delay */ 307 static const struct e1000_option opt = { 308 .type = range_option, 309 .name = "Receive Absolute Interrupt Delay", 310 .err = "using default of " 311 __MODULE_STRING(DEFAULT_RADV), 312 .def = DEFAULT_RADV, 313 .arg = { .r = { .min = MIN_RXABSDELAY, 314 .max = MAX_RXABSDELAY } } 315 }; 316 317 if (num_RxAbsIntDelay > bd) { 318 adapter->rx_abs_int_delay = RxAbsIntDelay[bd]; 319 e1000_validate_option(&adapter->rx_abs_int_delay, &opt, 320 adapter); 321 } else { 322 adapter->rx_abs_int_delay = opt.def; 323 } 324 } 325 { /* Interrupt Throttling Rate */ 326 static const struct e1000_option opt = { 327 .type = range_option, 328 .name = "Interrupt Throttling Rate (ints/sec)", 329 .err = "using default of " 330 __MODULE_STRING(DEFAULT_ITR), 331 .def = DEFAULT_ITR, 332 .arg = { .r = { .min = MIN_ITR, 333 .max = MAX_ITR } } 334 }; 335 336 if (num_InterruptThrottleRate > bd) { 337 adapter->itr = InterruptThrottleRate[bd]; 338 339 /* Make sure a message is printed for non-special 340 * values. And in case of an invalid option, display 341 * warning, use default and go through itr/itr_setting 342 * adjustment logic below 343 */ 344 if ((adapter->itr > 4) && 345 e1000_validate_option(&adapter->itr, &opt, adapter)) 346 adapter->itr = opt.def; 347 } else { 348 /* If no option specified, use default value and go 349 * through the logic below to adjust itr/itr_setting 350 */ 351 adapter->itr = opt.def; 352 353 /* Make sure a message is printed for non-special 354 * default values 355 */ 356 if (adapter->itr > 4) 357 dev_info(&adapter->pdev->dev, 358 "%s set to default %d\n", opt.name, 359 adapter->itr); 360 } 361 362 adapter->itr_setting = adapter->itr; 363 switch (adapter->itr) { 364 case 0: 365 dev_info(&adapter->pdev->dev, "%s turned off\n", 366 opt.name); 367 break; 368 case 1: 369 dev_info(&adapter->pdev->dev, 370 "%s set to dynamic mode\n", opt.name); 371 adapter->itr = 20000; 372 break; 373 case 3: 374 dev_info(&adapter->pdev->dev, 375 "%s set to dynamic conservative mode\n", 376 opt.name); 377 adapter->itr = 20000; 378 break; 379 case 4: 380 dev_info(&adapter->pdev->dev, 381 "%s set to simplified (2000-8000 ints) mode\n", 382 opt.name); 383 break; 384 default: 385 /* Save the setting, because the dynamic bits 386 * change itr. 387 * 388 * Clear the lower two bits because 389 * they are used as control. 390 */ 391 adapter->itr_setting &= ~3; 392 break; 393 } 394 } 395 { /* Interrupt Mode */ 396 static struct e1000_option opt = { 397 .type = range_option, 398 .name = "Interrupt Mode", 399 #ifndef CONFIG_PCI_MSI 400 .err = "defaulting to 0 (legacy)", 401 .def = E1000E_INT_MODE_LEGACY, 402 .arg = { .r = { .min = 0, 403 .max = 0 } } 404 #endif 405 }; 406 407 #ifdef CONFIG_PCI_MSI 408 if (adapter->flags & FLAG_HAS_MSIX) { 409 opt.err = kstrdup("defaulting to 2 (MSI-X)", 410 GFP_KERNEL); 411 opt.def = E1000E_INT_MODE_MSIX; 412 opt.arg.r.max = E1000E_INT_MODE_MSIX; 413 } else { 414 opt.err = kstrdup("defaulting to 1 (MSI)", GFP_KERNEL); 415 opt.def = E1000E_INT_MODE_MSI; 416 opt.arg.r.max = E1000E_INT_MODE_MSI; 417 } 418 419 if (!opt.err) { 420 dev_err(&adapter->pdev->dev, 421 "Failed to allocate memory\n"); 422 return; 423 } 424 #endif 425 426 if (num_IntMode > bd) { 427 unsigned int int_mode = IntMode[bd]; 428 e1000_validate_option(&int_mode, &opt, adapter); 429 adapter->int_mode = int_mode; 430 } else { 431 adapter->int_mode = opt.def; 432 } 433 434 #ifdef CONFIG_PCI_MSI 435 kfree(opt.err); 436 #endif 437 } 438 { /* Smart Power Down */ 439 static const struct e1000_option opt = { 440 .type = enable_option, 441 .name = "PHY Smart Power Down", 442 .err = "defaulting to Disabled", 443 .def = OPTION_DISABLED 444 }; 445 446 if (num_SmartPowerDownEnable > bd) { 447 unsigned int spd = SmartPowerDownEnable[bd]; 448 e1000_validate_option(&spd, &opt, adapter); 449 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && spd) 450 adapter->flags |= FLAG_SMART_POWER_DOWN; 451 } 452 } 453 { /* CRC Stripping */ 454 static const struct e1000_option opt = { 455 .type = enable_option, 456 .name = "CRC Stripping", 457 .err = "defaulting to Enabled", 458 .def = OPTION_ENABLED 459 }; 460 461 if (num_CrcStripping > bd) { 462 unsigned int crc_stripping = CrcStripping[bd]; 463 e1000_validate_option(&crc_stripping, &opt, adapter); 464 if (crc_stripping == OPTION_ENABLED) { 465 adapter->flags2 |= FLAG2_CRC_STRIPPING; 466 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING; 467 } 468 } else { 469 adapter->flags2 |= FLAG2_CRC_STRIPPING; 470 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING; 471 } 472 } 473 { /* Kumeran Lock Loss Workaround */ 474 static const struct e1000_option opt = { 475 .type = enable_option, 476 .name = "Kumeran Lock Loss Workaround", 477 .err = "defaulting to Enabled", 478 .def = OPTION_ENABLED 479 }; 480 481 if (num_KumeranLockLoss > bd) { 482 unsigned int kmrn_lock_loss = KumeranLockLoss[bd]; 483 e1000_validate_option(&kmrn_lock_loss, &opt, adapter); 484 if (hw->mac.type == e1000_ich8lan) 485 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 486 kmrn_lock_loss); 487 } else { 488 if (hw->mac.type == e1000_ich8lan) 489 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 490 opt.def); 491 } 492 } 493 { /* Write-protect NVM */ 494 static const struct e1000_option opt = { 495 .type = enable_option, 496 .name = "Write-protect NVM", 497 .err = "defaulting to Enabled", 498 .def = OPTION_ENABLED 499 }; 500 501 if (adapter->flags & FLAG_IS_ICH) { 502 if (num_WriteProtectNVM > bd) { 503 unsigned int write_protect_nvm = WriteProtectNVM[bd]; 504 e1000_validate_option(&write_protect_nvm, &opt, 505 adapter); 506 if (write_protect_nvm) 507 adapter->flags |= FLAG_READ_ONLY_NVM; 508 } else { 509 if (opt.def) 510 adapter->flags |= FLAG_READ_ONLY_NVM; 511 } 512 } 513 } 514 } 515