1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 #include <linux/netdevice.h>
5 #include <linux/module.h>
10 /* This is the only thing that needs to be changed to adjust the
11 * maximum number of ports that the driver can manage.
13 #define E1000_MAX_NIC 32
15 #define OPTION_UNSET -1
16 #define OPTION_DISABLED 0
17 #define OPTION_ENABLED 1
19 #define COPYBREAK_DEFAULT 256
20 unsigned int copybreak
= COPYBREAK_DEFAULT
;
21 module_param(copybreak
, uint
, 0644);
22 MODULE_PARM_DESC(copybreak
,
23 "Maximum size of packet that is copied to a new buffer on receive");
25 /* All parameters are treated the same, as an integer array of values.
26 * This macro just reduces the need to repeat the same declaration code
27 * over and over (plus this helps to avoid typo bugs).
29 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
30 #define E1000_PARAM(X, desc) \
31 static int X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
32 static unsigned int num_##X; \
33 module_param_array_named(X, X, int, &num_##X, 0); \
34 MODULE_PARM_DESC(X, desc);
36 /* Transmit Interrupt Delay in units of 1.024 microseconds
37 * Tx interrupt delay needs to typically be set to something non-zero
39 * Valid Range: 0-65535
41 E1000_PARAM(TxIntDelay
, "Transmit Interrupt Delay");
42 #define DEFAULT_TIDV 8
43 #define MAX_TXDELAY 0xFFFF
46 /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
48 * Valid Range: 0-65535
50 E1000_PARAM(TxAbsIntDelay
, "Transmit Absolute Interrupt Delay");
51 #define DEFAULT_TADV 32
52 #define MAX_TXABSDELAY 0xFFFF
53 #define MIN_TXABSDELAY 0
55 /* Receive Interrupt Delay in units of 1.024 microseconds
56 * hardware will likely hang if you set this to anything but zero.
58 * Burst variant is used as default if device has FLAG2_DMA_BURST.
60 * Valid Range: 0-65535
62 E1000_PARAM(RxIntDelay
, "Receive Interrupt Delay");
63 #define DEFAULT_RDTR 0
64 #define BURST_RDTR 0x20
65 #define MAX_RXDELAY 0xFFFF
68 /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
70 * Burst variant is used as default if device has FLAG2_DMA_BURST.
72 * Valid Range: 0-65535
74 E1000_PARAM(RxAbsIntDelay
, "Receive Absolute Interrupt Delay");
75 #define DEFAULT_RADV 8
76 #define BURST_RADV 0x20
77 #define MAX_RXABSDELAY 0xFFFF
78 #define MIN_RXABSDELAY 0
80 /* Interrupt Throttle Rate (interrupts/sec)
82 * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative
84 E1000_PARAM(InterruptThrottleRate
, "Interrupt Throttling Rate");
86 #define MAX_ITR 100000
89 /* IntMode (Interrupt Mode)
91 * Valid Range: varies depending on kernel configuration & hardware support
93 * legacy=0, MSI=1, MSI-X=2
95 * When MSI/MSI-X support is enabled in kernel-
96 * Default Value: 2 (MSI-X) when supported by hardware, 1 (MSI) otherwise
97 * When MSI/MSI-X support is not enabled in kernel-
98 * Default Value: 0 (legacy)
100 * When a mode is specified that is not allowed/supported, it will be
101 * demoted to the most advanced interrupt mode available.
103 E1000_PARAM(IntMode
, "Interrupt Mode");
104 #define MAX_INTMODE 2
105 #define MIN_INTMODE 0
107 /* Enable Smart Power Down of the PHY
111 * Default Value: 0 (disabled)
113 E1000_PARAM(SmartPowerDownEnable
, "Enable PHY smart power down");
115 /* Enable Kumeran Lock Loss workaround
119 * Default Value: 1 (enabled)
121 E1000_PARAM(KumeranLockLoss
, "Enable Kumeran lock loss workaround");
127 * Default Value: 1 (enabled)
129 E1000_PARAM(WriteProtectNVM
,
130 "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
132 /* Enable CRC Stripping
136 * Default Value: 1 (enabled)
138 E1000_PARAM(CrcStripping
,
139 "Enable CRC Stripping, disable if your BMC needs the CRC");
141 struct e1000_option
{
142 enum { enable_option
, range_option
, list_option
} type
;
147 /* range_option info */
152 /* list_option info */
155 struct e1000_opt_list
{
163 static int e1000_validate_option(unsigned int *value
,
164 const struct e1000_option
*opt
,
165 struct e1000_adapter
*adapter
)
167 if (*value
== OPTION_UNSET
) {
176 dev_info(&adapter
->pdev
->dev
, "%s Enabled\n",
179 case OPTION_DISABLED
:
180 dev_info(&adapter
->pdev
->dev
, "%s Disabled\n",
186 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
187 dev_info(&adapter
->pdev
->dev
, "%s set to %i\n",
194 struct e1000_opt_list
*ent
;
196 for (i
= 0; i
< opt
->arg
.l
.nr
; i
++) {
197 ent
= &opt
->arg
.l
.p
[i
];
198 if (*value
== ent
->i
) {
199 if (ent
->str
[0] != '\0')
200 dev_info(&adapter
->pdev
->dev
, "%s\n",
211 dev_info(&adapter
->pdev
->dev
, "Invalid %s value specified (%i) %s\n",
212 opt
->name
, *value
, opt
->err
);
218 * e1000e_check_options - Range Checking for Command Line Parameters
219 * @adapter: board private structure
221 * This routine checks all command line parameters for valid user
222 * input. If an invalid value is given, or if no user specified
223 * value exists, a default value is used. The final value is stored
224 * in a variable in the adapter structure.
226 void e1000e_check_options(struct e1000_adapter
*adapter
)
228 struct e1000_hw
*hw
= &adapter
->hw
;
229 int bd
= adapter
->bd_number
;
231 if (bd
>= E1000_MAX_NIC
) {
232 dev_notice(&adapter
->pdev
->dev
,
233 "Warning: no configuration for board #%i\n", bd
);
234 dev_notice(&adapter
->pdev
->dev
,
235 "Using defaults for all values\n");
238 /* Transmit Interrupt Delay */
240 static const struct e1000_option opt
= {
241 .type
= range_option
,
242 .name
= "Transmit Interrupt Delay",
243 .err
= "using default of "
244 __MODULE_STRING(DEFAULT_TIDV
),
246 .arg
= { .r
= { .min
= MIN_TXDELAY
,
247 .max
= MAX_TXDELAY
} }
250 if (num_TxIntDelay
> bd
) {
251 adapter
->tx_int_delay
= TxIntDelay
[bd
];
252 e1000_validate_option(&adapter
->tx_int_delay
, &opt
,
255 adapter
->tx_int_delay
= opt
.def
;
258 /* Transmit Absolute Interrupt Delay */
260 static const struct e1000_option opt
= {
261 .type
= range_option
,
262 .name
= "Transmit Absolute Interrupt Delay",
263 .err
= "using default of "
264 __MODULE_STRING(DEFAULT_TADV
),
266 .arg
= { .r
= { .min
= MIN_TXABSDELAY
,
267 .max
= MAX_TXABSDELAY
} }
270 if (num_TxAbsIntDelay
> bd
) {
271 adapter
->tx_abs_int_delay
= TxAbsIntDelay
[bd
];
272 e1000_validate_option(&adapter
->tx_abs_int_delay
, &opt
,
275 adapter
->tx_abs_int_delay
= opt
.def
;
278 /* Receive Interrupt Delay */
280 static struct e1000_option opt
= {
281 .type
= range_option
,
282 .name
= "Receive Interrupt Delay",
283 .err
= "using default of "
284 __MODULE_STRING(DEFAULT_RDTR
),
286 .arg
= { .r
= { .min
= MIN_RXDELAY
,
287 .max
= MAX_RXDELAY
} }
290 if (adapter
->flags2
& FLAG2_DMA_BURST
)
291 opt
.def
= BURST_RDTR
;
293 if (num_RxIntDelay
> bd
) {
294 adapter
->rx_int_delay
= RxIntDelay
[bd
];
295 e1000_validate_option(&adapter
->rx_int_delay
, &opt
,
298 adapter
->rx_int_delay
= opt
.def
;
301 /* Receive Absolute Interrupt Delay */
303 static struct e1000_option opt
= {
304 .type
= range_option
,
305 .name
= "Receive Absolute Interrupt Delay",
306 .err
= "using default of "
307 __MODULE_STRING(DEFAULT_RADV
),
309 .arg
= { .r
= { .min
= MIN_RXABSDELAY
,
310 .max
= MAX_RXABSDELAY
} }
313 if (adapter
->flags2
& FLAG2_DMA_BURST
)
314 opt
.def
= BURST_RADV
;
316 if (num_RxAbsIntDelay
> bd
) {
317 adapter
->rx_abs_int_delay
= RxAbsIntDelay
[bd
];
318 e1000_validate_option(&adapter
->rx_abs_int_delay
, &opt
,
321 adapter
->rx_abs_int_delay
= opt
.def
;
324 /* 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
),
332 .arg
= { .r
= { .min
= MIN_ITR
,
336 if (num_InterruptThrottleRate
> bd
) {
337 adapter
->itr
= InterruptThrottleRate
[bd
];
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
344 if ((adapter
->itr
> 4) &&
345 e1000_validate_option(&adapter
->itr
, &opt
, adapter
))
346 adapter
->itr
= opt
.def
;
348 /* If no option specified, use default value and go
349 * through the logic below to adjust itr/itr_setting
351 adapter
->itr
= opt
.def
;
353 /* Make sure a message is printed for non-special
356 if (adapter
->itr
> 4)
357 dev_info(&adapter
->pdev
->dev
,
358 "%s set to default %d\n", opt
.name
,
362 adapter
->itr_setting
= adapter
->itr
;
363 switch (adapter
->itr
) {
365 dev_info(&adapter
->pdev
->dev
, "%s turned off\n",
369 dev_info(&adapter
->pdev
->dev
,
370 "%s set to dynamic mode\n", opt
.name
);
371 adapter
->itr
= 20000;
374 dev_info(&adapter
->pdev
->dev
,
375 "%s Invalid mode - setting default\n",
377 adapter
->itr_setting
= opt
.def
;
380 dev_info(&adapter
->pdev
->dev
,
381 "%s set to dynamic conservative mode\n",
383 adapter
->itr
= 20000;
386 dev_info(&adapter
->pdev
->dev
,
387 "%s set to simplified (2000-8000 ints) mode\n",
391 /* Save the setting, because the dynamic bits
394 * Clear the lower two bits because
395 * they are used as control.
397 adapter
->itr_setting
&= ~3;
403 static struct e1000_option opt
= {
404 .type
= range_option
,
405 .name
= "Interrupt Mode",
406 #ifndef CONFIG_PCI_MSI
407 .err
= "defaulting to 0 (legacy)",
408 .def
= E1000E_INT_MODE_LEGACY
,
409 .arg
= { .r
= { .min
= 0,
414 #ifdef CONFIG_PCI_MSI
415 if (adapter
->flags
& FLAG_HAS_MSIX
) {
416 opt
.err
= kstrdup("defaulting to 2 (MSI-X)",
418 opt
.def
= E1000E_INT_MODE_MSIX
;
419 opt
.arg
.r
.max
= E1000E_INT_MODE_MSIX
;
421 opt
.err
= kstrdup("defaulting to 1 (MSI)", GFP_KERNEL
);
422 opt
.def
= E1000E_INT_MODE_MSI
;
423 opt
.arg
.r
.max
= E1000E_INT_MODE_MSI
;
427 dev_err(&adapter
->pdev
->dev
,
428 "Failed to allocate memory\n");
433 if (num_IntMode
> bd
) {
434 unsigned int int_mode
= IntMode
[bd
];
436 e1000_validate_option(&int_mode
, &opt
, adapter
);
437 adapter
->int_mode
= int_mode
;
439 adapter
->int_mode
= opt
.def
;
442 #ifdef CONFIG_PCI_MSI
446 /* Smart Power Down */
448 static const struct e1000_option opt
= {
449 .type
= enable_option
,
450 .name
= "PHY Smart Power Down",
451 .err
= "defaulting to Disabled",
452 .def
= OPTION_DISABLED
455 if (num_SmartPowerDownEnable
> bd
) {
456 unsigned int spd
= SmartPowerDownEnable
[bd
];
458 e1000_validate_option(&spd
, &opt
, adapter
);
459 if ((adapter
->flags
& FLAG_HAS_SMART_POWER_DOWN
) && spd
)
460 adapter
->flags
|= FLAG_SMART_POWER_DOWN
;
465 static const struct e1000_option opt
= {
466 .type
= enable_option
,
467 .name
= "CRC Stripping",
468 .err
= "defaulting to Enabled",
469 .def
= OPTION_ENABLED
472 if (num_CrcStripping
> bd
) {
473 unsigned int crc_stripping
= CrcStripping
[bd
];
475 e1000_validate_option(&crc_stripping
, &opt
, adapter
);
476 if (crc_stripping
== OPTION_ENABLED
) {
477 adapter
->flags2
|= FLAG2_CRC_STRIPPING
;
478 adapter
->flags2
|= FLAG2_DFLT_CRC_STRIPPING
;
481 adapter
->flags2
|= FLAG2_CRC_STRIPPING
;
482 adapter
->flags2
|= FLAG2_DFLT_CRC_STRIPPING
;
485 /* Kumeran Lock Loss Workaround */
487 static const struct e1000_option opt
= {
488 .type
= enable_option
,
489 .name
= "Kumeran Lock Loss Workaround",
490 .err
= "defaulting to Enabled",
491 .def
= OPTION_ENABLED
493 bool enabled
= opt
.def
;
495 if (num_KumeranLockLoss
> bd
) {
496 unsigned int kmrn_lock_loss
= KumeranLockLoss
[bd
];
498 e1000_validate_option(&kmrn_lock_loss
, &opt
, adapter
);
499 enabled
= kmrn_lock_loss
;
502 if (hw
->mac
.type
== e1000_ich8lan
)
503 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw
,
506 /* Write-protect NVM */
508 static const struct e1000_option opt
= {
509 .type
= enable_option
,
510 .name
= "Write-protect NVM",
511 .err
= "defaulting to Enabled",
512 .def
= OPTION_ENABLED
515 if (adapter
->flags
& FLAG_IS_ICH
) {
516 if (num_WriteProtectNVM
> bd
) {
517 unsigned int write_protect_nvm
=
519 e1000_validate_option(&write_protect_nvm
, &opt
,
521 if (write_protect_nvm
)
522 adapter
->flags
|= FLAG_READ_ONLY_NVM
;
525 adapter
->flags
|= FLAG_READ_ONLY_NVM
;