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