1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2013 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>
35 /* This is the only thing that needs to be changed to adjust the
36 * maximum number of ports that the driver can manage.
38 #define E1000_MAX_NIC 32
40 #define OPTION_UNSET -1
41 #define OPTION_DISABLED 0
42 #define OPTION_ENABLED 1
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");
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).
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);
61 /* Transmit Interrupt Delay in units of 1.024 microseconds
62 * Tx interrupt delay needs to typically be set to something non-zero
64 * Valid Range: 0-65535
66 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
67 #define DEFAULT_TIDV 8
68 #define MAX_TXDELAY 0xFFFF
71 /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
73 * Valid Range: 0-65535
75 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
76 #define DEFAULT_TADV 32
77 #define MAX_TXABSDELAY 0xFFFF
78 #define MIN_TXABSDELAY 0
80 /* Receive Interrupt Delay in units of 1.024 microseconds
81 * hardware will likely hang if you set this to anything but zero.
83 * Valid Range: 0-65535
85 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
86 #define MAX_RXDELAY 0xFFFF
89 /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
91 * Valid Range: 0-65535
93 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
94 #define MAX_RXABSDELAY 0xFFFF
95 #define MIN_RXABSDELAY 0
97 /* Interrupt Throttle Rate (interrupts/sec)
99 * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative
101 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
102 #define DEFAULT_ITR 3
103 #define MAX_ITR 100000
106 /* IntMode (Interrupt Mode)
108 * Valid Range: varies depending on kernel configuration & hardware support
110 * legacy=0, MSI=1, MSI-X=2
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)
117 * When a mode is specified that is not allowed/supported, it will be
118 * demoted to the most advanced interrupt mode available.
120 E1000_PARAM(IntMode, "Interrupt Mode");
121 #define MAX_INTMODE 2
122 #define MIN_INTMODE 0
124 /* Enable Smart Power Down of the PHY
128 * Default Value: 0 (disabled)
130 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
132 /* Enable Kumeran Lock Loss workaround
136 * Default Value: 1 (enabled)
138 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
144 * Default Value: 1 (enabled)
146 E1000_PARAM(WriteProtectNVM,
147 "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
149 /* Enable CRC Stripping
153 * Default Value: 1 (enabled)
155 E1000_PARAM(CrcStripping,
156 "Enable CRC Stripping, disable if your BMC needs the CRC");
158 struct e1000_option {
159 enum { enable_option, range_option, list_option } type;
164 /* range_option info */
169 /* list_option info */
172 struct e1000_opt_list { int i; char *str; } *p;
177 static int e1000_validate_option(unsigned int *value,
178 const struct e1000_option *opt,
179 struct e1000_adapter *adapter)
181 if (*value == OPTION_UNSET) {
190 dev_info(&adapter->pdev->dev, "%s Enabled\n",
193 case OPTION_DISABLED:
194 dev_info(&adapter->pdev->dev, "%s Disabled\n",
200 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
201 dev_info(&adapter->pdev->dev, "%s set to %i\n",
208 struct e1000_opt_list *ent;
210 for (i = 0; i < opt->arg.l.nr; i++) {
211 ent = &opt->arg.l.p[i];
212 if (*value == ent->i) {
213 if (ent->str[0] != '\0')
214 dev_info(&adapter->pdev->dev, "%s\n",
225 dev_info(&adapter->pdev->dev, "Invalid %s value specified (%i) %s\n",
226 opt->name, *value, opt->err);
232 * e1000e_check_options - Range Checking for Command Line Parameters
233 * @adapter: board private structure
235 * This routine checks all command line parameters for valid user
236 * input. If an invalid value is given, or if no user specified
237 * value exists, a default value is used. The final value is stored
238 * in a variable in the adapter structure.
240 void e1000e_check_options(struct e1000_adapter *adapter)
242 struct e1000_hw *hw = &adapter->hw;
243 int bd = adapter->bd_number;
245 if (bd >= E1000_MAX_NIC) {
246 dev_notice(&adapter->pdev->dev,
247 "Warning: no configuration for board #%i\n", bd);
248 dev_notice(&adapter->pdev->dev,
249 "Using defaults for all values\n");
252 /* Transmit Interrupt Delay */
254 static const struct e1000_option opt = {
255 .type = range_option,
256 .name = "Transmit Interrupt Delay",
257 .err = "using default of "
258 __MODULE_STRING(DEFAULT_TIDV),
260 .arg = { .r = { .min = MIN_TXDELAY,
261 .max = MAX_TXDELAY } }
264 if (num_TxIntDelay > bd) {
265 adapter->tx_int_delay = TxIntDelay[bd];
266 e1000_validate_option(&adapter->tx_int_delay, &opt,
269 adapter->tx_int_delay = opt.def;
272 /* Transmit Absolute Interrupt Delay */
274 static const struct e1000_option opt = {
275 .type = range_option,
276 .name = "Transmit Absolute Interrupt Delay",
277 .err = "using default of "
278 __MODULE_STRING(DEFAULT_TADV),
280 .arg = { .r = { .min = MIN_TXABSDELAY,
281 .max = MAX_TXABSDELAY } }
284 if (num_TxAbsIntDelay > bd) {
285 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
286 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
289 adapter->tx_abs_int_delay = opt.def;
292 /* Receive Interrupt Delay */
294 static struct e1000_option opt = {
295 .type = range_option,
296 .name = "Receive Interrupt Delay",
297 .err = "using default of "
298 __MODULE_STRING(DEFAULT_RDTR),
300 .arg = { .r = { .min = MIN_RXDELAY,
301 .max = MAX_RXDELAY } }
304 if (num_RxIntDelay > bd) {
305 adapter->rx_int_delay = RxIntDelay[bd];
306 e1000_validate_option(&adapter->rx_int_delay, &opt,
309 adapter->rx_int_delay = opt.def;
312 /* Receive Absolute Interrupt Delay */
314 static const struct e1000_option opt = {
315 .type = range_option,
316 .name = "Receive Absolute Interrupt Delay",
317 .err = "using default of "
318 __MODULE_STRING(DEFAULT_RADV),
320 .arg = { .r = { .min = MIN_RXABSDELAY,
321 .max = MAX_RXABSDELAY } }
324 if (num_RxAbsIntDelay > bd) {
325 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
326 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
329 adapter->rx_abs_int_delay = opt.def;
332 /* Interrupt Throttling Rate */
334 static const struct e1000_option opt = {
335 .type = range_option,
336 .name = "Interrupt Throttling Rate (ints/sec)",
337 .err = "using default of "
338 __MODULE_STRING(DEFAULT_ITR),
340 .arg = { .r = { .min = MIN_ITR,
344 if (num_InterruptThrottleRate > bd) {
345 adapter->itr = InterruptThrottleRate[bd];
347 /* Make sure a message is printed for non-special
348 * values. And in case of an invalid option, display
349 * warning, use default and go through itr/itr_setting
350 * adjustment logic below
352 if ((adapter->itr > 4) &&
353 e1000_validate_option(&adapter->itr, &opt, adapter))
354 adapter->itr = opt.def;
356 /* If no option specified, use default value and go
357 * through the logic below to adjust itr/itr_setting
359 adapter->itr = opt.def;
361 /* Make sure a message is printed for non-special
364 if (adapter->itr > 4)
365 dev_info(&adapter->pdev->dev,
366 "%s set to default %d\n", opt.name,
370 adapter->itr_setting = adapter->itr;
371 switch (adapter->itr) {
373 dev_info(&adapter->pdev->dev, "%s turned off\n",
377 dev_info(&adapter->pdev->dev,
378 "%s set to dynamic mode\n", opt.name);
379 adapter->itr = 20000;
382 dev_info(&adapter->pdev->dev,
383 "%s set to dynamic conservative mode\n",
385 adapter->itr = 20000;
388 dev_info(&adapter->pdev->dev,
389 "%s set to simplified (2000-8000 ints) mode\n",
393 /* Save the setting, because the dynamic bits
396 * Clear the lower two bits because
397 * they are used as control.
399 adapter->itr_setting &= ~3;
405 static struct e1000_option opt = {
406 .type = range_option,
407 .name = "Interrupt Mode",
408 #ifndef CONFIG_PCI_MSI
409 .err = "defaulting to 0 (legacy)",
410 .def = E1000E_INT_MODE_LEGACY,
411 .arg = { .r = { .min = 0,
416 #ifdef CONFIG_PCI_MSI
417 if (adapter->flags & FLAG_HAS_MSIX) {
418 opt.err = kstrdup("defaulting to 2 (MSI-X)",
420 opt.def = E1000E_INT_MODE_MSIX;
421 opt.arg.r.max = E1000E_INT_MODE_MSIX;
423 opt.err = kstrdup("defaulting to 1 (MSI)", GFP_KERNEL);
424 opt.def = E1000E_INT_MODE_MSI;
425 opt.arg.r.max = E1000E_INT_MODE_MSI;
429 dev_err(&adapter->pdev->dev,
430 "Failed to allocate memory\n");
435 if (num_IntMode > bd) {
436 unsigned int int_mode = IntMode[bd];
437 e1000_validate_option(&int_mode, &opt, adapter);
438 adapter->int_mode = int_mode;
440 adapter->int_mode = opt.def;
443 #ifdef CONFIG_PCI_MSI
447 /* Smart Power Down */
449 static const struct e1000_option opt = {
450 .type = enable_option,
451 .name = "PHY Smart Power Down",
452 .err = "defaulting to Disabled",
453 .def = OPTION_DISABLED
456 if (num_SmartPowerDownEnable > bd) {
457 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];
474 e1000_validate_option(&crc_stripping, &opt, adapter);
475 if (crc_stripping == OPTION_ENABLED) {
476 adapter->flags2 |= FLAG2_CRC_STRIPPING;
477 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
480 adapter->flags2 |= FLAG2_CRC_STRIPPING;
481 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
484 /* Kumeran Lock Loss Workaround */
486 static const struct e1000_option opt = {
487 .type = enable_option,
488 .name = "Kumeran Lock Loss Workaround",
489 .err = "defaulting to Enabled",
490 .def = OPTION_ENABLED
492 bool enabled = opt.def;
494 if (num_KumeranLockLoss > bd) {
495 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
496 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
497 enabled = kmrn_lock_loss;
500 if (hw->mac.type == e1000_ich8lan)
501 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
504 /* Write-protect NVM */
506 static const struct e1000_option opt = {
507 .type = enable_option,
508 .name = "Write-protect NVM",
509 .err = "defaulting to Enabled",
510 .def = OPTION_ENABLED
513 if (adapter->flags & FLAG_IS_ICH) {
514 if (num_WriteProtectNVM > bd) {
515 unsigned int write_protect_nvm =
517 e1000_validate_option(&write_protect_nvm, &opt,
519 if (write_protect_nvm)
520 adapter->flags |= FLAG_READ_ONLY_NVM;
523 adapter->flags |= FLAG_READ_ONLY_NVM;