1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
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
27 *******************************************************************************/
29 #include <linux/netdevice.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
36 * This is the only thing that needs to be changed to adjust the
37 * maximum number of ports that the driver can manage.
40 #define E1000_MAX_NIC 32
42 #define OPTION_UNSET -1
43 #define OPTION_DISABLED 0
44 #define OPTION_ENABLED 1
46 #define COPYBREAK_DEFAULT 256
47 unsigned int copybreak
= COPYBREAK_DEFAULT
;
48 module_param(copybreak
, uint
, 0644);
49 MODULE_PARM_DESC(copybreak
,
50 "Maximum size of packet that is copied to a new buffer on receive");
53 * All parameters are treated the same, as an integer array of values.
54 * This macro just reduces the need to repeat the same declaration code
55 * over and over (plus this helps to avoid typo bugs).
58 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
59 #define E1000_PARAM(X, desc) \
60 static int __devinitdata X[E1000_MAX_NIC+1] \
62 static unsigned int num_##X; \
63 module_param_array_named(X, X, int, &num_##X, 0); \
64 MODULE_PARM_DESC(X, desc);
67 * Transmit Interrupt Delay in units of 1.024 microseconds
68 * Tx interrupt delay needs to typically be set to something non-zero
70 * Valid Range: 0-65535
72 E1000_PARAM(TxIntDelay
, "Transmit Interrupt Delay");
73 #define DEFAULT_TIDV 8
74 #define MAX_TXDELAY 0xFFFF
78 * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
80 * Valid Range: 0-65535
82 E1000_PARAM(TxAbsIntDelay
, "Transmit Absolute Interrupt Delay");
83 #define DEFAULT_TADV 32
84 #define MAX_TXABSDELAY 0xFFFF
85 #define MIN_TXABSDELAY 0
88 * Receive Interrupt Delay in units of 1.024 microseconds
89 * hardware will likely hang if you set this to anything but zero.
91 * Valid Range: 0-65535
93 E1000_PARAM(RxIntDelay
, "Receive Interrupt Delay");
94 #define MAX_RXDELAY 0xFFFF
98 * Receive Absolute Interrupt Delay in units of 1.024 microseconds
100 * Valid Range: 0-65535
102 E1000_PARAM(RxAbsIntDelay
, "Receive Absolute Interrupt Delay");
103 #define MAX_RXABSDELAY 0xFFFF
104 #define MIN_RXABSDELAY 0
107 * Interrupt Throttle Rate (interrupts/sec)
109 * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative
111 E1000_PARAM(InterruptThrottleRate
, "Interrupt Throttling Rate");
112 #define DEFAULT_ITR 3
113 #define MAX_ITR 100000
117 * IntMode (Interrupt Mode)
119 * Valid Range: varies depending on kernel configuration & hardware support
121 * legacy=0, MSI=1, MSI-X=2
123 * When MSI/MSI-X support is enabled in kernel-
124 * Default Value: 2 (MSI-X) when supported by hardware, 1 (MSI) otherwise
125 * When MSI/MSI-X support is not enabled in kernel-
126 * Default Value: 0 (legacy)
128 * When a mode is specified that is not allowed/supported, it will be
129 * demoted to the most advanced interrupt mode available.
131 E1000_PARAM(IntMode
, "Interrupt Mode");
132 #define MAX_INTMODE 2
133 #define MIN_INTMODE 0
136 * Enable Smart Power Down of the PHY
140 * Default Value: 0 (disabled)
142 E1000_PARAM(SmartPowerDownEnable
, "Enable PHY smart power down");
145 * Enable Kumeran Lock Loss workaround
149 * Default Value: 1 (enabled)
151 E1000_PARAM(KumeranLockLoss
, "Enable Kumeran lock loss workaround");
158 * Default Value: 1 (enabled)
160 E1000_PARAM(WriteProtectNVM
, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
163 * Enable CRC Stripping
167 * Default Value: 1 (enabled)
169 E1000_PARAM(CrcStripping
,
170 "Enable CRC Stripping, disable if your BMC needs the CRC");
172 struct e1000_option
{
173 enum { enable_option
, range_option
, list_option
} type
;
178 struct { /* range_option info */
182 struct { /* list_option info */
184 struct e1000_opt_list
{ int i
; char *str
; } *p
;
189 static int __devinit
e1000_validate_option(unsigned int *value
,
190 const struct e1000_option
*opt
,
191 struct e1000_adapter
*adapter
)
193 if (*value
== OPTION_UNSET
) {
202 dev_info(&adapter
->pdev
->dev
, "%s Enabled\n",
205 case OPTION_DISABLED
:
206 dev_info(&adapter
->pdev
->dev
, "%s Disabled\n",
212 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
213 dev_info(&adapter
->pdev
->dev
, "%s set to %i\n",
220 struct e1000_opt_list
*ent
;
222 for (i
= 0; i
< opt
->arg
.l
.nr
; i
++) {
223 ent
= &opt
->arg
.l
.p
[i
];
224 if (*value
== ent
->i
) {
225 if (ent
->str
[0] != '\0')
226 dev_info(&adapter
->pdev
->dev
, "%s\n",
237 dev_info(&adapter
->pdev
->dev
, "Invalid %s value specified (%i) %s\n",
238 opt
->name
, *value
, opt
->err
);
244 * e1000e_check_options - Range Checking for Command Line Parameters
245 * @adapter: board private structure
247 * This routine checks all command line parameters for valid user
248 * input. If an invalid value is given, or if no user specified
249 * value exists, a default value is used. The final value is stored
250 * in a variable in the adapter structure.
252 void __devinit
e1000e_check_options(struct e1000_adapter
*adapter
)
254 struct e1000_hw
*hw
= &adapter
->hw
;
255 int bd
= adapter
->bd_number
;
257 if (bd
>= E1000_MAX_NIC
) {
258 dev_notice(&adapter
->pdev
->dev
,
259 "Warning: no configuration for board #%i\n", bd
);
260 dev_notice(&adapter
->pdev
->dev
,
261 "Using defaults for all values\n");
264 { /* Transmit Interrupt Delay */
265 static const struct e1000_option opt
= {
266 .type
= range_option
,
267 .name
= "Transmit Interrupt Delay",
268 .err
= "using default of "
269 __MODULE_STRING(DEFAULT_TIDV
),
271 .arg
= { .r
= { .min
= MIN_TXDELAY
,
272 .max
= MAX_TXDELAY
} }
275 if (num_TxIntDelay
> bd
) {
276 adapter
->tx_int_delay
= TxIntDelay
[bd
];
277 e1000_validate_option(&adapter
->tx_int_delay
, &opt
,
280 adapter
->tx_int_delay
= opt
.def
;
283 { /* Transmit Absolute Interrupt Delay */
284 static const struct e1000_option opt
= {
285 .type
= range_option
,
286 .name
= "Transmit Absolute Interrupt Delay",
287 .err
= "using default of "
288 __MODULE_STRING(DEFAULT_TADV
),
290 .arg
= { .r
= { .min
= MIN_TXABSDELAY
,
291 .max
= MAX_TXABSDELAY
} }
294 if (num_TxAbsIntDelay
> bd
) {
295 adapter
->tx_abs_int_delay
= TxAbsIntDelay
[bd
];
296 e1000_validate_option(&adapter
->tx_abs_int_delay
, &opt
,
299 adapter
->tx_abs_int_delay
= opt
.def
;
302 { /* Receive Interrupt Delay */
303 static struct e1000_option opt
= {
304 .type
= range_option
,
305 .name
= "Receive Interrupt Delay",
306 .err
= "using default of "
307 __MODULE_STRING(DEFAULT_RDTR
),
309 .arg
= { .r
= { .min
= MIN_RXDELAY
,
310 .max
= MAX_RXDELAY
} }
313 if (num_RxIntDelay
> bd
) {
314 adapter
->rx_int_delay
= RxIntDelay
[bd
];
315 e1000_validate_option(&adapter
->rx_int_delay
, &opt
,
318 adapter
->rx_int_delay
= opt
.def
;
321 { /* Receive Absolute Interrupt Delay */
322 static const struct e1000_option opt
= {
323 .type
= range_option
,
324 .name
= "Receive Absolute Interrupt Delay",
325 .err
= "using default of "
326 __MODULE_STRING(DEFAULT_RADV
),
328 .arg
= { .r
= { .min
= MIN_RXABSDELAY
,
329 .max
= MAX_RXABSDELAY
} }
332 if (num_RxAbsIntDelay
> bd
) {
333 adapter
->rx_abs_int_delay
= RxAbsIntDelay
[bd
];
334 e1000_validate_option(&adapter
->rx_abs_int_delay
, &opt
,
337 adapter
->rx_abs_int_delay
= opt
.def
;
340 { /* Interrupt Throttling Rate */
341 static const struct e1000_option opt
= {
342 .type
= range_option
,
343 .name
= "Interrupt Throttling Rate (ints/sec)",
344 .err
= "using default of "
345 __MODULE_STRING(DEFAULT_ITR
),
347 .arg
= { .r
= { .min
= MIN_ITR
,
351 if (num_InterruptThrottleRate
> bd
) {
352 adapter
->itr
= InterruptThrottleRate
[bd
];
355 * Make sure a message is printed for non-special
356 * values. And in case of an invalid option, display
357 * warning, use default and go through itr/itr_setting
358 * adjustment logic below
360 if ((adapter
->itr
> 4) &&
361 e1000_validate_option(&adapter
->itr
, &opt
, adapter
))
362 adapter
->itr
= opt
.def
;
365 * If no option specified, use default value and go
366 * through the logic below to adjust itr/itr_setting
368 adapter
->itr
= opt
.def
;
371 * Make sure a message is printed for non-special
374 if (adapter
->itr
> 4)
375 dev_info(&adapter
->pdev
->dev
,
376 "%s set to default %d\n", opt
.name
,
380 adapter
->itr_setting
= adapter
->itr
;
381 switch (adapter
->itr
) {
383 dev_info(&adapter
->pdev
->dev
, "%s turned off\n",
387 dev_info(&adapter
->pdev
->dev
,
388 "%s set to dynamic mode\n", opt
.name
);
389 adapter
->itr
= 20000;
392 dev_info(&adapter
->pdev
->dev
,
393 "%s set to dynamic conservative mode\n",
395 adapter
->itr
= 20000;
398 dev_info(&adapter
->pdev
->dev
,
399 "%s set to simplified (2000-8000 ints) mode\n",
404 * Save the setting, because the dynamic bits
407 * Clear the lower two bits because
408 * they are used as control.
410 adapter
->itr_setting
&= ~3;
414 { /* Interrupt Mode */
415 static struct e1000_option opt
= {
416 .type
= range_option
,
417 .name
= "Interrupt Mode",
418 #ifndef CONFIG_PCI_MSI
419 .err
= "defaulting to 0 (legacy)",
420 .def
= E1000E_INT_MODE_LEGACY
,
421 .arg
= { .r
= { .min
= 0,
426 #ifdef CONFIG_PCI_MSI
427 if (adapter
->flags
& FLAG_HAS_MSIX
) {
428 opt
.err
= kstrdup("defaulting to 2 (MSI-X)",
430 opt
.def
= E1000E_INT_MODE_MSIX
;
431 opt
.arg
.r
.max
= E1000E_INT_MODE_MSIX
;
433 opt
.err
= kstrdup("defaulting to 1 (MSI)", GFP_KERNEL
);
434 opt
.def
= E1000E_INT_MODE_MSI
;
435 opt
.arg
.r
.max
= E1000E_INT_MODE_MSI
;
439 dev_err(&adapter
->pdev
->dev
,
440 "Failed to allocate memory\n");
445 if (num_IntMode
> bd
) {
446 unsigned int int_mode
= IntMode
[bd
];
447 e1000_validate_option(&int_mode
, &opt
, adapter
);
448 adapter
->int_mode
= int_mode
;
450 adapter
->int_mode
= opt
.def
;
453 #ifdef CONFIG_PCI_MSI
457 { /* Smart Power Down */
458 static const struct e1000_option opt
= {
459 .type
= enable_option
,
460 .name
= "PHY Smart Power Down",
461 .err
= "defaulting to Disabled",
462 .def
= OPTION_DISABLED
465 if (num_SmartPowerDownEnable
> bd
) {
466 unsigned int spd
= SmartPowerDownEnable
[bd
];
467 e1000_validate_option(&spd
, &opt
, adapter
);
468 if ((adapter
->flags
& FLAG_HAS_SMART_POWER_DOWN
)
470 adapter
->flags
|= FLAG_SMART_POWER_DOWN
;
473 { /* CRC Stripping */
474 static const struct e1000_option opt
= {
475 .type
= enable_option
,
476 .name
= "CRC Stripping",
477 .err
= "defaulting to Enabled",
478 .def
= OPTION_ENABLED
481 if (num_CrcStripping
> bd
) {
482 unsigned int crc_stripping
= CrcStripping
[bd
];
483 e1000_validate_option(&crc_stripping
, &opt
, adapter
);
484 if (crc_stripping
== OPTION_ENABLED
) {
485 adapter
->flags2
|= FLAG2_CRC_STRIPPING
;
486 adapter
->flags2
|= FLAG2_DFLT_CRC_STRIPPING
;
489 adapter
->flags2
|= FLAG2_CRC_STRIPPING
;
490 adapter
->flags2
|= FLAG2_DFLT_CRC_STRIPPING
;
493 { /* Kumeran Lock Loss Workaround */
494 static const struct e1000_option opt
= {
495 .type
= enable_option
,
496 .name
= "Kumeran Lock Loss Workaround",
497 .err
= "defaulting to Enabled",
498 .def
= OPTION_ENABLED
501 if (num_KumeranLockLoss
> bd
) {
502 unsigned int kmrn_lock_loss
= KumeranLockLoss
[bd
];
503 e1000_validate_option(&kmrn_lock_loss
, &opt
, adapter
);
504 if (hw
->mac
.type
== e1000_ich8lan
)
505 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw
,
508 if (hw
->mac
.type
== e1000_ich8lan
)
509 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw
,
513 { /* Write-protect NVM */
514 static const struct e1000_option opt
= {
515 .type
= enable_option
,
516 .name
= "Write-protect NVM",
517 .err
= "defaulting to Enabled",
518 .def
= OPTION_ENABLED
521 if (adapter
->flags
& FLAG_IS_ICH
) {
522 if (num_WriteProtectNVM
> bd
) {
523 unsigned int write_protect_nvm
= WriteProtectNVM
[bd
];
524 e1000_validate_option(&write_protect_nvm
, &opt
,
526 if (write_protect_nvm
)
527 adapter
->flags
|= FLAG_READ_ONLY_NVM
;
530 adapter
->flags
|= FLAG_READ_ONLY_NVM
;