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