1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2013 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
29 #include <linux/netdevice.h>
33 /* This is the only thing that needs to be changed to adjust the
34 * maximum number of ports that the driver can manage.
37 #define IGB_MAX_NIC 32
39 #define OPTION_UNSET -1
40 #define OPTION_DISABLED 0
41 #define OPTION_ENABLED 1
42 #define MAX_NUM_LIST_OPTS 15
44 /* All parameters are treated the same, as an integer array of values.
45 * This macro just reduces the need to repeat the same declaration code
46 * over and over (plus this helps to avoid typo bugs).
49 #define IGB_PARAM_INIT { [0 ... IGB_MAX_NIC] = OPTION_UNSET }
50 #ifndef module_param_array
51 /* Module Parameters are always initialized to -1, so that the driver
52 * can tell the difference between no user specified value or the
53 * user asking for the default value.
54 * The true default values are loaded in when igb_check_options is called.
56 * This is a GCC extension to ANSI C.
57 * See the item "Labeled Elements in Initializers" in the section
58 * "Extensions to the C Language Family" of the GCC documentation.
61 #define IGB_PARAM(X, desc) \
62 static const int X[IGB_MAX_NIC+1] = IGB_PARAM_INIT; \
63 MODULE_PARM(X, "1-" __MODULE_STRING(IGB_MAX_NIC) "i"); \
64 MODULE_PARM_DESC(X, desc);
66 #define IGB_PARAM(X, desc) \
67 static int X[IGB_MAX_NIC+1] = IGB_PARAM_INIT; \
68 static unsigned int num_##X; \
69 module_param_array_named(X, X, int, &num_##X, 0); \
70 MODULE_PARM_DESC(X, desc);
73 /* Interrupt Throttle Rate (interrupts/sec)
75 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
77 IGB_PARAM(InterruptThrottleRate,
78 "Maximum interrupts per second, per vector, (max 100000), default 3=adaptive");
80 #define MAX_ITR 100000
81 /* #define MIN_ITR 120 */
83 /* IntMode (Interrupt Mode)
87 * Default Value: 2 (MSI-X)
89 IGB_PARAM(IntMode, "Change Interrupt Mode (0=Legacy, 1=MSI, 2=MSI-X), default 2");
90 #define MAX_INTMODE IGB_INT_MODE_MSIX
91 #define MIN_INTMODE IGB_INT_MODE_LEGACY
93 IGB_PARAM(Node, "set the starting node to allocate memory on, default -1");
95 /* LLIPort (Low Latency Interrupt TCP Port)
97 * Valid Range: 0 - 65535
99 * Default Value: 0 (disabled)
101 IGB_PARAM(LLIPort, "Low Latency Interrupt TCP Port (0-65535), default 0=off");
103 #define DEFAULT_LLIPORT 0
104 #define MAX_LLIPORT 0xFFFF
105 #define MIN_LLIPORT 0
107 /* LLIPush (Low Latency Interrupt on TCP Push flag)
111 * Default Value: 0 (disabled)
113 IGB_PARAM(LLIPush, "Low Latency Interrupt on TCP Push flag (0,1), default 0=off");
115 #define DEFAULT_LLIPUSH 0
116 #define MAX_LLIPUSH 1
117 #define MIN_LLIPUSH 0
119 /* LLISize (Low Latency Interrupt on Packet Size)
121 * Valid Range: 0 - 1500
123 * Default Value: 0 (disabled)
125 IGB_PARAM(LLISize, "Low Latency Interrupt on Packet Size (0-1500), default 0=off");
127 #define DEFAULT_LLISIZE 0
128 #define MAX_LLISIZE 1500
129 #define MIN_LLISIZE 0
131 /* RSS (Enable RSS multiqueue receive)
137 IGB_PARAM(RSS, "Number of Receive-Side Scaling Descriptor Queues (0-8), default 1, 0=number of cpus");
139 #define DEFAULT_RSS 1
143 /* VMDQ (Enable VMDq multiqueue receive)
149 IGB_PARAM(VMDQ, "Number of Virtual Machine Device Queues: 0-1 = disable, 2-8 enable, default 0");
151 #define DEFAULT_VMDQ 0
152 #define MAX_VMDQ MAX_RSS
155 /* max_vfs (Enable SR-IOV VF devices)
161 IGB_PARAM(max_vfs, "Number of Virtual Functions: 0 = disable, 1-7 enable, default 0");
163 #define DEFAULT_SRIOV 0
167 /* MDD (Enable Malicious Driver Detection)
169 * Only available when SR-IOV is enabled - max_vfs is greater than 0
175 IGB_PARAM(MDD, "Malicious Driver Detection (0/1), default 1 = enabled. "
176 "Only available when max_vfs is greater than 0");
180 /* Disable Hardware Reset on Tx Hang
184 * Default Value: 0 (disabled, i.e. h/w will reset)
186 IGB_PARAM(DisableHwReset, "Disable reset of hardware on Tx hang");
188 /* Dump Transmit and Receive buffers
194 IGB_PARAM(DumpBuffers, "Dump Tx/Rx buffers on Tx hang or by request");
198 /* QueuePairs (Enable TX/RX queue pairs for interrupt handling)
204 IGB_PARAM(QueuePairs, "Enable Tx/Rx queue pairs for interrupt handling (0,1), default 1=on");
206 #define DEFAULT_QUEUE_PAIRS 1
207 #define MAX_QUEUE_PAIRS 1
208 #define MIN_QUEUE_PAIRS 0
210 /* Enable/disable EEE (a.k.a. IEEE802.3az)
216 IGB_PARAM(EEE, "Enable/disable on parts that support the feature");
218 /* Enable/disable DMA Coalescing
220 * Valid Values: 0(off), 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000,
221 * 9000, 10000(msec), 250(usec), 500(usec)
225 IGB_PARAM(DMAC, "Disable or set latency for DMA Coalescing ((0=off, 1000-10000(msec), 250, 500 (usec))");
228 /* Enable/disable Large Receive Offload
230 * Valid Values: 0(off), 1(on)
234 IGB_PARAM(LRO, "Large Receive Offload (0,1), default 0=off");
237 struct igb_opt_list {
242 enum { enable_option, range_option, list_option } type;
247 struct { /* range_option info */
251 struct { /* list_option info */
253 struct igb_opt_list *p;
258 static int igb_validate_option(unsigned int *value,
259 struct igb_option *opt,
260 struct igb_adapter *adapter)
262 if (*value == OPTION_UNSET) {
271 DPRINTK(PROBE, INFO, "%s Enabled\n", opt->name);
273 case OPTION_DISABLED:
274 DPRINTK(PROBE, INFO, "%s Disabled\n", opt->name);
279 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
281 "%s set to %d\n", opt->name, *value);
287 struct igb_opt_list *ent;
289 for (i = 0; i < opt->arg.l.nr; i++) {
290 ent = &opt->arg.l.p[i];
291 if (*value == ent->i) {
292 if (ent->str[0] != '\0')
293 DPRINTK(PROBE, INFO, "%s\n", ent->str);
303 DPRINTK(PROBE, INFO, "Invalid %s value specified (%d) %s\n",
304 opt->name, *value, opt->err);
310 * igb_check_options - Range Checking for Command Line Parameters
311 * @adapter: board private structure
313 * This routine checks all command line parameters for valid user
314 * input. If an invalid value is given, or if no user specified
315 * value exists, a default value is used. The final value is stored
316 * in a variable in the adapter structure.
319 void igb_check_options(struct igb_adapter *adapter)
321 int bd = adapter->bd_number;
322 struct e1000_hw *hw = &adapter->hw;
324 if (bd >= IGB_MAX_NIC) {
325 DPRINTK(PROBE, NOTICE,
326 "Warning: no configuration for board #%d\n", bd);
327 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
328 #ifndef module_param_array
333 { /* Interrupt Throttling Rate */
334 struct igb_option opt = {
335 .type = range_option,
336 .name = "Interrupt Throttling Rate (ints/sec)",
337 .err = "using default of " __MODULE_STRING(DEFAULT_ITR),
339 .arg = { .r = { .min = MIN_ITR,
343 #ifdef module_param_array
344 if (num_InterruptThrottleRate > bd) {
346 unsigned int itr = InterruptThrottleRate[bd];
350 DPRINTK(PROBE, INFO, "%s turned off\n",
352 if (hw->mac.type >= e1000_i350)
353 adapter->dmac = IGB_DMAC_DISABLE;
354 adapter->rx_itr_setting = itr;
357 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
359 adapter->rx_itr_setting = itr;
363 "%s set to dynamic conservative mode\n",
365 adapter->rx_itr_setting = itr;
368 igb_validate_option(&itr, &opt, adapter);
369 /* Save the setting, because the dynamic bits
370 * change itr. In case of invalid user value,
371 * default to conservative mode, else need to
372 * clear the lower two bits because they are
375 adapter->rx_itr_setting = itr;
377 adapter->rx_itr_setting = 1000000000 /
379 adapter->rx_itr_setting &= ~3;
383 #ifdef module_param_array
385 adapter->rx_itr_setting = opt.def;
388 adapter->tx_itr_setting = adapter->rx_itr_setting;
390 { /* Interrupt Mode */
391 struct igb_option opt = {
392 .type = range_option,
393 .name = "Interrupt Mode",
394 .err = "defaulting to 2 (MSI-X)",
395 .def = IGB_INT_MODE_MSIX,
396 .arg = { .r = { .min = MIN_INTMODE,
397 .max = MAX_INTMODE } }
400 #ifdef module_param_array
401 if (num_IntMode > bd) {
403 unsigned int int_mode = IntMode[bd];
404 igb_validate_option(&int_mode, &opt, adapter);
405 adapter->int_mode = int_mode;
406 #ifdef module_param_array
408 adapter->int_mode = opt.def;
412 { /* Low Latency Interrupt TCP Port */
413 struct igb_option opt = {
414 .type = range_option,
415 .name = "Low Latency Interrupt TCP Port",
416 .err = "using default of " __MODULE_STRING(DEFAULT_LLIPORT),
417 .def = DEFAULT_LLIPORT,
418 .arg = { .r = { .min = MIN_LLIPORT,
419 .max = MAX_LLIPORT } }
422 #ifdef module_param_array
423 if (num_LLIPort > bd) {
425 adapter->lli_port = LLIPort[bd];
426 if (adapter->lli_port) {
427 igb_validate_option(&adapter->lli_port, &opt,
430 DPRINTK(PROBE, INFO, "%s turned off\n",
433 #ifdef module_param_array
435 adapter->lli_port = opt.def;
439 { /* Low Latency Interrupt on Packet Size */
440 struct igb_option opt = {
441 .type = range_option,
442 .name = "Low Latency Interrupt on Packet Size",
443 .err = "using default of " __MODULE_STRING(DEFAULT_LLISIZE),
444 .def = DEFAULT_LLISIZE,
445 .arg = { .r = { .min = MIN_LLISIZE,
446 .max = MAX_LLISIZE } }
449 #ifdef module_param_array
450 if (num_LLISize > bd) {
452 adapter->lli_size = LLISize[bd];
453 if (adapter->lli_size) {
454 igb_validate_option(&adapter->lli_size, &opt,
457 DPRINTK(PROBE, INFO, "%s turned off\n",
460 #ifdef module_param_array
462 adapter->lli_size = opt.def;
466 { /* Low Latency Interrupt on TCP Push flag */
467 struct igb_option opt = {
468 .type = enable_option,
469 .name = "Low Latency Interrupt on TCP Push flag",
470 .err = "defaulting to Disabled",
471 .def = OPTION_DISABLED
474 #ifdef module_param_array
475 if (num_LLIPush > bd) {
477 unsigned int lli_push = LLIPush[bd];
478 igb_validate_option(&lli_push, &opt, adapter);
479 adapter->flags |= lli_push ? IGB_FLAG_LLI_PUSH : 0;
480 #ifdef module_param_array
482 adapter->flags |= opt.def ? IGB_FLAG_LLI_PUSH : 0;
486 { /* SRIOV - Enable SR-IOV VF devices */
487 struct igb_option opt = {
488 .type = range_option,
489 .name = "max_vfs - SR-IOV VF devices",
490 .err = "using default of " __MODULE_STRING(DEFAULT_SRIOV),
491 .def = DEFAULT_SRIOV,
492 .arg = { .r = { .min = MIN_SRIOV,
496 #ifdef module_param_array
497 if (num_max_vfs > bd) {
499 adapter->vfs_allocated_count = max_vfs[bd];
500 igb_validate_option(&adapter->vfs_allocated_count, &opt, adapter);
502 #ifdef module_param_array
504 adapter->vfs_allocated_count = opt.def;
507 if (adapter->vfs_allocated_count) {
508 switch (hw->mac.type) {
514 adapter->vfs_allocated_count = 0;
515 DPRINTK(PROBE, INFO, "SR-IOV option max_vfs not supported.\n");
521 { /* VMDQ - Enable VMDq multiqueue receive */
522 struct igb_option opt = {
523 .type = range_option,
524 .name = "VMDQ - VMDq multiqueue queue count",
525 .err = "using default of " __MODULE_STRING(DEFAULT_VMDQ),
527 .arg = { .r = { .min = MIN_VMDQ,
528 .max = (MAX_VMDQ - adapter->vfs_allocated_count) } }
530 if ((hw->mac.type != e1000_i210) ||
531 (hw->mac.type != e1000_i211)) {
532 #ifdef module_param_array
535 adapter->vmdq_pools = (VMDQ[bd] == 1 ? 0 : VMDQ[bd]);
536 if (adapter->vfs_allocated_count && !adapter->vmdq_pools) {
537 DPRINTK(PROBE, INFO, "Enabling SR-IOV requires VMDq be set to at least 1\n");
538 adapter->vmdq_pools = 1;
540 igb_validate_option(&adapter->vmdq_pools, &opt, adapter);
542 #ifdef module_param_array
544 if (!adapter->vfs_allocated_count)
545 adapter->vmdq_pools = (opt.def == 1 ? 0 : opt.def);
547 adapter->vmdq_pools = 1;
550 #ifdef CONFIG_IGB_VMDQ_NETDEV
551 if (hw->mac.type == e1000_82575 && adapter->vmdq_pools) {
552 DPRINTK(PROBE, INFO, "VMDq not supported on this part.\n");
553 adapter->vmdq_pools = 0;
558 DPRINTK(PROBE, INFO, "VMDq option is not supported.\n");
559 adapter->vmdq_pools = opt.def;
562 { /* RSS - Enable RSS multiqueue receives */
563 struct igb_option opt = {
564 .type = range_option,
565 .name = "RSS - RSS multiqueue receive count",
566 .err = "using default of " __MODULE_STRING(DEFAULT_RSS),
568 .arg = { .r = { .min = MIN_RSS,
572 switch (hw->mac.type) {
574 #ifndef CONFIG_IGB_VMDQ_NETDEV
575 if (!!adapter->vmdq_pools) {
576 if (adapter->vmdq_pools <= 2) {
577 if (adapter->vmdq_pools == 2)
586 opt.arg.r.max = !!adapter->vmdq_pools ? 1 : 4;
587 #endif /* CONFIG_IGB_VMDQ_NETDEV */
596 #ifndef CONFIG_IGB_VMDQ_NETDEV
597 if (!!adapter->vmdq_pools)
600 #endif /* CONFIG_IGB_VMDQ_NETDEV */
605 if (!!adapter->vmdq_pools)
610 if (adapter->int_mode != IGB_INT_MODE_MSIX) {
611 DPRINTK(PROBE, INFO, "RSS is not supported when in MSI/Legacy Interrupt mode, %s\n",
616 #ifdef module_param_array
619 adapter->rss_queues = RSS[bd];
620 switch (adapter->rss_queues) {
624 igb_validate_option(&adapter->rss_queues, &opt, adapter);
625 if (adapter->rss_queues)
628 adapter->rss_queues = min_t(u32, opt.arg.r.max, num_online_cpus());
631 #ifdef module_param_array
633 adapter->rss_queues = opt.def;
637 { /* QueuePairs - Enable Tx/Rx queue pairs for interrupt handling */
638 struct igb_option opt = {
639 .type = enable_option,
640 .name = "QueuePairs - Tx/Rx queue pairs for interrupt handling",
641 .err = "defaulting to Enabled",
642 .def = OPTION_ENABLED
644 #ifdef module_param_array
645 if (num_QueuePairs > bd) {
647 unsigned int qp = QueuePairs[bd];
649 * We must enable queue pairs if the number of queues
650 * exceeds the number of available interrupts. We are
651 * limited to 10, or 3 per unallocated vf. On I210 and
652 * I211 devices, we are limited to 5 interrupts.
653 * However, since I211 only supports 2 queues, we do not
654 * need to check and override the user option.
656 if (qp == OPTION_DISABLED) {
657 if (adapter->rss_queues > 4)
660 if (adapter->vmdq_pools > 4)
663 if (adapter->rss_queues > 1 &&
664 (adapter->vmdq_pools > 3 ||
665 adapter->vfs_allocated_count > 6))
668 if (hw->mac.type == e1000_i210 &&
669 adapter->rss_queues > 2)
672 if (qp == OPTION_ENABLED)
673 DPRINTK(PROBE, INFO, "Number of queues exceeds available interrupts, %s\n",
676 igb_validate_option(&qp, &opt, adapter);
677 adapter->flags |= qp ? IGB_FLAG_QUEUE_PAIRS : 0;
678 #ifdef module_param_array
680 adapter->flags |= opt.def ? IGB_FLAG_QUEUE_PAIRS : 0;
684 { /* EEE - Enable EEE for capable adapters */
686 if (hw->mac.type >= e1000_i350) {
687 struct igb_option opt = {
688 .type = enable_option,
689 .name = "EEE Support",
690 .err = "defaulting to Enabled",
691 .def = OPTION_ENABLED
693 #ifdef module_param_array
696 unsigned int eee = EEE[bd];
697 igb_validate_option(&eee, &opt, adapter);
698 adapter->flags |= eee ? IGB_FLAG_EEE : 0;
700 hw->dev_spec._82575.eee_disable = false;
702 hw->dev_spec._82575.eee_disable = true;
704 #ifdef module_param_array
706 adapter->flags |= opt.def ? IGB_FLAG_EEE : 0;
707 if (adapter->flags & IGB_FLAG_EEE)
708 hw->dev_spec._82575.eee_disable = false;
710 hw->dev_spec._82575.eee_disable = true;
715 { /* DMAC - Enable DMA Coalescing for capable adapters */
717 if (hw->mac.type >= e1000_i350) {
718 struct igb_opt_list list [] = {
719 { IGB_DMAC_DISABLE, "DMAC Disable"},
720 { IGB_DMAC_MIN, "DMAC 250 usec"},
721 { IGB_DMAC_500, "DMAC 500 usec"},
722 { IGB_DMAC_EN_DEFAULT, "DMAC 1000 usec"},
723 { IGB_DMAC_2000, "DMAC 2000 usec"},
724 { IGB_DMAC_3000, "DMAC 3000 usec"},
725 { IGB_DMAC_4000, "DMAC 4000 usec"},
726 { IGB_DMAC_5000, "DMAC 5000 usec"},
727 { IGB_DMAC_6000, "DMAC 6000 usec"},
728 { IGB_DMAC_7000, "DMAC 7000 usec"},
729 { IGB_DMAC_8000, "DMAC 8000 usec"},
730 { IGB_DMAC_9000, "DMAC 9000 usec"},
731 { IGB_DMAC_MAX, "DMAC 10000 usec"}
733 struct igb_option opt = {
735 .name = "DMA Coalescing",
736 .err = "using default of "__MODULE_STRING(IGB_DMAC_DISABLE),
737 .def = IGB_DMAC_DISABLE,
738 .arg = { .l = { .nr = 13,
743 #ifdef module_param_array
746 unsigned int dmac = DMAC[bd];
747 if (adapter->rx_itr_setting == IGB_DMAC_DISABLE)
748 dmac = IGB_DMAC_DISABLE;
749 igb_validate_option(&dmac, &opt, adapter);
751 case IGB_DMAC_DISABLE:
752 adapter->dmac = dmac;
755 adapter->dmac = dmac;
758 adapter->dmac = dmac;
760 case IGB_DMAC_EN_DEFAULT:
761 adapter->dmac = dmac;
764 adapter->dmac = dmac;
767 adapter->dmac = dmac;
770 adapter->dmac = dmac;
773 adapter->dmac = dmac;
776 adapter->dmac = dmac;
779 adapter->dmac = dmac;
782 adapter->dmac = dmac;
785 adapter->dmac = dmac;
788 adapter->dmac = dmac;
791 adapter->dmac = opt.def;
793 "Invalid DMAC setting, "
794 "resetting DMAC to %d\n", opt.def);
796 #ifdef module_param_array
798 adapter->dmac = opt.def;
803 { /* LRO - Enable Large Receive Offload */
804 struct igb_option opt = {
805 .type = enable_option,
806 .name = "LRO - Large Receive Offload",
807 .err = "defaulting to Disabled",
808 .def = OPTION_DISABLED
810 struct net_device *netdev = adapter->netdev;
811 #ifdef module_param_array
814 unsigned int lro = LRO[bd];
815 igb_validate_option(&lro, &opt, adapter);
816 netdev->features |= lro ? NETIF_F_LRO : 0;
817 #ifdef module_param_array
818 } else if (opt.def == OPTION_ENABLED) {
819 netdev->features |= NETIF_F_LRO;
823 #endif /* IGB_NO_LRO */
824 { /* MDD - Enable Malicious Driver Detection. Only available when
825 SR-IOV is enabled. */
826 struct igb_option opt = {
827 .type = enable_option,
828 .name = "Malicious Driver Detection",
829 .err = "defaulting to 1",
830 .def = OPTION_ENABLED,
831 .arg = { .r = { .min = OPTION_DISABLED,
832 .max = OPTION_ENABLED } }
835 #ifdef module_param_array
838 adapter->mdd = MDD[bd];
839 igb_validate_option((uint *)&adapter->mdd, &opt,
841 #ifdef module_param_array
843 adapter->mdd = opt.def;