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