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