e1000_param.c 21.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/*******************************************************************************

3 4 5 6 7 8 9 10 11 12
  Intel PRO/1000 Linux driver
  Copyright(c) 1999 - 2006 Intel Corporation.

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
L
Linus Torvalds 已提交
13
  more details.
14

L
Linus Torvalds 已提交
15
  You should have received a copy of the GNU General Public License along with
16 17 18 19 20 21
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

L
Linus Torvalds 已提交
22 23
  Contact Information:
  Linux NICS <linux.nics@intel.com>
24
  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
L
Linus Torvalds 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497

*******************************************************************************/

#include "e1000.h"

/* This is the only thing that needs to be changed to adjust the
 * maximum number of ports that the driver can manage.
 */

#define E1000_MAX_NIC 32

#define OPTION_UNSET   -1
#define OPTION_DISABLED 0
#define OPTION_ENABLED  1

/* All parameters are treated the same, as an integer array of values.
 * This macro just reduces the need to repeat the same declaration code
 * over and over (plus this helps to avoid typo bugs).
 */

#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
#define E1000_PARAM(X, desc) \
	static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
S
Stephen Hemminger 已提交
49
	static unsigned int num_##X; \
L
Linus Torvalds 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
	module_param_array_named(X, X, int, &num_##X, 0); \
	MODULE_PARM_DESC(X, desc);

/* Transmit Descriptor Count
 *
 * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
 * Valid Range: 80-4096 for 82544 and newer
 *
 * Default Value: 256
 */
E1000_PARAM(TxDescriptors, "Number of transmit descriptors");

/* Receive Descriptor Count
 *
 * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
 * Valid Range: 80-4096 for 82544 and newer
 *
 * Default Value: 256
 */
E1000_PARAM(RxDescriptors, "Number of receive descriptors");

/* User Specified Speed Override
 *
 * Valid Range: 0, 10, 100, 1000
 *  - 0    - auto-negotiate at all supported speeds
 *  - 10   - only link at 10 Mbps
 *  - 100  - only link at 100 Mbps
 *  - 1000 - only link at 1000 Mbps
 *
 * Default Value: 0
 */
E1000_PARAM(Speed, "Speed setting");

/* User Specified Duplex Override
 *
 * Valid Range: 0-2
 *  - 0 - auto-negotiate for duplex
 *  - 1 - only link at half duplex
 *  - 2 - only link at full duplex
 *
 * Default Value: 0
 */
E1000_PARAM(Duplex, "Duplex setting");

/* Auto-negotiation Advertisement Override
 *
 * Valid Range: 0x01-0x0F, 0x20-0x2F (copper); 0x20 (fiber)
 *
 * The AutoNeg value is a bit mask describing which speed and duplex
 * combinations should be advertised during auto-negotiation.
 * The supported speed and duplex modes are listed below
 *
 * Bit           7     6     5      4      3     2     1      0
 * Speed (Mbps)  N/A   N/A   1000   N/A    100   100   10     10
 * Duplex                    Full          Full  Half  Full   Half
 *
 * Default Value: 0x2F (copper); 0x20 (fiber)
 */
E1000_PARAM(AutoNeg, "Advertised auto-negotiation setting");
A
Auke Kok 已提交
109 110
#define AUTONEG_ADV_DEFAULT  0x2F
#define AUTONEG_ADV_MASK     0x2F
L
Linus Torvalds 已提交
111 112 113 114 115 116 117 118 119 120 121 122

/* User Specified Flow Control Override
 *
 * Valid Range: 0-3
 *  - 0 - No Flow Control
 *  - 1 - Rx only, respond to PAUSE frames but do not generate them
 *  - 2 - Tx only, generate PAUSE frames but ignore them on receive
 *  - 3 - Full Flow Control Support
 *
 * Default Value: Read flow control settings from the EEPROM
 */
E1000_PARAM(FlowControl, "Flow Control setting");
A
Auke Kok 已提交
123
#define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
L
Linus Torvalds 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136

/* XsumRX - Receive Checksum Offload Enable/Disable
 *
 * Valid Range: 0, 1
 *  - 0 - disables all checksum offload
 *  - 1 - enables receive IP/TCP/UDP checksum offload
 *        on 82543 and newer -based NICs
 *
 * Default Value: 1
 */
E1000_PARAM(XsumRX, "Disable or enable Receive Checksum offload");

/* Transmit Interrupt Delay in units of 1.024 microseconds
A
Auke Kok 已提交
137
 *  Tx interrupt delay needs to typically be set to something non zero
L
Linus Torvalds 已提交
138 139 140 141
 *
 * Valid Range: 0-65535
 */
E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
J
Jesse Brandeburg 已提交
142
#define DEFAULT_TIDV                   8
A
Auke Kok 已提交
143 144
#define MAX_TXDELAY               0xFFFF
#define MIN_TXDELAY                    0
L
Linus Torvalds 已提交
145 146 147 148 149 150

/* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
 *
 * Valid Range: 0-65535
 */
E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
J
Jesse Brandeburg 已提交
151
#define DEFAULT_TADV                  32
A
Auke Kok 已提交
152 153
#define MAX_TXABSDELAY            0xFFFF
#define MIN_TXABSDELAY                 0
L
Linus Torvalds 已提交
154 155

/* Receive Interrupt Delay in units of 1.024 microseconds
A
Auke Kok 已提交
156
 *   hardware will likely hang if you set this to anything but zero.
L
Linus Torvalds 已提交
157 158 159 160
 *
 * Valid Range: 0-65535
 */
E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
A
Auke Kok 已提交
161 162 163
#define DEFAULT_RDTR                   0
#define MAX_RXDELAY               0xFFFF
#define MIN_RXDELAY                    0
L
Linus Torvalds 已提交
164 165 166 167 168 169

/* Receive Absolute Interrupt Delay in units of 1.024 microseconds
 *
 * Valid Range: 0-65535
 */
E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
J
Jesse Brandeburg 已提交
170
#define DEFAULT_RADV                   8
A
Auke Kok 已提交
171 172
#define MAX_RXABSDELAY            0xFFFF
#define MIN_RXABSDELAY                 0
L
Linus Torvalds 已提交
173 174 175

/* Interrupt Throttle Rate (interrupts/sec)
 *
J
Jesse Brandeburg 已提交
176
 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
L
Linus Torvalds 已提交
177 178
 */
E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
J
Jesse Brandeburg 已提交
179
#define DEFAULT_ITR                    3
A
Auke Kok 已提交
180 181
#define MAX_ITR                   100000
#define MIN_ITR                      100
L
Linus Torvalds 已提交
182

A
Auke Kok 已提交
183 184 185 186 187 188 189 190
/* Enable Smart Power Down of the PHY
 *
 * Valid Range: 0, 1
 *
 * Default Value: 0 (disabled)
 */
E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");

191 192 193 194 195 196 197 198
/* Enable Kumeran Lock Loss workaround
 *
 * Valid Range: 0, 1
 *
 * Default Value: 1 (enabled)
 */
E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");

L
Linus Torvalds 已提交
199 200
struct e1000_option {
	enum { enable_option, range_option, list_option } type;
S
Stephen Hemminger 已提交
201 202 203
	const char *name;
	const char *err;
	int def;
L
Linus Torvalds 已提交
204 205 206 207 208 209 210
	union {
		struct { /* range_option info */
			int min;
			int max;
		} r;
		struct { /* list_option info */
			int nr;
L
Linus Torvalds 已提交
211
			const struct e1000_opt_list { int i; char *str; } *p;
L
Linus Torvalds 已提交
212 213 214 215
		} l;
	} arg;
};

216 217 218
static int __devinit e1000_validate_option(unsigned int *value,
					   const struct e1000_option *opt,
					   struct e1000_adapter *adapter)
L
Linus Torvalds 已提交
219
{
J
Jesse Brandeburg 已提交
220
	if (*value == OPTION_UNSET) {
L
Linus Torvalds 已提交
221 222 223 224 225 226 227 228
		*value = opt->def;
		return 0;
	}

	switch (opt->type) {
	case enable_option:
		switch (*value) {
		case OPTION_ENABLED:
229
			e_dev_info("%s Enabled\n", opt->name);
L
Linus Torvalds 已提交
230 231
			return 0;
		case OPTION_DISABLED:
232
			e_dev_info("%s Disabled\n", opt->name);
L
Linus Torvalds 已提交
233 234 235 236
			return 0;
		}
		break;
	case range_option:
J
Jesse Brandeburg 已提交
237
		if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
238
			e_dev_info("%s set to %i\n", opt->name, *value);
L
Linus Torvalds 已提交
239 240 241 242 243
			return 0;
		}
		break;
	case list_option: {
		int i;
L
Linus Torvalds 已提交
244
		const struct e1000_opt_list *ent;
L
Linus Torvalds 已提交
245

J
Jesse Brandeburg 已提交
246
		for (i = 0; i < opt->arg.l.nr; i++) {
L
Linus Torvalds 已提交
247
			ent = &opt->arg.l.p[i];
J
Jesse Brandeburg 已提交
248 249
			if (*value == ent->i) {
				if (ent->str[0] != '\0')
250
					e_dev_info("%s\n", ent->str);
L
Linus Torvalds 已提交
251 252 253 254 255 256 257 258 259
				return 0;
			}
		}
	}
		break;
	default:
		BUG();
	}

260
	e_dev_info("Invalid %s value specified (%i) %s\n",
L
Linus Torvalds 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	       opt->name, *value, opt->err);
	*value = opt->def;
	return -1;
}

static void e1000_check_fiber_options(struct e1000_adapter *adapter);
static void e1000_check_copper_options(struct e1000_adapter *adapter);

/**
 * e1000_check_options - Range Checking for Command Line Parameters
 * @adapter: board private structure
 *
 * This routine checks all command line parameters for valid user
 * input.  If an invalid value is given, or if no user specified
 * value exists, a default value is used.  The final value is stored
 * in a variable in the adapter structure.
 **/

279
void __devinit e1000_check_options(struct e1000_adapter *adapter)
L
Linus Torvalds 已提交
280
{
L
Linus Torvalds 已提交
281
	struct e1000_option opt;
L
Linus Torvalds 已提交
282
	int bd = adapter->bd_number;
L
Linus Torvalds 已提交
283

J
Jesse Brandeburg 已提交
284
	if (bd >= E1000_MAX_NIC) {
285 286
		e_dev_warn("Warning: no configuration for board #%i "
			   "using defaults for all values\n", bd);
L
Linus Torvalds 已提交
287 288 289
	}

	{ /* Transmit Descriptor Count */
L
Linus Torvalds 已提交
290 291 292 293 294
		struct e1000_tx_ring *tx_ring = adapter->tx_ring;
		int i;
		e1000_mac_type mac_type = adapter->hw.mac_type;

		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
295 296 297 298 299
			.type = range_option,
			.name = "Transmit Descriptors",
			.err  = "using default of "
				__MODULE_STRING(E1000_DEFAULT_TXD),
			.def  = E1000_DEFAULT_TXD,
L
Linus Torvalds 已提交
300 301 302 303
			.arg  = { .r = {
				.min = E1000_MIN_TXD,
				.max = mac_type < e1000_82544 ? E1000_MAX_TXD : E1000_MAX_82544_TXD
				}}
L
Linus Torvalds 已提交
304 305
		};

A
Auke Kok 已提交
306 307 308
		if (num_TxDescriptors > bd) {
			tx_ring->count = TxDescriptors[bd];
			e1000_validate_option(&tx_ring->count, &opt, adapter);
309
			tx_ring->count = ALIGN(tx_ring->count,
A
Auke Kok 已提交
310 311 312 313
						REQ_TX_DESCRIPTOR_MULTIPLE);
		} else {
			tx_ring->count = opt.def;
		}
314
		for (i = 0; i < adapter->num_tx_queues; i++)
315
			tx_ring[i].count = tx_ring->count;
L
Linus Torvalds 已提交
316 317
	}
	{ /* Receive Descriptor Count */
L
Linus Torvalds 已提交
318 319 320 321 322
		struct e1000_rx_ring *rx_ring = adapter->rx_ring;
		int i;
		e1000_mac_type mac_type = adapter->hw.mac_type;

		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
323 324 325 326 327
			.type = range_option,
			.name = "Receive Descriptors",
			.err  = "using default of "
				__MODULE_STRING(E1000_DEFAULT_RXD),
			.def  = E1000_DEFAULT_RXD,
L
Linus Torvalds 已提交
328 329 330 331
			.arg  = { .r = {
				.min = E1000_MIN_RXD,
				.max = mac_type < e1000_82544 ? E1000_MAX_RXD : E1000_MAX_82544_RXD
			}}
L
Linus Torvalds 已提交
332 333
		};

A
Auke Kok 已提交
334 335 336
		if (num_RxDescriptors > bd) {
			rx_ring->count = RxDescriptors[bd];
			e1000_validate_option(&rx_ring->count, &opt, adapter);
337
			rx_ring->count = ALIGN(rx_ring->count,
A
Auke Kok 已提交
338 339 340 341
						REQ_RX_DESCRIPTOR_MULTIPLE);
		} else {
			rx_ring->count = opt.def;
		}
342
		for (i = 0; i < adapter->num_rx_queues; i++)
343
			rx_ring[i].count = rx_ring->count;
L
Linus Torvalds 已提交
344 345
	}
	{ /* Checksum Offload Enable/Disable */
L
Linus Torvalds 已提交
346
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
347 348 349 350 351 352
			.type = enable_option,
			.name = "Checksum Offload",
			.err  = "defaulting to Enabled",
			.def  = OPTION_ENABLED
		};

A
Auke Kok 已提交
353
		if (num_XsumRX > bd) {
S
Stephen Hemminger 已提交
354
			unsigned int rx_csum = XsumRX[bd];
A
Auke Kok 已提交
355 356 357 358 359
			e1000_validate_option(&rx_csum, &opt, adapter);
			adapter->rx_csum = rx_csum;
		} else {
			adapter->rx_csum = opt.def;
		}
L
Linus Torvalds 已提交
360 361 362 363
	}
	{ /* Flow Control */

		struct e1000_opt_list fc_list[] =
364 365 366 367 368
			{{ E1000_FC_NONE,    "Flow Control Disabled" },
			 { E1000_FC_RX_PAUSE,"Flow Control Receive Only" },
			 { E1000_FC_TX_PAUSE,"Flow Control Transmit Only" },
			 { E1000_FC_FULL,    "Flow Control Enabled" },
			 { E1000_FC_DEFAULT, "Flow Control Hardware Default" }};
L
Linus Torvalds 已提交
369

L
Linus Torvalds 已提交
370
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
371 372 373
			.type = list_option,
			.name = "Flow Control",
			.err  = "reading default settings from EEPROM",
374
			.def  = E1000_FC_DEFAULT,
L
Linus Torvalds 已提交
375 376 377 378
			.arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
					 .p = fc_list }}
		};

A
Auke Kok 已提交
379
		if (num_FlowControl > bd) {
S
Stephen Hemminger 已提交
380
			unsigned int fc = FlowControl[bd];
A
Auke Kok 已提交
381 382 383 384 385
			e1000_validate_option(&fc, &opt, adapter);
			adapter->hw.fc = adapter->hw.original_fc = fc;
		} else {
			adapter->hw.fc = adapter->hw.original_fc = opt.def;
		}
L
Linus Torvalds 已提交
386 387
	}
	{ /* Transmit Interrupt Delay */
L
Linus Torvalds 已提交
388
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
389 390 391 392 393 394 395 396
			.type = range_option,
			.name = "Transmit Interrupt Delay",
			.err  = "using default of " __MODULE_STRING(DEFAULT_TIDV),
			.def  = DEFAULT_TIDV,
			.arg  = { .r = { .min = MIN_TXDELAY,
					 .max = MAX_TXDELAY }}
		};

A
Auke Kok 已提交
397 398 399 400 401 402 403
		if (num_TxIntDelay > bd) {
			adapter->tx_int_delay = TxIntDelay[bd];
			e1000_validate_option(&adapter->tx_int_delay, &opt,
			                      adapter);
		} else {
			adapter->tx_int_delay = opt.def;
		}
L
Linus Torvalds 已提交
404 405
	}
	{ /* Transmit Absolute Interrupt Delay */
L
Linus Torvalds 已提交
406
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
407 408 409 410 411 412 413 414
			.type = range_option,
			.name = "Transmit Absolute Interrupt Delay",
			.err  = "using default of " __MODULE_STRING(DEFAULT_TADV),
			.def  = DEFAULT_TADV,
			.arg  = { .r = { .min = MIN_TXABSDELAY,
					 .max = MAX_TXABSDELAY }}
		};

A
Auke Kok 已提交
415 416 417 418 419 420 421
		if (num_TxAbsIntDelay > bd) {
			adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
			e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
			                      adapter);
		} else {
			adapter->tx_abs_int_delay = opt.def;
		}
L
Linus Torvalds 已提交
422 423
	}
	{ /* Receive Interrupt Delay */
L
Linus Torvalds 已提交
424
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
425 426 427 428 429 430 431 432
			.type = range_option,
			.name = "Receive Interrupt Delay",
			.err  = "using default of " __MODULE_STRING(DEFAULT_RDTR),
			.def  = DEFAULT_RDTR,
			.arg  = { .r = { .min = MIN_RXDELAY,
					 .max = MAX_RXDELAY }}
		};

A
Auke Kok 已提交
433 434 435 436 437 438 439
		if (num_RxIntDelay > bd) {
			adapter->rx_int_delay = RxIntDelay[bd];
			e1000_validate_option(&adapter->rx_int_delay, &opt,
			                      adapter);
		} else {
			adapter->rx_int_delay = opt.def;
		}
L
Linus Torvalds 已提交
440 441
	}
	{ /* Receive Absolute Interrupt Delay */
L
Linus Torvalds 已提交
442
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
443 444 445 446 447 448 449 450
			.type = range_option,
			.name = "Receive Absolute Interrupt Delay",
			.err  = "using default of " __MODULE_STRING(DEFAULT_RADV),
			.def  = DEFAULT_RADV,
			.arg  = { .r = { .min = MIN_RXABSDELAY,
					 .max = MAX_RXABSDELAY }}
		};

A
Auke Kok 已提交
451 452 453 454 455 456 457
		if (num_RxAbsIntDelay > bd) {
			adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
			e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
			                      adapter);
		} else {
			adapter->rx_abs_int_delay = opt.def;
		}
L
Linus Torvalds 已提交
458 459
	}
	{ /* Interrupt Throttling Rate */
L
Linus Torvalds 已提交
460
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
461 462 463 464 465 466 467 468
			.type = range_option,
			.name = "Interrupt Throttling Rate (ints/sec)",
			.err  = "using default of " __MODULE_STRING(DEFAULT_ITR),
			.def  = DEFAULT_ITR,
			.arg  = { .r = { .min = MIN_ITR,
					 .max = MAX_ITR }}
		};

A
Auke Kok 已提交
469 470 471 472
		if (num_InterruptThrottleRate > bd) {
			adapter->itr = InterruptThrottleRate[bd];
			switch (adapter->itr) {
			case 0:
473
				e_dev_info("%s turned off\n", opt.name);
A
Auke Kok 已提交
474 475
				break;
			case 1:
476 477
				e_dev_info("%s set to dynamic mode\n",
					   opt.name);
J
Jesse Brandeburg 已提交
478 479 480 481
				adapter->itr_setting = adapter->itr;
				adapter->itr = 20000;
				break;
			case 3:
482 483
				e_dev_info("%s set to dynamic conservative "
					   "mode\n", opt.name);
J
Jesse Brandeburg 已提交
484 485
				adapter->itr_setting = adapter->itr;
				adapter->itr = 20000;
A
Auke Kok 已提交
486
				break;
487 488 489 490 491
			case 4:
				e_dev_info("%s set to simplified "
				           "(2000-8000) ints mode\n", opt.name);
				adapter->itr_setting = adapter->itr;
				break;
A
Auke Kok 已提交
492 493
			default:
				e1000_validate_option(&adapter->itr, &opt,
J
Jesse Brandeburg 已提交
494
				        adapter);
495 496 497
				/* save the setting, because the dynamic bits
				 * change itr.
				 * clear the lower two bits because they are
498 499
				 * used as control */
				adapter->itr_setting = adapter->itr & ~3;
A
Auke Kok 已提交
500 501 502
				break;
			}
		} else {
J
Jesse Brandeburg 已提交
503 504
			adapter->itr_setting = opt.def;
			adapter->itr = 20000;
L
Linus Torvalds 已提交
505 506
		}
	}
A
Auke Kok 已提交
507
	{ /* Smart Power Down */
L
Linus Torvalds 已提交
508
		opt = (struct e1000_option) {
A
Auke Kok 已提交
509 510 511 512 513 514
			.type = enable_option,
			.name = "PHY Smart Power Down",
			.err  = "defaulting to Disabled",
			.def  = OPTION_DISABLED
		};

A
Auke Kok 已提交
515
		if (num_SmartPowerDownEnable > bd) {
S
Stephen Hemminger 已提交
516
			unsigned int spd = SmartPowerDownEnable[bd];
A
Auke Kok 已提交
517 518 519 520 521
			e1000_validate_option(&spd, &opt, adapter);
			adapter->smart_power_down = spd;
		} else {
			adapter->smart_power_down = opt.def;
		}
A
Auke Kok 已提交
522
	}
L
Linus Torvalds 已提交
523

J
Jesse Brandeburg 已提交
524
	switch (adapter->hw.media_type) {
L
Linus Torvalds 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
	case e1000_media_type_fiber:
	case e1000_media_type_internal_serdes:
		e1000_check_fiber_options(adapter);
		break;
	case e1000_media_type_copper:
		e1000_check_copper_options(adapter);
		break;
	default:
		BUG();
	}
}

/**
 * e1000_check_fiber_options - Range Checking for Link Options, Fiber Version
 * @adapter: board private structure
 *
 * Handles speed and duplex options on fiber adapters
 **/

544
static void __devinit e1000_check_fiber_options(struct e1000_adapter *adapter)
L
Linus Torvalds 已提交
545 546
{
	int bd = adapter->bd_number;
A
Auke Kok 已提交
547
	if (num_Speed > bd) {
548 549
		e_dev_info("Speed not valid for fiber adapters, parameter "
			   "ignored\n");
L
Linus Torvalds 已提交
550 551
	}

A
Auke Kok 已提交
552
	if (num_Duplex > bd) {
553 554
		e_dev_info("Duplex not valid for fiber adapters, parameter "
			   "ignored\n");
L
Linus Torvalds 已提交
555 556
	}

A
Auke Kok 已提交
557
	if ((num_AutoNeg > bd) && (AutoNeg[bd] != 0x20)) {
558 559
		e_dev_info("AutoNeg other than 1000/Full is not valid for fiber"
			   "adapters, parameter ignored\n");
L
Linus Torvalds 已提交
560 561 562 563 564 565 566 567 568 569
	}
}

/**
 * e1000_check_copper_options - Range Checking for Link Options, Copper Version
 * @adapter: board private structure
 *
 * Handles speed and duplex options on copper adapters
 **/

570
static void __devinit e1000_check_copper_options(struct e1000_adapter *adapter)
L
Linus Torvalds 已提交
571
{
L
Linus Torvalds 已提交
572
	struct e1000_option opt;
S
Stephen Hemminger 已提交
573
	unsigned int speed, dplx, an;
L
Linus Torvalds 已提交
574 575 576
	int bd = adapter->bd_number;

	{ /* Speed */
L
Linus Torvalds 已提交
577 578 579 580 581
		static const struct e1000_opt_list speed_list[] = {
			{          0, "" },
			{   SPEED_10, "" },
			{  SPEED_100, "" },
			{ SPEED_1000, "" }};
L
Linus Torvalds 已提交
582

L
Linus Torvalds 已提交
583
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
584 585 586 587 588 589 590 591
			.type = list_option,
			.name = "Speed",
			.err  = "parameter ignored",
			.def  = 0,
			.arg  = { .l = { .nr = ARRAY_SIZE(speed_list),
					 .p = speed_list }}
		};

A
Auke Kok 已提交
592 593 594 595 596 597
		if (num_Speed > bd) {
			speed = Speed[bd];
			e1000_validate_option(&speed, &opt, adapter);
		} else {
			speed = opt.def;
		}
L
Linus Torvalds 已提交
598 599
	}
	{ /* Duplex */
L
Linus Torvalds 已提交
600 601 602 603
		static const struct e1000_opt_list dplx_list[] = {
			{           0, "" },
			{ HALF_DUPLEX, "" },
			{ FULL_DUPLEX, "" }};
L
Linus Torvalds 已提交
604

L
Linus Torvalds 已提交
605
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
606 607 608 609 610 611 612 613
			.type = list_option,
			.name = "Duplex",
			.err  = "parameter ignored",
			.def  = 0,
			.arg  = { .l = { .nr = ARRAY_SIZE(dplx_list),
					 .p = dplx_list }}
		};

A
Auke Kok 已提交
614 615 616 617 618 619
		if (num_Duplex > bd) {
			dplx = Duplex[bd];
			e1000_validate_option(&dplx, &opt, adapter);
		} else {
			dplx = opt.def;
		}
L
Linus Torvalds 已提交
620 621
	}

A
Auke Kok 已提交
622
	if ((num_AutoNeg > bd) && (speed != 0 || dplx != 0)) {
623 624
		e_dev_info("AutoNeg specified along with Speed or Duplex, "
			   "parameter ignored\n");
L
Linus Torvalds 已提交
625 626
		adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
	} else { /* Autoneg */
L
Linus Torvalds 已提交
627
		static const struct e1000_opt_list an_list[] =
L
Linus Torvalds 已提交
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
			#define AA "AutoNeg advertising "
			{{ 0x01, AA "10/HD" },
			 { 0x02, AA "10/FD" },
			 { 0x03, AA "10/FD, 10/HD" },
			 { 0x04, AA "100/HD" },
			 { 0x05, AA "100/HD, 10/HD" },
			 { 0x06, AA "100/HD, 10/FD" },
			 { 0x07, AA "100/HD, 10/FD, 10/HD" },
			 { 0x08, AA "100/FD" },
			 { 0x09, AA "100/FD, 10/HD" },
			 { 0x0a, AA "100/FD, 10/FD" },
			 { 0x0b, AA "100/FD, 10/FD, 10/HD" },
			 { 0x0c, AA "100/FD, 100/HD" },
			 { 0x0d, AA "100/FD, 100/HD, 10/HD" },
			 { 0x0e, AA "100/FD, 100/HD, 10/FD" },
			 { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
			 { 0x20, AA "1000/FD" },
			 { 0x21, AA "1000/FD, 10/HD" },
			 { 0x22, AA "1000/FD, 10/FD" },
			 { 0x23, AA "1000/FD, 10/FD, 10/HD" },
			 { 0x24, AA "1000/FD, 100/HD" },
			 { 0x25, AA "1000/FD, 100/HD, 10/HD" },
			 { 0x26, AA "1000/FD, 100/HD, 10/FD" },
			 { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
			 { 0x28, AA "1000/FD, 100/FD" },
			 { 0x29, AA "1000/FD, 100/FD, 10/HD" },
			 { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
			 { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
			 { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
			 { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
			 { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
			 { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }};

L
Linus Torvalds 已提交
661
		opt = (struct e1000_option) {
L
Linus Torvalds 已提交
662 663 664 665 666 667 668 669
			.type = list_option,
			.name = "AutoNeg",
			.err  = "parameter ignored",
			.def  = AUTONEG_ADV_DEFAULT,
			.arg  = { .l = { .nr = ARRAY_SIZE(an_list),
					 .p = an_list }}
		};

A
Auke Kok 已提交
670 671 672 673 674 675
		if (num_AutoNeg > bd) {
			an = AutoNeg[bd];
			e1000_validate_option(&an, &opt, adapter);
		} else {
			an = opt.def;
		}
L
Linus Torvalds 已提交
676 677 678 679 680 681
		adapter->hw.autoneg_advertised = an;
	}

	switch (speed + dplx) {
	case 0:
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
A
Auke Kok 已提交
682
		if ((num_Speed > bd) && (speed != 0 || dplx != 0))
683 684
			e_dev_info("Speed and duplex autonegotiation "
				   "enabled\n");
L
Linus Torvalds 已提交
685 686
		break;
	case HALF_DUPLEX:
687 688
		e_dev_info("Half Duplex specified without Speed\n");
		e_dev_info("Using Autonegotiation at Half Duplex only\n");
L
Linus Torvalds 已提交
689 690 691 692 693
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
		                                 ADVERTISE_100_HALF;
		break;
	case FULL_DUPLEX:
694 695
		e_dev_info("Full Duplex specified without Speed\n");
		e_dev_info("Using Autonegotiation at Full Duplex only\n");
L
Linus Torvalds 已提交
696 697 698 699 700 701
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		adapter->hw.autoneg_advertised = ADVERTISE_10_FULL |
		                                 ADVERTISE_100_FULL |
		                                 ADVERTISE_1000_FULL;
		break;
	case SPEED_10:
702 703
		e_dev_info("10 Mbps Speed specified without Duplex\n");
		e_dev_info("Using Autonegotiation at 10 Mbps only\n");
L
Linus Torvalds 已提交
704 705 706 707 708
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
		                                 ADVERTISE_10_FULL;
		break;
	case SPEED_10 + HALF_DUPLEX:
709
		e_dev_info("Forcing to 10 Mbps Half Duplex\n");
L
Linus Torvalds 已提交
710 711 712 713 714
		adapter->hw.autoneg = adapter->fc_autoneg = 0;
		adapter->hw.forced_speed_duplex = e1000_10_half;
		adapter->hw.autoneg_advertised = 0;
		break;
	case SPEED_10 + FULL_DUPLEX:
715
		e_dev_info("Forcing to 10 Mbps Full Duplex\n");
L
Linus Torvalds 已提交
716 717 718 719 720
		adapter->hw.autoneg = adapter->fc_autoneg = 0;
		adapter->hw.forced_speed_duplex = e1000_10_full;
		adapter->hw.autoneg_advertised = 0;
		break;
	case SPEED_100:
721 722
		e_dev_info("100 Mbps Speed specified without Duplex\n");
		e_dev_info("Using Autonegotiation at 100 Mbps only\n");
L
Linus Torvalds 已提交
723 724 725 726 727
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		adapter->hw.autoneg_advertised = ADVERTISE_100_HALF |
		                                 ADVERTISE_100_FULL;
		break;
	case SPEED_100 + HALF_DUPLEX:
728
		e_dev_info("Forcing to 100 Mbps Half Duplex\n");
L
Linus Torvalds 已提交
729 730 731 732 733
		adapter->hw.autoneg = adapter->fc_autoneg = 0;
		adapter->hw.forced_speed_duplex = e1000_100_half;
		adapter->hw.autoneg_advertised = 0;
		break;
	case SPEED_100 + FULL_DUPLEX:
734
		e_dev_info("Forcing to 100 Mbps Full Duplex\n");
L
Linus Torvalds 已提交
735 736 737 738 739
		adapter->hw.autoneg = adapter->fc_autoneg = 0;
		adapter->hw.forced_speed_duplex = e1000_100_full;
		adapter->hw.autoneg_advertised = 0;
		break;
	case SPEED_1000:
740
		e_dev_info("1000 Mbps Speed specified without Duplex\n");
741
		goto full_duplex_only;
L
Linus Torvalds 已提交
742
	case SPEED_1000 + HALF_DUPLEX:
743
		e_dev_info("Half Duplex is not supported at 1000 Mbps\n");
744
		/* fall through */
L
Linus Torvalds 已提交
745
	case SPEED_1000 + FULL_DUPLEX:
746
full_duplex_only:
747 748
		e_dev_info("Using Autonegotiation at 1000 Mbps Full Duplex "
			   "only\n");
L
Linus Torvalds 已提交
749 750 751 752 753 754 755 756 757
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
		break;
	default:
		BUG();
	}

	/* Speed, AutoNeg and MDI/MDI-X must all play nice */
	if (e1000_validate_mdi_setting(&(adapter->hw)) < 0) {
758 759
		e_dev_info("Speed, AutoNeg and MDI-X specs are incompatible. "
			   "Setting MDI-X to a compatible value.\n");
L
Linus Torvalds 已提交
760 761 762
	}
}