1 // SPDX-License-Identifier: GPL-2.0
2 /*******************************************************************************
4 Intel(R) Gigabit Ethernet Linux driver
5 Copyright(c) 2007-2013 Intel Corporation.
8 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 *******************************************************************************/
14 #include <linux/netdevice.h>
18 /* This is the only thing that needs to be changed to adjust the
19 * maximum number of ports that the driver can manage.
22 #define IGB_MAX_NIC 32
24 #define OPTION_UNSET -1
25 #define OPTION_DISABLED 0
26 #define OPTION_ENABLED 1
27 #define MAX_NUM_LIST_OPTS 15
29 /* All parameters are treated the same, as an integer array of values.
30 * This macro just reduces the need to repeat the same declaration code
31 * over and over (plus this helps to avoid typo bugs).
34 #define IGB_PARAM_INIT { [0 ... IGB_MAX_NIC] = OPTION_UNSET }
35 #ifndef module_param_array
36 /* Module Parameters are always initialized to -1, so that the driver
37 * can tell the difference between no user specified value or the
38 * user asking for the default value.
39 * The true default values are loaded in when igb_check_options is called.
41 * This is a GCC extension to ANSI C.
42 * See the item "Labeled Elements in Initializers" in the section
43 * "Extensions to the C Language Family" of the GCC documentation.
46 #define IGB_PARAM(X, desc) \
47 static const int X[IGB_MAX_NIC+1] = IGB_PARAM_INIT; \
48 MODULE_PARM(X, "1-" __MODULE_STRING(IGB_MAX_NIC) "i"); \
49 MODULE_PARM_DESC(X, desc);
51 #define IGB_PARAM(X, desc) \
52 static int X[IGB_MAX_NIC+1] = IGB_PARAM_INIT; \
53 static unsigned int num_##X; \
54 module_param_array_named(X, X, int, &num_##X, 0); \
55 MODULE_PARM_DESC(X, desc);
58 /* Interrupt Throttle Rate (interrupts/sec)
60 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
62 IGB_PARAM(InterruptThrottleRate,
63 "Maximum interrupts per second, per vector, (max 100000), default 3=adaptive");
65 #define MAX_ITR 100000
66 /* #define MIN_ITR 120 */
68 /* IntMode (Interrupt Mode)
72 * Default Value: 2 (MSI-X)
74 IGB_PARAM(IntMode, "Change Interrupt Mode (0=Legacy, 1=MSI, 2=MSI-X), default 2");
75 #define MAX_INTMODE IGB_INT_MODE_MSIX
76 #define MIN_INTMODE IGB_INT_MODE_LEGACY
78 IGB_PARAM(Node, "set the starting node to allocate memory on, default -1");
80 /* LLIPort (Low Latency Interrupt TCP Port)
82 * Valid Range: 0 - 65535
84 * Default Value: 0 (disabled)
86 IGB_PARAM(LLIPort, "Low Latency Interrupt TCP Port (0-65535), default 0=off");
88 #define DEFAULT_LLIPORT 0
89 #define MAX_LLIPORT 0xFFFF
92 /* LLIPush (Low Latency Interrupt on TCP Push flag)
96 * Default Value: 0 (disabled)
98 IGB_PARAM(LLIPush, "Low Latency Interrupt on TCP Push flag (0,1), default 0=off");
100 #define DEFAULT_LLIPUSH 0
101 #define MAX_LLIPUSH 1
102 #define MIN_LLIPUSH 0
104 /* LLISize (Low Latency Interrupt on Packet Size)
106 * Valid Range: 0 - 1500
108 * Default Value: 0 (disabled)
110 IGB_PARAM(LLISize, "Low Latency Interrupt on Packet Size (0-1500), default 0=off");
112 #define DEFAULT_LLISIZE 0
113 #define MAX_LLISIZE 1500
114 #define MIN_LLISIZE 0
116 /* RSS (Enable RSS multiqueue receive)
122 IGB_PARAM(RSS, "Number of Receive-Side Scaling Descriptor Queues (0-8), default 1, 0=number of cpus");
124 #define DEFAULT_RSS 1
128 /* VMDQ (Enable VMDq multiqueue receive)
134 IGB_PARAM(VMDQ, "Number of Virtual Machine Device Queues: 0-1 = disable, 2-8 enable, default 0");
136 #define DEFAULT_VMDQ 0
137 #define MAX_VMDQ MAX_RSS
140 /* max_vfs (Enable SR-IOV VF devices)
146 IGB_PARAM(max_vfs, "Number of Virtual Functions: 0 = disable, 1-7 enable, default 0");
148 #define DEFAULT_SRIOV 0
152 /* MDD (Enable Malicious Driver Detection)
154 * Only available when SR-IOV is enabled - max_vfs is greater than 0
160 IGB_PARAM(MDD, "Malicious Driver Detection (0/1), default 1 = enabled. "
161 "Only available when max_vfs is greater than 0");
165 /* Disable Hardware Reset on Tx Hang
169 * Default Value: 0 (disabled, i.e. h/w will reset)
171 IGB_PARAM(DisableHwReset, "Disable reset of hardware on Tx hang");
173 /* Dump Transmit and Receive buffers
179 IGB_PARAM(DumpBuffers, "Dump Tx/Rx buffers on Tx hang or by request");
183 /* QueuePairs (Enable TX/RX queue pairs for interrupt handling)
189 IGB_PARAM(QueuePairs, "Enable Tx/Rx queue pairs for interrupt handling (0,1), default 1=on");
191 #define DEFAULT_QUEUE_PAIRS 1
192 #define MAX_QUEUE_PAIRS 1
193 #define MIN_QUEUE_PAIRS 0
195 /* Enable/disable EEE (a.k.a. IEEE802.3az)
201 IGB_PARAM(EEE, "Enable/disable on parts that support the feature");
203 /* Enable/disable DMA Coalescing
205 * Valid Values: 0(off), 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000,
206 * 9000, 10000(msec), 250(usec), 500(usec)
210 IGB_PARAM(DMAC, "Disable or set latency for DMA Coalescing ((0=off, 1000-10000(msec), 250, 500 (usec))");
213 /* Enable/disable Large Receive Offload
215 * Valid Values: 0(off), 1(on)
219 IGB_PARAM(LRO, "Large Receive Offload (0,1), default 0=off");
222 struct igb_opt_list {
227 enum { enable_option, range_option, list_option } type;
232 struct { /* range_option info */
236 struct { /* list_option info */
238 struct igb_opt_list *p;
243 static int igb_validate_option(unsigned int *value,
244 struct igb_option *opt,
245 struct igb_adapter *adapter)
247 if (*value == OPTION_UNSET) {
256 DPRINTK(PROBE, INFO, "%s Enabled\n", opt->name);
258 case OPTION_DISABLED:
259 DPRINTK(PROBE, INFO, "%s Disabled\n", opt->name);
264 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
266 "%s set to %d\n", opt->name, *value);
272 struct igb_opt_list *ent;
274 for (i = 0; i < opt->arg.l.nr; i++) {
275 ent = &opt->arg.l.p[i];
276 if (*value == ent->i) {
277 if (ent->str[0] != '\0')
278 DPRINTK(PROBE, INFO, "%s\n", ent->str);
288 DPRINTK(PROBE, INFO, "Invalid %s value specified (%d) %s\n",
289 opt->name, *value, opt->err);
295 * igb_check_options - Range Checking for Command Line Parameters
296 * @adapter: board private structure
298 * This routine checks all command line parameters for valid user
299 * input. If an invalid value is given, or if no user specified
300 * value exists, a default value is used. The final value is stored
301 * in a variable in the adapter structure.
304 void igb_check_options(struct igb_adapter *adapter)
306 int bd = adapter->bd_number;
307 struct e1000_hw *hw = &adapter->hw;
309 if (bd >= IGB_MAX_NIC) {
310 DPRINTK(PROBE, NOTICE,
311 "Warning: no configuration for board #%d\n", bd);
312 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
313 #ifndef module_param_array
318 { /* Interrupt Throttling Rate */
319 struct igb_option opt = {
320 .type = range_option,
321 .name = "Interrupt Throttling Rate (ints/sec)",
322 .err = "using default of " __MODULE_STRING(DEFAULT_ITR),
324 .arg = { .r = { .min = MIN_ITR,
328 #ifdef module_param_array
329 if (num_InterruptThrottleRate > bd) {
331 unsigned int itr = InterruptThrottleRate[bd];
335 DPRINTK(PROBE, INFO, "%s turned off\n",
337 if (hw->mac.type >= e1000_i350)
338 adapter->dmac = IGB_DMAC_DISABLE;
339 adapter->rx_itr_setting = itr;
342 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
344 adapter->rx_itr_setting = itr;
348 "%s set to dynamic conservative mode\n",
350 adapter->rx_itr_setting = itr;
353 igb_validate_option(&itr, &opt, adapter);
354 /* Save the setting, because the dynamic bits
355 * change itr. In case of invalid user value,
356 * default to conservative mode, else need to
357 * clear the lower two bits because they are
360 adapter->rx_itr_setting = itr;
362 adapter->rx_itr_setting = 1000000000 /
364 adapter->rx_itr_setting &= ~3;
368 #ifdef module_param_array
370 adapter->rx_itr_setting = opt.def;
373 adapter->tx_itr_setting = adapter->rx_itr_setting;
375 { /* Interrupt Mode */
376 struct igb_option opt = {
377 .type = range_option,
378 .name = "Interrupt Mode",
379 .err = "defaulting to 2 (MSI-X)",
380 .def = IGB_INT_MODE_MSIX,
381 .arg = { .r = { .min = MIN_INTMODE,
382 .max = MAX_INTMODE } }
385 #ifdef module_param_array
386 if (num_IntMode > bd) {
388 unsigned int int_mode = IntMode[bd];
389 igb_validate_option(&int_mode, &opt, adapter);
390 adapter->int_mode = int_mode;
391 #ifdef module_param_array
393 adapter->int_mode = opt.def;
397 { /* Low Latency Interrupt TCP Port */
398 struct igb_option opt = {
399 .type = range_option,
400 .name = "Low Latency Interrupt TCP Port",
401 .err = "using default of " __MODULE_STRING(DEFAULT_LLIPORT),
402 .def = DEFAULT_LLIPORT,
403 .arg = { .r = { .min = MIN_LLIPORT,
404 .max = MAX_LLIPORT } }
407 #ifdef module_param_array
408 if (num_LLIPort > bd) {
410 adapter->lli_port = LLIPort[bd];
411 if (adapter->lli_port) {
412 igb_validate_option(&adapter->lli_port, &opt,
415 DPRINTK(PROBE, INFO, "%s turned off\n",
418 #ifdef module_param_array
420 adapter->lli_port = opt.def;
424 { /* Low Latency Interrupt on Packet Size */
425 struct igb_option opt = {
426 .type = range_option,
427 .name = "Low Latency Interrupt on Packet Size",
428 .err = "using default of " __MODULE_STRING(DEFAULT_LLISIZE),
429 .def = DEFAULT_LLISIZE,
430 .arg = { .r = { .min = MIN_LLISIZE,
431 .max = MAX_LLISIZE } }
434 #ifdef module_param_array
435 if (num_LLISize > bd) {
437 adapter->lli_size = LLISize[bd];
438 if (adapter->lli_size) {
439 igb_validate_option(&adapter->lli_size, &opt,
442 DPRINTK(PROBE, INFO, "%s turned off\n",
445 #ifdef module_param_array
447 adapter->lli_size = opt.def;
451 { /* Low Latency Interrupt on TCP Push flag */
452 struct igb_option opt = {
453 .type = enable_option,
454 .name = "Low Latency Interrupt on TCP Push flag",
455 .err = "defaulting to Disabled",
456 .def = OPTION_DISABLED
459 #ifdef module_param_array
460 if (num_LLIPush > bd) {
462 unsigned int lli_push = LLIPush[bd];
463 igb_validate_option(&lli_push, &opt, adapter);
464 adapter->flags |= lli_push ? IGB_FLAG_LLI_PUSH : 0;
465 #ifdef module_param_array
467 adapter->flags |= opt.def ? IGB_FLAG_LLI_PUSH : 0;
471 { /* SRIOV - Enable SR-IOV VF devices */
472 struct igb_option opt = {
473 .type = range_option,
474 .name = "max_vfs - SR-IOV VF devices",
475 .err = "using default of " __MODULE_STRING(DEFAULT_SRIOV),
476 .def = DEFAULT_SRIOV,
477 .arg = { .r = { .min = MIN_SRIOV,
481 #ifdef module_param_array
482 if (num_max_vfs > bd) {
484 adapter->vfs_allocated_count = max_vfs[bd];
485 igb_validate_option(&adapter->vfs_allocated_count, &opt, adapter);
487 #ifdef module_param_array
489 adapter->vfs_allocated_count = opt.def;
492 if (adapter->vfs_allocated_count) {
493 switch (hw->mac.type) {
499 adapter->vfs_allocated_count = 0;
500 DPRINTK(PROBE, INFO, "SR-IOV option max_vfs not supported.\n");
506 { /* VMDQ - Enable VMDq multiqueue receive */
507 struct igb_option opt = {
508 .type = range_option,
509 .name = "VMDQ - VMDq multiqueue queue count",
510 .err = "using default of " __MODULE_STRING(DEFAULT_VMDQ),
512 .arg = { .r = { .min = MIN_VMDQ,
513 .max = (MAX_VMDQ - adapter->vfs_allocated_count) } }
515 if ((hw->mac.type != e1000_i210) ||
516 (hw->mac.type != e1000_i211)) {
517 #ifdef module_param_array
520 adapter->vmdq_pools = (VMDQ[bd] == 1 ? 0 : VMDQ[bd]);
521 if (adapter->vfs_allocated_count && !adapter->vmdq_pools) {
522 DPRINTK(PROBE, INFO, "Enabling SR-IOV requires VMDq be set to at least 1\n");
523 adapter->vmdq_pools = 1;
525 igb_validate_option(&adapter->vmdq_pools, &opt, adapter);
527 #ifdef module_param_array
529 if (!adapter->vfs_allocated_count)
530 adapter->vmdq_pools = (opt.def == 1 ? 0 : opt.def);
532 adapter->vmdq_pools = 1;
535 #ifdef CONFIG_IGB_VMDQ_NETDEV
536 if (hw->mac.type == e1000_82575 && adapter->vmdq_pools) {
537 DPRINTK(PROBE, INFO, "VMDq not supported on this part.\n");
538 adapter->vmdq_pools = 0;
543 DPRINTK(PROBE, INFO, "VMDq option is not supported.\n");
544 adapter->vmdq_pools = opt.def;
547 { /* RSS - Enable RSS multiqueue receives */
548 struct igb_option opt = {
549 .type = range_option,
550 .name = "RSS - RSS multiqueue receive count",
551 .err = "using default of " __MODULE_STRING(DEFAULT_RSS),
553 .arg = { .r = { .min = MIN_RSS,
557 switch (hw->mac.type) {
559 #ifndef CONFIG_IGB_VMDQ_NETDEV
560 if (!!adapter->vmdq_pools) {
561 if (adapter->vmdq_pools <= 2) {
562 if (adapter->vmdq_pools == 2)
571 opt.arg.r.max = !!adapter->vmdq_pools ? 1 : 4;
572 #endif /* CONFIG_IGB_VMDQ_NETDEV */
581 #ifndef CONFIG_IGB_VMDQ_NETDEV
582 if (!!adapter->vmdq_pools)
585 #endif /* CONFIG_IGB_VMDQ_NETDEV */
590 if (!!adapter->vmdq_pools)
595 if (adapter->int_mode != IGB_INT_MODE_MSIX) {
596 DPRINTK(PROBE, INFO, "RSS is not supported when in MSI/Legacy Interrupt mode, %s\n",
601 #ifdef module_param_array
604 adapter->rss_queues = RSS[bd];
605 switch (adapter->rss_queues) {
609 igb_validate_option(&adapter->rss_queues, &opt, adapter);
610 if (adapter->rss_queues)
613 adapter->rss_queues = min_t(u32, opt.arg.r.max, num_online_cpus());
616 #ifdef module_param_array
618 adapter->rss_queues = opt.def;
622 { /* QueuePairs - Enable Tx/Rx queue pairs for interrupt handling */
623 struct igb_option opt = {
624 .type = enable_option,
625 .name = "QueuePairs - Tx/Rx queue pairs for interrupt handling",
626 .err = "defaulting to Enabled",
627 .def = OPTION_ENABLED
629 #ifdef module_param_array
630 if (num_QueuePairs > bd) {
632 unsigned int qp = QueuePairs[bd];
634 * We must enable queue pairs if the number of queues
635 * exceeds the number of available interrupts. We are
636 * limited to 10, or 3 per unallocated vf. On I210 and
637 * I211 devices, we are limited to 5 interrupts.
638 * However, since I211 only supports 2 queues, we do not
639 * need to check and override the user option.
641 if (qp == OPTION_DISABLED) {
642 if (adapter->rss_queues > 4)
645 if (adapter->vmdq_pools > 4)
648 if (adapter->rss_queues > 1 &&
649 (adapter->vmdq_pools > 3 ||
650 adapter->vfs_allocated_count > 6))
653 if (hw->mac.type == e1000_i210 &&
654 adapter->rss_queues > 2)
657 if (qp == OPTION_ENABLED)
658 DPRINTK(PROBE, INFO, "Number of queues exceeds available interrupts, %s\n",
661 igb_validate_option(&qp, &opt, adapter);
662 adapter->flags |= qp ? IGB_FLAG_QUEUE_PAIRS : 0;
663 #ifdef module_param_array
665 adapter->flags |= opt.def ? IGB_FLAG_QUEUE_PAIRS : 0;
669 { /* EEE - Enable EEE for capable adapters */
671 if (hw->mac.type >= e1000_i350) {
672 struct igb_option opt = {
673 .type = enable_option,
674 .name = "EEE Support",
675 .err = "defaulting to Enabled",
676 .def = OPTION_ENABLED
678 #ifdef module_param_array
681 unsigned int eee = EEE[bd];
682 igb_validate_option(&eee, &opt, adapter);
683 adapter->flags |= eee ? IGB_FLAG_EEE : 0;
685 hw->dev_spec._82575.eee_disable = false;
687 hw->dev_spec._82575.eee_disable = true;
689 #ifdef module_param_array
691 adapter->flags |= opt.def ? IGB_FLAG_EEE : 0;
692 if (adapter->flags & IGB_FLAG_EEE)
693 hw->dev_spec._82575.eee_disable = false;
695 hw->dev_spec._82575.eee_disable = true;
700 { /* DMAC - Enable DMA Coalescing for capable adapters */
702 if (hw->mac.type >= e1000_i350) {
703 struct igb_opt_list list [] = {
704 { IGB_DMAC_DISABLE, "DMAC Disable"},
705 { IGB_DMAC_MIN, "DMAC 250 usec"},
706 { IGB_DMAC_500, "DMAC 500 usec"},
707 { IGB_DMAC_EN_DEFAULT, "DMAC 1000 usec"},
708 { IGB_DMAC_2000, "DMAC 2000 usec"},
709 { IGB_DMAC_3000, "DMAC 3000 usec"},
710 { IGB_DMAC_4000, "DMAC 4000 usec"},
711 { IGB_DMAC_5000, "DMAC 5000 usec"},
712 { IGB_DMAC_6000, "DMAC 6000 usec"},
713 { IGB_DMAC_7000, "DMAC 7000 usec"},
714 { IGB_DMAC_8000, "DMAC 8000 usec"},
715 { IGB_DMAC_9000, "DMAC 9000 usec"},
716 { IGB_DMAC_MAX, "DMAC 10000 usec"}
718 struct igb_option opt = {
720 .name = "DMA Coalescing",
721 .err = "using default of "__MODULE_STRING(IGB_DMAC_DISABLE),
722 .def = IGB_DMAC_DISABLE,
723 .arg = { .l = { .nr = 13,
728 #ifdef module_param_array
731 unsigned int dmac = DMAC[bd];
732 if (adapter->rx_itr_setting == IGB_DMAC_DISABLE)
733 dmac = IGB_DMAC_DISABLE;
734 igb_validate_option(&dmac, &opt, adapter);
736 case IGB_DMAC_DISABLE:
737 adapter->dmac = dmac;
740 adapter->dmac = dmac;
743 adapter->dmac = dmac;
745 case IGB_DMAC_EN_DEFAULT:
746 adapter->dmac = dmac;
749 adapter->dmac = dmac;
752 adapter->dmac = dmac;
755 adapter->dmac = dmac;
758 adapter->dmac = dmac;
761 adapter->dmac = dmac;
764 adapter->dmac = dmac;
767 adapter->dmac = dmac;
770 adapter->dmac = dmac;
773 adapter->dmac = dmac;
776 adapter->dmac = opt.def;
778 "Invalid DMAC setting, "
779 "resetting DMAC to %d\n", opt.def);
781 #ifdef module_param_array
783 adapter->dmac = opt.def;
788 { /* LRO - Enable Large Receive Offload */
789 struct igb_option opt = {
790 .type = enable_option,
791 .name = "LRO - Large Receive Offload",
792 .err = "defaulting to Disabled",
793 .def = OPTION_DISABLED
795 struct net_device *netdev = adapter->netdev;
796 #ifdef module_param_array
799 unsigned int lro = LRO[bd];
800 igb_validate_option(&lro, &opt, adapter);
801 netdev->features |= lro ? NETIF_F_LRO : 0;
802 #ifdef module_param_array
803 } else if (opt.def == OPTION_ENABLED) {
804 netdev->features |= NETIF_F_LRO;
808 #endif /* IGB_NO_LRO */
809 { /* MDD - Enable Malicious Driver Detection. Only available when
810 SR-IOV is enabled. */
811 struct igb_option opt = {
812 .type = enable_option,
813 .name = "Malicious Driver Detection",
814 .err = "defaulting to 1",
815 .def = OPTION_ENABLED,
816 .arg = { .r = { .min = OPTION_DISABLED,
817 .max = OPTION_ENABLED } }
820 #ifdef module_param_array
823 adapter->mdd = MDD[bd];
824 igb_validate_option((uint *)&adapter->mdd, &opt,
826 #ifdef module_param_array
828 adapter->mdd = opt.def;