1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/netdevice.h>
23#include <linux/module.h>
24#include <linux/pci.h>
25
26#include "e1000.h"
27
28
29
30
31#define E1000_MAX_NIC 32
32
33#define OPTION_UNSET -1
34#define OPTION_DISABLED 0
35#define OPTION_ENABLED 1
36
37#define COPYBREAK_DEFAULT 256
38unsigned int copybreak = COPYBREAK_DEFAULT;
39module_param(copybreak, uint, 0644);
40MODULE_PARM_DESC(copybreak,
41 "Maximum size of packet that is copied to a new buffer on receive");
42
43
44
45
46
47#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
48#define E1000_PARAM(X, desc) \
49 static int X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
50 static unsigned int num_##X; \
51 module_param_array_named(X, X, int, &num_##X, 0); \
52 MODULE_PARM_DESC(X, desc);
53
54
55
56
57
58
59E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
60#define DEFAULT_TIDV 8
61#define MAX_TXDELAY 0xFFFF
62#define MIN_TXDELAY 0
63
64
65
66
67
68E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
69#define DEFAULT_TADV 32
70#define MAX_TXABSDELAY 0xFFFF
71#define MIN_TXABSDELAY 0
72
73
74
75
76
77
78E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
79#define MAX_RXDELAY 0xFFFF
80#define MIN_RXDELAY 0
81
82
83
84
85
86E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
87#define MAX_RXABSDELAY 0xFFFF
88#define MIN_RXABSDELAY 0
89
90
91
92
93
94E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
95#define DEFAULT_ITR 3
96#define MAX_ITR 100000
97#define MIN_ITR 100
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113E1000_PARAM(IntMode, "Interrupt Mode");
114#define MAX_INTMODE 2
115#define MIN_INTMODE 0
116
117
118
119
120
121
122
123E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
124
125
126
127
128
129
130
131E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
132
133
134
135
136
137
138
139E1000_PARAM(WriteProtectNVM,
140 "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
141
142
143
144
145
146
147
148E1000_PARAM(CrcStripping,
149 "Enable CRC Stripping, disable if your BMC needs the CRC");
150
151struct e1000_option {
152 enum { enable_option, range_option, list_option } type;
153 const char *name;
154 const char *err;
155 int def;
156 union {
157
158 struct {
159 int min;
160 int max;
161 } r;
162
163 struct {
164 int nr;
165 struct e1000_opt_list {
166 int i;
167 char *str;
168 } *p;
169 } l;
170 } arg;
171};
172
173static int e1000_validate_option(unsigned int *value,
174 const struct e1000_option *opt,
175 struct e1000_adapter *adapter)
176{
177 if (*value == OPTION_UNSET) {
178 *value = opt->def;
179 return 0;
180 }
181
182 switch (opt->type) {
183 case enable_option:
184 switch (*value) {
185 case OPTION_ENABLED:
186 dev_info(&adapter->pdev->dev, "%s Enabled\n",
187 opt->name);
188 return 0;
189 case OPTION_DISABLED:
190 dev_info(&adapter->pdev->dev, "%s Disabled\n",
191 opt->name);
192 return 0;
193 }
194 break;
195 case range_option:
196 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
197 dev_info(&adapter->pdev->dev, "%s set to %i\n",
198 opt->name, *value);
199 return 0;
200 }
201 break;
202 case list_option: {
203 int i;
204 struct e1000_opt_list *ent;
205
206 for (i = 0; i < opt->arg.l.nr; i++) {
207 ent = &opt->arg.l.p[i];
208 if (*value == ent->i) {
209 if (ent->str[0] != '\0')
210 dev_info(&adapter->pdev->dev, "%s\n",
211 ent->str);
212 return 0;
213 }
214 }
215 }
216 break;
217 default:
218 BUG();
219 }
220
221 dev_info(&adapter->pdev->dev, "Invalid %s value specified (%i) %s\n",
222 opt->name, *value, opt->err);
223 *value = opt->def;
224 return -1;
225}
226
227
228
229
230
231
232
233
234
235
236void e1000e_check_options(struct e1000_adapter *adapter)
237{
238 struct e1000_hw *hw = &adapter->hw;
239 int bd = adapter->bd_number;
240
241 if (bd >= E1000_MAX_NIC) {
242 dev_notice(&adapter->pdev->dev,
243 "Warning: no configuration for board #%i\n", bd);
244 dev_notice(&adapter->pdev->dev,
245 "Using defaults for all values\n");
246 }
247
248
249 {
250 static const struct e1000_option opt = {
251 .type = range_option,
252 .name = "Transmit Interrupt Delay",
253 .err = "using default of "
254 __MODULE_STRING(DEFAULT_TIDV),
255 .def = DEFAULT_TIDV,
256 .arg = { .r = { .min = MIN_TXDELAY,
257 .max = MAX_TXDELAY } }
258 };
259
260 if (num_TxIntDelay > bd) {
261 adapter->tx_int_delay = TxIntDelay[bd];
262 e1000_validate_option(&adapter->tx_int_delay, &opt,
263 adapter);
264 } else {
265 adapter->tx_int_delay = opt.def;
266 }
267 }
268
269 {
270 static const struct e1000_option opt = {
271 .type = range_option,
272 .name = "Transmit Absolute Interrupt Delay",
273 .err = "using default of "
274 __MODULE_STRING(DEFAULT_TADV),
275 .def = DEFAULT_TADV,
276 .arg = { .r = { .min = MIN_TXABSDELAY,
277 .max = MAX_TXABSDELAY } }
278 };
279
280 if (num_TxAbsIntDelay > bd) {
281 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
282 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
283 adapter);
284 } else {
285 adapter->tx_abs_int_delay = opt.def;
286 }
287 }
288
289 {
290 static struct e1000_option opt = {
291 .type = range_option,
292 .name = "Receive Interrupt Delay",
293 .err = "using default of "
294 __MODULE_STRING(DEFAULT_RDTR),
295 .def = DEFAULT_RDTR,
296 .arg = { .r = { .min = MIN_RXDELAY,
297 .max = MAX_RXDELAY } }
298 };
299
300 if (num_RxIntDelay > bd) {
301 adapter->rx_int_delay = RxIntDelay[bd];
302 e1000_validate_option(&adapter->rx_int_delay, &opt,
303 adapter);
304 } else {
305 adapter->rx_int_delay = opt.def;
306 }
307 }
308
309 {
310 static const struct e1000_option opt = {
311 .type = range_option,
312 .name = "Receive Absolute Interrupt Delay",
313 .err = "using default of "
314 __MODULE_STRING(DEFAULT_RADV),
315 .def = DEFAULT_RADV,
316 .arg = { .r = { .min = MIN_RXABSDELAY,
317 .max = MAX_RXABSDELAY } }
318 };
319
320 if (num_RxAbsIntDelay > bd) {
321 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
322 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
323 adapter);
324 } else {
325 adapter->rx_abs_int_delay = opt.def;
326 }
327 }
328
329 {
330 static const struct e1000_option opt = {
331 .type = range_option,
332 .name = "Interrupt Throttling Rate (ints/sec)",
333 .err = "using default of "
334 __MODULE_STRING(DEFAULT_ITR),
335 .def = DEFAULT_ITR,
336 .arg = { .r = { .min = MIN_ITR,
337 .max = MAX_ITR } }
338 };
339
340 if (num_InterruptThrottleRate > bd) {
341 adapter->itr = InterruptThrottleRate[bd];
342
343
344
345
346
347
348 if ((adapter->itr > 4) &&
349 e1000_validate_option(&adapter->itr, &opt, adapter))
350 adapter->itr = opt.def;
351 } else {
352
353
354
355 adapter->itr = opt.def;
356
357
358
359
360 if (adapter->itr > 4)
361 dev_info(&adapter->pdev->dev,
362 "%s set to default %d\n", opt.name,
363 adapter->itr);
364 }
365
366 adapter->itr_setting = adapter->itr;
367 switch (adapter->itr) {
368 case 0:
369 dev_info(&adapter->pdev->dev, "%s turned off\n",
370 opt.name);
371 break;
372 case 1:
373 dev_info(&adapter->pdev->dev,
374 "%s set to dynamic mode\n", opt.name);
375 adapter->itr = 20000;
376 break;
377 case 2:
378 dev_info(&adapter->pdev->dev,
379 "%s Invalid mode - setting default\n",
380 opt.name);
381 adapter->itr_setting = opt.def;
382
383 case 3:
384 dev_info(&adapter->pdev->dev,
385 "%s set to dynamic conservative mode\n",
386 opt.name);
387 adapter->itr = 20000;
388 break;
389 case 4:
390 dev_info(&adapter->pdev->dev,
391 "%s set to simplified (2000-8000 ints) mode\n",
392 opt.name);
393 break;
394 default:
395
396
397
398
399
400
401 adapter->itr_setting &= ~3;
402 break;
403 }
404 }
405
406 {
407 static struct e1000_option opt = {
408 .type = range_option,
409 .name = "Interrupt Mode",
410#ifndef CONFIG_PCI_MSI
411 .err = "defaulting to 0 (legacy)",
412 .def = E1000E_INT_MODE_LEGACY,
413 .arg = { .r = { .min = 0,
414 .max = 0 } }
415#endif
416 };
417
418#ifdef CONFIG_PCI_MSI
419 if (adapter->flags & FLAG_HAS_MSIX) {
420 opt.err = kstrdup("defaulting to 2 (MSI-X)",
421 GFP_KERNEL);
422 opt.def = E1000E_INT_MODE_MSIX;
423 opt.arg.r.max = E1000E_INT_MODE_MSIX;
424 } else {
425 opt.err = kstrdup("defaulting to 1 (MSI)", GFP_KERNEL);
426 opt.def = E1000E_INT_MODE_MSI;
427 opt.arg.r.max = E1000E_INT_MODE_MSI;
428 }
429
430 if (!opt.err) {
431 dev_err(&adapter->pdev->dev,
432 "Failed to allocate memory\n");
433 return;
434 }
435#endif
436
437 if (num_IntMode > bd) {
438 unsigned int int_mode = IntMode[bd];
439
440 e1000_validate_option(&int_mode, &opt, adapter);
441 adapter->int_mode = int_mode;
442 } else {
443 adapter->int_mode = opt.def;
444 }
445
446#ifdef CONFIG_PCI_MSI
447 kfree(opt.err);
448#endif
449 }
450
451 {
452 static const struct e1000_option opt = {
453 .type = enable_option,
454 .name = "PHY Smart Power Down",
455 .err = "defaulting to Disabled",
456 .def = OPTION_DISABLED
457 };
458
459 if (num_SmartPowerDownEnable > bd) {
460 unsigned int spd = SmartPowerDownEnable[bd];
461
462 e1000_validate_option(&spd, &opt, adapter);
463 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && spd)
464 adapter->flags |= FLAG_SMART_POWER_DOWN;
465 }
466 }
467
468 {
469 static const struct e1000_option opt = {
470 .type = enable_option,
471 .name = "CRC Stripping",
472 .err = "defaulting to Enabled",
473 .def = OPTION_ENABLED
474 };
475
476 if (num_CrcStripping > bd) {
477 unsigned int crc_stripping = CrcStripping[bd];
478
479 e1000_validate_option(&crc_stripping, &opt, adapter);
480 if (crc_stripping == OPTION_ENABLED) {
481 adapter->flags2 |= FLAG2_CRC_STRIPPING;
482 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
483 }
484 } else {
485 adapter->flags2 |= FLAG2_CRC_STRIPPING;
486 adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
487 }
488 }
489
490 {
491 static const struct e1000_option opt = {
492 .type = enable_option,
493 .name = "Kumeran Lock Loss Workaround",
494 .err = "defaulting to Enabled",
495 .def = OPTION_ENABLED
496 };
497 bool enabled = opt.def;
498
499 if (num_KumeranLockLoss > bd) {
500 unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
501
502 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
503 enabled = kmrn_lock_loss;
504 }
505
506 if (hw->mac.type == e1000_ich8lan)
507 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
508 enabled);
509 }
510
511 {
512 static const struct e1000_option opt = {
513 .type = enable_option,
514 .name = "Write-protect NVM",
515 .err = "defaulting to Enabled",
516 .def = OPTION_ENABLED
517 };
518
519 if (adapter->flags & FLAG_IS_ICH) {
520 if (num_WriteProtectNVM > bd) {
521 unsigned int write_protect_nvm =
522 WriteProtectNVM[bd];
523 e1000_validate_option(&write_protect_nvm, &opt,
524 adapter);
525 if (write_protect_nvm)
526 adapter->flags |= FLAG_READ_ONLY_NVM;
527 } else {
528 if (opt.def)
529 adapter->flags |= FLAG_READ_ONLY_NVM;
530 }
531 }
532 }
533}
534