devices/e1000e/param-2.6.37-orig.c
branchstable-1.5
changeset 2219 d52848f0be04
equal deleted inserted replaced
2218:2eb46694f484 2219:d52848f0be04
       
     1 /*******************************************************************************
       
     2 
       
     3   Intel PRO/1000 Linux driver
       
     4   Copyright(c) 1999 - 2010 Intel Corporation.
       
     5 
       
     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.
       
     9 
       
    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
       
    13   more details.
       
    14 
       
    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.
       
    18 
       
    19   The full GNU General Public License is included in this distribution in
       
    20   the file called "COPYING".
       
    21 
       
    22   Contact Information:
       
    23   Linux NICS <linux.nics@intel.com>
       
    24   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
       
    25   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
       
    26 
       
    27 *******************************************************************************/
       
    28 
       
    29 #include <linux/netdevice.h>
       
    30 #include <linux/pci.h>
       
    31 
       
    32 #include "e1000.h"
       
    33 
       
    34 int entropy = 0;
       
    35 module_param(entropy, int, 0);
       
    36 MODULE_PARM_DESC(entropy, "Allow e1000e to populate the /dev/random entropy pool");
       
    37 
       
    38 /*
       
    39  * This is the only thing that needs to be changed to adjust the
       
    40  * maximum number of ports that the driver can manage.
       
    41  */
       
    42 
       
    43 #define E1000_MAX_NIC 32
       
    44 
       
    45 #define OPTION_UNSET   -1
       
    46 #define OPTION_DISABLED 0
       
    47 #define OPTION_ENABLED  1
       
    48 
       
    49 #define COPYBREAK_DEFAULT 256
       
    50 unsigned int copybreak = COPYBREAK_DEFAULT;
       
    51 module_param(copybreak, uint, 0644);
       
    52 MODULE_PARM_DESC(copybreak,
       
    53 	"Maximum size of packet that is copied to a new buffer on receive");
       
    54 
       
    55 /*
       
    56  * All parameters are treated the same, as an integer array of values.
       
    57  * This macro just reduces the need to repeat the same declaration code
       
    58  * over and over (plus this helps to avoid typo bugs).
       
    59  */
       
    60 
       
    61 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
       
    62 #define E1000_PARAM(X, desc)					\
       
    63 	static int __devinitdata X[E1000_MAX_NIC+1]		\
       
    64 		= E1000_PARAM_INIT;				\
       
    65 	static unsigned int num_##X;				\
       
    66 	module_param_array_named(X, X, int, &num_##X, 0);	\
       
    67 	MODULE_PARM_DESC(X, desc);
       
    68 
       
    69 
       
    70 /*
       
    71  * Transmit Interrupt Delay in units of 1.024 microseconds
       
    72  * Tx interrupt delay needs to typically be set to something non zero
       
    73  *
       
    74  * Valid Range: 0-65535
       
    75  */
       
    76 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
       
    77 #define DEFAULT_TIDV 8
       
    78 #define MAX_TXDELAY 0xFFFF
       
    79 #define MIN_TXDELAY 0
       
    80 
       
    81 /*
       
    82  * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
       
    83  *
       
    84  * Valid Range: 0-65535
       
    85  */
       
    86 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
       
    87 #define DEFAULT_TADV 32
       
    88 #define MAX_TXABSDELAY 0xFFFF
       
    89 #define MIN_TXABSDELAY 0
       
    90 
       
    91 /*
       
    92  * Receive Interrupt Delay in units of 1.024 microseconds
       
    93  * hardware will likely hang if you set this to anything but zero.
       
    94  *
       
    95  * Valid Range: 0-65535
       
    96  */
       
    97 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
       
    98 #define MAX_RXDELAY 0xFFFF
       
    99 #define MIN_RXDELAY 0
       
   100 
       
   101 /*
       
   102  * Receive Absolute Interrupt Delay in units of 1.024 microseconds
       
   103  *
       
   104  * Valid Range: 0-65535
       
   105  */
       
   106 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
       
   107 #define MAX_RXABSDELAY 0xFFFF
       
   108 #define MIN_RXABSDELAY 0
       
   109 
       
   110 /*
       
   111  * Interrupt Throttle Rate (interrupts/sec)
       
   112  *
       
   113  * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
       
   114  */
       
   115 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
       
   116 #define DEFAULT_ITR 3
       
   117 #define MAX_ITR 100000
       
   118 #define MIN_ITR 100
       
   119 /* IntMode (Interrupt Mode)
       
   120  *
       
   121  * Valid Range: 0 - 2
       
   122  *
       
   123  * Default Value: 2 (MSI-X)
       
   124  */
       
   125 E1000_PARAM(IntMode, "Interrupt Mode");
       
   126 #define MAX_INTMODE	2
       
   127 #define MIN_INTMODE	0
       
   128 
       
   129 /*
       
   130  * Enable Smart Power Down of the PHY
       
   131  *
       
   132  * Valid Range: 0, 1
       
   133  *
       
   134  * Default Value: 0 (disabled)
       
   135  */
       
   136 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
       
   137 
       
   138 /*
       
   139  * Enable Kumeran Lock Loss workaround
       
   140  *
       
   141  * Valid Range: 0, 1
       
   142  *
       
   143  * Default Value: 1 (enabled)
       
   144  */
       
   145 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
       
   146 
       
   147 /*
       
   148  * Write Protect NVM
       
   149  *
       
   150  * Valid Range: 0, 1
       
   151  *
       
   152  * Default Value: 1 (enabled)
       
   153  */
       
   154 E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
       
   155 
       
   156 /*
       
   157  * Enable CRC Stripping
       
   158  *
       
   159  * Valid Range: 0, 1
       
   160  *
       
   161  * Default Value: 1 (enabled)
       
   162  */
       
   163 E1000_PARAM(CrcStripping, "Enable CRC Stripping, disable if your BMC needs " \
       
   164                           "the CRC");
       
   165 
       
   166 struct e1000_option {
       
   167 	enum { enable_option, range_option, list_option } type;
       
   168 	const char *name;
       
   169 	const char *err;
       
   170 	int def;
       
   171 	union {
       
   172 		struct { /* range_option info */
       
   173 			int min;
       
   174 			int max;
       
   175 		} r;
       
   176 		struct { /* list_option info */
       
   177 			int nr;
       
   178 			struct e1000_opt_list { int i; char *str; } *p;
       
   179 		} l;
       
   180 	} arg;
       
   181 };
       
   182 
       
   183 static int __devinit e1000_validate_option(unsigned int *value,
       
   184 					   const struct e1000_option *opt,
       
   185 					   struct e1000_adapter *adapter)
       
   186 {
       
   187 	if (*value == OPTION_UNSET) {
       
   188 		*value = opt->def;
       
   189 		return 0;
       
   190 	}
       
   191 
       
   192 	switch (opt->type) {
       
   193 	case enable_option:
       
   194 		switch (*value) {
       
   195 		case OPTION_ENABLED:
       
   196 			e_info("%s Enabled\n", opt->name);
       
   197 			return 0;
       
   198 		case OPTION_DISABLED:
       
   199 			e_info("%s Disabled\n", opt->name);
       
   200 			return 0;
       
   201 		}
       
   202 		break;
       
   203 	case range_option:
       
   204 		if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
       
   205 			e_info("%s set to %i\n", opt->name, *value);
       
   206 			return 0;
       
   207 		}
       
   208 		break;
       
   209 	case list_option: {
       
   210 		int i;
       
   211 		struct e1000_opt_list *ent;
       
   212 
       
   213 		for (i = 0; i < opt->arg.l.nr; i++) {
       
   214 			ent = &opt->arg.l.p[i];
       
   215 			if (*value == ent->i) {
       
   216 				if (ent->str[0] != '\0')
       
   217 					e_info("%s\n", ent->str);
       
   218 				return 0;
       
   219 			}
       
   220 		}
       
   221 	}
       
   222 		break;
       
   223 	default:
       
   224 		BUG();
       
   225 	}
       
   226 
       
   227 	e_info("Invalid %s value specified (%i) %s\n", opt->name, *value,
       
   228 	       opt->err);
       
   229 	*value = opt->def;
       
   230 	return -1;
       
   231 }
       
   232 
       
   233 /**
       
   234  * e1000e_check_options - Range Checking for Command Line Parameters
       
   235  * @adapter: board private structure
       
   236  *
       
   237  * This routine checks all command line parameters for valid user
       
   238  * input.  If an invalid value is given, or if no user specified
       
   239  * value exists, a default value is used.  The final value is stored
       
   240  * in a variable in the adapter structure.
       
   241  **/
       
   242 void __devinit e1000e_check_options(struct e1000_adapter *adapter)
       
   243 {
       
   244 	struct e1000_hw *hw = &adapter->hw;
       
   245 	int bd = adapter->bd_number;
       
   246 
       
   247 	if (bd >= E1000_MAX_NIC) {
       
   248 		e_notice("Warning: no configuration for board #%i\n", bd);
       
   249 		e_notice("Using defaults for all values\n");
       
   250 	}
       
   251 
       
   252 	{ /* Transmit Interrupt Delay */
       
   253 		static const struct e1000_option opt = {
       
   254 			.type = range_option,
       
   255 			.name = "Transmit Interrupt Delay",
       
   256 			.err  = "using default of "
       
   257 				__MODULE_STRING(DEFAULT_TIDV),
       
   258 			.def  = DEFAULT_TIDV,
       
   259 			.arg  = { .r = { .min = MIN_TXDELAY,
       
   260 					 .max = MAX_TXDELAY } }
       
   261 		};
       
   262 
       
   263 		if (num_TxIntDelay > bd) {
       
   264 			adapter->tx_int_delay = TxIntDelay[bd];
       
   265 			e1000_validate_option(&adapter->tx_int_delay, &opt,
       
   266 					      adapter);
       
   267 		} else {
       
   268 			adapter->tx_int_delay = opt.def;
       
   269 		}
       
   270 	}
       
   271 	{ /* Transmit Absolute Interrupt Delay */
       
   272 		static const struct e1000_option opt = {
       
   273 			.type = range_option,
       
   274 			.name = "Transmit Absolute Interrupt Delay",
       
   275 			.err  = "using default of "
       
   276 				__MODULE_STRING(DEFAULT_TADV),
       
   277 			.def  = DEFAULT_TADV,
       
   278 			.arg  = { .r = { .min = MIN_TXABSDELAY,
       
   279 					 .max = MAX_TXABSDELAY } }
       
   280 		};
       
   281 
       
   282 		if (num_TxAbsIntDelay > bd) {
       
   283 			adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
       
   284 			e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
       
   285 					      adapter);
       
   286 		} else {
       
   287 			adapter->tx_abs_int_delay = opt.def;
       
   288 		}
       
   289 	}
       
   290 	{ /* Receive Interrupt Delay */
       
   291 		static struct e1000_option opt = {
       
   292 			.type = range_option,
       
   293 			.name = "Receive Interrupt Delay",
       
   294 			.err  = "using default of "
       
   295 				__MODULE_STRING(DEFAULT_RDTR),
       
   296 			.def  = DEFAULT_RDTR,
       
   297 			.arg  = { .r = { .min = MIN_RXDELAY,
       
   298 					 .max = MAX_RXDELAY } }
       
   299 		};
       
   300 
       
   301 		if (num_RxIntDelay > bd) {
       
   302 			adapter->rx_int_delay = RxIntDelay[bd];
       
   303 			e1000_validate_option(&adapter->rx_int_delay, &opt,
       
   304 					      adapter);
       
   305 		} else {
       
   306 			adapter->rx_int_delay = opt.def;
       
   307 		}
       
   308 	}
       
   309 	{ /* Receive Absolute Interrupt Delay */
       
   310 		static const struct e1000_option opt = {
       
   311 			.type = range_option,
       
   312 			.name = "Receive Absolute Interrupt Delay",
       
   313 			.err  = "using default of "
       
   314 				__MODULE_STRING(DEFAULT_RADV),
       
   315 			.def  = DEFAULT_RADV,
       
   316 			.arg  = { .r = { .min = MIN_RXABSDELAY,
       
   317 					 .max = MAX_RXABSDELAY } }
       
   318 		};
       
   319 
       
   320 		if (num_RxAbsIntDelay > bd) {
       
   321 			adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
       
   322 			e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
       
   323 					      adapter);
       
   324 		} else {
       
   325 			adapter->rx_abs_int_delay = opt.def;
       
   326 		}
       
   327 	}
       
   328 	{ /* Interrupt Throttling Rate */
       
   329 		static const struct e1000_option opt = {
       
   330 			.type = range_option,
       
   331 			.name = "Interrupt Throttling Rate (ints/sec)",
       
   332 			.err  = "using default of "
       
   333 				__MODULE_STRING(DEFAULT_ITR),
       
   334 			.def  = DEFAULT_ITR,
       
   335 			.arg  = { .r = { .min = MIN_ITR,
       
   336 					 .max = MAX_ITR } }
       
   337 		};
       
   338 
       
   339 		if (num_InterruptThrottleRate > bd) {
       
   340 			adapter->itr = InterruptThrottleRate[bd];
       
   341 			switch (adapter->itr) {
       
   342 			case 0:
       
   343 				e_info("%s turned off\n", opt.name);
       
   344 				break;
       
   345 			case 1:
       
   346 				e_info("%s set to dynamic mode\n", opt.name);
       
   347 				adapter->itr_setting = adapter->itr;
       
   348 				adapter->itr = 20000;
       
   349 				break;
       
   350 			case 3:
       
   351 				e_info("%s set to dynamic conservative mode\n",
       
   352 					opt.name);
       
   353 				adapter->itr_setting = adapter->itr;
       
   354 				adapter->itr = 20000;
       
   355 				break;
       
   356 			case 4:
       
   357 				e_info("%s set to simplified (2000-8000 ints) "
       
   358 				       "mode\n", opt.name);
       
   359 				adapter->itr_setting = 4;
       
   360 				break;
       
   361 			default:
       
   362 				/*
       
   363 				 * Save the setting, because the dynamic bits
       
   364 				 * change itr.
       
   365 				 */
       
   366 				if (e1000_validate_option(&adapter->itr, &opt,
       
   367 							  adapter) &&
       
   368 				    (adapter->itr == 3)) {
       
   369 					/*
       
   370 					 * In case of invalid user value,
       
   371 					 * default to conservative mode.
       
   372 					 */
       
   373 					adapter->itr_setting = adapter->itr;
       
   374 					adapter->itr = 20000;
       
   375 				} else {
       
   376 					/*
       
   377 					 * Clear the lower two bits because
       
   378 					 * they are used as control.
       
   379 					 */
       
   380 					adapter->itr_setting =
       
   381 						adapter->itr & ~3;
       
   382 				}
       
   383 				break;
       
   384 			}
       
   385 		} else {
       
   386 			adapter->itr_setting = opt.def;
       
   387 			adapter->itr = 20000;
       
   388 		}
       
   389 	}
       
   390 	{ /* Interrupt Mode */
       
   391 		static struct e1000_option opt = {
       
   392 			.type = range_option,
       
   393 			.name = "Interrupt Mode",
       
   394 			.err  = "defaulting to 2 (MSI-X)",
       
   395 			.def  = E1000E_INT_MODE_MSIX,
       
   396 			.arg  = { .r = { .min = MIN_INTMODE,
       
   397 					 .max = MAX_INTMODE } }
       
   398 		};
       
   399 
       
   400 		if (num_IntMode > bd) {
       
   401 			unsigned int int_mode = IntMode[bd];
       
   402 			e1000_validate_option(&int_mode, &opt, adapter);
       
   403 			adapter->int_mode = int_mode;
       
   404 		} else {
       
   405 			adapter->int_mode = opt.def;
       
   406 		}
       
   407 	}
       
   408 	{ /* Smart Power Down */
       
   409 		static const struct e1000_option opt = {
       
   410 			.type = enable_option,
       
   411 			.name = "PHY Smart Power Down",
       
   412 			.err  = "defaulting to Disabled",
       
   413 			.def  = OPTION_DISABLED
       
   414 		};
       
   415 
       
   416 		if (num_SmartPowerDownEnable > bd) {
       
   417 			unsigned int spd = SmartPowerDownEnable[bd];
       
   418 			e1000_validate_option(&spd, &opt, adapter);
       
   419 			if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
       
   420 			    && spd)
       
   421 				adapter->flags |= FLAG_SMART_POWER_DOWN;
       
   422 		}
       
   423 	}
       
   424 	{ /* CRC Stripping */
       
   425 		static const struct e1000_option opt = {
       
   426 			.type = enable_option,
       
   427 			.name = "CRC Stripping",
       
   428 			.err  = "defaulting to enabled",
       
   429 			.def  = OPTION_ENABLED
       
   430 		};
       
   431 
       
   432 		if (num_CrcStripping > bd) {
       
   433 			unsigned int crc_stripping = CrcStripping[bd];
       
   434 			e1000_validate_option(&crc_stripping, &opt, adapter);
       
   435 			if (crc_stripping == OPTION_ENABLED)
       
   436 				adapter->flags2 |= FLAG2_CRC_STRIPPING;
       
   437 		} else {
       
   438 			adapter->flags2 |= FLAG2_CRC_STRIPPING;
       
   439 		}
       
   440 	}
       
   441 	{ /* Kumeran Lock Loss Workaround */
       
   442 		static const struct e1000_option opt = {
       
   443 			.type = enable_option,
       
   444 			.name = "Kumeran Lock Loss Workaround",
       
   445 			.err  = "defaulting to Enabled",
       
   446 			.def  = OPTION_ENABLED
       
   447 		};
       
   448 
       
   449 		if (num_KumeranLockLoss > bd) {
       
   450 			unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
       
   451 			e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
       
   452 			if (hw->mac.type == e1000_ich8lan)
       
   453 				e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
       
   454 								kmrn_lock_loss);
       
   455 		} else {
       
   456 			if (hw->mac.type == e1000_ich8lan)
       
   457 				e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
       
   458 								       opt.def);
       
   459 		}
       
   460 	}
       
   461 	{ /* Write-protect NVM */
       
   462 		static const struct e1000_option opt = {
       
   463 			.type = enable_option,
       
   464 			.name = "Write-protect NVM",
       
   465 			.err  = "defaulting to Enabled",
       
   466 			.def  = OPTION_ENABLED
       
   467 		};
       
   468 
       
   469 		if (adapter->flags & FLAG_IS_ICH) {
       
   470 			if (num_WriteProtectNVM > bd) {
       
   471 				unsigned int write_protect_nvm = WriteProtectNVM[bd];
       
   472 				e1000_validate_option(&write_protect_nvm, &opt,
       
   473 						      adapter);
       
   474 				if (write_protect_nvm)
       
   475 					adapter->flags |= FLAG_READ_ONLY_NVM;
       
   476 			} else {
       
   477 				if (opt.def)
       
   478 					adapter->flags |= FLAG_READ_ONLY_NVM;
       
   479 			}
       
   480 		}
       
   481 	}
       
   482 }