Linux Audio

Check our new training course

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