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