Linux Audio

Check our new training course

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