blob: 593251c78c6ff295261bee1a5577dd09080cb8bb [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan451152d2010-06-16 13:28:11 +00004 Copyright(c) 1999 - 2010 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>
Jeff Kirsher44defeb2008-08-04 17:20:41 -070030#include <linux/pci.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070031
32#include "e1000.h"
33
Bruce Allanad680762008-03-28 09:15:03 -070034/*
35 * This is the only thing that needs to be changed to adjust the
Auke Kokbc7f75f2007-09-17 12:30:59 -070036 * maximum number of ports that the driver can manage.
37 */
38
39#define E1000_MAX_NIC 32
40
41#define OPTION_UNSET -1
42#define OPTION_DISABLED 0
43#define OPTION_ENABLED 1
44
45#define COPYBREAK_DEFAULT 256
46unsigned int copybreak = COPYBREAK_DEFAULT;
47module_param(copybreak, uint, 0644);
48MODULE_PARM_DESC(copybreak,
49 "Maximum size of packet that is copied to a new buffer on receive");
50
Bruce Allanad680762008-03-28 09:15:03 -070051/*
52 * All parameters are treated the same, as an integer array of values.
Auke Kokbc7f75f2007-09-17 12:30:59 -070053 * This macro just reduces the need to repeat the same declaration code
54 * over and over (plus this helps to avoid typo bugs).
55 */
56
57#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
Stephen Hemminger5a9147b2007-10-29 10:46:05 -070058#define E1000_PARAM(X, desc) \
59 static int __devinitdata X[E1000_MAX_NIC+1] \
60 = E1000_PARAM_INIT; \
61 static unsigned int num_##X; \
62 module_param_array_named(X, X, int, &num_##X, 0); \
Auke Kokbc7f75f2007-09-17 12:30:59 -070063 MODULE_PARM_DESC(X, desc);
64
65
Bruce Allanad680762008-03-28 09:15:03 -070066/*
67 * Transmit Interrupt Delay in units of 1.024 microseconds
68 * 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");
94#define DEFAULT_RDTR 0
95#define MAX_RXDELAY 0xFFFF
96#define MIN_RXDELAY 0
97
Bruce Allanad680762008-03-28 09:15:03 -070098/*
99 * Receive Absolute Interrupt Delay in units of 1.024 microseconds
Auke Kokbc7f75f2007-09-17 12:30:59 -0700100 *
101 * Valid Range: 0-65535
102 */
103E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
104#define DEFAULT_RADV 8
105#define MAX_RXABSDELAY 0xFFFF
106#define MIN_RXABSDELAY 0
107
Bruce Allanad680762008-03-28 09:15:03 -0700108/*
109 * Interrupt Throttle Rate (interrupts/sec)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700110 *
111 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
112 */
113E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
114#define DEFAULT_ITR 3
115#define MAX_ITR 100000
116#define MIN_ITR 100
Bruce Allan4662e822008-08-26 18:37:06 -0700117/* IntMode (Interrupt Mode)
118 *
119 * Valid Range: 0 - 2
120 *
121 * Default Value: 2 (MSI-X)
122 */
123E1000_PARAM(IntMode, "Interrupt Mode");
124#define MAX_INTMODE 2
125#define MIN_INTMODE 0
Auke Kokbc7f75f2007-09-17 12:30:59 -0700126
Bruce Allanad680762008-03-28 09:15:03 -0700127/*
128 * Enable Smart Power Down of the PHY
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129 *
130 * Valid Range: 0, 1
131 *
132 * Default Value: 0 (disabled)
133 */
134E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
135
Bruce Allanad680762008-03-28 09:15:03 -0700136/*
137 * Enable Kumeran Lock Loss workaround
Auke Kokbc7f75f2007-09-17 12:30:59 -0700138 *
139 * Valid Range: 0, 1
140 *
141 * Default Value: 1 (enabled)
142 */
143E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
144
Bruce Allan4a770352008-10-01 17:18:35 -0700145/*
146 * Write Protect NVM
147 *
148 * Valid Range: 0, 1
149 *
150 * Default Value: 1 (enabled)
151 */
152E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
153
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000154/*
155 * Enable CRC Stripping
156 *
157 * Valid Range: 0, 1
158 *
159 * Default Value: 1 (enabled)
160 */
161E1000_PARAM(CrcStripping, "Enable CRC Stripping, disable if your BMC needs " \
162 "the CRC");
163
Bruce Allane52997f2010-06-16 13:27:49 +0000164/*
165 * Enable/disable EEE (a.k.a. IEEE802.3az)
166 *
167 * Valid Range: 0, 1
168 *
169 * Default Value: 1
170 */
171E1000_PARAM(EEE, "Enable/disable on parts that support the feature");
172
Auke Kokbc7f75f2007-09-17 12:30:59 -0700173struct e1000_option {
174 enum { enable_option, range_option, list_option } type;
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700175 const char *name;
176 const char *err;
177 int def;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700178 union {
179 struct { /* range_option info */
180 int min;
181 int max;
182 } r;
183 struct { /* list_option info */
184 int nr;
185 struct e1000_opt_list { int i; char *str; } *p;
186 } l;
187 } arg;
188};
189
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700190static int __devinit e1000_validate_option(unsigned int *value,
191 const struct e1000_option *opt,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700192 struct e1000_adapter *adapter)
193{
194 if (*value == OPTION_UNSET) {
195 *value = opt->def;
196 return 0;
197 }
198
199 switch (opt->type) {
200 case enable_option:
201 switch (*value) {
202 case OPTION_ENABLED:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700203 e_info("%s Enabled\n", opt->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700204 return 0;
205 case OPTION_DISABLED:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700206 e_info("%s Disabled\n", opt->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700207 return 0;
208 }
209 break;
210 case range_option:
211 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700212 e_info("%s set to %i\n", opt->name, *value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700213 return 0;
214 }
215 break;
216 case list_option: {
217 int i;
218 struct e1000_opt_list *ent;
219
220 for (i = 0; i < opt->arg.l.nr; i++) {
221 ent = &opt->arg.l.p[i];
222 if (*value == ent->i) {
223 if (ent->str[0] != '\0')
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700224 e_info("%s\n", ent->str);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700225 return 0;
226 }
227 }
228 }
229 break;
230 default:
231 BUG();
232 }
233
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700234 e_info("Invalid %s value specified (%i) %s\n", opt->name, *value,
235 opt->err);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700236 *value = opt->def;
237 return -1;
238}
239
240/**
241 * e1000e_check_options - Range Checking for Command Line Parameters
242 * @adapter: board private structure
243 *
244 * This routine checks all command line parameters for valid user
245 * input. If an invalid value is given, or if no user specified
246 * value exists, a default value is used. The final value is stored
247 * in a variable in the adapter structure.
248 **/
249void __devinit e1000e_check_options(struct e1000_adapter *adapter)
250{
251 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700252 int bd = adapter->bd_number;
253
254 if (bd >= E1000_MAX_NIC) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700255 e_notice("Warning: no configuration for board #%i\n", bd);
256 e_notice("Using defaults for all values\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257 }
258
259 { /* Transmit Interrupt Delay */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000260 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261 .type = range_option,
262 .name = "Transmit Interrupt Delay",
263 .err = "using default of "
264 __MODULE_STRING(DEFAULT_TIDV),
265 .def = DEFAULT_TIDV,
266 .arg = { .r = { .min = MIN_TXDELAY,
267 .max = MAX_TXDELAY } }
268 };
269
270 if (num_TxIntDelay > bd) {
271 adapter->tx_int_delay = TxIntDelay[bd];
272 e1000_validate_option(&adapter->tx_int_delay, &opt,
273 adapter);
274 } else {
275 adapter->tx_int_delay = opt.def;
276 }
277 }
278 { /* Transmit Absolute Interrupt Delay */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000279 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700280 .type = range_option,
281 .name = "Transmit Absolute Interrupt Delay",
282 .err = "using default of "
283 __MODULE_STRING(DEFAULT_TADV),
284 .def = DEFAULT_TADV,
285 .arg = { .r = { .min = MIN_TXABSDELAY,
286 .max = MAX_TXABSDELAY } }
287 };
288
289 if (num_TxAbsIntDelay > bd) {
290 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
291 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
292 adapter);
293 } else {
294 adapter->tx_abs_int_delay = opt.def;
295 }
296 }
297 { /* Receive Interrupt Delay */
Bruce Allan4fe44912010-05-10 14:59:10 +0000298 static struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299 .type = range_option,
300 .name = "Receive Interrupt Delay",
301 .err = "using default of "
302 __MODULE_STRING(DEFAULT_RDTR),
303 .def = DEFAULT_RDTR,
304 .arg = { .r = { .min = MIN_RXDELAY,
305 .max = MAX_RXDELAY } }
306 };
307
Auke Kokbc7f75f2007-09-17 12:30:59 -0700308 if (num_RxIntDelay > bd) {
309 adapter->rx_int_delay = RxIntDelay[bd];
310 e1000_validate_option(&adapter->rx_int_delay, &opt,
311 adapter);
312 } else {
313 adapter->rx_int_delay = opt.def;
314 }
315 }
316 { /* Receive Absolute Interrupt Delay */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000317 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700318 .type = range_option,
319 .name = "Receive Absolute Interrupt Delay",
320 .err = "using default of "
321 __MODULE_STRING(DEFAULT_RADV),
322 .def = DEFAULT_RADV,
323 .arg = { .r = { .min = MIN_RXABSDELAY,
324 .max = MAX_RXABSDELAY } }
325 };
326
327 if (num_RxAbsIntDelay > bd) {
328 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
329 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
330 adapter);
331 } else {
332 adapter->rx_abs_int_delay = opt.def;
333 }
334 }
335 { /* Interrupt Throttling Rate */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000336 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700337 .type = range_option,
338 .name = "Interrupt Throttling Rate (ints/sec)",
339 .err = "using default of "
340 __MODULE_STRING(DEFAULT_ITR),
341 .def = DEFAULT_ITR,
342 .arg = { .r = { .min = MIN_ITR,
343 .max = MAX_ITR } }
344 };
345
346 if (num_InterruptThrottleRate > bd) {
347 adapter->itr = InterruptThrottleRate[bd];
348 switch (adapter->itr) {
349 case 0:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700350 e_info("%s turned off\n", opt.name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700351 break;
352 case 1:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700353 e_info("%s set to dynamic mode\n", opt.name);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354 adapter->itr_setting = adapter->itr;
355 adapter->itr = 20000;
356 break;
357 case 3:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700358 e_info("%s set to dynamic conservative mode\n",
Auke Kokbc7f75f2007-09-17 12:30:59 -0700359 opt.name);
360 adapter->itr_setting = adapter->itr;
361 adapter->itr = 20000;
362 break;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +0000363 case 4:
364 e_info("%s set to simplified (2000-8000 ints) "
365 "mode\n", opt.name);
366 adapter->itr_setting = 4;
367 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700368 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700369 /*
Bruce Allan2d06cad2008-08-08 18:35:51 -0700370 * Save the setting, because the dynamic bits
371 * change itr.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700372 */
Bruce Allan2d06cad2008-08-08 18:35:51 -0700373 if (e1000_validate_option(&adapter->itr, &opt,
374 adapter) &&
375 (adapter->itr == 3)) {
376 /*
377 * In case of invalid user value,
378 * default to conservative mode.
379 */
380 adapter->itr_setting = adapter->itr;
381 adapter->itr = 20000;
382 } else {
383 /*
384 * Clear the lower two bits because
385 * they are used as control.
386 */
387 adapter->itr_setting =
388 adapter->itr & ~3;
389 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700390 break;
391 }
392 } else {
393 adapter->itr_setting = opt.def;
394 adapter->itr = 20000;
395 }
396 }
Bruce Allan4662e822008-08-26 18:37:06 -0700397 { /* Interrupt Mode */
Bruce Allan4fe44912010-05-10 14:59:10 +0000398 static struct e1000_option opt = {
Bruce Allan4662e822008-08-26 18:37:06 -0700399 .type = range_option,
400 .name = "Interrupt Mode",
401 .err = "defaulting to 2 (MSI-X)",
402 .def = E1000E_INT_MODE_MSIX,
403 .arg = { .r = { .min = MIN_INTMODE,
404 .max = MAX_INTMODE } }
405 };
406
407 if (num_IntMode > bd) {
408 unsigned int int_mode = IntMode[bd];
409 e1000_validate_option(&int_mode, &opt, adapter);
410 adapter->int_mode = int_mode;
411 } else {
412 adapter->int_mode = opt.def;
413 }
414 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700415 { /* Smart Power Down */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000416 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700417 .type = enable_option,
418 .name = "PHY Smart Power Down",
419 .err = "defaulting to Disabled",
420 .def = OPTION_DISABLED
421 };
422
423 if (num_SmartPowerDownEnable > bd) {
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700424 unsigned int spd = SmartPowerDownEnable[bd];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700425 e1000_validate_option(&spd, &opt, adapter);
426 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
427 && spd)
428 adapter->flags |= FLAG_SMART_POWER_DOWN;
429 }
430 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000431 { /* CRC Stripping */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000432 static const struct e1000_option opt = {
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000433 .type = enable_option,
434 .name = "CRC Stripping",
435 .err = "defaulting to enabled",
436 .def = OPTION_ENABLED
437 };
438
439 if (num_CrcStripping > bd) {
440 unsigned int crc_stripping = CrcStripping[bd];
441 e1000_validate_option(&crc_stripping, &opt, adapter);
442 if (crc_stripping == OPTION_ENABLED)
443 adapter->flags2 |= FLAG2_CRC_STRIPPING;
Bruce Allan6e50912a2009-06-02 11:28:01 +0000444 } else {
445 adapter->flags2 |= FLAG2_CRC_STRIPPING;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000446 }
447 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700448 { /* Kumeran Lock Loss Workaround */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000449 static const struct e1000_option opt = {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700450 .type = enable_option,
451 .name = "Kumeran Lock Loss Workaround",
452 .err = "defaulting to Enabled",
453 .def = OPTION_ENABLED
454 };
455
456 if (num_KumeranLockLoss > bd) {
Stephen Hemminger5a9147b2007-10-29 10:46:05 -0700457 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700458 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
459 if (hw->mac.type == e1000_ich8lan)
460 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
461 kmrn_lock_loss);
462 } else {
463 if (hw->mac.type == e1000_ich8lan)
464 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
465 opt.def);
466 }
467 }
Bruce Allan4a770352008-10-01 17:18:35 -0700468 { /* Write-protect NVM */
Jesse Brandeburg6f59d662010-04-09 10:51:09 +0000469 static const struct e1000_option opt = {
Bruce Allan4a770352008-10-01 17:18:35 -0700470 .type = enable_option,
471 .name = "Write-protect NVM",
472 .err = "defaulting to Enabled",
473 .def = OPTION_ENABLED
474 };
475
476 if (adapter->flags & FLAG_IS_ICH) {
477 if (num_WriteProtectNVM > bd) {
478 unsigned int write_protect_nvm = WriteProtectNVM[bd];
479 e1000_validate_option(&write_protect_nvm, &opt,
480 adapter);
481 if (write_protect_nvm)
482 adapter->flags |= FLAG_READ_ONLY_NVM;
483 } else {
484 if (opt.def)
485 adapter->flags |= FLAG_READ_ONLY_NVM;
486 }
487 }
488 }
Bruce Allane52997f2010-06-16 13:27:49 +0000489 { /* EEE for parts supporting the feature */
490 static const struct e1000_option opt = {
491 .type = enable_option,
492 .name = "EEE Support",
493 .err = "defaulting to Enabled",
494 .def = OPTION_ENABLED
495 };
496
497 if (adapter->flags2 & FLAG2_HAS_EEE) {
498 /* Currently only supported on 82579 */
499 if (num_EEE > bd) {
500 unsigned int eee = EEE[bd];
501 e1000_validate_option(&eee, &opt, adapter);
502 hw->dev_spec.ich8lan.eee_disable = !eee;
503 } else {
504 hw->dev_spec.ich8lan.eee_disable = !opt.def;
505 }
506 }
507 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508}