blob: 20e93b08e7f3c7e6e2389bea815e0b3dec227d71 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
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.
9
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
13 more details.
14
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.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
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
26
27*******************************************************************************/
28
29#include <linux/netdevice.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040030#include <linux/module.h>
Jeff Kirsher44defeb2008-08-04 17:20:41 -070031#include <linux/pci.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070032
33#include "e1000.h"
34
Bruce Allanad680762008-03-28 09:15:03 -070035/*
36 * This is the only thing that needs to be changed to adjust the
Auke Kokbc7f75f2007-09-17 12:30:59 -070037 * maximum number of ports that the driver can manage.
38 */
39
40#define E1000_MAX_NIC 32
41
42#define OPTION_UNSET -1
43#define OPTION_DISABLED 0
44#define OPTION_ENABLED 1
45
46#define COPYBREAK_DEFAULT 256
47unsigned int copybreak = COPYBREAK_DEFAULT;
48module_param(copybreak, uint, 0644);
49MODULE_PARM_DESC(copybreak,
50 "Maximum size of packet that is copied to a new buffer on receive");
51
Bruce Allanad680762008-03-28 09:15:03 -070052/*
53 * All parameters are treated the same, as an integer array of values.
Auke Kokbc7f75f2007-09-17 12:30:59 -070054 * This macro just reduces the need to repeat the same declaration code
55 * over and over (plus this helps to avoid typo bugs).
56 */
57
58#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
Stephen Hemminger5a9147b2007-10-29 10:46:05 -070059#define E1000_PARAM(X, desc) \
60 static int __devinitdata X[E1000_MAX_NIC+1] \
61 = E1000_PARAM_INIT; \
62 static unsigned int num_##X; \
63 module_param_array_named(X, X, int, &num_##X, 0); \
Auke Kokbc7f75f2007-09-17 12:30:59 -070064 MODULE_PARM_DESC(X, desc);
65
Bruce Allanad680762008-03-28 09:15:03 -070066/*
67 * Transmit Interrupt Delay in units of 1.024 microseconds
Bruce Allanaf667a22010-12-31 06:10:01 +000068 * Tx interrupt delay needs to typically be set to something non-zero
Auke Kokbc7f75f2007-09-17 12:30:59 -070069 *
70 * Valid Range: 0-65535
71 */
72E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
73#define DEFAULT_TIDV 8
74#define MAX_TXDELAY 0xFFFF
75#define MIN_TXDELAY 0
76
Bruce Allanad680762008-03-28 09:15:03 -070077/*
78 * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
Auke Kokbc7f75f2007-09-17 12:30:59 -070079 *
80 * Valid Range: 0-65535
81 */
82E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
83#define DEFAULT_TADV 32
84#define MAX_TXABSDELAY 0xFFFF
85#define MIN_TXABSDELAY 0
86
Bruce Allanad680762008-03-28 09:15:03 -070087/*
88 * Receive Interrupt Delay in units of 1.024 microseconds
89 * hardware will likely hang if you set this to anything but zero.
Auke Kokbc7f75f2007-09-17 12:30:59 -070090 *
91 * Valid Range: 0-65535
92 */
93E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
Auke Kokbc7f75f2007-09-17 12:30:59 -070094#define MAX_RXDELAY 0xFFFF
95#define MIN_RXDELAY 0
96
Bruce Allanad680762008-03-28 09:15:03 -070097/*
98 * Receive Absolute Interrupt Delay in units of 1.024 microseconds
Auke Kokbc7f75f2007-09-17 12:30:59 -070099 *
100 * Valid Range: 0-65535
101 */
102E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700103#define MAX_RXABSDELAY 0xFFFF
104#define MIN_RXABSDELAY 0
105
Bruce Allanad680762008-03-28 09:15:03 -0700106/*
107 * Interrupt Throttle Rate (interrupts/sec)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700108 *
109 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
110 */
111E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
112#define DEFAULT_ITR 3
113#define MAX_ITR 100000
114#define MIN_ITR 100
Bruce Allanaf667a22010-12-31 06:10:01 +0000115
Bruce Allan4662e822008-08-26 18:37:06 -0700116/* IntMode (Interrupt Mode)
117 *
118 * Valid Range: 0 - 2
119 *
120 * Default Value: 2 (MSI-X)
121 */
122E1000_PARAM(IntMode, "Interrupt Mode");
123#define MAX_INTMODE 2
124#define MIN_INTMODE 0
Auke Kokbc7f75f2007-09-17 12:30:59 -0700125
Bruce Allanad680762008-03-28 09:15:03 -0700126/*
127 * Enable Smart Power Down of the PHY
Auke Kokbc7f75f2007-09-17 12:30:59 -0700128 *
129 * Valid Range: 0, 1
130 *
131 * Default Value: 0 (disabled)
132 */
133E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
134
Bruce Allanad680762008-03-28 09:15:03 -0700135/*
136 * Enable Kumeran Lock Loss workaround
Auke Kokbc7f75f2007-09-17 12:30:59 -0700137 *
138 * Valid Range: 0, 1
139 *
140 * Default Value: 1 (enabled)
141 */
142E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
143
Bruce Allan4a770352008-10-01 17:18:35 -0700144/*
145 * Write Protect NVM
146 *
147 * Valid Range: 0, 1
148 *
149 * Default Value: 1 (enabled)
150 */
151E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
152
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000153/*
154 * Enable CRC Stripping
155 *
156 * Valid Range: 0, 1
157 *
158 * Default Value: 1 (enabled)
159 */
160E1000_PARAM(CrcStripping, "Enable CRC Stripping, disable if your BMC needs " \
161 "the CRC");
162
Auke Kokbc7f75f2007-09-17 12:30:59 -0700163struct e1000_option {
164 enum { enable_option, range_option, list_option } type;
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700165 const char *name;
166 const char *err;
167 int def;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700168 union {
169 struct { /* range_option info */
170 int min;
171 int max;
172 } r;
173 struct { /* list_option info */
174 int nr;
175 struct e1000_opt_list { int i; char *str; } *p;
176 } l;
177 } arg;
178};
179
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700180static int __devinit e1000_validate_option(unsigned int *value,
181 const struct e1000_option *opt,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700182 struct e1000_adapter *adapter)
183{
184 if (*value == OPTION_UNSET) {
185 *value = opt->def;
186 return 0;
187 }
188
189 switch (opt->type) {
190 case enable_option:
191 switch (*value) {
192 case OPTION_ENABLED:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700193 e_info("%s Enabled\n", opt->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700194 return 0;
195 case OPTION_DISABLED:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700196 e_info("%s Disabled\n", opt->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700197 return 0;
198 }
199 break;
200 case range_option:
201 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700202 e_info("%s set to %i\n", opt->name, *value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700203 return 0;
204 }
205 break;
206 case list_option: {
207 int i;
208 struct e1000_opt_list *ent;
209
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')
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700214 e_info("%s\n", ent->str);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700215 return 0;
216 }
217 }
218 }
219 break;
220 default:
221 BUG();
222 }
223
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700224 e_info("Invalid %s value specified (%i) %s\n", opt->name, *value,
225 opt->err);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700226 *value = opt->def;
227 return -1;
228}
229
230/**
231 * e1000e_check_options - Range Checking for Command Line Parameters
232 * @adapter: board private structure
233 *
234 * This routine checks all command line parameters for valid user
235 * input. If an invalid value is given, or if no user specified
236 * value exists, a default value is used. The final value is stored
237 * in a variable in the adapter structure.
238 **/
239void __devinit e1000e_check_options(struct e1000_adapter *adapter)
240{
241 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700242 int bd = adapter->bd_number;
243
244 if (bd >= E1000_MAX_NIC) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700245 e_notice("Warning: no configuration for board #%i\n", bd);
246 e_notice("Using defaults for all values\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700247 }
248
249 { /* Transmit Interrupt Delay */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000250 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700251 .type = range_option,
252 .name = "Transmit Interrupt Delay",
253 .err = "using default of "
254 __MODULE_STRING(DEFAULT_TIDV),
255 .def = DEFAULT_TIDV,
256 .arg = { .r = { .min = MIN_TXDELAY,
257 .max = MAX_TXDELAY } }
258 };
259
260 if (num_TxIntDelay > bd) {
261 adapter->tx_int_delay = TxIntDelay[bd];
262 e1000_validate_option(&adapter->tx_int_delay, &opt,
263 adapter);
264 } else {
265 adapter->tx_int_delay = opt.def;
266 }
267 }
268 { /* Transmit Absolute Interrupt Delay */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000269 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700270 .type = range_option,
271 .name = "Transmit Absolute Interrupt Delay",
272 .err = "using default of "
273 __MODULE_STRING(DEFAULT_TADV),
274 .def = DEFAULT_TADV,
275 .arg = { .r = { .min = MIN_TXABSDELAY,
276 .max = MAX_TXABSDELAY } }
277 };
278
279 if (num_TxAbsIntDelay > bd) {
280 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
281 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
282 adapter);
283 } else {
284 adapter->tx_abs_int_delay = opt.def;
285 }
286 }
287 { /* Receive Interrupt Delay */
Bruce Allan4fe44912010-05-10 14:59:10 +0000288 static struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700289 .type = range_option,
290 .name = "Receive Interrupt Delay",
291 .err = "using default of "
292 __MODULE_STRING(DEFAULT_RDTR),
293 .def = DEFAULT_RDTR,
294 .arg = { .r = { .min = MIN_RXDELAY,
295 .max = MAX_RXDELAY } }
296 };
297
Auke Kokbc7f75f2007-09-17 12:30:59 -0700298 if (num_RxIntDelay > bd) {
299 adapter->rx_int_delay = RxIntDelay[bd];
300 e1000_validate_option(&adapter->rx_int_delay, &opt,
301 adapter);
302 } else {
303 adapter->rx_int_delay = opt.def;
304 }
305 }
306 { /* Receive Absolute Interrupt Delay */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000307 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700308 .type = range_option,
309 .name = "Receive Absolute Interrupt Delay",
310 .err = "using default of "
311 __MODULE_STRING(DEFAULT_RADV),
312 .def = DEFAULT_RADV,
313 .arg = { .r = { .min = MIN_RXABSDELAY,
314 .max = MAX_RXABSDELAY } }
315 };
316
317 if (num_RxAbsIntDelay > bd) {
318 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
319 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
320 adapter);
321 } else {
322 adapter->rx_abs_int_delay = opt.def;
323 }
324 }
325 { /* Interrupt Throttling Rate */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000326 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700327 .type = range_option,
328 .name = "Interrupt Throttling Rate (ints/sec)",
329 .err = "using default of "
330 __MODULE_STRING(DEFAULT_ITR),
331 .def = DEFAULT_ITR,
332 .arg = { .r = { .min = MIN_ITR,
333 .max = MAX_ITR } }
334 };
335
336 if (num_InterruptThrottleRate > bd) {
337 adapter->itr = InterruptThrottleRate[bd];
338 switch (adapter->itr) {
339 case 0:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700340 e_info("%s turned off\n", opt.name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700341 break;
342 case 1:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700343 e_info("%s set to dynamic mode\n", opt.name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700344 adapter->itr_setting = adapter->itr;
345 adapter->itr = 20000;
346 break;
347 case 3:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700348 e_info("%s set to dynamic conservative mode\n",
Auke Kokbc7f75f2007-09-17 12:30:59 -0700349 opt.name);
350 adapter->itr_setting = adapter->itr;
351 adapter->itr = 20000;
352 break;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +0000353 case 4:
354 e_info("%s set to simplified (2000-8000 ints) "
355 "mode\n", opt.name);
356 adapter->itr_setting = 4;
357 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700358 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700359 /*
Bruce Allan2d06cad2008-08-08 18:35:51 -0700360 * Save the setting, because the dynamic bits
361 * change itr.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700362 */
Bruce Allan2d06cad2008-08-08 18:35:51 -0700363 if (e1000_validate_option(&adapter->itr, &opt,
364 adapter) &&
365 (adapter->itr == 3)) {
366 /*
367 * In case of invalid user value,
368 * default to conservative mode.
369 */
370 adapter->itr_setting = adapter->itr;
371 adapter->itr = 20000;
372 } else {
373 /*
374 * Clear the lower two bits because
375 * they are used as control.
376 */
377 adapter->itr_setting =
378 adapter->itr & ~3;
379 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700380 break;
381 }
382 } else {
383 adapter->itr_setting = opt.def;
384 adapter->itr = 20000;
385 }
386 }
Bruce Allan4662e822008-08-26 18:37:06 -0700387 { /* Interrupt Mode */
Bruce Allan4fe44912010-05-10 14:59:10 +0000388 static struct e1000_option opt = {
Bruce Allan4662e822008-08-26 18:37:06 -0700389 .type = range_option,
390 .name = "Interrupt Mode",
391 .err = "defaulting to 2 (MSI-X)",
392 .def = E1000E_INT_MODE_MSIX,
393 .arg = { .r = { .min = MIN_INTMODE,
394 .max = MAX_INTMODE } }
395 };
396
397 if (num_IntMode > bd) {
398 unsigned int int_mode = IntMode[bd];
399 e1000_validate_option(&int_mode, &opt, adapter);
400 adapter->int_mode = int_mode;
401 } else {
402 adapter->int_mode = opt.def;
403 }
404 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700405 { /* Smart Power Down */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000406 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700407 .type = enable_option,
408 .name = "PHY Smart Power Down",
409 .err = "defaulting to Disabled",
410 .def = OPTION_DISABLED
411 };
412
413 if (num_SmartPowerDownEnable > bd) {
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700414 unsigned int spd = SmartPowerDownEnable[bd];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700415 e1000_validate_option(&spd, &opt, adapter);
416 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
417 && spd)
418 adapter->flags |= FLAG_SMART_POWER_DOWN;
419 }
420 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000421 { /* CRC Stripping */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000422 static const struct e1000_option opt = {
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000423 .type = enable_option,
424 .name = "CRC Stripping",
Bruce Allane9262442010-11-24 06:02:06 +0000425 .err = "defaulting to Enabled",
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000426 .def = OPTION_ENABLED
427 };
428
429 if (num_CrcStripping > bd) {
430 unsigned int crc_stripping = CrcStripping[bd];
431 e1000_validate_option(&crc_stripping, &opt, adapter);
432 if (crc_stripping == OPTION_ENABLED)
433 adapter->flags2 |= FLAG2_CRC_STRIPPING;
Bruce Allan6e50912a2009-06-02 11:28:01 +0000434 } else {
435 adapter->flags2 |= FLAG2_CRC_STRIPPING;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000436 }
437 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700438 { /* Kumeran Lock Loss Workaround */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000439 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700440 .type = enable_option,
441 .name = "Kumeran Lock Loss Workaround",
442 .err = "defaulting to Enabled",
443 .def = OPTION_ENABLED
444 };
445
446 if (num_KumeranLockLoss > bd) {
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700447 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700448 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
449 if (hw->mac.type == e1000_ich8lan)
450 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
451 kmrn_lock_loss);
452 } else {
453 if (hw->mac.type == e1000_ich8lan)
454 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
455 opt.def);
456 }
457 }
Bruce Allan4a770352008-10-01 17:18:35 -0700458 { /* Write-protect NVM */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000459 static const struct e1000_option opt = {
Bruce Allan4a770352008-10-01 17:18:35 -0700460 .type = enable_option,
461 .name = "Write-protect NVM",
462 .err = "defaulting to Enabled",
463 .def = OPTION_ENABLED
464 };
465
466 if (adapter->flags & FLAG_IS_ICH) {
467 if (num_WriteProtectNVM > bd) {
468 unsigned int write_protect_nvm = WriteProtectNVM[bd];
469 e1000_validate_option(&write_protect_nvm, &opt,
470 adapter);
471 if (write_protect_nvm)
472 adapter->flags |= FLAG_READ_ONLY_NVM;
473 } else {
474 if (opt.def)
475 adapter->flags |= FLAG_READ_ONLY_NVM;
476 }
477 }
478 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700479}