include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / net / e1000e / param.c
blob4dd9b63273f62eac9917d69df9a613dd3fa14e61
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2011 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
13 more details.
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".
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
27 *******************************************************************************/
29 #include <linux/netdevice.h>
30 #include <linux/pci.h>
32 #include "e1000.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.
39 #define E1000_MAX_NIC 32
41 #define OPTION_UNSET -1
42 #define OPTION_DISABLED 0
43 #define OPTION_ENABLED 1
45 #define COPYBREAK_DEFAULT 256
46 unsigned int copybreak = COPYBREAK_DEFAULT;
47 module_param(copybreak, uint, 0644);
48 MODULE_PARM_DESC(copybreak,
49 "Maximum size of packet that is copied to a new buffer on receive");
52 * All parameters are treated the same, as an integer array of values.
53 * This macro just reduces the need to repeat the same declaration code
54 * over and over (plus this helps to avoid typo bugs).
57 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
58 #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); \
63 MODULE_PARM_DESC(X, desc);
66 * Transmit Interrupt Delay in units of 1.024 microseconds
67 * Tx interrupt delay needs to typically be set to something non-zero
69 * Valid Range: 0-65535
71 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
72 #define DEFAULT_TIDV 8
73 #define MAX_TXDELAY 0xFFFF
74 #define MIN_TXDELAY 0
77 * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
79 * Valid Range: 0-65535
81 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
82 #define DEFAULT_TADV 32
83 #define MAX_TXABSDELAY 0xFFFF
84 #define MIN_TXABSDELAY 0
87 * Receive Interrupt Delay in units of 1.024 microseconds
88 * hardware will likely hang if you set this to anything but zero.
90 * Valid Range: 0-65535
92 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
93 #define MAX_RXDELAY 0xFFFF
94 #define MIN_RXDELAY 0
97 * Receive Absolute Interrupt Delay in units of 1.024 microseconds
99 * Valid Range: 0-65535
101 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
102 #define MAX_RXABSDELAY 0xFFFF
103 #define MIN_RXABSDELAY 0
106 * Interrupt Throttle Rate (interrupts/sec)
108 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
110 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
111 #define DEFAULT_ITR 3
112 #define MAX_ITR 100000
113 #define MIN_ITR 100
115 /* IntMode (Interrupt Mode)
117 * Valid Range: 0 - 2
119 * Default Value: 2 (MSI-X)
121 E1000_PARAM(IntMode, "Interrupt Mode");
122 #define MAX_INTMODE 2
123 #define MIN_INTMODE 0
126 * Enable Smart Power Down of the PHY
128 * Valid Range: 0, 1
130 * Default Value: 0 (disabled)
132 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
135 * Enable Kumeran Lock Loss workaround
137 * Valid Range: 0, 1
139 * Default Value: 1 (enabled)
141 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
144 * Write Protect NVM
146 * Valid Range: 0, 1
148 * Default Value: 1 (enabled)
150 E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
153 * Enable CRC Stripping
155 * Valid Range: 0, 1
157 * Default Value: 1 (enabled)
159 E1000_PARAM(CrcStripping, "Enable CRC Stripping, disable if your BMC needs " \
160 "the CRC");
162 struct e1000_option {
163 enum { enable_option, range_option, list_option } type;
164 const char *name;
165 const char *err;
166 int def;
167 union {
168 struct { /* range_option info */
169 int min;
170 int max;
171 } r;
172 struct { /* list_option info */
173 int nr;
174 struct e1000_opt_list { int i; char *str; } *p;
175 } l;
176 } arg;
179 static int __devinit e1000_validate_option(unsigned int *value,
180 const struct e1000_option *opt,
181 struct e1000_adapter *adapter)
183 if (*value == OPTION_UNSET) {
184 *value = opt->def;
185 return 0;
188 switch (opt->type) {
189 case enable_option:
190 switch (*value) {
191 case OPTION_ENABLED:
192 e_info("%s Enabled\n", opt->name);
193 return 0;
194 case OPTION_DISABLED:
195 e_info("%s Disabled\n", opt->name);
196 return 0;
198 break;
199 case range_option:
200 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
201 e_info("%s set to %i\n", opt->name, *value);
202 return 0;
204 break;
205 case list_option: {
206 int i;
207 struct e1000_opt_list *ent;
209 for (i = 0; i < opt->arg.l.nr; i++) {
210 ent = &opt->arg.l.p[i];
211 if (*value == ent->i) {
212 if (ent->str[0] != '\0')
213 e_info("%s\n", ent->str);
214 return 0;
218 break;
219 default:
220 BUG();
223 e_info("Invalid %s value specified (%i) %s\n", opt->name, *value,
224 opt->err);
225 *value = opt->def;
226 return -1;
230 * e1000e_check_options - Range Checking for Command Line Parameters
231 * @adapter: board private structure
233 * This routine checks all command line parameters for valid user
234 * input. If an invalid value is given, or if no user specified
235 * value exists, a default value is used. The final value is stored
236 * in a variable in the adapter structure.
238 void __devinit e1000e_check_options(struct e1000_adapter *adapter)
240 struct e1000_hw *hw = &adapter->hw;
241 int bd = adapter->bd_number;
243 if (bd >= E1000_MAX_NIC) {
244 e_notice("Warning: no configuration for board #%i\n", bd);
245 e_notice("Using defaults for all values\n");
248 { /* Transmit Interrupt Delay */
249 static const struct e1000_option opt = {
250 .type = range_option,
251 .name = "Transmit Interrupt Delay",
252 .err = "using default of "
253 __MODULE_STRING(DEFAULT_TIDV),
254 .def = DEFAULT_TIDV,
255 .arg = { .r = { .min = MIN_TXDELAY,
256 .max = MAX_TXDELAY } }
259 if (num_TxIntDelay > bd) {
260 adapter->tx_int_delay = TxIntDelay[bd];
261 e1000_validate_option(&adapter->tx_int_delay, &opt,
262 adapter);
263 } else {
264 adapter->tx_int_delay = opt.def;
267 { /* Transmit Absolute Interrupt Delay */
268 static const struct e1000_option opt = {
269 .type = range_option,
270 .name = "Transmit Absolute Interrupt Delay",
271 .err = "using default of "
272 __MODULE_STRING(DEFAULT_TADV),
273 .def = DEFAULT_TADV,
274 .arg = { .r = { .min = MIN_TXABSDELAY,
275 .max = MAX_TXABSDELAY } }
278 if (num_TxAbsIntDelay > bd) {
279 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
280 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
281 adapter);
282 } else {
283 adapter->tx_abs_int_delay = opt.def;
286 { /* Receive Interrupt Delay */
287 static struct e1000_option opt = {
288 .type = range_option,
289 .name = "Receive Interrupt Delay",
290 .err = "using default of "
291 __MODULE_STRING(DEFAULT_RDTR),
292 .def = DEFAULT_RDTR,
293 .arg = { .r = { .min = MIN_RXDELAY,
294 .max = MAX_RXDELAY } }
297 if (num_RxIntDelay > bd) {
298 adapter->rx_int_delay = RxIntDelay[bd];
299 e1000_validate_option(&adapter->rx_int_delay, &opt,
300 adapter);
301 } else {
302 adapter->rx_int_delay = opt.def;
305 { /* Receive Absolute Interrupt Delay */
306 static const struct e1000_option opt = {
307 .type = range_option,
308 .name = "Receive Absolute Interrupt Delay",
309 .err = "using default of "
310 __MODULE_STRING(DEFAULT_RADV),
311 .def = DEFAULT_RADV,
312 .arg = { .r = { .min = MIN_RXABSDELAY,
313 .max = MAX_RXABSDELAY } }
316 if (num_RxAbsIntDelay > bd) {
317 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
318 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
319 adapter);
320 } else {
321 adapter->rx_abs_int_delay = opt.def;
324 { /* Interrupt Throttling Rate */
325 static const struct e1000_option opt = {
326 .type = range_option,
327 .name = "Interrupt Throttling Rate (ints/sec)",
328 .err = "using default of "
329 __MODULE_STRING(DEFAULT_ITR),
330 .def = DEFAULT_ITR,
331 .arg = { .r = { .min = MIN_ITR,
332 .max = MAX_ITR } }
335 if (num_InterruptThrottleRate > bd) {
336 adapter->itr = InterruptThrottleRate[bd];
337 switch (adapter->itr) {
338 case 0:
339 e_info("%s turned off\n", opt.name);
340 break;
341 case 1:
342 e_info("%s set to dynamic mode\n", opt.name);
343 adapter->itr_setting = adapter->itr;
344 adapter->itr = 20000;
345 break;
346 case 3:
347 e_info("%s set to dynamic conservative mode\n",
348 opt.name);
349 adapter->itr_setting = adapter->itr;
350 adapter->itr = 20000;
351 break;
352 case 4:
353 e_info("%s set to simplified (2000-8000 ints) "
354 "mode\n", opt.name);
355 adapter->itr_setting = 4;
356 break;
357 default:
359 * Save the setting, because the dynamic bits
360 * change itr.
362 if (e1000_validate_option(&adapter->itr, &opt,
363 adapter) &&
364 (adapter->itr == 3)) {
366 * In case of invalid user value,
367 * default to conservative mode.
369 adapter->itr_setting = adapter->itr;
370 adapter->itr = 20000;
371 } else {
373 * Clear the lower two bits because
374 * they are used as control.
376 adapter->itr_setting =
377 adapter->itr & ~3;
379 break;
381 } else {
382 adapter->itr_setting = opt.def;
383 adapter->itr = 20000;
386 { /* Interrupt Mode */
387 static struct e1000_option opt = {
388 .type = range_option,
389 .name = "Interrupt Mode",
390 .err = "defaulting to 2 (MSI-X)",
391 .def = E1000E_INT_MODE_MSIX,
392 .arg = { .r = { .min = MIN_INTMODE,
393 .max = MAX_INTMODE } }
396 if (num_IntMode > bd) {
397 unsigned int int_mode = IntMode[bd];
398 e1000_validate_option(&int_mode, &opt, adapter);
399 adapter->int_mode = int_mode;
400 } else {
401 adapter->int_mode = opt.def;
404 { /* Smart Power Down */
405 static const struct e1000_option opt = {
406 .type = enable_option,
407 .name = "PHY Smart Power Down",
408 .err = "defaulting to Disabled",
409 .def = OPTION_DISABLED
412 if (num_SmartPowerDownEnable > bd) {
413 unsigned int spd = SmartPowerDownEnable[bd];
414 e1000_validate_option(&spd, &opt, adapter);
415 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
416 && spd)
417 adapter->flags |= FLAG_SMART_POWER_DOWN;
420 { /* CRC Stripping */
421 static const struct e1000_option opt = {
422 .type = enable_option,
423 .name = "CRC Stripping",
424 .err = "defaulting to Enabled",
425 .def = OPTION_ENABLED
428 if (num_CrcStripping > bd) {
429 unsigned int crc_stripping = CrcStripping[bd];
430 e1000_validate_option(&crc_stripping, &opt, adapter);
431 if (crc_stripping == OPTION_ENABLED)
432 adapter->flags2 |= FLAG2_CRC_STRIPPING;
433 } else {
434 adapter->flags2 |= FLAG2_CRC_STRIPPING;
437 { /* Kumeran Lock Loss Workaround */
438 static const struct e1000_option opt = {
439 .type = enable_option,
440 .name = "Kumeran Lock Loss Workaround",
441 .err = "defaulting to Enabled",
442 .def = OPTION_ENABLED
445 if (num_KumeranLockLoss > bd) {
446 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
447 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
448 if (hw->mac.type == e1000_ich8lan)
449 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
450 kmrn_lock_loss);
451 } else {
452 if (hw->mac.type == e1000_ich8lan)
453 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
454 opt.def);
457 { /* Write-protect NVM */
458 static const struct e1000_option opt = {
459 .type = enable_option,
460 .name = "Write-protect NVM",
461 .err = "defaulting to Enabled",
462 .def = OPTION_ENABLED
465 if (adapter->flags & FLAG_IS_ICH) {
466 if (num_WriteProtectNVM > bd) {
467 unsigned int write_protect_nvm = WriteProtectNVM[bd];
468 e1000_validate_option(&write_protect_nvm, &opt,
469 adapter);
470 if (write_protect_nvm)
471 adapter->flags |= FLAG_READ_ONLY_NVM;
472 } else {
473 if (opt.def)
474 adapter->flags |= FLAG_READ_ONLY_NVM;