1 /*******************************************************************************
2 
3   Intel PRO/1000 Linux driver
4   Copyright(c) 1999 - 2006 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 "e1000.h"
30 
31 /* This is the only thing that needs to be changed to adjust the
32  * maximum number of ports that the driver can manage.
33  */
34 
35 #define E1000_MAX_NIC 32
36 
37 #define OPTION_UNSET   -1
38 #define OPTION_DISABLED 0
39 #define OPTION_ENABLED  1
40 
41 /* All parameters are treated the same, as an integer array of values.
42  * This macro just reduces the need to repeat the same declaration code
43  * over and over (plus this helps to avoid typo bugs).
44  */
45 
46 #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
47 #ifndef module_param_array
48 /* Module Parameters are always initialized to -1, so that the driver
49  * can tell the difference between no user specified value or the
50  * user asking for the default value.
51  * The true default values are loaded in when e1000_check_options is called.
52  *
53  * This is a GCC extension to ANSI C.
54  * See the item "Labeled Elements in Initializers" in the section
55  * "Extensions to the C Language Family" of the GCC documentation.
56  */
57 
58 #define E1000_PARAM(X, desc) \
59 	static const int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
60 	MODULE_PARM(X, "1-" __MODULE_STRING(E1000_MAX_NIC) "i"); \
61 	MODULE_PARM_DESC(X, desc);
62 #else
63 #define E1000_PARAM(X, desc) \
64 	static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
65 	static int num_##X = 0; \
66 	module_param_array_named(X, X, int, &num_##X, 0); \
67 	MODULE_PARM_DESC(X, desc);
68 #endif
69 
70 /* Transmit Descriptor Count
71  *
72  * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
73  * Valid Range: 80-4096 for 82544 and newer
74  *
75  * Default Value: 256
76  */
77 E1000_PARAM(TxDescriptors, "Number of transmit descriptors");
78 
79 /* Receive Descriptor Count
80  *
81  * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
82  * Valid Range: 80-4096 for 82544 and newer
83  *
84  * Default Value: 256
85  */
86 E1000_PARAM(RxDescriptors, "Number of receive descriptors");
87 
88 /* User Specified Speed Override
89  *
90  * Valid Range: 0, 10, 100, 1000
91  *  - 0    - auto-negotiate at all supported speeds
92  *  - 10   - only link at 10 Mbps
93  *  - 100  - only link at 100 Mbps
94  *  - 1000 - only link at 1000 Mbps
95  *
96  * Default Value: 0
97  */
98 E1000_PARAM(Speed, "Speed setting");
99 
100 /* User Specified Duplex Override
101  *
102  * Valid Range: 0-2
103  *  - 0 - auto-negotiate for duplex
104  *  - 1 - only link at half duplex
105  *  - 2 - only link at full duplex
106  *
107  * Default Value: 0
108  */
109 E1000_PARAM(Duplex, "Duplex setting");
110 
111 /* Auto-negotiation Advertisement Override
112  *
113  * Valid Range: 0x01-0x0F, 0x20-0x2F (copper); 0x20 (fiber)
114  *
115  * The AutoNeg value is a bit mask describing which speed and duplex
116  * combinations should be advertised during auto-negotiation.
117  * The supported speed and duplex modes are listed below
118  *
119  * Bit           7     6     5      4      3     2     1      0
120  * Speed (Mbps)  N/A   N/A   1000   N/A    100   100   10     10
121  * Duplex                    Full          Full  Half  Full   Half
122  *
123  * Default Value: 0x2F (copper); 0x20 (fiber)
124  */
125 E1000_PARAM(AutoNeg, "Advertised auto-negotiation setting");
126 #define AUTONEG_ADV_DEFAULT  0x2F
127 #define AUTONEG_ADV_MASK     0x2F
128 
129 /* User Specified Flow Control Override
130  *
131  * Valid Range: 0-3
132  *  - 0 - No Flow Control
133  *  - 1 - Rx only, respond to PAUSE frames but do not generate them
134  *  - 2 - Tx only, generate PAUSE frames but ignore them on receive
135  *  - 3 - Full Flow Control Support
136  *
137  * Default Value: Read flow control settings from the EEPROM
138  */
139 E1000_PARAM(FlowControl, "Flow Control setting");
140 #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
141 
142 /* XsumRX - Receive Checksum Offload Enable/Disable
143  *
144  * Valid Range: 0, 1
145  *  - 0 - disables all checksum offload
146  *  - 1 - enables receive IP/TCP/UDP checksum offload
147  *        on 82543 and newer -based NICs
148  *
149  * Default Value: 1
150  */
151 E1000_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
152 
153 /* Transmit Interrupt Delay in units of 1.024 microseconds
154  *  Tx interrupt delay needs to typically be set to something non zero
155  *
156  * Valid Range: 0-65535
157  */
158 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
159 #define DEFAULT_TIDV                   8
160 #define MAX_TXDELAY               0xFFFF
161 #define MIN_TXDELAY                    0
162 
163 /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
164  *
165  * Valid Range: 0-65535
166  */
167 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
168 #define DEFAULT_TADV                  32
169 #define MAX_TXABSDELAY            0xFFFF
170 #define MIN_TXABSDELAY                 0
171 
172 /* Receive Interrupt Delay in units of 1.024 microseconds
173  *   hardware will likely hang if you set this to anything but zero.
174  *
175  * Valid Range: 0-65535
176  */
177 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
178 #define DEFAULT_RDTR                   0
179 #define MAX_RXDELAY               0xFFFF
180 #define MIN_RXDELAY                    0
181 
182 /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
183  *
184  * Valid Range: 0-65535
185  */
186 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
187 #define DEFAULT_RADV                   8
188 #define MAX_RXABSDELAY            0xFFFF
189 #define MIN_RXABSDELAY                 0
190 
191 /* Interrupt Throttle Rate (interrupts/sec)
192  *
193  * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
194  */
195 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
196 #define DEFAULT_ITR                    3
197 #define MAX_ITR                   100000
198 #define MIN_ITR                      100
199 
200 /* Enable Smart Power Down of the PHY
201  *
202  * Valid Range: 0, 1
203  *
204  * Default Value: 0 (disabled)
205  */
206 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
207 
208 /* Enable Kumeran Lock Loss workaround
209  *
210  * Valid Range: 0, 1
211  *
212  * Default Value: 1 (enabled)
213  */
214 E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
215 
216 struct e1000_option {
217 	enum { enable_option, range_option, list_option } type;
218 	char *name;
219 	char *err;
220 	int  def;
221 	union {
222 		struct { /* range_option info */
223 			int min;
224 			int max;
225 		} r;
226 		struct { /* list_option info */
227 			int nr;
228 			struct e1000_opt_list { int i; char *str; } *p;
229 		} l;
230 	} arg;
231 };
232 
233 static int __devinit
e1000_validate_option(int * value,struct e1000_option * opt,struct e1000_adapter * adapter)234 e1000_validate_option(int *value, struct e1000_option *opt,
235 		struct e1000_adapter *adapter)
236 {
237 	if (*value == OPTION_UNSET) {
238 		*value = opt->def;
239 		return 0;
240 	}
241 
242 	switch (opt->type) {
243 	case enable_option:
244 		switch (*value) {
245 		case OPTION_ENABLED:
246 			DPRINTK(PROBE, INFO, "%s Enabled\n", opt->name);
247 			return 0;
248 		case OPTION_DISABLED:
249 			DPRINTK(PROBE, INFO, "%s Disabled\n", opt->name);
250 			return 0;
251 		}
252 		break;
253 	case range_option:
254 		if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
255 			DPRINTK(PROBE, INFO,
256 					"%s set to %i\n", opt->name, *value);
257 			return 0;
258 		}
259 		break;
260 	case list_option: {
261 		int i;
262 		struct e1000_opt_list *ent;
263 
264 		for (i = 0; i < opt->arg.l.nr; i++) {
265 			ent = &opt->arg.l.p[i];
266 			if (*value == ent->i) {
267 				if (ent->str[0] != '\0')
268 					DPRINTK(PROBE, INFO, "%s\n", ent->str);
269 				return 0;
270 			}
271 		}
272 	}
273 		break;
274 	default:
275 		BUG();
276 	}
277 
278 	DPRINTK(PROBE, INFO, "Invalid %s value specified (%i) %s\n",
279 	       opt->name, *value, opt->err);
280 	*value = opt->def;
281 	return -1;
282 }
283 
284 static void e1000_check_fiber_options(struct e1000_adapter *adapter);
285 static void e1000_check_copper_options(struct e1000_adapter *adapter);
286 
287 /**
288  * e1000_check_options - Range Checking for Command Line Parameters
289  * @adapter: board private structure
290  *
291  * This routine checks all command line parameters for valid user
292  * input.  If an invalid value is given, or if no user specified
293  * value exists, a default value is used.  The final value is stored
294  * in a variable in the adapter structure.
295  **/
296 
297 void __devinit
e1000_check_options(struct e1000_adapter * adapter)298 e1000_check_options(struct e1000_adapter *adapter)
299 {
300 	int bd = adapter->bd_number;
301 	if (bd >= E1000_MAX_NIC) {
302 		DPRINTK(PROBE, NOTICE,
303 		       "Warning: no configuration for board #%i\n", bd);
304 		DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
305 #ifndef module_param_array
306 		bd = E1000_MAX_NIC;
307 #endif
308 	}
309 
310 	{ /* Transmit Descriptor Count */
311 		struct e1000_option opt = {
312 			.type = range_option,
313 			.name = "Transmit Descriptors",
314 			.err  = "using default of "
315 				__MODULE_STRING(E1000_DEFAULT_TXD),
316 			.def  = E1000_DEFAULT_TXD,
317 			.arg  = { .r = { .min = E1000_MIN_TXD }}
318 		};
319 		struct e1000_tx_ring *tx_ring = adapter->tx_ring;
320 		int i;
321 		e1000_mac_type mac_type = adapter->hw.mac_type;
322 		opt.arg.r.max = mac_type < e1000_82544 ?
323 			E1000_MAX_TXD : E1000_MAX_82544_TXD;
324 
325 #ifdef module_param_array
326 		if (num_TxDescriptors > bd) {
327 #endif
328 			tx_ring->count = TxDescriptors[bd];
329 			e1000_validate_option(&tx_ring->count, &opt, adapter);
330 			E1000_ROUNDUP(tx_ring->count,
331 						REQ_TX_DESCRIPTOR_MULTIPLE);
332 #ifdef module_param_array
333 		} else {
334 			tx_ring->count = opt.def;
335 		}
336 #endif
337 		for (i = 0; i < adapter->num_tx_queues; i++)
338 			tx_ring[i].count = tx_ring->count;
339 	}
340 	{ /* Receive Descriptor Count */
341 		struct e1000_option opt = {
342 			.type = range_option,
343 			.name = "Receive Descriptors",
344 			.err  = "using default of "
345 				__MODULE_STRING(E1000_DEFAULT_RXD),
346 			.def  = E1000_DEFAULT_RXD,
347 			.arg  = { .r = { .min = E1000_MIN_RXD }}
348 		};
349 		struct e1000_rx_ring *rx_ring = adapter->rx_ring;
350 		int i;
351 		e1000_mac_type mac_type = adapter->hw.mac_type;
352 		opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
353 			E1000_MAX_82544_RXD;
354 
355 #ifdef module_param_array
356 		if (num_RxDescriptors > bd) {
357 #endif
358 			rx_ring->count = RxDescriptors[bd];
359 			e1000_validate_option(&rx_ring->count, &opt, adapter);
360 			E1000_ROUNDUP(rx_ring->count,
361 						REQ_RX_DESCRIPTOR_MULTIPLE);
362 #ifdef module_param_array
363 		} else {
364 			rx_ring->count = opt.def;
365 		}
366 #endif
367 		for (i = 0; i < adapter->num_rx_queues; i++)
368 			rx_ring[i].count = rx_ring->count;
369 	}
370 	{ /* Checksum Offload Enable/Disable */
371 		struct e1000_option opt = {
372 			.type = enable_option,
373 			.name = "Checksum Offload",
374 			.err  = "defaulting to Enabled",
375 			.def  = OPTION_ENABLED
376 		};
377 
378 #ifdef module_param_array
379 		if (num_XsumRX > bd) {
380 #endif
381 			int rx_csum = XsumRX[bd];
382 			e1000_validate_option(&rx_csum, &opt, adapter);
383 			adapter->rx_csum = rx_csum;
384 #ifdef module_param_array
385 		} else {
386 			adapter->rx_csum = opt.def;
387 		}
388 #endif
389 	}
390 	{ /* Flow Control */
391 
392 		struct e1000_opt_list fc_list[] =
393 			{{ E1000_FC_NONE,    "Flow Control Disabled" },
394 			 { E1000_FC_RX_PAUSE,"Flow Control Receive Only" },
395 			 { E1000_FC_TX_PAUSE,"Flow Control Transmit Only" },
396 			 { E1000_FC_FULL,    "Flow Control Enabled" },
397 			 { E1000_FC_DEFAULT, "Flow Control Hardware Default" }};
398 
399 		struct e1000_option opt = {
400 			.type = list_option,
401 			.name = "Flow Control",
402 			.err  = "reading default settings from EEPROM",
403 			.def  = E1000_FC_DEFAULT,
404 			.arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
405 					 .p = fc_list }}
406 		};
407 
408 #ifdef module_param_array
409 		if (num_FlowControl > bd) {
410 #endif
411 			int fc = FlowControl[bd];
412 			e1000_validate_option(&fc, &opt, adapter);
413 			adapter->hw.fc = adapter->hw.original_fc = fc;
414 #ifdef module_param_array
415 		} else {
416 			adapter->hw.fc = adapter->hw.original_fc = opt.def;
417 		}
418 #endif
419 	}
420 	{ /* Transmit Interrupt Delay */
421 		struct e1000_option opt = {
422 			.type = range_option,
423 			.name = "Transmit Interrupt Delay",
424 			.err  = "using default of " __MODULE_STRING(DEFAULT_TIDV),
425 			.def  = DEFAULT_TIDV,
426 			.arg  = { .r = { .min = MIN_TXDELAY,
427 					 .max = MAX_TXDELAY }}
428 		};
429 
430 #ifdef module_param_array
431 		if (num_TxIntDelay > bd) {
432 #endif
433 			adapter->tx_int_delay = TxIntDelay[bd];
434 			e1000_validate_option(&adapter->tx_int_delay, &opt,
435 			                      adapter);
436 #ifdef module_param_array
437 		} else {
438 			adapter->tx_int_delay = opt.def;
439 		}
440 #endif
441 	}
442 	{ /* Transmit Absolute Interrupt Delay */
443 		struct e1000_option opt = {
444 			.type = range_option,
445 			.name = "Transmit Absolute Interrupt Delay",
446 			.err  = "using default of " __MODULE_STRING(DEFAULT_TADV),
447 			.def  = DEFAULT_TADV,
448 			.arg  = { .r = { .min = MIN_TXABSDELAY,
449 					 .max = MAX_TXABSDELAY }}
450 		};
451 
452 #ifdef module_param_array
453 		if (num_TxAbsIntDelay > bd) {
454 #endif
455 			adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
456 			e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
457 			                      adapter);
458 #ifdef module_param_array
459 		} else {
460 			adapter->tx_abs_int_delay = opt.def;
461 		}
462 #endif
463 	}
464 	{ /* Receive Interrupt Delay */
465 		struct e1000_option opt = {
466 			.type = range_option,
467 			.name = "Receive Interrupt Delay",
468 			.err  = "using default of " __MODULE_STRING(DEFAULT_RDTR),
469 			.def  = DEFAULT_RDTR,
470 			.arg  = { .r = { .min = MIN_RXDELAY,
471 					 .max = MAX_RXDELAY }}
472 		};
473 
474 #ifdef module_param_array
475 		if (num_RxIntDelay > bd) {
476 #endif
477 			adapter->rx_int_delay = RxIntDelay[bd];
478 			e1000_validate_option(&adapter->rx_int_delay, &opt,
479 			                      adapter);
480 #ifdef module_param_array
481 		} else {
482 			adapter->rx_int_delay = opt.def;
483 		}
484 #endif
485 	}
486 	{ /* Receive Absolute Interrupt Delay */
487 		struct e1000_option opt = {
488 			.type = range_option,
489 			.name = "Receive Absolute Interrupt Delay",
490 			.err  = "using default of " __MODULE_STRING(DEFAULT_RADV),
491 			.def  = DEFAULT_RADV,
492 			.arg  = { .r = { .min = MIN_RXABSDELAY,
493 					 .max = MAX_RXABSDELAY }}
494 		};
495 
496 #ifdef module_param_array
497 		if (num_RxAbsIntDelay > bd) {
498 #endif
499 			adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
500 			e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
501 			                      adapter);
502 #ifdef module_param_array
503 		} else {
504 			adapter->rx_abs_int_delay = opt.def;
505 		}
506 #endif
507 	}
508 	{ /* Interrupt Throttling Rate */
509 		struct e1000_option opt = {
510 			.type = range_option,
511 			.name = "Interrupt Throttling Rate (ints/sec)",
512 			.err  = "using default of " __MODULE_STRING(DEFAULT_ITR),
513 			.def  = DEFAULT_ITR,
514 			.arg  = { .r = { .min = MIN_ITR,
515 					 .max = MAX_ITR }}
516 		};
517 
518 #ifdef module_param_array
519 		if (num_InterruptThrottleRate > bd) {
520 #endif
521 			adapter->itr = InterruptThrottleRate[bd];
522 			switch (adapter->itr) {
523 			case 0:
524 				DPRINTK(PROBE, INFO, "%s turned off\n",
525 				        opt.name);
526 				break;
527 			case 1:
528 				DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
529 					opt.name);
530 				adapter->itr_setting = adapter->itr;
531 				adapter->itr = 20000;
532 				break;
533 			case 3:
534 				DPRINTK(PROBE, INFO,
535 				        "%s set to dynamic conservative mode\n",
536 					opt.name);
537 				adapter->itr_setting = adapter->itr;
538 				adapter->itr = 20000;
539 				break;
540 			default:
541 				e1000_validate_option(&adapter->itr, &opt,
542 				        adapter);
543 				/* save the setting, because the dynamic bits change itr */
544 				/* clear the lower two bits because they are
545 				 * used as control */
546 				adapter->itr_setting = adapter->itr & ~3;
547 				break;
548 			}
549 #ifdef module_param_array
550 		} else {
551 			adapter->itr_setting = opt.def;
552 			adapter->itr = 20000;
553 		}
554 #endif
555 	}
556 	{ /* Smart Power Down */
557 		struct e1000_option opt = {
558 			.type = enable_option,
559 			.name = "PHY Smart Power Down",
560 			.err  = "defaulting to Disabled",
561 			.def  = OPTION_DISABLED
562 		};
563 
564 #ifdef module_param_array
565 		if (num_SmartPowerDownEnable > bd) {
566 #endif
567 			int spd = SmartPowerDownEnable[bd];
568 			e1000_validate_option(&spd, &opt, adapter);
569 			adapter->smart_power_down = spd;
570 #ifdef module_param_array
571 		} else {
572 			adapter->smart_power_down = opt.def;
573 		}
574 #endif
575 	}
576 	{ /* Kumeran Lock Loss Workaround */
577 		struct e1000_option opt = {
578 			.type = enable_option,
579 			.name = "Kumeran Lock Loss Workaround",
580 			.err  = "defaulting to Enabled",
581 			.def  = OPTION_ENABLED
582 		};
583 
584 #ifdef module_param_array
585 		if (num_KumeranLockLoss > bd) {
586 #endif
587 			int kmrn_lock_loss = KumeranLockLoss[bd];
588 			e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
589 			adapter->hw.kmrn_lock_loss_workaround_disabled = !kmrn_lock_loss;
590 #ifdef module_param_array
591 		} else {
592 			adapter->hw.kmrn_lock_loss_workaround_disabled = !opt.def;
593 		}
594 #endif
595 	}
596 
597 	switch (adapter->hw.media_type) {
598 	case e1000_media_type_fiber:
599 	case e1000_media_type_internal_serdes:
600 		e1000_check_fiber_options(adapter);
601 		break;
602 	case e1000_media_type_copper:
603 		e1000_check_copper_options(adapter);
604 		break;
605 	default:
606 		BUG();
607 	}
608 }
609 
610 /**
611  * e1000_check_fiber_options - Range Checking for Link Options, Fiber Version
612  * @adapter: board private structure
613  *
614  * Handles speed and duplex options on fiber adapters
615  **/
616 
617 static void __devinit
e1000_check_fiber_options(struct e1000_adapter * adapter)618 e1000_check_fiber_options(struct e1000_adapter *adapter)
619 {
620 	int bd = adapter->bd_number;
621 #ifndef module_param_array
622 	bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
623 	if ((Speed[bd] != OPTION_UNSET)) {
624 #else
625 	if (num_Speed > bd) {
626 #endif
627 		DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
628 		       "parameter ignored\n");
629 	}
630 
631 #ifndef module_param_array
632 	if ((Duplex[bd] != OPTION_UNSET)) {
633 #else
634 	if (num_Duplex > bd) {
635 #endif
636 		DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
637 		       "parameter ignored\n");
638 	}
639 
640 #ifndef module_param_array
641 	if ((AutoNeg[bd] != OPTION_UNSET) && (AutoNeg[bd] != 0x20)) {
642 #else
643 	if ((num_AutoNeg > bd) && (AutoNeg[bd] != 0x20)) {
644 #endif
645 		DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
646 				 "not valid for fiber adapters, "
647 				 "parameter ignored\n");
648 	}
649 }
650 
651 /**
652  * e1000_check_copper_options - Range Checking for Link Options, Copper Version
653  * @adapter: board private structure
654  *
655  * Handles speed and duplex options on copper adapters
656  **/
657 
658 static void __devinit
659 e1000_check_copper_options(struct e1000_adapter *adapter)
660 {
661 	int speed, dplx, an;
662 	int bd = adapter->bd_number;
663 #ifndef module_param_array
664 	bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
665 #endif
666 
667 	{ /* Speed */
668 		struct e1000_opt_list speed_list[] = {{          0, "" },
669 						      {   SPEED_10, "" },
670 						      {  SPEED_100, "" },
671 						      { SPEED_1000, "" }};
672 
673 		struct e1000_option opt = {
674 			.type = list_option,
675 			.name = "Speed",
676 			.err  = "parameter ignored",
677 			.def  = 0,
678 			.arg  = { .l = { .nr = ARRAY_SIZE(speed_list),
679 					 .p = speed_list }}
680 		};
681 
682 #ifdef module_param_array
683 		if (num_Speed > bd) {
684 #endif
685 			speed = Speed[bd];
686 			e1000_validate_option(&speed, &opt, adapter);
687 #ifdef module_param_array
688 		} else {
689 			speed = opt.def;
690 		}
691 #endif
692 	}
693 	{ /* Duplex */
694 		struct e1000_opt_list dplx_list[] = {{           0, "" },
695 						     { HALF_DUPLEX, "" },
696 						     { FULL_DUPLEX, "" }};
697 
698 		struct e1000_option opt = {
699 			.type = list_option,
700 			.name = "Duplex",
701 			.err  = "parameter ignored",
702 			.def  = 0,
703 			.arg  = { .l = { .nr = ARRAY_SIZE(dplx_list),
704 					 .p = dplx_list }}
705 		};
706 
707 		if (e1000_check_phy_reset_block(&adapter->hw)) {
708 			DPRINTK(PROBE, INFO,
709 				"Link active due to SoL/IDER Session. "
710 			        "Speed/Duplex/AutoNeg parameter ignored.\n");
711 			return;
712 		}
713 #ifdef module_param_array
714 		if (num_Duplex > bd) {
715 #endif
716 			dplx = Duplex[bd];
717 			e1000_validate_option(&dplx, &opt, adapter);
718 #ifdef module_param_array
719 		} else {
720 			dplx = opt.def;
721 		}
722 #endif
723 	}
724 
725 #ifdef module_param_array
726 	if ((num_AutoNeg > bd) && (speed != 0 || dplx != 0)) {
727 #else
728 	if (AutoNeg[bd] != OPTION_UNSET && (speed != 0 || dplx != 0)) {
729 #endif
730 		DPRINTK(PROBE, INFO,
731 		       "AutoNeg specified along with Speed or Duplex, "
732 		       "parameter ignored\n");
733 		adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
734 	} else { /* Autoneg */
735 		struct e1000_opt_list an_list[] =
736 			#define AA "AutoNeg advertising "
737 			{{ 0x01, AA "10/HD" },
738 			 { 0x02, AA "10/FD" },
739 			 { 0x03, AA "10/FD, 10/HD" },
740 			 { 0x04, AA "100/HD" },
741 			 { 0x05, AA "100/HD, 10/HD" },
742 			 { 0x06, AA "100/HD, 10/FD" },
743 			 { 0x07, AA "100/HD, 10/FD, 10/HD" },
744 			 { 0x08, AA "100/FD" },
745 			 { 0x09, AA "100/FD, 10/HD" },
746 			 { 0x0a, AA "100/FD, 10/FD" },
747 			 { 0x0b, AA "100/FD, 10/FD, 10/HD" },
748 			 { 0x0c, AA "100/FD, 100/HD" },
749 			 { 0x0d, AA "100/FD, 100/HD, 10/HD" },
750 			 { 0x0e, AA "100/FD, 100/HD, 10/FD" },
751 			 { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
752 			 { 0x20, AA "1000/FD" },
753 			 { 0x21, AA "1000/FD, 10/HD" },
754 			 { 0x22, AA "1000/FD, 10/FD" },
755 			 { 0x23, AA "1000/FD, 10/FD, 10/HD" },
756 			 { 0x24, AA "1000/FD, 100/HD" },
757 			 { 0x25, AA "1000/FD, 100/HD, 10/HD" },
758 			 { 0x26, AA "1000/FD, 100/HD, 10/FD" },
759 			 { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
760 			 { 0x28, AA "1000/FD, 100/FD" },
761 			 { 0x29, AA "1000/FD, 100/FD, 10/HD" },
762 			 { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
763 			 { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
764 			 { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
765 			 { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
766 			 { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
767 			 { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }};
768 
769 		struct e1000_option opt = {
770 			.type = list_option,
771 			.name = "AutoNeg",
772 			.err  = "parameter ignored",
773 			.def  = AUTONEG_ADV_DEFAULT,
774 			.arg  = { .l = { .nr = ARRAY_SIZE(an_list),
775 					 .p = an_list }}
776 		};
777 
778 #ifdef module_param_array
779 		if (num_AutoNeg > bd) {
780 #endif
781 			an = AutoNeg[bd];
782 			e1000_validate_option(&an, &opt, adapter);
783 #ifdef module_param_array
784 		} else {
785 			an = opt.def;
786 		}
787 #endif
788 		adapter->hw.autoneg_advertised = an;
789 	}
790 
791 	switch (speed + dplx) {
792 	case 0:
793 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
794 #ifdef module_param_array
795 		if ((num_Speed > bd) && (speed != 0 || dplx != 0))
796 #else
797 		if (Speed[bd] != OPTION_UNSET || Duplex[bd] != OPTION_UNSET)
798 #endif
799 			DPRINTK(PROBE, INFO,
800 			       "Speed and duplex autonegotiation enabled\n");
801 		break;
802 	case HALF_DUPLEX:
803 		DPRINTK(PROBE, INFO, "Half Duplex specified without Speed\n");
804 		DPRINTK(PROBE, INFO, "Using Autonegotiation at "
805 			"Half Duplex only\n");
806 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
807 		adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
808 		                                 ADVERTISE_100_HALF;
809 		break;
810 	case FULL_DUPLEX:
811 		DPRINTK(PROBE, INFO, "Full Duplex specified without Speed\n");
812 		DPRINTK(PROBE, INFO, "Using Autonegotiation at "
813 			"Full Duplex only\n");
814 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
815 		adapter->hw.autoneg_advertised = ADVERTISE_10_FULL |
816 		                                 ADVERTISE_100_FULL |
817 		                                 ADVERTISE_1000_FULL;
818 		break;
819 	case SPEED_10:
820 		DPRINTK(PROBE, INFO, "10 Mbps Speed specified "
821 			"without Duplex\n");
822 		DPRINTK(PROBE, INFO, "Using Autonegotiation at 10 Mbps only\n");
823 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
824 		adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
825 		                                 ADVERTISE_10_FULL;
826 		break;
827 	case SPEED_10 + HALF_DUPLEX:
828 		DPRINTK(PROBE, INFO, "Forcing to 10 Mbps Half Duplex\n");
829 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
830 		adapter->hw.forced_speed_duplex = e1000_10_half;
831 		adapter->hw.autoneg_advertised = 0;
832 		break;
833 	case SPEED_10 + FULL_DUPLEX:
834 		DPRINTK(PROBE, INFO, "Forcing to 10 Mbps Full Duplex\n");
835 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
836 		adapter->hw.forced_speed_duplex = e1000_10_full;
837 		adapter->hw.autoneg_advertised = 0;
838 		break;
839 	case SPEED_100:
840 		DPRINTK(PROBE, INFO, "100 Mbps Speed specified "
841 			"without Duplex\n");
842 		DPRINTK(PROBE, INFO, "Using Autonegotiation at "
843 			"100 Mbps only\n");
844 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
845 		adapter->hw.autoneg_advertised = ADVERTISE_100_HALF |
846 		                                 ADVERTISE_100_FULL;
847 		break;
848 	case SPEED_100 + HALF_DUPLEX:
849 		DPRINTK(PROBE, INFO, "Forcing to 100 Mbps Half Duplex\n");
850 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
851 		adapter->hw.forced_speed_duplex = e1000_100_half;
852 		adapter->hw.autoneg_advertised = 0;
853 		break;
854 	case SPEED_100 + FULL_DUPLEX:
855 		DPRINTK(PROBE, INFO, "Forcing to 100 Mbps Full Duplex\n");
856 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
857 		adapter->hw.forced_speed_duplex = e1000_100_full;
858 		adapter->hw.autoneg_advertised = 0;
859 		break;
860 	case SPEED_1000:
861 		DPRINTK(PROBE, INFO, "1000 Mbps Speed specified without "
862 			"Duplex\n");
863 		goto full_duplex_only;
864 	case SPEED_1000 + HALF_DUPLEX:
865 		DPRINTK(PROBE, INFO,
866 			"Half Duplex is not supported at 1000 Mbps\n");
867 		/* fall through */
868 	case SPEED_1000 + FULL_DUPLEX:
869 full_duplex_only:
870 		DPRINTK(PROBE, INFO,
871 		       "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
872 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
873 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
874 		break;
875 	default:
876 		BUG();
877 	}
878 
879 	/* Speed, AutoNeg and MDI/MDI-X must all play nice */
880 	if (e1000_validate_mdi_setting(&(adapter->hw)) < 0) {
881 		DPRINTK(PROBE, INFO,
882 			"Speed, AutoNeg and MDI-X specifications are "
883 			"incompatible. Setting MDI-X to a compatible value.\n");
884 	}
885 }
886 
887