0001
0002
0003
0004 #include <linux/netdevice.h>
0005 #include <linux/module.h>
0006 #include <linux/pci.h>
0007
0008 #include "e1000.h"
0009
0010
0011
0012
0013 #define E1000_MAX_NIC 32
0014
0015 #define OPTION_UNSET -1
0016 #define OPTION_DISABLED 0
0017 #define OPTION_ENABLED 1
0018
0019 #define COPYBREAK_DEFAULT 256
0020 unsigned int copybreak = COPYBREAK_DEFAULT;
0021 module_param(copybreak, uint, 0644);
0022 MODULE_PARM_DESC(copybreak,
0023 "Maximum size of packet that is copied to a new buffer on receive");
0024
0025
0026
0027
0028
0029 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
0030 #define E1000_PARAM(X, desc) \
0031 static int X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
0032 static unsigned int num_##X; \
0033 module_param_array_named(X, X, int, &num_##X, 0); \
0034 MODULE_PARM_DESC(X, desc);
0035
0036
0037
0038
0039
0040
0041 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
0042 #define DEFAULT_TIDV 8
0043 #define MAX_TXDELAY 0xFFFF
0044 #define MIN_TXDELAY 0
0045
0046
0047
0048
0049
0050 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
0051 #define DEFAULT_TADV 32
0052 #define MAX_TXABSDELAY 0xFFFF
0053 #define MIN_TXABSDELAY 0
0054
0055
0056
0057
0058
0059
0060
0061
0062 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
0063 #define DEFAULT_RDTR 0
0064 #define BURST_RDTR 0x20
0065 #define MAX_RXDELAY 0xFFFF
0066 #define MIN_RXDELAY 0
0067
0068
0069
0070
0071
0072
0073
0074 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
0075 #define DEFAULT_RADV 8
0076 #define BURST_RADV 0x20
0077 #define MAX_RXABSDELAY 0xFFFF
0078 #define MIN_RXABSDELAY 0
0079
0080
0081
0082
0083
0084 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
0085 #define DEFAULT_ITR 3
0086 #define MAX_ITR 100000
0087 #define MIN_ITR 100
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 E1000_PARAM(IntMode, "Interrupt Mode");
0104
0105
0106
0107
0108
0109
0110
0111 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
0112
0113
0114
0115
0116
0117
0118
0119 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
0120
0121
0122
0123
0124
0125
0126
0127 E1000_PARAM(WriteProtectNVM,
0128 "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
0129
0130
0131
0132
0133
0134
0135
0136 E1000_PARAM(CrcStripping,
0137 "Enable CRC Stripping, disable if your BMC needs the CRC");
0138
0139 struct e1000_option {
0140 enum { enable_option, range_option, list_option } type;
0141 const char *name;
0142 const char *err;
0143 int def;
0144 union {
0145
0146 struct {
0147 int min;
0148 int max;
0149 } r;
0150
0151 struct {
0152 int nr;
0153 struct e1000_opt_list {
0154 int i;
0155 char *str;
0156 } *p;
0157 } l;
0158 } arg;
0159 };
0160
0161 static int e1000_validate_option(unsigned int *value,
0162 const struct e1000_option *opt,
0163 struct e1000_adapter *adapter)
0164 {
0165 if (*value == OPTION_UNSET) {
0166 *value = opt->def;
0167 return 0;
0168 }
0169
0170 switch (opt->type) {
0171 case enable_option:
0172 switch (*value) {
0173 case OPTION_ENABLED:
0174 dev_info(&adapter->pdev->dev, "%s Enabled\n",
0175 opt->name);
0176 return 0;
0177 case OPTION_DISABLED:
0178 dev_info(&adapter->pdev->dev, "%s Disabled\n",
0179 opt->name);
0180 return 0;
0181 }
0182 break;
0183 case range_option:
0184 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
0185 dev_info(&adapter->pdev->dev, "%s set to %i\n",
0186 opt->name, *value);
0187 return 0;
0188 }
0189 break;
0190 case list_option: {
0191 int i;
0192 struct e1000_opt_list *ent;
0193
0194 for (i = 0; i < opt->arg.l.nr; i++) {
0195 ent = &opt->arg.l.p[i];
0196 if (*value == ent->i) {
0197 if (ent->str[0] != '\0')
0198 dev_info(&adapter->pdev->dev, "%s\n",
0199 ent->str);
0200 return 0;
0201 }
0202 }
0203 }
0204 break;
0205 default:
0206 BUG();
0207 }
0208
0209 dev_info(&adapter->pdev->dev, "Invalid %s value specified (%i) %s\n",
0210 opt->name, *value, opt->err);
0211 *value = opt->def;
0212 return -1;
0213 }
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224 void e1000e_check_options(struct e1000_adapter *adapter)
0225 {
0226 struct e1000_hw *hw = &adapter->hw;
0227 int bd = adapter->bd_number;
0228
0229 if (bd >= E1000_MAX_NIC) {
0230 dev_notice(&adapter->pdev->dev,
0231 "Warning: no configuration for board #%i\n", bd);
0232 dev_notice(&adapter->pdev->dev,
0233 "Using defaults for all values\n");
0234 }
0235
0236
0237 {
0238 static const struct e1000_option opt = {
0239 .type = range_option,
0240 .name = "Transmit Interrupt Delay",
0241 .err = "using default of "
0242 __MODULE_STRING(DEFAULT_TIDV),
0243 .def = DEFAULT_TIDV,
0244 .arg = { .r = { .min = MIN_TXDELAY,
0245 .max = MAX_TXDELAY } }
0246 };
0247
0248 if (num_TxIntDelay > bd) {
0249 adapter->tx_int_delay = TxIntDelay[bd];
0250 e1000_validate_option(&adapter->tx_int_delay, &opt,
0251 adapter);
0252 } else {
0253 adapter->tx_int_delay = opt.def;
0254 }
0255 }
0256
0257 {
0258 static const struct e1000_option opt = {
0259 .type = range_option,
0260 .name = "Transmit Absolute Interrupt Delay",
0261 .err = "using default of "
0262 __MODULE_STRING(DEFAULT_TADV),
0263 .def = DEFAULT_TADV,
0264 .arg = { .r = { .min = MIN_TXABSDELAY,
0265 .max = MAX_TXABSDELAY } }
0266 };
0267
0268 if (num_TxAbsIntDelay > bd) {
0269 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
0270 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
0271 adapter);
0272 } else {
0273 adapter->tx_abs_int_delay = opt.def;
0274 }
0275 }
0276
0277 {
0278 static struct e1000_option opt = {
0279 .type = range_option,
0280 .name = "Receive Interrupt Delay",
0281 .err = "using default of "
0282 __MODULE_STRING(DEFAULT_RDTR),
0283 .def = DEFAULT_RDTR,
0284 .arg = { .r = { .min = MIN_RXDELAY,
0285 .max = MAX_RXDELAY } }
0286 };
0287
0288 if (adapter->flags2 & FLAG2_DMA_BURST)
0289 opt.def = BURST_RDTR;
0290
0291 if (num_RxIntDelay > bd) {
0292 adapter->rx_int_delay = RxIntDelay[bd];
0293 e1000_validate_option(&adapter->rx_int_delay, &opt,
0294 adapter);
0295 } else {
0296 adapter->rx_int_delay = opt.def;
0297 }
0298 }
0299
0300 {
0301 static struct e1000_option opt = {
0302 .type = range_option,
0303 .name = "Receive Absolute Interrupt Delay",
0304 .err = "using default of "
0305 __MODULE_STRING(DEFAULT_RADV),
0306 .def = DEFAULT_RADV,
0307 .arg = { .r = { .min = MIN_RXABSDELAY,
0308 .max = MAX_RXABSDELAY } }
0309 };
0310
0311 if (adapter->flags2 & FLAG2_DMA_BURST)
0312 opt.def = BURST_RADV;
0313
0314 if (num_RxAbsIntDelay > bd) {
0315 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
0316 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
0317 adapter);
0318 } else {
0319 adapter->rx_abs_int_delay = opt.def;
0320 }
0321 }
0322
0323 {
0324 static const struct e1000_option opt = {
0325 .type = range_option,
0326 .name = "Interrupt Throttling Rate (ints/sec)",
0327 .err = "using default of "
0328 __MODULE_STRING(DEFAULT_ITR),
0329 .def = DEFAULT_ITR,
0330 .arg = { .r = { .min = MIN_ITR,
0331 .max = MAX_ITR } }
0332 };
0333
0334 if (num_InterruptThrottleRate > bd) {
0335 adapter->itr = InterruptThrottleRate[bd];
0336
0337
0338
0339
0340
0341
0342 if ((adapter->itr > 4) &&
0343 e1000_validate_option(&adapter->itr, &opt, adapter))
0344 adapter->itr = opt.def;
0345 } else {
0346
0347
0348
0349 adapter->itr = opt.def;
0350
0351
0352
0353
0354 if (adapter->itr > 4)
0355 dev_info(&adapter->pdev->dev,
0356 "%s set to default %d\n", opt.name,
0357 adapter->itr);
0358 }
0359
0360 adapter->itr_setting = adapter->itr;
0361 switch (adapter->itr) {
0362 case 0:
0363 dev_info(&adapter->pdev->dev, "%s turned off\n",
0364 opt.name);
0365 break;
0366 case 1:
0367 dev_info(&adapter->pdev->dev,
0368 "%s set to dynamic mode\n", opt.name);
0369 adapter->itr = 20000;
0370 break;
0371 case 2:
0372 dev_info(&adapter->pdev->dev,
0373 "%s Invalid mode - setting default\n",
0374 opt.name);
0375 adapter->itr_setting = opt.def;
0376 fallthrough;
0377 case 3:
0378 dev_info(&adapter->pdev->dev,
0379 "%s set to dynamic conservative mode\n",
0380 opt.name);
0381 adapter->itr = 20000;
0382 break;
0383 case 4:
0384 dev_info(&adapter->pdev->dev,
0385 "%s set to simplified (2000-8000 ints) mode\n",
0386 opt.name);
0387 break;
0388 default:
0389
0390
0391
0392
0393
0394
0395 adapter->itr_setting &= ~3;
0396 break;
0397 }
0398 }
0399
0400 {
0401 static struct e1000_option opt = {
0402 .type = range_option,
0403 .name = "Interrupt Mode",
0404 #ifndef CONFIG_PCI_MSI
0405 .err = "defaulting to 0 (legacy)",
0406 .def = E1000E_INT_MODE_LEGACY,
0407 .arg = { .r = { .min = 0,
0408 .max = 0 } }
0409 #endif
0410 };
0411
0412 #ifdef CONFIG_PCI_MSI
0413 if (adapter->flags & FLAG_HAS_MSIX) {
0414 opt.err = kstrdup("defaulting to 2 (MSI-X)",
0415 GFP_KERNEL);
0416 opt.def = E1000E_INT_MODE_MSIX;
0417 opt.arg.r.max = E1000E_INT_MODE_MSIX;
0418 } else {
0419 opt.err = kstrdup("defaulting to 1 (MSI)", GFP_KERNEL);
0420 opt.def = E1000E_INT_MODE_MSI;
0421 opt.arg.r.max = E1000E_INT_MODE_MSI;
0422 }
0423
0424 if (!opt.err) {
0425 dev_err(&adapter->pdev->dev,
0426 "Failed to allocate memory\n");
0427 return;
0428 }
0429 #endif
0430
0431 if (num_IntMode > bd) {
0432 unsigned int int_mode = IntMode[bd];
0433
0434 e1000_validate_option(&int_mode, &opt, adapter);
0435 adapter->int_mode = int_mode;
0436 } else {
0437 adapter->int_mode = opt.def;
0438 }
0439
0440 #ifdef CONFIG_PCI_MSI
0441 kfree(opt.err);
0442 #endif
0443 }
0444
0445 {
0446 static const struct e1000_option opt = {
0447 .type = enable_option,
0448 .name = "PHY Smart Power Down",
0449 .err = "defaulting to Disabled",
0450 .def = OPTION_DISABLED
0451 };
0452
0453 if (num_SmartPowerDownEnable > bd) {
0454 unsigned int spd = SmartPowerDownEnable[bd];
0455
0456 e1000_validate_option(&spd, &opt, adapter);
0457 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && spd)
0458 adapter->flags |= FLAG_SMART_POWER_DOWN;
0459 }
0460 }
0461
0462 {
0463 static const struct e1000_option opt = {
0464 .type = enable_option,
0465 .name = "CRC Stripping",
0466 .err = "defaulting to Enabled",
0467 .def = OPTION_ENABLED
0468 };
0469
0470 if (num_CrcStripping > bd) {
0471 unsigned int crc_stripping = CrcStripping[bd];
0472
0473 e1000_validate_option(&crc_stripping, &opt, adapter);
0474 if (crc_stripping == OPTION_ENABLED) {
0475 adapter->flags2 |= FLAG2_CRC_STRIPPING;
0476 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
0477 }
0478 } else {
0479 adapter->flags2 |= FLAG2_CRC_STRIPPING;
0480 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
0481 }
0482 }
0483
0484 {
0485 static const struct e1000_option opt = {
0486 .type = enable_option,
0487 .name = "Kumeran Lock Loss Workaround",
0488 .err = "defaulting to Enabled",
0489 .def = OPTION_ENABLED
0490 };
0491 bool enabled = opt.def;
0492
0493 if (num_KumeranLockLoss > bd) {
0494 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
0495
0496 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
0497 enabled = kmrn_lock_loss;
0498 }
0499
0500 if (hw->mac.type == e1000_ich8lan)
0501 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
0502 enabled);
0503 }
0504
0505 {
0506 static const struct e1000_option opt = {
0507 .type = enable_option,
0508 .name = "Write-protect NVM",
0509 .err = "defaulting to Enabled",
0510 .def = OPTION_ENABLED
0511 };
0512
0513 if (adapter->flags & FLAG_IS_ICH) {
0514 if (num_WriteProtectNVM > bd) {
0515 unsigned int write_protect_nvm =
0516 WriteProtectNVM[bd];
0517 e1000_validate_option(&write_protect_nvm, &opt,
0518 adapter);
0519 if (write_protect_nvm)
0520 adapter->flags |= FLAG_READ_ONLY_NVM;
0521 } else {
0522 if (opt.def)
0523 adapter->flags |= FLAG_READ_ONLY_NVM;
0524 }
0525 }
0526 }
0527 }