IB/mthca: Simplify use of size0 in work request posting
[linux-2.6] / drivers / net / ixgb / ixgb_param.c
1 /*******************************************************************************
2
3   Intel PRO/10GbE Linux driver
4   Copyright(c) 1999 - 2006 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 "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: 2 - Tx only (silicon bug avoidance)
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:  65535 (0xffff) (we'll send an xon if we recover)
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 DEFAULT_FCRTL                   0x28000
169 #define DEFAULT_FCRTH                   0x30000
170 #define MIN_FCRTL                             0
171 #define MAX_FCRTL                       0x3FFE8
172 #define MIN_FCRTH                             8
173 #define MAX_FCRTH                       0x3FFF0
174
175 #define MIN_FCPAUSE                           1
176 #define MAX_FCPAUSE                      0xffff
177 #define DEFAULT_FCPAUSE                  0xFFFF /* this may be too long */
178
179 struct ixgb_option {
180         enum { enable_option, range_option, list_option } type;
181         char *name;
182         char *err;
183         int def;
184         union {
185                 struct {        /* range_option info */
186                         int min;
187                         int max;
188                 } r;
189                 struct {        /* list_option info */
190                         int nr;
191                         struct ixgb_opt_list {
192                                 int i;
193                                 char *str;
194                         } *p;
195                 } l;
196         } arg;
197 };
198
199 static int __devinit
200 ixgb_validate_option(int *value, struct ixgb_option *opt)
201 {
202         if(*value == OPTION_UNSET) {
203                 *value = opt->def;
204                 return 0;
205         }
206
207         switch (opt->type) {
208         case enable_option:
209                 switch (*value) {
210                 case OPTION_ENABLED:
211                         printk(KERN_INFO "%s Enabled\n", opt->name);
212                         return 0;
213                 case OPTION_DISABLED:
214                         printk(KERN_INFO "%s Disabled\n", opt->name);
215                         return 0;
216                 }
217                 break;
218         case range_option:
219                 if(*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
220                         printk(KERN_INFO "%s set to %i\n", opt->name, *value);
221                         return 0;
222                 }
223                 break;
224         case list_option: {
225                 int i;
226                 struct ixgb_opt_list *ent;
227
228                 for(i = 0; i < opt->arg.l.nr; i++) {
229                         ent = &opt->arg.l.p[i];
230                         if(*value == ent->i) {
231                                 if(ent->str[0] != '\0')
232                                         printk(KERN_INFO "%s\n", ent->str);
233                                 return 0;
234                         }
235                 }
236         }
237                 break;
238         default:
239                 BUG();
240         }
241
242         printk(KERN_INFO "Invalid %s specified (%i) %s\n",
243                    opt->name, *value, opt->err);
244         *value = opt->def;
245         return -1;
246 }
247
248 /**
249  * ixgb_check_options - Range Checking for Command Line Parameters
250  * @adapter: board private structure
251  *
252  * This routine checks all command line parameters for valid user
253  * input.  If an invalid value is given, or if no user specified
254  * value exists, a default value is used.  The final value is stored
255  * in a variable in the adapter structure.
256  **/
257
258 void __devinit
259 ixgb_check_options(struct ixgb_adapter *adapter)
260 {
261         int bd = adapter->bd_number;
262         if(bd >= IXGB_MAX_NIC) {
263                 printk(KERN_NOTICE
264                            "Warning: no configuration for board #%i\n", bd);
265                 printk(KERN_NOTICE "Using defaults for all values\n");
266         }
267
268         { /* Transmit Descriptor Count */
269                 struct ixgb_option opt = {
270                         .type = range_option,
271                         .name = "Transmit Descriptors",
272                         .err  = "using default of " __MODULE_STRING(DEFAULT_TXD),
273                         .def  = DEFAULT_TXD,
274                         .arg  = { .r = { .min = MIN_TXD,
275                                          .max = MAX_TXD}}
276                 };
277                 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
278
279                 if(num_TxDescriptors > bd) {
280                         tx_ring->count = TxDescriptors[bd];
281                         ixgb_validate_option(&tx_ring->count, &opt);
282                 } else {
283                         tx_ring->count = opt.def;
284                 }
285                 tx_ring->count = ALIGN(tx_ring->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
286         }
287         { /* Receive Descriptor Count */
288                 struct ixgb_option opt = {
289                         .type = range_option,
290                         .name = "Receive Descriptors",
291                         .err  = "using default of " __MODULE_STRING(DEFAULT_RXD),
292                         .def  = DEFAULT_RXD,
293                         .arg  = { .r = { .min = MIN_RXD,
294                                          .max = MAX_RXD}}
295                 };
296                 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
297
298                 if(num_RxDescriptors > bd) {
299                         rx_ring->count = RxDescriptors[bd];
300                         ixgb_validate_option(&rx_ring->count, &opt);
301                 } else {
302                         rx_ring->count = opt.def;
303                 }
304                 rx_ring->count = ALIGN(rx_ring->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
305         }
306         { /* Receive Checksum Offload Enable */
307                 struct ixgb_option opt = {
308                         .type = enable_option,
309                         .name = "Receive Checksum Offload",
310                         .err  = "defaulting to Enabled",
311                         .def  = OPTION_ENABLED
312                 };
313
314                 if(num_XsumRX > bd) {
315                         int rx_csum = XsumRX[bd];
316                         ixgb_validate_option(&rx_csum, &opt);
317                         adapter->rx_csum = rx_csum;
318                 } else {
319                         adapter->rx_csum = opt.def;
320                 }
321         }
322         { /* Flow Control */
323
324                 struct ixgb_opt_list fc_list[] =
325                         {{ ixgb_fc_none,        "Flow Control Disabled" },
326                          { ixgb_fc_rx_pause,"Flow Control Receive Only" },
327                          { ixgb_fc_tx_pause,"Flow Control Transmit Only" },
328                          { ixgb_fc_full,        "Flow Control Enabled" },
329                          { ixgb_fc_default, "Flow Control Hardware Default" }};
330
331                 struct ixgb_option opt = {
332                         .type = list_option,
333                         .name = "Flow Control",
334                         .err  = "reading default settings from EEPROM",
335                         .def  = ixgb_fc_tx_pause,
336                         .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
337                                          .p = fc_list }}
338                 };
339
340                 if(num_FlowControl > bd) {
341                         int fc = FlowControl[bd];
342                         ixgb_validate_option(&fc, &opt);
343                         adapter->hw.fc.type = fc;
344                 } else {
345                         adapter->hw.fc.type = opt.def;
346                 }
347         }
348         { /* Receive Flow Control High Threshold */
349                 struct ixgb_option opt = {
350                         .type = range_option,
351                         .name = "Rx Flow Control High Threshold",
352                         .err  = "using default of " __MODULE_STRING(DEFAULT_FCRTH),
353                         .def  = DEFAULT_FCRTH,
354                         .arg  = { .r = { .min = MIN_FCRTH,
355                                          .max = MAX_FCRTH}}
356                 };
357
358                 if(num_RxFCHighThresh > bd) {
359                         adapter->hw.fc.high_water = RxFCHighThresh[bd];
360                         ixgb_validate_option(&adapter->hw.fc.high_water, &opt);
361                 } else {
362                         adapter->hw.fc.high_water = opt.def;
363                 }
364                 if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
365                         printk (KERN_INFO
366                                 "Ignoring RxFCHighThresh when no RxFC\n");
367         }
368         { /* Receive Flow Control Low Threshold */
369                 struct ixgb_option opt = {
370                         .type = range_option,
371                         .name = "Rx Flow Control Low Threshold",
372                         .err  = "using default of " __MODULE_STRING(DEFAULT_FCRTL),
373                         .def  = DEFAULT_FCRTL,
374                         .arg  = { .r = { .min = MIN_FCRTL,
375                                          .max = MAX_FCRTL}}
376                 };
377
378                 if(num_RxFCLowThresh > bd) {
379                         adapter->hw.fc.low_water = RxFCLowThresh[bd];
380                         ixgb_validate_option(&adapter->hw.fc.low_water, &opt);
381                 } else {
382                         adapter->hw.fc.low_water = opt.def;
383                 }
384                 if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
385                         printk (KERN_INFO
386                                 "Ignoring RxFCLowThresh when no RxFC\n");
387         }
388         { /* Flow Control Pause Time Request*/
389                 struct ixgb_option opt = {
390                         .type = range_option,
391                         .name = "Flow Control Pause Time Request",
392                         .err  = "using default of "__MODULE_STRING(DEFAULT_FCPAUSE),
393                         .def  = DEFAULT_FCPAUSE,
394                         .arg = { .r = { .min = MIN_FCPAUSE,
395                                         .max = MAX_FCPAUSE}}
396                 };
397
398                 if(num_FCReqTimeout > bd) {
399                         int pause_time = FCReqTimeout[bd];
400                         ixgb_validate_option(&pause_time, &opt);
401                         adapter->hw.fc.pause_time = pause_time;
402                 } else {
403                         adapter->hw.fc.pause_time = opt.def;
404                 }
405                 if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
406                         printk (KERN_INFO
407                                 "Ignoring FCReqTimeout when no RxFC\n");
408         }
409         /* high low and spacing check for rx flow control thresholds */
410         if (adapter->hw.fc.type & ixgb_fc_tx_pause) {
411                 /* high must be greater than low */
412                 if (adapter->hw.fc.high_water < (adapter->hw.fc.low_water + 8)) {
413                         /* set defaults */
414                         printk (KERN_INFO 
415                                 "RxFCHighThresh must be >= (RxFCLowThresh + 8), "
416                                 "Using Defaults\n");
417                         adapter->hw.fc.high_water = DEFAULT_FCRTH;
418                         adapter->hw.fc.low_water  = DEFAULT_FCRTL;
419                 }
420         }
421         { /* Receive Interrupt Delay */
422                 struct ixgb_option opt = {
423                         .type = range_option,
424                         .name = "Receive Interrupt Delay",
425                         .err  = "using default of " __MODULE_STRING(DEFAULT_RDTR),
426                         .def  = DEFAULT_RDTR,
427                         .arg  = { .r = { .min = MIN_RDTR,
428                                          .max = MAX_RDTR}}
429                 };
430
431                 if(num_RxIntDelay > bd) {
432                         adapter->rx_int_delay = RxIntDelay[bd];
433                         ixgb_validate_option(&adapter->rx_int_delay, &opt);
434                 } else {
435                         adapter->rx_int_delay = opt.def;
436                 }
437         }
438         { /* Transmit Interrupt Delay */
439                 struct ixgb_option opt = {
440                         .type = range_option,
441                         .name = "Transmit Interrupt Delay",
442                         .err  = "using default of " __MODULE_STRING(DEFAULT_TIDV),
443                         .def  = DEFAULT_TIDV,
444                         .arg  = { .r = { .min = MIN_TIDV,
445                                          .max = MAX_TIDV}}
446                 };
447
448                 if(num_TxIntDelay > bd) {
449                         adapter->tx_int_delay = TxIntDelay[bd];
450                         ixgb_validate_option(&adapter->tx_int_delay, &opt);
451                 } else {
452                         adapter->tx_int_delay = opt.def;
453                 }
454         }
455
456         { /* Transmit Interrupt Delay Enable */
457                 struct ixgb_option opt = {
458                         .type = enable_option,
459                         .name = "Tx Interrupt Delay Enable",
460                         .err  = "defaulting to Enabled",
461                         .def  = OPTION_ENABLED
462                 };
463
464                 if(num_IntDelayEnable > bd) {
465                         int ide = IntDelayEnable[bd];
466                         ixgb_validate_option(&ide, &opt);
467                         adapter->tx_int_delay_enable = ide;
468                 } else {
469                         adapter->tx_int_delay_enable = opt.def;
470                 }
471         }
472 }