Pull bugzilla-9429 into release branch
[pv_ops_mirror.git] / drivers / net / e1000e / param.c
blob332789238b9c9309a63210877700b021b3c9acfd
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2007 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>
31 #include "e1000.h"
33 /* This is the only thing that needs to be changed to adjust the
34 * maximum number of ports that the driver can manage.
37 #define E1000_MAX_NIC 32
39 #define OPTION_UNSET -1
40 #define OPTION_DISABLED 0
41 #define OPTION_ENABLED 1
43 #define COPYBREAK_DEFAULT 256
44 unsigned int copybreak = COPYBREAK_DEFAULT;
45 module_param(copybreak, uint, 0644);
46 MODULE_PARM_DESC(copybreak,
47 "Maximum size of packet that is copied to a new buffer on receive");
49 /* All parameters are treated the same, as an integer array of values.
50 * This macro just reduces the need to repeat the same declaration code
51 * 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 __devinitdata X[E1000_MAX_NIC+1] \
57 = E1000_PARAM_INIT; \
58 static unsigned int num_##X; \
59 module_param_array_named(X, X, int, &num_##X, 0); \
60 MODULE_PARM_DESC(X, desc);
63 /* Transmit Interrupt Delay in units of 1.024 microseconds
64 * Tx interrupt delay needs to typically be set to something non zero
66 * Valid Range: 0-65535
68 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
69 #define DEFAULT_TIDV 8
70 #define MAX_TXDELAY 0xFFFF
71 #define MIN_TXDELAY 0
73 /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
75 * Valid Range: 0-65535
77 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
78 #define DEFAULT_TADV 32
79 #define MAX_TXABSDELAY 0xFFFF
80 #define MIN_TXABSDELAY 0
82 /* Receive Interrupt Delay in units of 1.024 microseconds
83 * hardware will likely hang if you set this to anything but zero.
85 * Valid Range: 0-65535
87 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
88 #define DEFAULT_RDTR 0
89 #define MAX_RXDELAY 0xFFFF
90 #define MIN_RXDELAY 0
92 /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
94 * Valid Range: 0-65535
96 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
97 #define DEFAULT_RADV 8
98 #define MAX_RXABSDELAY 0xFFFF
99 #define MIN_RXABSDELAY 0
101 /* Interrupt Throttle Rate (interrupts/sec)
103 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
105 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
106 #define DEFAULT_ITR 3
107 #define MAX_ITR 100000
108 #define MIN_ITR 100
110 /* Enable Smart Power Down of the PHY
112 * Valid Range: 0, 1
114 * Default Value: 0 (disabled)
116 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
118 /* Enable Kumeran Lock Loss workaround
120 * Valid Range: 0, 1
122 * Default Value: 1 (enabled)
124 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
126 struct e1000_option {
127 enum { enable_option, range_option, list_option } type;
128 const char *name;
129 const char *err;
130 int def;
131 union {
132 struct { /* range_option info */
133 int min;
134 int max;
135 } r;
136 struct { /* list_option info */
137 int nr;
138 struct e1000_opt_list { int i; char *str; } *p;
139 } l;
140 } arg;
143 static int __devinit e1000_validate_option(unsigned int *value,
144 const struct e1000_option *opt,
145 struct e1000_adapter *adapter)
147 if (*value == OPTION_UNSET) {
148 *value = opt->def;
149 return 0;
152 switch (opt->type) {
153 case enable_option:
154 switch (*value) {
155 case OPTION_ENABLED:
156 ndev_info(adapter->netdev, "%s Enabled\n", opt->name);
157 return 0;
158 case OPTION_DISABLED:
159 ndev_info(adapter->netdev, "%s Disabled\n", opt->name);
160 return 0;
162 break;
163 case range_option:
164 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
165 ndev_info(adapter->netdev,
166 "%s set to %i\n", opt->name, *value);
167 return 0;
169 break;
170 case list_option: {
171 int i;
172 struct e1000_opt_list *ent;
174 for (i = 0; i < opt->arg.l.nr; i++) {
175 ent = &opt->arg.l.p[i];
176 if (*value == ent->i) {
177 if (ent->str[0] != '\0')
178 ndev_info(adapter->netdev, "%s\n",
179 ent->str);
180 return 0;
184 break;
185 default:
186 BUG();
189 ndev_info(adapter->netdev, "Invalid %s value specified (%i) %s\n",
190 opt->name, *value, opt->err);
191 *value = opt->def;
192 return -1;
196 * e1000e_check_options - Range Checking for Command Line Parameters
197 * @adapter: board private structure
199 * This routine checks all command line parameters for valid user
200 * input. If an invalid value is given, or if no user specified
201 * value exists, a default value is used. The final value is stored
202 * in a variable in the adapter structure.
204 void __devinit e1000e_check_options(struct e1000_adapter *adapter)
206 struct e1000_hw *hw = &adapter->hw;
207 struct net_device *netdev = adapter->netdev;
208 int bd = adapter->bd_number;
210 if (bd >= E1000_MAX_NIC) {
211 ndev_notice(netdev,
212 "Warning: no configuration for board #%i\n", bd);
213 ndev_notice(netdev, "Using defaults for all values\n");
216 { /* Transmit Interrupt Delay */
217 const struct e1000_option opt = {
218 .type = range_option,
219 .name = "Transmit Interrupt Delay",
220 .err = "using default of "
221 __MODULE_STRING(DEFAULT_TIDV),
222 .def = DEFAULT_TIDV,
223 .arg = { .r = { .min = MIN_TXDELAY,
224 .max = MAX_TXDELAY } }
227 if (num_TxIntDelay > bd) {
228 adapter->tx_int_delay = TxIntDelay[bd];
229 e1000_validate_option(&adapter->tx_int_delay, &opt,
230 adapter);
231 } else {
232 adapter->tx_int_delay = opt.def;
235 { /* Transmit Absolute Interrupt Delay */
236 const struct e1000_option opt = {
237 .type = range_option,
238 .name = "Transmit Absolute Interrupt Delay",
239 .err = "using default of "
240 __MODULE_STRING(DEFAULT_TADV),
241 .def = DEFAULT_TADV,
242 .arg = { .r = { .min = MIN_TXABSDELAY,
243 .max = MAX_TXABSDELAY } }
246 if (num_TxAbsIntDelay > bd) {
247 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
248 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
249 adapter);
250 } else {
251 adapter->tx_abs_int_delay = opt.def;
254 { /* Receive Interrupt Delay */
255 struct e1000_option opt = {
256 .type = range_option,
257 .name = "Receive Interrupt Delay",
258 .err = "using default of "
259 __MODULE_STRING(DEFAULT_RDTR),
260 .def = DEFAULT_RDTR,
261 .arg = { .r = { .min = MIN_RXDELAY,
262 .max = MAX_RXDELAY } }
265 /* modify min and default if 82573 for slow ping w/a,
266 * a value greater than 8 needs to be set for RDTR */
267 if (adapter->flags & FLAG_HAS_ASPM) {
268 opt.def = 32;
269 opt.arg.r.min = 8;
272 if (num_RxIntDelay > bd) {
273 adapter->rx_int_delay = RxIntDelay[bd];
274 e1000_validate_option(&adapter->rx_int_delay, &opt,
275 adapter);
276 } else {
277 adapter->rx_int_delay = opt.def;
280 { /* Receive Absolute Interrupt Delay */
281 const struct e1000_option opt = {
282 .type = range_option,
283 .name = "Receive Absolute Interrupt Delay",
284 .err = "using default of "
285 __MODULE_STRING(DEFAULT_RADV),
286 .def = DEFAULT_RADV,
287 .arg = { .r = { .min = MIN_RXABSDELAY,
288 .max = MAX_RXABSDELAY } }
291 if (num_RxAbsIntDelay > bd) {
292 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
293 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
294 adapter);
295 } else {
296 adapter->rx_abs_int_delay = opt.def;
299 { /* Interrupt Throttling Rate */
300 const struct e1000_option opt = {
301 .type = range_option,
302 .name = "Interrupt Throttling Rate (ints/sec)",
303 .err = "using default of "
304 __MODULE_STRING(DEFAULT_ITR),
305 .def = DEFAULT_ITR,
306 .arg = { .r = { .min = MIN_ITR,
307 .max = MAX_ITR } }
310 if (num_InterruptThrottleRate > bd) {
311 adapter->itr = InterruptThrottleRate[bd];
312 switch (adapter->itr) {
313 case 0:
314 ndev_info(netdev, "%s turned off\n",
315 opt.name);
316 break;
317 case 1:
318 ndev_info(netdev,
319 "%s set to dynamic mode\n",
320 opt.name);
321 adapter->itr_setting = adapter->itr;
322 adapter->itr = 20000;
323 break;
324 case 3:
325 ndev_info(netdev,
326 "%s set to dynamic conservative mode\n",
327 opt.name);
328 adapter->itr_setting = adapter->itr;
329 adapter->itr = 20000;
330 break;
331 default:
332 e1000_validate_option(&adapter->itr, &opt,
333 adapter);
335 * save the setting, because the dynamic bits
336 * change itr. clear the lower two bits
337 * because they are used as control
339 adapter->itr_setting = adapter->itr & ~3;
340 break;
342 } else {
343 adapter->itr_setting = opt.def;
344 adapter->itr = 20000;
347 { /* Smart Power Down */
348 const struct e1000_option opt = {
349 .type = enable_option,
350 .name = "PHY Smart Power Down",
351 .err = "defaulting to Disabled",
352 .def = OPTION_DISABLED
355 if (num_SmartPowerDownEnable > bd) {
356 unsigned int spd = SmartPowerDownEnable[bd];
357 e1000_validate_option(&spd, &opt, adapter);
358 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
359 && spd)
360 adapter->flags |= FLAG_SMART_POWER_DOWN;
363 { /* Kumeran Lock Loss Workaround */
364 const struct e1000_option opt = {
365 .type = enable_option,
366 .name = "Kumeran Lock Loss Workaround",
367 .err = "defaulting to Enabled",
368 .def = OPTION_ENABLED
371 if (num_KumeranLockLoss > bd) {
372 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
373 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
374 if (hw->mac.type == e1000_ich8lan)
375 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
376 kmrn_lock_loss);
377 } else {
378 if (hw->mac.type == e1000_ich8lan)
379 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
380 opt.def);