fp@2587: /******************************************************************************* fp@2587: fp@2587: Intel PRO/1000 Linux driver fp@2587: Copyright(c) 1999 - 2013 Intel Corporation. fp@2587: fp@2587: This program is free software; you can redistribute it and/or modify it fp@2587: under the terms and conditions of the GNU General Public License, fp@2587: version 2, as published by the Free Software Foundation. fp@2587: fp@2587: This program is distributed in the hope it will be useful, but WITHOUT fp@2587: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or fp@2587: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for fp@2587: more details. fp@2587: fp@2587: You should have received a copy of the GNU General Public License along with fp@2587: this program; if not, write to the Free Software Foundation, Inc., fp@2587: 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. fp@2587: fp@2587: The full GNU General Public License is included in this distribution in fp@2587: the file called "COPYING". fp@2587: fp@2587: Contact Information: fp@2587: Linux NICS fp@2587: e1000-devel Mailing List fp@2587: Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 fp@2587: fp@2587: *******************************************************************************/ fp@2587: fp@2587: #include fp@2587: #include fp@2587: #include fp@2587: fp@2587: #include "e1000-3.14-ethercat.h" fp@2587: fp@2587: /* This is the only thing that needs to be changed to adjust the fp@2587: * maximum number of ports that the driver can manage. fp@2587: */ fp@2587: #define E1000_MAX_NIC 32 fp@2587: fp@2587: #define OPTION_UNSET -1 fp@2587: #define OPTION_DISABLED 0 fp@2587: #define OPTION_ENABLED 1 fp@2587: fp@2587: #define COPYBREAK_DEFAULT 256 fp@2587: unsigned int copybreak = COPYBREAK_DEFAULT; fp@2587: module_param(copybreak, uint, 0644); fp@2587: MODULE_PARM_DESC(copybreak, fp@2587: "Maximum size of packet that is copied to a new buffer on receive"); fp@2587: fp@2587: /* All parameters are treated the same, as an integer array of values. fp@2587: * This macro just reduces the need to repeat the same declaration code fp@2587: * over and over (plus this helps to avoid typo bugs). fp@2587: */ fp@2587: #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET } fp@2587: #define E1000_PARAM(X, desc) \ fp@2587: static int X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \ fp@2587: static unsigned int num_##X; \ fp@2587: module_param_array_named(X, X, int, &num_##X, 0); \ fp@2587: MODULE_PARM_DESC(X, desc); fp@2587: fp@2587: /* Transmit Interrupt Delay in units of 1.024 microseconds fp@2587: * Tx interrupt delay needs to typically be set to something non-zero fp@2587: * fp@2587: * Valid Range: 0-65535 fp@2587: */ fp@2587: E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay"); fp@2587: #define DEFAULT_TIDV 8 fp@2587: #define MAX_TXDELAY 0xFFFF fp@2587: #define MIN_TXDELAY 0 fp@2587: fp@2587: /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds fp@2587: * fp@2587: * Valid Range: 0-65535 fp@2587: */ fp@2587: E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay"); fp@2587: #define DEFAULT_TADV 32 fp@2587: #define MAX_TXABSDELAY 0xFFFF fp@2587: #define MIN_TXABSDELAY 0 fp@2587: fp@2587: /* Receive Interrupt Delay in units of 1.024 microseconds fp@2587: * hardware will likely hang if you set this to anything but zero. fp@2587: * fp@2587: * Valid Range: 0-65535 fp@2587: */ fp@2587: E1000_PARAM(RxIntDelay, "Receive Interrupt Delay"); fp@2587: #define MAX_RXDELAY 0xFFFF fp@2587: #define MIN_RXDELAY 0 fp@2587: fp@2587: /* Receive Absolute Interrupt Delay in units of 1.024 microseconds fp@2587: * fp@2587: * Valid Range: 0-65535 fp@2587: */ fp@2587: E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay"); fp@2587: #define MAX_RXABSDELAY 0xFFFF fp@2587: #define MIN_RXABSDELAY 0 fp@2587: fp@2587: /* Interrupt Throttle Rate (interrupts/sec) fp@2587: * fp@2587: * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative fp@2587: */ fp@2587: E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate"); fp@2587: #define DEFAULT_ITR 3 fp@2587: #define MAX_ITR 100000 fp@2587: #define MIN_ITR 100 fp@2587: fp@2587: /* IntMode (Interrupt Mode) fp@2587: * fp@2587: * Valid Range: varies depending on kernel configuration & hardware support fp@2587: * fp@2587: * legacy=0, MSI=1, MSI-X=2 fp@2587: * fp@2587: * When MSI/MSI-X support is enabled in kernel- fp@2587: * Default Value: 2 (MSI-X) when supported by hardware, 1 (MSI) otherwise fp@2587: * When MSI/MSI-X support is not enabled in kernel- fp@2587: * Default Value: 0 (legacy) fp@2587: * fp@2587: * When a mode is specified that is not allowed/supported, it will be fp@2587: * demoted to the most advanced interrupt mode available. fp@2587: */ fp@2587: E1000_PARAM(IntMode, "Interrupt Mode"); fp@2587: #define MAX_INTMODE 2 fp@2587: #define MIN_INTMODE 0 fp@2587: fp@2587: /* Enable Smart Power Down of the PHY fp@2587: * fp@2587: * Valid Range: 0, 1 fp@2587: * fp@2587: * Default Value: 0 (disabled) fp@2587: */ fp@2587: E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down"); fp@2587: fp@2587: /* Enable Kumeran Lock Loss workaround fp@2587: * fp@2587: * Valid Range: 0, 1 fp@2587: * fp@2587: * Default Value: 1 (enabled) fp@2587: */ fp@2587: E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround"); fp@2587: fp@2587: /* Write Protect NVM fp@2587: * fp@2587: * Valid Range: 0, 1 fp@2587: * fp@2587: * Default Value: 1 (enabled) fp@2587: */ fp@2587: E1000_PARAM(WriteProtectNVM, fp@2587: "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]"); fp@2587: fp@2587: /* Enable CRC Stripping fp@2587: * fp@2587: * Valid Range: 0, 1 fp@2587: * fp@2587: * Default Value: 1 (enabled) fp@2587: */ fp@2587: E1000_PARAM(CrcStripping, fp@2587: "Enable CRC Stripping, disable if your BMC needs the CRC"); fp@2587: fp@2587: struct e1000_option { fp@2587: enum { enable_option, range_option, list_option } type; fp@2587: const char *name; fp@2587: const char *err; fp@2587: int def; fp@2587: union { fp@2587: /* range_option info */ fp@2587: struct { fp@2587: int min; fp@2587: int max; fp@2587: } r; fp@2587: /* list_option info */ fp@2587: struct { fp@2587: int nr; fp@2587: struct e1000_opt_list { fp@2587: int i; fp@2587: char *str; fp@2587: } *p; fp@2587: } l; fp@2587: } arg; fp@2587: }; fp@2587: fp@2587: static int e1000_validate_option(unsigned int *value, fp@2587: const struct e1000_option *opt, fp@2587: struct e1000_adapter *adapter) fp@2587: { fp@2587: if (*value == OPTION_UNSET) { fp@2587: *value = opt->def; fp@2587: return 0; fp@2587: } fp@2587: fp@2587: switch (opt->type) { fp@2587: case enable_option: fp@2587: switch (*value) { fp@2587: case OPTION_ENABLED: fp@2587: dev_info(&adapter->pdev->dev, "%s Enabled\n", fp@2587: opt->name); fp@2587: return 0; fp@2587: case OPTION_DISABLED: fp@2587: dev_info(&adapter->pdev->dev, "%s Disabled\n", fp@2587: opt->name); fp@2587: return 0; fp@2587: } fp@2587: break; fp@2587: case range_option: fp@2587: if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { fp@2587: dev_info(&adapter->pdev->dev, "%s set to %i\n", fp@2587: opt->name, *value); fp@2587: return 0; fp@2587: } fp@2587: break; fp@2587: case list_option: { fp@2587: int i; fp@2587: struct e1000_opt_list *ent; fp@2587: fp@2587: for (i = 0; i < opt->arg.l.nr; i++) { fp@2587: ent = &opt->arg.l.p[i]; fp@2587: if (*value == ent->i) { fp@2587: if (ent->str[0] != '\0') fp@2587: dev_info(&adapter->pdev->dev, "%s\n", fp@2587: ent->str); fp@2587: return 0; fp@2587: } fp@2587: } fp@2587: } fp@2587: break; fp@2587: default: fp@2587: BUG(); fp@2587: } fp@2587: fp@2587: dev_info(&adapter->pdev->dev, "Invalid %s value specified (%i) %s\n", fp@2587: opt->name, *value, opt->err); fp@2587: *value = opt->def; fp@2587: return -1; fp@2587: } fp@2587: fp@2587: /** fp@2587: * e1000e_check_options - Range Checking for Command Line Parameters fp@2587: * @adapter: board private structure fp@2587: * fp@2587: * This routine checks all command line parameters for valid user fp@2587: * input. If an invalid value is given, or if no user specified fp@2587: * value exists, a default value is used. The final value is stored fp@2587: * in a variable in the adapter structure. fp@2587: **/ fp@2587: void e1000e_check_options(struct e1000_adapter *adapter) fp@2587: { fp@2587: struct e1000_hw *hw = &adapter->hw; fp@2587: int bd = adapter->bd_number; fp@2587: fp@2587: if (bd >= E1000_MAX_NIC) { fp@2587: dev_notice(&adapter->pdev->dev, fp@2587: "Warning: no configuration for board #%i\n", bd); fp@2587: dev_notice(&adapter->pdev->dev, fp@2587: "Using defaults for all values\n"); fp@2587: } fp@2587: fp@2587: /* Transmit Interrupt Delay */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = range_option, fp@2587: .name = "Transmit Interrupt Delay", fp@2587: .err = "using default of " fp@2587: __MODULE_STRING(DEFAULT_TIDV), fp@2587: .def = DEFAULT_TIDV, fp@2587: .arg = { .r = { .min = MIN_TXDELAY, fp@2587: .max = MAX_TXDELAY } } fp@2587: }; fp@2587: fp@2587: if (num_TxIntDelay > bd) { fp@2587: adapter->tx_int_delay = TxIntDelay[bd]; fp@2587: e1000_validate_option(&adapter->tx_int_delay, &opt, fp@2587: adapter); fp@2587: } else { fp@2587: adapter->tx_int_delay = opt.def; fp@2587: } fp@2587: } fp@2587: /* Transmit Absolute Interrupt Delay */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = range_option, fp@2587: .name = "Transmit Absolute Interrupt Delay", fp@2587: .err = "using default of " fp@2587: __MODULE_STRING(DEFAULT_TADV), fp@2587: .def = DEFAULT_TADV, fp@2587: .arg = { .r = { .min = MIN_TXABSDELAY, fp@2587: .max = MAX_TXABSDELAY } } fp@2587: }; fp@2587: fp@2587: if (num_TxAbsIntDelay > bd) { fp@2587: adapter->tx_abs_int_delay = TxAbsIntDelay[bd]; fp@2587: e1000_validate_option(&adapter->tx_abs_int_delay, &opt, fp@2587: adapter); fp@2587: } else { fp@2587: adapter->tx_abs_int_delay = opt.def; fp@2587: } fp@2587: } fp@2587: /* Receive Interrupt Delay */ fp@2587: { fp@2587: static struct e1000_option opt = { fp@2587: .type = range_option, fp@2587: .name = "Receive Interrupt Delay", fp@2587: .err = "using default of " fp@2587: __MODULE_STRING(DEFAULT_RDTR), fp@2587: .def = DEFAULT_RDTR, fp@2587: .arg = { .r = { .min = MIN_RXDELAY, fp@2587: .max = MAX_RXDELAY } } fp@2587: }; fp@2587: fp@2587: if (num_RxIntDelay > bd) { fp@2587: adapter->rx_int_delay = RxIntDelay[bd]; fp@2587: e1000_validate_option(&adapter->rx_int_delay, &opt, fp@2587: adapter); fp@2587: } else { fp@2587: adapter->rx_int_delay = opt.def; fp@2587: } fp@2587: } fp@2587: /* Receive Absolute Interrupt Delay */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = range_option, fp@2587: .name = "Receive Absolute Interrupt Delay", fp@2587: .err = "using default of " fp@2587: __MODULE_STRING(DEFAULT_RADV), fp@2587: .def = DEFAULT_RADV, fp@2587: .arg = { .r = { .min = MIN_RXABSDELAY, fp@2587: .max = MAX_RXABSDELAY } } fp@2587: }; fp@2587: fp@2587: if (num_RxAbsIntDelay > bd) { fp@2587: adapter->rx_abs_int_delay = RxAbsIntDelay[bd]; fp@2587: e1000_validate_option(&adapter->rx_abs_int_delay, &opt, fp@2587: adapter); fp@2587: } else { fp@2587: adapter->rx_abs_int_delay = opt.def; fp@2587: } fp@2587: } fp@2587: /* Interrupt Throttling Rate */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = range_option, fp@2587: .name = "Interrupt Throttling Rate (ints/sec)", fp@2587: .err = "using default of " fp@2587: __MODULE_STRING(DEFAULT_ITR), fp@2587: .def = DEFAULT_ITR, fp@2587: .arg = { .r = { .min = MIN_ITR, fp@2587: .max = MAX_ITR } } fp@2587: }; fp@2587: fp@2587: if (num_InterruptThrottleRate > bd) { fp@2587: adapter->itr = InterruptThrottleRate[bd]; fp@2587: fp@2587: /* Make sure a message is printed for non-special fp@2587: * values. And in case of an invalid option, display fp@2587: * warning, use default and go through itr/itr_setting fp@2587: * adjustment logic below fp@2587: */ fp@2587: if ((adapter->itr > 4) && fp@2587: e1000_validate_option(&adapter->itr, &opt, adapter)) fp@2587: adapter->itr = opt.def; fp@2587: } else { fp@2587: /* If no option specified, use default value and go fp@2587: * through the logic below to adjust itr/itr_setting fp@2587: */ fp@2587: adapter->itr = opt.def; fp@2587: fp@2587: /* Make sure a message is printed for non-special fp@2587: * default values fp@2587: */ fp@2587: if (adapter->itr > 4) fp@2587: dev_info(&adapter->pdev->dev, fp@2587: "%s set to default %d\n", opt.name, fp@2587: adapter->itr); fp@2587: } fp@2587: fp@2587: adapter->itr_setting = adapter->itr; fp@2587: switch (adapter->itr) { fp@2587: case 0: fp@2587: dev_info(&adapter->pdev->dev, "%s turned off\n", fp@2587: opt.name); fp@2587: break; fp@2587: case 1: fp@2587: dev_info(&adapter->pdev->dev, fp@2587: "%s set to dynamic mode\n", opt.name); fp@2587: adapter->itr = 20000; fp@2587: break; fp@2587: case 3: fp@2587: dev_info(&adapter->pdev->dev, fp@2587: "%s set to dynamic conservative mode\n", fp@2587: opt.name); fp@2587: adapter->itr = 20000; fp@2587: break; fp@2587: case 4: fp@2587: dev_info(&adapter->pdev->dev, fp@2587: "%s set to simplified (2000-8000 ints) mode\n", fp@2587: opt.name); fp@2587: break; fp@2587: default: fp@2587: /* Save the setting, because the dynamic bits fp@2587: * change itr. fp@2587: * fp@2587: * Clear the lower two bits because fp@2587: * they are used as control. fp@2587: */ fp@2587: adapter->itr_setting &= ~3; fp@2587: break; fp@2587: } fp@2587: } fp@2587: /* Interrupt Mode */ fp@2587: { fp@2587: static struct e1000_option opt = { fp@2587: .type = range_option, fp@2587: .name = "Interrupt Mode", fp@2587: #ifndef CONFIG_PCI_MSI fp@2587: .err = "defaulting to 0 (legacy)", fp@2587: .def = E1000E_INT_MODE_LEGACY, fp@2587: .arg = { .r = { .min = 0, fp@2587: .max = 0 } } fp@2587: #endif fp@2587: }; fp@2587: fp@2587: #ifdef CONFIG_PCI_MSI fp@2587: if (adapter->flags & FLAG_HAS_MSIX) { fp@2587: opt.err = kstrdup("defaulting to 2 (MSI-X)", fp@2587: GFP_KERNEL); fp@2587: opt.def = E1000E_INT_MODE_MSIX; fp@2587: opt.arg.r.max = E1000E_INT_MODE_MSIX; fp@2587: } else { fp@2587: opt.err = kstrdup("defaulting to 1 (MSI)", GFP_KERNEL); fp@2587: opt.def = E1000E_INT_MODE_MSI; fp@2587: opt.arg.r.max = E1000E_INT_MODE_MSI; fp@2587: } fp@2587: fp@2587: if (!opt.err) { fp@2587: dev_err(&adapter->pdev->dev, fp@2587: "Failed to allocate memory\n"); fp@2587: return; fp@2587: } fp@2587: #endif fp@2587: fp@2587: if (num_IntMode > bd) { fp@2587: unsigned int int_mode = IntMode[bd]; fp@2587: e1000_validate_option(&int_mode, &opt, adapter); fp@2587: adapter->int_mode = int_mode; fp@2587: } else { fp@2587: adapter->int_mode = opt.def; fp@2587: } fp@2587: fp@2587: #ifdef CONFIG_PCI_MSI fp@2587: kfree(opt.err); fp@2587: #endif fp@2587: } fp@2587: /* Smart Power Down */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = enable_option, fp@2587: .name = "PHY Smart Power Down", fp@2587: .err = "defaulting to Disabled", fp@2587: .def = OPTION_DISABLED fp@2587: }; fp@2587: fp@2587: if (num_SmartPowerDownEnable > bd) { fp@2587: unsigned int spd = SmartPowerDownEnable[bd]; fp@2587: e1000_validate_option(&spd, &opt, adapter); fp@2587: if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && spd) fp@2587: adapter->flags |= FLAG_SMART_POWER_DOWN; fp@2587: } fp@2587: } fp@2587: /* CRC Stripping */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = enable_option, fp@2587: .name = "CRC Stripping", fp@2587: .err = "defaulting to Enabled", fp@2587: .def = OPTION_ENABLED fp@2587: }; fp@2587: fp@2587: if (num_CrcStripping > bd) { fp@2587: unsigned int crc_stripping = CrcStripping[bd]; fp@2587: e1000_validate_option(&crc_stripping, &opt, adapter); fp@2587: if (crc_stripping == OPTION_ENABLED) { fp@2587: adapter->flags2 |= FLAG2_CRC_STRIPPING; fp@2587: adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING; fp@2587: } fp@2587: } else { fp@2587: adapter->flags2 |= FLAG2_CRC_STRIPPING; fp@2587: adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING; fp@2587: } fp@2587: } fp@2587: /* Kumeran Lock Loss Workaround */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = enable_option, fp@2587: .name = "Kumeran Lock Loss Workaround", fp@2587: .err = "defaulting to Enabled", fp@2587: .def = OPTION_ENABLED fp@2587: }; fp@2587: bool enabled = opt.def; fp@2587: fp@2587: if (num_KumeranLockLoss > bd) { fp@2587: unsigned int kmrn_lock_loss = KumeranLockLoss[bd]; fp@2587: e1000_validate_option(&kmrn_lock_loss, &opt, adapter); fp@2587: enabled = kmrn_lock_loss; fp@2587: } fp@2587: fp@2587: if (hw->mac.type == e1000_ich8lan) fp@2587: e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, fp@2587: enabled); fp@2587: } fp@2587: /* Write-protect NVM */ fp@2587: { fp@2587: static const struct e1000_option opt = { fp@2587: .type = enable_option, fp@2587: .name = "Write-protect NVM", fp@2587: .err = "defaulting to Enabled", fp@2587: .def = OPTION_ENABLED fp@2587: }; fp@2587: fp@2587: if (adapter->flags & FLAG_IS_ICH) { fp@2587: if (num_WriteProtectNVM > bd) { fp@2587: unsigned int write_protect_nvm = fp@2587: WriteProtectNVM[bd]; fp@2587: e1000_validate_option(&write_protect_nvm, &opt, fp@2587: adapter); fp@2587: if (write_protect_nvm) fp@2587: adapter->flags |= FLAG_READ_ONLY_NVM; fp@2587: } else { fp@2587: if (opt.def) fp@2587: adapter->flags |= FLAG_READ_ONLY_NVM; fp@2587: } fp@2587: } fp@2587: } fp@2587: }