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