/home/lenb/src/to-linus branch 'acpi-2.6.12'
[linux-2.6] / drivers / net / ixgb / ixgb_param.c
1 /*******************************************************************************
2
3   
4   Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
5   
6   This program is free software; you can redistribute it and/or modify it 
7   under the terms of the GNU General Public License as published by the Free 
8   Software Foundation; either version 2 of the License, or (at your option) 
9   any later version.
10   
11   This program is distributed in the hope that it will be useful, but WITHOUT 
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
14   more details.
15   
16   You should have received a copy of the GNU General Public License along with
17   this program; if not, write to the Free Software Foundation, Inc., 59 
18   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19   
20   The full GNU General Public License is included in this distribution in the
21   file called LICENSE.
22   
23   Contact Information:
24   Linux NICS <linux.nics@intel.com>
25   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27 *******************************************************************************/
28
29 #include "ixgb.h"
30
31 /* This is the only thing that needs to be changed to adjust the
32  * maximum number of ports that the driver can manage.
33  */
34
35 #define IXGB_MAX_NIC 8
36
37 #define OPTION_UNSET    -1
38 #define OPTION_DISABLED 0
39 #define OPTION_ENABLED  1
40
41 /* All parameters are treated the same, as an integer array of values.
42  * This macro just reduces the need to repeat the same declaration code
43  * over and over (plus this helps to avoid typo bugs).
44  */
45
46 #define IXGB_PARAM_INIT { [0 ... IXGB_MAX_NIC] = OPTION_UNSET }
47 #define IXGB_PARAM(X, desc) \
48         static int __devinitdata X[IXGB_MAX_NIC+1] = IXGB_PARAM_INIT; \
49         static int num_##X = 0; \
50         module_param_array_named(X, X, int, &num_##X, 0); \
51         MODULE_PARM_DESC(X, desc);
52
53 /* Transmit Descriptor Count
54  *
55  * Valid Range: 64-4096
56  *
57  * Default Value: 256
58  */
59
60 IXGB_PARAM(TxDescriptors, "Number of transmit descriptors");
61
62 /* Receive Descriptor Count
63  *
64  * Valid Range: 64-4096
65  *
66  * Default Value: 1024
67  */
68
69 IXGB_PARAM(RxDescriptors, "Number of receive descriptors");
70
71 /* User Specified Flow Control Override
72  *
73  * Valid Range: 0-3
74  *  - 0 - No Flow Control
75  *  - 1 - Rx only, respond to PAUSE frames but do not generate them
76  *  - 2 - Tx only, generate PAUSE frames but ignore them on receive
77  *  - 3 - Full Flow Control Support
78  *
79  * Default Value: Read flow control settings from the EEPROM
80  */
81
82 IXGB_PARAM(FlowControl, "Flow Control setting");
83
84 /* XsumRX - Receive Checksum Offload Enable/Disable
85  *
86  * Valid Range: 0, 1
87  *  - 0 - disables all checksum offload
88  *  - 1 - enables receive IP/TCP/UDP checksum offload
89  *        on 82597 based NICs
90  *
91  * Default Value: 1
92  */
93
94 IXGB_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
95
96 /* Transmit Interrupt Delay in units of 0.8192 microseconds
97  *
98  * Valid Range: 0-65535
99  *
100  * Default Value: 32
101  */
102
103 IXGB_PARAM(TxIntDelay, "Transmit Interrupt Delay");
104
105 /* Receive Interrupt Delay in units of 0.8192 microseconds
106  *
107  * Valid Range: 0-65535
108  *
109  * Default Value: 72
110  */
111
112 IXGB_PARAM(RxIntDelay, "Receive Interrupt Delay");
113
114 /* Receive Flow control high threshold (when we send a pause frame)
115  * (FCRTH)
116  *
117  * Valid Range: 1,536 - 262,136 (0x600 - 0x3FFF8, 8 byte granularity)
118  *
119  * Default Value: 196,608 (0x30000)
120  */
121
122 IXGB_PARAM(RxFCHighThresh, "Receive Flow Control High Threshold");
123
124 /* Receive Flow control low threshold (when we send a resume frame)
125  * (FCRTL)
126  *
127  * Valid Range: 64 - 262,136 (0x40 - 0x3FFF8, 8 byte granularity)
128  *              must be less than high threshold by at least 8 bytes
129  *
130  * Default Value:  163,840 (0x28000)
131  */
132
133 IXGB_PARAM(RxFCLowThresh, "Receive Flow Control Low Threshold");
134
135 /* Flow control request timeout (how long to pause the link partner's tx)
136  * (PAP 15:0)
137  *
138  * Valid Range: 1 - 65535 
139  *
140  * Default Value:  256 (0x100)
141  */
142
143 IXGB_PARAM(FCReqTimeout, "Flow Control Request Timeout");
144
145 /* Interrupt Delay Enable
146  *
147  * Valid Range: 0, 1
148  *
149  *  - 0 - disables transmit interrupt delay
150  *  - 1 - enables transmmit interrupt delay
151  *
152  * Default Value: 1
153  */
154
155 IXGB_PARAM(IntDelayEnable, "Transmit Interrupt Delay Enable");
156
157
158 #define DEFAULT_TIDV                         32
159 #define MAX_TIDV                         0xFFFF
160 #define MIN_TIDV                              0
161
162 #define DEFAULT_RDTR                         72
163 #define MAX_RDTR                         0xFFFF
164 #define MIN_RDTR                              0
165
166 #define XSUMRX_DEFAULT           OPTION_ENABLED
167
168 #define FLOW_CONTROL_FULL          ixgb_fc_full
169 #define FLOW_CONTROL_DEFAULT  FLOW_CONTROL_FULL
170 #define DEFAULT_FCRTL                   0x28000
171 #define DEFAULT_FCRTH                   0x30000
172 #define MIN_FCRTL                             0
173 #define MAX_FCRTL                       0x3FFE8
174 #define MIN_FCRTH                             8
175 #define MAX_FCRTH                       0x3FFF0
176
177 #define DEFAULT_FCPAUSE                 0x100   /* this may be too long */
178 #define MIN_FCPAUSE                           1
179 #define MAX_FCPAUSE                      0xffff
180
181 struct ixgb_option {
182         enum { enable_option, range_option, list_option } type;
183         char *name;
184         char *err;
185         int def;
186         union {
187                 struct {        /* range_option info */
188                         int min;
189                         int max;
190                 } r;
191                 struct {        /* list_option info */
192                         int nr;
193                         struct ixgb_opt_list {
194                                 int i;
195                                 char *str;
196                         } *p;
197                 } l;
198         } arg;
199 };
200
201 static int __devinit
202 ixgb_validate_option(int *value, struct ixgb_option *opt)
203 {
204         if(*value == OPTION_UNSET) {
205                 *value = opt->def;
206                 return 0;
207         }
208
209         switch (opt->type) {
210         case enable_option:
211                 switch (*value) {
212                 case OPTION_ENABLED:
213                         printk(KERN_INFO "%s Enabled\n", opt->name);
214                         return 0;
215                 case OPTION_DISABLED:
216                         printk(KERN_INFO "%s Disabled\n", opt->name);
217                         return 0;
218                 }
219                 break;
220         case range_option:
221                 if(*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
222                         printk(KERN_INFO "%s set to %i\n", opt->name, *value);
223                         return 0;
224                 }
225                 break;
226         case list_option: {
227                 int i;
228                 struct ixgb_opt_list *ent;
229
230                 for(i = 0; i < opt->arg.l.nr; i++) {
231                         ent = &opt->arg.l.p[i];
232                         if(*value == ent->i) {
233                                 if(ent->str[0] != '\0')
234                                         printk(KERN_INFO "%s\n", ent->str);
235                                 return 0;
236                         }
237                 }
238         }
239                 break;
240         default:
241                 BUG();
242         }
243
244         printk(KERN_INFO "Invalid %s specified (%i) %s\n",
245                    opt->name, *value, opt->err);
246         *value = opt->def;
247         return -1;
248 }
249
250 #define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
251
252 /**
253  * ixgb_check_options - Range Checking for Command Line Parameters
254  * @adapter: board private structure
255  *
256  * This routine checks all command line parameters for valid user
257  * input.  If an invalid value is given, or if no user specified
258  * value exists, a default value is used.  The final value is stored
259  * in a variable in the adapter structure.
260  **/
261
262 void __devinit
263 ixgb_check_options(struct ixgb_adapter *adapter)
264 {
265         int bd = adapter->bd_number;
266         if(bd >= IXGB_MAX_NIC) {
267                 printk(KERN_NOTICE
268                            "Warning: no configuration for board #%i\n", bd);
269                 printk(KERN_NOTICE "Using defaults for all values\n");
270         }
271
272         { /* Transmit Descriptor Count */
273                 struct ixgb_option opt = {
274                         .type = range_option,
275                         .name = "Transmit Descriptors",
276                         .err  = "using default of " __MODULE_STRING(DEFAULT_TXD),
277                         .def  = DEFAULT_TXD,
278                         .arg  = { .r = { .min = MIN_TXD,
279                                          .max = MAX_TXD}}
280                 };
281                 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
282
283                 if(num_TxDescriptors > bd) {
284                         tx_ring->count = TxDescriptors[bd];
285                         ixgb_validate_option(&tx_ring->count, &opt);
286                 } else {
287                         tx_ring->count = opt.def;
288                 }
289                 IXGB_ROUNDUP(tx_ring->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
290         }
291         { /* Receive Descriptor Count */
292                 struct ixgb_option opt = {
293                         .type = range_option,
294                         .name = "Receive Descriptors",
295                         .err  = "using default of " __MODULE_STRING(DEFAULT_RXD),
296                         .def  = DEFAULT_RXD,
297                         .arg  = { .r = { .min = MIN_RXD,
298                                          .max = MAX_RXD}}
299                 };
300                 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
301
302                 if(num_RxDescriptors > bd) {
303                         rx_ring->count = RxDescriptors[bd];
304                         ixgb_validate_option(&rx_ring->count, &opt);
305                 } else {
306                         rx_ring->count = opt.def;
307                 }
308                 IXGB_ROUNDUP(rx_ring->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
309         }
310         { /* Receive Checksum Offload Enable */
311                 struct ixgb_option opt = {
312                         .type = enable_option,
313                         .name = "Receive Checksum Offload",
314                         .err  = "defaulting to Enabled",
315                         .def  = OPTION_ENABLED
316                 };
317
318                 if(num_XsumRX > bd) {
319                         int rx_csum = XsumRX[bd];
320                         ixgb_validate_option(&rx_csum, &opt);
321                         adapter->rx_csum = rx_csum;
322                 } else {
323                         adapter->rx_csum = opt.def;
324                 }
325         }
326         { /* Flow Control */
327
328                 struct ixgb_opt_list fc_list[] =
329                         {{ ixgb_fc_none,        "Flow Control Disabled" },
330                          { ixgb_fc_rx_pause,"Flow Control Receive Only" },
331                          { ixgb_fc_tx_pause,"Flow Control Transmit Only" },
332                          { ixgb_fc_full,        "Flow Control Enabled" },
333                          { ixgb_fc_default, "Flow Control Hardware Default" }};
334
335                 struct ixgb_option opt = {
336                         .type = list_option,
337                         .name = "Flow Control",
338                         .err  = "reading default settings from EEPROM",
339                         .def  = ixgb_fc_full,
340                         .arg  = { .l = { .nr = LIST_LEN(fc_list),
341                                          .p = fc_list }}
342                 };
343
344                 if(num_FlowControl > bd) {
345                         int fc = FlowControl[bd];
346                         ixgb_validate_option(&fc, &opt);
347                         adapter->hw.fc.type = fc;
348                 } else {
349                         adapter->hw.fc.type = opt.def;
350                 }
351         }
352         { /* Receive Flow Control High Threshold */
353                 struct ixgb_option opt = {
354                         .type = range_option,
355                         .name = "Rx Flow Control High Threshold",
356                         .err  = "using default of " __MODULE_STRING(DEFAULT_FCRTH),
357                         .def  = DEFAULT_FCRTH,
358                         .arg  = { .r = { .min = MIN_FCRTH,
359                                          .max = MAX_FCRTH}}
360                 };
361
362                 if(num_RxFCHighThresh > bd) {
363                         adapter->hw.fc.high_water = RxFCHighThresh[bd];
364                         ixgb_validate_option(&adapter->hw.fc.high_water, &opt);
365                 } else {
366                         adapter->hw.fc.high_water = opt.def;
367                 }
368                 if(!(adapter->hw.fc.type & ixgb_fc_rx_pause) )
369                         printk (KERN_INFO 
370                                 "Ignoring RxFCHighThresh when no RxFC\n");
371         }
372         { /* Receive Flow Control Low Threshold */
373                 struct ixgb_option opt = {
374                         .type = range_option,
375                         .name = "Rx Flow Control Low Threshold",
376                         .err  = "using default of " __MODULE_STRING(DEFAULT_FCRTL),
377                         .def  = DEFAULT_FCRTL,
378                         .arg  = { .r = { .min = MIN_FCRTL,
379                                          .max = MAX_FCRTL}}
380                 };
381
382                 if(num_RxFCLowThresh > bd) {
383                         adapter->hw.fc.low_water = RxFCLowThresh[bd];
384                         ixgb_validate_option(&adapter->hw.fc.low_water, &opt);
385                 } else {
386                         adapter->hw.fc.low_water = opt.def;
387                 }
388                 if(!(adapter->hw.fc.type & ixgb_fc_rx_pause) )
389                         printk (KERN_INFO 
390                                 "Ignoring RxFCLowThresh when no RxFC\n");
391         }
392         { /* Flow Control Pause Time Request*/
393                 struct ixgb_option opt = {
394                         .type = range_option,
395                         .name = "Flow Control Pause Time Request",
396                         .err  = "using default of "__MODULE_STRING(DEFAULT_FCPAUSE),
397                         .def  = DEFAULT_FCPAUSE,
398                         .arg = { .r = { .min = MIN_FCPAUSE,
399                                         .max = MAX_FCPAUSE}}
400                 };
401
402                 if(num_FCReqTimeout > bd) {
403                         int pause_time = FCReqTimeout[bd];
404                         ixgb_validate_option(&pause_time, &opt);
405                         adapter->hw.fc.pause_time = pause_time;
406                 } else {
407                         adapter->hw.fc.pause_time = opt.def;
408                 }
409                 if(!(adapter->hw.fc.type & ixgb_fc_rx_pause) )
410                         printk (KERN_INFO 
411                                 "Ignoring FCReqTimeout when no RxFC\n");
412         }
413         /* high low and spacing check for rx flow control thresholds */
414         if (adapter->hw.fc.type & ixgb_fc_rx_pause) {
415                 /* high must be greater than low */
416                 if (adapter->hw.fc.high_water < (adapter->hw.fc.low_water + 8)) {
417                         /* set defaults */
418                         printk (KERN_INFO 
419                                 "RxFCHighThresh must be >= (RxFCLowThresh + 8), "
420                                 "Using Defaults\n");
421                         adapter->hw.fc.high_water = DEFAULT_FCRTH;
422                         adapter->hw.fc.low_water  = DEFAULT_FCRTL;
423                 }
424         }
425         { /* Receive Interrupt Delay */
426                 struct ixgb_option opt = {
427                         .type = range_option,
428                         .name = "Receive Interrupt Delay",
429                         .err  = "using default of " __MODULE_STRING(DEFAULT_RDTR),
430                         .def  = DEFAULT_RDTR,
431                         .arg  = { .r = { .min = MIN_RDTR,
432                                          .max = MAX_RDTR}}
433                 };
434
435                 if(num_RxIntDelay > bd) {
436                         adapter->rx_int_delay = RxIntDelay[bd];
437                         ixgb_validate_option(&adapter->rx_int_delay, &opt);
438                 } else {
439                         adapter->rx_int_delay = opt.def;
440                 }
441         }
442         { /* Transmit Interrupt Delay */
443                 struct ixgb_option opt = {
444                         .type = range_option,
445                         .name = "Transmit Interrupt Delay",
446                         .err  = "using default of " __MODULE_STRING(DEFAULT_TIDV),
447                         .def  = DEFAULT_TIDV,
448                         .arg  = { .r = { .min = MIN_TIDV,
449                                          .max = MAX_TIDV}}
450                 };
451
452                 if(num_TxIntDelay > bd) {
453                         adapter->tx_int_delay = TxIntDelay[bd];
454                         ixgb_validate_option(&adapter->tx_int_delay, &opt);
455                 } else {
456                         adapter->tx_int_delay = opt.def;
457                 }
458         }
459
460         { /* Transmit Interrupt Delay Enable */
461                 struct ixgb_option opt = {
462                         .type = enable_option,
463                         .name = "Tx Interrupt Delay Enable",
464                         .err  = "defaulting to Enabled",
465                         .def  = OPTION_ENABLED
466                 };
467
468                 if(num_IntDelayEnable > bd) {
469                         int ide = IntDelayEnable[bd];
470                         ixgb_validate_option(&ide, &opt);
471                         adapter->tx_int_delay_enable = ide;
472                 } else {
473                         adapter->tx_int_delay_enable = opt.def;
474                 }
475         }
476 }