blob: af35e1ddadd6d7f50faac9adf712628206d2c0e3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/10GbE Linux driver
Jesse Brandeburgf731a9e2008-07-08 15:53:09 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kok0abb6eb2006-09-27 12:53:14 -07005
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok0abb6eb2006-09-27 12:53:14 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 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 }
Stephen Hemminger273dc742007-10-29 10:46:13 -070047#define IXGB_PARAM(X, desc) \
48 static int __devinitdata X[IXGB_MAX_NIC+1] \
49 = IXGB_PARAM_INIT; \
50 static unsigned int num_##X = 0; \
51 module_param_array_named(X, X, int, &num_##X, 0); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 MODULE_PARM_DESC(X, desc);
53
54/* Transmit Descriptor Count
55 *
56 * Valid Range: 64-4096
57 *
58 * Default Value: 256
59 */
60
61IXGB_PARAM(TxDescriptors, "Number of transmit descriptors");
62
63/* Receive Descriptor Count
64 *
65 * Valid Range: 64-4096
66 *
67 * Default Value: 1024
68 */
69
70IXGB_PARAM(RxDescriptors, "Number of receive descriptors");
71
72/* User Specified Flow Control Override
73 *
74 * Valid Range: 0-3
75 * - 0 - No Flow Control
76 * - 1 - Rx only, respond to PAUSE frames but do not generate them
77 * - 2 - Tx only, generate PAUSE frames but ignore them on receive
78 * - 3 - Full Flow Control Support
79 *
Auke Kok953784d2006-05-23 10:29:50 -070080 * Default Value: 2 - Tx only (silicon bug avoidance)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 */
82
83IXGB_PARAM(FlowControl, "Flow Control setting");
84
85/* XsumRX - Receive Checksum Offload Enable/Disable
86 *
87 * Valid Range: 0, 1
88 * - 0 - disables all checksum offload
89 * - 1 - enables receive IP/TCP/UDP checksum offload
90 * on 82597 based NICs
91 *
92 * Default Value: 1
93 */
94
95IXGB_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
96
97/* Transmit Interrupt Delay in units of 0.8192 microseconds
98 *
99 * Valid Range: 0-65535
100 *
101 * Default Value: 32
102 */
103
104IXGB_PARAM(TxIntDelay, "Transmit Interrupt Delay");
105
106/* Receive Interrupt Delay in units of 0.8192 microseconds
107 *
108 * Valid Range: 0-65535
109 *
110 * Default Value: 72
111 */
112
113IXGB_PARAM(RxIntDelay, "Receive Interrupt Delay");
114
115/* Receive Flow control high threshold (when we send a pause frame)
116 * (FCRTH)
117 *
118 * Valid Range: 1,536 - 262,136 (0x600 - 0x3FFF8, 8 byte granularity)
119 *
120 * Default Value: 196,608 (0x30000)
121 */
122
123IXGB_PARAM(RxFCHighThresh, "Receive Flow Control High Threshold");
124
125/* Receive Flow control low threshold (when we send a resume frame)
126 * (FCRTL)
127 *
128 * Valid Range: 64 - 262,136 (0x40 - 0x3FFF8, 8 byte granularity)
129 * must be less than high threshold by at least 8 bytes
130 *
131 * Default Value: 163,840 (0x28000)
132 */
133
134IXGB_PARAM(RxFCLowThresh, "Receive Flow Control Low Threshold");
135
136/* Flow control request timeout (how long to pause the link partner's tx)
137 * (PAP 15:0)
138 *
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700139 * Valid Range: 1 - 65535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 *
Auke Kok953784d2006-05-23 10:29:50 -0700141 * Default Value: 65535 (0xffff) (we'll send an xon if we recover)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 */
143
144IXGB_PARAM(FCReqTimeout, "Flow Control Request Timeout");
145
146/* Interrupt Delay Enable
147 *
148 * Valid Range: 0, 1
149 *
150 * - 0 - disables transmit interrupt delay
151 * - 1 - enables transmmit interrupt delay
152 *
153 * Default Value: 1
154 */
155
156IXGB_PARAM(IntDelayEnable, "Transmit Interrupt Delay Enable");
157
158
159#define DEFAULT_TIDV 32
160#define MAX_TIDV 0xFFFF
161#define MIN_TIDV 0
162
163#define DEFAULT_RDTR 72
164#define MAX_RDTR 0xFFFF
165#define MIN_RDTR 0
166
167#define XSUMRX_DEFAULT OPTION_ENABLED
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#define DEFAULT_FCRTL 0x28000
170#define DEFAULT_FCRTH 0x30000
171#define MIN_FCRTL 0
172#define MAX_FCRTL 0x3FFE8
173#define MIN_FCRTH 8
174#define MAX_FCRTH 0x3FFF0
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#define MIN_FCPAUSE 1
177#define MAX_FCPAUSE 0xffff
Auke Kok953784d2006-05-23 10:29:50 -0700178#define DEFAULT_FCPAUSE 0xFFFF /* this may be too long */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180struct ixgb_option {
181 enum { enable_option, range_option, list_option } type;
Stephen Hemminger273dc742007-10-29 10:46:13 -0700182 const char *name;
183 const char *err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 int def;
185 union {
186 struct { /* range_option info */
187 int min;
188 int max;
189 } r;
190 struct { /* list_option info */
191 int nr;
192 struct ixgb_opt_list {
193 int i;
194 char *str;
195 } *p;
196 } l;
197 } arg;
198};
199
200static int __devinit
Stephen Hemminger273dc742007-10-29 10:46:13 -0700201ixgb_validate_option(unsigned int *value, const struct ixgb_option *opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700203 if (*value == OPTION_UNSET) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 *value = opt->def;
205 return 0;
206 }
207
208 switch (opt->type) {
209 case enable_option:
210 switch (*value) {
211 case OPTION_ENABLED:
212 printk(KERN_INFO "%s Enabled\n", opt->name);
213 return 0;
214 case OPTION_DISABLED:
215 printk(KERN_INFO "%s Disabled\n", opt->name);
216 return 0;
217 }
218 break;
219 case range_option:
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700220 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 printk(KERN_INFO "%s set to %i\n", opt->name, *value);
222 return 0;
223 }
224 break;
225 case list_option: {
226 int i;
227 struct ixgb_opt_list *ent;
228
Jesse Brandeburg14593362008-07-08 15:52:33 -0700229 for (i = 0; i < opt->arg.l.nr; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 ent = &opt->arg.l.p[i];
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700231 if (*value == ent->i) {
232 if (ent->str[0] != '\0')
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 printk(KERN_INFO "%s\n", ent->str);
234 return 0;
235 }
236 }
237 }
238 break;
239 default:
240 BUG();
241 }
242
243 printk(KERN_INFO "Invalid %s specified (%i) %s\n",
244 opt->name, *value, opt->err);
245 *value = opt->def;
246 return -1;
247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249/**
250 * ixgb_check_options - Range Checking for Command Line Parameters
251 * @adapter: board private structure
252 *
253 * This routine checks all command line parameters for valid user
254 * input. If an invalid value is given, or if no user specified
255 * value exists, a default value is used. The final value is stored
256 * in a variable in the adapter structure.
257 **/
258
259void __devinit
260ixgb_check_options(struct ixgb_adapter *adapter)
261{
262 int bd = adapter->bd_number;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700263 if (bd >= IXGB_MAX_NIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 printk(KERN_NOTICE
265 "Warning: no configuration for board #%i\n", bd);
266 printk(KERN_NOTICE "Using defaults for all values\n");
267 }
268
269 { /* Transmit Descriptor Count */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700270 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 .type = range_option,
272 .name = "Transmit Descriptors",
273 .err = "using default of " __MODULE_STRING(DEFAULT_TXD),
274 .def = DEFAULT_TXD,
275 .arg = { .r = { .min = MIN_TXD,
276 .max = MAX_TXD}}
277 };
278 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
279
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700280 if (num_TxDescriptors > bd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 tx_ring->count = TxDescriptors[bd];
282 ixgb_validate_option(&tx_ring->count, &opt);
283 } else {
284 tx_ring->count = opt.def;
285 }
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700286 tx_ring->count = ALIGN(tx_ring->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
288 { /* Receive Descriptor Count */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700289 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .type = range_option,
291 .name = "Receive Descriptors",
292 .err = "using default of " __MODULE_STRING(DEFAULT_RXD),
293 .def = DEFAULT_RXD,
294 .arg = { .r = { .min = MIN_RXD,
295 .max = MAX_RXD}}
296 };
297 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
298
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700299 if (num_RxDescriptors > bd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 rx_ring->count = RxDescriptors[bd];
301 ixgb_validate_option(&rx_ring->count, &opt);
302 } else {
303 rx_ring->count = opt.def;
304 }
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700305 rx_ring->count = ALIGN(rx_ring->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307 { /* Receive Checksum Offload Enable */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700308 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 .type = enable_option,
310 .name = "Receive Checksum Offload",
311 .err = "defaulting to Enabled",
312 .def = OPTION_ENABLED
313 };
314
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700315 if (num_XsumRX > bd) {
Stephen Hemminger273dc742007-10-29 10:46:13 -0700316 unsigned int rx_csum = XsumRX[bd];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 ixgb_validate_option(&rx_csum, &opt);
318 adapter->rx_csum = rx_csum;
319 } else {
320 adapter->rx_csum = opt.def;
321 }
322 }
323 { /* Flow Control */
324
325 struct ixgb_opt_list fc_list[] =
326 {{ ixgb_fc_none, "Flow Control Disabled" },
327 { ixgb_fc_rx_pause,"Flow Control Receive Only" },
328 { ixgb_fc_tx_pause,"Flow Control Transmit Only" },
329 { ixgb_fc_full, "Flow Control Enabled" },
330 { ixgb_fc_default, "Flow Control Hardware Default" }};
331
Stephen Hemminger273dc742007-10-29 10:46:13 -0700332 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 .type = list_option,
334 .name = "Flow Control",
335 .err = "reading default settings from EEPROM",
Auke Kok953784d2006-05-23 10:29:50 -0700336 .def = ixgb_fc_tx_pause,
Ahmed S. Darwish1c8816c2007-03-06 11:08:28 -0800337 .arg = { .l = { .nr = ARRAY_SIZE(fc_list),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 .p = fc_list }}
339 };
340
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700341 if (num_FlowControl > bd) {
Stephen Hemminger273dc742007-10-29 10:46:13 -0700342 unsigned int fc = FlowControl[bd];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 ixgb_validate_option(&fc, &opt);
344 adapter->hw.fc.type = fc;
345 } else {
346 adapter->hw.fc.type = opt.def;
347 }
348 }
349 { /* Receive Flow Control High Threshold */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700350 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 .type = range_option,
352 .name = "Rx Flow Control High Threshold",
353 .err = "using default of " __MODULE_STRING(DEFAULT_FCRTH),
354 .def = DEFAULT_FCRTH,
355 .arg = { .r = { .min = MIN_FCRTH,
356 .max = MAX_FCRTH}}
357 };
358
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700359 if (num_RxFCHighThresh > bd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 adapter->hw.fc.high_water = RxFCHighThresh[bd];
361 ixgb_validate_option(&adapter->hw.fc.high_water, &opt);
362 } else {
363 adapter->hw.fc.high_water = opt.def;
364 }
Auke Kok953784d2006-05-23 10:29:50 -0700365 if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
Jesse Brandeburg8441dab2008-07-08 15:52:38 -0700366 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 "Ignoring RxFCHighThresh when no RxFC\n");
368 }
369 { /* Receive Flow Control Low Threshold */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700370 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 .type = range_option,
372 .name = "Rx Flow Control Low Threshold",
373 .err = "using default of " __MODULE_STRING(DEFAULT_FCRTL),
374 .def = DEFAULT_FCRTL,
375 .arg = { .r = { .min = MIN_FCRTL,
376 .max = MAX_FCRTL}}
377 };
378
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700379 if (num_RxFCLowThresh > bd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 adapter->hw.fc.low_water = RxFCLowThresh[bd];
381 ixgb_validate_option(&adapter->hw.fc.low_water, &opt);
382 } else {
383 adapter->hw.fc.low_water = opt.def;
384 }
Auke Kok953784d2006-05-23 10:29:50 -0700385 if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
Jesse Brandeburg8441dab2008-07-08 15:52:38 -0700386 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 "Ignoring RxFCLowThresh when no RxFC\n");
388 }
389 { /* Flow Control Pause Time Request*/
Stephen Hemminger273dc742007-10-29 10:46:13 -0700390 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .type = range_option,
392 .name = "Flow Control Pause Time Request",
393 .err = "using default of "__MODULE_STRING(DEFAULT_FCPAUSE),
394 .def = DEFAULT_FCPAUSE,
395 .arg = { .r = { .min = MIN_FCPAUSE,
396 .max = MAX_FCPAUSE}}
397 };
398
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700399 if (num_FCReqTimeout > bd) {
Stephen Hemminger273dc742007-10-29 10:46:13 -0700400 unsigned int pause_time = FCReqTimeout[bd];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 ixgb_validate_option(&pause_time, &opt);
402 adapter->hw.fc.pause_time = pause_time;
403 } else {
404 adapter->hw.fc.pause_time = opt.def;
405 }
Auke Kok953784d2006-05-23 10:29:50 -0700406 if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
Jesse Brandeburg8441dab2008-07-08 15:52:38 -0700407 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 "Ignoring FCReqTimeout when no RxFC\n");
409 }
410 /* high low and spacing check for rx flow control thresholds */
Auke Kok953784d2006-05-23 10:29:50 -0700411 if (adapter->hw.fc.type & ixgb_fc_tx_pause) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* high must be greater than low */
413 if (adapter->hw.fc.high_water < (adapter->hw.fc.low_water + 8)) {
414 /* set defaults */
Jesse Brandeburg8441dab2008-07-08 15:52:38 -0700415 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 "RxFCHighThresh must be >= (RxFCLowThresh + 8), "
417 "Using Defaults\n");
418 adapter->hw.fc.high_water = DEFAULT_FCRTH;
419 adapter->hw.fc.low_water = DEFAULT_FCRTL;
420 }
421 }
422 { /* Receive Interrupt Delay */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700423 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .type = range_option,
425 .name = "Receive Interrupt Delay",
426 .err = "using default of " __MODULE_STRING(DEFAULT_RDTR),
427 .def = DEFAULT_RDTR,
428 .arg = { .r = { .min = MIN_RDTR,
429 .max = MAX_RDTR}}
430 };
431
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700432 if (num_RxIntDelay > bd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 adapter->rx_int_delay = RxIntDelay[bd];
434 ixgb_validate_option(&adapter->rx_int_delay, &opt);
435 } else {
436 adapter->rx_int_delay = opt.def;
437 }
438 }
439 { /* Transmit Interrupt Delay */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700440 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .type = range_option,
442 .name = "Transmit Interrupt Delay",
443 .err = "using default of " __MODULE_STRING(DEFAULT_TIDV),
444 .def = DEFAULT_TIDV,
445 .arg = { .r = { .min = MIN_TIDV,
446 .max = MAX_TIDV}}
447 };
448
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700449 if (num_TxIntDelay > bd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 adapter->tx_int_delay = TxIntDelay[bd];
451 ixgb_validate_option(&adapter->tx_int_delay, &opt);
452 } else {
453 adapter->tx_int_delay = opt.def;
454 }
455 }
456
457 { /* Transmit Interrupt Delay Enable */
Stephen Hemminger273dc742007-10-29 10:46:13 -0700458 const struct ixgb_option opt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 .type = enable_option,
460 .name = "Tx Interrupt Delay Enable",
461 .err = "defaulting to Enabled",
462 .def = OPTION_ENABLED
463 };
464
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700465 if (num_IntDelayEnable > bd) {
Stephen Hemminger273dc742007-10-29 10:46:13 -0700466 unsigned int ide = IntDelayEnable[bd];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 ixgb_validate_option(&ide, &opt);
468 adapter->tx_int_delay_enable = ide;
469 } else {
470 adapter->tx_int_delay_enable = opt.def;
471 }
472 }
473}