Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6.git] / drivers / net / e1000e / param.c
1 /*******************************************************************************
2
3   Intel PRO/1000 Linux driver
4   Copyright(c) 1999 - 2008 Intel Corporation.
5
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>
30 #include <linux/pci.h>
31
32 #include "e1000.h"
33
34 /*
35  * This is the only thing that needs to be changed to adjust the
36  * 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
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");
50
51 /*
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).
55  */
56
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);
64
65
66 /*
67  * Transmit Interrupt Delay in units of 1.024 microseconds
68  * Tx interrupt delay needs to typically be set to something non zero
69  *
70  * Valid Range: 0-65535
71  */
72 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
73 #define DEFAULT_TIDV 8
74 #define MAX_TXDELAY 0xFFFF
75 #define MIN_TXDELAY 0
76
77 /*
78  * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
79  *
80  * Valid Range: 0-65535
81  */
82 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
83 #define DEFAULT_TADV 32
84 #define MAX_TXABSDELAY 0xFFFF
85 #define MIN_TXABSDELAY 0
86
87 /*
88  * Receive Interrupt Delay in units of 1.024 microseconds
89  * hardware will likely hang if you set this to anything but zero.
90  *
91  * Valid Range: 0-65535
92  */
93 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
94 #define DEFAULT_RDTR 0
95 #define MAX_RXDELAY 0xFFFF
96 #define MIN_RXDELAY 0
97
98 /*
99  * Receive Absolute Interrupt Delay in units of 1.024 microseconds
100  *
101  * Valid Range: 0-65535
102  */
103 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
104 #define DEFAULT_RADV 8
105 #define MAX_RXABSDELAY 0xFFFF
106 #define MIN_RXABSDELAY 0
107
108 /*
109  * Interrupt Throttle Rate (interrupts/sec)
110  *
111  * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
112  */
113 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
114 #define DEFAULT_ITR 3
115 #define MAX_ITR 100000
116 #define MIN_ITR 100
117 /* IntMode (Interrupt Mode)
118  *
119  * Valid Range: 0 - 2
120  *
121  * Default Value: 2 (MSI-X)
122  */
123 E1000_PARAM(IntMode, "Interrupt Mode");
124 #define MAX_INTMODE     2
125 #define MIN_INTMODE     0
126
127 /*
128  * Enable Smart Power Down of the PHY
129  *
130  * Valid Range: 0, 1
131  *
132  * Default Value: 0 (disabled)
133  */
134 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
135
136 /*
137  * Enable Kumeran Lock Loss workaround
138  *
139  * Valid Range: 0, 1
140  *
141  * Default Value: 1 (enabled)
142  */
143 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
144
145 /*
146  * Write Protect NVM
147  *
148  * Valid Range: 0, 1
149  *
150  * Default Value: 1 (enabled)
151  */
152 E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
153
154 struct e1000_option {
155         enum { enable_option, range_option, list_option } type;
156         const char *name;
157         const char *err;
158         int def;
159         union {
160                 struct { /* range_option info */
161                         int min;
162                         int max;
163                 } r;
164                 struct { /* list_option info */
165                         int nr;
166                         struct e1000_opt_list { int i; char *str; } *p;
167                 } l;
168         } arg;
169 };
170
171 static int __devinit e1000_validate_option(unsigned int *value,
172                                            const struct e1000_option *opt,
173                                            struct e1000_adapter *adapter)
174 {
175         if (*value == OPTION_UNSET) {
176                 *value = opt->def;
177                 return 0;
178         }
179
180         switch (opt->type) {
181         case enable_option:
182                 switch (*value) {
183                 case OPTION_ENABLED:
184                         e_info("%s Enabled\n", opt->name);
185                         return 0;
186                 case OPTION_DISABLED:
187                         e_info("%s Disabled\n", opt->name);
188                         return 0;
189                 }
190                 break;
191         case range_option:
192                 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
193                         e_info("%s set to %i\n", opt->name, *value);
194                         return 0;
195                 }
196                 break;
197         case list_option: {
198                 int i;
199                 struct e1000_opt_list *ent;
200
201                 for (i = 0; i < opt->arg.l.nr; i++) {
202                         ent = &opt->arg.l.p[i];
203                         if (*value == ent->i) {
204                                 if (ent->str[0] != '\0')
205                                         e_info("%s\n", ent->str);
206                                 return 0;
207                         }
208                 }
209         }
210                 break;
211         default:
212                 BUG();
213         }
214
215         e_info("Invalid %s value specified (%i) %s\n", opt->name, *value,
216                opt->err);
217         *value = opt->def;
218         return -1;
219 }
220
221 /**
222  * e1000e_check_options - Range Checking for Command Line Parameters
223  * @adapter: board private structure
224  *
225  * This routine checks all command line parameters for valid user
226  * input.  If an invalid value is given, or if no user specified
227  * value exists, a default value is used.  The final value is stored
228  * in a variable in the adapter structure.
229  **/
230 void __devinit e1000e_check_options(struct e1000_adapter *adapter)
231 {
232         struct e1000_hw *hw = &adapter->hw;
233         int bd = adapter->bd_number;
234
235         if (bd >= E1000_MAX_NIC) {
236                 e_notice("Warning: no configuration for board #%i\n", bd);
237                 e_notice("Using defaults for all values\n");
238         }
239
240         { /* Transmit Interrupt Delay */
241                 const struct e1000_option opt = {
242                         .type = range_option,
243                         .name = "Transmit Interrupt Delay",
244                         .err  = "using default of "
245                                 __MODULE_STRING(DEFAULT_TIDV),
246                         .def  = DEFAULT_TIDV,
247                         .arg  = { .r = { .min = MIN_TXDELAY,
248                                          .max = MAX_TXDELAY } }
249                 };
250
251                 if (num_TxIntDelay > bd) {
252                         adapter->tx_int_delay = TxIntDelay[bd];
253                         e1000_validate_option(&adapter->tx_int_delay, &opt,
254                                               adapter);
255                 } else {
256                         adapter->tx_int_delay = opt.def;
257                 }
258         }
259         { /* Transmit Absolute Interrupt Delay */
260                 const struct e1000_option opt = {
261                         .type = range_option,
262                         .name = "Transmit Absolute Interrupt Delay",
263                         .err  = "using default of "
264                                 __MODULE_STRING(DEFAULT_TADV),
265                         .def  = DEFAULT_TADV,
266                         .arg  = { .r = { .min = MIN_TXABSDELAY,
267                                          .max = MAX_TXABSDELAY } }
268                 };
269
270                 if (num_TxAbsIntDelay > bd) {
271                         adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
272                         e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
273                                               adapter);
274                 } else {
275                         adapter->tx_abs_int_delay = opt.def;
276                 }
277         }
278         { /* Receive Interrupt Delay */
279                 struct e1000_option opt = {
280                         .type = range_option,
281                         .name = "Receive Interrupt Delay",
282                         .err  = "using default of "
283                                 __MODULE_STRING(DEFAULT_RDTR),
284                         .def  = DEFAULT_RDTR,
285                         .arg  = { .r = { .min = MIN_RXDELAY,
286                                          .max = MAX_RXDELAY } }
287                 };
288
289                 if (num_RxIntDelay > bd) {
290                         adapter->rx_int_delay = RxIntDelay[bd];
291                         e1000_validate_option(&adapter->rx_int_delay, &opt,
292                                               adapter);
293                 } else {
294                         adapter->rx_int_delay = opt.def;
295                 }
296         }
297         { /* Receive Absolute Interrupt Delay */
298                 const struct e1000_option opt = {
299                         .type = range_option,
300                         .name = "Receive Absolute Interrupt Delay",
301                         .err  = "using default of "
302                                 __MODULE_STRING(DEFAULT_RADV),
303                         .def  = DEFAULT_RADV,
304                         .arg  = { .r = { .min = MIN_RXABSDELAY,
305                                          .max = MAX_RXABSDELAY } }
306                 };
307
308                 if (num_RxAbsIntDelay > bd) {
309                         adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
310                         e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
311                                               adapter);
312                 } else {
313                         adapter->rx_abs_int_delay = opt.def;
314                 }
315         }
316         { /* Interrupt Throttling Rate */
317                 const struct e1000_option opt = {
318                         .type = range_option,
319                         .name = "Interrupt Throttling Rate (ints/sec)",
320                         .err  = "using default of "
321                                 __MODULE_STRING(DEFAULT_ITR),
322                         .def  = DEFAULT_ITR,
323                         .arg  = { .r = { .min = MIN_ITR,
324                                          .max = MAX_ITR } }
325                 };
326
327                 if (num_InterruptThrottleRate > bd) {
328                         adapter->itr = InterruptThrottleRate[bd];
329                         switch (adapter->itr) {
330                         case 0:
331                                 e_info("%s turned off\n", opt.name);
332                                 break;
333                         case 1:
334                                 e_info("%s set to dynamic mode\n", opt.name);
335                                 adapter->itr_setting = adapter->itr;
336                                 adapter->itr = 20000;
337                                 break;
338                         case 3:
339                                 e_info("%s set to dynamic conservative mode\n",
340                                         opt.name);
341                                 adapter->itr_setting = adapter->itr;
342                                 adapter->itr = 20000;
343                                 break;
344                         default:
345                                 /*
346                                  * Save the setting, because the dynamic bits
347                                  * change itr.
348                                  */
349                                 if (e1000_validate_option(&adapter->itr, &opt,
350                                                           adapter) &&
351                                     (adapter->itr == 3)) {
352                                         /*
353                                          * In case of invalid user value,
354                                          * default to conservative mode.
355                                          */
356                                         adapter->itr_setting = adapter->itr;
357                                         adapter->itr = 20000;
358                                 } else {
359                                         /*
360                                          * Clear the lower two bits because
361                                          * they are used as control.
362                                          */
363                                         adapter->itr_setting =
364                                                 adapter->itr & ~3;
365                                 }
366                                 break;
367                         }
368                 } else {
369                         adapter->itr_setting = opt.def;
370                         adapter->itr = 20000;
371                 }
372         }
373         { /* Interrupt Mode */
374                 struct e1000_option opt = {
375                         .type = range_option,
376                         .name = "Interrupt Mode",
377                         .err  = "defaulting to 2 (MSI-X)",
378                         .def  = E1000E_INT_MODE_MSIX,
379                         .arg  = { .r = { .min = MIN_INTMODE,
380                                          .max = MAX_INTMODE } }
381                 };
382
383                 if (num_IntMode > bd) {
384                         unsigned int int_mode = IntMode[bd];
385                         e1000_validate_option(&int_mode, &opt, adapter);
386                         adapter->int_mode = int_mode;
387                 } else {
388                         adapter->int_mode = opt.def;
389                 }
390         }
391         { /* Smart Power Down */
392                 const struct e1000_option opt = {
393                         .type = enable_option,
394                         .name = "PHY Smart Power Down",
395                         .err  = "defaulting to Disabled",
396                         .def  = OPTION_DISABLED
397                 };
398
399                 if (num_SmartPowerDownEnable > bd) {
400                         unsigned int spd = SmartPowerDownEnable[bd];
401                         e1000_validate_option(&spd, &opt, adapter);
402                         if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
403                             && spd)
404                                 adapter->flags |= FLAG_SMART_POWER_DOWN;
405                 }
406         }
407         { /* Kumeran Lock Loss Workaround */
408                 const struct e1000_option opt = {
409                         .type = enable_option,
410                         .name = "Kumeran Lock Loss Workaround",
411                         .err  = "defaulting to Enabled",
412                         .def  = OPTION_ENABLED
413                 };
414
415                 if (num_KumeranLockLoss > bd) {
416                         unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
417                         e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
418                         if (hw->mac.type == e1000_ich8lan)
419                                 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
420                                                                 kmrn_lock_loss);
421                 } else {
422                         if (hw->mac.type == e1000_ich8lan)
423                                 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
424                                                                        opt.def);
425                 }
426         }
427         { /* Write-protect NVM */
428                 const struct e1000_option opt = {
429                         .type = enable_option,
430                         .name = "Write-protect NVM",
431                         .err  = "defaulting to Enabled",
432                         .def  = OPTION_ENABLED
433                 };
434
435                 if (adapter->flags & FLAG_IS_ICH) {
436                         if (num_WriteProtectNVM > bd) {
437                                 unsigned int write_protect_nvm = WriteProtectNVM[bd];
438                                 e1000_validate_option(&write_protect_nvm, &opt,
439                                                       adapter);
440                                 if (write_protect_nvm)
441                                         adapter->flags |= FLAG_READ_ONLY_NVM;
442                         } else {
443                                 if (opt.def)
444                                         adapter->flags |= FLAG_READ_ONLY_NVM;
445                         }
446                 }
447         }
448 }