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