1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2012 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 __devinitdata 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 __devinitdata 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=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");
179 /* QueuePairs (Enable TX/RX queue pairs for interrupt handling)
185 IGB_PARAM(QueuePairs, "Enable TX/RX queue pairs for interrupt handling (0,1), default 1=on");
187 #define DEFAULT_QUEUE_PAIRS 1
188 #define MAX_QUEUE_PAIRS 1
189 #define MIN_QUEUE_PAIRS 0
191 /* Enable/disable EEE (a.k.a. IEEE802.3az)
197 IGB_PARAM(EEE, "Enable/disable on parts that support the feature");
199 /* Enable/disable DMA Coalescing
201 * Valid Values: 0(off), 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000,
202 * 9000, 10000(msec), 250(usec), 500(usec)
206 IGB_PARAM(DMAC, "Disable or set latency for DMA Coalescing ((0=off, 1000-10000(msec), 250, 500 (usec))");
209 /* Enable/disable Large Receive Offload
211 * Valid Values: 0(off), 1(on)
215 IGB_PARAM(LRO, "Large Receive Offload (0,1), default 0=off");
218 struct igb_opt_list {
223 enum { enable_option, range_option, list_option } type;
228 struct { /* range_option info */
232 struct { /* list_option info */
234 struct igb_opt_list *p;
239 static int __devinit igb_validate_option(unsigned int *value,
240 struct igb_option *opt,
241 struct igb_adapter *adapter)
243 if (*value == OPTION_UNSET) {
252 DPRINTK(PROBE, INFO, "%s Enabled\n", opt->name);
254 case OPTION_DISABLED:
255 DPRINTK(PROBE, INFO, "%s Disabled\n", opt->name);
260 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
262 "%s set to %d\n", opt->name, *value);
268 struct igb_opt_list *ent;
270 for (i = 0; i < opt->arg.l.nr; i++) {
271 ent = &opt->arg.l.p[i];
272 if (*value == ent->i) {
273 if (ent->str[0] != '\0')
274 DPRINTK(PROBE, INFO, "%s\n", ent->str);
284 DPRINTK(PROBE, INFO, "Invalid %s value specified (%d) %s\n",
285 opt->name, *value, opt->err);
291 * igb_check_options - Range Checking for Command Line Parameters
292 * @adapter: board private structure
294 * This routine checks all command line parameters for valid user
295 * input. If an invalid value is given, or if no user specified
296 * value exists, a default value is used. The final value is stored
297 * in a variable in the adapter structure.
300 void __devinit igb_check_options(struct igb_adapter *adapter)
302 int bd = adapter->bd_number;
303 struct e1000_hw *hw = &adapter->hw;
305 if (bd >= IGB_MAX_NIC) {
306 DPRINTK(PROBE, NOTICE,
307 "Warning: no configuration for board #%d\n", bd);
308 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
309 #ifndef module_param_array
314 { /* Interrupt Throttling Rate */
315 struct igb_option opt = {
316 .type = range_option,
317 .name = "Interrupt Throttling Rate (ints/sec)",
318 .err = "using default of " __MODULE_STRING(DEFAULT_ITR),
320 .arg = { .r = { .min = MIN_ITR,
324 #ifdef module_param_array
325 if (num_InterruptThrottleRate > bd) {
327 unsigned int itr = InterruptThrottleRate[bd];
331 DPRINTK(PROBE, INFO, "%s turned off\n",
333 if(hw->mac.type >= e1000_i350)
334 adapter->dmac = IGB_DMAC_DISABLE;
335 adapter->rx_itr_setting = itr;
338 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
340 adapter->rx_itr_setting = itr;
344 "%s set to dynamic conservative mode\n",
346 adapter->rx_itr_setting = itr;
349 igb_validate_option(&itr, &opt, adapter);
350 /* Save the setting, because the dynamic bits
351 * change itr. In case of invalid user value,
352 * default to conservative mode, else need to
353 * clear the lower two bits because they are
356 adapter->rx_itr_setting = itr;
358 adapter->rx_itr_setting = 1000000000 /
360 adapter->rx_itr_setting &= ~3;
364 #ifdef module_param_array
366 adapter->rx_itr_setting = opt.def;
369 adapter->tx_itr_setting = adapter->rx_itr_setting;
371 { /* Interrupt Mode */
372 struct igb_option opt = {
373 .type = range_option,
374 .name = "Interrupt Mode",
375 .err = "defaulting to 2 (MSI-X)",
376 .def = IGB_INT_MODE_MSIX,
377 .arg = { .r = { .min = MIN_INTMODE,
378 .max = MAX_INTMODE } }
381 #ifdef module_param_array
382 if (num_IntMode > bd) {
384 unsigned int int_mode = IntMode[bd];
385 igb_validate_option(&int_mode, &opt, adapter);
386 adapter->int_mode = int_mode;
387 #ifdef module_param_array
389 adapter->int_mode = opt.def;
393 { /* Low Latency Interrupt TCP Port */
394 struct igb_option opt = {
395 .type = range_option,
396 .name = "Low Latency Interrupt TCP Port",
397 .err = "using default of " __MODULE_STRING(DEFAULT_LLIPORT),
398 .def = DEFAULT_LLIPORT,
399 .arg = { .r = { .min = MIN_LLIPORT,
400 .max = MAX_LLIPORT } }
403 #ifdef module_param_array
404 if (num_LLIPort > bd) {
406 adapter->lli_port = LLIPort[bd];
407 if (adapter->lli_port) {
408 igb_validate_option(&adapter->lli_port, &opt,
411 DPRINTK(PROBE, INFO, "%s turned off\n",
414 #ifdef module_param_array
416 adapter->lli_port = opt.def;
420 { /* Low Latency Interrupt on Packet Size */
421 struct igb_option opt = {
422 .type = range_option,
423 .name = "Low Latency Interrupt on Packet Size",
424 .err = "using default of " __MODULE_STRING(DEFAULT_LLISIZE),
425 .def = DEFAULT_LLISIZE,
426 .arg = { .r = { .min = MIN_LLISIZE,
427 .max = MAX_LLISIZE } }
430 #ifdef module_param_array
431 if (num_LLISize > bd) {
433 adapter->lli_size = LLISize[bd];
434 if (adapter->lli_size) {
435 igb_validate_option(&adapter->lli_size, &opt,
438 DPRINTK(PROBE, INFO, "%s turned off\n",
441 #ifdef module_param_array
443 adapter->lli_size = opt.def;
447 { /* Low Latency Interrupt on TCP Push flag */
448 struct igb_option opt = {
449 .type = enable_option,
450 .name = "Low Latency Interrupt on TCP Push flag",
451 .err = "defaulting to Disabled",
452 .def = OPTION_DISABLED
455 #ifdef module_param_array
456 if (num_LLIPush > bd) {
458 unsigned int lli_push = LLIPush[bd];
459 igb_validate_option(&lli_push, &opt, adapter);
460 adapter->flags |= lli_push ? IGB_FLAG_LLI_PUSH : 0;
461 #ifdef module_param_array
463 adapter->flags |= opt.def ? IGB_FLAG_LLI_PUSH : 0;
467 { /* SRIOV - Enable SR-IOV VF devices */
468 struct igb_option opt = {
469 .type = range_option,
470 .name = "max_vfs - SR-IOV VF devices",
471 .err = "using default of " __MODULE_STRING(DEFAULT_SRIOV),
472 .def = DEFAULT_SRIOV,
473 .arg = { .r = { .min = MIN_SRIOV,
477 #ifdef module_param_array
478 if (num_max_vfs > bd) {
480 adapter->vfs_allocated_count = max_vfs[bd];
481 igb_validate_option(&adapter->vfs_allocated_count, &opt, adapter);
483 #ifdef module_param_array
485 adapter->vfs_allocated_count = opt.def;
488 if (adapter->vfs_allocated_count) {
489 switch (hw->mac.type) {
492 adapter->vfs_allocated_count = 0;
493 DPRINTK(PROBE, INFO, "SR-IOV option max_vfs not supported.\n");
499 { /* VMDQ - Enable VMDq multiqueue receive */
500 struct igb_option opt = {
501 .type = range_option,
502 .name = "VMDQ - VMDq multiqueue queue count",
503 .err = "using default of " __MODULE_STRING(DEFAULT_VMDQ),
505 .arg = { .r = { .min = MIN_VMDQ,
506 .max = (MAX_VMDQ - adapter->vfs_allocated_count) } }
508 #ifdef module_param_array
511 adapter->vmdq_pools = (VMDQ[bd] == 1 ? 0 : VMDQ[bd]);
512 if (adapter->vfs_allocated_count && !adapter->vmdq_pools) {
513 DPRINTK(PROBE, INFO, "Enabling SR-IOV requires VMDq be set to at least 1\n");
514 adapter->vmdq_pools = 1;
516 igb_validate_option(&adapter->vmdq_pools, &opt, adapter);
518 #ifdef module_param_array
520 if (!adapter->vfs_allocated_count)
521 adapter->vmdq_pools = (opt.def == 1 ? 0 : opt.def);
523 adapter->vmdq_pools = 1;
526 #ifdef CONFIG_IGB_VMDQ_NETDEV
527 if (hw->mac.type == e1000_82575 && adapter->vmdq_pools) {
528 DPRINTK(PROBE, INFO, "VMDq not supported on this part.\n");
529 adapter->vmdq_pools = 0;
533 { /* RSS - Enable RSS multiqueue receives */
534 struct igb_option opt = {
535 .type = range_option,
536 .name = "RSS - RSS multiqueue receive count",
537 .err = "using default of " __MODULE_STRING(DEFAULT_RSS),
539 .arg = { .r = { .min = MIN_RSS,
543 if (adapter->vmdq_pools) {
544 switch (hw->mac.type) {
545 #ifndef CONFIG_IGB_VMDQ_NETDEV
550 if (adapter->vmdq_pools == 2)
552 if (adapter->vmdq_pools <= 2)
561 switch (hw->mac.type) {
569 #ifdef module_param_array
572 adapter->rss_queues = RSS[bd];
573 switch (adapter->rss_queues) {
577 igb_validate_option(&adapter->rss_queues, &opt, adapter);
578 if (adapter->rss_queues)
581 adapter->rss_queues = min_t(u32, opt.arg.r.max, num_online_cpus());
584 #ifdef module_param_array
586 adapter->rss_queues = opt.def;
590 { /* QueuePairs - Enable TX/RX queue pairs for interrupt handling */
591 struct igb_option opt = {
592 .type = enable_option,
593 .name = "QueuePairs - TX/RX queue pairs for interrupt handling",
594 .err = "defaulting to Enabled",
595 .def = OPTION_ENABLED
597 #ifdef module_param_array
598 if (num_QueuePairs > bd) {
600 unsigned int qp = QueuePairs[bd];
602 * we must enable queue pairs if the number of queues
603 * exceeds the number of avaialble interrupts. We are
604 * limited to 10, or 3 per unallocated vf.
606 if ((adapter->rss_queues > 4) ||
607 (adapter->vmdq_pools > 4) ||
608 ((adapter->rss_queues > 1) &&
609 ((adapter->vmdq_pools > 3) ||
610 (adapter->vfs_allocated_count > 6)))) {
611 if (qp == OPTION_DISABLED) {
614 "Number of queues exceeds available interrupts, %s\n",opt.err);
617 igb_validate_option(&qp, &opt, adapter);
618 adapter->flags |= qp ? IGB_FLAG_QUEUE_PAIRS : 0;
619 #ifdef module_param_array
621 adapter->flags |= opt.def ? IGB_FLAG_QUEUE_PAIRS : 0;
625 { /* EEE - Enable EEE for capable adapters */
627 if (hw->mac.type >= e1000_i350) {
628 struct igb_option opt = {
629 .type = enable_option,
630 .name = "EEE Support",
631 .err = "defaulting to Enabled",
632 .def = OPTION_ENABLED
634 #ifdef module_param_array
637 unsigned int eee = EEE[bd];
638 igb_validate_option(&eee, &opt, adapter);
639 adapter->flags |= eee ? IGB_FLAG_EEE : 0;
641 hw->dev_spec._82575.eee_disable = false;
643 hw->dev_spec._82575.eee_disable = true;
645 #ifdef module_param_array
647 adapter->flags |= opt.def ? IGB_FLAG_EEE : 0;
648 if (adapter->flags & IGB_FLAG_EEE)
649 hw->dev_spec._82575.eee_disable = false;
651 hw->dev_spec._82575.eee_disable = true;
656 { /* DMAC - Enable DMA Coalescing for capable adapters */
658 if (hw->mac.type >= e1000_i350) {
659 struct igb_opt_list list [] = {
660 { IGB_DMAC_DISABLE, "DMAC Disable"},
661 { IGB_DMAC_MIN, "DMAC 250 usec"},
662 { IGB_DMAC_500, "DMAC 500 usec"},
663 { IGB_DMAC_EN_DEFAULT, "DMAC 1000 usec"},
664 { IGB_DMAC_2000, "DMAC 2000 usec"},
665 { IGB_DMAC_3000, "DMAC 3000 usec"},
666 { IGB_DMAC_4000, "DMAC 4000 usec"},
667 { IGB_DMAC_5000, "DMAC 5000 usec"},
668 { IGB_DMAC_6000, "DMAC 6000 usec"},
669 { IGB_DMAC_7000, "DMAC 7000 usec"},
670 { IGB_DMAC_8000, "DMAC 8000 usec"},
671 { IGB_DMAC_9000, "DMAC 9000 usec"},
672 { IGB_DMAC_MAX, "DMAC 10000 usec"}
674 struct igb_option opt = {
676 .name = "DMA Coalescing",
677 .err = "using default of "__MODULE_STRING(IGB_DMAC_DISABLE),
678 .def = IGB_DMAC_DISABLE,
679 .arg = { .l = { .nr = 13,
684 #ifdef module_param_array
687 unsigned int dmac = DMAC[bd];
688 if (adapter->rx_itr_setting == IGB_DMAC_DISABLE)
689 dmac = IGB_DMAC_DISABLE;
690 igb_validate_option(&dmac, &opt, adapter);
692 case IGB_DMAC_DISABLE:
693 adapter->dmac = dmac;
696 adapter->dmac = dmac;
699 adapter->dmac = dmac;
701 case IGB_DMAC_EN_DEFAULT:
702 adapter->dmac = dmac;
705 adapter->dmac = dmac;
708 adapter->dmac = dmac;
711 adapter->dmac = dmac;
714 adapter->dmac = dmac;
717 adapter->dmac = dmac;
720 adapter->dmac = dmac;
723 adapter->dmac = dmac;
726 adapter->dmac = dmac;
729 adapter->dmac = dmac;
732 adapter->dmac = opt.def;
734 "Invalid DMAC setting, "
735 "resetting DMAC to %d\n", opt.def);
737 #ifdef module_param_array
739 adapter->dmac = opt.def;
744 { /* LRO - Enable Large Receive Offload */
745 struct igb_option opt = {
746 .type = enable_option,
747 .name = "LRO - Large Receive Offload",
748 .err = "defaulting to Disabled",
749 .def = OPTION_DISABLED
751 struct net_device *netdev = adapter->netdev;
752 #ifdef module_param_array
755 unsigned int lro = LRO[bd];
756 igb_validate_option(&lro, &opt, adapter);
757 netdev->features |= lro ? NETIF_F_LRO : 0;
758 #ifdef module_param_array
759 } else if (opt.def == OPTION_ENABLED) {
760 netdev->features |= NETIF_F_LRO;
764 #endif /* IGB_NO_LRO */
765 { /* Node assignment */
766 static struct igb_option opt = {
767 .type = range_option,
768 .name = "Node to start on",
769 .err = "defaulting to -1",
770 #ifdef HAVE_EARLY_VMALLOC_NODE
775 .arg = { .r = { .min = 0,
776 .max = (MAX_NUMNODES - 1)}}
778 int node_param = opt.def;
780 /* if the default was zero then we need to set the
781 * default value to an online node, which is not
782 * necessarily zero, and the constant initializer
783 * above can't take first_online_node */
785 /* must set opt.def for validate */
786 opt.def = node_param = first_online_node;
788 #ifdef module_param_array
791 node_param = Node[bd];
792 igb_validate_option((uint *)&node_param, &opt, adapter);
794 if (node_param != OPTION_UNSET) {
795 DPRINTK(PROBE, INFO, "node set to %d\n", node_param);
797 #ifdef module_param_array
801 /* check sanity of the value */
802 if (node_param != -1 && !node_online(node_param)) {
804 "ignoring node set to invalid value %d\n",
806 node_param = opt.def;
809 adapter->node = node_param;
811 { /* MDD - Enable Malicious Driver Detection. Only available when
812 SR-IOV is enabled. */
813 struct igb_option opt = {
814 .type = enable_option,
815 .name = "Malicious Driver Detection",
816 .err = "defaulting to 1",
817 .def = OPTION_ENABLED,
818 .arg = { .r = { .min = OPTION_DISABLED,
819 .max = OPTION_ENABLED } }
822 #ifdef module_param_array
825 adapter->mdd = MDD[bd];
826 igb_validate_option((uint *)&adapter->mdd, &opt,
828 #ifdef module_param_array
830 adapter->mdd = opt.def;