ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / ixgb / ixgb_param.c
1 /*******************************************************************************
2
3   
4   Copyright(c) 1999 - 2003 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 #include "ixgb.h"
29
30 /* This is the only thing that needs to be changed to adjust the
31  * maximum number of ports that the driver can manage.
32  */
33
34 #define IXGB_MAX_NIC                     8
35
36 #define OPTION_UNSET                    -1
37 #define OPTION_DISABLED                  0
38 #define OPTION_ENABLED                   1
39
40 /* Module Parameters are always initialized to -1, so that the driver
41  * can tell the difference between no user specified value or the
42  * user asking for the default value.
43  * The true default values are loaded in when ixgb_check_options is called.
44  *
45  * This is a GCC extension to ANSI C.
46  * See the item "Labeled Elements in Initializers" in the section
47  * "Extensions to the C Language Family" of the GCC documentation.
48  */
49
50 #define IXGB_PARAM_INIT { [0 ... IXGB_MAX_NIC] = OPTION_UNSET }
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 IXGB_PARAM(X, S) \
58 static const int __devinitdata X[IXGB_MAX_NIC + 1] = IXGB_PARAM_INIT; \
59 MODULE_PARM(X, "1-" __MODULE_STRING(IXGB_MAX_NIC) "i"); \
60 MODULE_PARM_DESC(X, S);
61
62 /* Transmit Descriptor Count
63  *
64  * Valid Range: 64-4096
65  *
66  * Default Value: 256
67  */
68
69 IXGB_PARAM(TxDescriptors, "Number of transmit descriptors");
70
71 /* Receive Descriptor Count
72  *
73  * Valid Range: 64-4096
74  *
75  * Default Value: 1024
76  */
77
78 IXGB_PARAM(RxDescriptors, "Number of receive descriptors");
79
80 /* User Specified Flow Control Override
81  *
82  * Valid Range: 0-3
83  *  - 0 - No Flow Control
84  *  - 1 - Rx only, respond to PAUSE frames but do not generate them
85  *  - 2 - Tx only, generate PAUSE frames but ignore them on receive
86  *  - 3 - Full Flow Control Support
87  *
88  * Default Value: Read flow control settings from the EEPROM
89  */
90
91 IXGB_PARAM(FlowControl, "Flow Control setting");
92
93 /* XsumRX - Receive Checksum Offload Enable/Disable
94  *
95  * Valid Range: 0, 1
96  *  - 0 - disables all checksum offload
97  *  - 1 - enables receive IP/TCP/UDP checksum offload
98  *        on 82597 based NICs
99  *
100  * Default Value: 1
101  */
102
103 IXGB_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
104
105 /* XsumTX - Transmit Checksum Offload Enable/Disable
106  *
107  * Valid Range: 0, 1
108  *  - 0 - disables all checksum offload
109  *  - 1 - enables transmmit IP/TCP/UDP checksum offload
110  *        on 82597 based NICs
111  *
112  * Default Value: 1
113  */
114
115 IXGB_PARAM(XsumTX, "Disable or enable Transmit Checksum offload");
116
117 /* Receive Interrupt Delay in units of 0.8192 microseconds
118  *
119  * Valid Range: 0-65535
120  *
121  * Default Value: 72
122  */
123
124 IXGB_PARAM(RxIntDelay, "Receive Interrupt Delay");
125
126 /* Receive Interrupt Moderation enable (uses RxIntDelay too)
127  *
128  * Valid Range: 0,1
129  *
130  * Default Value: 1
131  */
132
133 IXGB_PARAM(RAIDC, "Disable or enable Receive Interrupt Moderation");
134
135 /* Receive Flow control high threshold (when we send a pause frame)
136  * (FCRTH)
137  *
138  * Valid Range: 1,536 - 262,136 (0x600 - 0x3FFF8, 8 byte granularity)
139  *
140  * Default Value: 196,608 (0x30000)
141  */
142
143 IXGB_PARAM(RxFCHighThresh, "Receive Flow Control High Threshold");
144
145 /* Receive Flow control low threshold (when we send a resume frame)
146  * (FCRTL)
147  *
148  * Valid Range: 64 - 262,136 (0x40 - 0x3FFF8, 8 byte granularity)
149  *              must be less than high threshold by at least 8 bytes
150  *
151  * Default Value:  163,840 (0x28000)
152  */
153
154 IXGB_PARAM(RxFCLowThresh, "Receive Flow Control Low Threshold");
155
156 /* Flow control request timeout (how long to pause the link partner's tx)
157  * (PAP 15:0)
158  *
159  * Valid Range: 1 - 65535 
160  *
161  * Default Value:  256 (0x100)
162  */
163
164 IXGB_PARAM(FCReqTimeout, "Flow Control Request Timeout");
165
166 /* Transmit Interrupt Delay in units of 0.8192 microseconds
167  *
168  * Valid Range: 0-65535
169  *
170  * Default Value: 32
171  */
172
173 IXGB_PARAM(TxIntDelay, "Transmit Interrupt Delay");
174
175 /* Interrupt Delay Enable
176  *
177  * Valid Range: 0, 1
178  *
179  *  - 0 - disables transmit interrupt delay
180  *  - 1 - enables transmmit interrupt delay
181  *
182  * Default Value: 1
183  */
184
185 IXGB_PARAM(IntDelayEnable, "Transmit Interrupt Delay Enable");
186
187 #define DEFAULT_TXD                         256
188 #define MAX_TXD                            4096
189 #define MIN_TXD                              64
190 #define DEFAULT_RXD                        1024
191 #define MAX_RXD                            4096
192 #define MIN_RXD                              64
193 #define DEFAULT_TIDV                         32
194 #define MAX_TIDV                         0xFFFF
195 #define MIN_TIDV                              0
196 #define DEFAULT_RDTR                         72
197 #define MAX_RDTR                         0xFFFF
198 #define MIN_RDTR                              0
199 #define XSUMRX_DEFAULT           OPTION_ENABLED
200 #define FLOW_CONTROL_FULL          ixgb_fc_full
201 #define FLOW_CONTROL_DEFAULT  FLOW_CONTROL_FULL
202 #define DEFAULT_FCRTL                   0x28000
203 #define DEFAULT_FCRTH                   0x30000
204 #define MIN_FCRTL                             0
205 #define MAX_FCRTL                       0x3FFE8
206 #define MIN_FCRTH                             8
207 #define MAX_FCRTH                       0x3FFF0
208 #define DEFAULT_FCPAUSE                   0x100
209 #define MIN_FCPAUSE                           1
210 #define MAX_FCPAUSE                      0xffff
211
212 struct ixgb_option {
213         enum { enable_option, range_option, list_option } type;
214         char *name;
215         char *err;
216         int def;
217         union {
218                 struct {        /* range option information */
219                         int min;
220                         int max;
221                 } r;
222                 struct {        /* list option information */
223                         int nr;
224                         struct ixgb_opt_list {
225                                 int i;
226                                 char *str;
227                         } *p;
228                 } l;
229         } arg;
230 };
231
232 static int __devinit
233 ixgb_validate_option(int *value, struct ixgb_option *opt)
234 {
235         if (*value == OPTION_UNSET) {
236                 *value = opt->def;
237                 return 0;
238         }
239
240         switch (opt->type) {
241         case enable_option:
242                 switch (*value) {
243                 case OPTION_ENABLED:
244                         printk(KERN_INFO "%s Enabled\n", opt->name);
245                         return 0;
246                 case OPTION_DISABLED:
247                         printk(KERN_INFO "%s Disabled\n", opt->name);
248                         return 0;
249                 }
250                 break;
251         case range_option:
252                 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
253                         printk(KERN_INFO "%s set to %i\n", opt->name, *value);
254                         return 0;
255                 }
256                 break;
257         case list_option:
258                 {
259                         int i;
260                         struct ixgb_opt_list *ent;
261
262                         for (i = 0; i < opt->arg.l.nr; i++) {
263                                 ent = &opt->arg.l.p[i];
264                                 if (*value == ent->i) {
265                                         if (ent->str[0] != '\0')
266                                                 printk(KERN_INFO "%s",
267                                                        ent->str);
268                                         return 0;
269                                 }
270                         }
271                 }
272                 break;
273         default:
274                 BUG();
275         }
276
277         printk(KERN_INFO "Invalid %s specified (%i) %s\n", opt->name, *value,
278                opt->err);
279         *value = opt->def;
280         return -1;
281 }
282
283 #define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
284
285 /**
286  * ixgb_check_options - Range Checking for Command Line Parameters
287  * @adapter: board private structure
288  *
289  * This routine checks all command line paramters for valid user
290  * input.  If an invalid value is given, or if no user specified
291  * value exists, a default value is used.  The final value is stored
292  * in a variable in the adapter structure.
293  **/
294
295 void __devinit
296 ixgb_check_options(struct ixgb_adapter *adapter)
297 {
298         int board = adapter->bd_number;
299
300         IXGB_DBG("ixgb_check_options\n");
301
302         if (board >= IXGB_MAX_NIC) {
303                 printk(KERN_NOTICE "Warning: no configuration for board #%i\n",
304                        board);
305                 printk(KERN_NOTICE "Using defaults for all values\n");
306                 board = IXGB_MAX_NIC;
307         }
308
309         {                       /* Transmit Descriptor Count */
310                 struct ixgb_option opt = {
311                         .type = range_option,
312                         .name = "Transmit Descriptors",
313                         .err = "using default of " __MODULE_STRING(DEFAULT_TXD),
314                         .def = DEFAULT_TXD,
315                         .arg = {.r = {.min = MIN_TXD,.max = MAX_TXD}}
316                 };
317                 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
318
319                 tx_ring->count = TxDescriptors[board];
320                 ixgb_validate_option(&tx_ring->count, &opt);
321                 IXGB_ROUNDUP(tx_ring->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
322         }
323
324         {                       /* Receive Descriptor Count */
325                 struct ixgb_option opt = {
326                         .type = range_option,
327                         .name = "Receive Descriptors",
328                         .err = "using default of " __MODULE_STRING(DEFAULT_RXD),
329                         .def = DEFAULT_RXD,
330                         .arg = {.r = {.min = MIN_RXD,.max = MAX_RXD}}
331                 };
332                 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
333
334                 rx_ring->count = RxDescriptors[board];
335                 ixgb_validate_option(&rx_ring->count, &opt);
336                 IXGB_ROUNDUP(rx_ring->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
337         }
338
339         {                       /* Receive Checksum Offload Enable */
340                 struct ixgb_option opt = {
341                         .type = enable_option,
342                         .name = "Receive Checksum Offload",
343                         .err = "defaulting to Enabled",
344                         .def = OPTION_ENABLED,
345                 };
346                 int rx_csum = XsumRX[board];
347
348                 ixgb_validate_option(&rx_csum, &opt);
349                 adapter->rx_csum = rx_csum;
350         }
351
352         {                       /* Transmit Checksum Offload Enable */
353                 struct ixgb_option opt = {
354                         .type = enable_option,
355                         .name = "Transmit Checksum Offload",
356                         .err = "defaulting to Enabled",
357                         .def = OPTION_ENABLED,
358                 };
359                 int tx_csum = XsumTX[board];
360
361                 ixgb_validate_option(&tx_csum, &opt);
362                 adapter->tx_csum = tx_csum;
363         }
364
365         {                       /* Flow Control */
366                 struct ixgb_opt_list fc_list[] = {
367                         {ixgb_fc_none, "Flow Control Disabled\n"},
368                         {ixgb_fc_rx_pause, "Flow Control Receive Only\n"},
369                         {ixgb_fc_tx_pause, "Flow Control Transmit Only\n"},
370                         {ixgb_fc_full, "Flow Control Enabled\n"},
371                         {ixgb_fc_default, "Flow Control Hardware Default\n"}
372                 };
373
374                 struct ixgb_option opt = {
375                         .type = list_option,
376                         .name = "Flow Control",
377                         .err = "reading default settings from EEPROM",
378                         .def = ixgb_fc_full,
379                         .arg = {.l = {.nr = LIST_LEN(fc_list),.p = fc_list}}
380                 };
381
382                 int fc = FlowControl[board];
383
384                 ixgb_validate_option(&fc, &opt);
385                 adapter->hw.fc.type = fc;
386         }
387         {                       /* Receive Flow Control High Threshold */
388                 struct ixgb_option fcrth = {
389                         .type = range_option,
390                         .name = "Rx Flow Control High Threshold",
391                         .err =
392                             "using default of " __MODULE_STRING(DEFAULT_FCRTH),
393                         .def = DEFAULT_FCRTH,
394                         .arg = {.r = {.min = MIN_FCRTH,.max = MAX_FCRTH}}
395                 };
396
397                 adapter->hw.fc.high_water = RxFCHighThresh[board];
398                 ixgb_validate_option(&adapter->hw.fc.high_water, &fcrth);
399                 if (!(adapter->hw.fc.type & ixgb_fc_rx_pause))
400                         printk(KERN_INFO
401                                "Ignoring RxFCHighThresh when no RxFC\n");
402         }
403         {                       /* Receive Flow Control Low Threshold */
404                 struct ixgb_option fcrtl = {
405                         .type = range_option,
406                         .name = "Rx Flow Control Low Threshold",
407                         .err =
408                             "using default of " __MODULE_STRING(DEFAULT_FCRTL),
409                         .def = DEFAULT_FCRTL,
410                         .arg = {.r = {.min = MIN_FCRTL,.max = MAX_FCRTL}}
411                 };
412
413                 adapter->hw.fc.low_water = RxFCLowThresh[board];
414                 ixgb_validate_option(&adapter->hw.fc.low_water, &fcrtl);
415                 if (!(adapter->hw.fc.type & ixgb_fc_rx_pause))
416                         printk(KERN_INFO
417                                "Ignoring RxFCLowThresh when no RxFC\n");
418         }
419         {                       /* Flow Control Pause Time Request */
420                 struct ixgb_option fcpap = {
421                         .type = range_option,
422                         .name = "Flow Control Pause Time Request",
423                         .err =
424                             "using default of "
425                             __MODULE_STRING(DEFAULT_FCPAUSE),
426                         .def = DEFAULT_FCPAUSE,
427                         .arg = {.r = {.min = MIN_FCPAUSE,.max = MAX_FCPAUSE}}
428                 };
429
430                 int pause_time = FCReqTimeout[board];
431
432                 ixgb_validate_option(&pause_time, &fcpap);
433                 if (!(adapter->hw.fc.type & ixgb_fc_rx_pause))
434                         printk(KERN_INFO
435                                "Ignoring FCReqTimeout when no RxFC\n");
436                 adapter->hw.fc.pause_time = pause_time;
437         }
438         /* high low and spacing check for rx flow control thresholds */
439         if (adapter->hw.fc.type & ixgb_fc_rx_pause) {
440                 /* high must be greater than low */
441                 if (adapter->hw.fc.high_water < (adapter->hw.fc.low_water + 8)) {
442                         /* set defaults */
443                         printk(KERN_INFO
444                                "RxFCHighThresh must be >= (RxFCLowThresh + 8), "
445                                "Using Defaults\n");
446                         adapter->hw.fc.high_water = DEFAULT_FCRTH;
447                         adapter->hw.fc.low_water = DEFAULT_FCRTL;
448                 }
449         }
450         {                       /* Receive Interrupt Delay */
451                 struct ixgb_option opt = {
452                         .type = range_option,
453                         .name = "Receive Interrupt Delay",
454                         .err =
455                             "using default of " __MODULE_STRING(DEFAULT_RDTR),
456                         .def = DEFAULT_RDTR,
457                         .arg = {.r = {.min = MIN_RDTR,.max = MAX_RDTR}}
458                 };
459
460                 adapter->rx_int_delay = RxIntDelay[board];
461                 ixgb_validate_option(&adapter->rx_int_delay, &opt);
462         }
463         {                       /* Receive Interrupt Moderation */
464                 struct ixgb_option opt = {
465                         .type = enable_option,
466                         .name = "Advanced Receive Interrupt Moderation",
467                         .err = "defaulting to Enabled",
468                         .def = OPTION_ENABLED,
469                 };
470                 int raidc = RAIDC[board];
471
472                 ixgb_validate_option(&raidc, &opt);
473                 adapter->raidc = raidc;
474         }
475
476         {                       /* Transmit Interrupt Delay */
477                 struct ixgb_option opt = {
478                         .type = range_option,
479                         .name = "Transmit Interrupt Delay",
480                         .err =
481                             "using default of " __MODULE_STRING(DEFAULT_TIDV),
482                         .def = DEFAULT_TIDV,
483                         .arg = {.r = {.min = MIN_TIDV,.max = MAX_TIDV}}
484                 };
485
486                 adapter->tx_int_delay = TxIntDelay[board];
487                 ixgb_validate_option(&adapter->tx_int_delay, &opt);
488         }
489
490         {                       /* Transmit Interrupt Delay Enable */
491                 struct ixgb_option opt = {
492                         .type = enable_option,
493                         .name = "Tx Interrupt Delay Enable",
494                         .err = "defaulting to Enabled",
495                         .def = OPTION_ENABLED,
496                 };
497                 int ide = IntDelayEnable[board];
498
499                 ixgb_validate_option(&ide, &opt);
500                 adapter->tx_int_delay_enable = ide;
501         }
502 }