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